summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2009-07-29 04:14:54 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2009-07-29 04:14:54 +0000
commitad1660074fd42c893f74d4fe4587ca68b1cc5479 (patch)
tree53c946b77be1b1261d53705b863073c3a2cc37d7
parentd10f9511cfa3587960ac86a2b726d86ab403ee76 (diff)
downloadrockbox-ad1660074fd42c893f74d4fe4587ca68b1cc5479.tar.gz
rockbox-ad1660074fd42c893f74d4fe4587ca68b1cc5479.zip
Reversi: Attempt to account for screen aspect, add preliminary absolute touchscreen support (Menu button and quit button need to be added to display)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22079 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/reversi/reversi-gui.c113
-rw-r--r--apps/plugins/reversi/reversi-gui.h10
2 files changed, 80 insertions, 43 deletions
diff --git a/apps/plugins/reversi/reversi-gui.c b/apps/plugins/reversi/reversi-gui.c
index 0bf32daed0..2ad27caf01 100644
--- a/apps/plugins/reversi/reversi-gui.c
+++ b/apps/plugins/reversi/reversi-gui.c
@@ -51,52 +51,69 @@ further options:
51 51
52PLUGIN_HEADER 52PLUGIN_HEADER
53 53
54/* Thickness of the grid lines */ 54/* Where the board begins */
55#define LINE_THCK 1 55#define XOFS 4
56#define YOFS 4
56 57
57#if (LCD_WIDTH/12) < (LCD_HEIGHT/10) 58#if LCD_HEIGHT > LCD_WIDTH
58#define CELL_WIDTH (LCD_WIDTH/12) 59#define MARGIN_W (XOFS*2+1)
59#define CELL_HEIGHT (LCD_WIDTH/12) 60#define MARGIN_H (YOFS*2+1)
61#define MARGIN_C_W 0
62#define MARGIN_C_H 2
60#else 63#else
61#define CELL_WIDTH (LCD_HEIGHT/10) 64#define MARGIN_W (XOFS*2 + 16)
62#define CELL_HEIGHT (LCD_HEIGHT/10) 65#define MARGIN_H (YOFS*2+1)
66#define MARGIN_C_W 1
67#define MARGIN_C_H 0
63#endif 68#endif
64 69
70#if ( (LCD_WIDTH - MARGIN_W) / (BOARD_SIZE+MARGIN_C_W)) < \
71 ( (LCD_HEIGHT - MARGIN_H) / (BOARD_SIZE+MARGIN_C_H))
65 72
66/* Where the board begins */ 73#define CELL_PRE ( ( (LCD_WIDTH * LCD_PIXEL_ASPECT_WIDTH / \
67#define XOFS 4 74 LCD_PIXEL_ASPECT_HEIGHT) - MARGIN_W) / \
68#define YOFS 4 75 (BOARD_SIZE+MARGIN_C_W) )
76
77#define CELL_WIDTH (CELL_PRE*LCD_PIXEL_ASPECT_HEIGHT / LCD_PIXEL_ASPECT_WIDTH)
78#define CELL_HEIGHT (CELL_PRE)
79#else
80#define CELL_PRE ( ( (LCD_HEIGHT * LCD_PIXEL_ASPECT_HEIGHT / \
81 LCD_PIXEL_ASPECT_WIDTH) - MARGIN_H) / \
82 (BOARD_SIZE+MARGIN_C_H) )
83
84#define CELL_WIDTH (CELL_PRE)
85#define CELL_HEIGHT (CELL_PRE*LCD_PIXEL_ASPECT_WIDTH / LCD_PIXEL_ASPECT_HEIGHT)
86#endif
69 87
70/* Total width and height of the board without enclosing box */ 88/* Total width and height of the board without enclosing box */
71#define BOARD_WIDTH (CELL_WIDTH*BOARD_SIZE + LINE_THCK*(BOARD_SIZE+1)) 89#define BOARD_WIDTH (CELL_WIDTH*BOARD_SIZE)
72#define BOARD_HEIGHT (CELL_HEIGHT*BOARD_SIZE + LINE_THCK*(BOARD_SIZE+1)) 90#define BOARD_HEIGHT (CELL_HEIGHT*BOARD_SIZE)
73 91
74/* Thickness of the white cells' lines */ 92/* Thickness of the white cells' lines */
75#if (CELL_WIDTH >= 15) && (CELL_HEIGHT >= 15) 93#if (CELL_WIDTH >= 10) && (CELL_HEIGHT >= 10)
76#define CELL_LINE_THICKNESS 2 94#define CELL_LINE_THICKNESS CELL_WIDTH/5
77#else 95#else
78#define CELL_LINE_THICKNESS 1 96#define CELL_LINE_THICKNESS 1
79#endif 97#endif
80 98
81/* Margins within a cell */ 99/* Margins within a cell */
82#if (CELL_WIDTH >= 10) && (CELL_HEIGHT >= 10)
83#define STONE_MARGIN 2 100#define STONE_MARGIN 2
84#else
85#define STONE_MARGIN 1
86#endif
87 101
88#define CURSOR_MARGIN (STONE_MARGIN + CELL_LINE_THICKNESS) 102#define CURSOR_MARGIN 1
89 103
90/* Upper left corner of a cell */ 104/* Upper left corner of a cell */
91#define CELL_X(c) (XOFS + (c)*CELL_WIDTH + ((c)+1)*LINE_THCK) 105#define CELL_X(c) (XOFS + (c)*CELL_WIDTH)
92#define CELL_Y(r) (YOFS + (r)*CELL_HEIGHT + ((r)+1)*LINE_THCK) 106#define CELL_Y(r) (YOFS + (r)*CELL_HEIGHT)
93 107
108/* Used for touchscreen to convert an X/Y location to a cell location */
109#define CELL_C(x) (((x)-XOFS)/CELL_WIDTH)
110#define CELL_R(y) (((y)-YOFS)/CELL_HEIGHT)
94 111
95#ifdef VERTICAL_LAYOUT 112#if LCD_HEIGHT > LCD_WIDTH
96#define LEGEND_X(lc) (CELL_X(lc)) 113#define LEGEND_X(lc) (CELL_X(lc))
97#define LEGEND_Y(lr) (CELL_Y(BOARD_SIZE+(lr)) + CELL_HEIGHT/2) 114#define LEGEND_Y(lr) (CELL_Y(BOARD_SIZE+lr) + YOFS + 1)
98#else 115#else
99#define LEGEND_X(lc) (CELL_X(BOARD_SIZE+(lc)) + CELL_WIDTH/2) 116#define LEGEND_X(lc) (CELL_X(BOARD_SIZE+lc) + XOFS + 1)
100#define LEGEND_Y(lr) (CELL_Y(lr)) 117#define LEGEND_Y(lr) (CELL_Y(lr))
101#endif 118#endif
102 119
@@ -146,15 +163,15 @@ static void reversi_gui_display_cursor(int row, int col) {
146 163
147 rb->lcd_set_drawmode(DRMODE_COMPLEMENT); 164 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
148 rb->lcd_drawline(x+CURSOR_MARGIN, y+CURSOR_MARGIN, 165 rb->lcd_drawline(x+CURSOR_MARGIN, y+CURSOR_MARGIN,
149 x+CELL_WIDTH-CURSOR_MARGIN-1, y+CELL_HEIGHT-CURSOR_MARGIN-1); 166 x+CELL_WIDTH-CURSOR_MARGIN, y+CELL_HEIGHT-CURSOR_MARGIN);
150 rb->lcd_drawline(x+CURSOR_MARGIN, y+CELL_HEIGHT-CURSOR_MARGIN-1, 167 rb->lcd_drawline(x+CURSOR_MARGIN, y+CELL_HEIGHT-CURSOR_MARGIN,
151 x+CELL_WIDTH-CURSOR_MARGIN-1, y+CURSOR_MARGIN); 168 x+CELL_WIDTH-CURSOR_MARGIN, y+CURSOR_MARGIN);
152 169
153 /* Draw the shadows */ 170 /* Draw the shadows */
154 rb->lcd_hline(x, x+CELL_WIDTH-1, YOFS-3); 171 rb->lcd_hline(x, x+CELL_WIDTH-1, YOFS-3);
155 rb->lcd_hline(x, x+CELL_WIDTH-1, YOFS+BOARD_HEIGHT+2); 172 rb->lcd_hline(x, x+CELL_WIDTH-1, YOFS+BOARD_HEIGHT+3);
156 rb->lcd_vline(XOFS-3, y, y+CELL_HEIGHT-1); 173 rb->lcd_vline(XOFS-3, y, y+CELL_HEIGHT-1);
157 rb->lcd_vline(XOFS+BOARD_WIDTH+2, y, y+CELL_HEIGHT-1); 174 rb->lcd_vline(XOFS+BOARD_WIDTH+3, y, y+CELL_HEIGHT-1);
158 175
159 rb->lcd_set_drawmode(old_mode); 176 rb->lcd_set_drawmode(old_mode);
160 rb->lcd_update(); 177 rb->lcd_update();
@@ -168,11 +185,11 @@ static void reversi_gui_draw_cell(int x, int y, int color) {
168 if (color == WHITE) { 185 if (color == WHITE) {
169 for (i = 0; i < CELL_LINE_THICKNESS; i++) { 186 for (i = 0; i < CELL_LINE_THICKNESS; i++) {
170 rb->lcd_drawrect(x+STONE_MARGIN+i, y+STONE_MARGIN+i, 187 rb->lcd_drawrect(x+STONE_MARGIN+i, y+STONE_MARGIN+i,
171 CELL_WIDTH-2*(STONE_MARGIN+i), CELL_HEIGHT-2*(STONE_MARGIN+i)); 188 CELL_WIDTH+1-2*(STONE_MARGIN+i), CELL_HEIGHT+1-2*(STONE_MARGIN+i));
172 } 189 }
173 } else if (color == BLACK) { 190 } else if (color == BLACK) {
174 rb->lcd_fillrect(x+STONE_MARGIN, y+STONE_MARGIN, 191 rb->lcd_fillrect(x+STONE_MARGIN, y+STONE_MARGIN,
175 CELL_WIDTH-2*STONE_MARGIN, CELL_HEIGHT-2*STONE_MARGIN); 192 CELL_WIDTH-STONE_MARGIN-1, CELL_HEIGHT-1-STONE_MARGIN);
176 } else { 193 } else {
177 /* Cell is free -> nothing to do */ 194 /* Cell is free -> nothing to do */
178 } 195 }
@@ -189,13 +206,13 @@ static void reversi_gui_display_board(void) {
189 rb->lcd_set_drawmode(DRMODE_FG); 206 rb->lcd_set_drawmode(DRMODE_FG);
190 207
191 /* Thicker board box */ 208 /* Thicker board box */
192 rb->lcd_drawrect(XOFS-1, YOFS-1, BOARD_WIDTH+2, BOARD_HEIGHT+2); 209 rb->lcd_drawrect(XOFS-1, YOFS-1, BOARD_WIDTH+3, BOARD_HEIGHT+3);
193 210
194 /* Draw the gridlines */ 211 /* Draw the gridlines */
195 for (r=0, x=XOFS, y=YOFS; r<=BOARD_SIZE; 212 for (r=0, x=XOFS, y=YOFS; r<=BOARD_SIZE;
196 r++, x+=CELL_WIDTH+LINE_THCK, y+=CELL_HEIGHT+LINE_THCK) { 213 r++, x+=CELL_WIDTH, y+=CELL_HEIGHT) {
197 rb->lcd_hline(XOFS, XOFS+BOARD_WIDTH-1, y); 214 rb->lcd_hline(XOFS, XOFS+BOARD_WIDTH, y);
198 rb->lcd_vline(x, YOFS, YOFS+BOARD_HEIGHT-1); 215 rb->lcd_vline(x, YOFS, YOFS+BOARD_HEIGHT);
199 } 216 }
200 217
201 /* Draw the stones. This is not the most efficient way but more readable */ 218 /* Draw the stones. This is not the most efficient way but more readable */
@@ -219,18 +236,18 @@ static void reversi_gui_display_board(void) {
219 reversi_gui_draw_cell(x, y, BLACK); 236 reversi_gui_draw_cell(x, y, BLACK);
220 rb->snprintf(buf, sizeof(buf), "%d", c); 237 rb->snprintf(buf, sizeof(buf), "%d", c);
221 y += (CELL_HEIGHT-x_height) / 2; 238 y += (CELL_HEIGHT-x_height) / 2;
222 rb->lcd_putsxy(x + CELL_WIDTH + CELL_WIDTH/2, y, buf); 239 rb->lcd_putsxy(x + CELL_WIDTH + 2, y, buf);
223 240
224 y = LEGEND_Y(1); 241 y = LEGEND_Y(1);
225 reversi_gui_draw_cell(x, y, WHITE); 242 reversi_gui_draw_cell(x, y, WHITE);
226 rb->snprintf(buf, sizeof(buf), "%d", r); 243 rb->snprintf(buf, sizeof(buf), "%d", r);
227 y += (CELL_HEIGHT-x_height) / 2; 244 y += (CELL_HEIGHT-x_height) / 2;
228 rb->lcd_putsxy(x + CELL_WIDTH + CELL_WIDTH/2, y, buf); 245 rb->lcd_putsxy(x + CELL_WIDTH + 2, y, buf);
229 246
230 /* Draw the box around the current player */ 247 /* Draw the box around the current player */
231 r = (cur_player == BLACK ? 0 : 1); 248 r = (cur_player == BLACK ? 0 : 1);
232 y = LEGEND_Y(r); 249 y = LEGEND_Y(r);
233 rb->lcd_drawrect(x-1, y-1, CELL_WIDTH+2, CELL_HEIGHT+2); 250 rb->lcd_drawrect(x, y, CELL_WIDTH+1, CELL_HEIGHT+1);
234 251
235 /* Update the screen */ 252 /* Update the screen */
236 rb->lcd_update(); 253 rb->lcd_update();
@@ -466,10 +483,17 @@ static void reversi_gui_move_cursor(int new_row, int new_col) {
466enum plugin_status plugin_start(const void *parameter) { 483enum plugin_status plugin_start(const void *parameter) {
467 bool exit, draw_screen; 484 bool exit, draw_screen;
468 int button; 485 int button;
486#ifdef HAVE_TOUCHSCREEN
487 int button_x, button_y;
488#endif
469 int lastbutton = BUTTON_NONE; 489 int lastbutton = BUTTON_NONE;
470 int row, col; 490 int row, col;
471 int w_cnt, b_cnt; 491 int w_cnt, b_cnt;
472 char msg_buf[30]; 492 char msg_buf[30];
493
494#ifdef HAVE_TOUCHSCREEN
495 rb->touchscreen_set_mode(TOUCHSCREEN_POINT);
496#endif
473 497
474#if LCD_DEPTH > 1 498#if LCD_DEPTH > 1
475 rb->lcd_set_backdrop(NULL); 499 rb->lcd_set_backdrop(NULL);
@@ -540,6 +564,19 @@ enum plugin_status plugin_start(const void *parameter) {
540 break; 564 break;
541#endif 565#endif
542 566
567#ifdef HAVE_TOUCHSCREEN
568 case BUTTON_TOUCHSCREEN:
569 button_x = rb->button_get_data() >> 16;
570 button_y = rb->button_get_data() & 0xffff;
571 if( (CELL_R(button_y)>(BOARD_SIZE-1)) ||
572 (CELL_C(button_x)>(BOARD_SIZE-1)) )
573 {
574 break;
575 } else {
576 reversi_gui_move_cursor(CELL_R(button_y), CELL_C(button_x));
577 }
578#endif
579
543#ifdef REVERSI_BUTTON_ALT_MAKE_MOVE 580#ifdef REVERSI_BUTTON_ALT_MAKE_MOVE
544 case REVERSI_BUTTON_ALT_MAKE_MOVE: 581 case REVERSI_BUTTON_ALT_MAKE_MOVE:
545#endif 582#endif
diff --git a/apps/plugins/reversi/reversi-gui.h b/apps/plugins/reversi/reversi-gui.h
index 9ae6e9f286..8c409e9a75 100644
--- a/apps/plugins/reversi/reversi-gui.h
+++ b/apps/plugins/reversi/reversi-gui.h
@@ -128,7 +128,7 @@
128#define REVERSI_BUTTON_MENU (BUTTON_SELECT|BUTTON_REPEAT) 128#define REVERSI_BUTTON_MENU (BUTTON_SELECT|BUTTON_REPEAT)
129 129
130#elif CONFIG_KEYPAD == MROBE500_PAD 130#elif CONFIG_KEYPAD == MROBE500_PAD
131#define REVERSI_QUIT BUTTON_POWER 131#define REVERSI_BUTTON_QUIT BUTTON_POWER
132 132
133#elif (CONFIG_KEYPAD == MROBE100_PAD) 133#elif (CONFIG_KEYPAD == MROBE100_PAD)
134#define REVERSI_BUTTON_QUIT BUTTON_POWER 134#define REVERSI_BUTTON_QUIT BUTTON_POWER
@@ -149,7 +149,7 @@
149#define REVERSI_BUTTON_MENU BUTTON_RC_MENU 149#define REVERSI_BUTTON_MENU BUTTON_RC_MENU
150 150
151#elif CONFIG_KEYPAD == COWOND2_PAD 151#elif CONFIG_KEYPAD == COWOND2_PAD
152#define REVERSI_QUIT BUTTON_POWER 152#define REVERSI_BUTTON_QUIT BUTTON_POWER
153#define REVERSI_BUTTON_MENU BUTTON_MENU 153#define REVERSI_BUTTON_MENU BUTTON_MENU
154 154
155#elif CONFIG_KEYPAD == IAUDIO67_PAD 155#elif CONFIG_KEYPAD == IAUDIO67_PAD
@@ -180,7 +180,7 @@
180#define REVERSI_BUTTON_MENU BUTTON_MENU 180#define REVERSI_BUTTON_MENU BUTTON_MENU
181 181
182#elif CONFIG_KEYPAD == ONDAVX747_PAD 182#elif CONFIG_KEYPAD == ONDAVX747_PAD
183#define REVERSI_QUIT BUTTON_POWER 183#define REVERSI_BUTTON_QUIT BUTTON_POWER
184#define REVERSI_BUTTON_MENU BUTTON_MENU 184#define REVERSI_BUTTON_MENU BUTTON_MENU
185 185
186#else 186#else
@@ -188,8 +188,8 @@
188#endif 188#endif
189 189
190#ifdef HAVE_TOUCHSCREEN 190#ifdef HAVE_TOUCHSCREEN
191#ifndef REVERSI_QUIT 191#ifndef REVERSI_BUTTON_QUIT
192#define REVERSI_QUIT BUTTON_TOPLEFT 192#define REVERSI_BUTTON_QUIT BUTTON_TOPLEFT
193#endif 193#endif
194#ifndef REVERSI_BUTTON_UP 194#ifndef REVERSI_BUTTON_UP
195#define REVERSI_BUTTON_UP BUTTON_TOPMIDDLE 195#define REVERSI_BUTTON_UP BUTTON_TOPMIDDLE