246 lines
13 KiB
C++
246 lines
13 KiB
C++
// This file is part of c-evo-evo.
|
|
//
|
|
// This software is governed by the CeCILL license under French law and
|
|
// abiding by the rules of distribution of free software. You can use,
|
|
// modify and/or redistribute the software under the terms of the CeCILL
|
|
// license as circulated by CEA, CNRS and INRIA at the following URL
|
|
// "http://www.cecill.info".
|
|
//
|
|
// As a counterpart to the access to the source code and rights to copy,
|
|
// modify and redistribute granted by the license, users are provided only
|
|
// with a limited warranty and the software's author, the holder of the
|
|
// economic rights, and the successive licensors have only limited
|
|
// liability.
|
|
//
|
|
// In this respect, the user's attention is drawn to the risks associated
|
|
// with loading, using, modifying and/or developing or reproducing the
|
|
// software by the user in light of its specific status of free software,
|
|
// that may mean that it is complicated to manipulate, and that also
|
|
// therefore means that it is reserved for developers and experienced
|
|
// professionals having in-depth computer knowledge. Users are therefore
|
|
// encouraged to load and test the software's suitability as regards their
|
|
// requirements in conditions enabling the security of their systems and/or
|
|
// data to be ensured and, more generally, to use and operate it in the
|
|
// same conditions as regards security.
|
|
//
|
|
// The fact that you are presently reading this means that you have had
|
|
// knowledge of the CeCILL license and that you accept its terms.
|
|
|
|
#pragma once
|
|
|
|
#include "Cevo/CevoGraphicSet.h"
|
|
#include "Dpi/DpiGraphics.h"
|
|
|
|
#include <QColor>
|
|
#include <QPoint>
|
|
#include <QRect>
|
|
#include <QString>
|
|
#include <array>
|
|
|
|
namespace Cevo {
|
|
|
|
class Texture;
|
|
class GraphicSetItem;
|
|
|
|
// Delphi/VCL TColor ints are packed as $00BBGGRR (red in the low byte, the
|
|
// reverse of Qt's QRgb/QColor byte order). Convert ported color literals
|
|
// (e.g. ButtonA's $0000FF placeholder color) with this helper rather than
|
|
// constructing QColor from the raw hex value directly.
|
|
QColor colorFromDelphi(int value);
|
|
// Inverse of colorFromDelphi(): packs a QColor back into a Delphi/VCL
|
|
// $00BBGGRR int (needed whenever a QColor-valued field, e.g. a tribe's
|
|
// Color, must be passed to a raw-Delphi-int API like imageOpBCC()).
|
|
int colorToDelphi(const QColor &color);
|
|
|
|
// Global display gamma correction setting, in percent (100 = no
|
|
// correction) - ScreenTools.pas's `Gamma`. Call applyGammaToBitmap()
|
|
// (automatically done by loadGraphicSet()) after changing it.
|
|
extern int gamma;
|
|
void applyGammaToBitmap(Dpi::Bitmap &bitmap);
|
|
// Parses a "RRGGBB" hex string (leading spaces ignored, missing trailing
|
|
// digits treated as 0) into a gamma-corrected QColor.
|
|
QColor hexStringToColor(const QString &text);
|
|
|
|
// ScreenTools.pas's global `GrExt` registry of loaded GraphicSets.
|
|
extern GraphicSets grExt;
|
|
// Directory loadGraphicSet() resolves names against - the application
|
|
// layer (game/'s Global::getGraphicsDir()) must set this at startup;
|
|
// widget/ has no Directories.pas port of its own to call directly.
|
|
extern QString graphicsDir;
|
|
// Equivalent of ScreenTools.pas's LoadGraphicSet(): loads (or returns the
|
|
// already-cached) named .png from getGraphicsDir(), building its
|
|
// transparency mask (magenta/half-magenta color-keyed, matching the
|
|
// original exactly since sprite() still does raster-op AND/OR
|
|
// compositing against data/mask, not alpha blending) and companion .grs
|
|
// item metadata if present. Returns nullptr if the file doesn't exist.
|
|
GraphicSet *loadGraphicSet(const QString &name, bool transparency = true);
|
|
|
|
enum class FontType { Normal, Small, Tiny, Caption, Button, Count };
|
|
|
|
// ScreenTools.pas's LoadFonts(): fills UniFont[] from a Fonts.txt script
|
|
// ("#SECTION" lines followed by "Name, <pixel height>[B][I]" lines).
|
|
void loadFonts(const QString &scriptFileName);
|
|
|
|
// Fonts, the main background texture and the system sprite sheets are
|
|
// populated by the application's asset-loading step (ScreenTools.pas's
|
|
// UnitInit/LoadAssets in the original, not ported here); null/default until
|
|
// the application assigns them.
|
|
extern std::array<Dpi::Font, static_cast<size_t>(FontType::Count)> UniFont;
|
|
extern Texture *MainTexture;
|
|
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;
|
|
constexpr int xSizeBig = 56;
|
|
constexpr int ySizeBig = 40;
|
|
// Frames then blits an xSrc,ySrc/width,height region of src onto canvas at
|
|
// x,y - isControl selects the lighter "control" bevel over the plain
|
|
// black double-frame.
|
|
void frameImage(Dpi::Canvas &canvas, Dpi::Bitmap &src, int x, int y, int width, int height, int xSrc, int ySrc,
|
|
bool isControl = false);
|
|
// ScreenTools.pas's Dump(): a plain sprite-sheet blit with no mask/
|
|
// transparency handling (unlike sprite()).
|
|
void dump(Dpi::Bitmap &dst, GraphicSet &graphicSet, int xDst, int yDst, int width, int height, int xGr, int yGr);
|
|
|
|
// Colors palette row/column indices (Colors->image().pixelColor(col, row)).
|
|
constexpr int clkAge0 = 1;
|
|
constexpr int cliTexture = 0;
|
|
constexpr int cliBevelLight = 1;
|
|
constexpr int cliBevelShade = 2;
|
|
constexpr int cliTextLight = 3;
|
|
constexpr int cliTextShade = 4;
|
|
constexpr int cliLitText = 5;
|
|
constexpr int cliMark = 6;
|
|
constexpr int cliDimmedText = 7;
|
|
constexpr int cliRoad = 8;
|
|
constexpr int cliHouse = 9;
|
|
constexpr int cliImp = 10;
|
|
constexpr int cliImpProject = 11;
|
|
constexpr int cliPage = 13;
|
|
constexpr int cliCover = 14;
|
|
constexpr int clkMisc = 5;
|
|
constexpr int cliPaper = 0;
|
|
constexpr int cliPaperText = 1;
|
|
constexpr int cliPaperCaption = 2;
|
|
constexpr int clkCity = 6;
|
|
constexpr int cliPlains = 0;
|
|
constexpr int cliPrairie = 1;
|
|
constexpr int cliHills = 2;
|
|
constexpr int cliTundra = 3;
|
|
constexpr int cliWater = 4;
|
|
|
|
enum class RasterOp { Copy, And, Paint, Invert };
|
|
|
|
// Mirrors ScreenTools.pas's BitBltBitmap raster-op blit (classic AND-mask +
|
|
// OR-data sprite compositing) and UnshareBitmap (a no-op here: QImage is
|
|
// already copy-on-write safe, so there is no shared-handle cache to break).
|
|
void bitBltBitmap(Dpi::Bitmap &dest, int x, int y, int width, int height,
|
|
Dpi::Bitmap &src, int xSrc, int ySrc, RasterOp rop = RasterOp::Copy);
|
|
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);
|
|
// ScreenTools.pas's shared `DrawBuffer` scratch bitmap (resized on demand
|
|
// by drawBufferEnsureSize()) - used by dialogs that need an off-screen
|
|
// compositing surface for a one-off effect.
|
|
extern Dpi::Bitmap drawBuffer;
|
|
void drawBufferEnsureSize(int width, int height);
|
|
|
|
// 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).
|
|
void sprite(Dpi::Canvas &canvas, GraphicSet &graphicSet, int xDst, int yDst,
|
|
int width, int height, int xGr, int yGr);
|
|
void sprite(Dpi::Canvas &canvas, int xDst, int yDst, const GraphicSetItem &item);
|
|
|
|
void frame(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1);
|
|
void rframe(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1);
|
|
// A "double line" bevel effect (one line in cl0, a second offset by one
|
|
// pixel in cl1), e.g. used to separate a label from its value.
|
|
void dLine(Dpi::Canvas &canvas, int x0, int x1, int y, QColor cl0, QColor cl1);
|
|
void btnFrame(Dpi::Canvas &canvas, const QRect &rect, const Texture &texture);
|
|
void editFrame(Dpi::Canvas &canvas, const QRect &rect, const Texture &texture);
|
|
// Unimplemented in the original ScreenTools.pas too (body is commented out there).
|
|
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,
|
|
// `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);
|
|
// Same as paintProgressBar, but pos/growth/max are expressed relative to a
|
|
// `size`-pixel-wide bar instead of raw pixel counts; optionally draws a
|
|
// "complete" checkmark sprite when pos+growth reaches max.
|
|
void paintRelativeProgressBar(Dpi::Canvas &canvas, int kind, int x, int y, int size, int pos, int growth, int max,
|
|
bool indicateComplete, const Texture &texture);
|
|
// Darkens dst's [x,y,width,height) region to half brightness per channel.
|
|
void makeBlue(Dpi::Bitmap &dst, int x, int y, int width, int height);
|
|
// Converts dst's [x,y,width,height) region to a greyscale-derived red tint.
|
|
void makeRed(Dpi::Bitmap &dst, int x, int y, int width, int height);
|
|
// Draws a labelled HGrSystem icon-bar count (e.g. "Food +3") at (x,y),
|
|
// `val` icons wide (tens-icon then ones-icon), capped to fit within `w`.
|
|
void countBar(Dpi::Bitmap &dst, int x, int y, int w, int kind, const QString &cap, int val, 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);
|
|
void risedTextOut(Dpi::Canvas &canvas, int x, int y, const QString &text);
|
|
// cl == -2: mixed bevel colors; cl < 0: texture's text shade/light pair; cl >= 0: explicit color.
|
|
void loweredTextOut(Dpi::Canvas &canvas, int cl, const Texture &texture, int x, int y, const QString &text);
|
|
|
|
// Template-based color blending (Src is a greyscale "template" bitmap whose
|
|
// channels encode per-pixel blend amplitudes). color0/color1/color2 use the
|
|
// Delphi $BBGGRR byte order, like colorFromDelphi's input.
|
|
void imageOpB(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc, int width, int height);
|
|
void imageOpBCC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
|
|
int width, int height, int color1, int color2);
|
|
void imageOpCBC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
|
|
int width, int height, int color0, int color2);
|
|
void imageOpCCC(Dpi::Bitmap &bmp, int x, int y, int width, int height, int color0, int color1, int color2);
|
|
|
|
// ScreenTools.pas's TurnToYear(): maps a game turn to a calendar year
|
|
// (negative = BC), using the same variable-length-era table as the original.
|
|
int turnToYear(int turn);
|
|
// ScreenTools.pas's MovementToString(): formats a x100-scaled movement
|
|
// points value as e.g. "1.5" / "12.75".
|
|
QString movementToString(int movement);
|
|
// ScreenTools.pas's LightGradient()/DarkGradient(): a 16-step horizontal
|
|
// brightness gradient starting at `color` (LightGradient) or the HGrSystem
|
|
// swatch at row 137+kind (DarkGradient), ending in a black L-shaped border.
|
|
void lightGradient(Dpi::Canvas &canvas, int x, int y, int width, QColor color);
|
|
void darkGradient(Dpi::Canvas &canvas, int x, int y, int width, int kind);
|
|
// Vertical counterparts of lightGradient()/darkGradient().
|
|
void vLightGradient(Dpi::Canvas &canvas, int x, int y, int height, QColor color);
|
|
void vDarkGradient(Dpi::Canvas &canvas, int x, int y, int height, int kind);
|
|
// ScreenTools.pas's NumberBar(): a labeled stat row (title + DLine divider
|
|
// + right-aligned number), skipped entirely if val <= 0.
|
|
void numberBar(Dpi::Canvas &canvas, int x, int y, const QString &cap, int val, const Texture &texture);
|
|
|
|
} // namespace Cevo
|