diff --git a/windows/area.h b/windows/area.h index 73ea30c6..f60bf06f 100644 --- a/windows/area.h +++ b/windows/area.h @@ -41,3 +41,6 @@ extern void unregisterAreaFilter(void); // areautil.c extern void renderTargetGetSize(ID2D1RenderTarget *rt, D2D1_SIZE_F *size); +extern void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height); +extern void pixelsToDIP(uiArea *a, double *x, double *y); +extern void dipToPixels(uiArea *a, double *x, double *y); diff --git a/windows/areadraw.c b/windows/areadraw.c index a6cd3ac8..95c3cbf0 100644 --- a/windows/areadraw.c +++ b/windows/areadraw.c @@ -8,17 +8,10 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip) uiAreaDrawParams dp; COLORREF bgcolorref; D2D1_COLOR_F bgcolor; - D2D1_SIZE_F size; dp.Context = newContext(rt); - dp.AreaWidth = 0; - dp.AreaHeight = 0; - if (!a->scrolling) { - renderTargetGetSize(rt, &size); - dp.AreaWidth = size.width; - dp.AreaHeight = size.height; - } + loadAreaSize(a, rt, &(dp.AreaWidth), &(dp.AreaHeight)); dp.ClipX = clip->left; dp.ClipY = clip->top; diff --git a/windows/areaevents.c b/windows/areaevents.c index a61b25fe..5af03e32 100644 --- a/windows/areaevents.c +++ b/windows/areaevents.c @@ -81,8 +81,6 @@ static void areaMouseEvent(uiArea *a, uintmax_t down, uintmax_t up, WPARAM wPar RECT client; BOOL inClient; double xpix, ypix; - FLOAT dpix, dpiy; - D2D1_SIZE_F size; if (a->capturing) { clientpt.x = GET_X_LPARAM(lParam); @@ -104,18 +102,9 @@ static void areaMouseEvent(uiArea *a, uintmax_t down, uintmax_t up, WPARAM wPar xpix = (double) GET_X_LPARAM(lParam); ypix = (double) GET_Y_LPARAM(lParam); // these are in pixels; we need points - ID2D1HwndRenderTarget_GetDpi(a->rt, &dpix, &dpiy); - // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd756649%28v=vs.85%29.aspx (and others; search "direct2d mouse") - me.X = (xpix * 96) / dpix; - me.Y = (ypix * 96) / dpiy; + pixelsToDIP(a, &xpix, &ypix); - me.AreaWidth = 0; - me.AreaHeight = 0; - if (!a->scrolling) { - renderTargetGetSize((ID2D1RenderTarget *) (a->rt), &size); - me.AreaWidth = size.width; - me.AreaHeight = size.height; - } + loadAreaSize(a, NULL, &(me.AreaWidth), &(me.AreaHeight)); me.Down = down; me.Up = up; diff --git a/windows/areautil.c b/windows/areautil.c index f1b9377c..3373fc0c 100644 --- a/windows/areautil.c +++ b/windows/areautil.c @@ -17,3 +17,37 @@ void renderTargetGetSize(ID2D1RenderTarget *rt, D2D1_SIZE_F *size) f = (fptr) (rt->lpVtbl->GetSize); (*f)(rt, size); } + +void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height) +{ + D2D1_SIZE_F size; + + *width = 0; + *height = 0; + if (!a->scrolling) { + if (rt == NULL) + rt = (ID2D1RenderTarget *) (a->rt); + renderTargetGetSize(rt, &size); + *width = size.width; + *height = size.height; + } +} + +void pixelsToDIP(uiArea *a, double *x, double *y) +{ + FLOAT dpix, dpiy; + + ID2D1HwndRenderTarget_GetDpi(a->rt, &dpix, &dpiy); + // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd756649%28v=vs.85%29.aspx (and others; search "direct2d mouse") + *x = (*x * 96) / dpix; + *y = (*y * 96) / dpiy; +} + +void dipToPixels(uiArea *a, double *x, double *y) +{ + FLOAT dpix, dpiy; + + ID2D1HwndRenderTarget_GetDpi(a->rt, &dpix, &dpiy); + *x = (*x * dpix) / 96; + *y = (*y * dpiy) / 96; +}