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;
135 *((
int *) inlet->
dest) = cast(Number, obj)->value;
143 const Array *array = cast(Array, obj);
145 assert(array->count == 2);
147 const Number *x = $(array, objectAtIndex, 0);
148 const Number *y = $(array, objectAtIndex, 1);
150 *((SDL_Point *) inlet->
dest) = MakePoint(x->value, y->value);
158 if ($((Object *) obj, isKindOfClass, _Number())) {
159 const Number *n = obj;
161 *((SDL_Rect *) inlet->
dest) = MakeRect(n->value, n->value, n->value, n->value);
163 const Array *array = cast(Array, obj);
165 assert(array->count == 4);
167 const Number *x = $(array, objectAtIndex, 0);
168 const Number *y = $(array, objectAtIndex, 1);
169 const Number *w = $(array, objectAtIndex, 2);
170 const Number *h = $(array, objectAtIndex, 3);
172 *((SDL_Rect *) inlet->
dest) = MakeRect(x->value, y->value, w->value, h->value);
181 const Array *array = cast(Array, obj);
183 assert(array->count == 2);
185 const Number *w = $(array, objectAtIndex, 0);
186 const Number *h = $(array, objectAtIndex, 1);
188 *((SDL_Size *) inlet->
dest) = MakeSize(w->value, h->value);
198 const Dictionary *dictionary = cast(Dictionary, obj);
200 const String *className = $(dictionary, objectForKeyPath,
"class");
201 if (className || dest == NULL) {
203 Class *clazz = className ? classForName(className->chars) :
_View();
206 const Class *c = clazz;
211 c = c->def.superclass;
215 if (clazz !=
_View()) {
216 if (interfaceof(
View, clazz)->
init == interfaceof(
View, clazz->def.superclass)->
init) {
217 MVC_LogWarn(
"%s does not implement View::init\n", clazz->def.name);
238 MVC_LogWarn(
"Inlet %s has NULL destination and no className specified\n", inlet->
name);
254 View *subview = NULL;
308 bool didBindInlets =
false;
310 for (
const Inlet *inlet = inlets; inlet->
name; inlet++) {
311 const ident obj = $(dictionary, objectForKeyPath, inlet->name);
314 didBindInlets =
true;
318 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)
#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 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.