48#define _Class _Control
102 $(self, bind, inlets, (Dictionary *) style->
attributes);
119 $(self, bind, inlets, dictionary);
151 assert(simpleSelector);
155 switch (simpleSelector->
type) {
157 if (strcmp(
"highlighted", simpleSelector->
pattern) == 0) {
159 }
else if (strcmp(
"disabled", simpleSelector->
pattern) == 0) {
161 }
else if (strcmp(
"selected", simpleSelector->
pattern) == 0) {
163 }
else if (strcmp(
"focused", simpleSelector->
pattern) == 0) {
165 }
else if (strcmp(
"single", simpleSelector->
pattern) == 0) {
167 }
else if (strcmp(
"multiple", simpleSelector->
pattern) == 0) {
192 $(renderer,
drawBevel, &frame, self->
borderRadius, 1, &this->bevelDarkColor, &this->bevelLightColor);
194 $(renderer,
drawBevel, &frame, self->
borderRadius, 1, &this->bevelLightColor, &this->bevelDarkColor);
207 points[0].x = frame.x;
208 points[0].y = frame.y + frame.h;
210 points[1].x = frame.x + frame.w;
211 points[1].y = frame.y + frame.h;
213 points[2].x = frame.x + frame.w;
214 points[2].y = frame.y;
216 $(renderer,
drawLines, points, lengthof(points), &this->bevelLightColor);
218 points[0].x = frame.x;
219 points[0].y = frame.y + frame.h;
221 points[1].x = frame.x;
222 points[1].y = frame.y;
224 points[2].x = frame.x + frame.w;
225 points[2].y = frame.y;
227 $(renderer,
drawLines, points, lengthof(points), &this->bevelDarkColor);
233 points[0].x = frame.x;
234 points[0].y = frame.y + frame.h;
236 points[1].x = frame.x + frame.w;
237 points[1].y = frame.y + frame.h;
239 points[2].x = frame.x + frame.w;
240 points[2].y = frame.y;
242 $(renderer,
drawLines, points, lengthof(points), &this->bevelDarkColor);
244 points[0].x = frame.x;
245 points[0].y = frame.y + frame.h;
247 points[1].x = frame.x;
248 points[1].y = frame.y;
250 points[2].x = frame.x + frame.w;
251 points[2].y = frame.y;
253 $(renderer,
drawLines, points, lengthof(points), &this->bevelLightColor);
271 this->state &= ~ControlStateHighlighted;
272 this->state &= ~ControlStateFocused;
292 if (this->state != state) {
305#pragma mark - Control
381#pragma mark - Class lifecycle
388 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
392 ((ViewInterface *) clazz->interface)->applyStyle =
applyStyle;
395 ((ViewInterface *) clazz->interface)->init =
init;
397 ((ViewInterface *) clazz->interface)->render =
render;
399 ((ViewInterface *) clazz->interface)->respondToEvent =
respondToEvent;
401 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
402 ((ControlInterface *) clazz->interface)->initWithFrame =
initWithFrame;
404 ((ControlInterface *) clazz->interface)->isFocused =
isFocused;
405 ((ControlInterface *) clazz->interface)->isHighlighted =
isHighlighted;
406 ((ControlInterface *) clazz->interface)->isSelected =
isSelected;
407 ((ControlInterface *) clazz->interface)->stateDidChange =
stateDidChange;
419 clazz = _initialize(&(
const ClassDef) {
421 .superclass =
_View(),
422 .instanceSize =
sizeof(
Control),
423 .interfaceSize =
sizeof(ControlInterface),
const EnumName ControlBevelNames[]
const EnumName ControlSelectionNames[]
static void becomeKeyResponder(View *self)
static void stateDidChange(Control *self)
static bool acceptsKeyResponder(const View *self)
static View * init(View *self)
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
static Control * initWithFrame(Control *self, const SDL_Rect *frame)
const EnumName ControlStateNames[]
static void respondToEvent(View *self, const SDL_Event *event)
static void applyStyle(View *self, const Style *style)
static bool matchesSelector(const View *self, const SimpleSelector *simpleSelector)
static bool captureEvent(Control *self, const SDL_Event *event)
static bool isHighlighted(const Control *self)
static void render(View *self, Renderer *renderer)
static void dealloc(Object *self)
static void resignKeyResponder(View *self)
static bool isDisabled(const Control *self)
static void initialize(Class *clazz)
static bool acceptsTouchResponder(const View *self)
static bool isFocused(const Control *self)
static bool isSelected(const Control *self)
Controls are Views which capture and respond to events.
@ ControlSelectionMultiple
ControlState
Control states, which are bit-masked.
@ ControlStateHighlighted
static void drawLines(const Renderer *self, const SDL_Point *points, size_t count, const SDL_Color *color)
static void drawRoundedRect(const Renderer *self, const SDL_Rect *rect, int radius, int width, const SDL_Color *color)
static void drawRect(const Renderer *self, const SDL_Rect *rect, const SDL_Color *color)
static void drawBevel(const Renderer *self, const SDL_Rect *rect, int radius, int width, const SDL_Color *topLeft, const SDL_Color *bottomRight)
@ SimpleSelectorTypePseudo
@ ViewEventFocus
A Control's state has focus.
@ ViewEventBlur
A Control has lost focus.
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
static void invalidateStyle(View *self)
static void setNeedsLayout(View *self)
static SDL_Rect renderFrame(const View *self)
static void emitViewEvent(View *self, ViewEvent code, ident data)
Controls are Views which capture and respond to events.
unsigned int state
The bit mask of ControlState.
SDL_Color bevelLightColor
The bevel color for the lit edges.
bool isDisabled(const Control *self)
SDL_Color bevelDarkColor
The bevel color for the shadowed edges.
Inlets enable inbound data binding of View attributes through JSON.
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
SimpleSelectorType type
The SimpleSelectorType.
char * pattern
The pattern, as provided by the user.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
int borderRadius
The corner radius applied to the background, border and bevel.
bool matchesSelector(const View *self, const SimpleSelector *simpleSelector)