146 {
147
149
150 if (event->type == SDL_MOUSEBUTTONDOWN) {
153 }
154 }
155
156 else if (event->type == SDL_MOUSEBUTTONUP) {
158 self->
state &= ~ControlStateHighlighted;
159 }
160 }
161
162 else if (event->type == SDL_MOUSEMOTION) {
165 if (frame.w) {
166
167 const double fraction = (event->motion.x - frame.x) / (double) frame.w;
168 double value = this->min + (this->max - this->min) * clamp(fraction, 0.0, 1.0);
169
170 if (this->snapToStep && this->step) {
171 value = clamp(round(value / this->step) * this->step, this->min, this->max);
172 }
173
174 const double delta = fabs(this->value - value);
175 if (delta > __DBL_EPSILON__) {
177
178 if (this->delegate.didSetValue) {
179 this->delegate.didSetValue(this, this->value);
180 }
181 }
182
183 return true;
184 }
185 }
186 }
187
189}
@ ControlStateHighlighted
Controls are Views which capture events and dispatch Actions.
_Bool captureEvent(Control *self, const SDL_Event *event)
Captures a given event, potentially altering the state of this Control.
unsigned int state
The bit mask of ControlState.
_Bool didReceiveEvent(const View *self, const SDL_Event *event)
SDL_Rect renderFrame(const View *self)