diff --git a/widget/include/Cevo/CevoScreenTools.h b/widget/include/Cevo/CevoScreenTools.h index 56f3e84..fea0cd3 100644 --- a/widget/include/Cevo/CevoScreenTools.h +++ b/widget/include/Cevo/CevoScreenTools.h @@ -104,6 +104,10 @@ void fill(Dpi::Canvas &canvas, int left, int top, int width, int height, int xOf void fill(Dpi::Canvas &canvas, const QRect &rect, const QPoint &offset = QPoint()); 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, +// `growth` more pixels animating in (negative: shrinking), out of `max`. +void paintProgressBar(Dpi::Canvas &canvas, int kind, int x, int y, int pos, int growth, int max, + const Texture &texture); void biColorTextOut(Dpi::Canvas &canvas, QColor mainColor, QColor backColor, int x, int y, const QString &text); int biColorTextWidth(Dpi::Canvas &canvas, const QString &text); diff --git a/widget/src/CevoScreenTools.cpp b/widget/src/CevoScreenTools.cpp index 7061b0c..3b9a3c1 100644 --- a/widget/src/CevoScreenTools.cpp +++ b/widget/src/CevoScreenTools.cpp @@ -32,6 +32,7 @@ #include "Dpi/DpiPixelPointer.h" #include +#include namespace Cevo { @@ -178,6 +179,47 @@ void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int heig fill(canvas, left, top, width, height, 0, 0); } +void paintProgressBar(Dpi::Canvas &canvas, int kind, int x, int y, int pos, int growth, int max, + const Texture &texture) +{ + if (pos > max) + pos = max; + if (growth < 0) { + pos += growth; + if (pos < 0) { + growth -= pos; + if (growth > max) + growth = max; + pos = 0; + } + } else if (pos + growth > max) { + growth = max - pos; + } + frame(canvas, x - 1, y - 1, x + max, y + 7, Qt::black, Qt::black); + rframe(canvas, x - 2, y - 2, x + max + 1, y + 8, texture.colorBevelShade, texture.colorBevelLight); + if (!HGrSystem) + return; + Dpi::Canvas &src = HGrSystem->data.canvas(); + for (int i = 0; i < pos / 8; ++i) + canvas.copyRect(QRect(x + i * 8, y, 8, 7), src, QRect(104, 9 + 8 * kind, 8, 7)); + canvas.copyRect(QRect(x + 8 * (pos / 8), y, pos - 8 * (pos / 8), 7), src, QRect(104, 9 + 8 * kind, pos - 8 * (pos / 8), 7)); + if (growth > 0) { + for (int i = 0; i < growth / 8; ++i) + canvas.copyRect(QRect(x + pos + i * 8, y, 8, 7), src, QRect(112, 9 + 8 * kind, 8, 7)); + canvas.copyRect(QRect(x + pos + 8 * (growth / 8), y, growth - 8 * (growth / 8), 7), src, + QRect(112, 9 + 8 * kind, growth - 8 * (growth / 8), 7)); + } else if (growth < 0) { + for (int i = 0; i < -growth / 8; ++i) + canvas.copyRect(QRect(x + pos + i * 8, y, 8, 7), src, QRect(104, 1, 8, 7)); + canvas.copyRect(QRect(x + pos + 8 * (-growth / 8), y, -growth - 8 * (-growth / 8), 7), src, + QRect(104, 1, -growth - 8 * (-growth / 8), 7)); + } + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(Qt::black); + canvas.fillRect(QRect(x + pos + std::abs(growth), y, max - pos - std::abs(growth), 7)); + canvas.brush().setStyle(Qt::NoBrush); +} + namespace { // %c=combat %f=food %l=luxury %m=manufacture %n=nation %o=output