22#include <Objectively.h>
32 *((_Bool *) inlet->
dest) = cast(Boole, obj)->value;
40 char **dest = inlet->
dest;
46 *dest = strdup(cast(String, obj)->chars);
70 if ($((Object *) obj, isKindOfClass, _String())) {
72 String *
string = cast(String, obj);
75 if (strcmp(
"none", string->chars) == 0) {
79 if (string->chars[0] ==
'#') {
87 const Array *array = cast(Array, obj);
89 assert(array->count == 4);
91 const Number *r = $(array, objectAtIndex, 0);
92 const Number *g = $(array, objectAtIndex, 1);
93 const Number *b = $(array, objectAtIndex, 2);
94 const Number *a = $(array, objectAtIndex, 3);
96 #define ScaleColor(c) (c > 0.0 && c < 1.0 ? c * 255 : c)
106 *((SDL_Color *) inlet->
dest) = color;
113 *((
double *) inlet->
dest) = cast(Number, obj)->value;
120 *((
int *) inlet->
dest) = valueof(inlet->
data, cast(String, obj)->chars);
127 *((
float *) inlet->
dest) = cast(Number, obj)->value;
156 *((
int *) inlet->
dest) = cast(Number, obj)->value;
164 const Array *array = cast(Array, obj);
166 assert(array->count == 2);
168 const Number *x = $(array, objectAtIndex, 0);
169 const Number *y = $(array, objectAtIndex, 1);
171 *((SDL_Point *) inlet->
dest) =
MakePoint(x->value, y->value);
179 if ($((Object *) obj, isKindOfClass, _Number())) {
180 const Number *n = obj;
182 *((SDL_Rect *) inlet->
dest) =
MakeRect(n->value, n->value, n->value, n->value);
184 const Array *array = cast(Array, obj);
186 assert(array->count == 4);
188 const Number *x = $(array, objectAtIndex, 0);
189 const Number *y = $(array, objectAtIndex, 1);
190 const Number *w = $(array, objectAtIndex, 2);
191 const Number *h = $(array, objectAtIndex, 3);
193 *((SDL_Rect *) inlet->
dest) =
MakeRect(x->value, y->value, w->value, h->value);
202 const Array *array = cast(Array, obj);
204 assert(array->count == 2);
206 const Number *w = $(array, objectAtIndex, 0);
207 const Number *h = $(array, objectAtIndex, 1);
219 const Dictionary *dictionary = cast(Dictionary, obj);
221 const String *className = $(dictionary, objectForKeyPath,
"class");
222 if (className || dest == NULL) {
224 Class *clazz = className ? classForName(className->chars) :
_View();
227 const Class *c = clazz;
232 c = c->def.superclass;
236 if (clazz !=
_View()) {
237 if (interfaceof(
View, clazz)->
init == interfaceof(
View, clazz->def.superclass)->
init) {
238 MVC_LogWarn(
"%s does not implement View::init\n", clazz->def.name);
259 MVC_LogWarn(
"Inlet %s has NULL destination and no className specified\n", inlet->
name);
275 View *subview = NULL;
331 _Bool didBindInlets =
false;
333 for (
const Inlet *inlet = inlets; inlet->
name; inlet++) {
334 const ident obj = $(dictionary, objectForKeyPath, inlet->name);
337 didBindInlets =
true;
341 return didBindInlets;
#define MVC_LogWarn(fmt,...)
ObjectivelyMVC: Object oriented MVC framework for OpenGL, SDL2 and GNU C.
#define MakeSize(w, h)
Creates an SDL_Size with the given dimensions.
#define MakePoint(x, y)
Creates an SDL_Point with the given coordinates.
#define MakeRect(x, y, w, h)
Creates an SDL_Rect with the given origin and size.
static void bindColor(const Inlet *inlet, ident obj)
InletBinding for InletTypeColor.
static void bindEnum(const Inlet *inlet, ident obj)
InletBinding for InletTypeEnum.
static void bindPoint(const Inlet *inlet, ident obj)
InletBinding for InletTypePoint.
static void bindApplicationDefined(const Inlet *inlet, ident obj)
InletBinding for InletTypeApplicationDefined.
static void bindImage(const Inlet *inlet, ident obj)
InletBinding for InletTypeImage.
static void bindFont(const Inlet *inlet, ident obj)
InletBinding for InletTypeFont.
static void bindClassNames_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for bindClassNames.
static void bindSubviews_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for bind subview recursion.
_Bool bindInlets(const Inlet *inlets, const Dictionary *dictionary)
Binds each Inlet specified in inlets to the data provided in dictionary.
static void bindDouble(const Inlet *inlet, ident obj)
InletBinding for InletTypeDouble.
static void bindClassNames(const Inlet *inlet, ident obj)
InletBinding for InletTypeClassNames.
static void bindInteger(const Inlet *inlet, ident obj)
InletBinding for InletTypeInteger.
static void bindFloat(const Inlet *inlet, ident obj)
InletBinding for InletTypeFloat.
static void bindRectangle(const Inlet *inlet, ident obj)
InletBinding for InletTypeRectangle.
static void bindSize(const Inlet *inlet, ident obj)
InletBinding for InletTypeSize.
static void bindBool(const Inlet *inlet, ident obj)
InletBinding for InletTypeBool.
static void bindView(const Inlet *inlet, ident obj)
Binds the given View with the specified Dictionary.
static void bindCharacters(const Inlet *inlet, ident obj)
InletBinding for InletTypeCharacters.
const InletBinding inletBindings[]
The array of InletBinding functions, indexed by InletType.
static void bindSubviews(const Inlet *inlet, ident obj)
InletBinding for InletTypeSubviews.
static void bindStyle(const Inlet *inlet, ident obj)
InletBinding for InletTypeStyle.
#define BindInlet(inlet, obj)
Binds the Inlet to obj by invoking the appropriate InletBinding function.
void(* InletBinding)(const Inlet *inlet, ident obj)
A function pointer for Inlet binding.
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
OBJECTIVELYMVC_EXPORT SDL_Color MVC_HexToRGBA(const char *hexString)
Converts the given hexadecimal color string to an RGBA color.
#define MakeColor(r, g, b, a)
Creates an SDL_Color with the given components.
OBJECTIVELYMVC_EXPORT SDL_Color MVC_ColorForName(const char *name)
Image * initWithResourceName(Image *self, const char *name)
Initializes this Image, loading the Resource by the given name.
Inlets enable inbound data binding of View attributes through JSON.
const char * name
The Inlet name, e.g. "alignment".
ident data
Type-specific data, e.g. an array of EnumNames.
ident dest
The Inlet destination.
void addAttributes(Style *self, const Dictionary *attributes)
Adds or replaces the attribtues in attributes to this Style.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
View * superview
The super View.
Class * _View(void)
The View archetype.
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
void addClassName(View *self, const char *className)
Adds the given class name to this View.
void replaceSubview(View *self, View *subview, View *replacement)
Replaces the specified subview with the given replacement.
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.