2013-06-02 04:14:49 +00:00
|
|
|
/*
|
2013-06-15 11:09:02 +00:00
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
2013-06-02 04:14:49 +00:00
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2013-07-21 20:20:37 +00:00
|
|
|
* http://ugfx.org/license.html
|
2013-06-02 04:14:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file src/gwin/checkbox.c
|
2013-06-06 04:33:32 +00:00
|
|
|
* @brief GWIN sub-system button code.
|
2013-06-02 04:14:49 +00:00
|
|
|
*
|
|
|
|
* @defgroup Checkbox Checkbox
|
|
|
|
* @ingroup GWIN
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gfx.h"
|
|
|
|
|
|
|
|
#if (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) || defined(__DOXYGEN__)
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
#include "gwin/class_gwin.h"
|
|
|
|
|
|
|
|
// Our checked state
|
|
|
|
#define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0)
|
|
|
|
|
|
|
|
// Send the checkbox event
|
|
|
|
static void SendCheckboxEvent(GWidgetObject *gw) {
|
|
|
|
GSourceListener * psl;
|
|
|
|
GEvent * pe;
|
|
|
|
#define pce ((GEventGWinCheckbox *)pe)
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
// Trigger a GWIN Checkbox Event
|
2013-06-02 16:43:19 +00:00
|
|
|
psl = 0;
|
2013-06-10 07:18:01 +00:00
|
|
|
while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
|
2013-06-02 16:43:19 +00:00
|
|
|
if (!(pe = geventGetEventBuffer(psl)))
|
|
|
|
continue;
|
2013-06-06 04:33:32 +00:00
|
|
|
pce->type = GEVENT_GWIN_CHECKBOX;
|
|
|
|
pce->checkbox = &gw->g;
|
|
|
|
pce->isChecked = (gw->g.flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE;
|
2013-06-02 16:43:19 +00:00
|
|
|
geventSendEvent(psl);
|
2013-06-06 04:33:32 +00:00
|
|
|
}
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
#undef pce
|
|
|
|
}
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
#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);
|
|
|
|
}
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
|
|
|
|
(void) role;
|
|
|
|
((GCheckboxObject *)gw)->toggle = instance;
|
|
|
|
}
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
|
|
|
|
(void) role;
|
|
|
|
return ((GCheckboxObject *)gw)->toggle;
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-10 07:18:01 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
// 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
|
|
|
|
};
|
2013-06-10 07:18:01 +00:00
|
|
|
|
2013-10-24 08:36:11 +00:00
|
|
|
GHandle gwinGCheckboxCreate(GDisplay *g, GCheckboxObject *gb, const GWidgetInit *pInit) {
|
|
|
|
if (!(gb = (GCheckboxObject *)_gwidgetCreate(g, &gb->w, pInit, &checkboxVMT)))
|
2013-06-06 04:33:32 +00:00
|
|
|
return 0;
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_TOGGLE
|
|
|
|
gb->toggle = GWIDGET_NO_INSTANCE;
|
|
|
|
#endif
|
2013-06-24 12:58:37 +00:00
|
|
|
gwinSetVisible((GHandle)gb, pInit->g.show);
|
2013-06-02 04:14:49 +00:00
|
|
|
return (GHandle)gb;
|
|
|
|
}
|
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
void gwinCheckboxCheck(GHandle gh, bool_t isChecked) {
|
|
|
|
if (gh->vmt != (gwinVMT *)&checkboxVMT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isChecked) {
|
|
|
|
if ((gh->flags & GCHECKBOX_FLG_CHECKED)) return;
|
|
|
|
gh->flags |= GCHECKBOX_FLG_CHECKED;
|
|
|
|
} else {
|
|
|
|
if (!(gh->flags & GCHECKBOX_FLG_CHECKED)) return;
|
|
|
|
gh->flags &= ~GCHECKBOX_FLG_CHECKED;
|
|
|
|
}
|
|
|
|
_gwidgetRedraw(gh);
|
|
|
|
SendCheckboxEvent((GWidgetObject *)gh);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool_t gwinCheckboxIsChecked(GHandle gh) {
|
2013-06-06 04:33:32 +00:00
|
|
|
if (gh->vmt != (gwinVMT *)&checkboxVMT)
|
|
|
|
return FALSE;
|
2013-06-03 15:36:39 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
return (gh->flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE;
|
2013-06-03 15:36:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
/*----------------------------------------------------------
|
|
|
|
* Custom Draw Routines
|
|
|
|
*----------------------------------------------------------*/
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
static const GColorSet *getDrawColors(GWidgetObject *gw) {
|
|
|
|
if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &gw->pstyle->disabled;
|
|
|
|
if ((gw->g.flags & GCHECKBOX_FLG_CHECKED)) return &gw->pstyle->pressed;
|
|
|
|
return &gw->pstyle->enabled;
|
2013-06-02 04:14:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
#define gcw ((GCheckboxObject *)gw)
|
2014-01-05 04:05:59 +00:00
|
|
|
coord_t ld, df;
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
|
|
|
(void) param;
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2014-01-05 04:05:59 +00:00
|
|
|
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
|
2013-07-07 09:40:37 +00:00
|
|
|
pcol = getDrawColors(gw);
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
|
2014-01-05 04:05:59 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+1, ld, ld-2, gw->pstyle->background);
|
|
|
|
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, ld, ld, pcol->edge);
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
df = ld < 4 ? 1 : 2;
|
|
|
|
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
|
2014-01-05 04:05:59 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill);
|
2013-06-02 04:14:49 +00:00
|
|
|
|
2014-01-05 04:05:59 +00:00
|
|
|
gdispGFillStringBox(gw->g.display, gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyLeft);
|
2013-06-02 04:14:49 +00:00
|
|
|
#undef gcw
|
|
|
|
}
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
#define gcw ((GCheckboxObject *)gw)
|
2014-01-05 04:05:59 +00:00
|
|
|
coord_t ep, ld, df;
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
|
|
|
(void) param;
|
2013-06-02 14:15:46 +00:00
|
|
|
|
2014-01-05 04:05:59 +00:00
|
|
|
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
|
2013-07-07 09:40:37 +00:00
|
|
|
pcol = getDrawColors(gw);
|
2013-06-02 14:15:46 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
|
|
|
|
ep = gw->g.width-ld-1;
|
2014-01-05 04:05:59 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x+ep-1, gw->g.y+1, ld, ld-2, gw->pstyle->background);
|
|
|
|
gdispGDrawBox(gw->g.display, gw->g.x+ep, gw->g.y, ld, ld, pcol->edge);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
|
|
|
df = ld < 4 ? 1 : 2;
|
|
|
|
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
|
2014-01-05 04:05:59 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x+ep+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill);
|
2013-06-02 14:15:46 +00:00
|
|
|
|
2014-01-05 04:05:59 +00:00
|
|
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, ep-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyRight);
|
2013-06-02 14:15:46 +00:00
|
|
|
#undef gcw
|
|
|
|
}
|
|
|
|
|
2013-06-02 04:14:49 +00:00
|
|
|
#endif /* (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) */
|
|
|
|
/** @} */
|
|
|
|
|