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 View * init (View *self)
 
static void initialize (Class *clazz)
 
static Checkbox * initWithFrame (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 180 of file Checkbox.c.

180 {
181 static Class *clazz;
182 static Once once;
183
184 do_once(&once, {
185 clazz = _initialize(&(const ClassDef) {
186 .name = "Checkbox",
187 .superclass = _Control(),
188 .instanceSize = sizeof(Checkbox),
189 .interfaceSize = sizeof(CheckboxInterface),
190 .initialize = initialize,
191 .destroy = destroy,
192 });
193 });
194
195 return clazz;
196}
static void destroy(Class *clazz)
Definition Checkbox.c:172
static void initialize(Class *clazz)
Definition Checkbox.c:155
Class * _Control(void)
Definition Control.c:414
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:133
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition View+JSON.h:215
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition View+JSON.h:210
Inlets enable inbound data binding of View attributes through JSON.
Definition View+JSON.h:149
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:225

◆ 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:726
static void emitViewEvent(View *self, ViewEvent code, ident data)
Definition View.c:794
Controls are Views which capture and respond to events.
Definition Control.h:83
unsigned int state
The bit mask of ControlState.
Definition Control.h:117

◆ 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 172 of file Checkbox.c.

172 {
173 release(_check);
174}
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 155 of file Checkbox.c.

155 {
156
157 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
158
159 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
160 ((ViewInterface *) clazz->interface)->init = init;
161
162 ((ControlInterface *) clazz->interface)->captureEvent = captureEvent;
163
164 ((CheckboxInterface *) clazz->interface)->initWithFrame = initWithFrame;
165
166 _check = $(alloc(Image), initWithBytes, check_png, check_png_len - 1, 1.f);
167}
static View * init(View *self)
Definition Checkbox.c:72
static Image * initWithBytes(Image *self, const uint8_t *bytes, size_t length, float pixelDensity)
Definition Image.c:118
Image loading.
Definition Image.h:41
View * initWithFrame(View *self, const SDL_Rect *frame)
Initializes this View with the specified frame.
Definition View.c:1047

◆ 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
140 self->check = $(alloc(ImageView), initWithImage, _check);
141 assert(self->check);
142
143 $((View *) self->box, addSubview, (View *) self->check);
144 $((View *) self, addSubview, (View *) self->box);
145 }
146
147 return self;
148}
static AtlasImage * initWithImage(AtlasImage *self, ImageAtlas *atlas, Image *image)
Definition AtlasImage.c:32
static void addSubview(View *self, View *subview)
Definition PageView.c:49
ImageView * check
The check.
Definition Checkbox.h:93
Control * box
The box.
Definition Checkbox.h:88
ImageViews render an Image in the context of a View hierarchy.
Definition ImageView.h:45

Variable Documentation

◆ _check

Image* _check
static

Definition at line 32 of file Checkbox.c.