tcMenu
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BaseMenuRenderer Class Referenceabstract

#include <BaseRenderers.h>

Inheritance diagram for BaseMenuRenderer:
MenuRenderer tcgfx::BaseGraphicalRenderer tcgfx::GraphicsDeviceRenderer

Public Types

enum  DisplayTakeoverMode { NOT_TAKEN_OVER , TAKEN_OVER_FN , START_CUSTOM_DRAW , RUNNING_CUSTOM_DRAW }
 

Public Member Functions

 BaseMenuRenderer (int bufferSize, RendererType rType=RENDER_TYPE_BASE, uint8_t displayNum=0)
 
 ~BaseMenuRenderer () override
 
void initialise () override
 
void setUpdatesPerSecond (int updatesSec)
 
void turnOffDisplayUpdates (bool)
 
void setResetIntervalTimeSeconds (uint16_t interval)
 
void turnOffResetLogic ()
 
void resetNotifiesOnly (uint16_t ticks)
 
void setResetCallback (ResetCallbackFn resetFn)
 
void setCustomDrawingHandler (CustomDrawing *customDrawingParam)
 
CustomDrawinggetCurrentCustomDrawing ()
 
void exec () override
 
virtual void render ()=0
 
bool tryTakeSelectIfNeeded (int currentReading, RenderPressMode pressMode) override
 
virtual MenuItemgetMenuItemAtIndex (MenuItem *pItem, uint8_t idx)
 
virtual int findItemIndex (MenuItem *root, MenuItem *toFind)
 
virtual uint8_t itemCount (MenuItem *item, bool includeNonVisible)
 
virtual uint8_t setActiveItem (MenuItem *item)
 
MenuItemgetActiveItem ()
 
int findActiveItem (MenuItem *root)
 
void setFirstWidget (TitleWidget *widget)
 
TitleWidgetgetFirstWidget ()
 
void menuAltered ()
 
void takeOverDisplay (RendererCallbackFn displayFn=nullptr)
 
void giveBackDisplay ()
 
void resetToDefault ()
 
void redrawRequirement (MenuRedrawState state)
 
void invalidateAll ()
 
- Public Member Functions inherited from MenuRenderer
 MenuRenderer (RendererType rendererType, int bufferSize)
 
virtual BaseDialoggetDialog ()=0
 
virtual ~MenuRenderer ()
 
char * getBuffer ()
 
uint8_t getBufferSize ()
 
RendererType getRendererType ()
 

Static Public Member Functions

static BaseMenuRenderergetInstance ()
 
- Static Public Member Functions inherited from MenuRenderer
static MenuRenderergetInstance ()
 

Protected Member Functions

void countdownToDefaulting ()
 

Protected Attributes

uint8_t lastOffset
 
uint8_t updatesPerSecond
 
uint8_t displayNumber = 0
 
MenuRedrawState redrawMode
 
uint16_t ticksToReset
 
uint16_t resetValInTicks
 
TitleWidgetfirstWidget
 
CustomDrawingcustomDrawing
 
BaseDialogdialog
 
DisplayTakeoverMode displayTakenMode
 
RenderPressMode renderFnPressType
 
RendererCallbackFn renderCallback
 
MenuItemactiveItem = nullptr
 
- Protected Attributes inherited from MenuRenderer
char * buffer
 
uint8_t bufferSize
 
RendererType rendererType
 

Additional Inherited Members

- Static Protected Attributes inherited from MenuRenderer
static MenuRenderertheInstance = nullptr
 

Detailed Description

This class provides the base functionality that will be required by most implementations of renderer, you can extend this class to add new renderers, it proivides much of the core functionality that's needed by a renderer.

Renderers work in a similar way to a game loop, the render method is repeatedly called and in this loop any rendering or event callbacks should be handled.

Constructor & Destructor Documentation

◆ BaseMenuRenderer()

BaseMenuRenderer::BaseMenuRenderer ( int  bufferSize,
RendererType  rType = RENDER_TYPE_BASE,
uint8_t  displayNum = 0 
)

constructs the renderer with a given buffer size

Parameters
bufferSizesize of text buffer to create

◆ ~BaseMenuRenderer()

BaseMenuRenderer::~BaseMenuRenderer ( )
inlineoverride

Destructs the class removing the allocated buffer

Member Function Documentation

◆ initialise()

void BaseMenuRenderer::initialise ( )
overridevirtual

Initialise the render setting up the refresh task at the update frequency provided (or leave blank for default).

Parameters
updatesPerSecondthe number of times to update the display per second, set to 0 or leave blank for default

Implements MenuRenderer.

Reimplemented in tcgfx::BaseGraphicalRenderer.

◆ setUpdatesPerSecond()

void BaseMenuRenderer::setUpdatesPerSecond ( int  updatesSec)

Set the number of updates per second for the display, use caution not to set too high, and never set to 0. Important note: This re-initialises the reset interval to 30 seconds

Parameters
updatesSecthe number of updates.

◆ turnOffDisplayUpdates()

void BaseMenuRenderer::turnOffDisplayUpdates ( bool  )
inline

Turn off the display updates to allow for low power state transition, to re-enable call setUpdatesPerSecond

See also
setUpdatesPerSecond

◆ setResetIntervalTimeSeconds()

void BaseMenuRenderer::setResetIntervalTimeSeconds ( uint16_t  interval)
inline

Adjust the default reset interval of 30 seconds. Maximum value is 60 seconds. At this point the reset callback is called and the menu is reset to root with no present editor. Values range from 1..4096

Parameters
resetTimethe number of seconds before calling the reset handler.

◆ turnOffResetLogic()

void BaseMenuRenderer::turnOffResetLogic ( )
inline

Completely turn off the reset interval so there will never be a reset event on the renderer.

◆ resetNotifiesOnly()

void BaseMenuRenderer::resetNotifiesOnly ( uint16_t  ticks)
inline

Indicates to the renderer that you want reset notification, but you do not want any changes to be made to the position in the menu, instead of the default behaviour to reset to the root menu.

Parameters
ticksthe number of seconds before calling the reset handler

◆ setResetCallback()

void BaseMenuRenderer::setResetCallback ( ResetCallbackFn  resetFn)
inline

Sets the callback that will receive reset events when the menu has not been edited for some time. You can optionally use an instance of CustomDrawing instead of this, and that will be notified of both reset events and take over display events.

◆ setCustomDrawingHandler()

void BaseMenuRenderer::setCustomDrawingHandler ( CustomDrawing customDrawingParam)
inline

Sets the CustomDrawing implementation that will handle both the reset event and also any custom drawing that needs to be done. The reset method will be called whenever the display times out back to it's defaults, the started will be called when the display is first taken over, followed by renderLoop until it's given back.

◆ getCurrentCustomDrawing()

CustomDrawing* BaseMenuRenderer::getCurrentCustomDrawing ( )
inline
Returns
the current custom drawing set on this renderer, it could be nullptr if never set.

◆ exec()

void BaseMenuRenderer::exec ( )
override

Called by taskManager when we are scheduled

◆ render()

virtual void BaseMenuRenderer::render ( )
pure virtual

This is the rendering call that must be implemented by subclasses. Generally it is called a few times a second, and should render the menu, if changes are detected

Implemented in tcgfx::BaseGraphicalRenderer.

◆ tryTakeSelectIfNeeded()

bool BaseMenuRenderer::tryTakeSelectIfNeeded ( int  currentReading,
RenderPressMode  pressMode 
)
overridevirtual

If this renderer has been taken over, displaying a dialog or needs to do something special with a button press, then this function can take action BEFORE anything else

Parameters
editorthe current editor
Returns
Ah it

Implements MenuRenderer.

◆ getMenuItemAtIndex()

MenuItem * BaseMenuRenderer::getMenuItemAtIndex ( MenuItem pItem,
uint8_t  idx 
)
virtual

Gets the menu item at a specific position

Parameters
rootthe root item
idxthe index to find
Returns
the item at the index or root.

Reimplemented in tcgfx::BaseGraphicalRenderer.

◆ findItemIndex()

int BaseMenuRenderer::findItemIndex ( MenuItem root,
MenuItem toFind 
)
virtual

Find an item's offset in a given root, safely returns 0.

Parameters
rootthe root item
toFindthe item within that root
Returns
the index if found, otherwise 0.

Reimplemented in tcgfx::BaseGraphicalRenderer.

◆ itemCount()

uint8_t BaseMenuRenderer::itemCount ( MenuItem item,
bool  includeNonVisible 
)
virtual

Get the count of items in the current root

Parameters
itemthe root item
includeNonVisibleif non visible should be included
Returns
the count

Reimplemented in tcgfx::BaseGraphicalRenderer.

◆ setActiveItem()

uint8_t BaseMenuRenderer::setActiveItem ( MenuItem item)
virtual

Set the active index to a new menu item, the active item is the one that is selected for editing and other display purposes. You must never pass null to this method, and you are returned the index in the array that is now selected.

Returns
the active item index.

Reimplemented in tcgfx::BaseGraphicalRenderer.

◆ findActiveItem()

int BaseMenuRenderer::findActiveItem ( MenuItem root)

Find the active item offset in the list

Parameters
rootthe root item
Returns
the position 0 based.

◆ setFirstWidget()

void BaseMenuRenderer::setFirstWidget ( TitleWidget widget)

For menu systems that support title widgets, this will allow the first widget.

Parameters
thefirst widget in a chain of widgets linked by next pointer.

◆ menuAltered()

void BaseMenuRenderer::menuAltered ( )
inline

Called when the menu has been altered, to reset the countdown to reset behaviour

◆ takeOverDisplay()

void BaseMenuRenderer::takeOverDisplay ( RendererCallbackFn  displayFn = nullptr)

In order to take over the display, provide a callback function that will receive the regular render call backs instead of this renderer. If you have already registered a custom drawing class that implements CustomDrawing by calling setCustomDrawing(..) then you can omit the display function parameter, and your custom drawing class will be called instead. Unlike standard drawing you callback must include api calls that would reset the display to a known state for example when using U8G2 library you must call setDrawColor method prior to any other calls

Parameters
displayFnthe callback to render the display

◆ giveBackDisplay()

void BaseMenuRenderer::giveBackDisplay ( )

Call this method to clear custom display rendering after a call to takeOverDisplay. It will cause a complete repaint of the display.

◆ resetToDefault()

void BaseMenuRenderer::resetToDefault ( )

Used to reset the display to it's default state, root menu, nothing being edited

◆ redrawRequirement()

void BaseMenuRenderer::redrawRequirement ( MenuRedrawState  state)
inline

Sets the type of redraw that is needed

Parameters
statethe required redraw

◆ invalidateAll()

void BaseMenuRenderer::invalidateAll ( )
inline

Completely invalidate all drawing and instigate a complete redraw of all elements.

◆ countdownToDefaulting()

void BaseMenuRenderer::countdownToDefaulting ( )
protected

set up a countdown to default back to the submenu


The documentation for this class was generated from the following files: