Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
control.h
Go to the documentation of this file.
1
2
3/*
4 * control.h
5 *
6* Created on: Mar 20, 2022
7 * Author: micahbly
8 */
9
10#ifndef CONTROL_H_
11#define CONTROL_H_
12
13
14/* about this class: Control
15 *
16 * Provides structures and functions for managing window controls such as close widgets, buttons, sliders, etc.
17 *
18 *** things this class needs to be able to do
19 * Create a control instance from a proto-control (control template struct)
20 * Toggle a control between active to inactive state
21 * Tell a control to reposition itself on the window
22 * Toggle a control's visibility
23 * Render a control onto its parent bitmap
24 * Get and Set the ID of a control
25 * Get and Set the caption of the control (if any)
26 * Get and Set the state of the control
27 * Get and Set the max, minimum, and current values of the control
28 *
29 *
30 * STRETCH GOALS
31 *
32 *
33 * SUPER STRETCH GOALS
34 *
35 *
36 */
37
38
39/*****************************************************************************/
40/* Includes */
41/*****************************************************************************/
42
43// project includes
44
45
46// C includes
47#include <stdbool.h>
48
49
50// A2560 includes
51#include <mcp/syscalls.h>
52#include "a2560k.h"
53
54
55/*****************************************************************************/
56/* Macro Definitions */
57/*****************************************************************************/
58
59#define CONTROL_NO_GROUP -1
60#define CONTROL_MAX_CAPTION_SIZE 128
61
62#define CONTROL_ID_ERROR -2
63#define CONTROL_ID_NOT_FOUND -1
64
65
66/*****************************************************************************/
67/* Enumerations */
68/*****************************************************************************/
69
70typedef enum control_active_state
71{
72 CONTROL_INACTIVE = 0,
73 CONTROL_ACTIVE = 1,
74} control_active_state;
75
76typedef enum control_pushed_state
77{
78 CONTROL_NOT_PRESSED = 0,
79 CONTROL_PRESSED = 1,
80} control_pushed_state;
81
82typedef enum control_type
83{
84 CONTROL_TYPE_ERROR = -1,
107
108
109typedef enum h_align_type
110{
111 H_ALIGN_LEFT = 0,
112 H_ALIGN_CENTER = 1,
113 H_ALIGN_RIGHT = 2
114} h_align_type;
115
116typedef enum v_align_type
117{
118 V_ALIGN_TOP = 0,
119 V_ALIGN_CENTER = 1,
120 V_ALIGN_BOTTOM = 2
121} v_align_type;
122
123
124/*****************************************************************************/
125/* Structs */
126/*****************************************************************************/
127
130{
131 int16_t group_id_;
132 int16_t id_;
138 h_align_type h_align_;
139 v_align_type v_align_;
140 int16_t x_offset_;
141 int16_t y_offset_;
142 int16_t width_;
143 int16_t height_;
145 bool active_;
146 bool enabled_;
147 bool pressed_;
148 bool invalidated_; // if true, the control needs to be re-drawn and re-blitted in the next render pass
149 int16_t value_;
150 int16_t min_;
151 int16_t max_;
152 Bitmap* image_[2][2];
153 char* caption_;
155// char* hover_text_; //! optional string to show in help/hover-text situations
156};
157
158
159
160
161/*****************************************************************************/
162/* Global Variables */
163/*****************************************************************************/
164
165
166/*****************************************************************************/
167/* Public Function Prototypes */
168/*****************************************************************************/
169
170
171// **** CONSTRUCTOR AND DESTRUCTOR *****
172
173// constructor
181Control* Control_New(ControlTemplate* the_template, Window* the_window, Rectangle* the_parent_rect, int16_t control_id, int16_t group_id);
182
183// destructor
184// frees all allocated memory associated with the passed object, and the object itself
187bool Control_Destroy(Control** the_control);
188
189
190
191
192
193
194// **** xxx functions *****
195
196
197
198
199// **** Set xxx functions *****
200
201// uint16_t id_; //! used to identify the control in the control list, etc.
202// control_type type_; //! button vs checkbox vs radio button, etc.
203// int8_t group_; //! group number, if this control is part of a group of controls. -1 (no group) is default. Typical use case: radio buttons.
204// Control* next_; //! next control in the list
205// Window* parent_; //! parent window
206// Rectangle rect_; //! coordinates relative to the parent window (ie, these are not global coordinates)
207// bool visible_;
208// bool active_; //! is the control activated or not (in appearance). Does not affect ability to receive events.
209// bool enabled_; //! is the control enabled or not. If not enabled, it will not receive events.
210// int16_t value_; //! current value of the control
211// int16_t min_; //! minimum allowed value
212// int16_t max_; //! maximum allowed value
213// Bitmap* image_inactive_; //! image of the control in inactive state. size must match the length and width defined in the rect_. If not supplied, the control will be effectively invisible.
214// Bitmap* image_active_up_; //! image of the control when active, and not clicked/pressed. size must match the length and width defined in the rect_. If not supplied, the control will be effectively invisible.
215// Bitmap* image_active_down_; //! image of the control when active, and clicked/depressed. size must match the length and width defined in the rect_. If not supplied, the control will be effectively invisible.
216// char* caption_; //! optional string to draw centered horizontally and vertically on the control. Typical use cases include buttons and labels.
217
218
222int16_t Control_GetID(Control* the_control);
223
228
232bool Control_GetPressed(Control* the_control);
233
234int8_t Control_GetGroup(Control* the_control);
235
240
241Window* Control_GetParent(Control* the_control);
242Rectangle Control_GetRect(Control* the_control);
243bool Control_GetVisible(Control* the_control);
244bool Control_GetActive(Control* the_control);
245bool Control_GetEnabled(Control* the_control);
246int16_t Control_GetValue(Control* the_control);
247int16_t Control_GetMinValue(Control* the_control);
248int16_t Control_GetMaxValue(Control* the_control);
249Bitmap* Control_GetImageUp(Control* the_control);
250Bitmap* Control_GetImageDown(Control* the_control);
251Bitmap* Control_GetImageInactive(Control* the_control);
252char* Control_GetCaption(Control* the_control);
253
254bool Control_SetID(Control* the_control, uint16_t the_new_id);
255bool Control_SetType(Control* the_control, control_type the_type);
256bool Control_SetGroup(Control* the_control, int16_t the_group_id);
257
262bool Control_SetNextControl(Control* the_control, Control* the_next_control);
263
264bool Control_SetParent(Control* the_control, Window* the_window);
265bool Control_SetRect(Control* the_control, Rectangle the_rect);
266
270void Control_SetActive(Control* the_control, bool is_active);
271
275void Control_SetPressed(Control* the_control, bool is_pressed);
276
281void Control_MarkInvalidated(Control* the_control, bool invalidated);
282
283bool Control_SetEnabled(Control* the_control, bool is_enabled);
284bool Control_SetValue(Control* the_control, int16_t the_value);
285bool Control_SetMinValue(Control* the_control, int16_t the_value);
286bool Control_SetMaxValue(Control* the_control, int16_t the_value);
287bool Control_SetImageUp(Control* the_control, Bitmap* the_image);
288bool Control_SetImageDown(Control* the_control, Bitmap* the_image);
289bool Control_SetImageInactive(Control* the_control, Bitmap* the_image);
290bool Control_SetCaption(Control* the_control, char* the_text);
291
295void Control_AlignToParentRect(Control* the_control);
296
297
298
304bool Control_IsRighter(Control* the_control, int16_t* x);
305
311bool Control_IsLefter(Control* the_control, int16_t* x);
312
313
314// **** Get xxx functions *****
315
316
317
318
319
320// **** xxx functions *****
321
328bool Control_UpdateFromTemplate(Control* the_control, ControlTemplate* the_template);
329
330
331
332// **** Render functions *****
333
339void Control_Render(Control* the_control);
340
341
342
343
344#endif /* CONTROL_H_ */
345
346
void Control_SetPressed(Control *the_control, bool is_pressed)
Set the control's pressed/unpressed state.
Definition: control.c:454
control_type Control_GetType(Control *the_control)
Get the control type.
Definition: control.c:622
void Control_SetActive(Control *the_control, bool is_active)
Set the control's active/inactive state.
Definition: control.c:430
bool Control_IsRighter(Control *the_control, int16_t *x)
Compare the control's right-edge coordinate to the passed value If the control is more to the right t...
Definition: control.c:662
Control * Control_GetNextControl(Control *the_control)
Get the next control in the chain.
Definition: control.c:603
bool Control_SetNextControl(Control *the_control, Control *the_next_control)
Links the control to the next control passed.
Definition: control.c:409
bool Control_UpdateFromTemplate(Control *the_control, ControlTemplate *the_template)
Updates the passed control with new theme info from the passed control template Call this when the th...
Definition: control.c:352
void Control_Render(Control *the_control)
Blits the control to the control's parent window if the control is visible, and if it is listed as in...
Definition: control.c:718
bool Control_IsLefter(Control *the_control, int16_t *x)
Compare the control's left-edge coordinate to the passed value If the control is more to the left tha...
Definition: control.c:688
control_type
Definition: control.h:83
@ LABEL
proportional control for handling vertical scrolling within a defined area
Definition: control.h:98
@ SIZE_NORMAL
standard system control; the minimize widget of a window. do not add outside of the context of a wind...
Definition: control.h:94
@ IMAGE_BUTTON
multi-line text input field
Definition: control.h:91
@ TEXT_FIELD
flexible-width button with text caption
Definition: control.h:86
@ FUTURE_GROW_R
not sure these will be treated as generic controls, but reserving the id
Definition: control.h:100
@ RADIO_BUTTON
flexible-width single-line text input field
Definition: control.h:87
@ CLOSE_WIDGET
a fixed height/width button control with no caption, up/down states, and a no defined shape in the th...
Definition: control.h:92
@ SIZE_MAXIMIZE
standard system control; the normal-size widget of a window. do not add outside of the context of a w...
Definition: control.h:95
@ H_SCROLLER
standard system control; the maximize widget of a window. do not add outside of the context of a wind...
Definition: control.h:96
@ V_SCROLLER
proportional control for handling horizontal scrolling within a defined area
Definition: control.h:97
@ FUTURE_GROW_UP
not sure these will be treated as generic controls, but reserving the id
Definition: control.h:101
@ CUSTOM
image?
Definition: control.h:105
@ SIZE_MINIMIZE
standard system control; the close widget of a window. do not add outside of the context of a window ...
Definition: control.h:93
@ TEXT_BOX
the titlebar of a window
Definition: control.h:90
@ TEXT_BUTTON
for functions that return a control type, this value will be returned in the event of an error
Definition: control.h:85
@ FUTURE_GROW_L
static text label
Definition: control.h:99
@ TITLEBAR
checkbox control. do not assign the same group id to each control, as checkboxes are not mutually exc...
Definition: control.h:89
@ RESERVED1x
not sure these will be treated as generic controls, but reserving the id
Definition: control.h:103
@ CHECKBOX
mutually-exclusive radio button control, assign each control in the set the same group id
Definition: control.h:88
@ FUTURE_GROW_DN
not sure these will be treated as generic controls, but reserving the id
Definition: control.h:102
@ RESERVED2x
progress bar?
Definition: control.h:104
Control * Control_New(ControlTemplate *the_template, Window *the_window, Rectangle *the_parent_rect, int16_t control_id, int16_t group_id)
Allocate a Control object.
Definition: control.c:215
bool Control_GetPressed(Control *the_control)
Get the pressed/not pressed state.
Definition: control.c:641
bool Control_Destroy(Control **the_control)
Frees all allocated memory associated with the passed object, and the object itself.
Definition: control.c:312
int16_t Control_GetID(Control *the_control)
Get the ID of the control.
Definition: control.c:584
void Control_AlignToParentRect(Control *the_control)
Set or uppdate the control's position and/or size as appropriate to the control's parent rect Call wh...
Definition: control.c:500
void Control_MarkInvalidated(Control *the_control, bool invalidated)
Mark the specified control is invalidated or validated Note: Marking a control as invalidated causes ...
Definition: control.c:479
Definition: bitmap.h:97
This structure describes an instantiated control on a window.
Definition: control.h:130
bool visible_
height of the control
Definition: control.h:144
bool invalidated_
is the control currently in a clicked/pushed/depressed state or not. Drives rendering choice....
Definition: control.h:148
h_align_type h_align_
coordinates relative to the parent window (ie, these are not global coordinates)
Definition: control.h:138
int16_t y_offset_
horizontal coordinate relative to the parent window's left or right edge. If h_align_ is H_ALIGN_CENT...
Definition: control.h:141
int16_t min_
current value of the control
Definition: control.h:150
int16_t width_
vertical coordinate relative to the parent window's top or bottom edge. If v_align_ is V_ALIGN_CENTER...
Definition: control.h:142
int16_t avail_text_width_
optional string to draw centered horizontally and vertically on the control. Typical use cases includ...
Definition: control.h:154
int16_t max_
minimum allowed value
Definition: control.h:151
Window * parent_win_
next control in the list
Definition: control.h:135
v_align_type v_align_
whether the control should be positioned relative to the left side, right side, or centered
Definition: control.h:139
int16_t x_offset_
whether the control should be positioned relative to the top edge, bottom edge, or centered
Definition: control.h:140
bool enabled_
is the control activated or not (in appearance). Does not affect ability to receive events.
Definition: control.h:146
Rectangle rect_
parent rectangle (the window segment it belongs to: titlebar, contentarea, iconbar
Definition: control.h:137
Control * next_
button vs checkbox vs radio button, etc.
Definition: control.h:134
bool pressed_
is the control enabled or not. If not enabled, it will not receive events.
Definition: control.h:147
int16_t id_
group number, if this control is part of a group of controls. -1 (no group) is default....
Definition: control.h:132
int16_t height_
width of the control
Definition: control.h:143
Rectangle * parent_rect_
parent window
Definition: control.h:136
char * caption_
4 image state bitmaps: [active yes/no][pushed down yes/no]
Definition: control.h:153
control_type type_
used to identify the control in the control list, etc.
Definition: control.h:133
Bitmap * image_[2][2]
maximum allowed value
Definition: control.h:152
A structure that can be used to instantiate a ControlTemplate object instance in a window The Control...
Definition: control_template.h:69
Definition: a2560k.h:1369
Definition: window.h:135