add a "popup" menu variant (for the reflow profile editor)

master
Ondřej Hruška 5 years ago
parent 7240773581
commit e22d4fb9e2
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      main/CMakeLists.txt
  2. 8
      main/graphics/drawing.c
  3. 3
      main/graphics/drawing.h
  4. 28
      main/scenes/scene_manual_menu.c
  5. 6
      main/scenes/scene_menu.c
  6. 2
      main/scenes/scene_menu.h
  7. 36
      main/scenes/scene_popup_menu.c
  8. 25
      main/scenes/scene_popup_test.c
  9. 5
      main/scenes/scene_root.c
  10. 6
      main/scenes/scenes.h

@ -9,6 +9,8 @@ set(COMPONENT_SRCS
"scenes/scene_menu.c" "scenes/scene_menu.c"
"scenes/scene_number.c" "scenes/scene_number.c"
"scenes/scene_manual_menu.c" "scenes/scene_manual_menu.c"
"scenes/scene_popup_menu.c"
"scenes/scene_popup_test.c"
"graphics/nokia.c" "graphics/nokia.c"
"graphics/utf8.c" "graphics/utf8.c"
"graphics/font.c" "graphics/font.c"

@ -89,7 +89,7 @@ void LCD_setRect(int x0, int y0, int x1, int y1, bool fill, enum Color bw)
else else
xDiff = x1 - x0; xDiff = x1 - x0;
while (xDiff > 0) { while (xDiff >= 0) {
LCD_setLine(x0, y0, x0, y1, bw); LCD_setLine(x0, y0, x0, y1, bw);
if (x0 > x1) if (x0 > x1)
@ -361,3 +361,9 @@ void LCD_invertDisplayData()
LCD_displayMap[i] ^= 0xFF; LCD_displayMap[i] ^= 0xFF;
} }
} }
void LCD_setShadeOverlay() {
for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) {
LCD_displayMap[i] |= i & 1 ? 0x88 : 0x22;
}
}

@ -87,4 +87,7 @@ void LCD_invertDisplayData();
void LCD_setBitmap(const struct BitmapImage *image, int x, int y, bool bg, enum Color color); void LCD_setBitmap(const struct BitmapImage *image, int x, int y, bool bg, enum Color color);
/** draw dotted shadow over current content */
void LCD_setShadeOverlay();
#endif //LCD_DRAWING_H #endif //LCD_DRAWING_H

@ -14,7 +14,8 @@
#include "scene_menu.h" #include "scene_menu.h"
struct Priv { struct Priv {
Scene_paint_t basePaint; int _placeholder;
//Scene_paint_t basePaint;
}; };
static struct SceneEvent onSelect(struct MenuScene *self) { static struct SceneEvent onSelect(struct MenuScene *self) {
@ -27,11 +28,13 @@ static struct SceneEvent onSelect(struct MenuScene *self) {
opts->max = 350; opts->max = 350;
return SceneEvent_OpenChild(NewScene_Number(opts), 0); return SceneEvent_OpenChild(NewScene_Number(opts), 0);
} }
else if (self->selected == 1) {
if (self->selected == 1) {
fire_enable(!fire_enabled()); fire_enable(!fire_enabled());
return SceneEvent_Repaint(); return SceneEvent_Repaint();
} }
else if (self->selected == 2) {
return SceneEvent_OpenChild(NewScene_PopupTest(), 1);
}
return SceneEvent_None(); return SceneEvent_None();
} }
@ -60,12 +63,12 @@ void print_labels(struct MenuItem *items) {
} else { } else {
strncpy(items[1].label, "▶START", MENUITEM_LABEL_LEN); strncpy(items[1].label, "▶START", MENUITEM_LABEL_LEN);
} }
strncpy(items[2].label, "▶Item with popup", MENUITEM_LABEL_LEN);
} }
static void paint(struct MenuScene *self) static void paint(struct MenuScene *self)
{ {
struct Priv *priv = self->extra;
print_labels(self->items); print_labels(self->items);
LCD_clearDisplay(0); LCD_clearDisplay(0);
@ -87,27 +90,26 @@ static void paint(struct MenuScene *self)
LCD_setBitmap(img, XLINE/2-24/2, 26, false, BLACK); LCD_setBitmap(img, XLINE/2-24/2, 26, false, BLACK);
priv->basePaint((struct Scene *) self); MenuScene_Paint(self);
} }
struct Scene *NewScene_MenuTest() { struct Scene *NewScene_MenuManual() {
struct MenuItem *items = calloc(2, sizeof(struct MenuItem)); struct MenuItem *items = calloc(3, sizeof(struct MenuItem));
print_labels(items); print_labels(items);
struct MenuScene * scene = NewScene_Menu(items, 2); struct MenuScene * scene = NewScene_Menu(items, 3);
scene->onSelect = onSelect; scene->onSelect = onSelect;
scene->x = XLINE; scene->x = XLINE;
scene->ncols = 8; scene->ncols = 7;
// private data added by the subclass // private data added by the subclass
struct Priv *priv = calloc(1, sizeof(struct Priv));
priv->basePaint = scene->base.paint;
scene->base.paint = (Scene_paint_t) paint; scene->base.paint = (Scene_paint_t) paint;
struct Priv *priv = calloc(1, sizeof(struct Priv));
scene->extra = priv; scene->extra = priv;
scene->extra_deinit = (Scene_deinit_t) priv_deinit; scene->extra_deinit = (Scene_deinit_t) priv_deinit;
scene->wraparound = true;
// add a child return handler (base does not use this) // add a child return handler (base does not use this)
scene->base.onChildReturn = (Scene_onChildReturn_t) onChildReturn; scene->base.onChildReturn = (Scene_onChildReturn_t) onChildReturn;

@ -28,7 +28,7 @@ static void paint(struct MenuScene *self)
#define HSCROLL_START_MS 750 #define HSCROLL_START_MS 750
#define HSCROLL_MS 250 #define HSCROLL_MS 250
static void paint(struct MenuScene *self) void MenuScene_Paint(struct MenuScene *self)
{ {
LCD_setRect(self->x, self->y, self->x + self->ncols*6, self->y + self->nlines*9, 1, WHITE); LCD_setRect(self->x, self->y, self->x + self->ncols*6, self->y + self->nlines*9, 1, WHITE);
@ -46,7 +46,7 @@ static void paint(struct MenuScene *self)
} }
LCD_setStrEx(self->items[i].label, self->x + 1, self->y + row * 9 + 1, !selected, (struct TextStyle) { LCD_setStrEx(self->items[i].label, self->x + 1, self->y + row * 9 + 1, !selected, (struct TextStyle) {
.bg = selected, .bg = selected,
.nowrap = 1, .limit = self->ncols,
.skip = shift, .skip = shift,
}); });
} }
@ -143,7 +143,7 @@ static void deinit(struct MenuScene *self)
struct MenuScene *NewScene_Menu(struct MenuItem *items, size_t items_len) { struct MenuScene *NewScene_Menu(struct MenuItem *items, size_t items_len) {
struct MenuScene *scene = calloc(1, sizeof(struct MenuScene)); struct MenuScene *scene = calloc(1, sizeof(struct MenuScene));
scene->base.paint = (Scene_paint_t) paint; scene->base.paint = (Scene_paint_t) MenuScene_Paint;
scene->base.onInput = (Scene_onInput_t) onInput; scene->base.onInput = (Scene_onInput_t) onInput;
scene->base.deinit = (Scene_deinit_t) deinit; scene->base.deinit = (Scene_deinit_t) deinit;
scene->base.onTick = (Scene_onTick_t) onTick; scene->base.onTick = (Scene_onTick_t) onTick;

@ -78,4 +78,6 @@ struct MenuScene {
*/ */
struct MenuScene *NewScene_Menu(struct MenuItem *items, size_t items_len); struct MenuScene *NewScene_Menu(struct MenuItem *items, size_t items_len);
void MenuScene_Paint(struct MenuScene *self);
#endif //REFLOWER_SCENE_MENU_H #endif //REFLOWER_SCENE_MENU_H

@ -0,0 +1,36 @@
#include <malloc.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <common_utils/utils.h>
#include "analog.h"
#include "firehazard.h"
#include "graphics/bitmaps.h"
#include "liquid.h"
#include "graphics/drawing.h"
#include "graphics/display_spec.h"
#include "scenes.h"
#include "scene_menu.h"
static void paint(struct MenuScene *self)
{
LCD_setShadeOverlay();
// frame around the menu items
LCD_setRect(self->x - 3, self->y - 3, self->x + self->ncols*6 + 3, self->y + self->nlines * 9 + 2, true, WHITE);
LCD_setRect(self->x - 2, self->y - 2, self->x + self->ncols*6 + 2, self->y + self->nlines * 9 + 1, false, BLACK);
MenuScene_Paint(self);
}
struct MenuScene *NewScene_PopupMenu(struct MenuItem *items, size_t items_len)
{
struct MenuScene * scene = NewScene_Menu(items, items_len);
scene->x = 12;
scene->y = 6;
scene->ncols = 10;
scene->nlines = MIN(items_len, 4);
scene->base.paint = (Scene_paint_t) paint;
return scene;
}

@ -0,0 +1,25 @@
#include <malloc.h>
#include <string.h>
#include "liquid.h"
#include "scenes.h"
#include "scene_menu.h"
static struct SceneEvent onSelect(struct MenuScene *self) {
return SceneEvent_Close(0, NULL);
}
struct Scene *NewScene_PopupTest() {
struct MenuItem *items = calloc(5, sizeof(struct MenuItem));
strncpy(items[0].label, "Item 1", MENUITEM_LABEL_LEN);
strncpy(items[1].label, "Item Two", MENUITEM_LABEL_LEN);
strncpy(items[2].label, "Item Three hereee", MENUITEM_LABEL_LEN);
strncpy(items[3].label, "FOURTH", MENUITEM_LABEL_LEN);
strncpy(items[4].label, "EXTRA SECRET FIFTH ITEM", MENUITEM_LABEL_LEN);
struct MenuScene * scene = NewScene_PopupMenu(items, 5);
scene->onSelect = onSelect;
return (struct Scene *) scene;
}

@ -18,13 +18,14 @@ struct RootScene {
static struct SceneEvent init(struct RootScene *self) static struct SceneEvent init(struct RootScene *self)
{ {
return SceneEvent_OpenChild(NewScene_Boot(), 1); return SceneEvent_OpenChild(NewScene_MenuManual(), 0);
// return SceneEvent_OpenChild(NewScene_Boot(), 1); // TODO swap
} }
static struct SceneEvent onChildReturn(struct RootScene *self, uint32_t tag, int32_t status, void *data) static struct SceneEvent onChildReturn(struct RootScene *self, uint32_t tag, int32_t status, void *data)
{ {
if (tag == 1) { if (tag == 1) {
return SceneEvent_OpenChild(NewScene_MenuTest(), 0); return SceneEvent_OpenChild(NewScene_MenuManual(), 0);
} }
// this should be unreachable // this should be unreachable

@ -11,9 +11,13 @@
struct Scene *NewScene_Root(void); struct Scene *NewScene_Root(void);
struct Scene *NewScene_Boot(void); struct Scene *NewScene_Boot(void);
struct Scene *NewScene_MenuTest(void); struct Scene *NewScene_MenuManual(void);
struct Scene *NewScene_PopupTest();
#include "scene_menu.h" #include "scene_menu.h"
#include "scene_number.h" #include "scene_number.h"
struct MenuScene *NewScene_PopupMenu(struct MenuItem *items, size_t items_len);
#endif //REFLOWER_SCENES_H #endif //REFLOWER_SCENES_H

Loading…
Cancel
Save