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 View * init (View *self)
 
static void initialize (Class *clazz)
 
static HueColorPicker * initWithFrame (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, ident data)
 

Macro Definition Documentation

◆ _Class

#define _Class   _HueColorPicker

Definition at line 27 of file HueColorPicker.c.

Function Documentation

◆ _HueColorPicker()

Class * _HueColorPicker ( void  )

Definition at line 212 of file HueColorPicker.c.

212 {
213 static Class *clazz;
214 static Once once;
215
216 do_once(&once, {
217 clazz = _initialize(&(const ClassDef) {
218 .name = "HueColorPicker",
219 .superclass = _Control(),
220 .instanceSize = sizeof(HueColorPicker),
221 .interfaceSize = sizeof(HueColorPickerInterface),
222 .initialize = initialize,
223 });
224 });
225
226 return clazz;
227}
Class * _Control(void)
Definition Control.c:414
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:133
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition View+JSON.h:215
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition View+JSON.h:210
Inlets enable inbound data binding of View attributes through JSON.
Definition View+JSON.h:149
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:225

◆ 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, NULL);
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 data)
ident self
The delegate self-reference.
Definition Slider.h:50
SliderDelegate delegate
The delegate.
Definition Slider.h:86

◆ 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 194 of file HueColorPicker.c.

194 {
195
196 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
197
198 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
199 ((ViewInterface *) clazz->interface)->init = init;
200 ((ViewInterface *) clazz->interface)->updateBindings = updateBindings;
201
202 ((HueColorPickerInterface *) clazz->interface)->initWithFrame = initWithFrame;
203 ((HueColorPickerInterface *) clazz->interface)->rgbColor = rgbColor;
204 ((HueColorPickerInterface *) clazz->interface)->setColor = setColor;
205 ((HueColorPickerInterface *) clazz->interface)->setRGBColor = setRGBColor;
206}
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, ident data)
Updates data bindings, prompting the appropriate layout changes.

◆ initWithFrame()

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

Definition at line 119 of file HueColorPicker.c.

119 {
120
121 self = (HueColorPicker *) super(Control, self, initWithFrame, frame);
122 if (self) {
123
124 self->stackView = $(alloc(StackView), initWithFrame, NULL);
125 assert(self->stackView);
126
127 $((View *) self, addSubview, (View *) self->stackView);
128
129 self->colorView = $(alloc(View), initWithFrame, &MakeRect(0, 0, 0, 24));
130 assert(self->colorView);
131
132 $(self->colorView, addClassName, "colorView");
133 $((View *) self->stackView, addSubview, self->colorView);
134
135 self->hueSlider = $(alloc(Slider), initWithFrame, NULL);
136 assert(self->hueSlider);
137
138 self->hueSlider->delegate.self = self;
139 self->hueSlider->delegate.didSetValue = didSetHue;
140 self->hueSlider->max = 360.0;
141 $(self->hueSlider, setLabelFormat, "%.0lf");
142
143 self->hueInput = $(alloc(Input), initWithFrame, NULL);
144 assert(self->hueInput);
145
146 $(self->hueInput, setControl, (Control *) self->hueSlider);
147 $(self->hueInput->label->text, setText, "H");
148
149 $((View *) self->stackView, addSubview, (View *) self->hueInput);
150
151 $(self, setColor, 0.0, 1.0, 1.0);
152 }
153
154 return self;
155}
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:899
static void addClassName(View *self, const char *className)
Definition View.c:183
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:65
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 161 of file HueColorPicker.c.

161 {
162 return MVC_HSVToRGB(self->hue, self->saturation, self->value);
163}
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 169 of file HueColorPicker.c.

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

◆ setRGBColor()

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

Definition at line 182 of file HueColorPicker.c.

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

◆ updateBindings()

static void updateBindings ( View *  self,
ident  data 
)
static
See also
View::updateBindings(View *, ident)

Definition at line 100 of file HueColorPicker.c.

100 {
101
102 super(View, self, updateBindings, data);
103
104 HueColorPicker *this = (HueColorPicker *) self;
105
106 $(this->hueSlider, setValue, this->hue);
107
108 const SDL_Color color = $(this, rgbColor);
109 $(this->colorView->style, addColorAttribute, "background-color", &color);
110 $(this->colorView, invalidateStyle);
111}
static void setValue(ProgressBar *self, double value)
static void addColorAttribute(Style *self, const char *attr, const SDL_Color *color)
Definition Style.c:253
static void invalidateStyle(View *self)
Definition View.c:1092