diff --git a/windows/area.c b/windows/area.c index e0fed706..a2d4ff17 100644 --- a/windows/area.c +++ b/windows/area.c @@ -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; } diff --git a/windows/area.h b/windows/area.h index f60bf06f..35966989 100644 --- a/windows/area.h +++ b/windows/area.h @@ -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 diff --git a/windows/areadraw.c b/windows/areadraw.c index 93b4555f..4b05caa1 100644 --- a/windows/areadraw.c +++ b/windows/areadraw.c @@ -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); } diff --git a/windows/areascroll.c b/windows/areascroll.c index ed058e2b..799b2707 100644 --- a/windows/areascroll.c +++ b/windows/areascroll.c @@ -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) {