99
1010namespace tcgfx {
1111
12-
1312void BaseGraphicalRenderer::render () {
14- checkIfRootHasChanged ();
13+ // do not attempt rendering before everything is initialised.
14+ if (currentRootMenu == nullptr ) return ;
1515
1616 uint8_t locRedrawMode = redrawMode;
1717 redrawMode = MENUDRAW_NO_CHANGE;
@@ -263,11 +263,7 @@ GridPosition::GridDrawingMode modeFromItem(MenuItem* item, bool useSlider) {
263263 }
264264}
265265
266- void BaseGraphicalRenderer::checkIfRootHasChanged () {
267- auto * rootItem = menuMgr.getCurrentMenu ();
268- if (currentRootMenu != rootItem)
269- {
270- serlogF (SER_TCMENU_INFO, " root has changed" );
266+ void BaseGraphicalRenderer::rootHasChanged (MenuItem* rootItem) {
271267 currentRootMenu = rootItem;
272268 redrawMode = MENUDRAW_COMPLETE_REDRAW;
273269 recalculateDisplayOrder (rootItem, false );
@@ -278,7 +274,6 @@ void BaseGraphicalRenderer::checkIfRootHasChanged() {
278274 serlogF3 (SER_TCMENU_INFO, " Force encoder size: " , switches.getEncoder ()->getMaximumValue (), expectedCount)
279275 menuMgr.setItemsInCurrentMenu (expectedCount, switches.getEncoder ()->getCurrentReading ());
280276 }
281- }
282277}
283278
284279void BaseGraphicalRenderer::recalculateDisplayOrder (MenuItem *root, bool safeMode) {
@@ -394,7 +389,6 @@ int BaseGraphicalRenderer::calculateHeightTo(int index, MenuItem *pItem) {
394389}
395390
396391uint8_t BaseGraphicalRenderer::itemCount (MenuItem*, bool ) {
397- checkIfRootHasChanged ();
398392 if (currentRootMenu && currentRootMenu->getMenuType () == MENUTYPE_RUNTIME_LIST) {
399393 auto * listItem = reinterpret_cast <ListRuntimeMenuItem*>(currentRootMenu);
400394 return listItem->getNumberOfRows () + 1 ; // accounts for title.
@@ -405,7 +399,6 @@ uint8_t BaseGraphicalRenderer::itemCount(MenuItem*, bool ) {
405399}
406400
407401int BaseGraphicalRenderer::findItemIndex (MenuItem *root, MenuItem *toFind) {
408- checkIfRootHasChanged ();
409402 for (bsize_t i=0 ;i<itemOrderByRow.count ();i++) {
410403 auto * possibleActive = itemOrderByRow.itemAtIndex (i);
411404 if (possibleActive->getMenuItem () == toFind) return i;
@@ -414,7 +407,6 @@ int BaseGraphicalRenderer::findItemIndex(MenuItem *root, MenuItem *toFind) {
414407}
415408
416409int BaseGraphicalRenderer::findActiveItem (MenuItem* root) {
417- checkIfRootHasChanged ();
418410 if (currentRootMenu && currentRootMenu->getMenuType () == MENUTYPE_RUNTIME_LIST) {
419411 auto * listItem = reinterpret_cast <ListRuntimeMenuItem*>(currentRootMenu);
420412 return listItem->getActiveIndex (); // accounts for title.
@@ -427,7 +419,6 @@ int BaseGraphicalRenderer::findActiveItem(MenuItem* root) {
427419}
428420
429421MenuItem *BaseGraphicalRenderer::getMenuItemAtIndex (MenuItem* item, uint8_t idx) {
430- checkIfRootHasChanged ();
431422 if (currentRootMenu && currentRootMenu->getMenuType () == MENUTYPE_RUNTIME_LIST) {
432423 return currentRootMenu;
433424 }
@@ -463,6 +454,30 @@ void BaseGraphicalRenderer::setTitleMode(BaseGraphicalRenderer::TitleMode mode)
463454 menuMgr.changeMenu (menuMgr.getCurrentMenu ());
464455}
465456
457+ BaseGraphicalRenderer::BaseGraphicalRenderer (int bufferSize, int wid, int hei, bool lastRowExact,const char *appTitle)
458+ : BaseMenuRenderer(bufferSize, RENDER_TYPE_CONFIGURABLE), navigationListener(this ) {
459+ width = wid;
460+ height = hei;
461+ flags = 0 ;
462+ setTitleOnDisplay (true );
463+ setLastRowExactFit (lastRowExact);
464+ setUseSliderForAnalog (true );
465+ setEditStatusIconsEnabled (true );
466+ currentRootMenu = nullptr ;
467+ pgmTitle = appTitle;
468+ }
469+
470+ void BaseGraphicalRenderer::initialise () {
471+ BaseMenuRenderer::initialise ();
472+ menuMgr.getNavigationStore ().addNavigationListener (&navigationListener);
473+ }
474+
475+ void BaseGraphicalRenderer::displayPropertiesHaveChanged () {
476+ currentRootMenu = nullptr ;
477+ rootHasChanged (menuMgr.getCurrentMenu ());
478+ redrawMode = MENUDRAW_COMPLETE_REDRAW;
479+ }
480+
466481void preparePropertiesFromConfig (ConfigurableItemDisplayPropertiesFactory& factory, const ColorGfxMenuConfig<const void *>* gfxConfig, int titleHeight, int itemHeight) {
467482 // TEXT, BACKGROUND, HIGHLIGHT1, HIGHLIGHT2, SELECTED_FG, SELECTED_BG
468483 color_t paletteItems[] { gfxConfig->fgItemColor , gfxConfig->bgItemColor , gfxConfig->bgSelectColor , gfxConfig->fgSelectColor };
@@ -479,4 +494,15 @@ void preparePropertiesFromConfig(ConfigurableItemDisplayPropertiesFactory& facto
479494 ConfigurableItemDisplayPropertiesFactory::refreshCache ();
480495}
481496
497+ void RenderingNavigationListener::navigationHasChanged (MenuItem *newItem, bool completelyReset) {
498+ if (renderer->getCurrentRendererRoot () != newItem) {
499+ serlogF (SER_TCMENU_INFO, " Rendering root needs to change" );
500+ renderer->rootHasChanged (newItem);
501+ }
502+ }
503+
504+ RenderingNavigationListener::RenderingNavigationListener (BaseGraphicalRenderer *r) {
505+ renderer = r;
506+ }
507+
482508} // namespace tcgfx
0 commit comments