From 583d22efb5901296d1e3dcbc091be5dee9d8a14f Mon Sep 17 00:00:00 2001 From: B Stack Date: Fri, 14 Jun 2019 22:33:49 -0400 Subject: 10.13 --- wx+/rtl.h | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'wx+/rtl.h') diff --git a/wx+/rtl.h b/wx+/rtl.h index 26380f9d..16fde699 100644 --- a/wx+/rtl.h +++ b/wx+/rtl.h @@ -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& 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& 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& buffer) +void drawBitmapRtlMirror(wxDC& dc, const wxBitmap& bmp, const wxRect& rect, int alignment, std::optional& 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 } -- cgit