aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2013-06-02 16:15:46 +0200
committerJoel Bodenmann <joel@unormal.org>2013-06-02 16:15:46 +0200
commitdadcf535d45b8c778c013494e8142215d32e4204 (patch)
treec245caa97250f99ab7922d8d4e95be90f635b424
parent8a5596b39d44d7fe1fbb359cd436fe23cde97339 (diff)
downloaduGFX-dadcf535d45b8c778c013494e8142215d32e4204.tar.gz
uGFX-dadcf535d45b8c778c013494e8142215d32e4204.tar.bz2
uGFX-dadcf535d45b8c778c013494e8142215d32e4204.zip
added default theme
-rw-r--r--include/gwin/checkbox.h37
-rw-r--r--src/gwin/checkbox.c86
2 files changed, 48 insertions, 75 deletions
diff --git a/include/gwin/checkbox.h b/include/gwin/checkbox.h
index 84ecd65a..cfa9f646 100644
--- a/include/gwin/checkbox.h
+++ b/include/gwin/checkbox.h
@@ -46,12 +46,14 @@ typedef enum GCheckboxShape_e {
} GCheckboxShape;
typedef enum GCheckboxState_e {
- GCHBX_SET, GCHBX_UNSET
+ GCHBX_UNCHECKED, GCHBX_CHECKED
} GCheckboxState;
-typedef struct GCheckboxDrawStyle_t {
- color_t color;
-} GCheckboxDrawStyle;
+typedef struct GCheckboxColor_t {
+ color_t border;
+ color_t checked;
+ color_t bg;
+} GCheckboxColor;
/* custom rendering interface */
typedef void (*GCheckboxDrawFunction)(GHandle gh, bool_t enabled, bool_t state, void* param);
@@ -62,8 +64,7 @@ typedef struct GCheckboxObject_t {
GListener listener;
GCheckboxDrawFunction fn;
- GCheckboxDrawStyle set;
- GCheckboxDrawStyle unset;
+ GCheckboxColor *colors;
bool_t state;
void *param;
} GCheckboxObject;
@@ -122,7 +123,7 @@ void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled);
*
* @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
*/
@@ -148,27 +149,7 @@ void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled);
* @api
*/
bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance);
-#endif
-
-/**
- * @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 /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
#endif /* _GWIN_NEED_CHECKBOX */
diff --git a/src/gwin/checkbox.c b/src/gwin/checkbox.c
index 4e990896..1b70614b 100644
--- a/src/gwin/checkbox.c
+++ b/src/gwin/checkbox.c
@@ -19,13 +19,28 @@
#if (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) || defined(__DOXYGEN__)
-static const GCheckboxDrawStyle GCheckboxDefaultStyleSelected = {
- Green
+static const GCheckboxColor defaultColors = {
+ Grey, // border
+ Grey, // selected
+ Black // background
};
-static const GCheckboxDrawStyle GCheckboxDefaultStyleUnselected = {
- Red
-};
+/* default style drawing routine */
+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 */
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))))
return 0;
- gb->gwin.type = GW_CHECKBOX;
- gb->fn = 0;
- gb->param = 0;
- gb->state = GCHBX_UNSET;
+ gb->gwin.type = GW_CHECKBOX; // create a window of the type checkbox
+ gb->fn = gwinCheckboxDrawDefaultStyle; // set the default style drawing routine
+ gb->colors = &defaultColors; // asign the default colors
+ 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);
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;
}
-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) {
if (gh->type != GW_CHECKBOX)
return;
@@ -145,16 +134,6 @@ void gwinCheckboxDraw(GHandle gh) {
#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
bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance) {
GSourceHandle gsh;
@@ -166,6 +145,19 @@ void gwinCheckboxDraw_Normal(GHandle gh, bool_t enabled, bool_t state, void* par
}
#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) */
/** @} */