Slight optimization to window surface creation.
This commit is contained in:
parent
80802fe53a
commit
28560e8721
3 changed files with 9 additions and 25 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue