From daeaba909d9d0719690c63db581541a96c44c9e6 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Wed, 23 Oct 2019 23:35:33 +0800 Subject: [PATCH] menu: fix display of gamepad. --- menu.cpp | 87 ++++++++++++++++++++++++++++++++++---------------------- osd.cpp | 9 ------ osd.h | 1 - 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/menu.cpp b/menu.cpp index 90f7e2f..c628eb2 100644 --- a/menu.cpp +++ b/menu.cpp @@ -820,6 +820,8 @@ void HandleUI(void) static uint32_t hdmask = 0; static pid_t ttypid = 0; static int has_fb_terminal = 0; + static unsigned long flash_timer = 0; + static int flash_state = 0; static char cp_MenuCancel; @@ -2128,6 +2130,8 @@ void HandleUI(void) OsdSetTitle("Define buttons", 0); menustate = MENU_JOYDIGMAP1; parentstate = MENU_JOYDIGMAP; + flash_timer = 0; + flash_state = 0; for (int i = 0; i < OsdGetSize(); i++) OsdWrite(i); if (is_menu_core()) { @@ -2217,44 +2221,59 @@ void HandleUI(void) OsdWrite(3, s, 0, 0); OsdWrite(4); - - if (!line_info) { - if(is_menu_core() && joy_bcount && get_map_button() < DPAD_BUTTON_NAMES) + + if(is_menu_core() && joy_bcount && get_map_button() >= SYS_BTN_RIGHT && get_map_button() <= SYS_BTN_START) + { + // draw an on-screen gamepad to help with central button mapping + if (!flash_timer || CheckTimer(flash_timer)) { - p = joy_bnames[get_map_button() - DPAD_NAMES]; - // draw an on-screen gamepad to help with central button mapping - OsdWrite(10, " \x86 L1\x88 \x86 R1\x88 "); - if (!strcmp(p, "L")) OsdWriteDelay(10, " \x86 \x1b \x88 \x86 R1\x88 "); - if (!strcmp(p, "R")) OsdWriteDelay(10, " \x86 L1\x88 \x86 \x1b \x88 "); - OsdWrite(11, " \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88"); - OsdWrite(12, " \x83 U X \x83"); - if (!strcmp(p, "UP")) OsdWriteDelay(12, " \x83 \x1b X \x83"); - if (!strcmp(p, "X (Backspace)"))OsdWriteDelay(12, " \x83 U \x1b \x83"); - OsdWrite(13, " \x83 L \x1b R Sel Start Y A \x83"); - if (!strcmp(p, "A (OK/Enter)")) OsdWriteDelay(13, " \x83 L \x1b R Sel Start Y \x1b \x83"); - if (!strcmp(p, "Y")) OsdWriteDelay(13, " \x83 L \x1b R Sel Start \x1b A \x83"); - if (!strcmp(p, "LEFT")) OsdWriteDelay(13, " \x83 \x1b \x1b R Sel Start \x1b A \x83"); - if (!strcmp(p, "RIGHT")) OsdWriteDelay(13, " \x83 L \x1b \x1b Sel Start \x1b A \x83"); - if (!strcmp(p, "Select")) OsdWriteDelay(13, " \x83 L \x1b R \x1b Start Y A \x83"); - if (!strcmp(p, "Start")) OsdWriteDelay(13, " \x83 L \x1b R Sel \x1b Y A \x83"); - OsdWrite(14, " \x83 D \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88 B \x83"); - if (!strcmp(p, "DOWN")) OsdWrite(14, " \x83 \x1b \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88 B \x83"); - if (!strcmp(p, "B (ESC/Back)")) OsdWrite(14, " \x83 D \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88 \x1b \x83"); - OsdWrite(15, " \x8b\x81\x81\x81\x81\x81\x81\x81\x8a \x8b\x81\x81\x81\x81\x81\x81\x81\x8a"); - } else { - if(is_menu_core()){ - //clear all gamepad gfx - OsdWrite(10); - OsdWrite(11); - OsdWrite(12); - OsdWrite(13); - OsdWrite(14); - OsdWrite(15); - } else { - OsdWrite(12); + flash_timer = GetTimer(100); + if (flash_state) + { + switch (get_map_button()) + { + case SYS_BTN_L: OsdWrite(10, " \x86 \x88 \x86 R \x88 "); break; + case SYS_BTN_R: OsdWrite(10, " \x86 L \x88 \x86 \x88 "); break; + case SYS_BTN_UP: OsdWrite(12, " \x83 X \x83"); break; + case SYS_BTN_X: OsdWrite(12, " \x83 U \x83"); break; + case SYS_BTN_A: OsdWrite(13, " \x83 L \x1b R Sel Start Y \x83"); break; + case SYS_BTN_Y: OsdWrite(13, " \x83 L \x1b R Sel Start A \x83"); break; + case SYS_BTN_LEFT: OsdWrite(13, " \x83 \x1b R Sel Start Y A \x83"); break; + case SYS_BTN_RIGHT: OsdWrite(13, " \x83 L \x1b Sel Start Y A \x83"); break; + case SYS_BTN_SELECT: OsdWrite(13, " \x83 L \x1b R Start Y A \x83"); break; + case SYS_BTN_START: OsdWrite(13, " \x83 L \x1b R Sel Y A \x83"); break; + case SYS_BTN_DOWN: OsdWrite(14, " \x83 \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88 B \x83"); break; + case SYS_BTN_B: OsdWrite(14, " \x83 D \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88 \x83"); break; + } } + else + { + OsdWrite(10, " \x86 L \x88 \x86 R \x88 "); + OsdWrite(11, " \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88"); + OsdWrite(12, " \x83 U X \x83"); + OsdWrite(13, " \x83 L \x1b R Sel Start Y A \x83"); + OsdWrite(14, " \x83 D \x86\x81\x81\x81\x81\x81\x81\x81\x81\x81\x88 B \x83"); + OsdWrite(15, " \x8b\x81\x81\x81\x81\x81\x81\x81\x8a \x8b\x81\x81\x81\x81\x81\x81\x81\x8a"); + } + flash_state = !flash_state; } } + else + { + if(flash_timer) + { + //clear all gamepad gfx + OsdWrite(10); + OsdWrite(11); + OsdWrite(12); + OsdWrite(13); + OsdWrite(14); + OsdWrite(15); + flash_timer = 0; + } + + if (!line_info) OsdWrite(12); + } if (get_map_vid() || get_map_pid()) { diff --git a/osd.cpp b/osd.cpp index 7619d5a..8dcc90b 100644 --- a/osd.cpp +++ b/osd.cpp @@ -205,15 +205,6 @@ void OsdWrite(unsigned char n, const char *s, unsigned char invert, unsigned cha OsdWriteOffset(n, s, invert, stipple, 0, 0, usebg, maxinv); } -void OsdWriteDelay(unsigned char n, const char *s, unsigned char invert, unsigned char stipple, char usebg, int maxinv) -{ - if (s && s[0] && CheckTimer(scroll_timer)) // scroll if long name and timer delay elapsed - { - OsdWrite(n, s, invert, stipple, usebg, maxinv); - scroll_timer = GetTimer(SCROLL_DELAY2); // reset scroll timer to repeat delay - } -} - // write a null-terminated string to the OSD buffer starting at line void OsdWriteOffset(unsigned char n, const char *s, unsigned char invert, unsigned char stipple, char offset, char leftchar, char usebg, int maxinv) { diff --git a/osd.h b/osd.h index 90fccd5..6c35a69 100644 --- a/osd.h +++ b/osd.h @@ -24,7 +24,6 @@ void OsdSetTitle(const char *s, int arrow = 0); // arrow > 0 = display right arr void OsdSetArrow(int arrow); void OsdWrite(unsigned char n, const char *s="", unsigned char inver=0, unsigned char stipple=0, char usebg = 0, int maxinv = 32); void OsdWriteOffset(unsigned char n, const char *s, unsigned char inver, unsigned char stipple, char offset, char leftchar, char usebg = 0, int maxinv = 32); // Used for scrolling "Exit" text downwards... -void OsdWriteDelay(unsigned char n, const char *s="", unsigned char inver=0, unsigned char stipple=0, char usebg = 0, int maxinv = 32); //same as OsdWrite but with a certain delay. Used for "blinking" text lines void OsdClear(void); void OsdEnable(unsigned char mode); void InfoEnable(int x, int y, int width, int height);