very minor code police. also fix a possible but unlikely missed cpu_boost(false)
[Rockbox.git] / apps / plugins / reversi / reversi-gui.c
blobd91f24b3d9434393b801402ee225274b6f6e813e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (c) 2006 Alexander Levin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 GUI part of reversi. Code is inspired by sudoku code by Dave Chapman
24 which is copyright (c) 2005 Dave Chapman and is released under the
25 GNU General Public License.
28 User instructions
29 -----------------
31 Use the arrow keys to move cursor, and press TOGGLE to place a stone.
33 At any time during the game, press MENU to bring up the game menu with
34 further options:
36 - Save
37 - Reload
38 - Clear
42 #include "plugin.h"
44 #ifdef HAVE_LCD_BITMAP
46 #include "reversi-game.h"
47 #include "reversi-strategy.h"
48 #include "reversi-gui.h"
50 #include "../lib/oldmenuapi.h"
52 PLUGIN_HEADER
54 /* The global api struct pointer. While not strictly necessary,
55 it's nice not to have to pass the api pointer in all function
56 calls in the plugin */
57 static const struct plugin_api* rb;
59 /* Thickness of the grid lines */
60 #define LINE_THCK 1
62 #if LCD_HEIGHT <= LCD_WIDTH /* Horizontal layout */
64 #if (LCD_HEIGHT==64) && (LCD_WIDTH==112)
65 /* Archos Recorders and Ondios - 112x64, 8 cells @ 8x6 with 9 border lines */
67 /* Internal dimensions of a cell */
68 #define CELL_WIDTH 8
69 #define CELL_HEIGHT 6
70 #define SMALL_BOARD
72 #elif (LCD_HEIGHT==80) && (LCD_WIDTH==132)
73 /* Sansa C200 - 132x80, 8 cells @ 9x9 with 9 border lines */
75 /* Internal dimensions of a cell */
76 #define CELL_WIDTH 8
77 #define CELL_HEIGHT 8
78 #define SMALL_BOARD
80 #elif (LCD_HEIGHT==96) && (LCD_WIDTH==128) \
81 || (LCD_HEIGHT==110) && (LCD_WIDTH==138) \
82 || (LCD_HEIGHT==128) && (LCD_WIDTH==128)
83 /* iAudio M3 - 138x110, 8 cells @ 10x10 with 9 border lines */
84 /* iPod Mini - 138x110, 8 cells @ 10x10 with 9 border lines */
85 /* iriver H10 5-6GB - 128x128, 8 cells @ 10x10 with 9 border lines */
87 /* Internal dimensions of a cell */
88 #define CELL_WIDTH 10
89 #define CELL_HEIGHT 10
91 #elif ((LCD_HEIGHT==128) && (LCD_WIDTH==160)) \
92 || ((LCD_HEIGHT==132) && (LCD_WIDTH==176))
93 /* iAudio X5, Iriver H1x0, iPod G3, G4 - 160x128; */
94 /* iPod Nano - 176x132, 8 cells @ 12x12 with 9 border lines */
96 /* Internal dimensions of a cell */
97 #define CELL_WIDTH 12
98 #define CELL_HEIGHT 12
100 #elif ((LCD_HEIGHT==176) && (LCD_WIDTH==220)) || \
101 ((LCD_HEIGHT==220) && (LCD_WIDTH==176))
102 /* Iriver h300, iPod Color/Photo - 220x176, 8 cells @ 16x16 with 9 border lines */
104 /* Internal dimensions of a cell */
105 #define CELL_WIDTH 16
106 #define CELL_HEIGHT 16
108 #elif (LCD_HEIGHT>=240) && (LCD_WIDTH>=320)
109 /* iPod Video - 320x240, 8 cells @ 24x24 with 9 border lines */
111 /* Internal dimensions of a cell */
112 #define CELL_WIDTH 24
113 #define CELL_HEIGHT 24
115 #else
116 #error REVERSI: Unsupported LCD size
117 #endif
119 #else /* Vertical layout */
120 #define VERTICAL_LAYOUT
122 #if (LCD_HEIGHT>=320) && (LCD_WIDTH>=240)
123 /* Gigabeat - 240x320, 8 cells @ 24x24 with 9 border lines */
125 /* Internal dimensions of a cell */
126 #define CELL_WIDTH 24
127 #define CELL_HEIGHT 24
129 #elif (LCD_HEIGHT>=220) && (LCD_WIDTH>=176)
130 /* e200 - 176x220, 8 cells @ 12x12 with 9 border lines */
132 /* Internal dimensions of a cell */
133 #define CELL_WIDTH 18
134 #define CELL_HEIGHT 18
136 #else
137 #error REVERSI: Unsupported LCD size
138 #endif
140 #endif /* Layout */
143 /* Where the board begins */
144 #define XOFS 4
145 #define YOFS 4
147 /* Total width and height of the board without enclosing box */
148 #define BOARD_WIDTH (CELL_WIDTH*BOARD_SIZE + LINE_THCK*(BOARD_SIZE+1))
149 #define BOARD_HEIGHT (CELL_HEIGHT*BOARD_SIZE + LINE_THCK*(BOARD_SIZE+1))
151 /* Thickness of the white cells' lines */
152 #if (CELL_WIDTH >= 15) && (CELL_HEIGHT >= 15)
153 #define CELL_LINE_THICKNESS 2
154 #else
155 #define CELL_LINE_THICKNESS 1
156 #endif
158 /* Margins within a cell */
159 #if (CELL_WIDTH >= 10) && (CELL_HEIGHT >= 10)
160 #define STONE_MARGIN 2
161 #else
162 #define STONE_MARGIN 1
163 #endif
165 #define CURSOR_MARGIN (STONE_MARGIN + CELL_LINE_THICKNESS)
167 /* Upper left corner of a cell */
168 #define CELL_X(c) (XOFS + (c)*CELL_WIDTH + ((c)+1)*LINE_THCK)
169 #define CELL_Y(r) (YOFS + (r)*CELL_HEIGHT + ((r)+1)*LINE_THCK)
172 #ifdef VERTICAL_LAYOUT
173 #define LEGEND_X(lc) (CELL_X(lc))
174 #define LEGEND_Y(lr) (CELL_Y(BOARD_SIZE+(lr)) + CELL_HEIGHT/2)
175 #else
176 #define LEGEND_X(lc) (CELL_X(BOARD_SIZE+(lc)) + CELL_WIDTH/2)
177 #define LEGEND_Y(lr) (CELL_Y(lr))
178 #endif
181 /* Board state */
182 static reversi_board_t game;
184 /* --- Setting values --- */
186 /* Playing strategies used by white and black players */
187 const game_strategy_t *white_strategy;
188 const game_strategy_t *black_strategy;
190 /* Cursor position */
191 static int cur_row, cur_col;
193 /* Color for the next move (BLACK/WHITE) */
194 static int cur_player;
196 /* Active cursor wrapping mode */
197 static cursor_wrap_mode_t cursor_wrap_mode;
199 static bool quit_plugin;
200 static bool game_finished;
203 /* Initialises the state of the game (starts a new game) */
204 static void reversi_gui_init(void) {
205 reversi_init_game(&game);
206 game_finished = false;
207 cur_player = BLACK;
209 /* Place the cursor so that WHITE can make a move */
210 cur_row = 2;
211 cur_col = 3;
215 /* Draws the cursor in the specified cell. Cursor is drawn in the complement
216 * mode, i.e. drawing it twice will result in no changes on the screen.
218 static void reversi_gui_display_cursor(int row, int col) {
219 int old_mode, x, y;
220 old_mode = rb->lcd_get_drawmode();
221 x = CELL_X(col);
222 y = CELL_Y(row);
224 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
225 rb->lcd_drawline(x+CURSOR_MARGIN, y+CURSOR_MARGIN,
226 x+CELL_WIDTH-CURSOR_MARGIN-1, y+CELL_HEIGHT-CURSOR_MARGIN-1);
227 rb->lcd_drawline(x+CURSOR_MARGIN, y+CELL_HEIGHT-CURSOR_MARGIN-1,
228 x+CELL_WIDTH-CURSOR_MARGIN-1, y+CURSOR_MARGIN);
230 /* Draw the shadows */
231 rb->lcd_hline(x, x+CELL_WIDTH-1, YOFS-3);
232 rb->lcd_hline(x, x+CELL_WIDTH-1, YOFS+BOARD_HEIGHT+2);
233 rb->lcd_vline(XOFS-3, y, y+CELL_HEIGHT-1);
234 rb->lcd_vline(XOFS+BOARD_WIDTH+2, y, y+CELL_HEIGHT-1);
236 rb->lcd_set_drawmode(old_mode);
237 rb->lcd_update();
241 /* Draws the cell of the specified color (WHITE/BLACK) assuming that
242 * the upper left corner of the cell is at (x, y) */
243 static void reversi_gui_draw_cell(int x, int y, int color) {
244 int i;
245 if (color == WHITE) {
246 for (i = 0; i < CELL_LINE_THICKNESS; i++) {
247 rb->lcd_drawrect(x+STONE_MARGIN+i, y+STONE_MARGIN+i,
248 CELL_WIDTH-2*(STONE_MARGIN+i), CELL_HEIGHT-2*(STONE_MARGIN+i));
250 } else if (color == BLACK) {
251 rb->lcd_fillrect(x+STONE_MARGIN, y+STONE_MARGIN,
252 CELL_WIDTH-2*STONE_MARGIN, CELL_HEIGHT-2*STONE_MARGIN);
253 } else {
254 /* Cell is free -> nothing to do */
259 /* Draws the complete screen */
260 static void reversi_gui_display_board(void) {
261 int x, y, r, c, x_width, x_height;
262 char buf[8];
264 /* Clear the display buffer */
265 rb->lcd_clear_display();
266 rb->lcd_set_drawmode(DRMODE_FG);
268 /* Thicker board box */
269 rb->lcd_drawrect(XOFS-1, YOFS-1, BOARD_WIDTH+2, BOARD_HEIGHT+2);
271 /* Draw the gridlines */
272 for (r=0, x=XOFS, y=YOFS; r<=BOARD_SIZE;
273 r++, x+=CELL_WIDTH+LINE_THCK, y+=CELL_HEIGHT+LINE_THCK) {
274 rb->lcd_hline(XOFS, XOFS+BOARD_WIDTH-1, y);
275 rb->lcd_vline(x, YOFS, YOFS+BOARD_HEIGHT-1);
278 /* Draw the stones. This is not the most efficient way but more readable */
279 for (r=0; r<BOARD_SIZE; r++) {
280 y = CELL_Y(r);
281 for (c=0; c<BOARD_SIZE; c++) {
282 x = CELL_X(c);
283 reversi_gui_draw_cell(x, y, game.board[r][c]);
287 /* Draw the cursor */
288 reversi_gui_display_cursor(cur_row, cur_col);
290 /* Draw the current score */
291 reversi_count_occupied_cells(&game, &r, &c);
292 rb->lcd_getstringsize("x", &x_width, &x_height);
294 x = LEGEND_X(0);
295 y = LEGEND_Y(0);
296 reversi_gui_draw_cell(x, y, BLACK);
297 rb->snprintf(buf, sizeof(buf), "%d", c);
298 y += (CELL_HEIGHT-x_height) / 2;
299 rb->lcd_putsxy(x + CELL_WIDTH + CELL_WIDTH/2, y, buf);
301 y = LEGEND_Y(1);
302 reversi_gui_draw_cell(x, y, WHITE);
303 rb->snprintf(buf, sizeof(buf), "%d", r);
304 y += (CELL_HEIGHT-x_height) / 2;
305 rb->lcd_putsxy(x + CELL_WIDTH + CELL_WIDTH/2, y, buf);
307 /* Draw the box around the current player */
308 r = (cur_player == BLACK ? 0 : 1);
309 y = LEGEND_Y(r);
310 rb->lcd_drawrect(x-1, y-1, CELL_WIDTH+2, CELL_HEIGHT+2);
312 /* Update the screen */
313 rb->lcd_update();
318 * Menu related stuff
321 /* Menu entries and the corresponding values for cursor wrap mode */
322 #define MENU_TEXT_WRAP_MODE "Cursor wrap mode"
323 static const struct opt_items cursor_wrap_mode_settings[] = {
324 { "Flat board", -1 },
325 { "Sphere", -1 },
326 { "Torus", -1 },
328 static const cursor_wrap_mode_t cursor_wrap_mode_values[3] = {
329 WRAP_FLAT, WRAP_SPHERE, WRAP_TORUS };
332 /* Menu entries and the corresponding values for available strategies */
333 #define MENU_TEXT_STRAT_WHITE "Strategy for white"
334 #define MENU_TEXT_STRAT_BLACK "Strategy for black"
336 static struct opt_items strategy_settings[] = {
337 { "Human", -1 },
338 { "Naive robot", -1 },
339 { "Simple robot", -1 },
340 //{ "AB robot", -1 },
342 static const game_strategy_t * const strategy_values[] = {
343 &strategy_human, &strategy_naive, &strategy_simple, /*&strategy_ab*/ };
346 /* Sets the strategy for the specified player. 'player' is the
347 pointer to the player to set the strategy for (actually,
348 either white_strategy or black_strategy). propmpt is the
349 text to show as the prompt in the menu */
350 static bool reversi_gui_choose_strategy(
351 const game_strategy_t **player, const char *prompt) {
352 int index = 0, i;
353 int num_items = sizeof(strategy_settings)/sizeof(strategy_settings[0]);
354 bool result;
356 for (i = 0; i < num_items; i++) {
357 if ((*player) == strategy_values[i]) {
358 index = i;
359 break;
362 result = rb->set_option(prompt, &index, INT, strategy_settings, num_items, NULL);
363 (*player) = strategy_values[index];
365 if((*player)->init_func)
366 (*player)->init_func(&game);
368 return result;
372 /* Returns true iff USB ws connected while in the menu */
373 static bool reversi_gui_menu(void) {
374 int m, index, num_items, i;
375 int result;
377 static const struct menu_item items[] = {
378 { "Start new game", NULL },
379 { "Pass the move", NULL },
380 { MENU_TEXT_STRAT_BLACK, NULL },
381 { MENU_TEXT_STRAT_WHITE, NULL },
382 { MENU_TEXT_WRAP_MODE, NULL },
383 { "Quit", NULL },
386 m = menu_init(rb, items, sizeof(items) / sizeof(*items),
387 NULL, NULL, NULL, NULL);
389 result = menu_show(m);
391 switch (result) {
392 case 0: /* Start a new game */
393 reversi_gui_init();
394 break;
396 case 1: /* Pass the move to the partner */
397 cur_player = reversi_flipped_color(cur_player);
398 break;
400 case 2: /* Strategy for black */
401 reversi_gui_choose_strategy(&black_strategy, MENU_TEXT_STRAT_BLACK);
402 break;
404 case 3: /* Strategy for white */
405 reversi_gui_choose_strategy(&white_strategy, MENU_TEXT_STRAT_WHITE);
406 break;
408 case 4: /* Cursor wrap mode */
409 num_items = sizeof(cursor_wrap_mode_values)/sizeof(cursor_wrap_mode_values[0]);
410 index = 0;
411 for (i = 0; i < num_items; i++) {
412 if (cursor_wrap_mode == cursor_wrap_mode_values[i]) {
413 index = i;
414 break;
417 rb->set_option(MENU_TEXT_WRAP_MODE, &index, INT,
418 cursor_wrap_mode_settings, 3, NULL);
419 cursor_wrap_mode = cursor_wrap_mode_values[index];
420 break;
422 case 5: /* Quit */
423 quit_plugin = true;
424 break;
427 menu_exit(m);
429 return (result == MENU_ATTACHED_USB);
433 /* Calculates the new cursor position if the user wants to move it
434 * vertically as specified by delta. Current wrap mode is respected.
435 * The cursor is not actually moved.
437 * Returns true iff the cursor would be really moved. In any case, the
438 * new cursor position is stored in (new_row, new_col).
440 static bool reversi_gui_cursor_pos_vmove(int row_delta, int *new_row, int *new_col) {
441 *new_row = cur_row + row_delta;
442 *new_col = cur_col;
444 if (*new_row < 0) {
445 switch (cursor_wrap_mode) {
446 case WRAP_FLAT:
447 *new_row = cur_row;
448 break;
449 case WRAP_SPHERE:
450 *new_row = BOARD_SIZE - 1;
451 break;
452 case WRAP_TORUS:
453 *new_row = BOARD_SIZE - 1;
454 (*new_col)--;
455 if (*new_col < 0) {
456 *new_col = BOARD_SIZE - 1;
458 break;
460 } else if (*new_row >= BOARD_SIZE) {
461 switch (cursor_wrap_mode) {
462 case WRAP_FLAT:
463 *new_row = cur_row;
464 break;
465 case WRAP_SPHERE:
466 *new_row = 0;
467 break;
468 case WRAP_TORUS:
469 *new_row = 0;
470 (*new_col)++;
471 if (*new_col >= BOARD_SIZE) {
472 *new_col = 0;
474 break;
478 return (cur_row != (*new_row)) || (cur_col != (*new_col));
482 /* Calculates the new cursor position if the user wants to move it
483 * horisontally as specified by delta. Current wrap mode is respected.
484 * The cursor is not actually moved.
486 * Returns true iff the cursor would be really moved. In any case, the
487 * new cursor position is stored in (new_row, new_col).
489 static bool reversi_gui_cursor_pos_hmove(int col_delta, int *new_row, int *new_col) {
490 *new_row = cur_row;
491 *new_col = cur_col + col_delta;
493 if (*new_col < 0) {
494 switch (cursor_wrap_mode) {
495 case WRAP_FLAT:
496 *new_col = cur_col;
497 break;
498 case WRAP_SPHERE:
499 *new_col = BOARD_SIZE - 1;
500 break;
501 case WRAP_TORUS:
502 *new_col = BOARD_SIZE - 1;
503 (*new_row)--;
504 if (*new_row < 0) {
505 *new_row = BOARD_SIZE - 1;
507 break;
509 } else if (*new_col >= BOARD_SIZE) {
510 switch (cursor_wrap_mode) {
511 case WRAP_FLAT:
512 *new_col = cur_col;
513 break;
514 case WRAP_SPHERE:
515 *new_col = 0;
516 break;
517 case WRAP_TORUS:
518 *new_col = 0;
519 (*new_row)++;
520 if (*new_row >= BOARD_SIZE) {
521 *new_row = 0;
523 break;
527 return (cur_row != (*new_row)) || (cur_col != (*new_col));
531 /* Actually moves the cursor to the new position and updates the screen */
532 static void reversi_gui_move_cursor(int new_row, int new_col) {
533 int old_row, old_col;
535 old_row = cur_row;
536 old_col = cur_col;
538 cur_row = new_row;
539 cur_col = new_col;
541 /* Only update the changed cells since there are no global changes */
542 reversi_gui_display_cursor(old_row, old_col);
543 reversi_gui_display_cursor(new_row, new_col);
547 /* plugin entry point */
548 enum plugin_status plugin_start(const struct plugin_api *api, const void *parameter) {
549 bool exit, draw_screen;
550 int button;
551 int lastbutton = BUTTON_NONE;
552 int row, col;
553 int w_cnt, b_cnt;
554 char msg_buf[30];
556 /* plugin init */
557 rb = api;
558 /* end of plugin init */
560 #if LCD_DEPTH > 1
561 rb->lcd_set_backdrop(NULL);
562 rb->lcd_set_foreground(LCD_BLACK);
563 rb->lcd_set_background(LCD_WHITE);
564 #endif
566 /* Avoid compiler warnings */
567 (void)parameter;
569 game.rb = rb;
570 rb->srand(*rb->current_tick); /* Some AIs use rand() */
571 white_strategy = &strategy_human;
572 black_strategy = &strategy_human;
574 reversi_gui_init();
575 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
576 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
577 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
578 cursor_wrap_mode = WRAP_TORUS;
579 #else
580 cursor_wrap_mode = WRAP_FLAT;
581 #endif
582 /* The main game loop */
583 exit = false;
584 quit_plugin = false;
585 draw_screen = true;
586 while (!exit && !quit_plugin) {
587 const game_strategy_t *cur_strategy = NULL;
588 if (draw_screen) {
589 reversi_gui_display_board();
590 draw_screen = false;
592 switch(cur_player) {
593 case BLACK:
594 cur_strategy = black_strategy;
595 break;
596 case WHITE:
597 cur_strategy = white_strategy;
598 break;
601 if(cur_strategy->is_robot && !game_finished) {
602 move_t m = cur_strategy->move_func(&game, cur_player);
603 reversi_make_move(&game, MOVE_ROW(m), MOVE_COL(m), cur_player);
604 cur_player = reversi_flipped_color(cur_player);
605 draw_screen = true;
606 /* TODO: Add some delay to prevent it from being too fast ? */
607 /* TODO: Don't duplicate end of game check */
608 if (reversi_game_is_finished(&game, cur_player)) {
609 reversi_count_occupied_cells(&game, &w_cnt, &b_cnt);
610 rb->snprintf(msg_buf, sizeof(msg_buf),
611 "Game over. %s have won.",
612 (w_cnt>b_cnt?"WHITE":"BLACK"));
613 rb->splash(HZ*2, msg_buf);
614 draw_screen = true; /* Must update screen after splash */
615 game_finished = true;
617 continue;
620 button = rb->button_get(true);
622 switch (button) {
623 #ifdef REVERSI_BUTTON_QUIT
624 /* Exit game */
625 case REVERSI_BUTTON_QUIT:
626 exit = true;
627 break;
628 #endif
630 #ifdef REVERSI_BUTTON_ALT_MAKE_MOVE
631 case REVERSI_BUTTON_ALT_MAKE_MOVE:
632 #endif
633 case REVERSI_BUTTON_MAKE_MOVE:
634 #ifdef REVERSI_BUTTON_MAKE_MOVE_PRE
635 if ((button == REVERSI_BUTTON_MAKE_MOVE)
636 && (lastbutton != REVERSI_BUTTON_MAKE_MOVE_PRE))
637 break;
638 #endif
639 if (game_finished) break;
640 if (reversi_make_move(&game, cur_row, cur_col, cur_player) > 0) {
641 /* Move was made. Global changes on the board are possible */
642 draw_screen = true; /* Redraw the screen next time */
643 cur_player = reversi_flipped_color(cur_player);
644 if (reversi_game_is_finished(&game, cur_player)) {
645 reversi_count_occupied_cells(&game, &w_cnt, &b_cnt);
646 rb->snprintf(msg_buf, sizeof(msg_buf),
647 "Game over. %s have won.",
648 (w_cnt>b_cnt?"WHITE":"BLACK"));
649 rb->splash(HZ*2, msg_buf);
650 draw_screen = true; /* Must update screen after splash */
651 game_finished = true;
653 } else {
654 /* An attempt to make an invalid move */
655 rb->splash(HZ/2, "Illegal move!");
656 draw_screen = true;
657 /* Ignore any button presses during the splash */
658 rb->button_clear_queue();
660 break;
661 /* Move cursor left */
662 #ifdef REVERSI_BUTTON_ALT_LEFT
663 case REVERSI_BUTTON_ALT_LEFT:
664 case (REVERSI_BUTTON_ALT_LEFT | BUTTON_REPEAT):
665 #endif
666 case REVERSI_BUTTON_LEFT:
667 case (REVERSI_BUTTON_LEFT | BUTTON_REPEAT):
668 if (reversi_gui_cursor_pos_hmove(-1, &row, &col)) {
669 reversi_gui_move_cursor(row, col);
671 break;
673 /* Move cursor right */
674 #ifdef REVERSI_BUTTON_ALT_RIGHT
675 case REVERSI_BUTTON_ALT_RIGHT:
676 case (REVERSI_BUTTON_ALT_RIGHT | BUTTON_REPEAT):
677 #endif
678 case REVERSI_BUTTON_RIGHT:
679 case (REVERSI_BUTTON_RIGHT | BUTTON_REPEAT):
680 if (reversi_gui_cursor_pos_hmove(1, &row, &col)) {
681 reversi_gui_move_cursor(row, col);
683 break;
685 /* Move cursor up */
686 case REVERSI_BUTTON_UP:
687 case (REVERSI_BUTTON_UP | BUTTON_REPEAT):
688 if (reversi_gui_cursor_pos_vmove(-1, &row, &col)) {
689 reversi_gui_move_cursor(row, col);
691 break;
693 /* Move cursor down */
694 case REVERSI_BUTTON_DOWN:
695 case (REVERSI_BUTTON_DOWN | BUTTON_REPEAT):
696 if (reversi_gui_cursor_pos_vmove(1, &row, &col)) {
697 reversi_gui_move_cursor(row, col);
699 break;
701 case REVERSI_BUTTON_MENU:
702 #ifdef REVERSI_BUTTON_MENU_PRE
703 if (lastbutton != REVERSI_BUTTON_MENU_PRE) {
704 break;
706 #endif
707 if (reversi_gui_menu()) {
708 return PLUGIN_USB_CONNECTED;
710 draw_screen = true;
711 break;
713 default:
714 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
715 /* Quit if USB has been connected */
716 return PLUGIN_USB_CONNECTED;
718 break;
720 if (button != BUTTON_NONE) {
721 lastbutton = button;
725 return PLUGIN_OK;
728 #endif