From 2978f6edf727a517a0dc0827430ad413df103cbd Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 13:42:11 +0100 Subject: [PATCH] added missing tools --- widget/include/Cevo/CevoScreenTools.h | 3 ++ widget/src/CevoScreenTools.cpp | 49 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/widget/include/Cevo/CevoScreenTools.h b/widget/include/Cevo/CevoScreenTools.h index 095dce0..ae0629a 100644 --- a/widget/include/Cevo/CevoScreenTools.h +++ b/widget/include/Cevo/CevoScreenTools.h @@ -135,6 +135,9 @@ void unshareBitmap(Dpi::Bitmap &bitmap); // Replaces every pixel equal to oldColor with newColor within the given // rectangle (both already-resolved QColors, not raw Delphi ints). void bitmapReplaceColor(Dpi::Bitmap &dst, int x, int y, int width, int height, QColor oldColor, QColor newColor); +// A soft radial glow (GlowRange=8 px) painted around a (width,height) +// rectangle at (x0,y0) within dst, tinted by cl. +void glowFrame(Dpi::Bitmap &dst, int x0, int y0, int width, int height, QColor cl); // Draws a masked sprite (AND then OR, via an internal scratch buffer since // Qt's QPainter has no raster-op compositing against the live canvas). diff --git a/widget/src/CevoScreenTools.cpp b/widget/src/CevoScreenTools.cpp index 2a55068..7f7c7d9 100644 --- a/widget/src/CevoScreenTools.cpp +++ b/widget/src/CevoScreenTools.cpp @@ -232,6 +232,55 @@ void bitmapReplaceColor(Dpi::Bitmap &dst, int x, int y, int width, int height, Q } } +void glowFrame(Dpi::Bitmap &dst, int x0, int y0, int width, int height, QColor cl) +{ + constexpr int glowRange = 8; + const int red = cl.red(); + const int green = cl.green(); + const int blue = cl.blue(); + + for (int y = -glowRange + 1; y <= height - 1 + glowRange - 1; ++y) { + for (int x = -glowRange + 1; x <= width - 1 + glowRange - 1; ++x) { + int r; + if (x < 0) { + if (y < 0) + r = static_cast(std::lround(std::sqrt(static_cast(x * x + y * y)))); + else if (y >= height) + r = static_cast( + std::lround(std::sqrt(static_cast(x * x + (y - (height - 1)) * (y - (height - 1)))))); + else + r = -x; + } else if (x >= width) { + if (y < 0) + r = static_cast( + std::lround(std::sqrt(static_cast((x - (width - 1)) * (x - (width - 1)) + y * y)))); + else if (y >= height) + r = static_cast(std::lround(std::sqrt(static_cast( + (x - (width - 1)) * (x - (width - 1)) + (y - (height - 1)) * (y - (height - 1)))))); + else + r = x - (width - 1); + } else if (y < 0) { + r = -y; + } else if (y >= height) { + r = y - (height - 1); + } else { + continue; + } + if (r == 0) + r = 1; + if (r < glowRange) { + const int px = x0 + x; + const int py = y0 + y; + if (px < 0 || py < 0 || px >= dst.width() || py >= dst.height()) + continue; + const QRgb old = dst.image().pixel(px, py); + auto mix = [&](int oldC, int clC) { return (oldC * (r - 1) + clC * (glowRange - r)) / (glowRange - 1); }; + dst.image().setPixel(px, py, qRgb(mix(qRed(old), red), mix(qGreen(old), green), mix(qBlue(old), blue))); + } + } + } +} + void sprite(Dpi::Canvas &canvas, GraphicSet &graphicSet, int xDst, int yDst, int width, int height, int xGr, int yGr) {