From 6f0de32ba8a49ad8ba4f479c522cdbb5d54a8da2 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 20 Nov 2015 20:19:38 +0100 Subject: [PATCH] [Horus] Menu CurveOne improved --- radio/src/gui/9X/gui.h | 2 +- radio/src/gui/9X/popups.cpp | 2 +- radio/src/gui/9X/view_text.cpp | 2 +- radio/src/gui/9X/widgets.cpp | 2 +- radio/src/gui/Horus/gui.h | 6 +- radio/src/gui/Horus/menu_model_curves.cpp | 72 +++++++++++++---------- radio/src/gui/Horus/menu_model_select.cpp | 2 +- radio/src/gui/Horus/popups.cpp | 2 +- radio/src/gui/Horus/view_text.cpp | 2 +- radio/src/gui/Horus/widgets.cpp | 22 +++++-- radio/src/gui/Taranis/gui.h | 2 +- radio/src/gui/Taranis/navigation.cpp | 2 +- radio/src/gui/Taranis/popups.cpp | 2 +- radio/src/gui/Taranis/view_text.cpp | 2 +- radio/src/gui/Taranis/widgets.cpp | 2 +- 15 files changed, 73 insertions(+), 51 deletions(-) diff --git a/radio/src/gui/9X/gui.h b/radio/src/gui/9X/gui.h index 8f225bf2a..b6f1f0e07 100644 --- a/radio/src/gui/9X/gui.h +++ b/radio/src/gui/9X/gui.h @@ -46,7 +46,7 @@ void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr); #if !defined(CPUM64) #define DEFAULT_SCROLLBAR_X (LCD_W-1) - void drawScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible); + void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible); #endif #define SET_SCROLLBAR_X(x) diff --git a/radio/src/gui/9X/popups.cpp b/radio/src/gui/9X/popups.cpp index 83c541aa8..d12f14269 100644 --- a/radio/src/gui/9X/popups.cpp +++ b/radio/src/gui/9X/popups.cpp @@ -160,7 +160,7 @@ const char * displayMenu(uint8_t event) } if (s_menu_count > display_count) { - drawScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_LINES * (FH+1), s_menu_offset, s_menu_count, MENU_MAX_LINES); + drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_LINES * (FH+1), s_menu_offset, s_menu_count, MENU_MAX_LINES); } switch(event) { diff --git a/radio/src/gui/9X/view_text.cpp b/radio/src/gui/9X/view_text.cpp index 6000a9f82..8d601145a 100644 --- a/radio/src/gui/9X/view_text.cpp +++ b/radio/src/gui/9X/view_text.cpp @@ -151,7 +151,7 @@ void menuTextView(uint8_t event) lcd_invert_line(0); if (lines_count > LCD_LINES-1) { - drawScrollbar(LCD_W-1, FH, LCD_H-FH, s_pgOfs, lines_count, LCD_LINES-1); + drawVerticalScrollbar(LCD_W-1, FH, LCD_H-FH, s_pgOfs, lines_count, LCD_LINES-1); } } diff --git a/radio/src/gui/9X/widgets.cpp b/radio/src/gui/9X/widgets.cpp index a3abec3f6..f87cf6ad2 100644 --- a/radio/src/gui/9X/widgets.cpp +++ b/radio/src/gui/9X/widgets.cpp @@ -72,7 +72,7 @@ void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr) } #if !defined(CPUM64) -void drawScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible) +void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible) { lcdDrawVerticalLine(x, y, h, DOTTED); coord_t yofs = (h * offset) / count; diff --git a/radio/src/gui/Horus/gui.h b/radio/src/gui/Horus/gui.h index 956dfcf6b..cad76ac86 100644 --- a/radio/src/gui/Horus/gui.h +++ b/radio/src/gui/Horus/gui.h @@ -68,9 +68,13 @@ #define MENU_TITLE_NEXT_POS (lcdNextPos + 10) #define MENU_INIT_VPOS -1 +#define MENU_ICONS_SPACING 31 +#define SUBMENU_LINE_WIDTH 230 + void displaySplash(); void displayScreenIndex(uint8_t index, uint8_t count); -void drawScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible); +void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible); +void drawHorizontalScrollbar(coord_t x, coord_t y, coord_t w, uint16_t offset, uint16_t count, uint8_t visible); void drawHeader(int index); void drawFooter(); #define drawStatusLine(...) diff --git a/radio/src/gui/Horus/menu_model_curves.cpp b/radio/src/gui/Horus/menu_model_curves.cpp index 52b023729..eb74c10c1 100644 --- a/radio/src/gui/Horus/menu_model_curves.cpp +++ b/radio/src/gui/Horus/menu_model_curves.cpp @@ -135,24 +135,35 @@ void onCurveOneMenu(const char *result) } } +#define MODEL_CURVE_ONE_2ND_COLUMN 130 + +enum MenuModelCurveOneItems { + ITEM_CURVE_NAME, + ITEM_CURVE_TYPE, + ITEM_CURVE_POINTS, + ITEM_CURVE_SMOOTH, + ITEM_CURVE_COORDS1, + ITEM_CURVE_COORDS2, +}; + bool menuModelCurveOne(evt_t event) { static uint8_t pointsOfs = 0; CurveInfo & crv = g_model.curves[s_curveChan]; int8_t * points = curveAddress(s_curveChan); - SIMPLE_SUBMENU(STR_MENUCURVE, 4 + 5+crv.points + (crv.type==CURVE_TYPE_CUSTOM ? 5+crv.points-2 : 0), 0); + SUBMENU(STR_MENUCURVE, crv.type==CURVE_TYPE_CUSTOM ? 6 : 5, 0, { 0, 0, 0, 0, uint8_t(5+crv.points-1), uint8_t(5+crv.points-1) }); lcdDrawNumber(MENU_TITLE_NEXT_POS, MENU_TITLE_TOP+1, s_curveChan+1, LEFT|TEXT_COLOR); // Curve name lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP, STR_NAME); - editName(MENUS_MARGIN_LEFT+INDENT_WIDTH, MENU_CONTENT_TOP + FH, g_model.curveNames[s_curveChan], sizeof(g_model.curveNames[s_curveChan]), event, m_posVert==0); + editName(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP, g_model.curveNames[s_curveChan], sizeof(g_model.curveNames[s_curveChan]), event, m_posVert==ITEM_CURVE_NAME); // Curve type - LcdFlags attr = (m_posVert==1 ? (s_editMode>0 ? INVERS|BLINK : INVERS) : 0); - lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 2*FH, "Type"); - lcdDrawTextAtIndex(MENUS_MARGIN_LEFT+INDENT_WIDTH, MENU_CONTENT_TOP + 3*FH, STR_CURVE_TYPES, crv.type, attr); + LcdFlags attr = (m_posVert==ITEM_CURVE_TYPE ? (s_editMode>0 ? INVERS|BLINK : INVERS) : 0); + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + FH, "Type"); + lcdDrawTextAtIndex(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP + FH, STR_CURVE_TYPES, crv.type, attr); if (attr) { uint8_t newType = checkIncDecModelZero(event, crv.type, CURVE_TYPE_LAST); if (newType != crv.type) { @@ -168,9 +179,9 @@ bool menuModelCurveOne(evt_t event) } // Curve points count - attr = (m_posVert==2 ? (s_editMode>0 ? INVERS|BLINK : INVERS) : 0); - lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 4*FH, STR_COUNT); - lcdDrawNumber(MENUS_MARGIN_LEFT+INDENT_WIDTH, MENU_CONTENT_TOP + 5*FH, 5+crv.points, LEFT|attr, 0, NULL, STR_PTS); + attr = (m_posVert==ITEM_CURVE_POINTS ? (s_editMode>0 ? INVERS|BLINK : INVERS) : 0); + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 2*FH, STR_COUNT); + lcdDrawNumber(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP + 2*FH, 5+crv.points, LEFT|attr, 0, NULL, STR_PTS); if (attr) { int count = checkIncDecModel(event, crv.points, -3, 12); // 2pts - 17pts if (checkIncDec_Ret) { @@ -190,16 +201,16 @@ bool menuModelCurveOne(evt_t event) } // Curve smooth - lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 6*FH, STR_SMOOTH); - drawCheckBox(lcdNextPos + 10, MENU_CONTENT_TOP + 6*FH, crv.smooth, m_posVert==3 ? INVERS : 0); - if (m_posVert==3) crv.smooth = checkIncDecModel(event, crv.smooth, 0, 1); + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 3*FH, STR_SMOOTH); + drawCheckBox(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP + 3*FH, crv.smooth, m_posVert==ITEM_CURVE_SMOOTH ? INVERS : 0); + if (m_posVert==ITEM_CURVE_SMOOTH) crv.smooth = checkIncDecModel(event, crv.smooth, 0, 1); switch(event) { case EVT_ENTRY: pointsOfs = 0; break; case EVT_KEY_LONG(KEY_ENTER): - if (m_posVert > 1) { + if (m_posVert > ITEM_CURVE_POINTS) { killEvents(event); MENU_ADD_ITEM(STR_CURVE_PRESET); MENU_ADD_ITEM(STR_MIRROR); @@ -212,35 +223,30 @@ bool menuModelCurveOne(evt_t event) killEvents(event); } - if (m_posVert >= 0) { - DrawCurve(); - drawCurveHorizontalScale(); - if (m_posVert < 4) drawCurveVerticalScale(CURVE_CENTER_X-CURVE_SIDE_WIDTH-15); - } + DrawCurve(); + drawCurveHorizontalScale(); + if (m_posVert < ITEM_CURVE_COORDS1) drawCurveVerticalScale(CURVE_CENTER_X-CURVE_SIDE_WIDTH-15); - coord_t posY = MENU_CONTENT_TOP; + coord_t posX = 47; attr = (s_editMode > 0 ? INVERS|BLINK : INVERS); for (int i=0; i<5+crv.points; i++) { point_t point = getPoint(i); uint8_t selectionMode = 0; - if (crv.type==CURVE_TYPE_CUSTOM) { - if (m_posVert==4+2*i || (i==5+crv.points-1 && m_posVert==4+5+crv.points+5+crv.points-2-1)) + if (m_posHorz == i) { + if (m_posVert == ITEM_CURVE_COORDS2) selectionMode = 2; - else if (i>0 && m_posVert==3+2*i) + else if (m_posVert == ITEM_CURVE_COORDS1) selectionMode = 1; } - else if (m_posVert == 4+i) { - selectionMode = 2; - } int8_t x = -100 + 200*i/(5+crv.points-1); if (crv.type==CURVE_TYPE_CUSTOM && i>0 && i<5+crv.points-1) x = points[5+crv.points+i-1]; - if (i>=pointsOfs && i=pointsOfs && i 0) { @@ -281,15 +287,17 @@ bool menuModelCurveOne(evt_t event) } if (i < pointsOfs) pointsOfs = i; - else if (i > pointsOfs+NUM_BODY_LINES-1) - pointsOfs = i-NUM_BODY_LINES+1; + else if (i > pointsOfs+5-1) + pointsOfs = i-5+1; } else { drawCurvePoint(point.x-3, point.y-4, TEXT_COLOR); } } - drawScrollbar(240, DEFAULT_SCROLLBAR_Y, DEFAULT_SCROLLBAR_H+MENU_FOOTER_HEIGHT, pointsOfs, 5+crv.points, NUM_BODY_LINES+1); + lcdDrawHorizontalLine(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 6*FH - 1, SUBMENU_LINE_WIDTH, DOTTED, CURVE_AXIS_COLOR); + lcdDrawHorizontalLine(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 7*FH + 2, SUBMENU_LINE_WIDTH, DOTTED, CURVE_AXIS_COLOR); + drawHorizontalScrollbar(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 9*FH - 1, SUBMENU_LINE_WIDTH, pointsOfs, 5+crv.points, 5); return true; } diff --git a/radio/src/gui/Horus/menu_model_select.cpp b/radio/src/gui/Horus/menu_model_select.cpp index 1d6bb8a7c..eae453d5c 100644 --- a/radio/src/gui/Horus/menu_model_select.cpp +++ b/radio/src/gui/Horus/menu_model_select.cpp @@ -287,7 +287,7 @@ bool menuModelSelect(evt_t event) putEvent(EVT_REFRESH); } } - drawScrollbar(DEFAULT_SCROLLBAR_X, MENU_HEADER_HEIGHT+7, MENU_FOOTER_TOP-MENU_HEADER_HEIGHT-15, s_pgOfs, (index+1)/2, 3); + drawVerticalScrollbar(DEFAULT_SCROLLBAR_X, MENU_HEADER_HEIGHT+7, MENU_FOOTER_TOP-MENU_HEADER_HEIGHT-15, s_pgOfs, (index+1)/2, 3); } return true; diff --git a/radio/src/gui/Horus/popups.cpp b/radio/src/gui/Horus/popups.cpp index 04206e5c0..c431de24a 100644 --- a/radio/src/gui/Horus/popups.cpp +++ b/radio/src/gui/Horus/popups.cpp @@ -210,7 +210,7 @@ const char * displayMenu(evt_t event) } if (s_menu_count > display_count) { - drawScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_LINES * (FH+1), s_menu_offset, s_menu_count, MENU_MAX_LINES); + drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_LINES * (FH+1), s_menu_offset, s_menu_count, MENU_MAX_LINES); } return result; diff --git a/radio/src/gui/Horus/view_text.cpp b/radio/src/gui/Horus/view_text.cpp index db12a6d69..7ad559185 100644 --- a/radio/src/gui/Horus/view_text.cpp +++ b/radio/src/gui/Horus/view_text.cpp @@ -147,7 +147,7 @@ bool menuTextView(evt_t event) #endif lcd_putsCenter(MENU_FOOTER_TOP, title, HEADER_COLOR); - drawScrollbar(LCD_W-5, 30, MENU_FOOTER_TOP-34, s_pgOfs, lines_count, NUM_BODY_LINES); + drawVerticalScrollbar(LCD_W-5, 30, MENU_FOOTER_TOP-34, s_pgOfs, lines_count, NUM_BODY_LINES); return true; } diff --git a/radio/src/gui/Horus/widgets.cpp b/radio/src/gui/Horus/widgets.cpp index e1c8a64fc..7ca4d2aa6 100644 --- a/radio/src/gui/Horus/widgets.cpp +++ b/radio/src/gui/Horus/widgets.cpp @@ -104,7 +104,7 @@ void drawCheckBox(coord_t x, coord_t y, uint8_t value, LcdFlags attr) } } -void drawScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible) +void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible) { if (visible < count) { lcdDrawSolidVerticalLine(x, y, h, LINE_COLOR); @@ -116,6 +116,18 @@ void drawScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t co } } +void drawHorizontalScrollbar(coord_t x, coord_t y, coord_t w, uint16_t offset, uint16_t count, uint8_t visible) +{ + if (visible < count) { + lcdDrawSolidHorizontalLine(x, y, w, LINE_COLOR); + coord_t xofs = (w*offset + count/2) / count; + coord_t xhgt = (w*visible + count/2) / count; + if (xhgt + xofs > w) + xhgt = w - xofs; + lcdDrawSolidFilledRect(x+xofs, y-1, xhgt, 3, SCROLLBOX_COLOR); + } +} + void drawProgressBar(const char *label) { lcdDrawText(MENUS_MARGIN_LEFT, 4*FH, label); @@ -161,8 +173,6 @@ void drawScreenTemplate(const char * title) lcdDrawSolidFilledRect(0, MENU_FOOTER_TOP, LCD_W, MENU_FOOTER_HEIGHT, HEADER_BGCOLOR); } -#define MENU_ICONS_SPACING 31 - void drawSubmenuTemplate(const char * name, uint16_t scrollbar_X) { // clear the screen @@ -187,11 +197,11 @@ void drawSubmenuTemplate(const char * name, uint16_t scrollbar_X) if (name) { // must be done at the end so that we can write something at the right of the menu title lcdDrawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP+1, name, TEXT_COLOR); - lcdDrawSolidFilledRect(MENUS_MARGIN_LEFT-4, MENU_TITLE_TOP+19, 220, 2, TITLE_BGCOLOR); + lcdDrawSolidFilledRect(MENUS_MARGIN_LEFT-4, MENU_TITLE_TOP+20, SUBMENU_LINE_WIDTH, 2, TITLE_BGCOLOR); } if (scrollbar_X && linesCount > NUM_BODY_LINES+1) { - drawScrollbar(scrollbar_X, DEFAULT_SCROLLBAR_Y, DEFAULT_SCROLLBAR_H+MENU_FOOTER_HEIGHT, s_pgOfs, linesCount, NUM_BODY_LINES+1); + drawVerticalScrollbar(scrollbar_X, DEFAULT_SCROLLBAR_Y, DEFAULT_SCROLLBAR_H+MENU_FOOTER_HEIGHT, s_pgOfs, linesCount, NUM_BODY_LINES+1); } } @@ -235,7 +245,7 @@ void drawMenuTemplate(const char * name, uint16_t scrollbar_X) } if (scrollbar_X && linesCount > NUM_BODY_LINES) { - drawScrollbar(scrollbar_X, DEFAULT_SCROLLBAR_Y, DEFAULT_SCROLLBAR_H, s_pgOfs, linesCount, NUM_BODY_LINES); + drawVerticalScrollbar(scrollbar_X, DEFAULT_SCROLLBAR_Y, DEFAULT_SCROLLBAR_H, s_pgOfs, linesCount, NUM_BODY_LINES); } } diff --git a/radio/src/gui/Taranis/gui.h b/radio/src/gui/Taranis/gui.h index c11c1662a..07da5cf27 100644 --- a/radio/src/gui/Taranis/gui.h +++ b/radio/src/gui/Taranis/gui.h @@ -50,7 +50,7 @@ struct MenuItem { int circularIncDec(int current, int inc, int min, int max, IsValueAvailable isValueAvailable=NULL); void displaySplash(); void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr); -void drawScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible); +void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible); void displayMenuBar(const MenuItem *menu, int index); void drawProgressBar(const char *label); void updateProgressBar(int num, int den); diff --git a/radio/src/gui/Taranis/navigation.cpp b/radio/src/gui/Taranis/navigation.cpp index 4e0ca0d2a..f6be211f4 100644 --- a/radio/src/gui/Taranis/navigation.cpp +++ b/radio/src/gui/Taranis/navigation.cpp @@ -588,7 +588,7 @@ void check(const char *name, check_event_t event, uint8_t curr, const MenuFuncP } if (scrollbar_X && linesCount > NUM_BODY_LINES) { - drawScrollbar(scrollbar_X, MENU_HEADER_HEIGHT, LCD_H-MENU_HEADER_HEIGHT, s_pgOfs, linesCount, NUM_BODY_LINES); + drawVerticalScrollbar(scrollbar_X, MENU_HEADER_HEIGHT, LCD_H-MENU_HEADER_HEIGHT, s_pgOfs, linesCount, NUM_BODY_LINES); } if (name) { diff --git a/radio/src/gui/Taranis/popups.cpp b/radio/src/gui/Taranis/popups.cpp index aac4461c5..e3af011bd 100644 --- a/radio/src/gui/Taranis/popups.cpp +++ b/radio/src/gui/Taranis/popups.cpp @@ -139,7 +139,7 @@ const char * displayMenu(uint8_t event) } if (s_menu_count > display_count) { - drawScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_DISPLAY_LINES * (FH+1), s_menu_offset, s_menu_count, display_count); + drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_DISPLAY_LINES * (FH+1), s_menu_offset, s_menu_count, display_count); } switch(event) { diff --git a/radio/src/gui/Taranis/view_text.cpp b/radio/src/gui/Taranis/view_text.cpp index a79532f19..cc869954d 100644 --- a/radio/src/gui/Taranis/view_text.cpp +++ b/radio/src/gui/Taranis/view_text.cpp @@ -149,7 +149,7 @@ void menuTextView(uint8_t event) lcd_invert_line(0); if (lines_count > LCD_LINES-1) { - drawScrollbar(LCD_W-1, FH, LCD_H-FH, s_pgOfs, lines_count, LCD_LINES-1); + drawVerticalScrollbar(LCD_W-1, FH, LCD_H-FH, s_pgOfs, lines_count, LCD_LINES-1); } } diff --git a/radio/src/gui/Taranis/widgets.cpp b/radio/src/gui/Taranis/widgets.cpp index 583a3812c..73af88396 100644 --- a/radio/src/gui/Taranis/widgets.cpp +++ b/radio/src/gui/Taranis/widgets.cpp @@ -82,7 +82,7 @@ void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr) lcd_outdezAtt(x, 0, index+1, attr); } -void drawScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible) +void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible) { lcdDrawVerticalLine(x, y, h, DOTTED); coord_t yofs = (h * offset) / count;