From 28560e8721d379b037e57e4fc28e5a687901537e Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 31 Aug 2022 18:42:04 -0500 Subject: [PATCH] Slight optimization to window surface creation. --- roo-e/src/gui/widgets/scroll.c | 8 +++----- roo-e/src/gui/wmwindow.c | 18 ++++++------------ roo-e/src/gui/wmwindow.h | 8 -------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/roo-e/src/gui/widgets/scroll.c b/roo-e/src/gui/widgets/scroll.c index 195a390..9b742b8 100644 --- a/roo-e/src/gui/widgets/scroll.c +++ b/roo-e/src/gui/widgets/scroll.c @@ -66,8 +66,6 @@ ScrollableT *scrollableCreate(int16_t visibleWidth, int16_t visibleHeight, int16 s->original.x = visibleWidth; s->original.y = visibleHeight; - logWrite("scrollableCreate: %dx%d\n", s->original.x, s->original.y); - // Set up desired scroll bars. s->flags = flags; if (s->flags & SCROLLABLE_SCROLL_V) { @@ -119,8 +117,8 @@ static void scrollableFixupSizes(ScrollableT *s) { s->position.x = s->original.x - s->scrollv->base.r.w + 1; // Make scroll area smaller to make room for scrollbar. s->base.r.w = s->original.x - s->scrollv->base.r.w; - // Resize vertical scrollbar. - vscrollHeightSet(s->scrollv, s->original.y - (s->scrollh ? s->scrollh->base.r.h - 1 : 0)); + // Resize vertical scrollbar. + vscrollHeightSet(s->scrollv, s->original.y + 1); // Not quite sure why this is off by one. // Position vertical scrollbar. widgetMove(W(s->scrollv), s->base.r.x + s->position.x, s->base.r.y); } else { @@ -134,7 +132,7 @@ static void scrollableFixupSizes(ScrollableT *s) { s->position.y = s->original.y - s->scrollh->base.r.h + 1; // Make scroll area smaller to make room for scrollbar. s->base.r.h = s->original.y - s->scrollh->base.r.h; - // Resize horizontal scrollbar. + // Resize horizontal scrollbar. Take vertical scrollbar into account. hscrollWidthSet(s->scrollh, s->original.x - (s->scrollv ? s->scrollv->base.r.w - 1: 0)); // Position horizontal scrollbar. widgetMove(W(s->scrollh), s->base.r.x, s->base.r.y + s->position.y); diff --git a/roo-e/src/gui/wmwindow.c b/roo-e/src/gui/wmwindow.c index a1585cc..1a255b6 100644 --- a/roo-e/src/gui/wmwindow.c +++ b/roo-e/src/gui/wmwindow.c @@ -59,18 +59,16 @@ static void windowCache(WindowT *w, uint8_t redrawWindow) { ColorT gadgetColor; SurfaceT *target = surfaceGet(); - // Do we have a cached surface already? + // Do we have a cached surface already? ***TODO*** Maybe allocate maximum size right at the start? if (w->cached) { - // Did the size change? - if ((surfaceWidthGet(w->cached) != w->base.r.w) || (surfaceHeightGet(w->cached) != w->base.r.h)) { + // Did the size grow? + if ((surfaceWidthGet(w->cached) < w->base.r.w) || (surfaceHeightGet(w->cached) < w->base.r.h)) { // Yeah. We will recreate it. surfaceDestroy(&w->cached); } } // Do we need to create a surface? - if (!w->cached) { - w->cached = surfaceCreate(w->base.r.w, w->base.r.h); - } + if (!w->cached) w->cached = surfaceCreate(w->base.r.w, w->base.r.h); // Draw into cache. surfaceSet(w->cached); @@ -249,8 +247,6 @@ WindowT *windowCreate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, char *titl win->title = strdup(title); win->flags = (uint8_t)flags; - logWrite("windowCreate: %dx%d\n", win->base.r.w, win->base.r.h); - // Cache the window so we get valid bounds values. windowCache(win, 1); visibleSize.x = win->bounds.x2 - win->bounds.x + 1; @@ -538,7 +534,7 @@ static void windowPaint(struct WidgetS *widget, ...) { _iconCount++; } else { // By now we have a valid cached window. Blit it. - surfaceBlit(w->base.r.x, w->base.r.y, 0, 0, 0, 0, w->cached); + surfaceBlit(w->base.r.x, w->base.r.y, 0, 0, w->base.r.w, w->base.r.h, w->cached); } } @@ -571,7 +567,7 @@ void windowResize(WindowT *win, uint16_t width, uint16_t height) { chrome.y = win->base.r.h - (win->bounds.y2 - win->bounds.y) + 1; // Too small? - if (width < (GADGET_SIZE * 4) + chrome.x) width = (GADGET_SIZE * 4) + chrome.x; + if (width < (GADGET_SIZE * 5) + chrome.x) width = (GADGET_SIZE * 5) + chrome.x; if (height < (GADGET_SIZE * 4) + chrome.y) height = (GADGET_SIZE * 4) + chrome.y; // Too big? Horizontal. @@ -590,8 +586,6 @@ void windowResize(WindowT *win, uint16_t width, uint16_t height) { y = scrollableValueVGet(win->scroll); // Height of content area of window. content = win->bounds.y2 - win->bounds.y + 1; - // Do we need to take the height of the horizontal scroll bar into account? - if (win->scroll->scrollh) content -= win->scroll->scrollh->base.r.h; // Clamp. y = win->base.r.h - content + surfaceHeightGet(win->scroll->area); if (height > y) height = y; diff --git a/roo-e/src/gui/wmwindow.h b/roo-e/src/gui/wmwindow.h index 45da53e..30f62bc 100644 --- a/roo-e/src/gui/wmwindow.h +++ b/roo-e/src/gui/wmwindow.h @@ -63,14 +63,6 @@ typedef struct WindowS { RectWT restore; // Size of window if they restore from maximized. PointT restoreOffset; // Scroll position if they restore from maximized. RectT bounds; // Inside edge of window frame. - /* - RectT scrollv; // Vertical scroll bar. - RectT scrollh; // Horizontal scroll bar. - RectT thumbv; // Vertical scroll bar thumb. - RectT thumbh; // Horizontal scroll bar thumb. - PointT offset; // Content scroll offset in window. - SurfaceT *content; // Actual window contents - widgets and such. - */ SurfaceT *cached; // Once rendered, keep a cached copy for faster redrawing. } WindowT;