From 7baf5c5d448b626d6a062882434b25ca82212d94 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 6 Jun 2013 14:33:32 +1000 Subject: New simplified gwin using a pseudo class structure. --- demos/modules/gwin/widgets/main.c | 141 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 demos/modules/gwin/widgets/main.c (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c new file mode 100644 index 00000000..7845ba69 --- /dev/null +++ b/demos/modules/gwin/widgets/main.c @@ -0,0 +1,141 @@ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "gfx.h" + +static GListener gl; +static GHandle ghConsole; +static GHandle ghButton1, ghButton2, ghButton3, ghButton4; +static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4; +static GHandle ghCheckbox1, ghCheckbox2; + +#define ScrWidth gdispGetWidth() +#define ScrHeight gdispGetHeight() + +#define BUTTON_WIDTH 50 +#define BUTTON_HEIGHT 30 +#define SLIDER_WIDTH 10 +#define CHECKBOX_WIDTH 80 +#define CHECKBOX_HEIGHT 20 + +int main(void) { + GEvent * pe; + + // Initialize the display + gfxInit(); + gdispClear(White); + + // Set the font + gwinSetDefaultFont(gdispOpenFont("UI2")); + + // Create out gwin windows/widgets + ghButton1 = gwinCreateButton(NULL, 0+0*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); + ghButton2 = gwinCreateButton(NULL, 0+1*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); + ghButton3 = gwinCreateButton(NULL, 0+2*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); + ghButton4 = gwinCreateButton(NULL, 0+3*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); + ghConsole = gwinCreateConsole(NULL, ScrWidth/2+1, ScrHeight/2+1, ScrWidth/2-1, ScrHeight/2-1); + ghSlider1 = gwinCreateSlider(NULL, ScrWidth/2+1, ScrHeight/2-2*(SLIDER_WIDTH+1), ScrWidth/2-2, SLIDER_WIDTH); + ghSlider2 = gwinCreateSlider(NULL, ScrWidth/2+1, ScrHeight/2-1*(SLIDER_WIDTH+1), ScrWidth/2-2, SLIDER_WIDTH); + ghSlider3 = gwinCreateSlider(NULL, 0+1*(SLIDER_WIDTH+1), ScrHeight/2+1, SLIDER_WIDTH, ScrHeight/2-2); + ghSlider4 = gwinCreateSlider(NULL, 0+1*(SLIDER_WIDTH+1), ScrHeight/2+1, SLIDER_WIDTH, ScrHeight/2-2); + ghCheckbox1 = gwinCreateCheckbox(NULL, 0, BUTTON_HEIGHT+1, CHECKBOX_WIDTH, CHECKBOX_HEIGHT); + ghCheckbox2 = gwinCreateCheckbox(NULL, 0, BUTTON_HEIGHT+1+1*(CHECKBOX_HEIGHT+1), CHECKBOX_WIDTH, CHECKBOX_HEIGHT); + + // Color everything + gwinSetColor(ghConsole, Yellow); + gwinSetBgColor(ghConsole, Black); + + // Set the text on all the controls + gwinSetText(ghButton1, "B1", FALSE); + gwinSetText(ghButton2, "B2", FALSE); + gwinSetText(ghButton3, "B3", FALSE); + gwinSetText(ghButton4, "B4", FALSE); + gwinSetText(ghSlider1, "S1", FALSE); + gwinSetText(ghSlider2, "S2", FALSE); + gwinSetText(ghSlider3, "S3", FALSE); + gwinSetText(ghSlider4, "S4", FALSE); + gwinSetText(ghCheckbox1, "C1", FALSE); + gwinSetText(ghCheckbox2, "C2", FALSE); + + // Assign the mouse and dials to the buttons & sliders etc. +#if GINPUT_NEED_MOUSE + gwinAttachMouse(ghSlider1, 0); + gwinAttachMouse(ghSlider2, 0); + gwinAttachMouse(ghSlider3, 0); + gwinAttachMouse(ghSlider4, 0); + gwinAttachMouse(ghButton1, 0); + gwinAttachMouse(ghButton2, 0); + gwinAttachMouse(ghButton3, 0); + gwinAttachMouse(ghButton4, 0); + gwinAttachMouse(ghCheckbox1, 0); + gwinAttachMouse(ghCheckbox2, 0); +#endif +#if GINPUT_NEED_DIAL + gwinAttachSliderDial(ghSlider1, 0); + gwinAttachSliderDial(ghSlider3, 1); +#endif + + // We want to listen for widget events + geventListenerInit(&gl); + gwinAttachListener(ghSlider1, &gl, 0); + gwinAttachListener(ghSlider2, &gl, 0); + gwinAttachListener(ghSlider3, &gl, 0); + gwinAttachListener(ghSlider4, &gl, 0); + gwinAttachListener(ghButton1, &gl, 0); + gwinAttachListener(ghButton2, &gl, 0); + gwinAttachListener(ghButton3, &gl, 0); + gwinAttachListener(ghButton4, &gl, 0); + gwinAttachListener(ghCheckbox1, &gl, 0); + gwinAttachListener(ghCheckbox2, &gl, 0); + + // Draw everything on the screen + gwinClear(ghConsole); + gwinDraw(ghSlider1); + gwinDraw(ghSlider2); + gwinDraw(ghSlider3); + gwinDraw(ghSlider4); + gwinDraw(ghButton1); + gwinDraw(ghButton2); + gwinDraw(ghButton3); + gwinDraw(ghButton4); + gwinDraw(ghCheckbox1); + gwinDraw(ghCheckbox2); + + while(1) { + // Get an Event + pe = geventEventWait(&gl, TIME_INFINITE); + + switch(pe->type) { + case GEVENT_GWIN_BUTTON: + gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->button)); + break; + case GEVENT_GWIN_SLIDER: + gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position); + break; + case GEVENT_GWIN_CHECKBOX: + gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked"); + break; + default: + gwinPrintf(ghConsole, "Unknown %d\n", pe->type); + break; + } + } + return 0; +} -- cgit v1.2.3 From 663caba66214acdb6170903f6a203740ea1de8b9 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 6 Jun 2013 16:48:30 +1000 Subject: GWIN fixes --- demos/modules/gwin/widgets/main.c | 112 +++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 51 deletions(-) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index 7845ba69..2102d3a2 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -1,22 +1,29 @@ /* - ChibiOS/GFX - Copyright (C) 2012, 2013 - Joel Bodenmann aka Tectu - - This file is part of ChibiOS/GFX. - - ChibiOS/GFX is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/GFX is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ + * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #include "gfx.h" @@ -31,7 +38,7 @@ static GHandle ghCheckbox1, ghCheckbox2; #define BUTTON_WIDTH 50 #define BUTTON_HEIGHT 30 -#define SLIDER_WIDTH 10 +#define SLIDER_WIDTH 20 #define CHECKBOX_WIDTH 80 #define CHECKBOX_HEIGHT 20 @@ -42,48 +49,51 @@ int main(void) { gfxInit(); gdispClear(White); - // Set the font + // Set the font and defalt colors gwinSetDefaultFont(gdispOpenFont("UI2")); + gwinSetDefaultColor(Black); + gwinSetDefaultBgColor(White); // Create out gwin windows/widgets + ghConsole = gwinCreateConsole(NULL, ScrWidth/2+1, ScrHeight/2+1, ScrWidth/2-1, ScrHeight/2-1); ghButton1 = gwinCreateButton(NULL, 0+0*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); ghButton2 = gwinCreateButton(NULL, 0+1*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); ghButton3 = gwinCreateButton(NULL, 0+2*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); ghButton4 = gwinCreateButton(NULL, 0+3*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); - ghConsole = gwinCreateConsole(NULL, ScrWidth/2+1, ScrHeight/2+1, ScrWidth/2-1, ScrHeight/2-1); ghSlider1 = gwinCreateSlider(NULL, ScrWidth/2+1, ScrHeight/2-2*(SLIDER_WIDTH+1), ScrWidth/2-2, SLIDER_WIDTH); ghSlider2 = gwinCreateSlider(NULL, ScrWidth/2+1, ScrHeight/2-1*(SLIDER_WIDTH+1), ScrWidth/2-2, SLIDER_WIDTH); - ghSlider3 = gwinCreateSlider(NULL, 0+1*(SLIDER_WIDTH+1), ScrHeight/2+1, SLIDER_WIDTH, ScrHeight/2-2); + ghSlider3 = gwinCreateSlider(NULL, 0+0*(SLIDER_WIDTH+1), ScrHeight/2+1, SLIDER_WIDTH, ScrHeight/2-2); ghSlider4 = gwinCreateSlider(NULL, 0+1*(SLIDER_WIDTH+1), ScrHeight/2+1, SLIDER_WIDTH, ScrHeight/2-2); ghCheckbox1 = gwinCreateCheckbox(NULL, 0, BUTTON_HEIGHT+1, CHECKBOX_WIDTH, CHECKBOX_HEIGHT); ghCheckbox2 = gwinCreateCheckbox(NULL, 0, BUTTON_HEIGHT+1+1*(CHECKBOX_HEIGHT+1), CHECKBOX_WIDTH, CHECKBOX_HEIGHT); - // Color everything + // Color everything and set special drawing for some widgets gwinSetColor(ghConsole, Yellow); gwinSetBgColor(ghConsole, Black); + gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0); // Set the text on all the controls gwinSetText(ghButton1, "B1", FALSE); - gwinSetText(ghButton2, "B2", FALSE); - gwinSetText(ghButton3, "B3", FALSE); - gwinSetText(ghButton4, "B4", FALSE); - gwinSetText(ghSlider1, "S1", FALSE); - gwinSetText(ghSlider2, "S2", FALSE); - gwinSetText(ghSlider3, "S3", FALSE); - gwinSetText(ghSlider4, "S4", FALSE); - gwinSetText(ghCheckbox1, "C1", FALSE); - gwinSetText(ghCheckbox2, "C2", FALSE); + gwinSetText(ghButton2, "B2", FALSE); + gwinSetText(ghButton3, "B3", FALSE); + gwinSetText(ghButton4, "B4", FALSE); + gwinSetText(ghSlider1, "S1", FALSE); + gwinSetText(ghSlider2, "S2", FALSE); + gwinSetText(ghSlider3, "S3", FALSE); + gwinSetText(ghSlider4, "S4", FALSE); + gwinSetText(ghCheckbox1, "C1", FALSE); + gwinSetText(ghCheckbox2, "C2", FALSE); // Assign the mouse and dials to the buttons & sliders etc. #if GINPUT_NEED_MOUSE - gwinAttachMouse(ghSlider1, 0); - gwinAttachMouse(ghSlider2, 0); - gwinAttachMouse(ghSlider3, 0); - gwinAttachMouse(ghSlider4, 0); gwinAttachMouse(ghButton1, 0); gwinAttachMouse(ghButton2, 0); gwinAttachMouse(ghButton3, 0); gwinAttachMouse(ghButton4, 0); + gwinAttachMouse(ghSlider1, 0); + gwinAttachMouse(ghSlider2, 0); + gwinAttachMouse(ghSlider3, 0); + gwinAttachMouse(ghSlider4, 0); gwinAttachMouse(ghCheckbox1, 0); gwinAttachMouse(ghCheckbox2, 0); #endif @@ -94,29 +104,29 @@ int main(void) { // We want to listen for widget events geventListenerInit(&gl); - gwinAttachListener(ghSlider1, &gl, 0); - gwinAttachListener(ghSlider2, &gl, 0); - gwinAttachListener(ghSlider3, &gl, 0); - gwinAttachListener(ghSlider4, &gl, 0); gwinAttachListener(ghButton1, &gl, 0); gwinAttachListener(ghButton2, &gl, 0); gwinAttachListener(ghButton3, &gl, 0); gwinAttachListener(ghButton4, &gl, 0); + gwinAttachListener(ghSlider1, &gl, 0); + gwinAttachListener(ghSlider2, &gl, 0); + gwinAttachListener(ghSlider3, &gl, 0); + gwinAttachListener(ghSlider4, &gl, 0); gwinAttachListener(ghCheckbox1, &gl, 0); gwinAttachListener(ghCheckbox2, &gl, 0); // Draw everything on the screen - gwinClear(ghConsole); - gwinDraw(ghSlider1); - gwinDraw(ghSlider2); - gwinDraw(ghSlider3); - gwinDraw(ghSlider4); - gwinDraw(ghButton1); - gwinDraw(ghButton2); - gwinDraw(ghButton3); - gwinDraw(ghButton4); - gwinDraw(ghCheckbox1); - gwinDraw(ghCheckbox2); + gwinClear(ghConsole); + gwinDraw(ghButton1); + gwinDraw(ghButton2); + gwinDraw(ghButton3); + gwinDraw(ghButton4); + gwinDraw(ghSlider1); + gwinDraw(ghSlider2); + gwinDraw(ghSlider3); + gwinDraw(ghSlider4); + gwinDraw(ghCheckbox1); + gwinDraw(ghCheckbox2); while(1) { // Get an Event -- cgit v1.2.3 From 2cb35d6815a0a12035f4792c266b688c77085620 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 10 Jun 2013 17:18:01 +1000 Subject: Clean up GWIN Event assignment. Optimise event efficiency. --- demos/modules/gwin/widgets/main.c | 70 ++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 41 deletions(-) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index 2102d3a2..1c34b9fa 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -49,11 +49,20 @@ int main(void) { gfxInit(); gdispClear(White); - // Set the font and defalt colors + // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultColor(Black); gwinSetDefaultBgColor(White); + // We want to listen for widget events + geventListenerInit(&gl); + gwinAttachListener(&gl); + + // Connect the mouse + #if GINPUT_NEED_MOUSE + gwinAttachMouse(0); + #endif + // Create out gwin windows/widgets ghConsole = gwinCreateConsole(NULL, ScrWidth/2+1, ScrHeight/2+1, ScrWidth/2-1, ScrHeight/2-1); ghButton1 = gwinCreateButton(NULL, 0+0*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); @@ -84,49 +93,28 @@ int main(void) { gwinSetText(ghCheckbox1, "C1", FALSE); gwinSetText(ghCheckbox2, "C2", FALSE); - // Assign the mouse and dials to the buttons & sliders etc. -#if GINPUT_NEED_MOUSE - gwinAttachMouse(ghButton1, 0); - gwinAttachMouse(ghButton2, 0); - gwinAttachMouse(ghButton3, 0); - gwinAttachMouse(ghButton4, 0); - gwinAttachMouse(ghSlider1, 0); - gwinAttachMouse(ghSlider2, 0); - gwinAttachMouse(ghSlider3, 0); - gwinAttachMouse(ghSlider4, 0); - gwinAttachMouse(ghCheckbox1, 0); - gwinAttachMouse(ghCheckbox2, 0); -#endif -#if GINPUT_NEED_DIAL - gwinAttachSliderDial(ghSlider1, 0); - gwinAttachSliderDial(ghSlider3, 1); -#endif - - // We want to listen for widget events - geventListenerInit(&gl); - gwinAttachListener(ghButton1, &gl, 0); - gwinAttachListener(ghButton2, &gl, 0); - gwinAttachListener(ghButton3, &gl, 0); - gwinAttachListener(ghButton4, &gl, 0); - gwinAttachListener(ghSlider1, &gl, 0); - gwinAttachListener(ghSlider2, &gl, 0); - gwinAttachListener(ghSlider3, &gl, 0); - gwinAttachListener(ghSlider4, &gl, 0); - gwinAttachListener(ghCheckbox1, &gl, 0); - gwinAttachListener(ghCheckbox2, &gl, 0); + // Assign toggles and dials to the buttons & sliders etc. + #if GINPUT_NEED_TOGGLE + gwinAttachToggle(ghButton1, 0, 0); + gwinAttachToggle(ghButton2, 0, 1); + #endif + #if GINPUT_NEED_DIAL + gwinAttachDial(ghSlider1, 0, 0); + gwinAttachDial(ghSlider3, 0, 1); + #endif // Draw everything on the screen gwinClear(ghConsole); - gwinDraw(ghButton1); - gwinDraw(ghButton2); - gwinDraw(ghButton3); - gwinDraw(ghButton4); - gwinDraw(ghSlider1); - gwinDraw(ghSlider2); - gwinDraw(ghSlider3); - gwinDraw(ghSlider4); - gwinDraw(ghCheckbox1); - gwinDraw(ghCheckbox2); + gwinSetVisible(ghButton1, TRUE); + gwinSetVisible(ghButton2, TRUE); + gwinSetVisible(ghButton3, TRUE); + gwinSetVisible(ghButton4, TRUE); + gwinSetVisible(ghSlider1, TRUE); + gwinSetVisible(ghSlider2, TRUE); + gwinSetVisible(ghSlider3, TRUE); + gwinSetVisible(ghSlider4, TRUE); + gwinSetVisible(ghCheckbox1, TRUE); + gwinSetVisible(ghCheckbox2, TRUE); while(1) { // Get an Event -- cgit v1.2.3 From 49b3e8f55ae135ce6475d1185db68e665430fe5e Mon Sep 17 00:00:00 2001 From: inmarket Date: Sat, 15 Jun 2013 21:09:02 +1000 Subject: License header updates --- demos/modules/gwin/widgets/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index 1c34b9fa..33c288f4 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu + * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket * All rights reserved. * * Redistribution and use in source and binary forms, with or without -- cgit v1.2.3 From 8ed9e763c0f97f2946990a911bb940f8c80ff761 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 24 Jun 2013 22:58:37 +1000 Subject: GWIN reduce Initialisation parameters and fix visibility issues --- demos/modules/gwin/widgets/main.c | 83 +++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 42 deletions(-) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index 33c288f4..70f64572 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -64,35 +64,47 @@ int main(void) { gwinAttachMouse(0); #endif - // Create out gwin windows/widgets - ghConsole = gwinCreateConsole(NULL, ScrWidth/2+1, ScrHeight/2+1, ScrWidth/2-1, ScrHeight/2-1); - ghButton1 = gwinCreateButton(NULL, 0+0*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); - ghButton2 = gwinCreateButton(NULL, 0+1*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); - ghButton3 = gwinCreateButton(NULL, 0+2*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); - ghButton4 = gwinCreateButton(NULL, 0+3*(BUTTON_WIDTH+1), 0, BUTTON_WIDTH, BUTTON_HEIGHT); - ghSlider1 = gwinCreateSlider(NULL, ScrWidth/2+1, ScrHeight/2-2*(SLIDER_WIDTH+1), ScrWidth/2-2, SLIDER_WIDTH); - ghSlider2 = gwinCreateSlider(NULL, ScrWidth/2+1, ScrHeight/2-1*(SLIDER_WIDTH+1), ScrWidth/2-2, SLIDER_WIDTH); - ghSlider3 = gwinCreateSlider(NULL, 0+0*(SLIDER_WIDTH+1), ScrHeight/2+1, SLIDER_WIDTH, ScrHeight/2-2); - ghSlider4 = gwinCreateSlider(NULL, 0+1*(SLIDER_WIDTH+1), ScrHeight/2+1, SLIDER_WIDTH, ScrHeight/2-2); - ghCheckbox1 = gwinCreateCheckbox(NULL, 0, BUTTON_HEIGHT+1, CHECKBOX_WIDTH, CHECKBOX_HEIGHT); - ghCheckbox2 = gwinCreateCheckbox(NULL, 0, BUTTON_HEIGHT+1+1*(CHECKBOX_HEIGHT+1), CHECKBOX_WIDTH, CHECKBOX_HEIGHT); - - // Color everything and set special drawing for some widgets - gwinSetColor(ghConsole, Yellow); - gwinSetBgColor(ghConsole, Black); - gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0); - - // Set the text on all the controls - gwinSetText(ghButton1, "B1", FALSE); - gwinSetText(ghButton2, "B2", FALSE); - gwinSetText(ghButton3, "B3", FALSE); - gwinSetText(ghButton4, "B4", FALSE); - gwinSetText(ghSlider1, "S1", FALSE); - gwinSetText(ghSlider2, "S2", FALSE); - gwinSetText(ghSlider3, "S3", FALSE); - gwinSetText(ghSlider4, "S4", FALSE); - gwinSetText(ghCheckbox1, "C1", FALSE); - gwinSetText(ghCheckbox2, "C2", FALSE); + // Create the gwin windows/widgets + { + GWidgetInit wi; + + wi.g.show = TRUE; + + // Buttons + wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = 0; + wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; ghButton1 = gwinCreateButton(NULL, &wi); + wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; ghButton2 = gwinCreateButton(NULL, &wi); + wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; ghButton3 = gwinCreateButton(NULL, &wi); + wi.g.x = 0+3*(BUTTON_WIDTH+1); wi.text = "B4"; ghButton4 = gwinCreateButton(NULL, &wi); + + // Horizontal Sliders + wi.g.width = ScrWidth/2-2; wi.g.height = SLIDER_WIDTH; wi.g.x = ScrWidth/2+1; + wi.g.y = ScrHeight/2-2*(SLIDER_WIDTH+1); wi.text = "S1"; ghSlider1 = gwinCreateSlider(NULL, &wi); + wi.g.y = ScrHeight/2-1*(SLIDER_WIDTH+1); wi.text = "S2"; ghSlider2 = gwinCreateSlider(NULL, &wi); + + // Vertical Sliders + wi.g.width = SLIDER_WIDTH; wi.g.height = ScrHeight/2-2; wi.g.y = ScrHeight/2+1; + wi.g.x = 0+0*(SLIDER_WIDTH+1); wi.text = "S3"; ghSlider3 = gwinCreateSlider(NULL, &wi); + wi.g.x = 0+1*(SLIDER_WIDTH+1); wi.text = "S4"; ghSlider4 = gwinCreateSlider(NULL, &wi); + + // Checkboxes - for the 2nd checkbox we apply special drawing before making it visible + wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 0; + wi.g.y = BUTTON_HEIGHT+1+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCreateCheckbox(NULL, &wi); + wi.g.show = FALSE; + wi.g.y = BUTTON_HEIGHT+1+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCreateCheckbox(NULL, &wi); + gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0); + gwinSetVisible(ghCheckbox2, TRUE); + + // Console - we apply some special colors before making it visible + wi.g.show = FALSE; + wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1; + wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1; + ghConsole = gwinCreateConsole(NULL, &wi.g); + gwinSetColor(ghConsole, Yellow); + gwinSetBgColor(ghConsole, Black); + gwinSetVisible(ghConsole, TRUE); + gwinClear(ghConsole); + } // Assign toggles and dials to the buttons & sliders etc. #if GINPUT_NEED_TOGGLE @@ -104,19 +116,6 @@ int main(void) { gwinAttachDial(ghSlider3, 0, 1); #endif - // Draw everything on the screen - gwinClear(ghConsole); - gwinSetVisible(ghButton1, TRUE); - gwinSetVisible(ghButton2, TRUE); - gwinSetVisible(ghButton3, TRUE); - gwinSetVisible(ghButton4, TRUE); - gwinSetVisible(ghSlider1, TRUE); - gwinSetVisible(ghSlider2, TRUE); - gwinSetVisible(ghSlider3, TRUE); - gwinSetVisible(ghSlider4, TRUE); - gwinSetVisible(ghCheckbox1, TRUE); - gwinSetVisible(ghCheckbox2, TRUE); - while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); -- cgit v1.2.3 From dce9dc00a8bc9aa400b1354c442044586b82bfbc Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 4 Jul 2013 00:22:15 +1000 Subject: Widget demo update --- demos/modules/gwin/widgets/main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index 70f64572..fdd5ed43 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -33,6 +33,7 @@ static GHandle ghConsole; static GHandle ghButton1, ghButton2, ghButton3, ghButton4; static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4; static GHandle ghCheckbox1, ghCheckbox2; +static GHandle ghLabel1; #define ScrWidth gdispGetWidth() #define ScrHeight gdispGetHeight() @@ -95,6 +96,9 @@ int main(void) { gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0); gwinSetVisible(ghCheckbox2, TRUE); + wi.g.show = TRUE; wi.g.width = 0; + wi.g.y = BUTTON_HEIGHT+1+2*(CHECKBOX_HEIGHT+1); wi.text = "L1"; ghLabel1 = gwinLabelCreate(NULL, &wi); + // Console - we apply some special colors before making it visible wi.g.show = FALSE; wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1; @@ -116,6 +120,16 @@ int main(void) { gwinAttachDial(ghSlider3, 0, 1); #endif + gfxSleepMilliseconds(5000); + gwinSetBgColor(ghLabel1, Blue); + gwinSetColor(ghLabel1, Yellow); + gwinSetText(ghLabel1, "Very Big Label", FALSE); + + gfxSleepMilliseconds(5000); + gwinSetBgColor(ghLabel1, Yellow); + gwinSetColor(ghLabel1, Red); + gwinSetText(ghLabel1, "L1", FALSE); + while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); -- cgit v1.2.3 From 5191c278e7195de62b619be58c19ea338c31d54c Mon Sep 17 00:00:00 2001 From: inmarket Date: Sat, 6 Jul 2013 01:46:34 +1000 Subject: Add Radio buttons (can also be used as a Tab group) --- demos/modules/gwin/widgets/main.c | 102 +++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 19 deletions(-) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index fdd5ed43..e44ce6b0 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -30,19 +30,36 @@ static GListener gl; static GHandle ghConsole; +static GHandle ghTabButtons, ghTabSliders, ghTabCheckboxes, ghTabLabels, ghTabRadios, ghTabImages; static GHandle ghButton1, ghButton2, ghButton3, ghButton4; static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4; static GHandle ghCheckbox1, ghCheckbox2; static GHandle ghLabel1; +static GHandle ghRadio1, ghRadio2; +//static GHandle ghImage1; #define ScrWidth gdispGetWidth() #define ScrHeight gdispGetHeight() +#define TAB_HEIGHT 30 #define BUTTON_WIDTH 50 #define BUTTON_HEIGHT 30 #define SLIDER_WIDTH 20 #define CHECKBOX_WIDTH 80 #define CHECKBOX_HEIGHT 20 +#define RADIO_WIDTH 50 +#define RADIO_HEIGHT 20 +#define GROUP_TABS 0 +#define GROUP_R1R2 1 + +static GHandle createTab(GWidgetInit *pwi) { + GHandle gh; + + gh = gwinCreateRadio(NULL, pwi, GROUP_TABS); + gwinSetCustomDraw(gh, gwinRadioDraw_Tab, 0); + gwinSetVisible(gh, TRUE); + return gh; +} int main(void) { GEvent * pe; @@ -69,10 +86,17 @@ int main(void) { { GWidgetInit wi; - wi.g.show = TRUE; + // Create the Tabs + wi.g.show = FALSE; wi.g.width = ScrWidth/6; wi.g.height = TAB_HEIGHT; wi.g.y = 0; + wi.g.x = 0*wi.g.width; wi.text = "Buttons"; ghTabButtons = createTab(&wi); + wi.g.x = 1*wi.g.width; wi.text = "Sliders"; ghTabSliders = createTab(&wi); + wi.g.x = 2*wi.g.width; wi.text = "Checkbox"; ghTabCheckboxes = createTab(&wi); + wi.g.x = 3*wi.g.width; wi.text = "Labels"; ghTabLabels = createTab(&wi); + wi.g.x = 4*wi.g.width; wi.text = "Radios"; ghTabRadios = createTab(&wi); + wi.g.x = 5*wi.g.width; wi.text = "Images"; ghTabImages = createTab(&wi); // Buttons - wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = 0; + wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = TAB_HEIGHT+5; wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; ghButton1 = gwinCreateButton(NULL, &wi); wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; ghButton2 = gwinCreateButton(NULL, &wi); wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; ghButton3 = gwinCreateButton(NULL, &wi); @@ -90,24 +114,25 @@ int main(void) { // Checkboxes - for the 2nd checkbox we apply special drawing before making it visible wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 0; - wi.g.y = BUTTON_HEIGHT+1+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCreateCheckbox(NULL, &wi); - wi.g.show = FALSE; - wi.g.y = BUTTON_HEIGHT+1+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCreateCheckbox(NULL, &wi); + wi.g.y = TAB_HEIGHT+5+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCreateCheckbox(NULL, &wi); + wi.g.y = TAB_HEIGHT+5+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCreateCheckbox(NULL, &wi); gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0); - gwinSetVisible(ghCheckbox2, TRUE); - wi.g.show = TRUE; wi.g.width = 0; - wi.g.y = BUTTON_HEIGHT+1+2*(CHECKBOX_HEIGHT+1); wi.text = "L1"; ghLabel1 = gwinLabelCreate(NULL, &wi); + // Labels + wi.g.width = 0; // dynamic width + wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "L1"; ghLabel1 = gwinLabelCreate(NULL, &wi); + + // Radio Buttons + wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = TAB_HEIGHT+5; + wi.g.x = 0*wi.g.width; wi.text = "Yes"; ghRadio1 = gwinCreateRadio(NULL, &wi, GROUP_R1R2); + wi.g.x = 1*wi.g.width; wi.text = "No"; ghRadio2 = gwinCreateRadio(NULL, &wi, GROUP_R1R2); // Console - we apply some special colors before making it visible - wi.g.show = FALSE; wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1; wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1; ghConsole = gwinCreateConsole(NULL, &wi.g); gwinSetColor(ghConsole, Yellow); gwinSetBgColor(ghConsole, Black); - gwinSetVisible(ghConsole, TRUE); - gwinClear(ghConsole); } // Assign toggles and dials to the buttons & sliders etc. @@ -120,15 +145,12 @@ int main(void) { gwinAttachDial(ghSlider3, 0, 1); #endif - gfxSleepMilliseconds(5000); - gwinSetBgColor(ghLabel1, Blue); - gwinSetColor(ghLabel1, Yellow); - gwinSetText(ghLabel1, "Very Big Label", FALSE); + // Make the console visible + gwinSetVisible(ghConsole, TRUE); + gwinClear(ghConsole); - gfxSleepMilliseconds(5000); - gwinSetBgColor(ghLabel1, Yellow); - gwinSetColor(ghLabel1, Red); - gwinSetText(ghLabel1, "L1", FALSE); + // Press the Buttons Tab + gwinPressRadio(ghTabButtons); while(1) { // Get an Event @@ -144,6 +166,48 @@ int main(void) { case GEVENT_GWIN_CHECKBOX: gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked"); break; + case GEVENT_GWIN_RADIO: + gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->radio)); + + // Is this the tab radio's + if (((GEventGWinRadio *)pe)->group == GROUP_TABS) { + + // Do some special animation for Label1 + if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { + gwinSetBgColor(ghLabel1, gwinGetDefaultBgColor()); + gwinSetColor(ghLabel1, gwinGetDefaultColor()); + } + + // Set control visibility depending on the tab selected + gwinSetVisible(ghButton1, ((GEventGWinRadio *)pe)->radio == ghTabButtons); + gwinSetVisible(ghButton2, ((GEventGWinRadio *)pe)->radio == ghTabButtons); + gwinSetVisible(ghButton3, ((GEventGWinRadio *)pe)->radio == ghTabButtons); + gwinSetVisible(ghButton4, ((GEventGWinRadio *)pe)->radio == ghTabButtons); + gwinSetVisible(ghSlider1, ((GEventGWinRadio *)pe)->radio == ghTabSliders); + gwinSetVisible(ghSlider2, ((GEventGWinRadio *)pe)->radio == ghTabSliders); + gwinSetVisible(ghSlider3, ((GEventGWinRadio *)pe)->radio == ghTabSliders); + gwinSetVisible(ghSlider4, ((GEventGWinRadio *)pe)->radio == ghTabSliders); + gwinSetVisible(ghCheckbox1, ((GEventGWinRadio *)pe)->radio == ghTabCheckboxes); + gwinSetVisible(ghCheckbox2, ((GEventGWinRadio *)pe)->radio == ghTabCheckboxes); + gwinSetVisible(ghLabel1, ((GEventGWinRadio *)pe)->radio == ghTabLabels); + gwinSetVisible(ghRadio1, ((GEventGWinRadio *)pe)->radio == ghTabRadios); + gwinSetVisible(ghRadio2, ((GEventGWinRadio *)pe)->radio == ghTabRadios); + //gwinSetVisible(ghImage1, ((GEventGWinRadio *)pe)->radio == ghTabImages); + + // Do some special animation for Label1 + if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { + gfxSleepMilliseconds(1000); + gwinSetBgColor(ghLabel1, Blue); + gwinSetColor(ghLabel1, Yellow); + gwinSetText(ghLabel1, "Very Big Label", FALSE); + + gfxSleepMilliseconds(1000); + gwinSetBgColor(ghLabel1, Yellow); + gwinSetColor(ghLabel1, Red); + gwinSetText(ghLabel1, "L1", FALSE); + } + } + break; default: gwinPrintf(ghConsole, "Unknown %d\n", pe->type); break; -- cgit v1.2.3 From f2432096cd823bb781d0574492b47c71bd340e1a Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 6 Jul 2013 14:24:40 +0200 Subject: added GWIN image demo --- demos/modules/gwin/widgets/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index e44ce6b0..e0e4c401 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -28,6 +28,9 @@ #include "gfx.h" +// include our chibios logo in a .gif format +#include "image_chibios.h" + static GListener gl; static GHandle ghConsole; static GHandle ghTabButtons, ghTabSliders, ghTabCheckboxes, ghTabLabels, ghTabRadios, ghTabImages; @@ -36,7 +39,7 @@ static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4; static GHandle ghCheckbox1, ghCheckbox2; static GHandle ghLabel1; static GHandle ghRadio1, ghRadio2; -//static GHandle ghImage1; +static GHandle ghImage1; #define ScrWidth gdispGetWidth() #define ScrHeight gdispGetHeight() @@ -127,6 +130,12 @@ int main(void) { wi.g.x = 0*wi.g.width; wi.text = "Yes"; ghRadio1 = gwinCreateRadio(NULL, &wi, GROUP_R1R2); wi.g.x = 1*wi.g.width; wi.text = "No"; ghRadio2 = gwinCreateRadio(NULL, &wi, GROUP_R1R2); + // Image + wi.g.x = ScrWidth-210; wi.g.y = TAB_HEIGHT + 10; wi.g.width = 200; wi.g.height = 200; + ghImage1 = gwinImageCreate(NULL, &wi); + gwinImageOpenMemory(ghImage1, image_chibios); + gwinImageCache(ghImage1); + // Console - we apply some special colors before making it visible wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1; wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1; @@ -192,7 +201,7 @@ int main(void) { gwinSetVisible(ghLabel1, ((GEventGWinRadio *)pe)->radio == ghTabLabels); gwinSetVisible(ghRadio1, ((GEventGWinRadio *)pe)->radio == ghTabRadios); gwinSetVisible(ghRadio2, ((GEventGWinRadio *)pe)->radio == ghTabRadios); - //gwinSetVisible(ghImage1, ((GEventGWinRadio *)pe)->radio == ghTabImages); + gwinSetVisible(ghImage1, ((GEventGWinRadio *)pe)->radio == ghTabImages); // Do some special animation for Label1 if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { -- cgit v1.2.3 From ba264ef1add20e8ede39fde1ceae1d57687498d1 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 7 Jul 2013 19:43:34 +1000 Subject: Update GWIN demos --- demos/modules/gwin/widgets/main.c | 330 +++++++++++++++++++++++++------------- 1 file changed, 221 insertions(+), 109 deletions(-) (limited to 'demos/modules/gwin/widgets/main.c') diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index e44ce6b0..4d485186 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -28,37 +28,186 @@ #include "gfx.h" +/** + * This demo demonstrates many of the GWIN widgets. + * On the "Radio" tab try playing with the color radio buttons. + * On the "Checkbox" tab try playing with the "Disable All" checkbox. + */ + +/* Our custom yellow style */ +static const GWidgetStyle YellowWidgetStyle = { + Yellow, // window background + + // enabled color set + { + HTML2COLOR(0x0000FF), // text + HTML2COLOR(0x404040), // edge + HTML2COLOR(0xE0E0E0), // fill + HTML2COLOR(0xE0E0E0), // progress - inactive area + }, + + // disabled color set + { + HTML2COLOR(0xC0C0C0), // text + HTML2COLOR(0x808080), // edge + HTML2COLOR(0xE0E0E0), // fill + HTML2COLOR(0xC0E0C0), // progress - active area + }, + + // pressed color set + { + HTML2COLOR(0xFF00FF), // text + HTML2COLOR(0x404040), // edge + HTML2COLOR(0x808080), // fill + HTML2COLOR(0x00E000), // progress - active area + }, +}; + +/* The variables we need */ static GListener gl; static GHandle ghConsole; static GHandle ghTabButtons, ghTabSliders, ghTabCheckboxes, ghTabLabels, ghTabRadios, ghTabImages; static GHandle ghButton1, ghButton2, ghButton3, ghButton4; static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4; -static GHandle ghCheckbox1, ghCheckbox2; +static GHandle ghCheckbox1, ghCheckbox2, ghCheckDisableAll; static GHandle ghLabel1; static GHandle ghRadio1, ghRadio2; +static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow; //static GHandle ghImage1; +/* Some useful macros */ #define ScrWidth gdispGetWidth() #define ScrHeight gdispGetHeight() -#define TAB_HEIGHT 30 -#define BUTTON_WIDTH 50 -#define BUTTON_HEIGHT 30 -#define SLIDER_WIDTH 20 -#define CHECKBOX_WIDTH 80 -#define CHECKBOX_HEIGHT 20 -#define RADIO_WIDTH 50 -#define RADIO_HEIGHT 20 -#define GROUP_TABS 0 -#define GROUP_R1R2 1 - -static GHandle createTab(GWidgetInit *pwi) { - GHandle gh; - - gh = gwinCreateRadio(NULL, pwi, GROUP_TABS); - gwinSetCustomDraw(gh, gwinRadioDraw_Tab, 0); - gwinSetVisible(gh, TRUE); - return gh; +#define TAB_HEIGHT 30 +#define LABEL_HEIGHT 40 +#define BUTTON_WIDTH 50 +#define BUTTON_HEIGHT 30 +#define SLIDER_WIDTH 20 +#define CHECKBOX_WIDTH 80 +#define CHECKBOX_HEIGHT 20 +#define RADIO_WIDTH 50 +#define RADIO_HEIGHT 20 +#define COLOR_WIDTH 80 +#define DISABLEALL_WIDTH 100 +#define GROUP_TABS 0 +#define GROUP_YESNO 1 +#define GROUP_COLORS 2 + +/** + * Create all the widgets. + * With the exception of the Tabs they are all created invisible. + */ +static void createWidgets(void) { + GWidgetInit wi; + + wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; + + // Create the Tabs + wi.g.show = TRUE; wi.customDraw = gwinRadioDraw_Tab; + wi.g.width = ScrWidth/6; wi.g.height = TAB_HEIGHT; wi.g.y = 0; + wi.g.x = 0*wi.g.width; wi.text = "Buttons"; ghTabButtons = gwinRadioCreate(NULL, &wi, GROUP_TABS); + wi.g.x = 1*wi.g.width; wi.text = "Sliders"; ghTabSliders = gwinRadioCreate(NULL, &wi, GROUP_TABS); + wi.g.x = 2*wi.g.width; wi.text = "Checkbox"; ghTabCheckboxes = gwinRadioCreate(NULL, &wi, GROUP_TABS); + wi.g.x = 3*wi.g.width; wi.text = "Radios"; ghTabRadios = gwinRadioCreate(NULL, &wi, GROUP_TABS); + wi.g.x = 4*wi.g.width; wi.text = "Labels"; ghTabLabels = gwinRadioCreate(NULL, &wi, GROUP_TABS); + wi.g.x = 5*wi.g.width; wi.text = "Images"; ghTabImages = gwinRadioCreate(NULL, &wi, GROUP_TABS); + + // Buttons + wi.g.show = FALSE; wi.customDraw = 0; + wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = TAB_HEIGHT+5; + wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; ghButton1 = gwinButtonCreate(NULL, &wi); + wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; ghButton2 = gwinButtonCreate(NULL, &wi); + wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; ghButton3 = gwinButtonCreate(NULL, &wi); + wi.g.x = 0+3*(BUTTON_WIDTH+1); wi.text = "B4"; ghButton4 = gwinButtonCreate(NULL, &wi); + + // Horizontal Sliders + wi.g.width = ScrWidth/2-2; wi.g.height = SLIDER_WIDTH; wi.g.x = ScrWidth/2+1; + wi.g.y = ScrHeight/2-2*(SLIDER_WIDTH+1); wi.text = "S1"; ghSlider1 = gwinSliderCreate(NULL, &wi); + wi.g.y = ScrHeight/2-1*(SLIDER_WIDTH+1); wi.text = "S2"; ghSlider2 = gwinSliderCreate(NULL, &wi); + + // Vertical Sliders + wi.g.width = SLIDER_WIDTH; wi.g.height = ScrHeight/2-2; wi.g.y = ScrHeight/2+1; + wi.g.x = 0+0*(SLIDER_WIDTH+1); wi.text = "S3"; ghSlider3 = gwinSliderCreate(NULL, &wi); + wi.g.x = 0+1*(SLIDER_WIDTH+1); wi.text = "S4"; ghSlider4 = gwinSliderCreate(NULL, &wi); + + // Checkboxes - for the 2nd checkbox we apply special drawing before making it visible + wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 0; + wi.g.y = TAB_HEIGHT+5+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCheckboxCreate(NULL, &wi); + wi.customDraw = gwinCheckboxDraw_CheckOnRight; + wi.g.y = TAB_HEIGHT+5+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCheckboxCreate(NULL, &wi); + wi.customDraw = 0; wi.g.width = DISABLEALL_WIDTH; + wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "Disable All"; ghCheckDisableAll = gwinCheckboxCreate(NULL, &wi); + + // Labels + wi.g.width = 0; wi.g.height = LABEL_HEIGHT; // dynamic width, fixed height + wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "Label"; ghLabel1 = gwinLabelCreate(NULL, &wi); + + // Radio Buttons + wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = TAB_HEIGHT+5; + wi.g.x = 0*wi.g.width; wi.text = "Yes"; ghRadio1 = gwinRadioCreate(NULL, &wi, GROUP_YESNO); + wi.g.x = 1*wi.g.width; wi.text = "No"; ghRadio2 = gwinRadioCreate(NULL, &wi, GROUP_YESNO); + wi.g.width = COLOR_WIDTH; wi.g.y += RADIO_HEIGHT+5; + wi.g.x = 0*wi.g.width; wi.text = "Black"; ghRadioBlack = gwinRadioCreate(NULL, &wi, GROUP_COLORS); + wi.g.x = 1*wi.g.width; wi.text = "White"; ghRadioWhite = gwinRadioCreate(NULL, &wi, GROUP_COLORS); + wi.g.x = 2*wi.g.width; wi.text = "Yellow"; ghRadioYellow = gwinRadioCreate(NULL, &wi, GROUP_COLORS); + gwinRadioPress(ghRadioWhite); + + // Console - we apply some special colors before making it visible + wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1; + wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1; + ghConsole = gwinConsoleCreate(NULL, &wi.g); + gwinSetColor(ghConsole, Yellow); + gwinSetBgColor(ghConsole, Black); +} + +/** + * Set the visibility of widgets based on which tab is selected. + */ +static void setTab(GHandle tab) { + /* Make sure everything is invisible first */ + gwinSetVisible(ghButton1, FALSE); gwinSetVisible(ghButton2, FALSE); + gwinSetVisible(ghButton3, FALSE); gwinSetVisible(ghButton4, FALSE); + gwinSetVisible(ghSlider1, FALSE); gwinSetVisible(ghSlider2, FALSE); + gwinSetVisible(ghSlider3, FALSE); gwinSetVisible(ghSlider4, FALSE); + gwinSetVisible(ghCheckbox1, FALSE); gwinSetVisible(ghCheckbox2, FALSE); gwinSetVisible(ghCheckDisableAll, FALSE); + gwinSetVisible(ghLabel1, FALSE); + gwinSetVisible(ghRadio1, FALSE); gwinSetVisible(ghRadio2, FALSE); + gwinSetVisible(ghRadioWhite, FALSE);gwinSetVisible(ghRadioBlack, FALSE);gwinSetVisible(ghRadioYellow, FALSE); + //gwinSetVisible(ghImage1, FALSE); + + /* Turn on widgets depending on the tab selected */ + if (tab == ghTabButtons) { + gwinSetVisible(ghButton1, TRUE); gwinSetVisible(ghButton2, TRUE); + gwinSetVisible(ghButton3, TRUE); gwinSetVisible(ghButton4, TRUE); + } else if (tab == ghTabSliders) { + gwinSetVisible(ghSlider1, TRUE); gwinSetVisible(ghSlider2, TRUE); + gwinSetVisible(ghSlider3, TRUE); gwinSetVisible(ghSlider4, TRUE); + } else if (tab == ghTabCheckboxes) { + gwinSetVisible(ghCheckbox1, TRUE); gwinSetVisible(ghCheckbox2, TRUE); gwinSetVisible(ghCheckDisableAll, TRUE); + } else if (tab == ghTabLabels) { + gwinSetVisible(ghLabel1, TRUE); + } else if (tab == ghTabRadios) { + gwinSetVisible(ghRadio1, TRUE); gwinSetVisible(ghRadio2, TRUE); + gwinSetVisible(ghRadioWhite, TRUE); gwinSetVisible(ghRadioBlack, TRUE); gwinSetVisible(ghRadioYellow, TRUE); + } else if (tab == ghTabImages) { + //gwinSetVisible(ghImage1, TRUE); + } +} + +/** + * Set the enabled state of every widget (except the tabs etc) + */ +static void setEnabled(bool_t ena) { + gwinSetEnabled(ghButton1, ena); gwinSetEnabled(ghButton2, ena); + gwinSetEnabled(ghButton3, ena); gwinSetEnabled(ghButton4, ena); + gwinSetEnabled(ghSlider1, ena); gwinSetEnabled(ghSlider2, ena); + gwinSetEnabled(ghSlider3, ena); gwinSetEnabled(ghSlider4, ena); + gwinSetEnabled(ghCheckbox1, ena); gwinSetEnabled(ghCheckbox2, ena); //gwinSetEnabled(ghCheckDisableAll, TRUE); + gwinSetEnabled(ghLabel1, ena); + gwinSetEnabled(ghRadio1, ena); gwinSetEnabled(ghRadio2, ena); + gwinSetEnabled(ghRadioWhite, ena); gwinSetEnabled(ghRadioBlack, ena); gwinSetEnabled(ghRadioYellow, ena); + //gwinSetEnabled(ghImage1, ena); } int main(void) { @@ -66,16 +215,11 @@ int main(void) { // Initialize the display gfxInit(); - gdispClear(White); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("UI2")); - gwinSetDefaultColor(Black); - gwinSetDefaultBgColor(White); - - // We want to listen for widget events - geventListenerInit(&gl); - gwinAttachListener(&gl); + gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); + gdispClear(White); // Connect the mouse #if GINPUT_NEED_MOUSE @@ -83,59 +227,9 @@ int main(void) { #endif // Create the gwin windows/widgets - { - GWidgetInit wi; - - // Create the Tabs - wi.g.show = FALSE; wi.g.width = ScrWidth/6; wi.g.height = TAB_HEIGHT; wi.g.y = 0; - wi.g.x = 0*wi.g.width; wi.text = "Buttons"; ghTabButtons = createTab(&wi); - wi.g.x = 1*wi.g.width; wi.text = "Sliders"; ghTabSliders = createTab(&wi); - wi.g.x = 2*wi.g.width; wi.text = "Checkbox"; ghTabCheckboxes = createTab(&wi); - wi.g.x = 3*wi.g.width; wi.text = "Labels"; ghTabLabels = createTab(&wi); - wi.g.x = 4*wi.g.width; wi.text = "Radios"; ghTabRadios = createTab(&wi); - wi.g.x = 5*wi.g.width; wi.text = "Images"; ghTabImages = createTab(&wi); - - // Buttons - wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = TAB_HEIGHT+5; - wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; ghButton1 = gwinCreateButton(NULL, &wi); - wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; ghButton2 = gwinCreateButton(NULL, &wi); - wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; ghButton3 = gwinCreateButton(NULL, &wi); - wi.g.x = 0+3*(BUTTON_WIDTH+1); wi.text = "B4"; ghButton4 = gwinCreateButton(NULL, &wi); - - // Horizontal Sliders - wi.g.width = ScrWidth/2-2; wi.g.height = SLIDER_WIDTH; wi.g.x = ScrWidth/2+1; - wi.g.y = ScrHeight/2-2*(SLIDER_WIDTH+1); wi.text = "S1"; ghSlider1 = gwinCreateSlider(NULL, &wi); - wi.g.y = ScrHeight/2-1*(SLIDER_WIDTH+1); wi.text = "S2"; ghSlider2 = gwinCreateSlider(NULL, &wi); - - // Vertical Sliders - wi.g.width = SLIDER_WIDTH; wi.g.height = ScrHeight/2-2; wi.g.y = ScrHeight/2+1; - wi.g.x = 0+0*(SLIDER_WIDTH+1); wi.text = "S3"; ghSlider3 = gwinCreateSlider(NULL, &wi); - wi.g.x = 0+1*(SLIDER_WIDTH+1); wi.text = "S4"; ghSlider4 = gwinCreateSlider(NULL, &wi); - - // Checkboxes - for the 2nd checkbox we apply special drawing before making it visible - wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 0; - wi.g.y = TAB_HEIGHT+5+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCreateCheckbox(NULL, &wi); - wi.g.y = TAB_HEIGHT+5+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCreateCheckbox(NULL, &wi); - gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0); - - // Labels - wi.g.width = 0; // dynamic width - wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "L1"; ghLabel1 = gwinLabelCreate(NULL, &wi); - - // Radio Buttons - wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = TAB_HEIGHT+5; - wi.g.x = 0*wi.g.width; wi.text = "Yes"; ghRadio1 = gwinCreateRadio(NULL, &wi, GROUP_R1R2); - wi.g.x = 1*wi.g.width; wi.text = "No"; ghRadio2 = gwinCreateRadio(NULL, &wi, GROUP_R1R2); - - // Console - we apply some special colors before making it visible - wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1; - wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1; - ghConsole = gwinCreateConsole(NULL, &wi.g); - gwinSetColor(ghConsole, Yellow); - gwinSetBgColor(ghConsole, Black); - } + createWidgets(); - // Assign toggles and dials to the buttons & sliders etc. + // Assign toggles and dials to specific buttons & sliders etc. #if GINPUT_NEED_TOGGLE gwinAttachToggle(ghButton1, 0, 0); gwinAttachToggle(ghButton2, 0, 1); @@ -149,8 +243,12 @@ int main(void) { gwinSetVisible(ghConsole, TRUE); gwinClear(ghConsole); - // Press the Buttons Tab - gwinPressRadio(ghTabButtons); + // We want to listen for widget events + geventListenerInit(&gl); + gwinAttachListener(&gl); + + // Press the Tab we want visible + gwinRadioPress(ghTabButtons); while(1) { // Get an Event @@ -160,54 +258,68 @@ int main(void) { case GEVENT_GWIN_BUTTON: gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->button)); break; + case GEVENT_GWIN_SLIDER: gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position); break; + case GEVENT_GWIN_CHECKBOX: gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked"); + + // If it is the Disable All checkbox then do that. + if (((GEventGWinCheckbox *)pe)->checkbox == ghCheckDisableAll) { + gwinPrintf(ghConsole, "%s All\n", ((GEventGWinCheckbox *)pe)->isChecked ? "Disable" : "Enable"); + setEnabled(!((GEventGWinCheckbox *)pe)->isChecked); + } break; + case GEVENT_GWIN_RADIO: gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->radio)); - // Is this the tab radio's - if (((GEventGWinRadio *)pe)->group == GROUP_TABS) { - - // Do some special animation for Label1 - if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { - gwinSetBgColor(ghLabel1, gwinGetDefaultBgColor()); - gwinSetColor(ghLabel1, gwinGetDefaultColor()); - } + switch(((GEventGWinRadio *)pe)->group) { + case GROUP_TABS: // Set control visibility depending on the tab selected - gwinSetVisible(ghButton1, ((GEventGWinRadio *)pe)->radio == ghTabButtons); - gwinSetVisible(ghButton2, ((GEventGWinRadio *)pe)->radio == ghTabButtons); - gwinSetVisible(ghButton3, ((GEventGWinRadio *)pe)->radio == ghTabButtons); - gwinSetVisible(ghButton4, ((GEventGWinRadio *)pe)->radio == ghTabButtons); - gwinSetVisible(ghSlider1, ((GEventGWinRadio *)pe)->radio == ghTabSliders); - gwinSetVisible(ghSlider2, ((GEventGWinRadio *)pe)->radio == ghTabSliders); - gwinSetVisible(ghSlider3, ((GEventGWinRadio *)pe)->radio == ghTabSliders); - gwinSetVisible(ghSlider4, ((GEventGWinRadio *)pe)->radio == ghTabSliders); - gwinSetVisible(ghCheckbox1, ((GEventGWinRadio *)pe)->radio == ghTabCheckboxes); - gwinSetVisible(ghCheckbox2, ((GEventGWinRadio *)pe)->radio == ghTabCheckboxes); - gwinSetVisible(ghLabel1, ((GEventGWinRadio *)pe)->radio == ghTabLabels); - gwinSetVisible(ghRadio1, ((GEventGWinRadio *)pe)->radio == ghTabRadios); - gwinSetVisible(ghRadio2, ((GEventGWinRadio *)pe)->radio == ghTabRadios); - //gwinSetVisible(ghImage1, ((GEventGWinRadio *)pe)->radio == ghTabImages); - - // Do some special animation for Label1 + setTab(((GEventGWinRadio *)pe)->radio); + + // Do some special animation for Label1 to demonstrate auto width sizing if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { + gwinPrintf(ghConsole, "Change Label Text\n"); gfxSleepMilliseconds(1000); - gwinSetBgColor(ghLabel1, Blue); - gwinSetColor(ghLabel1, Yellow); gwinSetText(ghLabel1, "Very Big Label", FALSE); gfxSleepMilliseconds(1000); - gwinSetBgColor(ghLabel1, Yellow); - gwinSetColor(ghLabel1, Red); - gwinSetText(ghLabel1, "L1", FALSE); + gwinSetText(ghLabel1, "Label", FALSE); } + break; + + case GROUP_COLORS: + { + const GWidgetStyle *pstyle; + + gwinPrintf(ghConsole, "Change Color Scheme\n"); + + if (((GEventGWinRadio *)pe)->radio == ghRadioYellow) + pstyle = &YellowWidgetStyle; + else if (((GEventGWinRadio *)pe)->radio == ghRadioBlack) + pstyle = &BlackWidgetStyle; + else + pstyle = &WhiteWidgetStyle; + + // Clear the screen to the new color - we avoid the console area as it can't redraw itself + #if GDISP_NEED_CLIP + gdispUnsetClip(); + #endif + gdispFillArea(0, 0, ScrWidth, ScrHeight/2, pstyle->background); + gdispFillArea(0, ScrHeight/2, ScrWidth/2, ScrHeight/2, pstyle->background); + + // Update the style on all controls + gwinSetDefaultStyle(pstyle, TRUE); + } + break; } break; + default: gwinPrintf(ghConsole, "Unknown %d\n", pe->type); break; -- cgit v1.2.3