1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://chibios-gfx.com/license.html
*/
/**
* @file include/gwin/checkbox.h
* @brief GWIN Graphic window subsystem header file.
*
* @defgroup Checkbox Checkbox
* @ingroup GWIN
*
* @details GWIN allows it to easily create checkboxes.
*
* @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h
* @pre GWIN_NEED_CHECKBOX must be set to TRUE in your gfxconf.h
* @{
*/
#ifndef _GWIN_CHECKBOX_H
#define _GWIN_CHECKBOX_H
#if GWIN_NEED_CHECKBOX || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
#define GW_CHECKBOX 0x0005
#define GEVENT_GWIN_CHECKBOX (GEVENT_GWIN_FIRST+2)
/*===========================================================================*/
/* Type definitions */
/*===========================================================================*/
typedef struct GEventGWinCheckbox_t {
GEventType type; // The type of this event (GEVENT_GWIN_CHECKBOX)
GHandle checkbox; // The checkbox that has been depressed (actually triggered on release)
bool_t isChecked; // Is the checkbox currently checked or unchecked?
} GEventGWinCheckbox;
typedef enum GCheckboxState_e {
GCHBX_UNCHECKED, GCHBX_CHECKED
} GCheckboxState;
typedef struct GCheckboxColor_t {
color_t border;
color_t checked;
color_t bg;
} GCheckboxColor;
/* custom rendering interface */
typedef void (*GCheckboxDrawFunction)(GHandle gh, bool_t enabled, bool_t state, void* param);
/* A Checkbox window */
typedef struct GCheckboxObject_t {
GWindowObject gwin;
GListener listener;
GCheckboxDrawFunction fn;
GCheckboxColor *colors;
bool_t isChecked;
void *param;
} GCheckboxObject;
/**
* @brief Create a checkbox window.
*
* @param[in] gb The GCheckboxObject structure to initialise. If this is NULL, the structure is dynamically allocated.
* @param[in] x,y The screen co-ordinates for the bottom left corner of the window
* @param[in] width The width of the window
* @param[in] height The height of the window
*
* @note The checkbox is not automatically drawn. Call gwinCheckboxDraw() after changing the checkbox style.
*
* @return NULL if there is no resultant drawing area, otherwise a window handle.
*
* @api
*/
GHandle gwinCheckboxCreate(GCheckboxObject *gb, coord_t x, coord_t y, coord_t width, coord_t height);
/**
* @brief Redraw a checkbox
*
* @param[in] gh The window handle (must be a checkbox window)
*
* @api
*/
void gwinCheckboxDraw(GHandle gh);
/**
* @brief Enable or disable a button
*
* @param[in] gh The window handle (must be a checkbox window)
* @param[in] enabled Enable or disable the button
*
* @api
*/
void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled);
/**
* @brief Set the callback routine to perform a custom drawing.
*
* @param[in] gh The window handle (must be a checkbox window)
* @param[in] fn The function to use to draw the checkbox
* @param[in] param A parameter to pass to the checkbox drawing function
*
* @api
*/
void gwinCheckboxSetCustom(GHandle gh, GCheckboxDrawFunction fn, void *param);
/**
* @brief Enable a checkbox
*
* @api
*/
#define gwinCheckboxEnable(gh) gwinCheckboxSetEnabled( ((GCheckboxObject *)(gh)), TRUE)
/**
* @brief Disable a checkbox
*
* @api
*/
#define gwinCheckboxDisable(gh) gwinCheckboxSetEnabled( ((GCheckboxObject *)(gh)), FALSE)
/**
* @brief Get the state of a checkbox
*
* @param[in] gh The window handle (must be a checkbox window)
*
* @return The state of the checkbox (GCHBX_CHECKED or GCHBX_UNCHECKED)
*
* @api
*/
#define gwinCheckboxGetState(gh) (((GCheckboxObject *)(gh))->isChecked)
/**
* @brief Get the source handle of a checkbox
* @details Get the source handle of a checkbox so the application can listen for events
*
* @param[in] gh The window handle (must be a checkbox window)
*
* @api
*/
#define gwinCheckboxGetSource(gh) ((GSourceHandle)(gh))
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
/**
* @brief Attach a mouse to a checkbox
*
* @param[in] gh The checkbox handle
* @param[in] instance The mouse instance
*
* @api
*/
bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance);
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
#endif /* _GWIN_NEED_CHECKBOX */
#endif /* _GWIN_CHECKBOX_H */
/** @} */
|