Add wxIconEx
This simplifies loading DPI-aware icons. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
39
src/icon.cpp
Normal file
39
src/icon.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 2025 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
static wxSize GetDPIHelper(const wxWindowBase* w)
|
||||
{
|
||||
wxSize dpi;
|
||||
|
||||
if ( w )
|
||||
dpi = w->GetDPI();
|
||||
if ( !dpi.x || !dpi.y )
|
||||
dpi = wxDisplay().GetPPI();
|
||||
if ( !dpi.x || !dpi.y )
|
||||
dpi = wxDisplay::GetStdPPI();
|
||||
|
||||
return dpi;
|
||||
}
|
||||
|
||||
|
||||
wxIconEx::wxIconEx(const wxString& name,
|
||||
wxBitmapType type,
|
||||
int desiredWidth, int desiredHeight,
|
||||
wxWindowBase *window)
|
||||
{
|
||||
wxSize dpi = GetDPIHelper(window);
|
||||
wxSize baseline = wxDisplay::GetStdPPI();
|
||||
|
||||
if (desiredWidth != wxDefaultCoord)
|
||||
desiredWidth = wxMulDivInt32(desiredWidth, dpi.x, baseline.x);
|
||||
|
||||
if (desiredHeight != wxDefaultCoord)
|
||||
desiredHeight = wxMulDivInt32(desiredHeight, dpi.y, baseline.y);
|
||||
|
||||
LoadFile(name, type, desiredWidth, desiredHeight);
|
||||
SetScaleFactor((double)dpi.y / (double)baseline.y);
|
||||
}
|
||||
Reference in New Issue
Block a user