47#define _Class _Control
58 release(this->actions);
101 assert(simpleSelector);
105 switch (simpleSelector->
type) {
107 if (strcmp(
"highlighted", simpleSelector->
pattern) == 0) {
109 }
else if (strcmp(
"disabled", simpleSelector->
pattern) == 0) {
111 }
else if (strcmp(
"selected", simpleSelector->
pattern) == 0) {
113 }
else if (strcmp(
"focused", simpleSelector->
pattern) == 0) {
115 }
else if (strcmp(
"single", simpleSelector->
pattern) == 0) {
117 }
else if (strcmp(
"multiple", simpleSelector->
pattern) == 0) {
145 points[0].x = frame.x;
146 points[0].y = frame.y + frame.h;
148 points[1].x = frame.x + frame.w;
149 points[1].y = frame.y + frame.h;
151 points[2].x = frame.x + frame.w;
152 points[2].y = frame.y;
154 $(renderer,
drawLines, points, lengthof(points));
158 points[0].x = frame.x;
159 points[0].y = frame.y + frame.h;
161 points[1].x = frame.x;
162 points[1].y = frame.y;
164 points[2].x = frame.x + frame.w;
165 points[2].y = frame.y;
167 $(renderer,
drawLines, points, lengthof(points));
175 points[0].x = frame.x;
176 points[0].y = frame.y + frame.h;
178 points[1].x = frame.x + frame.w;
179 points[1].y = frame.y + frame.h;
181 points[2].x = frame.x + frame.w;
182 points[2].y = frame.y;
184 $(renderer,
drawLines, points, lengthof(points));
188 points[0].x = frame.x;
189 points[0].y = frame.y + frame.h;
191 points[1].x = frame.x;
192 points[1].y = frame.y;
194 points[2].x = frame.x + frame.w;
195 points[2].y = frame.y;
197 $(renderer,
drawLines, points, lengthof(points));
219 const _Bool didCaptureEvent = $(
this,
captureEvent, event);
220 if (didCaptureEvent) {
222 const Array *actions = (Array *) this->actions;
223 for (
size_t i = 0; i < actions->count; i++) {
225 const Action *action = $(actions, objectAtIndex, i);
232 if (this->state != state) {
236 if (didCaptureEvent) {
243#pragma mark - Control
249 return ((
Action *) obj)->eventType == ((SDL_Event *) data)->type;
268 $(self->actions, addObject, action);
290 self->actions = $$(MutableArray, arrayWithCapacity, 0);
291 assert(self->actions);
345 this->needsLayout =
true;
348#pragma mark - Class lifecycle
355 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
358 ((ViewInterface *) clazz->interface)->applyStyle =
applyStyle;
359 ((ViewInterface *) clazz->interface)->init =
init;
361 ((ViewInterface *) clazz->interface)->render =
render;
362 ((ViewInterface *) clazz->interface)->respondToEvent =
respondToEvent;
364 ((ControlInterface *) clazz->interface)->actionsForEvent =
actionsForEvent;
366 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
367 ((ControlInterface *) clazz->interface)->initWithFrame =
initWithFrame;
368 ((ControlInterface *) clazz->interface)->isDisabled =
isDisabled;
369 ((ControlInterface *) clazz->interface)->isFocused =
isFocused;
370 ((ControlInterface *) clazz->interface)->isHighlighted =
isHighlighted;
371 ((ControlInterface *) clazz->interface)->isSelected =
isSelected;
372 ((ControlInterface *) clazz->interface)->stateDidChange =
stateDidChange;
384 clazz = _initialize(&(
const ClassDef) {
386 .superclass =
_View(),
387 .instanceSize =
sizeof(
Control),
388 .interfaceOffset = offsetof(
Control, interface),
389 .interfaceSize =
sizeof(ControlInterface),
void(* ActionFunction)(Control *control, const SDL_Event *event, ident sender, ident data)
The ActionFunction callback.
const EnumName ControlBevelNames[]
const EnumName ControlSelectionNames[]
static _Bool actionsForEvent_predicate(const ident obj, ident data)
Predicate for actionsForEvent.
const EnumName ControlStateNames[]
static void dealloc(Object *self)
static void initialize(Class *clazz)
Controls are Views which capture events and dispatch Actions.
@ ControlSelectionMultiple
ControlState
Control states, which are bit-masked.
@ ControlStateHighlighted
@ SimpleSelectorTypePseudo
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Actions bind event-driven behavior to Controls.
SDL_EventType eventType
The event type.
Action * initWithEventType(Action *self, SDL_EventType eventType, ActionFunction function, ident sender, ident data)
Initializes this Action with the given function and data.
ActionFunction function
The function.
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Controls are Views which capture events and dispatch Actions.
void stateDidChange(Control *self)
Called when the state of this Control changes.
_Bool captureEvent(Control *self, const SDL_Event *event)
Captures a given event, potentially altering the state of this Control.
Array * actionsForEvent(const Control *self, const SDL_Event *event)
Class * _Control(void)
The Control archetype.
unsigned int state
The bit mask of ControlState.
_Bool isSelected(const Control *self)
void addActionForEventType(Control *self, SDL_EventType eventType, ActionFunction function, ident sender, ident data)
Adds an Action for the given event type to this Control.
_Bool isFocused(const Control *self)
_Bool isHighlighted(const Control *self)
_Bool isDisabled(const Control *self)
Inlets enable inbound data binding of View attributes through JSON.
The Renderer is responsible for rasterizing the View hierarchy of a WindowController.
void drawRect(const Renderer *self, const SDL_Rect *rect)
Draws a rectangle using GL_LINE_LOOP.
void drawLines(const Renderer *self, const SDL_Point *points, size_t count)
Draws line segments between adjacent points using GL_LINE_STRIP.
void setDrawColor(Renderer *self, const SDL_Color *color)
Sets the primary color for drawing operations.
SimpleSelectorType type
The SimpleSelectorType.
char * pattern
The pattern, as provided by the user.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
_Bool bind(View *self, const Inlet *inlets, const Dictionary *dictionary)
Performs data binding for the Inlets described in dictionary.
void invalidateStyle(View *self)
Invalidates the computed Style for this View and its descendants.
void becomeFirstResponder(View *self)
Become the first responder in the View hierarchy.
Class * _View(void)
The View archetype.
void applyStyle(View *self, const Style *style)
Applies the given Style to this View.
_Bool matchesSelector(const View *self, const SimpleSelector *simpleSelector)
void respondToEvent(View *self, const SDL_Event *event)
Responds to the specified event.
SDL_Rect renderFrame(const View *self)
void resignFirstResponder(View *self)
Resigns first responder priority.
_Bool acceptsFirstResponder(const View *self)
void render(View *self, Renderer *renderer)
Renders this View using the given renderer.