diff --git a/demos/modules/gwin/widgets/gfxconf.h b/demos/modules/gwin/widgets/gfxconf.h index 5c862441..fb83f860 100644 --- a/demos/modules/gwin/widgets/gfxconf.h +++ b/demos/modules/gwin/widgets/gfxconf.h @@ -73,7 +73,7 @@ /* Features for the GWIN sub-system. */ #define GWIN_NEED_WINDOWMANAGER TRUE #define GWIN_NEED_CONSOLE TRUE -#define GWIN_NEED_GRAPH FALSE +#define GWIN_NEED_GRAPH TRUE #define GWIN_NEED_WIDGET TRUE #define GWIN_NEED_BUTTON TRUE #define GWIN_NEED_SLIDER TRUE 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); + // Create the gwin windows/widgets + { + GWidgetInit wi; - // Color everything and set special drawing for some widgets - gwinSetColor(ghConsole, Yellow); - gwinSetBgColor(ghConsole, Black); - gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0); + wi.g.show = TRUE; - // 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); + // 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); diff --git a/include/gwin/button.h b/include/gwin/button.h index 21de74bd..a6b19333 100644 --- a/include/gwin/button.h +++ b/include/gwin/button.h @@ -70,26 +70,21 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gb The GButtonObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the top left corner of the window - * @param[in] width The width of the window - * @param[in] height The height of the window + * @param[in] pInit The initialisation parameters * * @note The drawing color and the background color get set to the current defaults. If you haven't called * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there * is no default font and text drawing operations will no nothing. - * @note The dimensions and position may be changed to fit on the real screen. * @note A button remembers its normal drawing state. If there is a window manager then it is automatically * redrawn if the window is moved or its visibility state is changed. - * @note The button is initially marked as invisible so that more properties can be set before display. - * Call @p gwinSetVisible() to display it when ready. * @note A button supports mouse and a toggle input. * @note When assigning a toggle, only one toggle is supported. If you try to assign more than one toggle it will * forget the previous toggle. When assigning a toggle the role parameter must be 0. * * @api */ -GHandle gwinCreateButton(GButtonObject *gb, coord_t x, coord_t y, coord_t width, coord_t height); +GHandle gwinCreateButton(GButtonObject *gb, GWidgetInit *pInit); /** * @brief Set the colors of a button. diff --git a/include/gwin/checkbox.h b/include/gwin/checkbox.h index 4a5e032a..9a19a2e1 100644 --- a/include/gwin/checkbox.h +++ b/include/gwin/checkbox.h @@ -59,26 +59,21 @@ typedef struct GCheckboxObject_t { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gb The GCheckboxObject structure to initialise. If this is NULL, the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the top left corner of the window - * @param[in] width The width of the window - * @param[in] height The height of the window + * @param[in] pInit The initialization parameters to use * * @note The drawing color and the background color get set to the current defaults. If you haven't called * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there * is no default font and text drawing operations will no nothing. - * @note The dimensions and position may be changed to fit on the real screen. * @note A checkbox remembers its normal drawing state. If there is a window manager then it is automatically * redrawn if the window is moved or its visibility state is changed. - * @note The checkbox is initially marked as invisible so that more properties can be set before display. - * Call @p gwinSetVisible() to display it when ready. * @note A checkbox supports mouse and a toggle input. * @note When assigning a toggle, only one toggle is supported. If you try to assign more than one toggle it will * forget the previous toggle. When assigning a toggle the role parameter must be 0. * * @api */ -GHandle gwinCreateCheckbox(GCheckboxObject *gb, coord_t x, coord_t y, coord_t width, coord_t height); +GHandle gwinCreateCheckbox(GCheckboxObject *gb, GWidgetInit *pInit); /** * @brief Get the state of a checkbox diff --git a/include/gwin/class_gwin.h b/include/gwin/class_gwin.h index eda69e1e..c3d2ee36 100644 --- a/include/gwin/class_gwin.h +++ b/include/gwin/class_gwin.h @@ -45,6 +45,7 @@ */ typedef struct gwinVMT { const char * classname; // @< The GWIN classname (mandatory) + size_t size; // @< The size of the class object void (*Destroy) (GWindowObject *gh); // @< The GWIN destroy function (optional) void (*Redraw) (GWindowObject *gh); // @< The GWIN redraw routine (optional) void (*AfterClear) (GWindowObject *gh); // @< The GWIN after-clear function (optional) @@ -116,7 +117,7 @@ typedef struct gwinVMT { typedef struct gwmVMT { void (*Init) (void); // @< The window manager has just been set as the current window manager void (*DeInit) (void); // @< The window manager has just been removed as the current window manager - bool_t (*Add) (GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h); // @< A window has been added + bool_t (*Add) (GHandle gh, GWindowInit *pInit); // @< A window has been added void (*Delete) (GHandle gh); // @< A window has been deleted void (*Visible) (GHandle gh); // @< A window has changed its visibility state void (*Redim) (GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h); // @< A window wants to be moved or resized @@ -139,15 +140,13 @@ extern "C" { * @brief Initialise (and allocate if necessary) the base GWIN object * * @param[in] pgw The GWindowObject structure. If NULL one is allocated from the heap - * @param[in] x, y The top left corner of the GWIN relative to the screen - * @param[in] w, h The width and height of the GWIN window - * @param[in] size The size of the GWIN object to allocate + * @param[in] pInit The user initialization parameters * @param[in] vmt The virtual method table for the GWIN object * @param[in] flags The default flags to use * * @notapi */ -GHandle _gwindowCreate(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwinVMT *vmt, uint16_t flags); +GHandle _gwindowCreate(GWindowObject *pgw, GWindowInit *pInit, const gwinVMT *vmt, uint16_t flags); #if GWIN_NEED_WIDGET || defined(__DOXYGEN__) /** @@ -161,7 +160,7 @@ GHandle _gwindowCreate(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coor * * @notapi */ - GHandle _gwidgetCreate(GWidgetObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwidgetVMT *vmt); + GHandle _gwidgetCreate(GWidgetObject *pgw, GWidgetInit *pInit, const gwidgetVMT *vmt); /** * @brief Destroy the Widget object diff --git a/include/gwin/console.h b/include/gwin/console.h index 5682113e..38c88f63 100644 --- a/include/gwin/console.h +++ b/include/gwin/console.h @@ -51,23 +51,20 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gc The GConsoleObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the top left corner of the window - * @param[in] width The width of the window - * @param[in] height The height of the window + * @param[in] pInit The initialization parameters to use * * @note The drawing color and the background color get set to the current defaults. If you haven't called * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there * is no default font and text drawing operations will no nothing. - * @note The dimensions and position may be changed to fit on the real screen. - * @note On creation the window is marked as visible but is not automatically cleared. You may do that by calling @p gwinClear() - * (possibly after changing your background color) + * @note On creation even if the window is visible it is not automatically cleared. + * You may do that by calling @p gwinClear() (possibly after changing your background color) * @note A console does not save the drawing state. It is not automatically redrawn if the window is moved or * its visibility state is changed. * * @api */ -GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height); +GHandle gwinCreateConsole(GConsoleObject *gc, GWindowInit *pInit); #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM /** diff --git a/include/gwin/graph.h b/include/gwin/graph.h index 2595d2e7..5e6abee1 100644 --- a/include/gwin/graph.h +++ b/include/gwin/graph.h @@ -91,17 +91,13 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gg The GGraphObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the top left corner of the window - * @param[in] width The width of the window - * @param[in] height The height of the window + * @param[in] pInit The initialization parameters to use * * @note The drawing color and the background color get set to the current defaults. If you haven't called * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there * is no default font and text drawing operations will no nothing. * @note The dimensions and position may be changed to fit on the real screen. - * @note On creation the window is marked as visible but is not automatically cleared. You may do that by calling @p gwinClear() - * (possibly after changing your background color) * @note A graph does not save the drawing state. It is not automatically redrawn if the window is moved or * its visibility state is changed. * @note The coordinate system within the window for graphing operations (but not for any other drawing @@ -111,7 +107,7 @@ extern "C" { * * @api */ -GHandle gwinCreateGraph(GGraphObject *gg, coord_t x, coord_t y, coord_t width, coord_t height); +GHandle gwinCreateGraph(GGraphObject *gg, GWindowInit *pInit); /** * @brief Set the style of the graphing operations. diff --git a/include/gwin/gwidget.h b/include/gwin/gwidget.h index 0c47dfde..50f19193 100644 --- a/include/gwin/gwidget.h +++ b/include/gwin/gwidget.h @@ -52,6 +52,22 @@ typedef struct GWidgetObject { } GWidgetObject; /* @} */ +/** + * @brief The structure to initialise a widget. + * + * @note Some widgets may have extra parameters. + * @note The text element must be static string (not stack allocated). If you want to use + * a dynamic string (eg a stack allocated string) use NULL for this member and then call + * @p gwinSetText() with useAlloc set to TRUE. + * + * @{ + */ +typedef struct GWidgetInit { + GWindowInit g; // @< The GWIN initializer + const char * text; // @< The initial text +} GWidgetInit; +/* @} */ + /** * A comment/rant on the above structure: * We would really like the GWindowObject member to be anonymous. While this is diff --git a/include/gwin/gwin.h b/include/gwin/gwin.h index efce49fc..2a03c125 100644 --- a/include/gwin/gwin.h +++ b/include/gwin/gwin.h @@ -49,6 +49,21 @@ typedef struct GWindowObject { } GWindowObject, * GHandle; /* @} */ +/** + * @brief The structure to initialise a GWIN. + * + * @note Some gwin's will need extra parameters. + * @note The dimensions and position may be changed to fit on the real screen. + * + * @{ + */ +typedef struct GWindowInit { + coord_t x, y; // @< The initial screen position + coord_t width, height; // @< The initial dimension + bool_t show; // @< Should the window be visible initially +} GWindowInit; +/* @} */ + /** * @brief A window's minimized, maximized or normal size */ @@ -128,22 +143,18 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] pgw The window structure to initialize. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen coordinates for the top left corner of the window - * @param[in] width The width of the window - * @param[in] height The height of the window + * @param[in] pInit How to initialise the window * * @note The drawing color and the background color get set to the current defaults. If you haven't called * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there * is no default font and text drawing operations will no nothing. - * @note The dimensions and position may be changed to fit on the real screen. - * @note On creation the window is marked as visible. * @note A basic window does not save the drawing state. It is not automatically redrawn if the window is moved or * its visibility state is changed. * * @api */ - GHandle gwinCreateWindow(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height); + GHandle gwinCreateWindow(GWindowObject *pgw, GWindowInit *pInit); /** * @brief Destroy a window (of any type). Releases any dynamically allocated memory. diff --git a/include/gwin/slider.h b/include/gwin/slider.h index 9baecbb1..4479950f 100644 --- a/include/gwin/slider.h +++ b/include/gwin/slider.h @@ -64,19 +64,14 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gb The GSliderObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the top left corner of the window - * @param[in] width The width of the window - * @param[in] height The height of the window + * @param[in] pInit The initialization parameters to use * * @note The drawing color and the background color get set to the current defaults. If you haven't called * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there * is no default font and text drawing operations will no nothing. - * @note The dimensions and position may be changed to fit on the real screen. * @note A slider remembers its normal drawing state. If there is a window manager then it is automatically * redrawn if the window is moved or its visibility state is changed. - * @note The slider is initially marked as invisible so that more properties can be set before display. - * Call @p gwinSetVisible() to display it when ready. * @note The initial slider range is from 0 to 100 with an initial position of 0. * @note A slider supports mouse, toggle and dial input. * @note When assigning a toggle, only one toggle is supported per role. If you try to assign more than @@ -87,7 +82,7 @@ extern "C" { * * @api */ -GHandle gwinCreateSlider(GSliderObject *gb, coord_t x, coord_t y, coord_t width, coord_t height); +GHandle gwinCreateSlider(GSliderObject *gb, GWidgetInit *pInit); /** * @brief Set the slider range. diff --git a/src/gwin/button.c b/src/gwin/button.c index fc432cb4..4f823aa6 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -41,6 +41,7 @@ static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role); static const gwidgetVMT buttonVMT = { { "Button", // The classname + sizeof(GButtonObject), // The object size _gwidgetDestroy, // The destroy routine _gwidgetRedraw, // The redraw routine 0, // The after-clear routine @@ -150,14 +151,15 @@ static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) { return ((GButtonObject *)gw)->toggle; } -GHandle gwinCreateButton(GButtonObject *gw, coord_t x, coord_t y, coord_t width, coord_t height) { - if (!(gw = (GButtonObject *)_gwidgetCreate((GWidgetObject *)gw, x, y, width, height, sizeof(GButtonObject), &buttonVMT))) +GHandle gwinCreateButton(GButtonObject *gw, GWidgetInit *pInit) { + if (!(gw = (GButtonObject *)_gwidgetCreate(&gw->w, pInit, &buttonVMT))) return 0; gw->toggle = GWIDGET_NO_INSTANCE; gw->c_up = GButtonDefaultColorsUp; gw->c_dn = GButtonDefaultColorsDown; gw->c_dis = GButtonDefaultColorsDisabled; + gwinSetVisible((GHandle)gw, pInit->g.show); return (GHandle)gw; } diff --git a/src/gwin/checkbox.c b/src/gwin/checkbox.c index 0282df42..b4628ae0 100644 --- a/src/gwin/checkbox.c +++ b/src/gwin/checkbox.c @@ -34,6 +34,7 @@ static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role); static const gwidgetVMT checkboxVMT = { { "Checkbox", // The classname + sizeof(GCheckboxObject),// The object size _gwidgetDestroy, // The destroy routine _gwidgetRedraw, // The redraw routine 0, // The after-clear routine @@ -112,12 +113,13 @@ static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) { return ((GCheckboxObject *)gw)->toggle; } -GHandle gwinCreateCheckbox(GCheckboxObject *gb, coord_t x, coord_t y, coord_t width, coord_t height) { - if (!(gb = (GCheckboxObject *)_gwidgetCreate((GWidgetObject *)gb, x, y, width, height, sizeof(GCheckboxObject), &checkboxVMT))) +GHandle gwinCreateCheckbox(GCheckboxObject *gb, GWidgetInit *pInit) { + if (!(gb = (GCheckboxObject *)_gwidgetCreate(&gb->w, pInit, &checkboxVMT))) return 0; gb->toggle = (uint16_t) -1; gb->c = defaultColors; // assign the default colors + gwinSetVisible((GHandle)gb, pInit->g.show); return (GHandle)gb; } diff --git a/src/gwin/console.c b/src/gwin/console.c index 38e2ea8b..39e534b4 100644 --- a/src/gwin/console.c +++ b/src/gwin/console.c @@ -60,19 +60,21 @@ static void AfterClear(GWindowObject *gh) { static const gwinVMT consoleVMT = { "Console", // The classname + sizeof(GConsoleObject), // The object size 0, // The destroy routine 0, // The redraw routine AfterClear, // The after-clear routine }; -GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height) { - if (!(gc = (GConsoleObject *)_gwindowCreate((GWindowObject *)gc, x, y, width, height, sizeof(GConsoleObject), &consoleVMT, GWIN_FLG_VISIBLE))) +GHandle gwinCreateConsole(GConsoleObject *gc, GWindowInit *pInit) { + if (!(gc = (GConsoleObject *)_gwindowCreate(&gc->g, pInit, &consoleVMT, 0))) return 0; #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM gc->stream.vmt = &GWindowConsoleVMT; #endif gc->cx = 0; gc->cy = 0; + gwinSetVisible((GHandle)gc, pInit->show); return (GHandle)gc; } diff --git a/src/gwin/graph.c b/src/gwin/graph.c index 708b90cb..81ce1b5f 100644 --- a/src/gwin/graph.c +++ b/src/gwin/graph.c @@ -31,6 +31,7 @@ static const GGraphStyle GGraphDefaultStyle = { static const gwinVMT graphVMT = { "Graph", // The classname + sizeof(GGraphObject), // The object size 0, // The destroy routine 0, // The redraw routine 0, // The after-clear routine @@ -164,12 +165,13 @@ static void lineto(GGraphObject *gg, coord_t x0, coord_t y0, coord_t x1, coord_t } } -GHandle gwinCreateGraph(GGraphObject *gg, coord_t x, coord_t y, coord_t width, coord_t height) { - if (!(gg = (GGraphObject *)_gwindowCreate((GWindowObject *)gg, x, y, width, height, sizeof(GGraphObject), &graphVMT, GWIN_FLG_VISIBLE))) +GHandle gwinCreateGraph(GGraphObject *gg, GWindowInit *pInit) { + if (!(gg = (GGraphObject *)_gwindowCreate(&gg->g, pInit, &graphVMT, 0))) return 0; gg->xorigin = gg->yorigin = 0; gg->lastx = gg->lasty = 0; gwinGraphSetStyle((GHandle)gg, &GGraphDefaultStyle); + gwinSetVisible((GHandle)gg, pInit->show); return (GHandle)gg; } diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 9d634c58..2825bf4c 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -165,15 +165,15 @@ void _gwidgetInit(void) { geventRegisterCallback(&gl, gwidgetEvent, 0); } -GHandle _gwidgetCreate(GWidgetObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height, size_t size, const gwidgetVMT *vmt) { - if (!(pgw = (GWidgetObject *)_gwindowCreate((GWindowObject *)pgw, x, y, width, height, size, (const gwinVMT *)vmt, GWIN_FLG_WIDGET|GWIN_FLG_ENABLED))) +GHandle _gwidgetCreate(GWidgetObject *pgw, GWidgetInit *pInit, const gwidgetVMT *vmt) { + if (!(pgw = (GWidgetObject *)_gwindowCreate(&pgw->g, &pInit->g, &vmt->g, GWIN_FLG_WIDGET|GWIN_FLG_ENABLED))) return 0; - pgw->txt = ""; + pgw->txt = pInit->text ? pInit->text : ""; pgw->fnDraw = vmt->DefaultDraw; pgw->fnParam = 0; - return (GHandle)pgw; + return &pgw->g; } void _gwidgetDestroy(GHandle gh) { diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index b918d297..110d35cc 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -21,6 +21,7 @@ static const gwinVMT basegwinVMT = { "GWIN", // The classname + sizeof(GWindowObject), // The object size 0, // The destroy routine 0, // The redraw routine 0, // The after-clear routine @@ -51,17 +52,17 @@ static color_t defaultBgColor = Black; } else gwinClear(gh); } - static void _gwm_redim(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h) { - if (x < 0) { w += x; x = 0; } - if (y < 0) { h += y; y = 0; } - if (x > gdispGetWidth()-MIN_WIN_WIDTH) x = gdispGetWidth()-MIN_WIN_WIDTH; - if (y > gdispGetHeight()-MIN_WIN_HEIGHT) y = gdispGetHeight()-MIN_WIN_HEIGHT; - if (w < MIN_WIN_WIDTH) { w = MIN_WIN_WIDTH; } - if (h < MIN_WIN_HEIGHT) { h = MIN_WIN_HEIGHT; } - if (x+w > gdispGetWidth()) w = gdispGetWidth() - x; - if (y+h > gdispGetHeight()) h = gdispGetHeight() - y; - gh->x = x; gh->y = y; - gh->width = w; gh->height = h; + static void _gwm_redim(GHandle gh, GWindowInit *pInit) { + gh->x = pInit->x; gh->y = pInit->y; + gh->width = pInit->width; gh->height = pInit->height; + if (gh->x < 0) { gh->width += gh->x; gh->x = 0; } + if (gh->y < 0) { gh->height += gh->y; gh->y = 0; } + if (gh->x > gdispGetWidth()-MIN_WIN_WIDTH) gh->x = gdispGetWidth()-MIN_WIN_WIDTH; + if (gh->y > gdispGetHeight()-MIN_WIN_HEIGHT) gh->y = gdispGetHeight()-MIN_WIN_HEIGHT; + if (gh->width < MIN_WIN_WIDTH) { gh->width = MIN_WIN_WIDTH; } + if (gh->height < MIN_WIN_HEIGHT) { gh->height = MIN_WIN_HEIGHT; } + if (gh->x+gh->width > gdispGetWidth()) gh->width = gdispGetWidth() - gh->x; + if (gh->y+gh->height > gdispGetHeight()) gh->height = gdispGetHeight() - gh->y; } #endif @@ -84,10 +85,10 @@ void _gwinInit(void) { // Internal routine for use by GWIN components only // Initialise a window creating it dynamically if required. -GHandle _gwindowCreate(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height, size_t size, const gwinVMT *vmt, uint16_t flags) { +GHandle _gwindowCreate(GWindowObject *pgw, GWindowInit *pInit, const gwinVMT *vmt, uint16_t flags) { // Allocate the structure if necessary if (!pgw) { - if (!(pgw = (GWindowObject *)gfxAlloc(size))) + if (!(pgw = (GWindowObject *)gfxAlloc(vmt->size))) return 0; pgw->flags = flags|GWIN_FLG_DYNAMIC; } else @@ -101,17 +102,15 @@ GHandle _gwindowCreate(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, pgw->font = defaultFont; #endif - #if GWIN_NEED_WINDOWMANAGER - if (!cwm->vmt->Add(pgw, x, y, width, height)) { - if ((pgw->flags & GWIN_FLG_DYNAMIC)) - gfxFree(pgw); - return 0; - } - #else - _gwm_redim(pgw, x, y, width, height); - if ((pgw->flags & GWIN_FLG_VISIBLE)) - _gwm_vis(pgw); - #endif +#if GWIN_NEED_WINDOWMANAGER + if (!cwm->vmt->Add(pgw, pInit)) { + if ((pgw->flags & GWIN_FLG_DYNAMIC)) + gfxFree(pgw); + return 0; + } +#else + _gwm_redim(pgw, pInit->x, pInit->y, pInit->width, pInit->height); +#endif return (GHandle)pgw; } @@ -150,8 +149,11 @@ void gwinSetDefaultBgColor(color_t bgclr) { * The GWindow Routines *-----------------------------------------------*/ -GHandle gwinCreateWindow(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height) { - return _gwindowCreate(pgw, x, y, width, height, sizeof(GWindowObject), &basegwinVMT, GWIN_FLG_VISIBLE); +GHandle gwinCreateWindow(GWindowObject *pgw, GWindowInit *pInit) { + if (!(pgw = _gwindowCreate(pgw, pInit, &basegwinVMT, 0))) + return 0; + gwinSetVisible(pgw, pInit->show); + return pgw; } void gwinDestroy(GHandle gh) { diff --git a/src/gwin/gwm.c b/src/gwin/gwm.c index 5a533c40..c3405d83 100644 --- a/src/gwin/gwm.c +++ b/src/gwin/gwm.c @@ -25,7 +25,7 @@ static void WM_Init(void); static void WM_DeInit(void); -static bool_t WM_Add(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h); +static bool_t WM_Add(GHandle gh, GWindowInit *pInit); static void WM_Delete(GHandle gh); static void WM_Visible(GHandle gh); static void WM_Redim(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h); @@ -65,12 +65,12 @@ static void WM_DeInit(void) { // A full window manager would remove any borders etc } -static bool_t WM_Add(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h) { +static bool_t WM_Add(GHandle gh, GWindowInit *pInit) { // Put it on the queue gfxQueueASyncPut(&_GWINList, &gh->wmq); // Make sure the size is valid - WM_Redim(gh, x, y, w, h); + WM_Redim(gh, pInit->x, pInit->y, pInit->width, pInit->height); // Display it if it is visible WM_Visible(gh); diff --git a/src/gwin/slider.c b/src/gwin/slider.c index f2052524..08dd6ca7 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -43,6 +43,7 @@ static uint16_t DialGet(GWidgetObject *gw, uint16_t role); static const gwidgetVMT sliderVMT = { { "Slider", // The classname + sizeof(GSliderObject), // The object size _gwidgetDestroy, // The destroy routine _gwidgetRedraw, // The redraw routine 0, // The after-clear routine @@ -232,8 +233,8 @@ static uint16_t DialGet(GWidgetObject *gw, uint16_t role) { return ((GSliderObject *)gw)->dial; } -GHandle gwinCreateSlider(GSliderObject *gs, coord_t x, coord_t y, coord_t width, coord_t height) { - if (!(gs = (GSliderObject *)_gwidgetCreate((GWidgetObject *)gs, x, y, width, height, sizeof(GSliderObject), &sliderVMT))) +GHandle gwinCreateSlider(GSliderObject *gs, GWidgetInit *pInit) { + if (!(gs = (GSliderObject *)_gwidgetCreate(&gs->w, pInit, &sliderVMT))) return 0; gs->t_dn = (uint16_t) -1; gs->t_up = (uint16_t) -1; @@ -243,6 +244,7 @@ GHandle gwinCreateSlider(GSliderObject *gs, coord_t x, coord_t y, coord_t width, gs->max = 100; gs->pos = 0; ResetDisplayPos(gs); + gwinSetVisible((GHandle)gs, pInit->g.show); return (GHandle)gs; }