Implemented redrawing on scrolling and adjusting scrolling on resizing and actually implemented scrolled drawing correctly on uiArea on Windows.

This commit is contained in:
Pietro Gagliardi 2015-12-19 14:43:34 -05:00
parent a922551b78
commit af374ed859
4 changed files with 13 additions and 17 deletions

View File

@ -40,6 +40,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
if (GetClientRect(a->hwnd, &client) == 0)
logLastError("error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling in areaWndProc()");
areaDrawOnResize(a, &client);
areaScrollOnResize(a, &client);
return 0;
}

View File

@ -33,6 +33,7 @@ extern void areaDrawOnResize(uiArea *, RECT *);
// areascroll.c
extern BOOL areaDoScroll(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult);
extern void areaScrollOnResize(uiArea *, RECT *);
extern void areaUpdateScroll(uiArea *a);
// areaevents.c

View File

@ -30,8 +30,9 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)
ZeroMemory(&scrollTransform, sizeof (D2D1_MATRIX_3X2_F));
scrollTransform._11 = 1;
scrollTransform._22 = 1;
scrollTransform._31 = a->hscrollpos;
scrollTransform._32 = a->vscrollpos;
// negative because we want nonzero scroll positions to move the drawing area up/left
scrollTransform._31 = -a->hscrollpos;
scrollTransform._32 = -a->vscrollpos;
ID2D1RenderTarget_SetTransform(rt, &scrollTransform);
}

View File

@ -22,7 +22,6 @@ struct scrollParams {
static void scrollto(uiArea *a, int which, struct scrollParams *p, intmax_t pos)
{
SCROLLINFO si;
intmax_t xamount, yamount;
// note that the pos < 0 check is /after/ the p->length - p->pagesize check
// it used to be /before/; this was actually a bug in Raymond Chen's original algorithm: if there are fewer than a page's worth of items, p->length - p->pagesize will be negative and our content draw at the bottom of the window
@ -32,19 +31,10 @@ static void scrollto(uiArea *a, int which, struct scrollParams *p, intmax_t pos)
if (pos < 0)
pos = 0;
// negative because ScrollWindowEx() is "backwards"
xamount = -(pos - *(p->pos));
yamount = 0;
if (which == SB_VERT) {
yamount = xamount;
xamount = 0;
}
// TODO this isn't safe with Direct2D
// if (ScrollWindowEx(a->hwnd, xamount, yamount,
// NULL, NULL, NULL, NULL,
// SW_ERASE | SW_INVALIDATE) == ERROR)
// logLastError("error scrolling area in scrollto()");
// Direct2D doesn't have a method for scrolling the existing contents of a render target.
// We'll have to just invalidate everything and hope for the best.
if (InvalidateRect(a->hwnd, NULL, FALSE) == 0)
logLastError("error invalidating uiArea after scrolling in scrollto()");
*(p->pos) = pos;
@ -247,7 +237,10 @@ BOOL areaDoScroll(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *l
return FALSE;
}
// TODO do we need an areaScrollOnResize()?
void areaScrollOnResize(uiArea *a, RECT *client)
{
areaUpdateScroll(a);
}
void areaUpdateScroll(uiArea *a)
{