added default theme

ugfx_release_2.6
Joel Bodenmann 2013-06-02 16:15:46 +02:00
parent 8a5596b39d
commit dadcf535d4
2 changed files with 48 additions and 75 deletions

View File

@ -46,12 +46,14 @@ typedef enum GCheckboxShape_e {
} GCheckboxShape; } GCheckboxShape;
typedef enum GCheckboxState_e { typedef enum GCheckboxState_e {
GCHBX_SET, GCHBX_UNSET GCHBX_UNCHECKED, GCHBX_CHECKED
} GCheckboxState; } GCheckboxState;
typedef struct GCheckboxDrawStyle_t { typedef struct GCheckboxColor_t {
color_t color; color_t border;
} GCheckboxDrawStyle; color_t checked;
color_t bg;
} GCheckboxColor;
/* custom rendering interface */ /* custom rendering interface */
typedef void (*GCheckboxDrawFunction)(GHandle gh, bool_t enabled, bool_t state, void* param); typedef void (*GCheckboxDrawFunction)(GHandle gh, bool_t enabled, bool_t state, void* param);
@ -62,8 +64,7 @@ typedef struct GCheckboxObject_t {
GListener listener; GListener listener;
GCheckboxDrawFunction fn; GCheckboxDrawFunction fn;
GCheckboxDrawStyle set; GCheckboxColor *colors;
GCheckboxDrawStyle unset;
bool_t state; bool_t state;
void *param; void *param;
} GCheckboxObject; } GCheckboxObject;
@ -122,7 +123,7 @@ void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled);
* *
* @param[in] gh The window handle (must be a checkbox window) * @param[in] gh The window handle (must be a checkbox window)
* *
* @return The state of the checkbox (GCHBX_SET or GCHBX_UNSET) * @return The state of the checkbox (GCHBX_CHECKED or GCHBX_UNCHECKED)
* *
* @api * @api
*/ */
@ -148,27 +149,7 @@ void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled);
* @api * @api
*/ */
bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance); bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance);
#endif #endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
/**
* @brief Standard checkbox drawing routines
* @details These routines are called to draw the standard checkbox styles.
*
* @param[in] gh The checkbox handle
* @param[in] enabled Is the checkbox currently enabled or disabled
* @param[in] state Is the checkbox currently set or unset
* @param[in] param A parameter passed from the user
*
* @note In your custom checkbox drawing function, you may optionally call these
* standard functions and then draw your extra details on top.
* @note The standard functions below ignore the param parameter. It is there only
* to ensure the functions match the GCheckboxDrawFunction type.
*
* @api
* @{
*/
void gwinCheckboxDraw_Normal(GHandle gh, bool_t enabled, bool_t state, void *param);
/** @} */
#endif /* _GWIN_NEED_CHECKBOX */ #endif /* _GWIN_NEED_CHECKBOX */

View File

@ -19,13 +19,28 @@
#if (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) || defined(__DOXYGEN__) #if (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) || defined(__DOXYGEN__)
static const GCheckboxDrawStyle GCheckboxDefaultStyleSelected = { static const GCheckboxColor defaultColors = {
Green Grey, // border
Grey, // selected
Black // background
}; };
static const GCheckboxDrawStyle GCheckboxDefaultStyleUnselected = { /* default style drawing routine */
Red static void gwinCheckboxDrawDefaultStyle(GHandle gh, bool_t enabled, bool_t state, void* param) {
}; #define gcw ((GCheckboxObject *)gh)
(void) enabled;
(void) param;
gdispDrawBox(gh->x, gh->y, gh->width, gh->height, gcw->colors->border);
if (state)
gdispFillArea(gh->x+2, gh->y+2, gh->width-4, gh->height-4, gcw->colors->checked);
else
gdispFillArea(gh->x+2, gh->y+2, gh->width-4, gh->height-4, gcw->colors->bg);
#undef gcw
}
/* process an event callback */ /* process an event callback */
static void gwinCheckboxCallback(void *param, GEvent *pe) { static void gwinCheckboxCallback(void *param, GEvent *pe) {
@ -78,12 +93,13 @@ GHandle gwinCheckboxCreate(GCheckboxObject *gb, coord_t x, coord_t y, coord_t wi
if (!(gb = (GCheckboxObject *)_gwinInit((GWindowObject *)gb, x, y, width, height, sizeof(GCheckboxObject)))) if (!(gb = (GCheckboxObject *)_gwinInit((GWindowObject *)gb, x, y, width, height, sizeof(GCheckboxObject))))
return 0; return 0;
gb->gwin.type = GW_CHECKBOX; gb->gwin.type = GW_CHECKBOX; // create a window of the type checkbox
gb->fn = 0; gb->fn = gwinCheckboxDrawDefaultStyle; // set the default style drawing routine
gb->param = 0; gb->colors = &defaultColors; // asign the default colors
gb->state = GCHBX_UNSET; gb->param = 0; // some safe value here
gb->state = GCHBX_UNCHECKED; // checkbox is currently unchecked
gb->gwin.enabled = TRUE; // checkboxes are enabled by default
gwinCheckboxSetStyle(&gb->gwin, GCHBX_NORMAL, &GCheckboxDefaultStyleSelected, &GCheckboxDefaultStyleUnselected);
geventListenerInit(&gb->listener); geventListenerInit(&gb->listener);
geventRegisterCallback(&gb->listener, gwinCheckboxCallback, gb); geventRegisterCallback(&gb->listener, gwinCheckboxCallback, gb);
@ -93,33 +109,6 @@ GHandle gwinCheckboxCreate(GCheckboxObject *gb, coord_t x, coord_t y, coord_t wi
return (GHandle)gb; return (GHandle)gb;
} }
void gwinCheckboxSetStyle(GHandle gh, GCheckboxShape shape, const GCheckboxDrawStyle *pSelected, const GCheckboxDrawStyle *pUnselected) {
#define gcw ((GCheckboxObject *)gh)
if (gh->type != GW_CHECKBOX)
return;
switch (shape) {
case GCHBX_NORMAL:
gcw->fn = gwinCheckboxDraw_Normal;
break;
default:
gcw->fn = gwinCheckboxDraw_Normal;
break;
}
if (pSelected) {
gcw->set.color = pSelected->color;
}
if (pUnselected) {
gcw->unset.color = pSelected->color;
}
#undef gcw
}
void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled) { void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled) {
if (gh->type != GW_CHECKBOX) if (gh->type != GW_CHECKBOX)
return; return;
@ -145,16 +134,6 @@ void gwinCheckboxDraw(GHandle gh) {
#undef gcw #undef gcw
} }
void gwinCheckboxDraw_Normal(GHandle gh, bool_t enabled, bool_t state, void* param) {
(void) enabled;
(void) param;
if (state)
gdispClear(Green);
else
gdispClear(Red);
}
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance) { bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance) {
GSourceHandle gsh; GSourceHandle gsh;
@ -166,6 +145,19 @@ void gwinCheckboxDraw_Normal(GHandle gh, bool_t enabled, bool_t state, void* par
} }
#endif #endif
void gwinCheckboxSetColors(GHandle gh, color_t border, color_t checked, color_t bg) {
#define gcw ((GCheckboxObject *)gh)
if (gh->type != GW_CHECKBOX)
return;
gcw->colors->border = border;
gcw->colors->checked = checked,
gcw->colors->bg = bg;
#undef gcw
}
#endif /* (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) */ #endif /* (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) */
/** @} */ /** @} */