From 0909d137b0f5171072db9ba1e6256c2fc9f1ec08 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 11 May 2014 07:31:22 -0700 Subject: [PATCH] Mirror toolbar button images for RTL locales Some of the toolbar buttons are seriously wrong when mirrored and there doesn't seem to be a way to disable mirroring for the images while using RTL layout for the toolbar itself, so double-mirror them so that they end up with their original appearance. Ideally the button images would be localizable as some of them actually should be mirrored, but that's probably not worth the work involved. See #1354. --- src/command/command.h | 14 +++++++------- src/libresrc/libresrc.cpp | 7 +++++-- src/libresrc/libresrc.h | 3 ++- src/toolbar.cpp | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/command/command.h b/src/command/command.h index e6ff83a14..245ebe9ee 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 { return _(a); } #define CMD_TYPE(a) int Type() const { using namespace cmd; return a; } -#define CMD_ICON(icon) wxBitmap Icon(int size) const override { \ - if (size == 64) return GETIMAGE(icon##_64); \ - if (size == 48) return GETIMAGE(icon##_48); \ - if (size == 32) return GETIMAGE(icon##_32); \ - if (size == 24) return GETIMAGE(icon##_24); \ - return GETIMAGE(icon##_16); \ +#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 COMMAND_GROUP(cname, cmdname, menu, disp, help) \ @@ -107,7 +107,7 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandNotFound, CommandError, "command/notfound /// Request icon. /// @param size Icon size. - virtual wxBitmap Icon(int size) const { return wxBitmap{}; } + virtual wxBitmap Icon(int size, 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 fa4e9f6e8..cb204ecb2 100644 --- a/src/libresrc/libresrc.cpp +++ b/src/libresrc/libresrc.cpp @@ -17,11 +17,14 @@ #include #include #include +#include #include -wxBitmap libresrc_getimage(const unsigned char *buff, size_t size) { +wxBitmap libresrc_getimage(const unsigned char *buff, size_t size, int dir) { wxMemoryInputStream mem(buff, size); - return wxBitmap(wxImage(mem)); + if (dir != wxLayout_RightToLeft) + return wxBitmap(wxImage(mem)); + return wxBitmap(wxImage(mem).Mirror()); } wxIcon libresrc_geticon(const unsigned char *buff, size_t size) { diff --git a/src/libresrc/libresrc.h b/src/libresrc/libresrc.h index 4c2605eb6..ca717aa8e 100644 --- a/src/libresrc/libresrc.h +++ b/src/libresrc/libresrc.h @@ -20,9 +20,10 @@ class wxBitmap; class wxIcon; -wxBitmap libresrc_getimage(const unsigned char *image, size_t size); +wxBitmap libresrc_getimage(const unsigned char *image, size_t size, 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 GETICON(a) libresrc_geticon(a, sizeof(a)) #define GET_DEFAULT_CONFIG(a) std::make_pair(reinterpret_cast(a), sizeof(a)) diff --git a/src/toolbar.cpp b/src/toolbar.cpp index 900b17547..96130643f 100644 --- a/src/toolbar.cpp +++ b/src/toolbar.cpp @@ -142,7 +142,7 @@ namespace { flags & cmd::COMMAND_TOGGLE ? wxITEM_CHECK : wxITEM_NORMAL; - wxBitmap const& bitmap = command->Icon(icon_size); + wxBitmap const& bitmap = command->Icon(icon_size, GetLayoutDirection()); AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), bitmap, GetTooltip(command), kind); commands.push_back(command);