discoverpixy
Data Structures | Macros | Typedefs | Functions
Checkbox
Collaboration diagram for Checkbox:

Data Structures

struct  CHECKBOX_STRUCT
 

Macros

#define CHECKBOX_WIN_FG_COLOR   RGB(32,161,34)
 

Typedefs

typedef void(* CHECKBOX_CALLBACK) (void *checkbox, bool checked)
 

Functions

bool gui_checkbox_add (CHECKBOX_STRUCT *checkbox)
 
void gui_checkbox_remove (CHECKBOX_STRUCT *checkbox)
 
void gui_checkbox_update (CHECKBOX_STRUCT *checkbox)
 
void gui_checkbox_redraw (CHECKBOX_STRUCT *checkbox)
 

Detailed Description

The Checkbox Gui-Element is a clickable, rectangular box with an optional tickmark inside of it. When the checkbox is pressed and released it's tick state changes and you will be notified via the provided callback.

Macro Definition Documentation

#define CHECKBOX_WIN_FG_COLOR   RGB(32,161,34)

Definition at line 82 of file checkbox.h.

Typedef Documentation

typedef void(* CHECKBOX_CALLBACK) (void *checkbox, bool checked)

Prototype for Event Listeners (called when the checkbox state has changed)

Note
You should NOT execute long running things in this callback nor should you update the gui. But you can call gui_screen_navigate() for instance.
Parameters
checkboxThe pointer to the CHECKBOX_STRUCT where to corresponding Checkbox has changed the state
checkedA boolean which indicates whether the checkbox is now checked or not.

Definition at line 45 of file checkbox.h.

Function Documentation

bool gui_checkbox_add ( CHECKBOX_STRUCT checkbox)

Adds a checkbox. Your Callback will be called from now on, if the checkbox changes state

Parameters
checkboxA Pointer to the preinitialized CHECKBOX_STRUCT
Returns
true on success

Definition at line 70 of file checkbox.c.

71 {
72  if (touch_have_empty(1)) { //Check if the touch module can handle one additional area
73  unsigned char size = 0;
74  checkbox->base.hookedActions = PEN_DOWN; //At first we are interested in PEN_DOWN events
75  checkbox->base.callback = checkboxes_cb; //Use our own callback for the touch area events
76 
77  //Check the size of the checkbox
78  if (checkbox->base.x2 > checkbox->base.x1) {
79  size = checkbox->base.x2 - checkbox->base.x1; //use width a as size
80  }
81 
82  if (checkbox->base.y2 > checkbox->base.y1) {
83  if ((checkbox->base.y2 - checkbox->base.y1) > size) { //height is larger than size
84  size = checkbox->base.y2 - checkbox->base.y1; //use height as size
85  }
86  }
87 
88  if (size == 0) { //no size found (maybe swap x2 and x1 or y2 and y1 ?)
89  return false; //signal error
90  }
91 
92  if ((size & 0x01)) { //the size is an odd number
93  size++; //make size an even number
94  }
95 
96  //Correct x2,y2 so that the checkbox is quadratic
97  checkbox->base.x2 = checkbox->base.x1 + size;
98  checkbox->base.y2 = checkbox->base.y1 + size;
99 
100  gui_checkbox_redraw(checkbox);//Call redraw method, which will take care of the drawing of the entire checkbox
101 
102  return touch_register_area(&checkbox->base); //Register the touch area and receive events for this checkbox, from now on
103  }
104 
105  return false; //no more touch areas left
106 }
bool touch_register_area(TOUCH_AREA_STRUCT *area)
Definition: touch.c:181
Receive an event when the pen goes down inside the region.
Definition: touch.h:54
uint16_t y1
Top Left Y-Coordinate of Area.
Definition: touch.h:75
uint16_t x1
Top Left X-Coordinate of Area.
Definition: touch.h:74
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
TOUCH_CALLBACK callback
Callback which is executed when an event occurred in this Area.
Definition: touch.h:78
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
TOUCH_ACTION hookedActions
Actions to listen to.
Definition: touch.h:73
TOUCH_AREA_STRUCT base
Basic geometry of the Checkbox. You only need to set the x1, y1, x2, y2 members of this struct...
Definition: checkbox.h:51
bool touch_have_empty(unsigned char num)
Definition: touch.c:165
void gui_checkbox_redraw(CHECKBOX_STRUCT *checkbox)
Definition: checkbox.c:108
void checkboxes_cb(void *touchArea, TOUCH_ACTION triggeredAction)
Definition: checkbox.c:34

Here is the call graph for this function:

Here is the caller graph for this function:

void gui_checkbox_redraw ( CHECKBOX_STRUCT checkbox)

Redraws the checkbox. Call this method if you have to redraw the entire screen or if you want to draw a checkbox on top of an image.

Parameters
checkboxA Pointer to the CHECKBOX_STRUCT

Definition at line 108 of file checkbox.c.

109 {
110  //Draw background and border
111  tft_fill_rectangle(checkbox->base.x1 + 1, checkbox->base.y1 + 1, checkbox->base.x2 - 1, checkbox->base.y2 - 1, BACKGROUND_COLOR);
112  tft_draw_rectangle(checkbox->base.x1, checkbox->base.y1, checkbox->base.x2, checkbox->base.y2, BORDER_COLOR);
113 
114  if (checkbox->checked) { //checkbox is currently checked
115  gui_checkbox_update(checkbox); //Call update method which will draw the tickmark
116  }
117 }
uint16_t y1
Top Left Y-Coordinate of Area.
Definition: touch.h:75
void gui_checkbox_update(CHECKBOX_STRUCT *checkbox)
Definition: checkbox.c:125
#define BACKGROUND_COLOR
Definition: checkbox.c:31
uint16_t x1
Top Left X-Coordinate of Area.
Definition: touch.h:74
bool checked
A boolean which indicates whether or not the checkbox is currently checked.
Definition: checkbox.h:53
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
void tft_fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:67
void tft_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:61
#define BORDER_COLOR
Definition: checkbox.c:30
TOUCH_AREA_STRUCT base
Basic geometry of the Checkbox. You only need to set the x1, y1, x2, y2 members of this struct...
Definition: checkbox.h:51

Here is the call graph for this function:

Here is the caller graph for this function:

void gui_checkbox_remove ( CHECKBOX_STRUCT checkbox)

Removes the checkbox. You will no longer receive events for this checkbox. This function will not overdraw the region where the checkbox was located.

Parameters
checkboxA Pointer to the CHECKBOX_STRUCT

Definition at line 119 of file checkbox.c.

120 {
121  //We only need to unregister the touch area, as we have not allocated anything else
123 }
void touch_unregister_area(TOUCH_AREA_STRUCT *area)
Definition: touch.c:195

Here is the call graph for this function:

Here is the caller graph for this function:

void gui_checkbox_update ( CHECKBOX_STRUCT checkbox)

Updates the checkbox. Call this function when you change the state of the checkbox through code.

Parameters
checkboxA Pointer to the CHECKBOX_STRUCT

Definition at line 125 of file checkbox.c.

126 {
127  unsigned int c = (checkbox->checked) ? checkbox->fgcolor : BACKGROUND_COLOR; //color to use for the tickmark
128 
129  //helper points inside the checkbox
130  unsigned int xcent = checkbox->base.x1 + (checkbox->base.x2 - checkbox->base.x1) * 6 / 14;
131  unsigned int yleft = checkbox->base.y2 - (xcent - checkbox->base.x1) - 1 ;
132  unsigned int yright = checkbox->base.y2 - (checkbox->base.x2 - xcent) - 1 ;
133  unsigned int ybot = checkbox->base.y2 - 4;
134 
135  //Draw tickmark as a 3pixel wide line
136  tft_draw_line(checkbox->base.x1 + 3, yleft - 1, xcent, ybot - 1, c);
137  tft_draw_line(checkbox->base.x1 + 3, yleft, xcent, ybot , c);
138  tft_draw_line(checkbox->base.x1 + 3, yleft + 1, xcent, ybot + 1, c);
139  xcent++;
140  ybot--;
141  tft_draw_line(xcent, ybot - 1, checkbox->base.x2 - 3, yright - 1, c);
142  tft_draw_line(xcent, ybot, checkbox->base.x2 - 3, yright + 0, c);
143  tft_draw_line(xcent, ybot + 1, checkbox->base.x2 - 3, yright + 1, c);
144 }
void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:50
#define BACKGROUND_COLOR
Definition: checkbox.c:31
uint16_t x1
Top Left X-Coordinate of Area.
Definition: touch.h:74
bool checked
A boolean which indicates whether or not the checkbox is currently checked.
Definition: checkbox.h:53
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
TOUCH_AREA_STRUCT base
Basic geometry of the Checkbox. You only need to set the x1, y1, x2, y2 members of this struct...
Definition: checkbox.h:51
uint16_t fgcolor
The 16-bit color of the tickmark.
Definition: checkbox.h:52

Here is the call graph for this function:

Here is the caller graph for this function: