From f9f00c86225c421c51eccc51ec7b04f5769f0f7b Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 13:36:57 +0100 Subject: [PATCH] added missing tools --- widget/include/Cevo/CevoScreenTools.h | 19 +++++++++ widget/src/CevoScreenTools.cpp | 59 ++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/widget/include/Cevo/CevoScreenTools.h b/widget/include/Cevo/CevoScreenTools.h index 1320b9c..095dce0 100644 --- a/widget/include/Cevo/CevoScreenTools.h +++ b/widget/include/Cevo/CevoScreenTools.h @@ -87,6 +87,15 @@ extern GraphicSet *HGrSystem; extern GraphicSet *HGrSystem2; extern GraphicSet *Templates; extern Dpi::Bitmap *Colors; // palette lookup bitmap, indexed by clkAge0/cli* below +// ScreenTools.pas's `Paper` decorative background bitmap (Graphics/Paper.jpg) +// - null until the application's asset-loading step loads it (no central +// UnitInit exists yet, so the first consumer that needs it loads it lazily). +extern Dpi::Bitmap paper; + +// ScreenTools.pas's magenta/half-magenta transparency color-key constants +// (also used by loadGraphicSet()'s own mask generation). +constexpr QRgb TransparentColor1 = 0xFF00FF; +constexpr QRgb TransparentColor2 = 0x7F007F; // ScreenTools.pas's "icons.bmp" sprite sheet (improvements/wonders, big // size) + its per-icon slot size; also populated by app asset-loading. extern Dpi::Bitmap *bigImp; @@ -145,6 +154,16 @@ void corner(Dpi::Canvas &canvas, int x, int y, int kind, const Texture &texture) void fill(Dpi::Canvas &canvas, int left, int top, int width, int height, int xOffset = 0, int yOffset = 0); void fill(Dpi::Canvas &canvas, const QRect &rect, const QPoint &offset = QPoint()); +// Seamlessly tiles `texture` (wrapping at its own width/height) into the +// given rectangle, offset by (xOffset,yOffset) - e.g. a background that +// must look continuous regardless of where the painted rect starts. +void fillSeamless(Dpi::Canvas &canvas, int left, int top, int width, int height, int xOffset, int yOffset, + Dpi::Bitmap &texture); +void fillRectSeamless(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, int xOffset, int yOffset, + Dpi::Bitmap &texture); +// Replaces every pixel in `dest` equal to transparentColor with the +// corresponding (wrapped) pixel of `texture`. +void texturize(Dpi::Bitmap &dest, Dpi::Bitmap &texture, QColor transparentColor); void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int height, int formWidth = 0, int formHeight = 0); // Draws a HGrSystem-sprited progress bar: `pos` pixels already filled, diff --git a/widget/src/CevoScreenTools.cpp b/widget/src/CevoScreenTools.cpp index bd15bd9..2a55068 100644 --- a/widget/src/CevoScreenTools.cpp +++ b/widget/src/CevoScreenTools.cpp @@ -46,6 +46,7 @@ GraphicSet *HGrSystem2 = nullptr; GraphicSet *Templates = nullptr; Dpi::Bitmap *Colors = nullptr; Dpi::Bitmap *bigImp = nullptr; +Dpi::Bitmap paper; QColor colorFromDelphi(int value) { @@ -152,8 +153,6 @@ GraphicSet *loadGraphicSet(const QString &name, bool transparency) result->resetPixUsed(); if (transparency) { - constexpr QRgb TransparentColor1 = 0xFF00FF; - constexpr QRgb TransparentColor2 = 0x7F007F; result->mask.setSize(result->data.width(), result->data.height()); Dpi::PixelPointer dataPixel(&result->data.image(), 0, 0); Dpi::PixelPointer maskPixel(&result->mask.image(), 0, 0); @@ -341,6 +340,62 @@ void fill(Dpi::Canvas &canvas, const QRect &rect, const QPoint &offset) fill(canvas, rect.left(), rect.top(), rect.width(), rect.height(), offset.x(), offset.y()); } +void fillSeamless(Dpi::Canvas &canvas, int left, int top, int width, int height, int xOffset, int yOffset, + Dpi::Bitmap &texture) +{ + if (texture.width() <= 0 || texture.height() <= 0) + return; + while (xOffset < 0) + xOffset += texture.width(); + while (yOffset < 0) + yOffset += texture.height(); + + for (int y = (top + yOffset) / texture.height(); y <= (top + yOffset + height - 1) / texture.height(); ++y) { + int y0cut = top + yOffset - y * texture.height(); + if (y0cut < 0) + y0cut = 0; + int y1cut = (y + 1) * texture.height() - (top + yOffset + height); + if (y1cut < 0) + y1cut = 0; + for (int x = (left + xOffset) / texture.width(); x <= (left + xOffset + width - 1) / texture.width(); ++x) { + int x0cut = left + xOffset - x * texture.width(); + if (x0cut < 0) + x0cut = 0; + int x1cut = (x + 1) * texture.width() - (left + xOffset + width); + if (x1cut < 0) + x1cut = 0; + canvas.copyRect(QRect(x * texture.width() + x0cut - xOffset, y * texture.height() + y0cut - yOffset, + texture.width() - x0cut - x1cut, texture.height() - y0cut - y1cut), + texture.canvas(), QRect(x0cut, y0cut, texture.width() - x0cut - x1cut, + texture.height() - y0cut - y1cut)); + } + } +} + +void fillRectSeamless(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, int xOffset, int yOffset, + Dpi::Bitmap &texture) +{ + fillSeamless(canvas, x0, y0, x1 - x0, y1 - y0, xOffset, yOffset, texture); +} + +void texturize(Dpi::Bitmap &dest, Dpi::Bitmap &texture, QColor transparentColor) +{ + if (texture.width() <= 0 || texture.height() <= 0) + return; + const QRgb transparentRgb = transparentColor.rgb() & 0xFFFFFFu; + Dpi::PixelPointer dstPixel(&dest.image(), 0, 0); + for (int y = 0; y < dest.height(); ++y) { + for (int x = 0; x < dest.width(); ++x) { + if ((dstPixel.pixelRGB() & 0xFFFFFFu) == transparentRgb) { + Dpi::PixelPointer srcPixel(&texture.image(), x % texture.width(), y % texture.height()); + dstPixel.setPixelRGB(srcPixel.pixelRGB()); + } + dstPixel.nextPixel(); + } + dstPixel.nextLine(); + } +} + void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int height, int formWidth, int formHeight) { Q_UNUSED(formWidth);