Use appropriate DPI images in more places on macOS

This commit is contained in:
Thomas Goyne 2019-10-06 12:45:03 -07:00
parent 85f711fccc
commit 6f546951b4
6 changed files with 28 additions and 17 deletions

View file

@ -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;

View file

@ -20,11 +20,11 @@
#include <wx/intl.h>
#include <wx/mstream.h>
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) {

View file

@ -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<const char *>(a), sizeof(a))

View file

@ -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 <libaegisub/character_count.h>
#include <libaegisub/make_unique.h>
#include <libaegisub/util.h>
#include <functional>
@ -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<RetinaHelper>(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());

View file

@ -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<RetinaHelper> retina_helper;
void SetControlsState(bool state);
/// @brief Update times of selected lines
/// @param field Field which changed

View file

@ -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