ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions
Theme.c File Reference
#include <assert.h>
#include <Objectively/JSONSerialization.h>
#include "Log.h"
#include "Theme.h"
#include "View.h"
#include "WindowController.h"

Go to the source code of this file.

Macros

#define _Class   _Theme
 

Functions

Class * _Theme (void)
 
static void addStylesheet (Theme *self, Stylesheet *stylesheet)
 
static StylecomputeStyle (const Theme *self, const View *view)
 
static ident computeStyle_reduce (const ident obj, ident accumulator, ident data)
 Reducer for computeStyle. More...
 
static void dealloc (Object *self)
 
static Themeinit (Theme *self)
 
static void initialize (Class *clazz)
 
static void removeStylesheet (Theme *self, Stylesheet *stylesheet)
 
static Themetheme (SDL_Window *window)
 

Macro Definition Documentation

◆ _Class

#define _Class   _Theme

Definition at line 33 of file Theme.c.

Function Documentation

◆ _Theme()

Class * _Theme ( void  )

Definition at line 175 of file Theme.c.

175 {
176 static Class *clazz;
177 static Once once;
178
179 do_once(&once, {
180 clazz = _initialize(&(const ClassDef) {
181 .name = "Theme",
182 .superclass = _Object(),
183 .instanceSize = sizeof(Theme),
184 .interfaceOffset = offsetof(Theme, interface),
185 .interfaceSize = sizeof(ThemeInterface),
187 });
188 });
189
190 return clazz;
191}
static void initialize(Class *clazz)
Definition: Theme.c:160
The Theme type.
Definition: Theme.h:51

◆ addStylesheet()

static void addStylesheet ( Theme self,
Stylesheet stylesheet 
)
static

Definition at line 55 of file Theme.c.

55 {
56 $((MutableArray *) self->stylesheets, addObject, stylesheet);
57}
MutableArray * stylesheets
The Stylesheets, in order of priority.
Definition: Theme.h:67

◆ computeStyle()

static Style * computeStyle ( const Theme self,
const View view 
)
static

Definition at line 103 of file Theme.c.

103 {
104
105 assert(view);
106
107 Style *style = $(alloc(Style), initWithAttributes, NULL);
108 assert(style);
109
110 return $((Array *) self->stylesheets, reduce, computeStyle_reduce, style, (ident) view);
111}
static ident computeStyle_reduce(const ident obj, ident accumulator, ident data)
Reducer for computeStyle.
Definition: Theme.c:62
The Style type.
Definition: Style.h:43
Style * initWithAttributes(Style *self, const Dictionary *attributes)
Initializes this Style with the given attributes.
Definition: Style.c:292

◆ computeStyle_reduce()

static ident computeStyle_reduce ( const ident  obj,
ident  accumulator,
ident  data 
)
static

Reducer for computeStyle.

Definition at line 62 of file Theme.c.

62 {
63
64 const Stylesheet *stylesheet = obj;
65
66 const View *view = data;
67
68 const Array *selectors = (Array *) stylesheet->selectors;
69 for (size_t i = 0; i < selectors->count; i++) {
70
71 Selector *selector = $(selectors, objectAtIndex, i);
72 if ($(selector, matchesView, view)) {
73
74 assert(selector->style);
75
76 if (MVC_LogEnabled(SDL_LOG_PRIORITY_VERBOSE)) {
77
78 String *this = $((Object *) selector, description);
79 String *that = $((Object *) view, description);
80
81 MVC_LogVerbose("%s -> %s\n", this->chars, that->chars);
82
83 release(this);
84 release(that);
85 }
86
87 if ($(selector->style, attributeValue, "debug")) {
88 SDL_TriggerBreakpoint();
89 }
90
91 $((Style *) accumulator, addSelector, selector);
92 $((Style *) accumulator, addAttributes, selector->style->attributes);
93 }
94 }
95
96 return accumulator;
97}
static String * description(const Object *self)
Definition: Label.c:47
#define MVC_LogVerbose(fmt,...)
Definition: Log.h:43
#define MVC_LogEnabled(priority)
Definition: Log.h:37
Selectors are comprised of one or more SelectorSequences.
Definition: Selector.h:49
Style * style
The Style.
Definition: Selector.h:82
_Bool matchesView(const Selector *self, View *view)
void addSelector(Style *self, Selector *selector)
Adds the given Selector to this Style.
Definition: Style.c:255
Dictionary * attributes
Definition: Style.h:59
void addAttributes(Style *self, const Dictionary *attributes)
Adds or replaces the attribtues in attributes to this Style.
Definition: Style.c:119
ident attributeValue(const Style *self, const char *attr)
Definition: Style.c:284
Stylesheets are comprised of Selectors and Styles.
Definition: Stylesheet.h:44
Array * selectors
The Selectors, ordered by specificity.
Definition: Stylesheet.h:60
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133

◆ dealloc()

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

Definition at line 40 of file Theme.c.

40 {
41
42 Theme *this = (Theme *) self;
43
44 release(this->stylesheets);
45
46 super(Object, self, dealloc);
47}
static void dealloc(Object *self)
Definition: Theme.c:40

◆ init()

static Theme * init ( Theme self)
static

Definition at line 117 of file Theme.c.

117 {
118
119 self = (Theme *) super(Object, self, init);
120 if (self) {
121
122 self->stylesheets = $$(MutableArray, arrayWithCapacity, 8);
123 assert(self->stylesheets);
124
126 }
127
128 return self;
129}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Stylesheet * defaultStylesheet(void)
Definition: Stylesheet.c:95
void addStylesheet(Theme *self, Stylesheet *stylesheet)
Adds the specified Stylesheet to this Theme.
Definition: Theme.c:55

◆ initialize()

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

Definition at line 160 of file Theme.c.

160 {
161
162 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
163
164 ((ThemeInterface *) clazz->interface)->addStylesheet = addStylesheet;
165 ((ThemeInterface *) clazz->interface)->computeStyle = computeStyle;
166 ((ThemeInterface *) clazz->interface)->init = init;
167 ((ThemeInterface *) clazz->interface)->removeStylesheet = removeStylesheet;
168 ((ThemeInterface *) clazz->interface)->theme = theme;
169}
Style * computeStyle(const Theme *self, View *view)
void removeStylesheet(Theme *self, Stylesheet *stylesheet)
Removes the given Stylesheet from this Theme.
Definition: Theme.c:135
Theme * theme(SDL_Window *window)
Definition: Theme.c:143

◆ removeStylesheet()

static void removeStylesheet ( Theme self,
Stylesheet stylesheet 
)
static

Definition at line 135 of file Theme.c.

135 {
136 $((MutableArray *) self->stylesheets, removeObject, stylesheet);
137}

◆ theme()

static Theme * theme ( SDL_Window *  window)
static

Definition at line 143 of file Theme.c.

143 {
144
145 assert(window);
146
148 if (windowController) {
149 return windowController->theme;
150 }
151
152 return NULL;
153}
A WindowController manages a ViewController and its descendants within an SDL_Window.
Theme * theme
The Theme.
WindowController * windowController(SDL_Window *window)