Skip to content

Commit

Permalink
Remove a bunch of unnecessary wx version checks
Browse files Browse the repository at this point in the history
We require wx 3.2.0+ now so no point keeping pre-3.1.6 code in
  • Loading branch information
sirjuddington committed May 31, 2024
1 parent 660e573 commit 916d97a
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 254 deletions.
75 changes: 0 additions & 75 deletions src/Graphics/Icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ bool icons::loadIcons()
return true;
}

#if wxCHECK_VERSION(3, 1, 6)
// -----------------------------------------------------------------------------
// Loads the icon [name] of [type] into a wxBitmapBundle of minimum [size], with
// optional [padding] (png icons only).
Expand Down Expand Up @@ -483,41 +482,7 @@ wxBitmapBundle icons::getIcon(Type type, string_view name, int size, const Point

return wxNullBitmap;
}
#else
// -----------------------------------------------------------------------------
// Loads the icon [name] of [type] into a wxBitmap of [size], with optional
// [padding].
//
// NOTE: this does not use any kind of caching and will generate/load the icon
// from svg/png data each time
// -----------------------------------------------------------------------------
wxBitmap icons::getIcon(Type type, string_view name, int size, Point2i padding)
{
// Get icon definition
const auto* icon_def = iconDef(type, name);
if (!icon_def)
{
log::warning("Unknown icon \"{}\"", name);
return wxNullBitmap;
}

// Check size
if (size <= 0)
size = ui::scalePx(16);

// If there is SVG data use that
if (!icon_def->svg_data.empty())
return loadSVGIcon(icon_def->svg_data, size, padding);

// Otherwise load from png
if (icon_def->entry_png16 || icon_def->entry_png32)
return loadPNGIcon(*icon_def, size, padding);

return wxNullBitmap;
}
#endif

#if wxCHECK_VERSION(3, 1, 6)
// -----------------------------------------------------------------------------
// Loads the interface icon [name] from [theme] into a wxBitmapBundle of minimum
// [size].
Expand Down Expand Up @@ -557,46 +522,6 @@ wxBitmapBundle icons::getInterfaceIcon(string_view name, int size, InterfaceThem

return wxNullBitmap;
}
#else
// -----------------------------------------------------------------------------
// Loads the interface icon [name] from [theme] into a wxBitmap of [size].
//
// NOTE: this does not use any kind of caching and will generate/load the icon
// from svg/png data each time
// -----------------------------------------------------------------------------
wxBitmap icons::getInterfaceIcon(string_view name, int size, InterfaceTheme theme)
{
// Get theme to use
bool dark = false;
switch (theme)
{
case System: dark = ui_icons_dark; break;
case Light: dark = false; break;
case Dark: dark = true; break;
}

// Get icon definition
auto& icon_set = dark ? iconset_ui_dark : iconset_ui_light;
IconDef* icon_def = nullptr;
if (auto i = icon_set.icons.find(name); i != icon_set.icons.end())
icon_def = &i->second;
if (!icon_def)
{
log::warning("Unknown interface icon \"{}\"", name);
return wxNullBitmap;
}

// Check size
if (size <= 0)
size = ui::scalePx(16);

// If there is SVG data use that
if (!icon_def->svg_data.empty())
return loadSVGIcon(icon_def->svg_data, size, {});

return wxNullBitmap;
}
#endif

// -----------------------------------------------------------------------------
// Returns a list of all defined icon sets for [type]
Expand Down
5 changes: 0 additions & 5 deletions src/Graphics/Icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ namespace icons

bool loadIcons();

#if wxCHECK_VERSION(3, 1, 6)
wxBitmapBundle getIcon(Type type, string_view name, int size = -1, const Point2i& padding = { 0, 0 });
wxBitmapBundle getInterfaceIcon(string_view name, int size = -1, InterfaceTheme theme = System);
#else
wxBitmap getIcon(Type type, string_view name, int size = -1, Point2i padding = { 0, 0 });
wxBitmap getInterfaceIcon(string_view name, int size = -1, InterfaceTheme theme = System);
#endif

vector<string> iconSets(Type type);
bool iconExists(Type type, string_view name);
Expand Down
4 changes: 0 additions & 4 deletions src/TextEditor/UI/SCallTip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ void SCallTip::setFont(const wxString& face, int size)
if (face.empty())
{
font_.SetFaceName(GetFont().GetFaceName());
#if wxCHECK_VERSION(3, 1, 6)
font_.SetPointSize(FromDIP(GetFont().GetPointSize()));
#else
font_.SetPointSize(GetFont().GetPointSize());
#endif
}
else
{
Expand Down
8 changes: 0 additions & 8 deletions src/TextEditor/UI/TextEditorCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,12 @@ TextEditorCtrl::TextEditorCtrl(wxWindow* parent, int id) :
SetMarginWidth(2, 4);

// Register icons for autocompletion list
#if wxCHECK_VERSION(3, 1, 6)
auto size = wxSize{ ui::scalePx(16), ui::scalePx(16) };
RegisterImage(1, icons::getIcon(icons::TextEditor, "keyword", -1, { 1, 3 }).GetBitmap(size));
RegisterImage(2, icons::getIcon(icons::TextEditor, "constant", -1, { 1, 3 }).GetBitmap(size));
RegisterImage(3, icons::getIcon(icons::TextEditor, "type", -1, { 1, 3 }).GetBitmap(size));
RegisterImage(4, icons::getIcon(icons::TextEditor, "property", -1, { 1, 3 }).GetBitmap(size));
RegisterImage(5, icons::getIcon(icons::TextEditor, "function", -1, { 1, 3 }).GetBitmap(size));
#else
RegisterImage(1, icons::getIcon(icons::TextEditor, "keyword", -1, { 1, 3 }));
RegisterImage(2, icons::getIcon(icons::TextEditor, "constant", -1, { 1, 3 }));
RegisterImage(3, icons::getIcon(icons::TextEditor, "type", -1, { 1, 3 }));
RegisterImage(4, icons::getIcon(icons::TextEditor, "property", -1, { 1, 3 }));
RegisterImage(5, icons::getIcon(icons::TextEditor, "function", -1, { 1, 3 }));
#endif

// Init w/no language
setLanguage(nullptr);
Expand Down
14 changes: 0 additions & 14 deletions src/UI/Controls/SIconButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,7 @@ SIconButton::SIconButton(
int icon_size) :
wxBitmapButton{ parent, -1, wxNullBitmap }
{
#if wxCHECK_VERSION(3, 1, 6)
auto bmp = icons::getIcon(icon_type, icon.ToStdString(), icon_size);
#else
// Create icon
auto size = ui::scalePx(icon_size);
auto bmp = icons::getIcon(icon_type, icon.ToStdString(), size);

// Scale icon if required
if (bmp.GetWidth() != size)
{
auto img = bmp.ConvertToImage();
img.Rescale(size, size, wxIMAGE_QUALITY_BICUBIC);
bmp = wxBitmap(img);
}
#endif

// Set button image and tooltip
SetBitmap(bmp);
Expand Down
28 changes: 7 additions & 21 deletions src/UI/Lists/ArchiveEntryTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,13 @@ using namespace ui;
// -----------------------------------------------------------------------------
namespace slade::ui
{
wxColour col_text_modified(0, 0, 0, 0);
wxColour col_text_new(0, 0, 0, 0);
wxColour col_text_locked(0, 0, 0, 0);
#if wxCHECK_VERSION(3, 1, 6)
wxColour col_text_modified(0, 0, 0, 0);
wxColour col_text_new(0, 0, 0, 0);
wxColour col_text_locked(0, 0, 0, 0);
std::unordered_map<string, wxBitmapBundle> icon_cache;
#else
std::unordered_map<string, wxIcon> icon_cache;
#endif
vector<int> elist_chars = {
'.', ',', '_', '-', '+', '=', '`', '~', '!', '@', '#', '$', '(', ')', '[',
']', '{', '}', ':', ';', '/', '\\', '<', '>', '?', '^', '&', '\'', '\"',
vector<int> elist_chars = {
'.', ',', '_', '-', '+', '=', '`', '~', '!', '@', '#', '$', '(', ')', '[',
']', '{', '}', ':', ';', '/', '\\', '<', '>', '?', '^', '&', '\'', '\"',
};
} // namespace slade::ui

Expand Down Expand Up @@ -384,19 +380,9 @@ void ArchiveViewModel::GetValue(wxVariant& variant, const wxDataViewItem& item,
if (icon_cache.find(entry->type()->icon()) == icon_cache.end())
{
// Not found, add to cache
const auto pad = Point2i{ 1, elist_icon_padding };

#if wxCHECK_VERSION(3, 1, 6)
const auto pad = Point2i{ 1, elist_icon_padding };
const auto bundle = icons::getIcon(icons::Type::Entry, entry->type()->icon(), elist_icon_size, pad);
icon_cache[entry->type()->icon()] = bundle;
#else
const auto size = scalePx(elist_icon_size);
const auto bmp = icons::getIcon(icons::Type::Entry, entry->type()->icon(), size, pad);

wxIcon icon;
icon.CopyFromBitmap(bmp);
icon_cache[entry->type()->icon()] = icon;
#endif
}

wxString name = entry->name();
Expand Down
Loading

0 comments on commit 916d97a

Please sign in to comment.