discoverpixy
Macros | Functions
checkbox.c File Reference
#include "tft.h"
#include "touch.h"
#include "checkbox.h"
#include <stdio.h>
Include dependency graph for checkbox.c:

Go to the source code of this file.

Macros

#define ACTIVE_COLOR   RGB(251,208,123)
 
#define BORDER_COLOR   RGB(29,82,129)
 
#define BACKGROUND_COLOR   WHITE
 

Functions

void checkboxes_cb (void *touchArea, TOUCH_ACTION triggeredAction)
 
bool gui_checkbox_add (CHECKBOX_STRUCT *checkbox)
 
void gui_checkbox_redraw (CHECKBOX_STRUCT *checkbox)
 
void gui_checkbox_remove (CHECKBOX_STRUCT *checkbox)
 
void gui_checkbox_update (CHECKBOX_STRUCT *checkbox)
 

Macro Definition Documentation

#define ACTIVE_COLOR   RGB(251,208,123)

Definition at line 29 of file checkbox.c.

#define BACKGROUND_COLOR   WHITE

Definition at line 31 of file checkbox.c.

#define BORDER_COLOR   RGB(29,82,129)

Definition at line 30 of file checkbox.c.

Function Documentation

void checkboxes_cb ( void *  touchArea,
TOUCH_ACTION  triggeredAction 
)

Definition at line 34 of file checkbox.c.

35 {
36  TOUCH_AREA_STRUCT* area = (TOUCH_AREA_STRUCT*)touchArea;
37  CHECKBOX_STRUCT* checkbox = (CHECKBOX_STRUCT*)touchArea;
38 
39  switch (triggeredAction) {
40  case PEN_DOWN: //If the user touches the area for the "first time"
41  area->hookedActions = PEN_UP | PEN_LEAVE; //for the future we only want PEN_UP and PEN_LEAVE events
42 
43  //Draw active shadows
44  tft_draw_rectangle(checkbox->base.x1 + 1, checkbox->base.y1 + 1, checkbox->base.x2 - 1, checkbox->base.y2 - 1, ACTIVE_COLOR);
45  tft_draw_rectangle(checkbox->base.x1 + 2, checkbox->base.y1 + 2, checkbox->base.x2 - 2, checkbox->base.y2 - 2, ACTIVE_COLOR);
46  break;
47 
48  case PEN_UP: //If the user took the pen away, while in the area (=toggle checkbox!)
49  checkbox->checked = !checkbox->checked; //Toggle checkbox state
50  gui_checkbox_update(checkbox); //redraw/overdraw tickmark
51 
52  if (checkbox->callback != NULL) { //The user provided a callback
53  checkbox->callback(checkbox, checkbox->checked); //Call the provided callback with the new checked state
54  }
55 
56  // no break statement here!
57  case PEN_LEAVE: //if the user "slided out" of the area
58  area->hookedActions = PEN_DOWN; //for the future we only want PEN_DOWN events
59 
60  //Draw inactive shadows
61  tft_draw_rectangle(checkbox->base.x1 + 1, checkbox->base.y1 + 1, checkbox->base.x2 - 1, checkbox->base.y2 - 1, BACKGROUND_COLOR);
62  tft_draw_rectangle(checkbox->base.x1 + 2, checkbox->base.y1 + 2, checkbox->base.x2 - 2, checkbox->base.y2 - 2, BACKGROUND_COLOR);
63  break;
64 
65  default:
66  break;
67  }
68 }
Receive an event when the pen goes down inside the region.
Definition: touch.h:54
Receive an event when the pen goes up inside the region.
Definition: touch.h:55
#define ACTIVE_COLOR
Definition: checkbox.c:29
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
TOUCH_ACTION hookedActions
Actions to listen to.
Definition: touch.h:73
void tft_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:61
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
CHECKBOX_CALLBACK callback
Callback which is executed when the checkbox changes state.
Definition: checkbox.h:54
Receive an event when the pen leaves the region (pen was inside region before)
Definition: touch.h:57

Here is the call graph for this function:

Here is the caller graph for this function: