GUI Toolkit for TI nSpire  0.55 beta (dated 2021-03-21)
A GUI toolkit for Ndless-TI NSpire using SDL and Ndless libraries.
CommuterWidget Class Reference

#include <CommuterWidget.h>

Inheritance diagram for CommuterWidget:
Collaboration diagram for CommuterWidget:

Public Types

enum  commutertype { style1 = 0, style2 = 1, style3 = 2, style4 = 3 }
 

Public Member Functions

 CommuterWidget ()
 
 CommuterWidget (char *l, int x, int y, int w, int h, Widget *p)
 
virtual ~CommuterWidget ()
 
virtual void invert ()
 
virtual bool isticked (void)
 
virtual void logic (CursorTask *mouse, KeyboardTask *keyboard) override
 
virtual void render (SDL_Surface *screen, ColorEngine *colors, FontEngine *fonts) override
 
virtual void settype (commutertype type)
 
virtual commutertype gettype ()
 
virtual void setnormal ()
 
virtual void setreversed ()
 
virtual bool isreversed ()
 
- Public Member Functions inherited from ButtonWidget
 ButtonWidget ()
 
 ButtonWidget (char *l, int x, int y, int w, int h, Widget *p)
 
 ~ButtonWidget ()
 
virtual bool ispressed ()
 
- Public Member Functions inherited from Widget
 Widget (char *l, int x, int y, int w, int h, Widget *p)
 
virtual void focus (Widget *emitter)
 
virtual void unfocusup (Widget *emitter)
 
virtual void unfocusdown (Widget *emitter)
 
virtual void addchild (Widget *child)
 
virtual void setdimensions (int mx, int my, int mw, int mh)
 
virtual void setxpos (int mx)
 
virtual void setypos (int my)
 
virtual void setwidth (int mw)
 
virtual void setheight (int mh)
 
virtual void setlabel (char *l)
 
virtual void setcontainerstatus (bool status)
 
virtual void setparent (Widget *p)
 
virtual void setvisible ()
 
virtual void setinvisible ()
 
virtual void enable ()
 
virtual void disable ()
 
virtual void adjust ()
 
virtual int getxpos ()
 
virtual int getypos ()
 
virtual int getwidth ()
 
virtual int getheight ()
 
virtual int getuseablexpos ()
 
virtual int getuseableypos ()
 
virtual int getuseablewidth ()
 
virtual int getuseableheight ()
 
virtual char * getlabel ()
 
virtual bool getcontainerstatus ()
 
virtual Widgetgetparent ()
 
virtual bool getisenabled ()
 
virtual bool isvisible ()
 
virtual char * getwidgettype ()
 
virtual void linkonclick (void(*func)(char *))
 
virtual void linkonrelease (void(*func)(char *))
 
virtual void linkonhover (void(*func)(char *))
 

Additional Inherited Members

- Protected Member Functions inherited from Widget
virtual bool cursoron (CursorTask *mouse)
 
- Protected Attributes inherited from Widget
bool has_focus = false
 
bool is_enabled = true
 
bool is_visible = true
 
char * widgettype
 
char * label
 
int xpos
 
int xrel
 
int ypos
 
int yrel
 
int width
 
int widrel
 
int height
 
int heirel
 
bool is_container = false
 
bool is_hovering = false
 
Widgetparent = nullptr
 
int nbchildren
 
std::vector< Widget * > children
 
void(* clickfunction )(char *) = nullptr
 
void(* releasefunction )(char *) = nullptr
 
void(* hoverfunction )(char *) = nullptr
 

Detailed Description

Example of program using CommuterWidget controls

The following simple example demonstrates how to use the CommuterWidget controls.

Examples of usage:

#include "Toolkit/GUIToolkit.h"
int main ( int argc, char** argv )
{
bool done = false;
MyApp->setuniformbackgroundcolor(0, 0, 0);
DesktopWidget *desktop1 = new DesktopWidget( (char*) "First Desktop", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, nullptr );
WindowWidget *window = new WindowWidget( (char*) "Examples of CommuterWidgets", 5, 5, 310, 230, desktop1 );
ContainerVWidget *containervert = new ContainerVWidget( (char*) "container", 1, 1, 1, 1, window );
LabelWidget *labelB = new LabelWidget( (char*) "Examples of CommuterWidget", 1, 1, 1, 1, containervert );
ContainerHWidget *contH1 = new ContainerHWidget( (char*) "container", 1, 1, 1, 1, containervert );
CommuterWidget *com11 = new CommuterWidget( (char*) "St.1 Normal", 1, 1, 1, 1, contH1 );
com11->settype( CommuterWidget::style1 );
com11->setnormal();
CommuterWidget *com12 = new CommuterWidget( (char*) "St.1 Reverse", 1, 1, 1, 1, contH1 );
com12->settype( CommuterWidget::style1 );
com12->setreversed();
ContainerHWidget *contH2 = new ContainerHWidget( (char*) "container", 1, 1, 1, 1, containervert );
CommuterWidget *com21 = new CommuterWidget( (char*) "St.2 Normal", 1, 1, 1, 1, contH2 );
com21->settype( CommuterWidget::style2 );
com21->setnormal();
CommuterWidget *com22 = new CommuterWidget( (char*) "St.2 Reverse", 1, 1, 1, 1, contH2 );
com22->settype( CommuterWidget::style2 );
com22->setreversed();
ContainerHWidget *contH3 = new ContainerHWidget( (char*) "container", 1, 1, 1, 1, containervert );
CommuterWidget *com31 = new CommuterWidget( (char*) "St.3 Normal", 1, 1, 1, 1, contH3 );
com31->settype( CommuterWidget::style3 );
com31->setnormal();
CommuterWidget *com32 = new CommuterWidget( (char*) "St.3 Reverse", 1, 1, 1, 1, contH3 );
com32->settype( CommuterWidget::style3 );
com32->setreversed();
ContainerHWidget *contH4 = new ContainerHWidget( (char*) "container", 1, 1, 1, 1, containervert );
CommuterWidget *com41 = new CommuterWidget( (char*) "St.4 Normal", 1, 1, 1, 1, contH4 );
com41->settype( CommuterWidget::style4 );
com41->setnormal();
CommuterWidget *com42 = new CommuterWidget( (char*) "St.4 Reverse", 1, 1, 1, 1, contH4 );
com42->settype( CommuterWidget::style4 );
com42->setreversed();
// the button to be clicked to quit
ButtonWidget *buttonQuit = new ButtonWidget( (char*) "Quit [CTRL]+[ESC]", 1, 1, 1, 1, contH );
// We ask for an automatic positioning of the widgets in the grid
// Note : this will fully override the dimensions given to the Widgets manually
window->adjust();
MyApp->addchild( desktop1 );
KeyboardTask *keyboard = MyApp->getkeyboardhandler();
// We render the app for the first time so what we can see what's happening on the screen
MyApp->render();
while (!done)
{
MyApp->logic();
if ((keyboard->kbCTRL && keyboard->kbESC) || buttonQuit->ispressed()) done = true;
}
return 0;
}

CommuterWidget class.

The class to be used for using a CommuterWidget control widget. CommuterWidget inherits from ButtonWidget class.

See also
ButtonWidget

Examples of usage:

CommuterWidget* myCommuter = new CommuterWidget(); // Simple constructor, will need specific properties assignement later
CommuterWidget* myCommuter = new CommuterWidget( "I am a CommuterWidget", 10, 50, 100, 15, parent ); // Full constructor

Member Enumeration Documentation

◆ commutertype

Enumerator for CommuterWidget style.

Gives the style of CommuterWidget (of the colors of both backgroud and commuter button). style1 the commuter background is blank and the button also style2 the commuter background is blank and the button is colorized style3 the commuter background is blank and the button is colorized in color depending on switch position style4 the commuter background and the button are colorized in color depending on switch position

Constructor & Destructor Documentation

◆ CommuterWidget() [1/2]

CommuterWidget::CommuterWidget ( )
inline

Simple constructor.

Widget properties are set to default, nothing more. Simple constructor, will need specific properties assignement later.

Parameters
None
Returns
Nothing
See also
ButtonWidget() or Widget()

◆ CommuterWidget() [2/2]

CommuterWidget::CommuterWidget ( char *  l,
int  x,
int  y,
int  w,
int  h,
Widget p 
)
inline

Advanced constructor.

Widget properties are set with parameters values given at call.

Parameters
l: text string (char*) that will be used as the widget textual content
x: position x in pixels relatively to the parent widget usable drawspace
y: position y in pixels relatively to the parent widget usable drawspace
w: width in pixel of the widget
h: height in pixel of the widget
p: pointer type to a Widget* to create a link with the parent widget (if any).
Note
p should be set to nullptr if no parent exists
p can be omitted (i.e. set to nullptr) and parent-children link can be created with a call to the Widget::addchild() method of the parent Widget.
Returns
Nothing
See also
ButtonWidget( char*, int, int, int, int, Widget* ) or Widget( char*, int, int, int, int, Widget* )

◆ ~CommuterWidget()

virtual CommuterWidget::~CommuterWidget ( )
inlinevirtual

Object destructor

Object destructor, remove all trace of the object and free allocated memory

Parameters
None
Returns
Nothing
See also
~Widget()

Member Function Documentation

◆ gettype()

virtual commutertype CommuterWidget::gettype ( )
inlinevirtual

CommuterWidget style getter.

Gives the style of CommuterWidget

Parameters
None
Returns
The corresponding type of CommuterWidget style
See also
commutertype

◆ invert()

virtual void CommuterWidget::invert ( )
inlinevirtual

Invert the CommuterWidget status

Invert the CommuterWidget status, if unticked --> ticked and if ticked --> unticked

Parameters
None
Returns
None
Note
It changes the internal property is_ticked of the CommuterWidget

◆ isreversed()

virtual bool CommuterWidget::isreversed ( )
inlinevirtual

CommuterWidget normal/reveresed style getter.

Ask if the CommuterWidget is normal or reversed

Parameters
None
Returns
Nothing
See also
setnormal() or setreversed()

◆ isticked()

virtual bool CommuterWidget::isticked ( void  )
inlinevirtual

Is the CommuterWidget ticked ?

Gives the status of the CommuterWidget (switched or not).

Parameters
None
Returns
Boolean value : true if the CommuterWidget is switched, false otherwise

◆ logic()

void CommuterWidget::logic ( CursorTask mouse,
KeyboardTask keyboard 
)
overridevirtual

The CommuterWidget logic mechanism

Method to be launched to drive the the mechanics behind the widget behavior.

Parameters
mouse: pointer to a CursorTask handler object serving at passing the mouse (Touchpad) state and position
keyboard: pointer to a KeyboardTask handler object serving at passing the keyboard state
Returns
Nothing, but will launch the logic() method of all the Widgets belonging to chidren (vector<Widget*>)
Note
This method overrides Widget::logic( CursorTask*, KeyboardTask*)
This method is not intended to be used by a direct call from the user, it is normally called through cascaded calls to children->logic() from the WidgetApplication class
Direct call can be used when the Widget is used out of the WidgetApplication 'ecosystem', for example in an application that just use few individual widgets (not recommended cause it may need intensive work from the developper to create adequate working conditions).
Warning
Before calling the logic method, a mouse handler and a keyboard handler must be instancied and properly updated through their respective logic() methods. This is normally done by using the WidgetApplication class.

Reimplemented from ButtonWidget.

◆ render()

void CommuterWidget::render ( SDL_Surface *  screen,
ColorEngine colors,
FontEngine fonts 
)
overridevirtual

The CommuterWidget render method.

Method to be launched to draw the CommuterWidget.

Parameters
screen: pointer to a SDL_Surface object where we would like to draw the wigdet
colors: pointer to a ColorEngine object giving all the color options to be used (theme) for drawing the widget
fonts: pointer to a FontEngine object giving all the fonts options to be used (theme) for drawing the widget
Returns
Nothing, but will launch the render() method of all the Widgets belonging to chidren (vector<Widget*>)
Note
This method overrides Widget::render( SDL_Surface*, ColorEngine*, FontEngine*)
This method is not intended to be used by a direct call from the user, it is normally called through cascaded calls to children->render() from the WidgetApplication class.
Direct call can be used when the Widget is used out of the WidgetApplication 'ecosystem', for example in an application that just use few individual widgets (not recommended cause it may need intensive work from the developper to create adequate working conditions).
Warning
Before calling the render method, a SDL_Surface (i.e. a rendering context) as well as a ColorEngine and FontEngine objects must be properly instancied. This is normally done by using the WidgetApplication class.

Reimplemented from ButtonWidget.

◆ setnormal()

virtual void CommuterWidget::setnormal ( )
inlinevirtual

CommuterWidget normal style setter.

Set the normal order of the CommuterWidget (false = switch on the left / true = switch on the right)

Parameters
None
Returns
Nothing

◆ setreversed()

virtual void CommuterWidget::setreversed ( )
inlinevirtual

CommuterWidget reversed style setter.

Set the normal order of the CommuterWidget (false = switch on the right / true = switch on the left)

Parameters
None
Returns
Nothing

◆ settype()

virtual void CommuterWidget::settype ( commutertype  type)
inlinevirtual

CommuterWidget style setter.

Gives the style of CommuterWidget

Parameters
typerefers to one of the styles given by the tick enumerator
Returns
Nothing
See also
commutertype

The documentation for this class was generated from the following files:
DesktopWidget
Definition: DesktopWidget.h:7
WidgetApplication
Definition: WidgetApplication.h:32
ButtonWidget::ispressed
virtual bool ispressed()
Definition: ButtonWidget.cpp:5
ButtonWidget::ButtonWidget
ButtonWidget()
Definition: ButtonWidget.h:102
CommuterWidget::setnormal
virtual void setnormal()
Definition: CommuterWidget.h:228
CommuterWidget::CommuterWidget
CommuterWidget()
Definition: CommuterWidget.h:117
ContainerVWidget
Definition: ContainerVWidget.h:105
ContainerHWidget
Definition: ContainerHWidget.h:105
WindowWidget
Definition: WindowWidget.h:7
ButtonWidget
Definition: ButtonWidget.h:91
CommuterWidget
Definition: CommuterWidget.h:106
KeyboardTask
Definition: KeyboardTask.h:99
CommuterWidget::settype
virtual void settype(commutertype type)
Definition: CommuterWidget.h:212
LabelWidget
Definition: LabelWidget.h:15
CommuterWidget::setreversed
virtual void setreversed()
Definition: CommuterWidget.h:236