aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/gwin/button.h4
-rw-r--r--include/gwin/checkbox.h4
-rw-r--r--include/gwin/class_gwin.h46
-rw-r--r--include/gwin/slider.h10
-rw-r--r--src/gwin/button.c164
-rw-r--r--src/gwin/checkbox.c122
-rw-r--r--src/gwin/label.c42
-rw-r--r--src/gwin/slider.c306
8 files changed, 364 insertions, 334 deletions
diff --git a/include/gwin/button.h b/include/gwin/button.h
index 73f42e37..afe6d0cc 100644
--- a/include/gwin/button.h
+++ b/include/gwin/button.h
@@ -55,7 +55,9 @@ typedef struct GButtonColors {
*/
typedef struct GButtonObject_t {
GWidgetObject w;
- uint16_t toggle;
+ #if GINPUT_NEED_TOGGLE
+ uint16_t toggle;
+ #endif
GButtonColors c_up;
GButtonColors c_dn;
GButtonColors c_dis;
diff --git a/include/gwin/checkbox.h b/include/gwin/checkbox.h
index 2823007a..679a5d9c 100644
--- a/include/gwin/checkbox.h
+++ b/include/gwin/checkbox.h
@@ -50,7 +50,9 @@ typedef struct GCheckboxColors {
/* A Checkbox window */
typedef struct GCheckboxObject_t {
GWidgetObject w;
- uint16_t toggle;
+ #if GINPUT_NEED_TOGGLE
+ uint16_t toggle;
+ #endif
GCheckboxColors c;
} GCheckboxObject;
diff --git a/include/gwin/class_gwin.h b/include/gwin/class_gwin.h
index dbda3619..1a4de5b9 100644
--- a/include/gwin/class_gwin.h
+++ b/include/gwin/class_gwin.h
@@ -31,8 +31,8 @@
#define GWIN_FLG_VISIBLE 0x0002 // @< The window is visible
#define GWIN_FLG_MINIMIZED 0x0004 // @< The window is minimized
#define GWIN_FLG_MAXIMIZED 0x0008 // @< The window is maximized
-#define GWIN_FLG_WIDGET 0x0010 // @< This is a widget
-#define GWIN_FLG_ENABLED 0x0020 // @< The widget is enabled
+#define GWIN_FLG_ENABLED 0x0010 // @< The window is enabled
+#define GWIN_FLG_WIDGET 0x0020 // @< This is a widget
#define GWIN_FLG_ALLOCTXT 0x0040 // @< The widget text is allocated
#define GWIN_FLG_MOUSECAPTURE 0x0080 // @< The widget has captured the mouse
#define GWIN_FIRST_WM_FLAG 0x0100 // @< 4 bits free for the window manager to use
@@ -76,24 +76,30 @@ typedef struct gwinVMT {
typedef struct gwidgetVMT {
struct gwinVMT g; // @< This is still a GWIN
void (*DefaultDraw) (GWidgetObject *gw, void *param); // @< The default drawing routine (mandatory)
- struct {
- void (*MouseDown) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse down events (optional)
- void (*MouseUp) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse up events (optional)
- void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse move events (optional)
- };
- struct {
- uint16_t toggleroles; // @< The roles supported for toggles (0->toggleroles-1)
- void (*ToggleAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Assign a toggle to a role (optional)
- uint16_t (*ToggleGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional)
- void (*ToggleOff) (GWidgetObject *gw, uint16_t role); // @< Process toggle off events (optional)
- void (*ToggleOn) (GWidgetObject *gw, uint16_t role); // @< Process toggle on events (optional)
- };
- struct {
- uint16_t dialroles; // @< The roles supported for dials (0->dialroles-1)
- void (*DialAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the dial instance handle (optional)
- uint16_t (*DialGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional)
- void (*DialMove) (GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max); // @< Process dial move events (optional)
- };
+ #if GINPUT_NEED_MOUSE
+ struct {
+ void (*MouseDown) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse down events (optional)
+ void (*MouseUp) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse up events (optional)
+ void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse move events (optional)
+ };
+ #endif
+ #if GINPUT_NEED_TOGGLE
+ struct {
+ uint16_t toggleroles; // @< The roles supported for toggles (0->toggleroles-1)
+ void (*ToggleAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Assign a toggle to a role (optional)
+ uint16_t (*ToggleGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional)
+ void (*ToggleOff) (GWidgetObject *gw, uint16_t role); // @< Process toggle off events (optional)
+ void (*ToggleOn) (GWidgetObject *gw, uint16_t role); // @< Process toggle on events (optional)
+ };
+ #endif
+ #if GINPUT_NEED_TOGGLE
+ struct {
+ uint16_t dialroles; // @< The roles supported for dials (0->dialroles-1)
+ void (*DialAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the dial instance handle (optional)
+ uint16_t (*DialGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional)
+ void (*DialMove) (GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max); // @< Process dial move events (optional)
+ };
+ #endif
} gwidgetVMT;
/* @} */
#endif
diff --git a/include/gwin/slider.h b/include/gwin/slider.h
index 57bd5a72..a8cf7ecf 100644
--- a/include/gwin/slider.h
+++ b/include/gwin/slider.h
@@ -45,9 +45,13 @@ typedef struct GSliderColors {
// A slider window
typedef struct GSliderObject_t {
GWidgetObject w;
- uint16_t t_dn;
- uint16_t t_up;
- uint16_t dial;
+ #if GINPUT_NEED_TOGGLE
+ uint16_t t_dn;
+ uint16_t t_up;
+ #endif
+ #if GINPUT_NEED_DIAL
+ uint16_t dial;
+ #endif
coord_t dpos;
int min;
int max;
diff --git a/src/gwin/button.c b/src/gwin/button.c
index 303d1078..73f56c2e 100644
--- a/src/gwin/button.c
+++ b/src/gwin/button.c
@@ -17,7 +17,7 @@
#include "gfx.h"
-#if (GFX_USE_GWIN && GWIN_NEED_BUTTON) || defined(__DOXYGEN__)
+#if GFX_USE_GWIN && GWIN_NEED_BUTTON
#include "gwin/class_gwin.h"
@@ -29,44 +29,6 @@
// Our pressed state
#define GBUTTON_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0)
-// Prototypes for button VMT functions
-static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y);
-static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y);
-static void ToggleOff(GWidgetObject *gw, uint16_t role);
-static void ToggleOn(GWidgetObject *gw, uint16_t role);
-static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance);
-static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role);
-
-// The button VMT table
-static const gwidgetVMT buttonVMT = {
- {
- "Button", // The classname
- sizeof(GButtonObject), // The object size
- _gwidgetDestroy, // The destroy routine
- _gwidgetRedraw, // The redraw routine
- 0, // The after-clear routine
- },
- gwinButtonDraw_3D, // The default drawing routine
- {
- MouseDown, // Process mouse down events
- MouseUp, // Process mouse up events
- 0, // Process mouse move events (NOT USED)
- },
- {
- 1, // 1 toggle role
- ToggleAssign, // Assign Toggles
- ToggleGet, // Get Toggles
- ToggleOff, // Process toggle off events
- ToggleOn, // Process toggle on events
- },
- {
- 0, // No dial roles
- 0, // Assign Dials (NOT USED)
- 0, // Get Dials (NOT USED)
- 0, // Process dial move events (NOT USED)
- }
-};
-
// Default color scheme
static const GButtonColors GButtonDefaultColorsUp = {
HTML2COLOR(0x404040), // color_up_edge;
@@ -103,59 +65,101 @@ static void SendButtonEvent(GWidgetObject *gw) {
#undef pbe
}
-// A mouse down has occurred over the button
-static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) {
- (void) x; (void) y;
- gw->g.flags |= GBUTTON_FLG_PRESSED;
- _gwidgetRedraw((GHandle)gw);
-}
+#if GINPUT_NEED_MOUSE
+ // A mouse down has occurred over the button
+ static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) {
+ (void) x; (void) y;
+ gw->g.flags |= GBUTTON_FLG_PRESSED;
+ _gwidgetRedraw((GHandle)gw);
+ }
-// A mouse up has occurred (it may or may not be over the button)
-static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) {
- (void) x; (void) y;
- gw->g.flags &= ~GBUTTON_FLG_PRESSED;
- _gwidgetRedraw((GHandle)gw);
+ // A mouse up has occurred (it may or may not be over the button)
+ static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) {
+ (void) x; (void) y;
+ gw->g.flags &= ~GBUTTON_FLG_PRESSED;
+ _gwidgetRedraw((GHandle)gw);
- #if !GWIN_BUTTON_LAZY_RELEASE
- // If the mouse up was not over the button then cancel the event
- if (x < 0 || y < 0 || x >= gw->g.width || y >= gw->g.height)
- return;
- #endif
+ #if !GWIN_BUTTON_LAZY_RELEASE
+ // If the mouse up was not over the button then cancel the event
+ if (x < 0 || y < 0 || x >= gw->g.width || y >= gw->g.height)
+ return;
+ #endif
- SendButtonEvent(gw);
-}
+ SendButtonEvent(gw);
+ }
+#endif
-// A toggle off has occurred
-static void ToggleOff(GWidgetObject *gw, uint16_t role) {
- (void) role;
- gw->g.flags &= ~GBUTTON_FLG_PRESSED;
- _gwidgetRedraw((GHandle)gw);
-}
+#if GINPUT_NEED_TOGGLE
+ // A toggle off has occurred
+ static void ToggleOff(GWidgetObject *gw, uint16_t role) {
+ (void) role;
+ gw->g.flags &= ~GBUTTON_FLG_PRESSED;
+ _gwidgetRedraw((GHandle)gw);
+ }
-// A toggle on has occurred
-static void ToggleOn(GWidgetObject *gw, uint16_t role) {
- (void) role;
- gw->g.flags |= GBUTTON_FLG_PRESSED;
- _gwidgetRedraw((GHandle)gw);
- // Trigger the event on button down (different than for mouse/touch)
- SendButtonEvent(gw);
-}
+ // A toggle on has occurred
+ static void ToggleOn(GWidgetObject *gw, uint16_t role) {
+ (void) role;
+ gw->g.flags |= GBUTTON_FLG_PRESSED;
+ _gwidgetRedraw((GHandle)gw);
+ // Trigger the event on button down (different than for mouse/touch)
+ SendButtonEvent(gw);
+ }
-static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
- (void) role;
- ((GButtonObject *)gw)->toggle = instance;
-}
+ static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
+ (void) role;
+ ((GButtonObject *)gw)->toggle = instance;
+ }
-static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
- (void) role;
- return ((GButtonObject *)gw)->toggle;
-}
+ static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
+ (void) role;
+ return ((GButtonObject *)gw)->toggle;
+ }
+#endif
+
+// The button VMT table
+static const gwidgetVMT buttonVMT = {
+ {
+ "Button", // The classname
+ sizeof(GButtonObject), // The object size
+ _gwidgetDestroy, // The destroy routine
+ _gwidgetRedraw, // The redraw routine
+ 0, // The after-clear routine
+ },
+ gwinButtonDraw_3D, // The default drawing routine
+ #if GINPUT_NEED_MOUSE
+ {
+ MouseDown, // Process mouse down events
+ MouseUp, // Process mouse up events
+ 0, // Process mouse move events (NOT USED)
+ },
+ #endif
+ #if GINPUT_NEED_TOGGLE
+ {
+ 1, // 1 toggle role
+ ToggleAssign, // Assign Toggles
+ ToggleGet, // Get Toggles
+ ToggleOff, // Process toggle off events
+ ToggleOn, // Process toggle on events
+ },
+ #endif
+ #if GINPUT_NEED_DIAL
+ {
+ 0, // No dial roles
+ 0, // Assign Dials (NOT USED)
+ 0, // Get Dials (NOT USED)
+ 0, // Process dial move events (NOT USED)
+ },
+ #endif
+};
GHandle gwinCreateButton(GButtonObject *gw, const GWidgetInit *pInit) {
if (!(gw = (GButtonObject *)_gwidgetCreate(&gw->w, pInit, &buttonVMT)))
return 0;
- gw->toggle = GWIDGET_NO_INSTANCE;
+ #if GINPUT_NEED_TOGGLE
+ gw->toggle = GWIDGET_NO_INSTANCE;
+ #endif
gw->c_up = GButtonDefaultColorsUp;
gw->c_dn = GButtonDefaultColorsDown;
gw->c_dis = GButtonDefaultColorsDisabled;
diff --git a/src/gwin/checkbox.c b/src/gwin/checkbox.c
index 62f4c55b..74d612d2 100644
--- a/src/gwin/checkbox.c
+++ b/src/gwin/checkbox.c
@@ -24,42 +24,6 @@
// Our checked state
#define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0)
-// Prototypes for button VMT functions
-static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y);
-static void ToggleOn(GWidgetObject *gw, uint16_t role);
-static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance);
-static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role);
-
-// The button VMT table
-static const gwidgetVMT checkboxVMT = {
- {
- "Checkbox", // The classname
- sizeof(GCheckboxObject),// The object size
- _gwidgetDestroy, // The destroy routine
- _gwidgetRedraw, // The redraw routine
- 0, // The after-clear routine
- },
- gwinCheckboxDraw_CheckOnLeft, // The default drawing routine
- {
- MouseDown, // Process mouse down events
- 0, // Process mouse up events (NOT USED)
- 0, // Process mouse move events (NOT USED)
- },
- {
- 1, // 1 toggle role
- ToggleAssign, // Assign Toggles
- ToggleGet, // Get Toggles
- 0, // Process toggle off events (NOT USED)
- ToggleOn, // Process toggle on events
- },
- {
- 0, // No dial roles
- 0, // Assign Dials (NOT USED)
- 0, // Get Dials (NOT USED)
- 0, // Process dial move events (NOT USED)
- }
-};
-
static const GCheckboxColors defaultColors = {
Black, // border
Grey, // selected
@@ -87,37 +51,77 @@ static void SendCheckboxEvent(GWidgetObject *gw) {
#undef pce
}
-// A mouse down has occurred over the checkbox
-static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) {
- (void) x; (void) y;
- gw->g.flags ^= GCHECKBOX_FLG_CHECKED;
- _gwidgetRedraw((GHandle)gw);
- SendCheckboxEvent(gw);
-}
+#if GINPUT_NEED_MOUSE
+ static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) {
+ (void) x; (void) y;
+ gw->g.flags ^= GCHECKBOX_FLG_CHECKED;
+ _gwidgetRedraw((GHandle)gw);
+ SendCheckboxEvent(gw);
+ }
+#endif
+
+#if GINPUT_NEED_TOGGLE
+ static void ToggleOn(GWidgetObject *gw, uint16_t role) {
+ (void) role;
+ gw->g.flags ^= GCHECKBOX_FLG_CHECKED;
+ _gwidgetRedraw((GHandle)gw);
+ SendCheckboxEvent(gw);
+ }
-// A toggle on has occurred
-static void ToggleOn(GWidgetObject *gw, uint16_t role) {
- (void) role;
- gw->g.flags ^= GCHECKBOX_FLG_CHECKED;
- _gwidgetRedraw((GHandle)gw);
- SendCheckboxEvent(gw);
-}
+ static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
+ (void) role;
+ ((GCheckboxObject *)gw)->toggle = instance;
+ }
-static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
- (void) role;
- ((GCheckboxObject *)gw)->toggle = instance;
-}
+ static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
+ (void) role;
+ return ((GCheckboxObject *)gw)->toggle;
+ }
+#endif
-static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
- (void) role;
- return ((GCheckboxObject *)gw)->toggle;
-}
+// The checkbox VMT table
+static const gwidgetVMT checkboxVMT = {
+ {
+ "Checkbox", // The classname
+ sizeof(GCheckboxObject),// The object size
+ _gwidgetDestroy, // The destroy routine
+ _gwidgetRedraw, // The redraw routine
+ 0, // The after-clear routine
+ },
+ gwinCheckboxDraw_CheckOnLeft, // The default drawing routine
+ #if GINPUT_NEED_MOUSE
+ {
+ MouseDown, // Process mouse down events
+ 0, // Process mouse up events (NOT USED)
+ 0, // Process mouse move events (NOT USED)
+ },
+ #endif
+ #if GINPUT_NEED_TOGGLE
+ {
+ 1, // 1 toggle role
+ ToggleAssign, // Assign Toggles
+ ToggleGet, // Get Toggles
+ 0, // Process toggle off events (NOT USED)
+ ToggleOn, // Process toggle on events
+ },
+ #endif
+ #if GINPUT_NEED_DIAL
+ {
+ 0, // No dial roles
+ 0, // Assign Dials (NOT USED)
+ 0, // Get Dials (NOT USED)
+ 0, // Process dial move events (NOT USED)
+ },
+ #endif
+};
GHandle gwinCreateCheckbox(GCheckboxObject *gb, const GWidgetInit *pInit) {
if (!(gb = (GCheckboxObject *)_gwidgetCreate(&gb->w, pInit, &checkboxVMT)))
return 0;
- gb->toggle = (uint16_t) -1;
+ #if GINPUT_NEED_TOGGLE
+ gb->toggle = GWIDGET_NO_INSTANCE;
+ #endif
gb->c = defaultColors; // assign the default colors
gwinSetVisible((GHandle)gb, pInit->g.show);
return (GHandle)gb;
diff --git a/src/gwin/label.c b/src/gwin/label.c
index e757892d..cd469210 100644
--- a/src/gwin/label.c
+++ b/src/gwin/label.c
@@ -62,24 +62,30 @@ static const gwidgetVMT labelVMT = {
0, // The after-clear routine
},
gwinLabelDefaultDraw, // default drawing routine
- {
- 0, // Process mose down events (NOT USED)
- 0, // Process mouse up events (NOT USED)
- 0, // Process mouse move events (NOT USED)
- },
- {
- 0, // No toggle role
- 0, // Assign Toggles (NOT USED)
- 0, // Get Toggles (NOT USED)
- 0, // Process toggle off event (NOT USED)
- 0, // Process toggle on event (NOT USED)
- },
- {
- 0, // No dial roles
- 0, // Assign Dials (NOT USED)
- 0, // Get Dials (NOT USED)
- 0, // Procees dial move events (NOT USED)
- }
+ #if GINPUT_NEED_MOUSE
+ {
+ 0, // Process mose down events (NOT USED)
+ 0, // Process mouse up events (NOT USED)
+ 0, // Process mouse move events (NOT USED)
+ },
+ #endif
+ #if GINPUT_NEED_TOGGLE
+ {
+ 0, // No toggle role
+ 0, // Assign Toggles (NOT USED)
+ 0, // Get Toggles (NOT USED)
+ 0, // Process toggle off event (NOT USED)
+ 0, // Process toggle on event (NOT USED)
+ },
+ #endif
+ #if GINPUT_NEED_DIAL
+ {
+ 0, // No dial roles
+ 0, // Assign Dials (NOT USED)
+ 0, // Get Dials (NOT USED)
+ 0, // Procees dial move events (NOT USED)
+ },
+ #endif
};
GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) {
diff --git a/src/gwin/slider.c b/src/gwin/slider.c
index 2dfa3a7c..5aa320f8 100644
--- a/src/gwin/slider.c
+++ b/src/gwin/slider.c
@@ -29,46 +29,6 @@
#define GWIN_SLIDER_TOGGLE_INC 20 // How many toggles to go from minimum to maximum
#endif
-// Prototypes for slider VMT functions
-static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y);
-static void MouseMove(GWidgetObject *gw, coord_t x, coord_t y);
-static void ToggleOn(GWidgetObject *gw, uint16_t role);
-static void DialMove(GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max);
-static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance);
-static void DialAssign(GWidgetObject *gw, uint16_t role, uint16_t instance);
-static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role);
-static uint16_t DialGet(GWidgetObject *gw, uint16_t role);
-
-// The button VMT table
-static const gwidgetVMT sliderVMT = {
- {
- "Slider", // The classname
- sizeof(GSliderObject), // The object size
- _gwidgetDestroy, // The destroy routine
- _gwidgetRedraw, // The redraw routine
- 0, // The after-clear routine
- },
- gwinSliderDraw_Std, // The default drawing routine
- {
- 0, // Process mouse down events (NOT USED)
- MouseUp, // Process mouse up events
- MouseMove, // Process mouse move events
- },
- {
- 2, // 1 toggle role
- ToggleAssign, // Assign Toggles
- ToggleGet, // Get Toggles
- 0, // Process toggle off events (NOT USED)
- ToggleOn, // Process toggle on events
- },
- {
- 1, // 1 dial roles
- DialAssign, // Assign Dials
- DialGet, // Get Dials
- DialMove, // Process dial move events
- }
-};
-
static const GSliderColors GSliderDefaultColors = {
HTML2COLOR(0x404040), // color_edge
HTML2COLOR(0x000000), // color_thumb
@@ -105,140 +65,182 @@ static void ResetDisplayPos(GSliderObject *gsw) {
gsw->dpos = ((gsw->w.g.width-1)*(gsw->pos-gsw->min))/(gsw->max-gsw->min);
}
-// A mouse up event
-static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) {
- #define gsw ((GSliderObject *)gw)
- #define gh ((GHandle)gw)
-
- #if GWIN_BUTTON_LAZY_RELEASE
- // Clip to the slider
- if (x < 0) x = 0;
- else if (x >= gh->width) x = gh->width-1;
- if (y < 0) y = 0;
- else if (y >= gh->height) x = gh->height-1;
- #else
- // Are we over the slider?
- if (x < 0 || x >= gh->width || y < 0 || y >= gh->height) {
- // No - restore the slider
- ResetDisplayPos(gsw);
- _gwidgetRedraw(gh);
- return;
+#if GINPUT_NEED_MOUSE
+ // A mouse up event
+ static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) {
+ #define gsw ((GSliderObject *)gw)
+ #define gh ((GHandle)gw)
+
+ #if GWIN_BUTTON_LAZY_RELEASE
+ // Clip to the slider
+ if (x < 0) x = 0;
+ else if (x >= gh->width) x = gh->width-1;
+ if (y < 0) y = 0;
+ else if (y >= gh->height) x = gh->height-1;
+ #else
+ // Are we over the slider?
+ if (x < 0 || x >= gh->width || y < 0 || y >= gh->height) {
+ // No - restore the slider
+ ResetDisplayPos(gsw);
+ _gwidgetRedraw(gh);
+ return;
+ }
+ #endif
+
+ // Set the new position
+ if (gh->width < gh->height) {
+ if (y > gh->height-GWIN_SLIDER_DEAD_BAND)
+ gsw->pos = gsw->min;
+ else if (y < GWIN_SLIDER_DEAD_BAND)
+ gsw->pos = gsw->max;
+ else
+ gsw->pos = (uint16_t)((int32_t)(gh->height-1-y-GWIN_SLIDER_DEAD_BAND)*(gsw->max-gsw->min)/(gh->height-2*GWIN_SLIDER_DEAD_BAND) + gsw->min);
+ } else {
+ if (x > gh->width-GWIN_SLIDER_DEAD_BAND)
+ gsw->pos = gsw->max;
+ else if (x < GWIN_SLIDER_DEAD_BAND)
+ gsw->pos = gsw->min;
+ else
+ gsw->pos = (uint16_t)((int32_t)(x-GWIN_SLIDER_DEAD_BAND)*(gsw->max-gsw->min)/(gh->width-2*GWIN_SLIDER_DEAD_BAND) + gsw->min);
}
- #endif
- // Set the new position
- if (gh->width < gh->height) {
- if (y > gh->height-GWIN_SLIDER_DEAD_BAND)
- gsw->pos = gsw->min;
- else if (y < GWIN_SLIDER_DEAD_BAND)
- gsw->pos = gsw->max;
- else
- gsw->pos = (uint16_t)((int32_t)(gh->height-1-y-GWIN_SLIDER_DEAD_BAND)*(gsw->max-gsw->min)/(gh->height-2*GWIN_SLIDER_DEAD_BAND) + gsw->min);
- } else {
- if (x > gh->width-GWIN_SLIDER_DEAD_BAND)
- gsw->pos = gsw->max;
- else if (x < GWIN_SLIDER_DEAD_BAND)
- gsw->pos = gsw->min;
- else
- gsw->pos = (uint16_t)((int32_t)(x-GWIN_SLIDER_DEAD_BAND)*(gsw->max-gsw->min)/(gh->width-2*GWIN_SLIDER_DEAD_BAND) + gsw->min);
+ ResetDisplayPos(gsw);
+ _gwidgetRedraw(gh);
+
+ // Generate the event
+ SendSliderEvent(gw);
+ #undef gh
+ #undef gsw
}
- ResetDisplayPos(gsw);
- _gwidgetRedraw(gh);
+ // A mouse move (or mouse down) event
+ static void MouseMove(GWidgetObject *gw, coord_t x, coord_t y) {
+ #define gsw ((GSliderObject *)gw)
+
+ // Determine the temporary display position (with range checking)
+ if (gw->g.width < gw->g.height) {
+ if (y < 0)
+ gsw->dpos = 0;
+ else if (y >= gw->g.height)
+ gsw->dpos = gw->g.height-1;
+ else
+ gsw->dpos = y;
+ } else {
+ if (x < 0)
+ gsw->dpos = 0;
+ else if (x >= gw->g.width)
+ gsw->dpos = gw->g.width-1;
+ else
+ gsw->dpos = x;
+ }
- // Generate the event
- SendSliderEvent(gw);
- #undef gh
- #undef gsw
-}
+ // Update the display
+ _gwidgetRedraw(&gw->g);
+ #undef gsw
+ }
+#endif
-// A mouse move (or mouse down) event
-static void MouseMove(GWidgetObject *gw, coord_t x, coord_t y) {
- #define gsw ((GSliderObject *)gw)
+#if GINPUT_NEED_TOGGLE
+ // A toggle on has occurred
+ static void ToggleOn(GWidgetObject *gw, uint16_t role) {
+ #define gsw ((GSliderObject *)gw)
+
+ if (role) {
+ gwinSetSliderPosition((GHandle)gw, gsw->pos+(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
+ SendSliderEvent(gw);
+ } else {
+ gwinSetSliderPosition((GHandle)gw, gsw->pos-(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
+ SendSliderEvent(gw);
+ }
+ #undef gsw
+ }
- // Determine the temporary display position (with range checking)
- if (gw->g.width < gw->g.height) {
- if (y < 0)
- gsw->dpos = 0;
- else if (y >= gw->g.height)
- gsw->dpos = gw->g.height-1;
+ static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
+ if (role)
+ ((GSliderObject *)gw)->t_up = instance;
else
- gsw->dpos = y;
- } else {
- if (x < 0)
- gsw->dpos = 0;
- else if (x >= gw->g.width)
- gsw->dpos = gw->g.width-1;
- else
- gsw->dpos = x;
+ ((GSliderObject *)gw)->t_dn = instance;
}
- // Update the display
- _gwidgetRedraw(&gw->g);
- #undef gsw
-}
-
-// A toggle on has occurred
-static void ToggleOn(GWidgetObject *gw, uint16_t role) {
- #define gsw ((GSliderObject *)gw)
-
- if (role) {
- gwinSetSliderPosition((GHandle)gw, gsw->pos+(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
- SendSliderEvent(gw);
- } else {
- gwinSetSliderPosition((GHandle)gw, gsw->pos-(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
- SendSliderEvent(gw);
+ static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
+ return role ? ((GSliderObject *)gw)->t_up : ((GSliderObject *)gw)->t_dn;
}
- #undef gsw
-}
-
-// A dial move event
-static void DialMove(GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max) {
-#if GFX_USE_GINPUT && GINPUT_NEED_DIAL
- #define gsw ((GSliderObject *)gw)
- (void) role;
+#endif
- // Set the new position
- gsw->pos = (uint16_t)((uint32_t)value*(gsw->max-gsw->min)/max + gsw->min);
+#if GINPUT_NEED_DIAL
+ // A dial move event
+ static void DialMove(GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max) {
+ #define gsw ((GSliderObject *)gw)
+ (void) role;
- ResetDisplayPos(gsw);
- gwinDraw(&gw->g);
+ // Set the new position
+ gsw->pos = (uint16_t)((uint32_t)value*(gsw->max-gsw->min)/max + gsw->min);
- // Generate the event
- SendSliderEvent(gw);
- #undef gsw
-#else
- (void)gw; (void)role; (void)value; (void)max;
-#endif
-}
+ ResetDisplayPos(gsw);
+ _gwidgetRedraw((GHandle)gw);
-static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
- if (role)
- ((GSliderObject *)gw)->t_up = instance;
- else
- ((GSliderObject *)gw)->t_dn = instance;
-}
+ // Generate the event
+ SendSliderEvent(gw);
+ #undef gsw
+ }
-static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
- return role ? ((GSliderObject *)gw)->t_up : ((GSliderObject *)gw)->t_dn;
-}
+ static void DialAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
+ (void) role;
+ ((GSliderObject *)gw)->dial = instance;
+ }
-static void DialAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
- (void) role;
- ((GSliderObject *)gw)->dial = instance;
-}
+ static uint16_t DialGet(GWidgetObject *gw, uint16_t role) {
+ (void) role;
+ return ((GSliderObject *)gw)->dial;
+ }
+#endif
-static uint16_t DialGet(GWidgetObject *gw, uint16_t role) {
- (void) role;
- return ((GSliderObject *)gw)->dial;
-}
+// The slider VMT table
+static const gwidgetVMT sliderVMT = {
+ {
+ "Slider", // The classname
+ sizeof(GSliderObject), // The object size
+ _gwidgetDestroy, // The destroy routine
+ _gwidgetRedraw, // The redraw routine
+ 0, // The after-clear routine
+ },
+ gwinSliderDraw_Std, // The default drawing routine
+ #if GINPUT_NEED_MOUSE
+ {
+ 0, // Process mouse down events (NOT USED)
+ MouseUp, // Process mouse up events
+ MouseMove, // Process mouse move events
+ },
+ #endif
+ #if GINPUT_NEED_TOGGLE
+ {
+ 2, // 1 toggle role
+ ToggleAssign, // Assign Toggles
+ ToggleGet, // Get Toggles
+ 0, // Process toggle off events (NOT USED)
+ ToggleOn, // Process toggle on events
+ },
+ #endif
+ #if GINPUT_NEED_DIAL
+ {
+ 1, // 1 dial roles
+ DialAssign, // Assign Dials
+ DialGet, // Get Dials
+ DialMove, // Process dial move events
+ },
+ #endif
+};
GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) {
if (!(gs = (GSliderObject *)_gwidgetCreate(&gs->w, pInit, &sliderVMT)))
return 0;
- gs->t_dn = (uint16_t) -1;
- gs->t_up = (uint16_t) -1;
- gs->dial = (uint16_t) -1;
+ #if GINPUT_NEED_TOGGLE
+ gs->t_dn = GWIDGET_NO_INSTANCE;
+ gs->t_up = GWIDGET_NO_INSTANCE;
+ #endif
+ #if GINPUT_NEED_DIAL
+ gs->dial = GWIDGET_NO_INSTANCE;
+ #endif
gs->c = GSliderDefaultColors;
gs->min = 0;
gs->max = 100;