ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Checkbox.c File Reference
#include <assert.h>
#include "Checkbox.h"
#include "../Assets/check.png.h"

Go to the source code of this file.

Macros

#define _Class   _Checkbox
 

Functions

Class * _Checkbox (void)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static bool captureEvent (Control *self, const SDL_Event *event)
 
static void dealloc (Object *self)
 
static void destroy (Class *clazz)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static CheckboxinitWithFrame (Checkbox *self, const SDL_Rect *frame)
 

Variables

static Image_check
 

Macro Definition Documentation

◆ _Class

#define _Class   _Checkbox

Definition at line 30 of file Checkbox.c.

Function Documentation

◆ _Checkbox()

Class * _Checkbox ( void  )

Definition at line 184 of file Checkbox.c.

184 {
185 static Class *clazz;
186 static Once once;
187
188 do_once(&once, {
189 clazz = _initialize(&(const ClassDef) {
190 .name = "Checkbox",
191 .superclass = _Control(),
192 .instanceSize = sizeof(Checkbox),
193 .interfaceOffset = offsetof(Checkbox, interface),
194 .interfaceSize = sizeof(CheckboxInterface),
196 .destroy = destroy,
197 });
198 });
199
200 return clazz;
201}
static void destroy(Class *clazz)
Definition Checkbox.c:176
static void initialize(Class *clazz)
Definition Checkbox.c:159
Class * _Control(void)
Definition Control.c:391
Checkboxes are toggle Controls that respond to click events.
Definition Checkbox.h:67

◆ awakeWithDictionary()

static void awakeWithDictionary ( View self,
const Dictionary *  dictionary 
)
static
See also
View::awakeWithDictionary(View *, const Dictionary *)

Definition at line 56 of file Checkbox.c.

56 {
57
58 super(View, self, awakeWithDictionary, dictionary);
59
60 Checkbox *this = (Checkbox *) self;
61
62 const Inlet inlets[] = MakeInlets(
63 MakeInlet("check", InletTypeView, &this->check, NULL)
64 );
65
66 $(self, bind, inlets, dictionary);
67}
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
Definition Checkbox.c:56
@ InletTypeView
Definition View+JSON.h:139
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition View+JSON.h:221
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition View+JSON.h:216
Inlets enable inbound data binding of View attributes through JSON.
Definition View+JSON.h:155
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134

◆ captureEvent()

static bool captureEvent ( Control self,
const SDL_Event *  event 
)
static
See also
Control::captureEvent(Control *, const SDL_Event *)

Definition at line 81 of file Checkbox.c.

81 {
82
83 Checkbox *this = (Checkbox *) self;
84
85 View *view = (View *) self;
86
87 const View *box = (View *) this->box;
88
89 switch (event->type) {
90 case SDL_EVENT_MOUSE_BUTTON_DOWN:
91 if ($(box, didReceiveEvent, event)) {
93 return true;
94 }
95 break;
96 case SDL_EVENT_MOUSE_BUTTON_UP:
97 if ($(box, didReceiveEvent, event)) {
99 self->state &= ~ControlStateHighlighted;
100 if (this->delegate.didToggle) {
101 this->delegate.didToggle(this);
102 }
103 $(view, emitViewEvent, ViewEventChange, NULL);
104 return true;
105 }
106 break;
107 case SDL_EVENT_KEY_DOWN:
108 switch (event->key.key) {
109 case SDLK_SPACE:
110 case SDLK_KP_SPACE:
111 case SDLK_RETURN:
112 case SDLK_KP_ENTER:
114 self->state &= ~ControlStateHighlighted;
115 if (this->delegate.didToggle) {
116 this->delegate.didToggle(this);
117 }
118 $(view, emitViewEvent, ViewEventChange, NULL);
119 return true;
120 }
121 }
122
123 return super(Control, self, captureEvent, event);
124}
static bool captureEvent(Control *self, const SDL_Event *event)
Definition Checkbox.c:81
@ ControlStateHighlighted
Definition Control.h:67
@ ControlStateSelected
Definition Control.h:68
@ ViewEventChange
A Control's input value has changed.
Definition Types.h:110
static bool didReceiveEvent(const View *self, const SDL_Event *event)
Definition View.c:668
static void emitViewEvent(View *self, ViewEvent code, ident data)
Definition View.c:736
Controls are Views which capture and respond to events.
Definition Control.h:83
unsigned int state
The bit mask of ControlState.
Definition Control.h:104

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

Definition at line 39 of file Checkbox.c.

39 {
40
41 Checkbox *this = (Checkbox *) self;
42
43 memset(&this->delegate, 0, sizeof(this->delegate));
44
45 release(this->box);
46 release(this->check);
47
48 super(Object, self, dealloc);
49}
static void dealloc(Object *self)
Definition Checkbox.c:39

◆ destroy()

static void destroy ( Class *  clazz)
static
See also
Class::destroy(Class *)

Definition at line 176 of file Checkbox.c.

176 {
177 release(_check);
178}
static Image * _check
Definition Checkbox.c:32

◆ init()

static View * init ( View self)
static
See also
View::init(View *)

Definition at line 72 of file Checkbox.c.

72 {
73 return (View *) $((Checkbox *) self, initWithFrame, NULL);
74}
static Checkbox * initWithFrame(Checkbox *self, const SDL_Rect *frame)
Definition Checkbox.c:132

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 159 of file Checkbox.c.

159 {
160
161 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
162
163 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
164 ((ViewInterface *) clazz->interface)->init = init;
165
166 ((ControlInterface *) clazz->interface)->captureEvent = captureEvent;
167
168 ((CheckboxInterface *) clazz->interface)->initWithFrame = initWithFrame;
169
170 _check = $(alloc(Image), initWithBytes, check_png, check_png_len - 1);
171}
static View * init(View *self)
Definition Checkbox.c:72
static Image * initWithBytes(Image *self, const uint8_t *bytes, size_t length)
Definition Image.c:88
Image loading.
Definition Image.h:38
View * initWithFrame(View *self, const SDL_Rect *frame)
Initializes this View with the specified frame.
Definition View.c:989

◆ initWithFrame()

static Checkbox * initWithFrame ( Checkbox self,
const SDL_Rect *  frame 
)
static

Definition at line 132 of file Checkbox.c.

132 {
133
134 self = (Checkbox *) super(Control, self, initWithFrame, frame);
135 if (self) {
136
137 self->box = $(alloc(Control), initWithFrame, frame);
138 assert(self->box);
139
141
142 self->check = $(alloc(ImageView), initWithImage, _check);
143 assert(self->check);
144
146
147 $((View *) self->box, addSubview, (View *) self->check);
148 $((View *) self, addSubview, (View *) self->box);
149 }
150
151 return self;
152}
static Button * initWithImage(Button *self, Image *image)
Definition Button.c:161
static void addSubview(View *self, View *subview)
Definition PageView.c:49
@ ViewAutoresizingFill
Definition View.h:90
@ ViewAlignmentMiddleCenter
Definition View.h:73
ImageView * check
The check.
Definition Checkbox.h:93
Control * box
The box.
Definition Checkbox.h:88
View view
The superclass.
Definition Control.h:88
ImageViews render an Image in the context of a View hierarchy.
Definition ImageView.h:45
View view
The superclass.
Definition ImageView.h:50
ViewAlignment alignment
The alignment.
Definition View.h:150
int autoresizingMask
The ViewAutoresizing bitmask.
Definition View.h:155

Variable Documentation

◆ _check

Image* _check
static

Definition at line 32 of file Checkbox.c.