Implement a "Toggle Button" using a checkbox with a custom draw.

Updated the widgets demo to show this.
ugfx_release_2.6
inmarket 2015-01-23 17:57:13 +10:00
parent fa8167b94d
commit b316263833
4 changed files with 52 additions and 3 deletions

View File

@ -87,7 +87,7 @@ static GHandle ghConsole;
static GHandle ghPgButtons, ghPgSliders, ghPgCheckboxes, ghPgLabels, ghPgRadios, ghPgLists, ghPgImages, ghPgProgressbars;
static GHandle ghButton1, ghButton2, ghButton3, ghButton4;
static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4;
static GHandle ghCheckbox1, ghCheckbox2, ghCheckDisableAll;
static GHandle ghCheckbox1, ghCheckbox2, ghCheckbox3, ghCheckDisableAll;
static GHandle ghLabelSlider1, ghLabelSlider2, ghLabelSlider3, ghLabelSlider4, ghLabelRadio1;
static GHandle ghRadio1, ghRadio2;
static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow;
@ -303,7 +303,7 @@ static void createWidgets(void) {
ghSlider4 = gwinSliderCreate(0, &wi);
gwinSliderSetPosition(ghSlider4, 76);
// Checkboxes - for the 2nd checkbox we apply special drawing before making it visible
// Checkboxes - for the 2nd and 3rd checkbox we apply special drawing before making it visible
wi.g.parent = ghPgCheckboxes;
wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 5;
wi.g.y = 5; wi.text = "C1";
@ -311,8 +311,11 @@ static void createWidgets(void) {
wi.customDraw = gwinCheckboxDraw_CheckOnRight;
wi.g.y += wi.g.height+1; wi.text = "C2";
ghCheckbox2 = gwinCheckboxCreate(0, &wi);
wi.customDraw = 0; wi.g.width = DISABLEALL_WIDTH;
wi.customDraw = gwinCheckboxDraw_Button;
wi.g.y += wi.g.height+1; wi.text = "C3"; wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT;
ghCheckbox3 = gwinCheckboxCreate(0, &wi);
wi.g.y += wi.g.height+1; wi.text = "Disable All";
wi.customDraw = 0; wi.g.width = DISABLEALL_WIDTH; wi.g.height = CHECKBOX_HEIGHT;
ghCheckDisableAll = gwinCheckboxCreate(0, &wi);
// Labels
@ -478,6 +481,7 @@ static void setEnabled(bool_t ena) {
// Checkboxes we need to do individually so we don't disable the checkbox to re-enable everything
gwinSetEnabled(ghCheckbox1, ena);
gwinSetEnabled(ghCheckbox2, ena);
gwinSetEnabled(ghCheckbox3, ena);
//gwinSetEnabled(ghCheckDisableAll, TRUE);
}

View File

@ -13,6 +13,9 @@ FEATURE: New Tabset GWIN widget
FEATURE: New keyboard driver interface with drivers for Win32 and X
FEATURE: Support for keyboard layouts for non-english keyboards
FEATURE: GDISP now supports pixmaps (in memory drawing)
FEATURE: Rename files to improve experience in certain brain-dead IDE's
FEATURE: Add a checkbox "Toggle Button" custom draw
FEATURE: Add Tetris as an application demo.
*** Release 2.2 ***

View File

@ -16,6 +16,10 @@
#include "gwin_class.h"
// Parameters for button custom draw
#define TOP_FADE 50 // (TOP_FADE/255)% fade to white for top of button
#define BOTTOM_FADE 25 // (BOTTOM_FADE/255)% fade to black for bottom of button
// Our checked state
#define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0)
@ -204,4 +208,41 @@ void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param) {
#undef gcw
}
#if GWIN_FLAT_STYLING
void gwinCheckboxDraw_Button(GWidgetObject *gw, void *param) {
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
pcol = getDrawColors(gw);
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter);
gdispGDrawLine(gw->g.display, gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->edge);
gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->edge);
}
#else
void gwinCheckboxDraw_Button(GWidgetObject *gw, void *param) {
const GColorSet * pcol;
fixed alpha;
fixed dalpha;
coord_t i;
color_t tcol, bcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
pcol = getDrawColors(gw);
/* Fill the box blended from variants of the fill color */
tcol = gdispBlendColor(White, pcol->fill, TOP_FADE);
bcol = gdispBlendColor(Black, pcol->fill, BOTTOM_FADE);
dalpha = FIXED(255)/gw->g.height;
for(alpha = 0, i = 0; i < gw->g.height; i++, alpha += dalpha)
gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y+i, gw->g.x+gw->g.width-2, gw->g.y+i, gdispBlendColor(bcol, tcol, NONFIXED(alpha)));
gdispGDrawStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, justifyCenter);
gdispGDrawLine(gw->g.display, gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->edge);
gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->edge);
}
#endif
#endif /* (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) */

View File

@ -116,6 +116,7 @@ bool_t gwinCheckboxIsChecked(GHandle gh);
*/
void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param);
void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param);
void gwinCheckboxDraw_Button(GWidgetObject *gw, void *param);
/** @} */
#ifdef __cplusplus