From 2ca12eb770bed58d6945becececb8e023e13d5bd Mon Sep 17 00:00:00 2001 From: Derek Jamison Date: Thu, 23 Mar 2023 08:33:00 -0400 Subject: [PATCH] Code cleanup --- .../rock_paper_scissors/rock_paper_scissors.c | 20 +++++++++----- .../rock_paper_scissors/rock_paper_scissors.h | 27 +++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/subghz/plugins/rock_paper_scissors/rock_paper_scissors.c b/subghz/plugins/rock_paper_scissors/rock_paper_scissors.c index a67e5ab..357fdf2 100644 --- a/subghz/plugins/rock_paper_scissors/rock_paper_scissors.c +++ b/subghz/plugins/rock_paper_scissors/rock_paper_scissors.c @@ -691,6 +691,9 @@ static void rps_render_past_games(Canvas* canvas, void* ctx) { } } +// Render UI when we are choosing a social identity to share. +// @param canvas rendering surface of the Flipper Zero. +// @param ctx pointer to a GameContext. static void rps_render_choose_social(Canvas* canvas, void* ctx) { GameContext* game_context = ctx; UNUSED(game_context); @@ -722,12 +725,9 @@ static void rps_render_choose_social(Canvas* canvas, void* ctx) { } } -char keyboard[4][14] = { - {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '.', '_', 8}, - {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '!', '$', '*', '&'}, - {'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '=', '+', ':', '(', ')'}, - {'Z', 'X', 'C', 'V', 'B', 'N', 'M', ' ', '@', '"', '#', '/', '\'', 13}}; - +// Return the character at the current keyboard cursor position. +// @param game_context pointer to a GameContext. +// @param long_press true if the key was held down for a long time. static char get_char(GameContext* game_context, bool long_press) { int c_r = game_context->data->keyboard_row; int c_c = game_context->data->keyboard_col; @@ -740,6 +740,11 @@ static char get_char(GameContext* game_context, bool long_press) { return ch; } +// Render an arrow, for enter and backspace. +// @param canvas rendering surface of the Flipper Zero. +// @param x x coordinate of the arrow. +// @param y y coordinate of the arrow. +// @param tail true for enter, false for backspace. static void draw_arrow(Canvas* canvas, int x, int y, bool tail) { canvas_draw_line(canvas, x, y + 2, x + 4, y + 2); canvas_draw_line(canvas, x, y + 2, x + 2, y); @@ -749,6 +754,9 @@ static void draw_arrow(Canvas* canvas, int x, int y, bool tail) { } } +// Render UI when we are inputting text. +// @param canvas rendering surface of the Flipper Zero. +// @param ctx pointer to a GameContext. static void rps_render_input_text(Canvas* canvas, void* ctx) { GameContext* game_context = ctx; UNUSED(game_context); diff --git a/subghz/plugins/rock_paper_scissors/rock_paper_scissors.h b/subghz/plugins/rock_paper_scissors/rock_paper_scissors.h index 356c6c5..713acfe 100644 --- a/subghz/plugins/rock_paper_scissors/rock_paper_scissors.h +++ b/subghz/plugins/rock_paper_scissors/rock_paper_scissors.h @@ -276,6 +276,12 @@ typedef struct { SubGhzTxRxWorker* subghz_txrx; } GameContext; +char keyboard[4][14] = { + {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '.', '_', 8}, + {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '!', '$', '*', '&'}, + {'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '=', '+', ':', '(', ')'}, + {'Z', 'X', 'C', 'V', 'B', 'N', 'M', ' ', '@', '"', '#', '/', '\'', 13}}; + // Checks if game state is winner. // @param state GameState to check. // @returns true if game state is a winner. @@ -365,6 +371,27 @@ static void rps_render_error(Canvas* canvas, void* ctx); // @param ctx pointer to a GameContext. static void rps_render_main_menu(Canvas* canvas, void* ctx); +// Render UI when we are choosing a social identity to share. +// @param canvas rendering surface of the Flipper Zero. +// @param ctx pointer to a GameContext. +static void rps_render_choose_social(Canvas* canvas, void* ctx); +// Return the character at the current keyboard cursor position. +// @param game_context pointer to a GameContext. +// @param long_press true if the key was held down for a long time. +static char get_char(GameContext* game_context, bool long_press); + +// Render an arrow, for enter and backspace. +// @param canvas rendering surface of the Flipper Zero. +// @param x x coordinate of the arrow. +// @param y y coordinate of the arrow. +// @param tail true for enter, false for backspace. +static void draw_arrow(Canvas* canvas, int x, int y, bool tail); + +// Render UI when we are inputting text. +// @param canvas rendering surface of the Flipper Zero. +// @param ctx pointer to a GameContext. +static void rps_render_input_text(Canvas* canvas, void* ctx); + // We register this callback to get invoked whenever we need to render the screen. // We render the UI on this callback thread. // @param canvas rendering surface of the Flipper Zero.