Shellminator V3.0.1
Simple Terminal
Loading...
Searching...
No Matches
ShellminatorButton Class Reference

This class can create a simple plotter object. More...

#include <Shellminator-Buttons.hpp>

Inheritance diagram for ShellminatorButton:
Collaboration diagram for ShellminatorButton:

Public Member Functions

 ShellminatorButton ()
 Empty constructor. More...
 
 ShellminatorButton (const char *name_p)
 Constructor with name. More...
 
void init (Shellminator *parent_p, Stream *channel_p) override
 Init function. More...
 
void draw (bool noClear=false) override
 Draw function. More...
 
void update (int width_p, int height_p) override
 Update function. More...
 
void attachEvent (Shellminator::shellEvent_t event_p)
 Attach optional event. More...
 
void attachTriggerFunction (void(*func_p)(ShellminatorScreen *))
 Attach a callback. More...
 
void setColor (Shellminator::textColor_t color_p)
 You can modify the color of the frame. More...
 
void forceRedraw () override
 
- Public Member Functions inherited from ShellminatorScreen
virtual void draw (bool noClear=false)
 Draw function. More...
 
virtual void init (Shellminator *parent_p, Stream *channel_p)
 Init function. More...
 
virtual void setOrigin (int x, int y)
 Origin of the top left corner. More...
 
virtual void update (int width_p, int height_p)
 Update function. More...
 
virtual void forceRedraw ()
 
int left ()
 Return the coordinate of the left column next to the object. More...
 
int right ()
 Return the coordinate of the right column next to the object. More...
 
int up ()
 Return the coordinate of the upper row next to the object. More...
 
int down ()
 Return the coordinate of the lower row next to the object. More...
 
ShellminatorgetParent ()
 
void attachEndFunction (void(*end_func_p)(Shellminator *))
 
void removeEndFunction ()
 

Private Member Functions

bool isUpper (char c)
 Check if the character is uppercase. More...
 
bool isLower (char c)
 Check if the character is lowercase. More...
 
char toUpper (char c)
 Make the character uppercase. More...
 

Private Attributes

const char * name
 This variable stores a pointer to the name text. More...
 
int textWidth
 This variable stores the name text width. More...
 
bool redraw = true
 This flag shows that redraw is necessary. More...
 
Shellminator::shellEvent_t event
 This variable stores the custom trigger event data. More...
 
char eventText [6]
 This is a buffer to store the event key text. More...
 
int eventTextSize = 0
 This variable stores the event key text size. More...
 
void(* func )(ShellminatorScreen *) = NULL
 Pointer to the event callback function. More...
 
Shellminator::textColor_t color = Shellminator::WHITE
 Button frame color. Default is White. More...
 

Friends

class ShellminatorButtonUT
 

Additional Inherited Members

- Public Attributes inherited from ShellminatorScreen
int row = 1
 It is used by the grid layout. More...
 
int column = 1
 It is used by the grid layout. More...
 
int columnSpan = 1
 It is used by the grid layout. More...
 
int rowSpan = 1
 It is used by the grid layout. More...
 
ShellminatorScreennextElement = NULL
 It is used by the grid layout. More...
 
void(*)(Shellminator *) getEndFunction ()
 
- Protected Attributes inherited from ShellminatorScreen
Shellminatorparent = NULL
 Pointer to the caller terminal object. More...
 
Stream * channel = NULL
 
int width = 1
 Actual width of the object. More...
 
int height = 1
 Actual height of the object. More...
 
int originX = 1
 X coordinate of the origin. More...
 
int originY = 1
 Y coordinate of the origin. More...
 
void(* end_func )(Shellminator *) = NULL
 

Detailed Description

This class can create a simple plotter object.

With this class, you can easily create a plotter object, which is capable of real time plotting. It can be attached to the main terminal with the beginScreen function.

Definition at line 60 of file Shellminator-Buttons.hpp.

Constructor & Destructor Documentation

◆ ShellminatorButton() [1/2]

ShellminatorButton::ShellminatorButton ( )

Empty constructor.

Definition at line 37 of file Shellminator-Buttons.cpp.

◆ ShellminatorButton() [2/2]

ShellminatorButton::ShellminatorButton ( const char *  name_p)

Constructor with name.

This constructor must be used to use the object properly.

Parameters
name_pThis is a string, which will be displayed on the center of the button.

Definition at line 46 of file Shellminator-Buttons.cpp.

Member Function Documentation

◆ attachEvent()

void ShellminatorButton::attachEvent ( Shellminator::shellEvent_t  event_p)

Attach optional event.

Optionally, you can attach a keyboard event to the button. It could be handy when the host terminal emulator does not support keyboard reporting( sadly, Windows currently does this in the emulator... ).

Parameters
event_pA configured structure, that contains the event data.

Example code:

// Create a structure to store the configuration.
// Configure the event to make it trigger for the 's' key.
buttonEvent.data = (uint8_t)'s';
@ SHELL_EVENT_KEY
To identify simple key events like: A, b...
Shell event structure.
shellEventType_t type
Identifies the type of the event.
uint8_t data
In case of SHELL_EVENT_KEY type, stores the corresponding character to the pressed key.

Definition at line 66 of file Shellminator-Buttons.cpp.

Here is the call graph for this function:

◆ attachTriggerFunction()

void ShellminatorButton::attachTriggerFunction ( void(*)(ShellminatorScreen *)  func_p)

Attach a callback.

You can attach a callback function to the button. When a mouse click event is detected on the button, or the attached event triggers, this function will be called.

Parameters
func_pPointer to a function, which will be called.

Example callback function prototype: void buttonEvent( ShellminatorScreen* parent ); A pointer to the caller button is passed to the callback. This way the callback function can access the caller button.

Definition at line 106 of file Shellminator-Buttons.cpp.

◆ draw()

void ShellminatorButton::draw ( bool  noClear = false)
overridevirtual

Draw function.

This function is called by the caller terminal if redraw is requested. If you need to draw your screen, the requestRedraw function must be called on the parent terminal object. The reason for this is to save some CPU time and do not waste it to draw something unnecessarily.

Reimplemented from ShellminatorScreen.

Definition at line 185 of file Shellminator-Buttons.cpp.

Here is the call graph for this function:

◆ forceRedraw()

void ShellminatorButton::forceRedraw ( )
overridevirtual

Reimplemented from ShellminatorScreen.

Definition at line 290 of file Shellminator-Buttons.cpp.

◆ init()

void ShellminatorButton::init ( Shellminator parent_p,
Stream *  channel_p 
)
overridevirtual

Init function.

This function is called by the host terminal, when the plot object gets registered to it. You can put all the initialisation section here.

Parameters
parent_pPointer to the caller terminal object.
channel_pThis is a pointer to a Stream object, which can be used to print the output data.
Note
Please use the channel_p object instead of parent -> channel method. This object can be a regular channel or a buffer accelerated one. The logic behind the buffering and flushing is handled by the caller terminal.

Reimplemented from ShellminatorScreen.

Definition at line 115 of file Shellminator-Buttons.cpp.

◆ isLower()

bool ShellminatorButton::isLower ( char  c)
private

Check if the character is lowercase.

Parameters
cCharacter to be checked.
Returns
Returns true if the input character is lowercase.

Definition at line 278 of file Shellminator-Buttons.cpp.

Here is the caller graph for this function:

◆ isUpper()

bool ShellminatorButton::isUpper ( char  c)
private

Check if the character is uppercase.

Parameters
cCharacter to be checked.
Returns
Returns true if the input character is uppercase.

Definition at line 274 of file Shellminator-Buttons.cpp.

Here is the caller graph for this function:

◆ setColor()

void ShellminatorButton::setColor ( Shellminator::textColor_t  color_p)

You can modify the color of the frame.

Definition at line 110 of file Shellminator-Buttons.cpp.

◆ toUpper()

char ShellminatorButton::toUpper ( char  c)
private

Make the character uppercase.

Parameters
cCharacter to convert to uppercase.
Returns
Returns the uppercase character if the input character was lowercase. Otherwise returns the input character.

Definition at line 282 of file Shellminator-Buttons.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

void ShellminatorButton::update ( int  width_p,
int  height_p 
)
overridevirtual

Update function.

The update function must be used to process events and not to draw the objects. It is called much frequently than, the draw function. All the event handling should be done in the update function, including key and mouse detection along with various events.

Parameters
width_pThe width of the screen area in characters.
height_pThe height of the screen area in characters.

Reimplemented from ShellminatorScreen.

Definition at line 121 of file Shellminator-Buttons.cpp.

Friends And Related Function Documentation

◆ ShellminatorButtonUT

friend class ShellminatorButtonUT
friend

Definition at line 189 of file Shellminator-Buttons.hpp.

Member Data Documentation

◆ color

Shellminator::textColor_t ShellminatorButton::color = Shellminator::WHITE
private

Button frame color. Default is White.

Definition at line 170 of file Shellminator-Buttons.hpp.

◆ event

Shellminator::shellEvent_t ShellminatorButton::event
private

This variable stores the custom trigger event data.

Definition at line 157 of file Shellminator-Buttons.hpp.

◆ eventText

char ShellminatorButton::eventText[6]
private

This is a buffer to store the event key text.

Definition at line 160 of file Shellminator-Buttons.hpp.

◆ eventTextSize

int ShellminatorButton::eventTextSize = 0
private

This variable stores the event key text size.

Definition at line 163 of file Shellminator-Buttons.hpp.

◆ func

void(* ShellminatorButton::func) (ShellminatorScreen *) = NULL
private

Pointer to the event callback function.

It it is null, the callback is disabled.

Definition at line 167 of file Shellminator-Buttons.hpp.

◆ name

const char* ShellminatorButton::name
private

This variable stores a pointer to the name text.

Definition at line 146 of file Shellminator-Buttons.hpp.

◆ redraw

bool ShellminatorButton::redraw = true
private

This flag shows that redraw is necessary.

In this implementation redraw is only required when the screen is resized.

Definition at line 154 of file Shellminator-Buttons.hpp.

◆ textWidth

int ShellminatorButton::textWidth
private

This variable stores the name text width.

Definition at line 149 of file Shellminator-Buttons.hpp.