added missing tools
This commit is contained in:
1 parent
cae16313f8
commit
2978f6edf7
2 files changed
+52
No files matched your search
@@ -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).
|
||||
|
||||
@@ -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<int>(std::lround(std::sqrt(static_cast<double>(x * x + y * y))));
|
||||
else if (y >= height)
|
||||
r = static_cast<int>(
|
||||
std::lround(std::sqrt(static_cast<double>(x * x + (y - (height - 1)) * (y - (height - 1))))));
|
||||
else
|
||||
r = -x;
|
||||
} else if (x >= width) {
|
||||
if (y < 0)
|
||||
r = static_cast<int>(
|
||||
std::lround(std::sqrt(static_cast<double>((x - (width - 1)) * (x - (width - 1)) + y * y))));
|
||||
else if (y >= height)
|
||||
r = static_cast<int>(std::lround(std::sqrt(static_cast<double>(
|
||||
(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)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user