diff options
Diffstat (limited to 'demos')
-rw-r--r-- | demos/modules/gwin/frame/demo.mk | 3 | ||||
-rw-r--r-- | demos/modules/gwin/frame/gfxconf.h | 107 | ||||
-rw-r--r-- | demos/modules/gwin/frame/main.c | 47 | ||||
-rw-r--r-- | demos/modules/gwin/imagebox/main.c | 2 | ||||
-rw-r--r-- | demos/modules/gwin/label/main.c | 4 | ||||
-rw-r--r-- | demos/modules/gwin/list/main.c | 4 | ||||
-rw-r--r-- | demos/modules/gwin/progressbar/main.c | 2 | ||||
-rw-r--r-- | demos/modules/gwin/widgets/gfxconf.h | 8 | ||||
-rw-r--r-- | demos/modules/gwin/widgets/main.c | 298 |
9 files changed, 335 insertions, 140 deletions
diff --git a/demos/modules/gwin/frame/demo.mk b/demos/modules/gwin/frame/demo.mk new file mode 100644 index 00000000..b10701c9 --- /dev/null +++ b/demos/modules/gwin/frame/demo.mk @@ -0,0 +1,3 @@ +DEMODIR = $(GFXLIB)/demos/modules/gwin/frame +GFXINC += $(DEMODIR) +GFXSRC += $(DEMODIR)/main.c diff --git a/demos/modules/gwin/frame/gfxconf.h b/demos/modules/gwin/frame/gfxconf.h new file mode 100644 index 00000000..6809013d --- /dev/null +++ b/demos/modules/gwin/frame/gfxconf.h @@ -0,0 +1,107 @@ +/** + * This file has a different license to the rest of the uGFX system. + * You can copy, modify and distribute this file as you see fit. + * You do not need to publish your source modifications to this file. + * The only thing you are not permitted to do is to relicense it + * under a different license. + */ + +/** + * Copy this file into your project directory and rename it as gfxconf.h + * Edit your copy to turn on the uGFX features you want to use. + * The values below are the defaults. You should delete anything + * you are leaving as default. + * + * Please use spaces instead of tabs in this file. + */ + +#ifndef _GFXCONF_H +#define _GFXCONF_H + +/* The operating system to use. One of these must be defined - preferably in your Makefile */ +//#define GFX_USE_OS_CHIBIOS TRUE +//#define GFX_USE_OS_WIN32 TRUE +//#define GFX_USE_OS_LINUX TRUE +//#define GFX_USE_OS_OSX TRUE + + +/////////////////////////////////////////////////////////////////////////// +// GDISP // +/////////////////////////////////////////////////////////////////////////// +#define GFX_USE_GDISP TRUE + +#define GDISP_NEED_AUTOFLUSH FALSE +#define GDISP_NEED_TIMERFLUSH FALSE +#define GDISP_NEED_VALIDATION TRUE +#define GDISP_NEED_CLIP TRUE +#define GDISP_NEED_TEXT TRUE + #define GDISP_INCLUDE_FONT_UI2 TRUE +#define GDISP_NEED_CIRCLE TRUE +#define GDISP_NEED_CONVEX_POLYGON TRUE +#define GDISP_NEED_MULTITHREAD TRUE + +#define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE + +/////////////////////////////////////////////////////////////////////////// +// GWIN // +/////////////////////////////////////////////////////////////////////////// +#define GFX_USE_GWIN TRUE + +#define GWIN_NEED_WINDOWMANAGER TRUE + +#define GWIN_NEED_CONSOLE TRUE + #define GWIN_CONSOLE_USE_HISTORY TRUE + #define GWIN_CONSOLE_HISTORY_AVERAGING TRUE + #define GWIN_CONSOLE_HISTORY_ATCREATE TRUE + #define GWIN_CONSOLE_ESCSEQ TRUE + #define GWIN_CONSOLE_USE_BASESTREAM TRUE +#define GWIN_NEED_GRAPH TRUE + +#define GWIN_NEED_WIDGET TRUE + #define GWIN_NEED_LABEL TRUE + #define GWIN_LABEL_ATTRIBUTE TRUE + #define GWIN_NEED_BUTTON TRUE + #define GWIN_BUTTON_LAZY_RELEASE TRUE + #define GWIN_NEED_SLIDER TRUE + #define GWIN_NEED_CHECKBOX TRUE + #define GWIN_NEED_IMAGE FALSE + #define GWIN_NEED_IMAGE_ANIMATION TRUE + #define GWIN_NEED_RADIO TRUE + #define GWIN_NEED_LIST TRUE + #define GWIN_NEED_LIST_IMAGES FALSE + #define GWIN_NEED_PROGRESSBAR TRUE + #define GWIN_PROGRESSBAR_AUTO TRUE + #define GWIN_FLAT_STYLING TRUE +#define GWIN_NEED_CONTAINERS TRUE + #define GWIN_NEED_CONTAINER TRUE + #define GWIN_NEED_FRAME TRUE + + +/////////////////////////////////////////////////////////////////////////// +// GEVENT // +/////////////////////////////////////////////////////////////////////////// +#define GFX_USE_GEVENT TRUE + +/////////////////////////////////////////////////////////////////////////// +// GTIMER // +/////////////////////////////////////////////////////////////////////////// +#define GFX_USE_GTIMER TRUE + +/////////////////////////////////////////////////////////////////////////// +// GQUEUE // +/////////////////////////////////////////////////////////////////////////// +#define GFX_USE_GQUEUE TRUE + +#define GQUEUE_NEED_ASYNC TRUE +#define GQUEUE_NEED_GSYNC TRUE +#define GQUEUE_NEED_FSYNC FALSE +#define GQUEUE_NEED_BUFFERS FALSE + +/////////////////////////////////////////////////////////////////////////// +// GINPUT // +/////////////////////////////////////////////////////////////////////////// +#define GFX_USE_GINPUT TRUE + +#define GINPUT_NEED_MOUSE TRUE + +#endif /* _GFXCONF_H */ diff --git a/demos/modules/gwin/frame/main.c b/demos/modules/gwin/frame/main.c new file mode 100644 index 00000000..ebfeaa6e --- /dev/null +++ b/demos/modules/gwin/frame/main.c @@ -0,0 +1,47 @@ +#include "gfx.h" + +static GListener gl; +static GHandle ghFrame1; + +static void createWidgets(void) { + GWidgetInit wi; + + // Apply some default values for GWIN + gwinWidgetClearInit(&wi); + wi.g.show = TRUE; + + // Apply the frame parameters + wi.g.width = 400; + wi.g.height = 300; + wi.g.y = 10; + wi.g.x = 10; + wi.text = "Frame 1"; + + ghFrame1 = gwinFrameCreate(0, &wi, GWIN_FRAME_BORDER | GWIN_FRAME_CLOSE_BTN | GWIN_FRAME_MINMAX_BTN); +} + +int main(void) { + // Initialize the display + gfxInit(); + + // Attach the mouse input + gwinAttachMouse(0); + + // Set the widget defaults + gwinSetDefaultFont(gdispOpenFont("*")); + gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); + gdispClear(White); + + // create the widget + createWidgets(); + + // We want to listen for widget events + geventListenerInit(&gl); + gwinAttachListener(&gl); + + while(1) { + gfxSleepMilliseconds(1000); + } + + return 0; +} diff --git a/demos/modules/gwin/imagebox/main.c b/demos/modules/gwin/imagebox/main.c index c15f5fb3..d8ebbe73 100644 --- a/demos/modules/gwin/imagebox/main.c +++ b/demos/modules/gwin/imagebox/main.c @@ -41,7 +41,7 @@ static void createWidgets(void) { // create the first image widget wi.g.x = 10; wi.g.y = 10; wi.g.width = 200; wi.g.height = 100; - ghImage1 = gwinImageCreate(NULL, &wi.g); + ghImage1 = gwinImageCreate(0, &wi.g); gwinImageOpenFile(ghImage1, "ugfx_logo_banner.bmp"); } diff --git a/demos/modules/gwin/label/main.c b/demos/modules/gwin/label/main.c index 175c0d6e..918f2787 100644 --- a/demos/modules/gwin/label/main.c +++ b/demos/modules/gwin/label/main.c @@ -44,13 +44,13 @@ static void createWidgets(void) { // Create the IP label wi.g.width = 200; wi.g.height = 20; wi.g.x = 10, wi.g.y = 80; wi.text = "192.168.1.42"; - ghLabel1 = gwinLabelCreate(NULL, &wi); + ghLabel1 = gwinLabelCreate(0, &wi); gwinLabelSetAttribute(ghLabel1, 100, "Current IP:"); // Create the DHCP label wi.g.width = 200; wi.g.height = 20; wi.g.x = 10, wi.g.y = 100; wi.text = "Off"; - ghLabel2 = gwinLabelCreate(NULL, &wi); + ghLabel2 = gwinLabelCreate(0, &wi); gwinLabelSetAttribute(ghLabel2, 100, "DHCP:"); } diff --git a/demos/modules/gwin/list/main.c b/demos/modules/gwin/list/main.c index 6d469626..ed5b6905 100644 --- a/demos/modules/gwin/list/main.c +++ b/demos/modules/gwin/list/main.c @@ -43,12 +43,12 @@ static void createWidgets(void) { // Create the label for the first list wi.g.width = 150; wi.g.height = 20; wi.g.x = 10, wi.g.y = 80; wi.text = "List 1: Default"; - ghLabel1 = gwinLabelCreate(NULL, &wi); + ghLabel1 = gwinLabelCreate(0, &wi); // Create the label for the second list wi.g.width = 150; wi.g.height = 20; wi.g.x = 165, wi.g.y = 80; wi.text = "List 2: Smooth scrolling"; - ghLabel1 = gwinLabelCreate(NULL, &wi); + ghLabel1 = gwinLabelCreate(0, &wi); // The first list widget wi.g.width = 150; diff --git a/demos/modules/gwin/progressbar/main.c b/demos/modules/gwin/progressbar/main.c index 6fb53c2e..8e9e8352 100644 --- a/demos/modules/gwin/progressbar/main.c +++ b/demos/modules/gwin/progressbar/main.c @@ -9,7 +9,7 @@ static void _createWidget(void) { wi.g.show = TRUE; wi.g.y = 10; wi.g.x = 10; wi.g.width = 200; wi.g.height = 20; wi.text = "Progress 1"; - ghProgressbar = gwinProgressbarCreate(NULL, &wi); + ghProgressbar = gwinProgressbarCreate(0, &wi); } int main(void) { diff --git a/demos/modules/gwin/widgets/gfxconf.h b/demos/modules/gwin/widgets/gfxconf.h index 25065b27..9f8601b8 100644 --- a/demos/modules/gwin/widgets/gfxconf.h +++ b/demos/modules/gwin/widgets/gfxconf.h @@ -43,6 +43,7 @@ #define GDISP_NEED_IMAGE_GIF TRUE #define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE +#define GDISP_NEED_MULTITHREAD TRUE /////////////////////////////////////////////////////////////////////////// // GWIN // @@ -52,10 +53,14 @@ #define GWIN_NEED_WINDOWMANAGER TRUE #define GWIN_NEED_CONSOLE TRUE + #define GWIN_CONSOLE_USE_HISTORY TRUE + #define GWIN_CONSOLE_HISTORY_AVERAGING TRUE + #define GWIN_CONSOLE_HISTORY_ATCREATE TRUE #define GWIN_NEED_GRAPH TRUE #define GWIN_NEED_WIDGET TRUE #define GWIN_NEED_LABEL TRUE + #define GWIN_LABEL_ATTRIBUTE TRUE #define GWIN_NEED_BUTTON TRUE // #define GWIN_BUTTON_LAZY_RELEASE TRUE #define GWIN_NEED_SLIDER TRUE @@ -67,6 +72,9 @@ #define GWIN_NEED_PROGRESSBAR TRUE #define GWIN_PROGRESSBAR_AUTO TRUE +#define GWIN_NEED_CONTAINERS TRUE + #define GWIN_NEED_CONTAINER TRUE + /////////////////////////////////////////////////////////////////////////// // GEVENT // /////////////////////////////////////////////////////////////////////////// diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index 9742a027..69f90285 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -25,7 +25,7 @@ * (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 <stdio.h> #include "gfx.h" /** @@ -71,13 +71,15 @@ static const GWidgetStyle YellowWidgetStyle = { }; /* The variables we need */ +static font_t font; static GListener gl; static GHandle ghConsole; static GHandle ghTabButtons, ghTabSliders, ghTabCheckboxes, ghTabLabels, ghTabRadios, ghTabLists, ghTabImages, ghTabProgressbar; +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 ghLabel1; +static GHandle ghLabelSlider1, ghLabelSlider2, ghLabelSlider3, ghLabelSlider4, ghLabelRadio1; static GHandle ghRadio1, ghRadio2; static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow; static GHandle ghList1, ghList2, ghList3, ghList4; @@ -89,11 +91,12 @@ static gdispImage imgYesNo; #define ScrWidth gdispGetWidth() #define ScrHeight gdispGetHeight() +#define BUTTON_PADDING 20 #define TAB_HEIGHT 30 -#define LABEL_HEIGHT 40 +#define LABEL_HEIGHT 15 #define BUTTON_WIDTH 50 #define BUTTON_HEIGHT 30 -#define LIST_WIDTH 100 +#define LIST_WIDTH 75 #define LIST_HEIGHT 80 #define SLIDER_WIDTH 20 #define CHECKBOX_WIDTH 80 @@ -106,6 +109,20 @@ static gdispImage imgYesNo; #define GROUP_YESNO 1 #define GROUP_COLORS 2 +// Wrap tabs onto the next line if they don't fit. +static void setbtntext(GWidgetInit *pwi, coord_t maxwidth, char *txt) { + if (pwi->g.x >= maxwidth) { + pwi->g.x = 0; + pwi->g.y += pwi->g.height; + } + pwi->text = txt; + pwi->g.width = gdispGetStringWidth(pwi->text, font) + BUTTON_PADDING; + if (pwi->g.x + pwi->g.width > maxwidth) { + pwi->g.x = 0; + pwi->g.y += pwi->g.height; + } +} + /** * Create all the widgets. * With the exception of the Tabs they are all created invisible. @@ -117,86 +134,132 @@ static void createWidgets(void) { // Create the Tabs wi.g.show = TRUE; wi.customDraw = gwinRadioDraw_Tab; - wi.g.width = ScrWidth/7; wi.g.height = TAB_HEIGHT; wi.g.y = 0; - wi.g.x = 0*wi.g.width; wi.text = "Buttons"; + wi.g.height = TAB_HEIGHT; wi.g.y = 0; + wi.g.x = 0; setbtntext(&wi, ScrWidth, "Buttons"); ghTabButtons = gwinRadioCreate(0, &wi, GROUP_TABS); - wi.g.x = 1*wi.g.width; wi.text = "Sliders"; + wi.g.x += wi.g.width; setbtntext(&wi, ScrWidth, "Sliders"); ghTabSliders = gwinRadioCreate(0, &wi, GROUP_TABS); - wi.g.x = 2*wi.g.width; wi.text = "Checkbox"; + wi.g.x += wi.g.width; setbtntext(&wi, ScrWidth, "Checkbox"); ghTabCheckboxes = gwinRadioCreate(0, &wi, GROUP_TABS); - wi.g.x = 3*wi.g.width; wi.text = "Radios"; + wi.g.x += wi.g.width; setbtntext(&wi, ScrWidth, "Radios"); ghTabRadios = gwinRadioCreate(0, &wi, GROUP_TABS); - wi.g.x = 4*wi.g.width; wi.text = "Lists"; + wi.g.x += wi.g.width; setbtntext(&wi, ScrWidth, "Lists"); ghTabLists = gwinRadioCreate(0, &wi, GROUP_TABS); - wi.g.x = 5*wi.g.width; wi.text = "Labels"; + wi.g.x += wi.g.width; setbtntext(&wi, ScrWidth, "Labels"); ghTabLabels = gwinRadioCreate(0, &wi, GROUP_TABS); - wi.g.x = 6*wi.g.width; wi.text = "Images"; + wi.g.x += wi.g.width; setbtntext(&wi, ScrWidth, "Images"); ghTabImages = gwinRadioCreate(0, &wi, GROUP_TABS); - wi.g.y = TAB_HEIGHT; - wi.g.x = 0*wi.g.width; wi.text = "Progressbar"; + wi.g.x += wi.g.width; setbtntext(&wi, ScrWidth, "Progressbar"); ghTabProgressbar = gwinRadioCreate(0, &wi, GROUP_TABS); + wi.g.y += wi.g.height; + wi.customDraw = 0; + + // Create the Pages + wi.g.show = FALSE; + wi.g.x = 5; wi.g.y += 5; + wi.g.width = ScrWidth/2 - 10; wi.g.height = ScrHeight-wi.g.y-5; + ghPgButtons = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + ghPgSliders = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + ghPgCheckboxes = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + ghPgRadios = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + ghPgLists = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + ghPgLabels = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + ghPgImages = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + ghPgProgressbars = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); + wi.g.show = TRUE; + + // Console - we apply some special colors before making it visible + wi.g.x = ScrWidth/2+1; + wi.g.width = ScrWidth/2 - 5; + ghConsole = gwinConsoleCreate(0, &wi.g); + gwinSetColor(ghConsole, Yellow); + gwinSetBgColor(ghConsole, Black); - // Buttons - wi.g.show = FALSE; wi.customDraw = 0; - wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = 2*TAB_HEIGHT+10; - wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; + // Buttons + wi.g.parent = ghPgButtons; + wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = 5; + wi.g.x = 5; setbtntext(&wi, gwinGetInnerWidth(ghPgButtons), "Button 1"); ghButton1 = gwinButtonCreate(0, &wi); - wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; + wi.g.x += wi.g.width+3; setbtntext(&wi, gwinGetInnerWidth(ghPgButtons), "Button 2"); ghButton2 = gwinButtonCreate(0, &wi); - wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; + wi.g.x += wi.g.width+3; setbtntext(&wi, gwinGetInnerWidth(ghPgButtons), "Button 3"); ghButton3 = gwinButtonCreate(0, &wi); - wi.g.x = 0+3*(BUTTON_WIDTH+1); wi.text = "B4"; + wi.g.x += wi.g.width+3; setbtntext(&wi, gwinGetInnerWidth(ghPgButtons), "Button 4"); ghButton4 = gwinButtonCreate(0, &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"; + wi.g.parent = ghPgSliders; + wi.g.width = gwinGetInnerWidth(ghPgSliders) - 10; wi.g.height = SLIDER_WIDTH; + wi.g.x = 5; wi.g.y = 5; wi.text = "S1"; ghSlider1 = gwinSliderCreate(0, &wi); - wi.g.y = ScrHeight/2-1*(SLIDER_WIDTH+1); wi.text = "S2"; + gwinSliderSetPosition(ghSlider1, 33); + wi.g.y += wi.g.height + 1; wi.text = "S2"; ghSlider2 = gwinSliderCreate(0, &wi); + gwinSliderSetPosition(ghSlider2, 86); // 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"; + wi.g.y += wi.g.height + 5; + wi.g.width = SLIDER_WIDTH; wi.g.height = gwinGetInnerHeight(ghPgSliders) - 5 - wi.g.y; + wi.g.x = 5; wi.text = "S3"; ghSlider3 = gwinSliderCreate(0, &wi); - wi.g.x = 0+1*(SLIDER_WIDTH+1); wi.text = "S4"; + gwinSliderSetPosition(ghSlider3, 13); + wi.g.x += wi.g.width+1; wi.text = "S4"; ghSlider4 = gwinSliderCreate(0, &wi); + gwinSliderSetPosition(ghSlider4, 76); // 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 = 2*TAB_HEIGHT+10+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; + 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"; ghCheckbox1 = gwinCheckboxCreate(0, &wi); wi.customDraw = gwinCheckboxDraw_CheckOnRight; - wi.g.y = 2*TAB_HEIGHT+10+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; + wi.g.y += wi.g.height+1; wi.text = "C2"; ghCheckbox2 = gwinCheckboxCreate(0, &wi); wi.customDraw = 0; wi.g.width = DISABLEALL_WIDTH; - wi.g.y = 2*TAB_HEIGHT+10+2*(CHECKBOX_HEIGHT+1); wi.text = "Disable All"; + wi.g.y += wi.g.height+1; wi.text = "Disable All"; ghCheckDisableAll = gwinCheckboxCreate(0, &wi); // Labels - wi.g.width = 0; wi.g.height = LABEL_HEIGHT; // dynamic width, fixed height - wi.g.y = 2*TAB_HEIGHT+10+2*(CHECKBOX_HEIGHT+1); wi.text = "Label"; - ghLabel1 = gwinLabelCreate(0, &wi); + wi.g.parent = ghPgLabels; + wi.g.width = 200; wi.g.height = LABEL_HEIGHT; + wi.g.x = wi.g.y = 5;wi.text = "N/A"; + ghLabelSlider1 = gwinLabelCreate(0, &wi); + gwinLabelSetAttribute(ghLabelSlider1, 100, "Slider 1:"); + wi.g.y += LABEL_HEIGHT + 2; + ghLabelSlider2 = gwinLabelCreate(0, &wi); + gwinLabelSetAttribute(ghLabelSlider2, 100, "Slider 2:"); + wi.g.y += LABEL_HEIGHT + 2; + ghLabelSlider3 = gwinLabelCreate(0, &wi); + gwinLabelSetAttribute(ghLabelSlider3, 100, "Slider 3:"); + wi.g.y += LABEL_HEIGHT + 2; + ghLabelSlider4 = gwinLabelCreate(0, &wi); + gwinLabelSetAttribute(ghLabelSlider4, 100, "Slider 4:"); + wi.g.y += LABEL_HEIGHT + 2; + ghLabelRadio1 = gwinLabelCreate(0, &wi); + gwinLabelSetAttribute(ghLabelRadio1, 100, "RadioButton 1:"); + // Radio Buttons - wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = 2*TAB_HEIGHT+10; - wi.g.x = 0*wi.g.width; wi.text = "Yes"; + wi.g.parent = ghPgRadios; + wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = 5; + wi.g.x = 5; wi.text = "Yes"; ghRadio1 = gwinRadioCreate(0, &wi, GROUP_YESNO); - wi.g.x = 1*wi.g.width; wi.text = "No"; + wi.g.x += wi.g.width; wi.text = "No"; if (wi.g.x + wi.g.width > gwinGetInnerWidth(ghPgRadios)) { wi.g.x = 0; wi.g.y += RADIO_HEIGHT; } ghRadio2 = gwinRadioCreate(0, &wi, GROUP_YESNO); + gwinRadioPress(ghRadio1); wi.g.width = COLOR_WIDTH; wi.g.y += RADIO_HEIGHT+5; - wi.g.x = 0*wi.g.width; wi.text = "Black"; + wi.g.x = 5; wi.text = "Black"; ghRadioBlack = gwinRadioCreate(0, &wi, GROUP_COLORS); - wi.g.x = 1*wi.g.width; wi.text = "White"; + wi.g.x += wi.g.width; wi.text = "White"; if (wi.g.x + wi.g.width > gwinGetInnerWidth(ghPgRadios)) { wi.g.x = 0; wi.g.y += RADIO_HEIGHT; } ghRadioWhite = gwinRadioCreate(0, &wi, GROUP_COLORS); - wi.g.x = 2*wi.g.width; wi.text = "Yellow"; + wi.g.x += wi.g.width; wi.text = "Yellow"; if (wi.g.x + wi.g.width > gwinGetInnerWidth(ghPgRadios)) { wi.g.x = 0; wi.g.y += RADIO_HEIGHT; } ghRadioYellow = gwinRadioCreate(0, &wi, GROUP_COLORS); gwinRadioPress(ghRadioWhite); // Lists - wi.g.show = FALSE; wi.customDraw = 0; - wi.g.width = LIST_WIDTH; wi.g.height = LIST_HEIGHT; wi.g.y = 2*TAB_HEIGHT+10; - wi.g.x = 0+0*(LIST_WIDTH+5); wi.text = "L1"; + wi.g.parent = ghPgLists; + wi.g.width = LIST_WIDTH; wi.g.height = LIST_HEIGHT; wi.g.y = 5; + wi.g.x = 5; wi.text = "L1"; ghList1 = gwinListCreate(0, &wi, FALSE); gwinListAddItem(ghList1, "Item 0", FALSE); gwinListAddItem(ghList1, "Item 1", FALSE); @@ -212,7 +275,7 @@ static void createWidgets(void) { gwinListAddItem(ghList1, "Item 11", FALSE); gwinListAddItem(ghList1, "Item 12", FALSE); gwinListAddItem(ghList1, "Item 13", FALSE); - wi.g.x = 0+1*(LIST_WIDTH+5); wi.text = "L2"; + wi.text = "L2"; wi.g.x += LIST_WIDTH+1; if (wi.g.x + LIST_WIDTH > gwinGetInnerWidth(ghPgLists)) { wi.g.x = 0; wi.g.y += LIST_HEIGHT+1; } ghList2 = gwinListCreate(0, &wi, TRUE); gwinListAddItem(ghList2, "Item 0", FALSE); gwinListAddItem(ghList2, "Item 1", FALSE); @@ -228,7 +291,7 @@ static void createWidgets(void) { gwinListAddItem(ghList2, "Item 11", FALSE); gwinListAddItem(ghList2, "Item 12", FALSE); gwinListAddItem(ghList2, "Item 13", FALSE); - wi.g.x = 0+2*(LIST_WIDTH+5); wi.text = "L3"; + wi.text = "L3"; wi.g.x += LIST_WIDTH+1; if (wi.g.x + LIST_WIDTH > gwinGetInnerWidth(ghPgLists)) { wi.g.x = 0; wi.g.y += LIST_HEIGHT+1; } ghList3 = gwinListCreate(0, &wi, TRUE); gwinListAddItem(ghList3, "Item 0", FALSE); gwinListAddItem(ghList3, "Item 1", FALSE); @@ -237,7 +300,7 @@ static void createWidgets(void) { gdispImageOpenFile(&imgYesNo, "image_yesno.gif"); gwinListItemSetImage(ghList3, 1, &imgYesNo); gwinListItemSetImage(ghList3, 3, &imgYesNo); - wi.g.x = 0+3*(LIST_WIDTH+5); wi.text = "L4"; + wi.text = "L4"; wi.g.x += LIST_WIDTH+1; if (wi.g.x + LIST_WIDTH > gwinGetInnerWidth(ghPgLists)) { wi.g.x = 0; wi.g.y += LIST_HEIGHT+1; } ghList4 = gwinListCreate(0, &wi, TRUE); gwinListAddItem(ghList4, "Item 0", FALSE); gwinListAddItem(ghList4, "Item 1", FALSE); @@ -256,23 +319,17 @@ static void createWidgets(void) { gwinListSetScroll(ghList4, scrollSmooth); // Image - wi.g.x = 20; wi.g.y = 2*TAB_HEIGHT+20; wi.g.width = 200; wi.g.height = 100; + wi.g.parent = ghPgImages; + wi.g.x = wi.g.y = 0; wi.g.width = gwinGetInnerWidth(ghPgImages); wi.g.height = gwinGetInnerHeight(ghPgImages); ghImage1 = gwinImageCreate(0, &wi.g); gwinImageOpenFile(ghImage1, "romfs_img_ugfx.gif"); // Progressbar - wi.g.show = FALSE; wi.customDraw = 0; - wi.g.width = 200; wi.g.height = 20; wi.g.y = 2*TAB_HEIGHT+10; - wi.g.x = 20; wi.text = "Progressbar 1"; + wi.g.parent = ghPgProgressbars; + wi.g.width = gwinGetInnerWidth(ghPgImages)-5; wi.g.height = SLIDER_WIDTH; wi.g.y = 5; + wi.g.x = 5; wi.text = "Progressbar 1"; ghProgressbar1 = gwinProgressbarCreate(0, &wi); gwinProgressbarSetResolution(ghProgressbar1, 10); - - // 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(0, &wi.g); - gwinSetColor(ghConsole, Yellow); - gwinSetBgColor(ghConsole, Black); } /** @@ -280,29 +337,14 @@ static void createWidgets(void) { */ 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(ghList1, FALSE); - gwinSetVisible(ghList2, FALSE); - gwinSetVisible(ghList3, FALSE); - gwinSetVisible(ghList4, FALSE); - gwinSetVisible(ghImage1, FALSE); - gwinSetVisible(ghProgressbar1, FALSE); + gwinHide(ghPgButtons); + gwinHide(ghPgSliders); + gwinHide(ghPgCheckboxes); + gwinHide(ghPgLabels); + gwinHide(ghPgRadios); + gwinHide(ghPgLists); + gwinHide(ghPgImages); + gwinHide(ghPgProgressbars); // Stop the progress bar gwinProgressbarStop(ghProgressbar1); @@ -310,36 +352,21 @@ static void setTab(GHandle tab) { /* Turn on widgets depending on the tab selected */ if (tab == ghTabButtons) { - gwinSetVisible(ghButton1, TRUE); - gwinSetVisible(ghButton2, TRUE); - gwinSetVisible(ghButton3, TRUE); - gwinSetVisible(ghButton4, TRUE); + gwinShow(ghPgButtons); } else if (tab == ghTabSliders) { - gwinSetVisible(ghSlider1, TRUE); - gwinSetVisible(ghSlider2, TRUE); - gwinSetVisible(ghSlider3, TRUE); - gwinSetVisible(ghSlider4, TRUE); + gwinShow(ghPgSliders); } else if (tab == ghTabCheckboxes) { - gwinSetVisible(ghCheckbox1, TRUE); - gwinSetVisible(ghCheckbox2, TRUE); - gwinSetVisible(ghCheckDisableAll, TRUE); + gwinShow(ghPgCheckboxes); } else if (tab == ghTabLabels) { - gwinSetVisible(ghLabel1, TRUE); + gwinShow(ghPgLabels); } else if (tab == ghTabRadios) { - gwinSetVisible(ghRadio1, TRUE); - gwinSetVisible(ghRadio2, TRUE); - gwinSetVisible(ghRadioWhite, TRUE); - gwinSetVisible(ghRadioBlack, TRUE); - gwinSetVisible(ghRadioYellow, TRUE); + gwinShow(ghPgRadios); } else if (tab == ghTabLists) { - gwinSetVisible(ghList1, TRUE); - gwinSetVisible(ghList2, TRUE); - gwinSetVisible(ghList3, TRUE); - gwinSetVisible(ghList4, TRUE); + gwinShow(ghPgLists); } else if (tab == ghTabImages) { - gwinSetVisible(ghImage1, TRUE); + gwinShow(ghPgImages); } else if (tab == ghTabProgressbar) { - gwinSetVisible(ghProgressbar1, TRUE); + gwinShow(ghPgProgressbars); // Start the progress bar gwinProgressbarStart(ghProgressbar1, 500); @@ -350,29 +377,17 @@ static void setTab(GHandle tab) { * 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(ghPgButtons, ena); + gwinSetEnabled(ghPgSliders, ena); + gwinSetEnabled(ghPgLabels, ena); + gwinSetEnabled(ghPgRadios, ena); + gwinSetEnabled(ghPgLists, ena); + gwinSetEnabled(ghPgImages, ena); + gwinSetEnabled(ghPgProgressbars, 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(ghCheckDisableAll, TRUE); - gwinSetEnabled(ghLabel1, ena); - gwinSetEnabled(ghRadio1, ena); - gwinSetEnabled(ghRadio2, ena); - gwinSetEnabled(ghList1, ena); - gwinSetEnabled(ghList2, ena); - gwinSetEnabled(ghList3, ena); - gwinSetEnabled(ghList4, ena); - gwinSetEnabled(ghRadioWhite, ena); - gwinSetEnabled(ghRadioBlack, ena); - gwinSetEnabled(ghRadioYellow, ena); - gwinSetEnabled(ghImage1, ena); - gwinSetEnabled(ghProgressbar1, ena); } int main(void) { @@ -387,7 +402,8 @@ int main(void) { #endif // Set the widget defaults - gwinSetDefaultFont(gdispOpenFont("*")); + font = gdispOpenFont("*"); // Get the first defined font. + gwinSetDefaultFont(font); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); @@ -405,7 +421,7 @@ int main(void) { #endif // Make the console visible - gwinSetVisible(ghConsole, TRUE); + gwinShow(ghConsole); gwinClear(ghConsole); // We want to listen for widget events @@ -452,14 +468,26 @@ int main(void) { // Set control visibility depending on the tab selected setTab(((GEventGWinRadio *)pe)->radio); - // Do some special animation for Label1 to demonstrate auto width sizing + // We show the state of some of the GUI elements here if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { - gwinPrintf(ghConsole, "Change Label Text\n"); - gfxSleepMilliseconds(1000); - gwinSetText(ghLabel1, "Very Big Label", FALSE); - - gfxSleepMilliseconds(1000); - gwinSetText(ghLabel1, "Label", FALSE); + char tmp[20]; + + // The sliders + snprintf(tmp, sizeof(tmp), "%d%%", gwinSliderGetPosition(ghSlider1)); + gwinSetText(ghLabelSlider1, tmp, TRUE); + snprintf(tmp, sizeof(tmp), "%d%%", gwinSliderGetPosition(ghSlider2)); + gwinSetText(ghLabelSlider2, tmp, TRUE); + snprintf(tmp, sizeof(tmp), "%d%%", gwinSliderGetPosition(ghSlider3)); + gwinSetText(ghLabelSlider3, tmp, TRUE); + snprintf(tmp, sizeof(tmp), "%d%%", gwinSliderGetPosition(ghSlider4)); + gwinSetText(ghLabelSlider4, tmp, TRUE); + + // The radio buttons + if (gwinRadioIsPressed(ghRadio1)) { + gwinSetText(ghLabelRadio1, "Yes", TRUE); + } else if (gwinRadioIsPressed(ghRadio2)) { + gwinSetText(ghLabelRadio1, "No", TRUE); + } } break; @@ -480,11 +508,13 @@ int main(void) { #if GDISP_NEED_CLIP gdispUnsetClip(); #endif - gdispFillArea(0, 0, ScrWidth, ScrHeight/2, pstyle->background); - gdispFillArea(0, ScrHeight/2, ScrWidth/2, ScrHeight/2, pstyle->background); + gdispClear(pstyle->background); // Update the style on all controls gwinSetDefaultStyle(pstyle, TRUE); + + // Redraw the console too + //gwinRedraw(ghConsole); } break; } |