summaryrefslogtreecommitdiff
path: root/apps/plugins/pegbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pegbox.c')
-rw-r--r--apps/plugins/pegbox.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c
index ed58ac605d..f3a4f0e67c 100644
--- a/apps/plugins/pegbox.c
+++ b/apps/plugins/pegbox.c
@@ -368,6 +368,32 @@ PLUGIN_HEADER
368#define BOARD_Y 0 368#define BOARD_Y 0
369#endif 369#endif
370 370
371#ifdef HAVE_TOUCHPAD
372#include "lib/touchscreen.h"
373
374static struct ts_mapping main_menu_items[5] =
375{
376{(LCD_WIDTH-BMPWIDTH_pegbox_menu_items)/2, BMPHEIGHT_pegbox_menu_top, BMPWIDTH_pegbox_menu_items, (BMPHEIGHT_pegbox_menu_items/9)},
377{(LCD_WIDTH-BMPWIDTH_pegbox_menu_items)/2, BMPHEIGHT_pegbox_menu_top+(BMPHEIGHT_pegbox_menu_items/9), BMPWIDTH_pegbox_menu_items, (BMPHEIGHT_pegbox_menu_items/9)},
378{(LCD_WIDTH-BMPWIDTH_pegbox_menu_items)/2, BMPHEIGHT_pegbox_menu_top+(BMPHEIGHT_pegbox_menu_items/9)*2, BMPWIDTH_pegbox_menu_items, (BMPHEIGHT_pegbox_menu_items/9)},
379{(LCD_WIDTH-BMPWIDTH_pegbox_menu_items)/2, BMPHEIGHT_pegbox_menu_top+(BMPHEIGHT_pegbox_menu_items/9)*3, BMPWIDTH_pegbox_menu_items, (BMPHEIGHT_pegbox_menu_items/9)},
380{
381#if (LCD_WIDTH >= 138) && (LCD_HEIGHT >= 110)
3820, BMPHEIGHT_pegbox_menu_top+4*(BMPHEIGHT_pegbox_menu_items/9)+8, SYSFONT_WIDTH*28, SYSFONT_HEIGHT
383#elif LCD_WIDTH > 112
3840, LCD_HEIGHT - 8, SYSFONT_WIDTH*28, SYSFONT_HEIGHT
385#else
386#error "Touchpad isn't supported on non-bitmap screens!"
387#endif
388}
389
390};
391static struct ts_mappings main_menu = {main_menu_items, 5};
392
393static struct ts_raster pegbox_raster = { BOARD_X, BOARD_Y, COLS*BMPWIDTH_pegbox_pieces, ROWS*BMPWIDTH_pegbox_pieces, BMPWIDTH_pegbox_pieces, BMPWIDTH_pegbox_pieces };
394static struct ts_raster_button_mapping pegbox_raster_btn = { &pegbox_raster, false, false, true, false, true, {0, 0}, 0, 0, 0 };
395#endif
396
371struct game_context { 397struct game_context {
372 unsigned int level; 398 unsigned int level;
373 unsigned int highlevel; 399 unsigned int highlevel;
@@ -612,6 +638,9 @@ static void display_text(char *str, bool waitkey)
612 key = rb->button_get(true); 638 key = rb->button_get(true);
613 switch (key) 639 switch (key)
614 { 640 {
641#ifdef HAVE_TOUCHPAD
642 case BUTTON_TOUCHPAD:
643#endif
615 case PEGBOX_QUIT: 644 case PEGBOX_QUIT:
616 case PEGBOX_LEFT: 645 case PEGBOX_LEFT:
617 case PEGBOX_DOWN: 646 case PEGBOX_DOWN:
@@ -738,6 +767,28 @@ static void new_piece(struct game_context* pb, unsigned int x_loc,
738 while (!exit) { 767 while (!exit) {
739 draw_board(pb); 768 draw_board(pb);
740 button = rb->button_get(true); 769 button = rb->button_get(true);
770#ifdef HAVE_TOUCHPAD
771 if(button & BUTTON_TOUCHPAD)
772 {
773 pegbox_raster_btn.two_d_from.y = x_loc;
774 pegbox_raster_btn.two_d_from.x = y_loc;
775
776 struct ts_raster_button_result ret = touchscreen_raster_map_button(&pegbox_raster_btn, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff, button);
777 if(ret.action == TS_ACTION_TWO_D_MOVEMENT)
778 {
779 if(ret.to.x > ret.from.x)
780 button = PEGBOX_UP;
781 else if(ret.to.x < ret.from.x)
782 button = PEGBOX_DOWN;
783 else if(ret.to.y > ret.from.y)
784 button = PEGBOX_LEFT;
785 else if(ret.to.y < ret.from.y)
786 button = PEGBOX_RIGHT;
787 }
788 else if(ret.action == TS_ACTION_CLICK && (unsigned)ret.to.x == y_loc && (unsigned)ret.to.y == x_loc)
789 button = PEGBOX_SAVE;
790 }
791#endif
741 switch(button){ 792 switch(button){
742 case PEGBOX_LEFT: 793 case PEGBOX_LEFT:
743 case (PEGBOX_LEFT|BUTTON_REPEAT): 794 case (PEGBOX_LEFT|BUTTON_REPEAT):
@@ -1053,6 +1104,24 @@ static unsigned int pegbox_menu(struct game_context* pb) {
1053 1104
1054 /* handle menu button presses */ 1105 /* handle menu button presses */
1055 button = rb->button_get(true); 1106 button = rb->button_get(true);
1107
1108#ifdef HAVE_TOUCHPAD
1109 if(button & BUTTON_TOUCHPAD)
1110 {
1111 unsigned int result = touchscreen_map(&main_menu, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff);
1112 if(result != (unsigned)-1 && button & BUTTON_REL)
1113 {
1114 if(result == 4)
1115 button = PEGBOX_LVL_UP;
1116 else
1117 {
1118 if(loc == result)
1119 button = PEGBOX_RIGHT;
1120 loc = result;
1121 }
1122 }
1123 }
1124#endif
1056 1125
1057 switch(button) { 1126 switch(button) {
1058 case PEGBOX_SAVE: /* start playing */ 1127 case PEGBOX_SAVE: /* start playing */
@@ -1169,6 +1238,17 @@ static int pegbox(struct game_context* pb) {
1169 1238
1170 while (true) { 1239 while (true) {
1171 temp_var = rb->button_get(true); 1240 temp_var = rb->button_get(true);
1241#ifdef HAVE_TOUCHPAD
1242 if(temp_var & BUTTON_TOUCHPAD)
1243 {
1244 pegbox_raster_btn.two_d_from.y = pb->player_row;
1245 pegbox_raster_btn.two_d_from.x = pb->player_col;
1246
1247 struct ts_raster_button_result ret = touchscreen_raster_map_button(&pegbox_raster_btn, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff, temp_var);
1248 if(ret.action == TS_ACTION_TWO_D_MOVEMENT)
1249 move_player(pb, ret.to.x - ret.from.x, ret.to.y - ret.from.y);
1250 }
1251#endif
1172 switch(temp_var){ 1252 switch(temp_var){
1173 case PEGBOX_LEFT: /* move cursor left */ 1253 case PEGBOX_LEFT: /* move cursor left */
1174 case (PEGBOX_LEFT|BUTTON_REPEAT): 1254 case (PEGBOX_LEFT|BUTTON_REPEAT):