libui/windows: some work on hiDPI shit

still looks derpy but atleast the rendering and touchscreen aren't broken
This commit is contained in:
StapleButter 2018-12-21 05:01:37 +01:00
parent f86fe46035
commit 63ae6bf8fb
6 changed files with 27 additions and 3 deletions

View File

@ -26,12 +26,14 @@
<Add library="advapi32" />
<Add library="wsock32" />
<Add library="oleacc" />
<Add library="ole32" />
<Add library="usp10" />
<Add library="gdi32" />
<Add library="d2d1" />
<Add library="dwrite" />
<Add library="uxtheme" />
<Add library="ole32" />
<Add library="iphlpapi" />
<Add library="user32" />
</Linker>
</Target>
<Target title="Release Windows">
@ -61,6 +63,8 @@
<Add library="d2d1" />
<Add library="dwrite" />
<Add library="uxtheme" />
<Add library="iphlpapi" />
<Add library="user32" />
</Linker>
</Target>
<Target title="DebugFast Windows">
@ -89,6 +93,8 @@
<Add library="d2d1" />
<Add library="dwrite" />
<Add library="uxtheme" />
<Add library="iphlpapi" />
<Add library="user32" />
</Linker>
</Target>
</Build>

View File

@ -26,6 +26,16 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)
rt->BeginDraw();
{
float dpi_x, dpi_y;
D2D1_MATRIX_3X2_F dm;
rt->GetDpi(&dpi_x, &dpi_y);
ZeroMemory(&dm, sizeof (D2D1_MATRIX_3X2_F));
dm._11 = 96.f/dpi_x;
dm._22 = 96.f/dpi_y;
rt->SetTransform(&dm);
}
if (a->scrolling) {
ZeroMemory(&scrollTransform, sizeof (D2D1_MATRIX_3X2_F));
scrollTransform._11 = 1;

View File

@ -101,7 +101,7 @@ static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM l
xpix = (double) GET_X_LPARAM(lParam);
ypix = (double) GET_Y_LPARAM(lParam);
// these are in pixels; we need points
pixelsToDIP(a, &xpix, &ypix);
//pixelsToDIP(a, &xpix, &ypix);
me.X = xpix;
me.Y = ypix;
if (a->scrolling) {

View File

@ -14,6 +14,7 @@ void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *heigh
size = realGetSize(rt);
*width = size.width;
*height = size.height;
dipToPixels(a, width, height);
}
}

View File

@ -560,6 +560,13 @@ void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRe
D2D_RECT_F _srcrect = D2D1::RectF(srcrect->X, srcrect->Y, srcrect->X+srcrect->Width, srcrect->Y+srcrect->Height);
D2D_RECT_F _dstrect = D2D1::RectF(dstrect->X, dstrect->Y, dstrect->X+dstrect->Width, dstrect->Y+dstrect->Height);
float dpix, dpiy;
c->rt->GetDpi(&dpix, &dpiy);
_srcrect.left = (_srcrect.left * 96.0f) / dpix;
_srcrect.top = (_srcrect.top * 96.0f) / dpiy;
_srcrect.right = (_srcrect.right * 96.0f) / dpix;
_srcrect.bottom = (_srcrect.bottom * 96.0f) / dpiy;
c->rt->DrawBitmap(bmp->bmp, &_dstrect, 1.0f, filter ? D2D1_BITMAP_INTERPOLATION_MODE_LINEAR : D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &_srcrect);
}

View File

@ -70,7 +70,7 @@ const char *uiInit(uiInitOptions *o)
if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
nCmdShow = si.wShowWindow;
// LONGTERM set DPI awareness
SetProcessDPIAware();
hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION);
if (hDefaultIcon == NULL)