ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
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.
 
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 210 of file HueColorPicker.c.

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

◆ awakeWithDictionary()

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

Definition at line 71 of file HueColorPicker.c.

71 {
72
73 super(View, self, awakeWithDictionary, dictionary);
74
75 HueColorPicker *this = (HueColorPicker *) self;
76
77 const Inlet inlets[] = MakeInlets(
78 MakeInlet("colorView", InletTypeView, &this->colorView, NULL),
79 MakeInlet("hue", InletTypeDouble, &this->hue, NULL),
80 MakeInlet("saturation", InletTypeDouble, &this->saturation, NULL),
81 MakeInlet("value", InletTypeDouble, &this->value, NULL),
82 MakeInlet("hueInput", InletTypeView, &this->hueInput, NULL),
83 MakeInlet("hueSlider", InletTypeView, &this->hueSlider, NULL),
84 MakeInlet("stackView", InletTypeView, &this->stackView, NULL)
85 );
86
87 $(self, bind, inlets, dictionary);
88}
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
@ 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:134

◆ 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 memset(&this->delegate, 0, sizeof(this->delegate));
57
58 release(this->colorView);
59 release(this->hueInput);
60 release(this->hueSlider);
61 release(this->stackView);
62
63 super(Object, self, dealloc);
64}
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}
static void updateBindings(View *self)
ident self
The delegate self-reference.
Definition Slider.h:47
SliderDelegate delegate
The delegate.
Definition Slider.h:83

◆ init()

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

Definition at line 93 of file HueColorPicker.c.

93 {
94 return (View *) $((HueColorPicker *) self, initWithFrame, NULL);
95}
static HueColorPicker * initWithFrame(HueColorPicker *self, const SDL_Rect *frame)

◆ initialize()

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

Definition at line 192 of file HueColorPicker.c.

192 {
193
194 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
195
196 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
197 ((ViewInterface *) clazz->interface)->init = init;
198 ((ViewInterface *) clazz->interface)->updateBindings = updateBindings;
199
200 ((HueColorPickerInterface *) clazz->interface)->initWithFrame = initWithFrame;
201 ((HueColorPickerInterface *) clazz->interface)->rgbColor = rgbColor;
202 ((HueColorPickerInterface *) clazz->interface)->setColor = setColor;
203 ((HueColorPickerInterface *) clazz->interface)->setRGBColor = setRGBColor;
204}
static SDL_Color rgbColor(const HueColorPicker *self)
static void setColor(HueColorPicker *self, double hue, double saturation, double value)
static View * init(View *self)
static void setRGBColor(HueColorPicker *self, const SDL_Color *color)
SDL_Color rgbColor(const HueColorPicker *self)
void updateBindings(View *self)
Updates data bindings, prompting the appropriate layout changes.

◆ initWithFrame()

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

Definition at line 117 of file HueColorPicker.c.

117 {
118
119 self = (HueColorPicker *) super(Control, self, initWithFrame, frame);
120 if (self) {
121
122 self->stackView = $(alloc(StackView), initWithFrame, NULL);
123 assert(self->stackView);
124
125 $((View *) self, addSubview, (View *) self->stackView);
126
127 self->colorView = $(alloc(View), initWithFrame, &MakeRect(0, 0, 0, 24));
128 assert(self->colorView);
129
130 $(self->colorView, addClassName, "colorView");
131 $((View *) self->stackView, addSubview, self->colorView);
132
133 self->hueSlider = $(alloc(Slider), initWithFrame, NULL);
134 assert(self->hueSlider);
135
136 self->hueSlider->delegate.self = self;
137 self->hueSlider->delegate.didSetValue = didSetHue;
138 self->hueSlider->max = 360.0;
139 $(self->hueSlider, setLabelFormat, "%.0lf");
140
141 self->hueInput = $(alloc(Input), initWithFrame, NULL);
142 assert(self->hueInput);
143
144 $(self->hueInput, setControl, (Control *) self->hueSlider);
145 $(self->hueInput->label->text, setText, "H");
146
147 $((View *) self->stackView, addSubview, (View *) self->hueInput);
148
149 $(self, setColor, 0.0, 1.0, 1.0);
150 }
151
152 return self;
153}
static void didSetHue(Slider *slider, double value)
SliderDelegate callback for hue modification.
static void setControl(Input *self, Control *control)
Definition Input.c:113
static void addSubview(View *self, View *subview)
Definition PageView.c:49
static void setLabelFormat(ProgressBar *self, const char *labelFormat)
static void setText(Text *self, const char *text)
Definition Text.c:532
static void addClassName(View *self, const char *className)
Definition View.c:159
Controls are Views which capture and respond to events.
Definition Control.h:83
StackView * stackView
The StackView.
An Input stacks a Label with a Control.
Definition Input.h:57
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

◆ rgbColor()

static SDL_Color rgbColor ( const HueColorPicker self)
static

Definition at line 159 of file HueColorPicker.c.

159 {
160 return MVC_HSVToRGB(self->hue, self->saturation, self->value);
161}
SDL_Color MVC_HSVToRGB(double hue, double saturation, double value)
Definition Colors.c:685
double hue
The color componenets.

◆ setColor()

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

Definition at line 167 of file HueColorPicker.c.

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

◆ setRGBColor()

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

Definition at line 180 of file HueColorPicker.c.

180 {
181
182 MVC_RGBToHSV(color, &self->hue, &self->saturation, &self->value);
183
184 $((View *) self, updateBindings);
185}
void MVC_RGBToHSV(const SDL_Color *color, double *hue, double *saturation, double *value)
Definition Colors.c:733

◆ updateBindings()

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

Definition at line 100 of file HueColorPicker.c.

100 {
101
102 super(View, self, updateBindings);
103
104 HueColorPicker *this = (HueColorPicker *) self;
105
106 $(this->hueSlider, setValue, this->hue);
107
108 this->colorView->backgroundColor = $(this, rgbColor);
109}
static void setValue(ProgressBar *self, double value)