Add wxIconEx

This simplifies loading DPI-aware icons.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman
2025-11-04 15:48:19 +01:00
parent 79ec083650
commit fd16ef2909
6 changed files with 197 additions and 116 deletions

39
src/icon.cpp Normal file
View 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);
}

View File

@@ -1,34 +1,35 @@
/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 2015-2022 Amebis
Copyright © 2016 GÉANT
*/
#pragma once
// Since including <wx/app.h> introduces wrong include order in 3.0.2,
// include the grand <wx/wx.h> at a cost of longer pre-compilation phase.
#include <codeanalysis\warnings.h>
#pragma warning(push)
#pragma warning(disable: ALL_CODE_ANALYSIS_WARNINGS 26812 26814)
#include <wx/wx.h>
#pragma warning(pop)
#include "../include/wxex/aui/framemanager.h"
#include "../include/wxex/persist/auimanager.h"
#include "../include/wxex/persist/toplevel.h"
#include "../include/wxex/appbar.h"
#include "../include/wxex/comutils.h"
#include "../include/wxex/crypto.h"
#include "../include/wxex/hex.h"
#include "../include/wxex/object.h"
#include "../include/wxex/url.h"
#include "../include/wxex/valhex.h"
#include "../include/wxex/valnet.h"
#include "../include/wxex/xml.h"
#include "../include/wxex/common.h"
#include "../include/wxex/private/tlwgeom.h"
/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 2015-2022 Amebis
Copyright © 2016 GÉANT
*/
#pragma once
// Since including <wx/app.h> introduces wrong include order in 3.0.2,
// include the grand <wx/wx.h> at a cost of longer pre-compilation phase.
#include <codeanalysis\warnings.h>
#pragma warning(push)
#pragma warning(disable: ALL_CODE_ANALYSIS_WARNINGS 26812 26814)
#include <wx/wx.h>
#pragma warning(pop)
#include "../include/wxex/aui/framemanager.h"
#include "../include/wxex/persist/auimanager.h"
#include "../include/wxex/persist/toplevel.h"
#include "../include/wxex/appbar.h"
#include "../include/wxex/comutils.h"
#include "../include/wxex/crypto.h"
#include "../include/wxex/hex.h"
#include "../include/wxex/icon.h"
#include "../include/wxex/object.h"
#include "../include/wxex/url.h"
#include "../include/wxex/valhex.h"
#include "../include/wxex/valnet.h"
#include "../include/wxex/xml.h"
#include "../include/wxex/common.h"
#include "../include/wxex/private/tlwgeom.h"