diff options
author | B Stack <bgstack15@gmail.com> | 2019-07-10 20:36:59 +0000 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2019-07-10 20:36:59 +0000 |
commit | b3eda3ab537804cfa07cc257944b6fc69bec59a8 (patch) | |
tree | cc720d69d3ca68b64ed0aa79438177b6953469a1 /wx+/rtl.h | |
parent | Merge branch '10.12' into 'master' (diff) | |
parent | 10.13 (diff) | |
download | FreeFileSync-b3eda3ab537804cfa07cc257944b6fc69bec59a8.tar.gz FreeFileSync-b3eda3ab537804cfa07cc257944b6fc69bec59a8.tar.bz2 FreeFileSync-b3eda3ab537804cfa07cc257944b6fc69bec59a8.zip |
Merge branch '10.13' into 'master'10.13
10.13
See merge request opensource-tracking/FreeFileSync!10
Diffstat (limited to 'wx+/rtl.h')
-rw-r--r-- | wx+/rtl.h | 53 |
1 files changed, 32 insertions, 21 deletions
@@ -15,8 +15,8 @@ namespace zen { //functions supporting right-to-left GUI layout -void drawBitmapRtlMirror (wxDC& dc, const wxBitmap& image, const wxRect& rect, int alignment, std::optional<wxBitmap>& buffer); -void drawBitmapRtlNoMirror(wxDC& dc, const wxBitmap& image, const wxRect& rect, int alignment); +void drawBitmapRtlMirror (wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment, std::optional<wxBitmap>& buffer); +void drawBitmapRtlNoMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment); //wxDC::DrawIcon DOES mirror by default -> implement RTL support when needed wxBitmap mirrorIfRtl(const wxBitmap& bmp); @@ -36,49 +36,60 @@ namespace impl //don't use wxDC::DrawLabel: it results in expensive GetTextExtent() call even when passing an empty string!!! //also avoid wxDC::DrawLabel 1-off alignment bugs inline -void drawBitmapAligned(wxDC& dc, const wxBitmap& image, const wxRect& rect, int alignment) +void drawBitmapAligned(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment) { wxPoint pt = rect.GetTopLeft(); if (alignment & wxALIGN_RIGHT) //note: wxALIGN_LEFT == 0! - pt.x += rect.width - image.GetWidth(); + pt.x += rect.width - bmp.GetWidth(); else if (alignment & wxALIGN_CENTER_HORIZONTAL) - pt.x += (rect.width - image.GetWidth()) / 2; + pt.x += (rect.width - bmp.GetWidth()) / 2; if (alignment & wxALIGN_BOTTOM) //note: wxALIGN_TOP == 0! - pt.y += rect.height - image.GetHeight(); + pt.y += rect.height - bmp.GetHeight(); else if (alignment & wxALIGN_CENTER_VERTICAL) - pt.y += (rect.height - image.GetHeight()) / 2; + pt.y += (rect.height - bmp.GetHeight()) / 2; - dc.DrawBitmap(image, pt); + dc.DrawBitmap(bmp, pt); } } inline -void drawBitmapRtlMirror(wxDC& dc, const wxBitmap& image, const wxRect& rect, int alignment, std::optional<wxBitmap>& buffer) +void drawBitmapRtlMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment, std::optional<wxBitmap>& buffer) { - if (dc.GetLayoutDirection() == wxLayout_RightToLeft) + switch (dc.GetLayoutDirection()) { - if (!buffer || buffer->GetWidth() != rect.width || buffer->GetHeight() < rect.height) //[!] since we do a mirror, width needs to match exactly! - buffer = wxBitmap(rect.width, rect.height); + case wxLayout_LeftToRight: + return impl::drawBitmapAligned(dc, bmp, rect, alignment); - wxMemoryDC memDc(*buffer); - memDc.Blit(wxPoint(0, 0), rect.GetSize(), &dc, rect.GetTopLeft()); //blit in: background is mirrored due to memDc, dc having different layout direction! + case wxLayout_RightToLeft: + { + if (!buffer || buffer->GetWidth() != rect.width || buffer->GetHeight() < rect.height) //[!] since we do a mirror, width needs to match exactly! + buffer = wxBitmap(rect.width, rect.height); - impl::drawBitmapAligned(memDc, image, wxRect(0, 0, rect.width, rect.height), alignment); - //note: we cannot simply use memDc.SetLayoutDirection(wxLayout_RightToLeft) due to some strange 1 pixel bug! + wxMemoryDC memDc(*buffer); + memDc.Blit(wxPoint(0, 0), rect.GetSize(), &dc, rect.GetTopLeft()); //blit in: background is mirrored due to memDc, dc having different layout direction! - dc.Blit(rect.GetTopLeft(), rect.GetSize(), &memDc, wxPoint(0, 0)); //blit out: mirror once again + impl::drawBitmapAligned(memDc, bmp, wxRect(0, 0, rect.width, rect.height), alignment); + //note: we cannot simply use memDc.SetLayoutDirection(wxLayout_RightToLeft) due to some strange 1 pixel bug! + + dc.Blit(rect.GetTopLeft(), rect.GetSize(), &memDc, wxPoint(0, 0)); //blit out: mirror once again + } + break; + + case wxLayout_Default: //CAVEAT: wxPaintDC/wxMemoryDC on wxGTK/wxMAC does not implement SetLayoutDirection()!!! => GetLayoutDirection() == wxLayout_Default + if (wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft) + return impl::drawBitmapAligned(dc, bmp.ConvertToImage().Mirror(), rect, alignment); + else + return impl::drawBitmapAligned(dc, bmp, rect, alignment); } - else - impl::drawBitmapAligned(dc, image, rect, alignment); } inline -void drawBitmapRtlNoMirror(wxDC& dc, const wxBitmap& image, const wxRect& rect, int alignment) +void drawBitmapRtlNoMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment) { - return impl::drawBitmapAligned(dc, image, rect, alignment); //wxDC::DrawBitmap does NOT mirror by default + return impl::drawBitmapAligned(dc, bmp, rect, alignment); //wxDC::DrawBitmap does NOT mirror by default } |