23#include <Objectively.h>
33 *((
bool *) inlet->
dest) = cast(Boole, obj)->value;
41 char **dest = inlet->
dest;
47 *dest = strdup(cast(String, obj)->chars);
71 if ($((Object *) obj, isKindOfClass, _String())) {
73 String *
string = cast(String, obj);
76 if (strcmp(
"none", string->chars) == 0) {
80 if (string->chars[0] ==
'#') {
88 const Array *array = cast(Array, obj);
90 assert(array->count == 4);
92 const Number *r = $(array, objectAtIndex, 0);
93 const Number *g = $(array, objectAtIndex, 1);
94 const Number *b = $(array, objectAtIndex, 2);
95 const Number *a = $(array, objectAtIndex, 3);
97 #define ScaleColor(c) (c > 0.0 && c < 1.0 ? c * 255 : c)
107 *((SDL_Color *) inlet->
dest) = color;
114 *((
double *) inlet->
dest) = cast(Number, obj)->value;
121 *((
int *) inlet->
dest) = valueof(inlet->
data, cast(String, obj)->chars);
128 *((
float *) inlet->
dest) = cast(Number, obj)->value;
157 *((
int *) inlet->
dest) = cast(Number, obj)->value;
165 const Array *array = cast(Array, obj);
167 assert(array->count == 2);
169 const Number *x = $(array, objectAtIndex, 0);
170 const Number *y = $(array, objectAtIndex, 1);
172 *((SDL_Point *) inlet->
dest) = MakePoint(x->value, y->value);
180 if ($((Object *) obj, isKindOfClass, _Number())) {
181 const Number *n = obj;
183 *((SDL_Rect *) inlet->
dest) = MakeRect(n->value, n->value, n->value, n->value);
185 const Array *array = cast(Array, obj);
187 assert(array->count == 4);
189 const Number *x = $(array, objectAtIndex, 0);
190 const Number *y = $(array, objectAtIndex, 1);
191 const Number *w = $(array, objectAtIndex, 2);
192 const Number *h = $(array, objectAtIndex, 3);
194 *((SDL_Rect *) inlet->
dest) = MakeRect(x->value, y->value, w->value, h->value);
203 const Array *array = cast(Array, obj);
205 assert(array->count == 2);
207 const Number *w = $(array, objectAtIndex, 0);
208 const Number *h = $(array, objectAtIndex, 1);
210 *((SDL_Size *) inlet->
dest) = MakeSize(w->value, h->value);
220 const Dictionary *dictionary = cast(Dictionary, obj);
222 const String *className = $(dictionary, objectForKeyPath,
"class");
223 if (className || dest == NULL) {
225 Class *clazz = className ? classForName(className->chars) :
_View();
228 const Class *c = clazz;
233 c = c->def.superclass;
237 if (clazz !=
_View()) {
238 if (interfaceof(
View, clazz)->
init == interfaceof(
View, clazz->def.superclass)->
init) {
239 MVC_LogWarn(
"%s does not implement View::init\n", clazz->def.name);
260 MVC_LogWarn(
"Inlet %s has NULL destination and no className specified\n", inlet->
name);
276 View *subview = NULL;
332 bool didBindInlets =
false;
334 for (
const Inlet *inlet = inlets; inlet->
name; inlet++) {
335 const ident obj = $(dictionary, objectForKeyPath, inlet->name);
338 didBindInlets =
true;
342 return didBindInlets;
static View * init(View *self)
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
SDL_Color MVC_ColorForName(const char *name)
SDL_Color MVC_HexToRGBA(const char *hex)
static Image * initWithResourceName(Image *self, const char *name)
#define MVC_LogWarn(fmt,...)
ObjectivelyMVC: Object oriented MVC framework for SDL3 and C.
static void addSubview(View *self, View *subview)
static void addAttributes(Style *self, const Dictionary *attributes)
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.
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.
bool bindInlets(const Inlet *inlets, const Dictionary *dictionary)
Binds each Inlet specified in inlets to the data provided in dictionary.
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.
static void addClassName(View *self, const char *className)
static void replaceSubview(View *self, View *subview, View *replacement)
static void enumerate(View *self, ViewEnumerator enumerator, ident data)
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.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
View * superview
The super View.
View * init(View *self)
Initializes this View.