13 #include "../../gfx.h"
15 #if (GFX_USE_GWIN && GWIN_NEED_SLIDER) || defined(__DOXYGEN__)
17 #include "gwin_class.h"
20 static int SliderCalcPosFromDPos(GSliderObject *gsw) {
24 if (gsw->w.g.width < gsw->w.g.height) {
30 if (gsw->min > gsw->max)
39 if (gsw->min > gsw->max)
45 static void SendSliderEvent(GSliderObject *gsw, gU8 action) {
46 GSourceListener * psl;
48 #define pse ((GEventGWinSlider *)pe)
59 if (psl->srcflags < action)
60 psl->srcflags = action;
67 pse->type = GEVENT_GWIN_SLIDER;
69 pse->action = psl->srcflags;
71 pse->tag = gsw->w.tag;
75 pse->position = pse->action >= GSLIDER_EVENT_CANCEL ? gsw->pos : SliderCalcPosFromDPos(gsw);
86 static void SliderResetDisplayPos(GSliderObject *gsw) {
87 if (gsw->w.g.width < gsw->w.g.height)
88 gsw->dpos = gsw->w.g.height-1-(gsw->w.g.height-1)*(gsw->pos-gsw->min)/(gsw->max-gsw->min);
90 gsw->dpos = (gsw->w.g.width-1)*(gsw->pos-gsw->min)/(gsw->max-gsw->min);
95 static void SetDisplayPosFromMouse(GSliderObject *gsw,
gCoord x,
gCoord y) {
96 if (gsw->w.g.width < gsw->w.g.height)
97 gsw->dpos = y < 0 ? 0 : (y >= gsw->w.g.height ? gsw->w.g.height-1 : y);
99 gsw->dpos = x < 0 ? 0 : (x >= gsw->w.g.width ? gsw->w.g.width-1 : x);
104 #define gsw ((GSliderObject *)gw)
106 #if !GWIN_BUTTON_LAZY_RELEASE
108 if (x < 0 || x >= gsw->w.g.width || y < 0 || y >= gsw->w.g.height) {
110 SliderResetDisplayPos(gsw);
111 _gwinUpdate(&gsw->w.g);
112 SendSliderEvent(gsw, GSLIDER_EVENT_CANCEL);
118 SetDisplayPosFromMouse(gsw, x, y);
119 gsw->pos = SliderCalcPosFromDPos(gsw);
122 #if GWIN_SLIDER_NOSNAP
124 if (gsw->w.g.width < gsw->w.g.height) {
125 if (gsw->pos == gsw->min)
126 gsw->dpos = gsw->w.g.height-1;
127 else if (gsw->pos == gsw->max)
130 if (gsw->pos == gsw->max)
131 gsw->dpos = gsw->w.g.width-1;
132 else if (gsw->pos == gsw->min)
136 SliderResetDisplayPos(gsw);
138 _gwinUpdate(&gsw->w.g);
141 SendSliderEvent(gsw, GSLIDER_EVENT_SET);
148 #define gsw ((GSliderObject *)gw)
151 SetDisplayPosFromMouse(gsw, x, y);
154 _gwinUpdate(&gsw->w.g);
157 SendSliderEvent(gsw, GSLIDER_EVENT_START);
164 #define gsw ((GSliderObject *)gw)
167 SetDisplayPosFromMouse(gsw, x, y);
170 _gwinUpdate(&gsw->w.g);
173 SendSliderEvent(gsw, GSLIDER_EVENT_MOVE);
179 #if GINPUT_NEED_TOGGLE
182 #define gsw ((GSliderObject *)gw)
186 SendSliderEvent(gsw, GSLIDER_EVENT_SET);
189 SendSliderEvent(gsw, GSLIDER_EVENT_SET);
194 static void SliderToggleAssign(
GWidgetObject *gw, gU16 role, gU16 instance) {
196 ((GSliderObject *)gw)->t_up = instance;
198 ((GSliderObject *)gw)->t_dn = instance;
202 return role ? ((GSliderObject *)gw)->t_up : ((GSliderObject *)gw)->t_dn;
208 static void SliderDialMove(
GWidgetObject *gw, gU16 role, gU16 value, gU16 max) {
209 #define gsw ((GSliderObject *)gw)
213 gsw->pos = (gU16)((gU32)value*(gsw->max-gsw->min)/max + gsw->min);
215 SliderResetDisplayPos(gsw);
216 _gwinUpdate(&gsw->w.g);
219 SendSliderEvent(gsw, GSLIDER_EVENT_SET);
223 static void SliderDialAssign(
GWidgetObject *gw, gU16 role, gU16 instance) {
225 ((GSliderObject *)gw)->dial = instance;
230 return ((GSliderObject *)gw)->dial;
238 sizeof(GSliderObject),
244 #if GINPUT_NEED_MOUSE
251 #if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
256 #if GINPUT_NEED_TOGGLE
276 if (!(gs = (GSliderObject *)_gwidgetCreate(g, &gs->w, pInit, &sliderVMT)))
278 #if GINPUT_NEED_TOGGLE
279 gs->t_dn = GWIDGET_NO_INSTANCE;
280 gs->t_up = GWIDGET_NO_INSTANCE;
283 gs->dial = GWIDGET_NO_INSTANCE;
288 SliderResetDisplayPos(gs);
294 #define gsw ((GSliderObject *)gh)
304 SliderResetDisplayPos(gsw);
309 #define gsw ((GSliderObject *)gh)
314 if (gsw->min <= gsw->max) {
315 if (pos < gsw->min) gsw->pos = gsw->min;
316 else if (pos > gsw->max) gsw->pos = gsw->max;
319 if (pos > gsw->min) gsw->pos = gsw->min;
320 else if (pos < gsw->max) gsw->pos = gsw->max;
323 SliderResetDisplayPos(gsw);
344 #define gsw ((GSliderObject *)gw)
351 if ((gw->
g.
flags & GWIN_FLG_SYSENABLED))
358 if (gsw->dpos != gw->
g.
height-1)
366 if (gsw->dpos <= gw->
g.
height-2)
371 if (gsw->dpos != gw->
g.
width-1)
379 if (gsw->dpos <= gw->
g.
width-2)
391 #define gsw ((GSliderObject *)gw)
392 #define gi ((gImage *)param)
399 if ((gw->
g.
flags & GWIN_FLG_SYSENABLED))
407 if (gsw->dpos != gw->
g.
height-1) {
408 for(z=gw->
g.
height, v=gi->height; z > gsw->dpos;) {
422 if (gsw->dpos != gw->
g.
width-1)
424 if (gsw->dpos != 0) {
425 for(z=0, v=gi->width; z < gsw->dpos; z += v) {
427 v -= z+v - gsw->dpos;
void gdispGDrawStringBox(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, const char *str, gFont font, gColor color, gJustify justify)
Draw a text string vertically centered within the specified box.
void gdispGFillArea(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, gColor color)
Fill an area with a color.
void gdispGDrawLine(GDisplay *g, gCoord x0, gCoord y0, gCoord x1, gCoord y1, gColor color)
Draw a line.
gI16 gCoord
The type for a coordinate or length on the screen.
void gdispGDrawBox(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, gColor color)
Draw a rectangular box.
GEvent * geventGetEventBuffer(GSourceListener *psl)
Get the event buffer from the GSourceListener.
void geventSendEvent(GSourceListener *psl)
Called by a source to indicate the listener's event buffer has been filled.
GSourceListener * geventGetSourceListener(GSourceHandle gsh, GSourceListener *lastlr)
Called by a source with a possible event to get a listener record.
#define GWIN_SLIDER_DEAD_BAND
The number of pixels of dead-band at each end of the slider.
#define GWIN_SLIDER_TOGGLE_INC
How many toggles it takes to go from minimum to maximum value on a slider.
gdispImageError gdispGImageDraw(GDisplay *g, gImage *img, gCoord x, gCoord y, gCoord cx, gCoord cy, gCoord sx, gCoord sy)
Draw the image.
void gwinSliderDraw_Std(GWidgetObject *gw, void *param)
The default rendering function for the slider widget.
void gwinSliderDraw_Image(GWidgetObject *gw, void *param)
The default rendering function.
void gwinSliderSetRange(GHandle gh, int min, int max)
Set the slider range.
GHandle gwinGSliderCreate(GDisplay *g, GSliderObject *gs, const GWidgetInit *pInit)
Create a slider window.
void gwinSliderSetPosition(GHandle gh, int pos)
Set the slider position.
void gwinSliderSendExtendedEvents(GHandle gh, gBool enabled)
Should the slider send extended events.
#define GSLIDER_FLG_EXTENDED_EVENTS
The internal slider object flags.
void gwinSetVisible(GHandle gh, gBool visible)
Sets whether a window is visible or not.
A window object structure.
const struct gwinVMT * vmt
The Virtual Method Table for a GWIN window.