26#include <Objectively/JSONContext.h>
45 release(this->fontCache);
46 release(this->imageCache);
48 release(this->stylesheets);
60 $((Array *) self->
stylesheets, addObject, stylesheet);
71 String *key = str(
"%s@%g",
name->chars, pixelDensity);
86 String *key = str(
"%s@%g",
name, pixelDensity);
89 Image *
image = $(self->imageCache, objectForKeyPath, key->chars);
94 $(self->imageCache, setObjectForKeyPath,
image, key->chars);
110 String *key =
cacheKey(attributes, pixelDensity);
112 Font *
font = $(self->fontCache, objectForKeyPath, key->chars);
123 String *resolvedKey =
cacheKey(&resolvedAttributes, pixelDensity);
125 font = $(self->fontCache, objectForKeyPath, resolvedKey->chars);
127 $(self->fontCache, setObjectForKeyPath, resolved, resolvedKey->chars);
131 release(resolvedKey);
146 if (self->icons == NULL) {
186 const View *view = data;
188 const Array *selectors = (Array *) stylesheet->
selectors;
189 for (
size_t i = 0; i < selectors->count; i++) {
191 Selector *selector = $(selectors, objectAtIndex, i);
194 assert(selector->
style);
198 String *
this = $((Object *) selector,
description);
208 SDL_TriggerBreakpoint();
239 self = (
Theme *) super(Object, self,
init);
242 self->fontCache = $$(Dictionary, dictionary);
243 assert(self->fontCache);
245 self->imageCache = $$(Dictionary, dictionary);
246 assert(self->imageCache);
248 self->
stylesheets = $$(Array, arrayWithCapacity, 8);
262 $((Array *) self->
stylesheets, removeObject, stylesheet);
307#pragma mark - Class lifecycle
314 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
317 ((ThemeInterface *) clazz->interface)->addStylesheet =
addStylesheet;
318 ((ThemeInterface *) clazz->interface)->computeStyle =
computeStyle;
319 ((ThemeInterface *) clazz->interface)->font =
font;
320 ((ThemeInterface *) clazz->interface)->image =
image;
321 ((ThemeInterface *) clazz->interface)->icon =
icon;
322 ((ThemeInterface *) clazz->interface)->icons =
icons;
323 ((ThemeInterface *) clazz->interface)->
init =
init;
327 ((ThemeInterface *) clazz->interface)->theme =
theme;
339 clazz = _initialize(&(
const ClassDef) {
341 .superclass = _Object(),
342 .instanceSize =
sizeof(
Theme),
343 .interfaceSize =
sizeof(ThemeInterface),
static String * nameWithAttributes(const FontAttributes *attributes)
static Font * fontWithAttributes(const FontAttributes *attributes, float pixelDensity)
static String * name(const Font *self)
static Image * imageWithResourceName(const char *name, float pixelDensity)
static AtlasImage * addImageWithName(ImageAtlas *self, const char *name, Image *image)
static AtlasImage * imageWithName(const ImageAtlas *self, const char *name)
static bool compile(ImageAtlas *self)
Packs many Images into one sheet, backed by one Texture.
static String * description(const Object *self)
View logging facilities via SDL_Log.
#define MVC_LogVerbose(fmt,...)
#define MVC_LogError(fmt,...)
#define MVC_LogEnabled(priority)
static bool matchesView(const Selector *self, const View *view)
static Style * initWithAttributes(Style *self, const Dictionary *attributes)
static ident attributeValue(const Style *self, const char *attr)
static void addSelector(Style *self, Selector *selector)
static void addAttributes(Style *self, const Dictionary *attributes)
static Stylesheet * defaultStylesheet(void)
static ident computeStyle_reduce(const ident obj, ident accumulator, ident data)
Reducer for computeStyle.
static AtlasImage * icon(Theme *self, const char *name)
static ImageAtlas * icons(Theme *self)
static void renderDeviceWillReset_enumerate(const Dictionary *dictionary, ident obj, ident key, ident data)
DictionaryEnumerator for renderDeviceWillReset.
static String * cacheKey(const FontAttributes *attributes, float pixelDensity)
Builds the cache key for the given attributes and pixel density.
static Font * font(Theme *self, const FontAttributes *attributes, float pixelDensity)
static Theme * theme(SDL_Window *window)
static void renderDeviceWillReset(Theme *self)
static void dealloc(Object *self)
static void addStylesheet(Theme *self, Stylesheet *stylesheet)
static Style * computeStyle(const Theme *self, const View *view)
static void removeStylesheet(Theme *self, Stylesheet *stylesheet)
static void initialize(Class *clazz)
static Theme * init(Theme *self)
static Image * image(Theme *self, const char *name, float pixelDensity)
static AtlasImage * addIcon(Theme *self, const char *name, Image *image)
static void renderDeviceDidReset(Theme *self)
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
static WindowController * windowController(SDL_Window *window)
A WindowController manages a ViewController and its descendants within an SDL_Window.
An Image packed into an ImageAtlas.
The family, size and style attributes that identify a Font, independent of the pixel density at which...
char * family
The family name.
Packs many Images into one sheet, backed by one Texture.
ImageAtlas * init(ImageAtlas *self)
Initializes this ImageAtlas.
Selectors are comprised of one or more SelectorSequences.
Stylesheets are comprised of Selectors and Styles.
Array * selectors
The Selectors, ordered by specificity.
void removeStylesheet(Theme *self, Stylesheet *stylesheet)
Removes the given Stylesheet from this Theme.
Array * stylesheets
The Stylesheets, in order of priority.
AtlasImage * addIcon(Theme *self, const char *name, Image *image)
Registers image as the icon name, so that :name: in any Text drawn under this Theme renders it inline...
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
A WindowController manages a ViewController and its descendants within an SDL_Window.