Implemented the other areautil.c functions.

This commit is contained in:
Pietro Gagliardi 2015-12-18 21:38:27 -05:00
parent 5e90cbcb93
commit adc72c9d0b
4 changed files with 40 additions and 21 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;
}