FINE I'll do it myself

This commit is contained in:
GenevensiS
2026-05-11 13:11:37 +02:00
parent 72830ec218
commit 2135a14b17
3 changed files with 53 additions and 8 deletions
+18 -2
View File
@@ -110,19 +110,35 @@ RealRect intersect(const RealRect& a, const RealRect& b) {
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);
#ifdef __WXMSW__
dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(*wxWHITE_PEN);
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;
}
#ifdef __WXMSW__
dc.SetLogicalFunction(wxCOPY);
#endif
}
RealRect TextViewer::Line::selectionRectangle(const Rotation& rot, size_t sel_start, size_t sel_end) {
+28
View File
@@ -10,6 +10,7 @@
#include <util/rotation.hpp>
#include <gfx/gfx.hpp>
#include <data/font.hpp>
#include <wx/rawbmp.h>
// ----------------------------------------------------------------------------- : 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)));
+1
View File
@@ -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