Skip to content

Commit

Permalink
directvt#571 WIP: Ignore DPI to be pixel perfect
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Apr 21, 2024
1 parent ab8c9c6 commit a3282cb
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/netxs/desktopio/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,29 @@ namespace netxs::gui
w32surface(w32surface const&) = default;
w32surface(w32surface&&) = default;
w32surface(gcfg context, HWND hWnd)
: hWnd{ hWnd },
: hdc{},
hWnd{ hWnd },
sync{ faux },
prev{ .coor = dot_mx, .size = dot_11 },
area{ .size = dot_11 },
size{ dot_11 },
prev{ .coor = dot_mx },
area{ dot_00, dot_00 },
size{ dot_00 },
refs{ 0 },
conf{ context },
surf{ nullptr }
{ }
void set_dpi(auto dpi)
{
if (S_OK == conf.pGdiInterop->CreateBitmapRenderTarget(NULL, size.x, size.y, &surf))
{
hdc = surf->GetMemoryDC();
}
else size = {};
auto pixelsPerDip = dpi / 96.f;
//surf->SetPixelsPerDip(pixelsPerDip);
log("DPI CHANGED ", pixelsPerDip);
}
void reset() // We are not using custom copy/move ctors.
{
if (surf) surf->Release();
}
auto canvas(bool wipe = faux)
{
if (area && hdc)
if (area)
{
if (area.size != size)
{
Expand All @@ -93,17 +94,21 @@ namespace netxs::gui
hdc = surf->GetMemoryDC();
wipe = faux;
size = area.size;
undo->Release();
if (undo) undo->Release();
surf->SetPixelsPerDip(1.f); // Ignore DPI to be pixel perfect.
}
else log("bitmap resizing error: ", utf::to_hex(hr));
}
sync = faux;
auto pv = BITMAP{};
if (sizeof(BITMAP) == ::GetObjectW(::GetCurrentObject(hdc, OBJ_BITMAP), sizeof(BITMAP), &pv))
if (hdc)
{
auto sz = (sz_t)size.x * size.y;
if (wipe) std::memset(pv.bmBits, 0, sz * sizeof(argb));
return bits{ std::span<argb>{ (argb*)pv.bmBits, sz }, rect{ area.coor, size }};
sync = faux;
auto pv = BITMAP{};
if (sizeof(BITMAP) == ::GetObjectW(::GetCurrentObject(hdc, OBJ_BITMAP), sizeof(BITMAP), &pv))
{
auto sz = (sz_t)size.x * size.y;
if (wipe) std::memset(pv.bmBits, 0, sz * sizeof(argb));
return bits{ std::span<argb>{ (argb*)pv.bmBits, sz }, rect{ area.coor, size }};
}
}
}
return bits{};
Expand Down Expand Up @@ -266,6 +271,7 @@ namespace netxs::gui
w32renderer()
: initialized{ faux }
{
auto old_dpi_ctx = ::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
//auto s = 96;//::GetDeviceCaps(hdc, LOGPIXELSY);
auto height = -16;//::MulDiv(24, s, 96);
auto hfont = ::CreateFontW(height, //_In_ int cHeight
Expand Down Expand Up @@ -365,6 +371,7 @@ namespace netxs::gui
case WM_SYSKEYDOWN: // WM_CHAR/WM_SYSCHAR and WM_DEADCHAR/WM_SYSDEADCHAR are derived messages after translation.
case WM_SYSKEYUP: w->keybd_press(wParam, lParam); break;
case WM_DESTROY: ::PostQuitMessage(0); break;
case WM_DPICHANGED: w->set_dpi(lo(wParam)); break;
//dx3d specific
case WM_PAINT: /*w->check_dx3d_state();*/ stat = ::DefWindowProcW(hWnd, msg, wParam, lParam); break;
default: stat = ::DefWindowProcW(hWnd, msg, wParam, lParam); break;
Expand Down Expand Up @@ -539,6 +546,11 @@ namespace netxs::gui
redraw();
initialized = true;
}
auto set_dpi(auto new_dpi)
{
for (auto& w : layers) w.set_dpi(new_dpi);
//tasks += task::all;
}
auto move_window(twod coor_delta)
{
layers[shadow].area.coor += coor_delta;
Expand Down

0 comments on commit a3282cb

Please sign in to comment.