From 2135a14b174387ff331d90050f951f18ecd55c05 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Mon, 11 May 2026 13:11:37 +0200 Subject: [PATCH] FINE I'll do it myself --- src/render/text/viewer.cpp | 30 +++++++++++++++++++++++------- src/util/rotation.cpp | 30 +++++++++++++++++++++++++++++- src/util/rotation.hpp | 1 + 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/render/text/viewer.cpp b/src/render/text/viewer.cpp index e4bba7d0..b1a3966c 100644 --- a/src/render/text/viewer.cpp +++ b/src/render/text/viewer.cpp @@ -105,24 +105,40 @@ RealRect intersect(const RealRect& a, const RealRect& b) { RealPoint tl = piecewise_max(a.topLeft(), b.topLeft()); RealPoint br = piecewise_min(a.bottomRight(), b.bottomRight()); return RealRect(tl, RealSize(br - tl)); -} +} void TextViewer::drawSelection(RotatedDC& dc, const TextStyle& style, size_t sel_start, size_t sel_end) { if (sel_start == sel_end) return; - if (sel_end < sel_start) swap(sel_start, sel_end); + if (sel_end < sel_start) swap(sel_start, sel_end); +#ifdef __WXMSW__ dc.SetBrush(*wxWHITE_BRUSH); dc.SetPen(*wxWHITE_PEN); - dc.SetLogicalFunction(wxXOR); + dc.SetLogicalFunction(wxXOR); +#endif RealRect prev_rect(0,0,0,0); FOR_EACH(l, lines) { RealRect rect = l.selectionRectangle(dc, sel_start, sel_end); - if (rect.height > 0) dc.DrawRectangle(rect); + if (rect.height > 0) { +#ifdef __WXMSW__ + dc.DrawRectangle(rect); +#else + dc.DrawInvertRectangle(rect); +#endif + } // compensate for overlap between lines RealRect overlap = intersect(rect, prev_rect); - if (overlap.height > 0 && overlap.width > 0) dc.DrawRectangle(overlap); + if (overlap.height > 0 && overlap.width > 0) { +#ifdef __WXMSW__ + dc.DrawRectangle(overlap); +#else + dc.DrawInvertRectangle(overlap); +#endif + } prev_rect = rect; - } - dc.SetLogicalFunction(wxCOPY); + } +#ifdef __WXMSW__ + dc.SetLogicalFunction(wxCOPY); +#endif } RealRect TextViewer::Line::selectionRectangle(const Rotation& rot, size_t sel_start, size_t sel_end) { diff --git a/src/util/rotation.cpp b/src/util/rotation.cpp index 8795ce9c..46f4a66c 100644 --- a/src/util/rotation.cpp +++ b/src/util/rotation.cpp @@ -9,7 +9,8 @@ #include #include #include -#include +#include +#include // ----------------------------------------------------------------------------- : Rotation @@ -276,6 +277,33 @@ void RotatedDC::DrawRoundedRectangle(const RealRect& r, double radius) { } } +void RotatedDC::DrawInvertRectangle(const RealRect& r) { + wxRect r_ext = trRectToBB(r); + + wxBitmap bmp(r_ext.width, r_ext.height, 24); + wxMemoryDC memDC(bmp); + memDC.Blit(0, 0, r_ext.width, r_ext.height, &dc, r_ext.x, r_ext.y); + memDC.SelectObject(wxNullBitmap); + + wxNativePixelData data(bmp); + if (!data) return; // Raw access not available on this platform/bitmap + wxNativePixelData::Iterator p(data); + for (int j = 0; j < r_ext.height; ++j) { + wxNativePixelData::Iterator rowStart = p; + for (int i = 0; i < r_ext.width; ++i) { + // Invert each channel + p.Red() = 255 - p.Red(); + p.Green() = 255 - p.Green(); + p.Blue() = 255 - p.Blue(); + ++p; // Move to next pixel in the row + } + p = rowStart; + p.OffsetY(data, 1); // Move to the next row + } + + dc.DrawBitmap(bmp, RealPoint(r_ext.x, r_ext.y)); +} + void RotatedDC::DrawCircle(const RealPoint& center, double radius) { wxPoint p = tr(center); dc.DrawCircle(p.x + 1, p.y + 1, int(trS(radius))); diff --git a/src/util/rotation.hpp b/src/util/rotation.hpp index 190a9d25..987560e3 100644 --- a/src/util/rotation.hpp +++ b/src/util/rotation.hpp @@ -173,6 +173,7 @@ public: void DrawLine (const RealPoint& p1, const RealPoint& p2); void DrawRectangle(const RealRect& r); void DrawRoundedRectangle(const RealRect& r, double radius); + void DrawInvertRectangle(const RealRect& r); void DrawCircle(const RealPoint& center, double radius); void DrawEllipse(const RealPoint& center, const RealSize& size); /// Draw an arc of an ellipse, angles are in radians