diff options
author | B Stack <bgstack15@gmail.com> | 2020-07-22 11:37:03 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-07-22 11:37:03 -0400 |
commit | c95b3937fef3e2c63768f1b3b1dc2c898f23d91d (patch) | |
tree | 10260e25ae905564f7978b83fc4e316670f987c6 /wx+/rtl.h | |
parent | Merge branch '10.25' into 'master' (diff) | |
download | FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.tar.gz FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.tar.bz2 FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.zip |
add upstream 11.0
Diffstat (limited to 'wx+/rtl.h')
-rw-r--r-- | wx+/rtl.h | 54 |
1 files changed, 22 insertions, 32 deletions
@@ -15,12 +15,11 @@ namespace zen { //functions supporting right-to-left GUI layout -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); +void drawBitmapRtlMirror (wxDC& dc, const wxImage& img, const wxRect& rect, int alignment, std::optional<wxBitmap>& buffer); +void drawBitmapRtlNoMirror(wxDC& dc, const wxImage& img, const wxRect& rect, int alignment); //wxDC::DrawIcon DOES mirror by default -> implement RTL support when needed -wxBitmap mirrorIfRtl(const wxBitmap& bmp); -wxImage mirrorIfRtl(const wxImage& bmp); +wxImage mirrorIfRtl(const wxImage& img); //manual text flow correction: https://www.w3.org/International/articles/inline-bidi-markup/ @@ -34,34 +33,35 @@ wxImage mirrorIfRtl(const wxImage& bmp); //---------------------- implementation ------------------------ 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 +//don't use wxDC::DrawLabel: +// - expensive GetTextExtent() call even when passing an empty string!!! +// - 1-off alignment bugs! inline -void drawBitmapAligned(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment) +void drawBitmapAligned(wxDC& dc, const wxImage& img, const wxRect& rect, int alignment) { wxPoint pt = rect.GetTopLeft(); if (alignment & wxALIGN_RIGHT) //note: wxALIGN_LEFT == 0! - pt.x += rect.width - bmp.GetWidth(); + pt.x += rect.width - img.GetWidth(); else if (alignment & wxALIGN_CENTER_HORIZONTAL) - pt.x += (rect.width - bmp.GetWidth()) / 2; + pt.x += (rect.width - img.GetWidth()) / 2; if (alignment & wxALIGN_BOTTOM) //note: wxALIGN_TOP == 0! - pt.y += rect.height - bmp.GetHeight(); + pt.y += rect.height - img.GetHeight(); else if (alignment & wxALIGN_CENTER_VERTICAL) - pt.y += (rect.height - bmp.GetHeight()) / 2; + pt.y += (rect.height - img.GetHeight()) / 2; - dc.DrawBitmap(bmp, pt); + dc.DrawBitmap(img, pt); } } inline -void drawBitmapRtlMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment, std::optional<wxBitmap>& buffer) +void drawBitmapRtlMirror(wxDC& dc, const wxImage& img, const wxRect& rect, int alignment, std::optional<wxBitmap>& buffer) { switch (dc.GetLayoutDirection()) { case wxLayout_LeftToRight: - return impl::drawBitmapAligned(dc, bmp, rect, alignment); + return impl::drawBitmapAligned(dc, img, rect, alignment); case wxLayout_RightToLeft: { @@ -71,7 +71,7 @@ void drawBitmapRtlMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int 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! - impl::drawBitmapAligned(memDc, bmp, wxRect(0, 0, rect.width, rect.height), alignment); + impl::drawBitmapAligned(memDc, img, 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 @@ -80,37 +80,27 @@ void drawBitmapRtlMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int 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); + return impl::drawBitmapAligned(dc, img.Mirror(), rect, alignment); else - return impl::drawBitmapAligned(dc, bmp, rect, alignment); + return impl::drawBitmapAligned(dc, img, rect, alignment); } } inline -void drawBitmapRtlNoMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment) +void drawBitmapRtlNoMirror(wxDC& dc, const wxImage& img, const wxRect& rect, int alignment) { - return impl::drawBitmapAligned(dc, bmp, rect, alignment); //wxDC::DrawBitmap does NOT mirror by default + return impl::drawBitmapAligned(dc, img, rect, alignment); //wxDC::DrawBitmap does NOT mirror by default } inline -wxImage mirrorIfRtl(const wxImage& bmp) +wxImage mirrorIfRtl(const wxImage& img) { if (wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft) - return bmp.Mirror(); + return img.Mirror(); else - return bmp; -} - - -inline -wxBitmap mirrorIfRtl(const wxBitmap& bmp) -{ - if (wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft) - return bmp.ConvertToImage().Mirror(); - else - return bmp; + return img; } } |