diff --git a/src/command/command.h b/src/command/command.h index 38ea38f8a..08752adbe 100644 --- a/src/command/command.h +++ b/src/command/command.h @@ -34,12 +34,12 @@ namespace agi { struct Context; } #define STR_HELP(a) wxString StrHelp() const override { return _(a); } #define CMD_TYPE(a) int Type() const override { using namespace cmd; return a; } -#define CMD_ICON(icon) wxBitmap Icon(int size, wxLayoutDirection dir = wxLayout_LeftToRight) const override { \ - if (size == 64) return GETIMAGEDIR(icon##_64, dir); \ - if (size == 48) return GETIMAGEDIR(icon##_48, dir); \ - if (size == 32) return GETIMAGEDIR(icon##_32, dir); \ - if (size == 24) return GETIMAGEDIR(icon##_24, dir); \ - return GETIMAGEDIR(icon##_16, dir); \ +#define CMD_ICON(icon) wxBitmap Icon(int size, double scale = 1.0, wxLayoutDirection dir = wxLayout_LeftToRight) const override { \ + if (size * scale >= 64) return GETIMAGEDIR(icon##_64, scale, dir); \ + if (size * scale >= 48) return GETIMAGEDIR(icon##_48, scale, dir); \ + if (size * scale >= 32) return GETIMAGEDIR(icon##_32, scale, dir); \ + if (size * scale >= 24) return GETIMAGEDIR(icon##_24, scale, dir); \ + return GETIMAGEDIR(icon##_16, scale, dir); \ } #define COMMAND_GROUP(cname, cmdname, menu, disp, help) \ @@ -107,7 +107,7 @@ DEFINE_EXCEPTION(CommandNotFound, CommandError); /// Request icon. /// @param size Icon size. - virtual wxBitmap Icon(int size, wxLayoutDirection = wxLayout_LeftToRight) const { return wxBitmap{}; } + virtual wxBitmap Icon(int size, double scale = 1.0, wxLayoutDirection = wxLayout_LeftToRight) const { return wxBitmap{}; } /// Command function virtual void operator()(agi::Context *c)=0; diff --git a/src/libresrc/libresrc.cpp b/src/libresrc/libresrc.cpp index cb204ecb2..79dc0f16c 100644 --- a/src/libresrc/libresrc.cpp +++ b/src/libresrc/libresrc.cpp @@ -20,11 +20,11 @@ #include #include -wxBitmap libresrc_getimage(const unsigned char *buff, size_t size, int dir) { +wxBitmap libresrc_getimage(const unsigned char *buff, size_t size, double scale, int dir) { wxMemoryInputStream mem(buff, size); if (dir != wxLayout_RightToLeft) - return wxBitmap(wxImage(mem)); - return wxBitmap(wxImage(mem).Mirror()); + return wxBitmap(wxImage(mem), -1, scale); + return wxBitmap(wxImage(mem).Mirror(), -1, scale); } wxIcon libresrc_geticon(const unsigned char *buff, size_t size) { diff --git a/src/libresrc/libresrc.h b/src/libresrc/libresrc.h index 020b8ccd8..ce3977c4a 100644 --- a/src/libresrc/libresrc.h +++ b/src/libresrc/libresrc.h @@ -21,10 +21,10 @@ class wxBitmap; class wxIcon; -wxBitmap libresrc_getimage(const unsigned char *image, size_t size, int dir=0); +wxBitmap libresrc_getimage(const unsigned char *image, size_t size, double scale=1.0, int dir=0); wxIcon libresrc_geticon(const unsigned char *image, size_t size); #define GETIMAGE(a) libresrc_getimage(a, sizeof(a)) -#define GETIMAGEDIR(a, d) libresrc_getimage(a, sizeof(a), d) +#define GETIMAGEDIR(a, s, d) libresrc_getimage(a, sizeof(a), s, d) #define GETICON(a) libresrc_geticon(a, sizeof(a)) #define GET_DEFAULT_CONFIG(a) std::make_pair(reinterpret_cast(a), sizeof(a)) diff --git a/src/subs_edit_box.cpp b/src/subs_edit_box.cpp index ca08b4177..fffb62384 100644 --- a/src/subs_edit_box.cpp +++ b/src/subs_edit_box.cpp @@ -45,8 +45,9 @@ #include "include/aegisub/hotkey.h" #include "initial_line_state.h" #include "options.h" -#include "project.h" #include "placeholder_ctrl.h" +#include "project.h" +#include "retina_helper.h" #include "selection_controller.h" #include "subs_edit_ctrl.h" #include "text_selection_controller.h" @@ -56,6 +57,7 @@ #include "validators.h" #include +#include #include #include @@ -105,6 +107,7 @@ const auto AssDialogue_Effect = &AssDialogue::Effect; SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxRAISED_BORDER, "SubsEditBox") , c(context) +, retina_helper(agi::make_unique(parent)) , undo_timer(GetEventHandler()) { using std::bind; @@ -273,7 +276,7 @@ TimeEdit *SubsEditBox::MakeTimeCtrl(wxString const& tooltip, TimeField field) { void SubsEditBox::MakeButton(const char *cmd_name) { cmd::Command *command = cmd::get(cmd_name); - wxBitmapButton *btn = new wxBitmapButton(this, -1, command->Icon(16)); + wxBitmapButton *btn = new wxBitmapButton(this, -1, command->Icon(16, retina_helper->GetScaleFactor())); ToolTipManager::Bind(btn, command->StrHelp(), "Subtitle Edit Box", cmd_name); middle_right_sizer->Add(btn, wxSizerFlags().Expand()); diff --git a/src/subs_edit_box.h b/src/subs_edit_box.h index 3cf9497e1..0443adbdc 100644 --- a/src/subs_edit_box.h +++ b/src/subs_edit_box.h @@ -43,6 +43,7 @@ namespace agi { struct Context; } namespace agi { class Time; } class AssDialogue; class AssStyle; +class RetinaHelper; class SubsTextEditCtrl; class TimeEdit; class wxButton; @@ -103,6 +104,8 @@ class SubsEditBox final : public wxPanel { wxSizer *middle_left_sizer; wxSizer *bottom_sizer; + std::unique_ptr retina_helper; + void SetControlsState(bool state); /// @brief Update times of selected lines /// @param field Field which changed diff --git a/src/toolbar.cpp b/src/toolbar.cpp index 5718b19d5..40c0a7769 100644 --- a/src/toolbar.cpp +++ b/src/toolbar.cpp @@ -68,6 +68,9 @@ namespace { /// Listener for icon size change signal agi::signal::Connection icon_size_slot; + /// Listener for scale factor change signal + agi::signal::Connection scale_factor_slot; + /// Listener for hotkey change signal agi::signal::Connection hotkeys_changed_slot; @@ -139,7 +142,7 @@ namespace { flags & cmd::COMMAND_TOGGLE ? wxITEM_CHECK : wxITEM_NORMAL; - wxBitmap const& bitmap = command->Icon(icon_size, GetLayoutDirection()); + wxBitmap const& bitmap = command->Icon(icon_size, retina_helper.GetScaleFactor(), GetLayoutDirection()); AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), bitmap, GetTooltip(command), kind); commands.push_back(command); @@ -173,6 +176,9 @@ namespace { , retina_helper(parent) , icon_size(OPT_GET("App/Toolbar Icon Size")->GetInt()) , icon_size_slot(OPT_SUB("App/Toolbar Icon Size", &Toolbar::OnIconSizeChange, this)) + , scale_factor_slot(retina_helper.AddScaleFactorListener([=](double scale) { + RegenerateToolbar(); + })) , hotkeys_changed_slot(hotkey::inst->AddHotkeyChangeListener(&Toolbar::RegenerateToolbar, this)) { Populate(); @@ -189,9 +195,8 @@ namespace { , icon_size(OPT_GET("App/Toolbar Icon Size")->GetInt()) , icon_size_slot(OPT_SUB("App/Toolbar Icon Size", &Toolbar::OnIconSizeChange, this)) #else - , icon_size(32 * retina_helper.GetScaleFactor()) + , icon_size(32) , icon_size_slot(retina_helper.AddScaleFactorListener([=](double scale) { - icon_size = 32 * retina_helper.GetScaleFactor(); RegenerateToolbar(); })) #endif