From 88941104234f9c479066767a8269a0acd53c93cd Mon Sep 17 00:00:00 2001 From: DiSlord Date: Fri, 3 Jul 2020 22:03:54 +0300 Subject: [PATCH] Full screen keyboard Custom buttons draw support --- nanovna.h | 1 - ui.c | 127 +++++++++++++++++++++++++++--------------------------- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/nanovna.h b/nanovna.h index 5e07ce1..b3edc98 100644 --- a/nanovna.h +++ b/nanovna.h @@ -102,7 +102,6 @@ enum stimulus_type { ST_START=0, ST_STOP, ST_CENTER, ST_SPAN, ST_CW }; -int shell_printf(const char *fmt, ...); void set_sweep_frequency(int type, uint32_t frequency); uint32_t get_sweep_frequency(int type); diff --git a/ui.c b/ui.c index 64f7aee..deb7113 100644 --- a/ui.c +++ b/ui.c @@ -1283,15 +1283,24 @@ menu_invoke(int item) #define MENU_BUTTON_MAX 8 // Menu buttons size #define MENU_BUTTON_WIDTH 60 -#define MENU_BUTTON_HEIGHT 30 +#define MENU_BUTTON_HEIGHT 29 +#define MENU_BUTTON_BORDER 1 // Height of numerical input field (at bottom) -#define NUM_INPUT_HEIGHT 30 +#define NUM_INPUT_HEIGHT 32 +#if 1 +#define KP_WIDTH ((LCD_WIDTH) / 4) // numeric keypad button width +#define KP_HEIGHT ((LCD_HEIGHT - NUM_INPUT_HEIGHT) / 4) // numeric keypad button height +// Key x, y position (0 - 15) on screen +#define KP_GET_X(posx) ((posx) * KP_WIDTH) // numeric keypad left +#define KP_GET_Y(posy) ((posy) * KP_HEIGHT) // numeric keypad top +#else #define KP_WIDTH 48 #define KP_HEIGHT 48 // Key x, y position (0 - 15) on screen #define KP_GET_X(posx) ((posx)*KP_WIDTH + (LCD_WIDTH-64-KP_WIDTH*4)) #define KP_GET_Y(posy) ((posy)*KP_HEIGHT + 12 ) +#endif // Key names #define KP_0 0 @@ -1399,6 +1408,18 @@ static const char * const keypad_mode_label[] = { "START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY" }; +static void +draw_button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t border_colour, uint16_t bg_colour) +{ +// background + const uint16_t bw = MENU_BUTTON_BORDER; + ili9341_fill(x + bw, y + bw, w - (bw * 2), h - (bw * 2), bg_colour); + ili9341_fill(x, y, w, bw, border_colour); // top + ili9341_fill(x + w - bw, y, bw, h, border_colour); // right + ili9341_fill(x, y, bw, h, border_colour); // left + ili9341_fill(x, y + h - bw, w, bw, border_colour); // bottom +} + static void draw_keypad(void) { @@ -1411,7 +1432,7 @@ draw_keypad(void) ili9341_set_background(bg); int x = KP_GET_X(keypads[i].x); int y = KP_GET_Y(keypads[i].y); - ili9341_fill(x+2, y+2, KP_WIDTH-4, KP_HEIGHT-4, bg); + draw_button(x, y, KP_WIDTH, KP_HEIGHT, DEFAULT_BG_COLOR, bg); ili9341_drawfont(keypads[i].c, x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2, y + (KP_HEIGHT - NUM_FONT_GET_HEIGHT) / 2); @@ -1484,111 +1505,91 @@ static void menu_item_modify_attribute(const menuitem_t *menu, int item, uint16_t *fg, uint16_t *bg) { + bool swap = false; if (menu == menu_trace && item < TRACES_MAX) { - if (trace[item].enabled) + if (trace[item].enabled){ *bg = config.trace_color[item]; + if (item == selection) *fg = ~config.trace_color[item]; + } } else if (menu == menu_marker_sel) { - if (item < 4) { - if (markers[item].enabled) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (item == 5) { - if (uistat.marker_delta) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } + if ((item < 4 && markers[item].enabled) || + (item == 5 && uistat.marker_delta)) + swap = true; + else if (item == 5 && uistat.marker_delta) + swap = true; } else if (menu == menu_marker_search) { - if (item == 4 && uistat.marker_tracking) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + if (item == 4 && uistat.marker_tracking) + swap = true; } else if (menu == menu_marker_smith) { - - if (marker_smith_format == item) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + if (marker_smith_format == item) + swap = true; } else if (menu == menu_calop) { if ((item == 0 && (cal_status & CALSTAT_OPEN)) || (item == 1 && (cal_status & CALSTAT_SHORT)) || (item == 2 && (cal_status & CALSTAT_LOAD)) || (item == 3 && (cal_status & CALSTAT_ISOLN)) - || (item == 4 && (cal_status & CALSTAT_THRU))) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + || (item == 4 && (cal_status & CALSTAT_THRU))) + swap = true; } else if (menu == menu_stimulus) { - if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) + swap = true; } else if (menu == menu_cal) { - if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY)) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY)) + swap = true; } else if (menu == menu_bandwidth) { - if (menu_bandwidth[item].data == config.bandwidth) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + if (menu_bandwidth[item].data == config.bandwidth) + swap = true; } else if (menu == menu_sweep_points) { - if (menu_sweep_points[item].data == sweep_points) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + if (menu_sweep_points[item].data == sweep_points) + swap = true; } else if (menu == menu_transform) { if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) || (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE) || (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP) || (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS) - ) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + ) swap = true; } else if (menu == menu_transform_window) { if ((item == 0 && (domain_mode & TD_WINDOW) == TD_WINDOW_MINIMUM) || (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL) || (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM) - ) { - *bg = DEFAULT_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } + ) swap = true; } + if (swap) {uint16_t t = *bg;*bg=*fg;*fg = t;} } static void draw_menu_buttons(const menuitem_t *menu) { - int i = 0; - for (i = 0; i < MENU_BUTTON_MAX; i++) { + int i = 0, y = 0; + for (i = 0; i < MENU_BUTTON_MAX; i++, y+=MENU_BUTTON_HEIGHT) { const char *l1, *l2; if (menu[i].type == MT_NONE) break; if (menu[i].type == MT_BLANK) continue; - int y = MENU_BUTTON_HEIGHT*i; + uint16_t bg = config.menu_normal_color; uint16_t fg = DEFAULT_MENU_TEXT_COLOR; // focus only in MENU mode but not in KEYPAD mode if (ui_mode == UI_MENU && i == selection) bg = config.menu_active_color; - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); - + menu_item_modify_attribute(menu, i, &fg, &bg); ili9341_set_foreground(fg); ili9341_set_background(bg); + + draw_button(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT, fg, bg); + if (menu_is_multiline(menu[i].label, &l1, &l2)) { - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH+3, y+MENU_BUTTON_HEIGHT/2-FONT_GET_HEIGHT-3, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(l1, LCD_WIDTH-MENU_BUTTON_WIDTH+5, y+MENU_BUTTON_HEIGHT/2-FONT_GET_HEIGHT-1); - ili9341_drawstring(l2, LCD_WIDTH-MENU_BUTTON_WIDTH+5, y+MENU_BUTTON_HEIGHT/2); + ili9341_drawstring(l1, LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER+4, y+MENU_BUTTON_HEIGHT/2-FONT_GET_HEIGHT-1); + ili9341_drawstring(l2, LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER+4, y+MENU_BUTTON_HEIGHT/2); } else { - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH+3, y+(MENU_BUTTON_HEIGHT-FONT_GET_HEIGHT-6)/2, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(menu[i].label, LCD_WIDTH-MENU_BUTTON_WIDTH+5, y+(MENU_BUTTON_HEIGHT-FONT_GET_HEIGHT-6)/2+2); + ili9341_drawstring(menu[i].label, LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER+4, y+(MENU_BUTTON_HEIGHT-FONT_GET_HEIGHT-6)/2+2); } } + for (; i < MENU_BUTTON_MAX; i++, y+=MENU_BUTTON_HEIGHT) { + ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT, DEFAULT_BG_COLOR); + } } static void @@ -1632,7 +1633,7 @@ draw_menu(void) static void erase_menu_buttons(void) { - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, DEFAULT_BG_COLOR); +// ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, DEFAULT_BG_COLOR); } static void