ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions
HueColorPicker.c File Reference
#include <assert.h>
#include "HueColorPicker.h"

Go to the source code of this file.

Macros

#define _Class   _HueColorPicker
 

Functions

Class * _HueColorPicker (void)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static void dealloc (Object *self)
 
static void didSetHue (Slider *slider, double value)
 SliderDelegate callback for hue modification. More...
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static HueColorPickerinitWithFrame (HueColorPicker *self, const SDL_Rect *frame)
 
static SDL_Color rgbColor (const HueColorPicker *self)
 
static void setColor (HueColorPicker *self, double hue, double saturation, double value)
 
static void setRGBColor (HueColorPicker *self, const SDL_Color *color)
 
static void updateBindings (View *self)
 

Macro Definition Documentation

◆ _Class

#define _Class   _HueColorPicker

Definition at line 27 of file HueColorPicker.c.

Function Documentation

◆ _HueColorPicker()

Class * _HueColorPicker ( void  )

Definition at line 208 of file HueColorPicker.c.

208 {
209 static Class *clazz;
210 static Once once;
211
212 do_once(&once, {
213 clazz = _initialize(&(const ClassDef) {
214 .name = "HueColorPicker",
215 .superclass = _Control(),
216 .instanceSize = sizeof(HueColorPicker),
217 .interfaceOffset = offsetof(HueColorPicker, interface),
218 .interfaceSize = sizeof(HueColorPickerInterface),
220 });
221 });
222
223 return clazz;
224}
static void initialize(Class *clazz)
Class * _Control(void)
The Control archetype.
Definition: Control.c:379
The HueColorPicker type.

◆ awakeWithDictionary()

static void awakeWithDictionary ( View self,
const Dictionary *  dictionary 
)
static
See also
View::awakeWithDictionary(View *, const Dictionary *)

Definition at line 69 of file HueColorPicker.c.

69 {
70
71 super(View, self, awakeWithDictionary, dictionary);
72
73 HueColorPicker *this = (HueColorPicker *) self;
74
75 const Inlet inlets[] = MakeInlets(
76 MakeInlet("colorView", InletTypeView, &this->colorView, NULL),
77 MakeInlet("hue", InletTypeDouble, &this->hue, NULL),
78 MakeInlet("saturation", InletTypeDouble, &this->saturation, NULL),
79 MakeInlet("value", InletTypeDouble, &this->value, NULL),
80 MakeInlet("hueInput", InletTypeView, &this->hueInput, NULL),
81 MakeInlet("hueSlider", InletTypeView, &this->hueSlider, NULL),
82 MakeInlet("stackView", InletTypeView, &this->stackView, NULL)
83 );
84
85 $(self, bind, inlets, dictionary);
86}
@ InletTypeDouble
Definition: View+JSON.h:67
@ InletTypeView
Definition: View+JSON.h:139
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition: View+JSON.h:221
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition: View+JSON.h:216
Inlets enable inbound data binding of View attributes through JSON.
Definition: View+JSON.h:155
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
_Bool bind(View *self, const Inlet *inlets, const Dictionary *dictionary)
Performs data binding for the Inlets described in dictionary.
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.
Definition: Box.c:50

◆ dealloc()

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

Definition at line 52 of file HueColorPicker.c.

52 {
53
54 HueColorPicker *this = (HueColorPicker *) self;
55
56 release(this->colorView);
57 release(this->hueInput);
58 release(this->hueSlider);
59 release(this->stackView);
60
61 super(Object, self, dealloc);
62}
static void dealloc(Object *self)

◆ didSetHue()

static void didSetHue ( Slider slider,
double  value 
)
static

SliderDelegate callback for hue modification.

Definition at line 34 of file HueColorPicker.c.

34 {
35
36 HueColorPicker *this = (HueColorPicker *) slider->delegate.self;
37
38 this->hue = value;
39
40 $((View *) this, updateBindings);
41
42 if (this->delegate.didPickColor) {
43 this->delegate.didPickColor(this, this->hue, this->saturation, this->value);
44 }
45}
ident self
The delegate self-reference.
Definition: Slider.h:47
SliderDelegate delegate
The delegate.
Definition: Slider.h:83
void updateBindings(View *self)
Updates data bindings, prompting the appropriate layout changes.

◆ init()

static View * init ( View self)
static
See also
View::init(View *)

Definition at line 91 of file HueColorPicker.c.

91 {
92 return (View *) $((HueColorPicker *) self, initWithFrame, NULL);
93}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92

◆ initialize()

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

Definition at line 190 of file HueColorPicker.c.

190 {
191
192 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
193
194 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
195 ((ViewInterface *) clazz->interface)->init = init;
196 ((ViewInterface *) clazz->interface)->updateBindings = updateBindings;
197
198 ((HueColorPickerInterface *) clazz->interface)->initWithFrame = initWithFrame;
199 ((HueColorPickerInterface *) clazz->interface)->rgbColor = rgbColor;
200 ((HueColorPickerInterface *) clazz->interface)->setColor = setColor;
201 ((HueColorPickerInterface *) clazz->interface)->setRGBColor = setRGBColor;
202}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
void setColor(HSVColorPicker *self, double hue, double saturation, double value)
Sets the color of the HSVColorPicker.
SDL_Color rgbColor(const HSVColorPicker *self)
void setRGBColor(HSVColorPicker *self, const SDL_Color *color)
Sets the color of the HSVColorPicker.

◆ initWithFrame()

static HueColorPicker * initWithFrame ( HueColorPicker self,
const SDL_Rect *  frame 
)
static

Definition at line 115 of file HueColorPicker.c.

115 {
116
117 self = (HueColorPicker *) super(Control, self, initWithFrame, frame);
118 if (self) {
119
120 self->stackView = $(alloc(StackView), initWithFrame, NULL);
121 assert(self->stackView);
122
123 $((View *) self, addSubview, (View *) self->stackView);
124
125 self->colorView = $(alloc(View), initWithFrame, &MakeRect(0, 0, 0, 24));
126 assert(self->colorView);
127
128 $(self->colorView, addClassName, "colorView");
129 $((View *) self->stackView, addSubview, self->colorView);
130
131 self->hueSlider = $(alloc(Slider), initWithFrame, NULL);
132 assert(self->hueSlider);
133
134 self->hueSlider->delegate.self = self;
135 self->hueSlider->delegate.didSetValue = didSetHue;
136 self->hueSlider->max = 360.0;
137 $(self->hueSlider, setLabelFormat, "%.0lf");
138
139 self->hueInput = $(alloc(Input), initWithFrame, NULL);
140 assert(self->hueInput);
141
142 $(self->hueInput, setControl, (Control *) self->hueSlider);
143 $(self->hueInput->label->text, setText, "H");
144
145 $((View *) self->stackView, addSubview, (View *) self->hueInput);
146
147 $(self, setColor, 0.0, 1.0, 1.0);
148 }
149
150 return self;
151}
static void didSetHue(Slider *slider, double value)
SliderDelegate callback for hue modification.
#define MakeRect(x, y, w, h)
Creates an SDL_Rect with the given origin and size.
Definition: Types.h:74
Controls are Views which capture events and dispatch Actions.
Definition: Control.h:83
StackView * stackView
The StackView.
An Input stacks a Label with a Control.
Definition: Input.h:57
void setControl(Input *self, Control *control)
Sets this Input's Control.
Definition: Input.c:113
void setLabelFormat(ProgressBar *self, const char *labelFormat)
Changes this ProgressBar's label format and calls appropriate update functions.
Definition: ProgressBar.c:145
A Control allowing users to drag a handle to select a numeric value.
Definition: Slider.h:62
StackViews are containers that manage the arrangement of their subviews.
Definition: StackView.h:68
void setText(Text *self, const char *text)
Sets this Text's text.
Definition: Text.c:261
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35
void addClassName(View *self, const char *className)
Adds the given class name to this View.
Definition: View.c:120

◆ rgbColor()

static SDL_Color rgbColor ( const HueColorPicker self)
static

Definition at line 157 of file HueColorPicker.c.

157 {
158 return MVC_HSVToRGB(self->hue, self->saturation, self->value);
159}
OBJECTIVELYMVC_EXPORT SDL_Color MVC_HSVToRGB(double hue, double saturation, double value)
Converts the given HSV components to an RGB color.
Definition: Colors.c:684
double hue
The color componenets.

◆ setColor()

static void setColor ( HueColorPicker self,
double  hue,
double  saturation,
double  value 
)
static

Definition at line 165 of file HueColorPicker.c.

165 {
166
167 self->hue = hue;
168 self->saturation = saturation;
169 self->value = value;
170
171 $((View *) self, updateBindings);
172}

◆ setRGBColor()

static void setRGBColor ( HueColorPicker self,
const SDL_Color *  color 
)
static

Definition at line 178 of file HueColorPicker.c.

178 {
179
180 MVC_RGBToHSV(color, &self->hue, &self->saturation, &self->value);
181
182 $((View *) self, updateBindings);
183}
OBJECTIVELYMVC_EXPORT void MVC_RGBToHSV(const SDL_Color *color, double *hue, double *saturation, double *value)
Converts the given RGB color to HSV components.
Definition: Colors.c:732

◆ updateBindings()

static void updateBindings ( View self)
static
See also
View::updateBindings(View *)

Definition at line 98 of file HueColorPicker.c.

98 {
99
100 super(View, self, updateBindings);
101
102 HueColorPicker *this = (HueColorPicker *) self;
103
104 $(this->hueSlider, setValue, this->hue);
105
106 this->colorView->backgroundColor = $(this, rgbColor);
107}
void setValue(const ProgressBar *self, double value)
Sets the value, which is clamped to min and max.