diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gwin/button.c | 6 | ||||
-rw-r--r-- | src/gwin/checkbox.c | 6 | ||||
-rw-r--r-- | src/gwin/console.c | 6 | ||||
-rw-r--r-- | src/gwin/graph.c | 6 | ||||
-rw-r--r-- | src/gwin/gwidget.c | 8 | ||||
-rw-r--r-- | src/gwin/gwin.c | 54 | ||||
-rw-r--r-- | src/gwin/gwm.c | 6 | ||||
-rw-r--r-- | src/gwin/slider.c | 6 |
8 files changed, 55 insertions, 43 deletions
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; } |