Remove widget structure members when they are not needed for input tracking

Also doco update for Enabled Flag
remotes/origin_old/ugfx_release_2.6
inmarket 2013-07-06 01:45:24 +10:00
parent f3f9b7dc01
commit ab44f32859
8 changed files with 372 additions and 342 deletions

View File

@ -55,7 +55,9 @@ typedef struct GButtonColors {
*/ */
typedef struct GButtonObject_t { typedef struct GButtonObject_t {
GWidgetObject w; GWidgetObject w;
uint16_t toggle; #if GINPUT_NEED_TOGGLE
uint16_t toggle;
#endif
GButtonColors c_up; GButtonColors c_up;
GButtonColors c_dn; GButtonColors c_dn;
GButtonColors c_dis; GButtonColors c_dis;

View File

@ -50,7 +50,9 @@ typedef struct GCheckboxColors {
/* A Checkbox window */ /* A Checkbox window */
typedef struct GCheckboxObject_t { typedef struct GCheckboxObject_t {
GWidgetObject w; GWidgetObject w;
uint16_t toggle; #if GINPUT_NEED_TOGGLE
uint16_t toggle;
#endif
GCheckboxColors c; GCheckboxColors c;
} GCheckboxObject; } GCheckboxObject;

View File

@ -31,8 +31,8 @@
#define GWIN_FLG_VISIBLE 0x0002 // @< The window is visible #define GWIN_FLG_VISIBLE 0x0002 // @< The window is visible
#define GWIN_FLG_MINIMIZED 0x0004 // @< The window is minimized #define GWIN_FLG_MINIMIZED 0x0004 // @< The window is minimized
#define GWIN_FLG_MAXIMIZED 0x0008 // @< The window is maximized #define GWIN_FLG_MAXIMIZED 0x0008 // @< The window is maximized
#define GWIN_FLG_WIDGET 0x0010 // @< This is a widget #define GWIN_FLG_ENABLED 0x0010 // @< The window is enabled
#define GWIN_FLG_ENABLED 0x0020 // @< The widget is enabled #define GWIN_FLG_WIDGET 0x0020 // @< This is a widget
#define GWIN_FLG_ALLOCTXT 0x0040 // @< The widget text is allocated #define GWIN_FLG_ALLOCTXT 0x0040 // @< The widget text is allocated
#define GWIN_FLG_MOUSECAPTURE 0x0080 // @< The widget has captured the mouse #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 #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 { typedef struct gwidgetVMT {
struct gwinVMT g; // @< This is still a GWIN struct gwinVMT g; // @< This is still a GWIN
void (*DefaultDraw) (GWidgetObject *gw, void *param); // @< The default drawing routine (mandatory) void (*DefaultDraw) (GWidgetObject *gw, void *param); // @< The default drawing routine (mandatory)
struct { #if GINPUT_NEED_MOUSE
void (*MouseDown) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse down events (optional) struct {
void (*MouseUp) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse up events (optional) void (*MouseDown) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse down events (optional)
void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse move 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) #endif
void (*ToggleAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Assign a toggle to a role (optional) #if GINPUT_NEED_TOGGLE
uint16_t (*ToggleGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional) struct {
void (*ToggleOff) (GWidgetObject *gw, uint16_t role); // @< Process toggle off events (optional) uint16_t toggleroles; // @< The roles supported for toggles (0->toggleroles-1)
void (*ToggleOn) (GWidgetObject *gw, uint16_t role); // @< Process toggle on events (optional) 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)
struct { void (*ToggleOff) (GWidgetObject *gw, uint16_t role); // @< Process toggle off events (optional)
uint16_t dialroles; // @< The roles supported for dials (0->dialroles-1) void (*ToggleOn) (GWidgetObject *gw, uint16_t role); // @< Process toggle on events (optional)
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) #endif
void (*DialMove) (GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max); // @< Process dial move events (optional) #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; } gwidgetVMT;
/* @} */ /* @} */
#endif #endif

View File

@ -45,9 +45,13 @@ typedef struct GSliderColors {
// A slider window // A slider window
typedef struct GSliderObject_t { typedef struct GSliderObject_t {
GWidgetObject w; GWidgetObject w;
uint16_t t_dn; #if GINPUT_NEED_TOGGLE
uint16_t t_up; uint16_t t_dn;
uint16_t dial; uint16_t t_up;
#endif
#if GINPUT_NEED_DIAL
uint16_t dial;
#endif
coord_t dpos; coord_t dpos;
int min; int min;
int max; int max;

View File

@ -17,7 +17,7 @@
#include "gfx.h" #include "gfx.h"
#if (GFX_USE_GWIN && GWIN_NEED_BUTTON) || defined(__DOXYGEN__) #if GFX_USE_GWIN && GWIN_NEED_BUTTON
#include "gwin/class_gwin.h" #include "gwin/class_gwin.h"
@ -29,44 +29,6 @@
// Our pressed state // Our pressed state
#define GBUTTON_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0) #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 // Default color scheme
static const GButtonColors GButtonDefaultColorsUp = { static const GButtonColors GButtonDefaultColorsUp = {
HTML2COLOR(0x404040), // color_up_edge; HTML2COLOR(0x404040), // color_up_edge;
@ -103,59 +65,101 @@ static void SendButtonEvent(GWidgetObject *gw) {
#undef pbe #undef pbe
} }
// A mouse down has occurred over the button #if GINPUT_NEED_MOUSE
static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) { // A mouse down has occurred over the button
(void) x; (void) y; static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) {
gw->g.flags |= GBUTTON_FLG_PRESSED; (void) x; (void) y;
_gwidgetRedraw((GHandle)gw); gw->g.flags |= GBUTTON_FLG_PRESSED;
} _gwidgetRedraw((GHandle)gw);
}
// A mouse up has occurred (it may or may not be over the button) // 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) { static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) {
(void) x; (void) y; (void) x; (void) y;
gw->g.flags &= ~GBUTTON_FLG_PRESSED; gw->g.flags &= ~GBUTTON_FLG_PRESSED;
_gwidgetRedraw((GHandle)gw); _gwidgetRedraw((GHandle)gw);
#if !GWIN_BUTTON_LAZY_RELEASE #if !GWIN_BUTTON_LAZY_RELEASE
// If the mouse up was not over the button then cancel the event // 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) if (x < 0 || y < 0 || x >= gw->g.width || y >= gw->g.height)
return; return;
#endif
SendButtonEvent(gw);
}
#endif
#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);
}
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;
}
#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 #endif
#if GINPUT_NEED_TOGGLE
SendButtonEvent(gw); {
} 1, // 1 toggle role
ToggleAssign, // Assign Toggles
// A toggle off has occurred ToggleGet, // Get Toggles
static void ToggleOff(GWidgetObject *gw, uint16_t role) { ToggleOff, // Process toggle off events
(void) role; ToggleOn, // Process toggle on events
gw->g.flags &= ~GBUTTON_FLG_PRESSED; },
_gwidgetRedraw((GHandle)gw); #endif
} #if GINPUT_NEED_DIAL
{
// A toggle on has occurred 0, // No dial roles
static void ToggleOn(GWidgetObject *gw, uint16_t role) { 0, // Assign Dials (NOT USED)
(void) role; 0, // Get Dials (NOT USED)
gw->g.flags |= GBUTTON_FLG_PRESSED; 0, // Process dial move events (NOT USED)
_gwidgetRedraw((GHandle)gw); },
// Trigger the event on button down (different than for mouse/touch) #endif
SendButtonEvent(gw); };
}
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;
}
GHandle gwinCreateButton(GButtonObject *gw, const GWidgetInit *pInit) { GHandle gwinCreateButton(GButtonObject *gw, const GWidgetInit *pInit) {
if (!(gw = (GButtonObject *)_gwidgetCreate(&gw->w, pInit, &buttonVMT))) if (!(gw = (GButtonObject *)_gwidgetCreate(&gw->w, pInit, &buttonVMT)))
return 0; return 0;
gw->toggle = GWIDGET_NO_INSTANCE; #if GINPUT_NEED_TOGGLE
gw->toggle = GWIDGET_NO_INSTANCE;
#endif
gw->c_up = GButtonDefaultColorsUp; gw->c_up = GButtonDefaultColorsUp;
gw->c_dn = GButtonDefaultColorsDown; gw->c_dn = GButtonDefaultColorsDown;
gw->c_dis = GButtonDefaultColorsDisabled; gw->c_dis = GButtonDefaultColorsDisabled;

View File

@ -24,42 +24,6 @@
// Our checked state // Our checked state
#define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0) #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 = { static const GCheckboxColors defaultColors = {
Black, // border Black, // border
Grey, // selected Grey, // selected
@ -87,37 +51,77 @@ static void SendCheckboxEvent(GWidgetObject *gw) {
#undef pce #undef pce
} }
// A mouse down has occurred over the checkbox #if GINPUT_NEED_MOUSE
static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) { static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) {
(void) x; (void) y; (void) x; (void) y;
gw->g.flags ^= GCHECKBOX_FLG_CHECKED; gw->g.flags ^= GCHECKBOX_FLG_CHECKED;
_gwidgetRedraw((GHandle)gw); _gwidgetRedraw((GHandle)gw);
SendCheckboxEvent(gw); SendCheckboxEvent(gw);
} }
#endif
// A toggle on has occurred #if GINPUT_NEED_TOGGLE
static void ToggleOn(GWidgetObject *gw, uint16_t role) { static void ToggleOn(GWidgetObject *gw, uint16_t role) {
(void) role; (void) role;
gw->g.flags ^= GCHECKBOX_FLG_CHECKED; gw->g.flags ^= GCHECKBOX_FLG_CHECKED;
_gwidgetRedraw((GHandle)gw); _gwidgetRedraw((GHandle)gw);
SendCheckboxEvent(gw); SendCheckboxEvent(gw);
} }
static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) { static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
(void) role; (void) role;
((GCheckboxObject *)gw)->toggle = instance; ((GCheckboxObject *)gw)->toggle = instance;
} }
static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) { static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
(void) role; (void) role;
return ((GCheckboxObject *)gw)->toggle; return ((GCheckboxObject *)gw)->toggle;
} }
#endif
// 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) { GHandle gwinCreateCheckbox(GCheckboxObject *gb, const GWidgetInit *pInit) {
if (!(gb = (GCheckboxObject *)_gwidgetCreate(&gb->w, pInit, &checkboxVMT))) if (!(gb = (GCheckboxObject *)_gwidgetCreate(&gb->w, pInit, &checkboxVMT)))
return 0; return 0;
gb->toggle = (uint16_t) -1; #if GINPUT_NEED_TOGGLE
gb->toggle = GWIDGET_NO_INSTANCE;
#endif
gb->c = defaultColors; // assign the default colors gb->c = defaultColors; // assign the default colors
gwinSetVisible((GHandle)gb, pInit->g.show); gwinSetVisible((GHandle)gb, pInit->g.show);
return (GHandle)gb; return (GHandle)gb;

View File

@ -62,24 +62,30 @@ static const gwidgetVMT labelVMT = {
0, // The after-clear routine 0, // The after-clear routine
}, },
gwinLabelDefaultDraw, // default drawing routine gwinLabelDefaultDraw, // default drawing routine
{ #if GINPUT_NEED_MOUSE
0, // Process mose down events (NOT USED) {
0, // Process mouse up events (NOT USED) 0, // Process mose down events (NOT USED)
0, // Process mouse move events (NOT USED) 0, // Process mouse up events (NOT USED)
}, 0, // Process mouse move events (NOT USED)
{ },
0, // No toggle role #endif
0, // Assign Toggles (NOT USED) #if GINPUT_NEED_TOGGLE
0, // Get Toggles (NOT USED) {
0, // Process toggle off event (NOT USED) 0, // No toggle role
0, // Process toggle on event (NOT USED) 0, // Assign Toggles (NOT USED)
}, 0, // Get Toggles (NOT USED)
{ 0, // Process toggle off event (NOT USED)
0, // No dial roles 0, // Process toggle on event (NOT USED)
0, // Assign Dials (NOT USED) },
0, // Get Dials (NOT USED) #endif
0, // Procees dial move events (NOT USED) #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) { GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) {

View File

@ -29,46 +29,6 @@
#define GWIN_SLIDER_TOGGLE_INC 20 // How many toggles to go from minimum to maximum #define GWIN_SLIDER_TOGGLE_INC 20 // How many toggles to go from minimum to maximum
#endif #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 = { static const GSliderColors GSliderDefaultColors = {
HTML2COLOR(0x404040), // color_edge HTML2COLOR(0x404040), // color_edge
HTML2COLOR(0x000000), // color_thumb 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); gsw->dpos = ((gsw->w.g.width-1)*(gsw->pos-gsw->min))/(gsw->max-gsw->min);
} }
// A mouse up event #if GINPUT_NEED_MOUSE
static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) { // A mouse up event
#define gsw ((GSliderObject *)gw) static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) {
#define gh ((GHandle)gw) #define gsw ((GSliderObject *)gw)
#define gh ((GHandle)gw)
#if GWIN_BUTTON_LAZY_RELEASE #if GWIN_BUTTON_LAZY_RELEASE
// Clip to the slider // Clip to the slider
if (x < 0) x = 0; if (x < 0) x = 0;
else if (x >= gh->width) x = gh->width-1; else if (x >= gh->width) x = gh->width-1;
if (y < 0) y = 0; if (y < 0) y = 0;
else if (y >= gh->height) x = gh->height-1; else if (y >= gh->height) x = gh->height-1;
#else #else
// Are we over the slider? // Are we over the slider?
if (x < 0 || x >= gh->width || y < 0 || y >= gh->height) { if (x < 0 || x >= gh->width || y < 0 || y >= gh->height) {
// No - restore the slider // No - restore the slider
ResetDisplayPos(gsw); ResetDisplayPos(gsw);
_gwidgetRedraw(gh); _gwidgetRedraw(gh);
return; 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 ResetDisplayPos(gsw);
if (gh->width < gh->height) { _gwidgetRedraw(gh);
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); // Generate the event
_gwidgetRedraw(gh);
// Generate the event
SendSliderEvent(gw);
#undef gh
#undef gsw
}
// 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;
}
// 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); SendSliderEvent(gw);
#undef gh
#undef gsw
} }
#undef gsw
}
// A dial move event // A mouse move (or mouse down) event
static void DialMove(GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max) { static void MouseMove(GWidgetObject *gw, coord_t x, coord_t y) {
#if GFX_USE_GINPUT && GINPUT_NEED_DIAL #define gsw ((GSliderObject *)gw)
#define gsw ((GSliderObject *)gw)
(void) role;
// Set the new position // Determine the temporary display position (with range checking)
gsw->pos = (uint16_t)((uint32_t)value*(gsw->max-gsw->min)/max + gsw->min); 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;
}
ResetDisplayPos(gsw); // Update the display
gwinDraw(&gw->g); _gwidgetRedraw(&gw->g);
#undef gsw
// Generate the event }
SendSliderEvent(gw);
#undef gsw
#else
(void)gw; (void)role; (void)value; (void)max;
#endif #endif
}
static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) { #if GINPUT_NEED_TOGGLE
if (role) // A toggle on has occurred
((GSliderObject *)gw)->t_up = instance; static void ToggleOn(GWidgetObject *gw, uint16_t role) {
else #define gsw ((GSliderObject *)gw)
((GSliderObject *)gw)->t_dn = instance;
}
static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) { if (role) {
return role ? ((GSliderObject *)gw)->t_up : ((GSliderObject *)gw)->t_dn; 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
}
static void DialAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) { static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
(void) role; if (role)
((GSliderObject *)gw)->dial = instance; ((GSliderObject *)gw)->t_up = instance;
} else
((GSliderObject *)gw)->t_dn = instance;
}
static uint16_t DialGet(GWidgetObject *gw, uint16_t role) { static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
(void) role; return role ? ((GSliderObject *)gw)->t_up : ((GSliderObject *)gw)->t_dn;
return ((GSliderObject *)gw)->dial; }
} #endif
#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;
// Set the new position
gsw->pos = (uint16_t)((uint32_t)value*(gsw->max-gsw->min)/max + gsw->min);
ResetDisplayPos(gsw);
_gwidgetRedraw((GHandle)gw);
// Generate the event
SendSliderEvent(gw);
#undef gsw
}
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
// 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) { GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) {
if (!(gs = (GSliderObject *)_gwidgetCreate(&gs->w, pInit, &sliderVMT))) if (!(gs = (GSliderObject *)_gwidgetCreate(&gs->w, pInit, &sliderVMT)))
return 0; return 0;
gs->t_dn = (uint16_t) -1; #if GINPUT_NEED_TOGGLE
gs->t_up = (uint16_t) -1; gs->t_dn = GWIDGET_NO_INSTANCE;
gs->dial = (uint16_t) -1; gs->t_up = GWIDGET_NO_INSTANCE;
#endif
#if GINPUT_NEED_DIAL
gs->dial = GWIDGET_NO_INSTANCE;
#endif
gs->c = GSliderDefaultColors; gs->c = GSliderDefaultColors;
gs->min = 0; gs->min = 0;
gs->max = 100; gs->max = 100;