tcMenu
TcThemeBuilder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
11 #ifndef TCCLIBSDK_TCTHEMEBUILDER_H
12 #define TCCLIBSDK_TCTHEMEBUILDER_H
13 
14 #include "GfxMenuConfig.h"
16 
17 #define COL_COUNT_FLAG_BULK_MODE 0x80
18 
19 namespace tcgfx {
20  class TcThemeBuilder;
21 
29  public:
30  enum ThemeLevel : uint8_t {
31  THEME_GLOBAL, THEME_SUB, THEME_ITEM, THEME_ITEM_NEEDS_PROPS, THEME_ITEM_NEEDS_GRID, THEME_ITEM_NEEDS_BOTH
32  };
33  private:
34  // do not reorder these fields, they are ordered this way to reduce the size, IE the packing overhead.
35  TcThemeBuilder *themeBuilder;
36  color_t palette[4]{};
37  const void* fontData{};
38  MenuItem* menuItem = nullptr;
39  MenuPadding padding {};
40  MenuBorder border{};
41  uint16_t gridHeight {};
42  ItemDisplayProperties::ComponentType componentType = ItemDisplayProperties::COMPTYPE_ITEM;
43  ThemeLevel currentLevel = THEME_GLOBAL;
44  uint8_t fontMag{};
45  uint8_t spacing{};
46  GridPosition::GridDrawingMode drawingMode{};
48  uint8_t row {};
49  uint8_t colPos {};
50  uint8_t colCount {};
51  public:
52  explicit ThemePropertiesBuilder(TcThemeBuilder *themeBuilder): themeBuilder(themeBuilder) {}
53 
60  border = b;
61  needsProps();
62  return *this;
63  }
64 
71  ThemePropertiesBuilder& withAdaFont(const GFXfont* font, int mag = 1) {
72  fontData = font;
73  fontMag = internal_min(1, mag);
74  needsProps();
75  return *this;
76  }
77 
83  ThemePropertiesBuilder& withTcUnicodeFont(const UnicodeFont* font) {
84  fontData = font;
85  fontMag = 0;
86  needsProps();
87  return *this;
88  }
89 
96  ThemePropertiesBuilder& withNativeFont(const void* data, uint8_t mag) {
97  fontData = data;
98  fontMag = mag;
99  needsProps();
100  return *this;
101  }
102 
109  padding = p;
110  needsProps();
111  return *this;
112  }
113 
120  spacing = s;
121  needsGrid(true);
122  return *this;
123  }
124 
131  justification = j;
132  needsGrid(true);
133  return *this;
134  }
135 
142  needsProps();
143  memcpy(palette, p, sizeof(palette));
144  return *this;
145  }
146 
154  gridHeight = height;
155  needsGrid(false);
156  return *this;
157  }
158 
162  ThemePropertiesBuilder& withImageOfType(Coord size, DrawableIcon::IconType iconType, const uint8_t* regIcon,
163  const uint8_t* selIcon, const color_t* palette = nullptr);
164 
173  ThemePropertiesBuilder& withImageXbmp(Coord size, const uint8_t* regIcon, const uint8_t* selIcon = nullptr) {
174  withImageOfType(size, DrawableIcon::ICON_XBITMAP, regIcon, selIcon);
175  return *this;
176  }
177 
187  ThemePropertiesBuilder& withImage2bpp(Coord size, const color_t* imgPalette, const uint8_t* regIcon, const uint8_t* selIcon = nullptr) {
188  withImageOfType(size, DrawableIcon::ICON_PALLETE_2BPP, regIcon, selIcon, imgPalette);
189  return *this;
190  }
191 
201  ThemePropertiesBuilder& withImage4bpp(Coord size, const color_t* imgPalette, const uint8_t* regIcon, const uint8_t* selIcon = nullptr) {
202  withImageOfType(size, DrawableIcon::ICON_PALLETE_4BPP, regIcon, selIcon, imgPalette);
203  return *this;
204  }
205 
214  ThemePropertiesBuilder& withMonoBitmap(Coord size, const uint8_t* regIcon, const uint8_t* selIcon = nullptr) {
215  withImageOfType(size, DrawableIcon::ICON_MONO, regIcon, selIcon);
216  return *this;
217  }
218 
219 
226  drawingMode = dm;
227  needsGrid(false);
228  return *this;
229  }
230 
239  ThemePropertiesBuilder& onRowCol(uint8_t actRow, uint8_t column, uint8_t numberOfCols) {
240  row = actRow;
241  colPos = column;
242  colCount = numberOfCols;
243  return *this;
244  }
245 
252  ThemePropertiesBuilder& onRow(uint8_t actualRow) {
253  colPos = 1;
254  colCount = 1;
255  row = actualRow;
256  return *this;
257  }
258 
263  void apply();
264 
265  protected:
266  void initForLevel(TcThemeBuilder *b, ItemDisplayProperties::ComponentType compType, ThemeLevel level, MenuItem *item = nullptr);
267 
268  void needsProps() {
269  if(currentLevel == THEME_SUB || currentLevel == THEME_GLOBAL) return;
270  if(currentLevel == THEME_ITEM) currentLevel = THEME_ITEM_NEEDS_PROPS;
271  else currentLevel = THEME_ITEM_NEEDS_BOTH;
272  }
273 
274  void needsGrid(bool propsOk) {
275  if(currentLevel == THEME_SUB || currentLevel == THEME_GLOBAL) return;
276  if(currentLevel == THEME_ITEM_NEEDS_PROPS && propsOk) return;
277  if(currentLevel == THEME_ITEM) currentLevel = THEME_ITEM_NEEDS_GRID;
278  else currentLevel = THEME_ITEM_NEEDS_BOTH;
279  }
280 
281  friend TcThemeBuilder;
282  };
283 
291  private:
292  GraphicsDeviceRenderer &renderer;
294  ThemePropertiesBuilder propertiesBuilder;
295  color_t defaultPalette[4] = {};
296  MenuPadding globalItemPadding;
297  MenuPadding globalTitlePadding;
298  const void *fontData;
299  uint8_t fontMag;
300  uint8_t defaultSpacing;
301  public:
306  explicit TcThemeBuilder(GraphicsDeviceRenderer& renderer) : renderer(renderer), factory(renderer.getGraphicsPropertiesFactory()),
307  propertiesBuilder(this) {
308  auto titleDef = factory.configFor(nullptr, ItemDisplayProperties::COMPTYPE_TITLE);
309  globalTitlePadding = titleDef->getPadding();
310  auto itemDef = factory.configFor(nullptr, ItemDisplayProperties::COMPTYPE_ITEM);
311  memcpy(defaultPalette, itemDef->getPalette(), sizeof defaultPalette);
312  globalItemPadding = itemDef->getPadding();
313  fontData = itemDef->getFont();
314  fontMag = itemDef->getFontMagnification();
315  defaultSpacing = itemDef->getSpaceAfter();
316  }
317 
325  factory.setSelectedColors(bg, fg);
326  return *this;
327  }
328 
336  TcThemeBuilder& withAdaFont(const GFXfont* font, int mag = 1) {
337  fontData = font;
338  fontMag = internal_min(1, mag);
339  return *this;
340  }
341 
347  TcThemeBuilder& withTcUnicodeFont(const UnicodeFont* font) {
348  fontData = font;
349  fontMag = 0;
350  return *this;
351  }
352 
360  TcThemeBuilder& withNativeFont(const void* data, uint8_t mag) {
361  fontData = data;
362  fontMag = mag;
363  return *this;
364  }
365 
373 
379 
389  TcThemeBuilder &withCursorIconsXbmp(Coord size, const uint8_t *editIcon, const uint8_t *activeIcon);
390 
397 
404 
410  TcThemeBuilder &withSpacing(uint8_t spacing) {
411  defaultSpacing = spacing;
412  return *this;
413  }
414 
421  globalItemPadding = padding;
422  return *this;
423  }
424 
431  globalTitlePadding = padding;
432  return *this;
433  }
434 
440  propertiesBuilder.initForLevel(this, ItemDisplayProperties::COMPTYPE_ITEM, ThemePropertiesBuilder::THEME_GLOBAL);
441  return propertiesBuilder;
442  }
443 
449  propertiesBuilder.initForLevel(this, ItemDisplayProperties::COMPTYPE_TITLE, ThemePropertiesBuilder::THEME_GLOBAL);
450  return propertiesBuilder;
451  }
452 
458  propertiesBuilder.initForLevel(this, ItemDisplayProperties::COMPTYPE_ACTION, ThemePropertiesBuilder::THEME_GLOBAL);
459  return propertiesBuilder;
460  }
461 
470 
480 
488  propertiesBuilder.initForLevel(this, ItemDisplayProperties::COMPTYPE_ITEM, ThemePropertiesBuilder::THEME_SUB, &item);
489  return propertiesBuilder;
490  }
491 
499  propertiesBuilder.initForLevel(this, ItemDisplayProperties::COMPTYPE_ACTION, ThemePropertiesBuilder::THEME_SUB, &item);
500  return propertiesBuilder;
501  }
502 
510  propertiesBuilder.initForLevel(this, ItemDisplayProperties::COMPTYPE_TITLE, ThemePropertiesBuilder::THEME_SUB, &item);
511  return propertiesBuilder;
512  }
513 
519  TcThemeBuilder& withPalette(const color_t* cols);
520 
529  renderer.setTitleMode(mode);
530  renderer.setUseSliderForAnalog(useAnalogSliders);
531  return *this;
532  }
533 
540 
547  TcThemeBuilder& manualDimensions(int x, int y);
548 
558  TcThemeBuilder& enableCardLayoutWithXbmImages(Coord iconSize, const uint8_t* leftIcon, const uint8_t* rightIcon, bool isMono);
565  TcThemeBuilder& setMenuAsCard(SubMenuItem& item, bool on);
566 
567  TcThemeBuilder& addingTitleWidget(TitleWidget& theWidget);
568 
572  void apply();
573 
574  ConfigurableItemDisplayPropertiesFactory& getItemFactory() { return factory; }
575 
576  MenuPadding getPaddingFor(ItemDisplayProperties::ComponentType type) {
577  return type == ItemDisplayProperties::COMPTYPE_TITLE ? globalTitlePadding : globalItemPadding;
578  }
579 
580  uint8_t getDefaultSpacing() const {
581  return defaultSpacing;
582  }
583 
584  GraphicsDeviceRenderer& getRenderer() {
585  return renderer;
586  }
587 
588  const color_t* getDefaultPalette() {
589  return defaultPalette;
590  }
591 
592  const void* getDefaultFontData() {
593  return fontData;
594  }
595 
596  uint8_t getDefaultFontMag() const {
597  return fontMag;
598  }
599  };
600 
601 }
602 #endif //TCCLIBSDK_TCTHEMEBUILDER_H
uint32_t color_t
Definition: DrawingPrimitives.h:29
the interface that all graphics devices should implement to do the actual graphics rendering.
Definition: MenuItems.h:329
Definition: RuntimeMenuItem.h:149
Definition: BaseRenderers.h:126
void setUseSliderForAnalog(bool useSlider)
Definition: BaseGraphicalRenderer.h:195
TitleMode
Definition: BaseGraphicalRenderer.h:136
ItemDisplayProperties * configFor(MenuItem *pItem, ItemDisplayProperties::ComponentType compType) override
Definition: GfxMenuConfig.cpp:66
void setSelectedColors(color_t background, color_t text)
Definition: GfxMenuConfig.h:641
IconType
Definition: DrawingPrimitives.h:154
@ ICON_XBITMAP
Definition: DrawingPrimitives.h:156
@ ICON_MONO
Definition: DrawingPrimitives.h:158
@ ICON_PALLETE_2BPP
Definition: DrawingPrimitives.h:161
@ ICON_PALLETE_4BPP
Definition: DrawingPrimitives.h:164
Definition: GraphicsDeviceRenderer.h:59
GridJustification
Definition: GfxMenuConfig.h:93
@ JUSTIFY_TITLE_LEFT_VALUE_RIGHT
Definition: GfxMenuConfig.h:107
GridDrawingMode
Definition: GfxMenuConfig.h:74
ComponentType
Definition: GfxMenuConfig.h:260
Definition: TcThemeBuilder.h:290
ThemePropertiesBuilder & defaultActionProperties()
Definition: TcThemeBuilder.h:457
TcThemeBuilder & withSpacing(uint8_t spacing)
Definition: TcThemeBuilder.h:410
TcThemeBuilder & withRenderingSettings(BaseGraphicalRenderer::TitleMode mode, bool useAnalogSliders)
Definition: TcThemeBuilder.h:528
TcThemeBuilder & withSelectedColors(color_t bg, color_t fg)
Definition: TcThemeBuilder.h:324
TcThemeBuilder & withStandardLowResCursorIcons()
Definition: TcThemeBuilder.cpp:131
TcThemeBuilder & withPalette(const color_t *cols)
Definition: TcThemeBuilder.cpp:97
ThemePropertiesBuilder & defaultItemProperties()
Definition: TcThemeBuilder.h:439
ThemePropertiesBuilder & menuItemOverride(MenuItem &item)
Definition: TcThemeBuilder.cpp:102
TcThemeBuilder & enableTcUnicode()
Definition: TcThemeBuilder.cpp:139
TcThemeBuilder & dimensionsFromRenderer()
Definition: TcThemeBuilder.cpp:144
ThemePropertiesBuilder & submenuPropertiesItemOverride(SubMenuItem &item)
Definition: TcThemeBuilder.h:487
TcThemeBuilder(GraphicsDeviceRenderer &renderer)
Definition: TcThemeBuilder.h:306
TcThemeBuilder & withTcUnicodeFont(const UnicodeFont *font)
Definition: TcThemeBuilder.h:347
TcThemeBuilder & withAdaFont(const GFXfont *font, int mag=1)
Definition: TcThemeBuilder.h:336
TcThemeBuilder & enableCardLayoutWithXbmImages(Coord iconSize, const uint8_t *leftIcon, const uint8_t *rightIcon, bool isMono)
Definition: TcThemeBuilder.cpp:119
TcThemeBuilder & manualDimensions(int x, int y)
Definition: TcThemeBuilder.cpp:150
TcThemeBuilder & enablingTcUnicode()
Definition: TcThemeBuilder.h:378
ThemePropertiesBuilder & submenuPropertiesActionOverride(SubMenuItem &item)
Definition: TcThemeBuilder.h:498
TcThemeBuilder & withStandardMedResCursorIcons()
Definition: TcThemeBuilder.cpp:135
TcThemeBuilder & withCursorIconsXbmp(Coord size, const uint8_t *editIcon, const uint8_t *activeIcon)
Definition: TcThemeBuilder.cpp:87
void apply()
Definition: TcThemeBuilder.cpp:93
TcThemeBuilder & withNativeFont(const void *data, uint8_t mag)
Definition: TcThemeBuilder.h:360
TcThemeBuilder & withTitlePadding(MenuPadding padding)
Definition: TcThemeBuilder.h:430
ThemePropertiesBuilder & defaultTitleProperties()
Definition: TcThemeBuilder.h:448
ThemePropertiesBuilder & submenuPropertiesTitleOverride(SubMenuItem &item)
Definition: TcThemeBuilder.h:509
TcThemeBuilder & setMenuAsCard(SubMenuItem &item, bool on)
Definition: TcThemeBuilder.cpp:126
TcThemeBuilder & withItemPadding(MenuPadding padding)
Definition: TcThemeBuilder.h:420
Definition: TcThemeBuilder.h:28
ThemePropertiesBuilder & withPadding(MenuPadding p)
Definition: TcThemeBuilder.h:108
ThemePropertiesBuilder & withRowHeight(uint16_t height)
Definition: TcThemeBuilder.h:153
ThemePropertiesBuilder & withSpacing(uint8_t s)
Definition: TcThemeBuilder.h:119
ThemePropertiesBuilder & onRowCol(uint8_t actRow, uint8_t column, uint8_t numberOfCols)
Definition: TcThemeBuilder.h:239
ThemePropertiesBuilder & withImage2bpp(Coord size, const color_t *imgPalette, const uint8_t *regIcon, const uint8_t *selIcon=nullptr)
Definition: TcThemeBuilder.h:187
ThemePropertiesBuilder & withBorder(const MenuBorder &b)
Definition: TcThemeBuilder.h:59
ThemePropertiesBuilder & withImage4bpp(Coord size, const color_t *imgPalette, const uint8_t *regIcon, const uint8_t *selIcon=nullptr)
Definition: TcThemeBuilder.h:201
ThemePropertiesBuilder & withNativeFont(const void *data, uint8_t mag)
Definition: TcThemeBuilder.h:96
ThemePropertiesBuilder & withImageOfType(Coord size, DrawableIcon::IconType iconType, const uint8_t *regIcon, const uint8_t *selIcon, const color_t *palette=nullptr)
Definition: TcThemeBuilder.cpp:80
ThemePropertiesBuilder & withPalette(const color_t *p)
Definition: TcThemeBuilder.h:141
ThemePropertiesBuilder & withTcUnicodeFont(const UnicodeFont *font)
Definition: TcThemeBuilder.h:83
ThemePropertiesBuilder & withJustification(GridPosition::GridJustification j)
Definition: TcThemeBuilder.h:130
ThemePropertiesBuilder & withMonoBitmap(Coord size, const uint8_t *regIcon, const uint8_t *selIcon=nullptr)
Definition: TcThemeBuilder.h:214
ThemePropertiesBuilder & onRow(uint8_t actualRow)
Definition: TcThemeBuilder.h:252
ThemePropertiesBuilder & withImageXbmp(Coord size, const uint8_t *regIcon, const uint8_t *selIcon=nullptr)
Definition: TcThemeBuilder.h:173
ThemePropertiesBuilder & withDrawingMode(GridPosition::GridDrawingMode dm)
Definition: TcThemeBuilder.h:225
void apply()
Definition: TcThemeBuilder.cpp:8
ThemePropertiesBuilder & withAdaFont(const GFXfont *font, int mag=1)
Definition: TcThemeBuilder.h:71
Definition: DrawingPrimitives.h:123
Definition: DrawingPrimitives.h:92
Definition: DrawingPrimitives.h:56