initial port for Cevo game in C++ (libs)

This commit is contained in:
Geoffray Levasseur committed 2026-10-22 17:20:45 +02:00
commit 8436242032
375 files changed
+46282

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <QWidget>
namespace Cevo {
// TArea equivalent: a disabled placeholder widget marking a region (e.g. the
// map view) that a parent dialog's smart-invalidate logic should not paint
// chrome over. The original also drew a red design-time-only frame in the
// Lazarus form designer; that has no equivalent at runtime in a hand-written
// Qt app, so it is omitted here.
class Area : public QWidget {
Q_OBJECT
public:
explicit Area(QWidget *parent = nullptr);
};
} // namespace Cevo
+84
View File
@@ -0,0 +1,84 @@
#pragma once
#include "Cevo/CevoDrawDlg.h"
#include "Dpi/DpiGraphics.h"
#include <functional>
namespace Cevo {
enum class WindowMode { None, Modal, Persistent, Submodal };
WindowMode windowModeMakePersistent(WindowMode mode);
constexpr int NarrowFrame = 11;
constexpr int WideFrame = 36;
constexpr int SideFrame = 9;
void createOffscreen(Dpi::Bitmap &offscreen, int width, int height);
void clearOffscreen(Dpi::Bitmap &offscreen);
// TBufferedDrawDlg equivalent: double-buffers dialog content into an
// offscreen bitmap composited in paintEvent (VPaint), separating "content"
// repaints (OffscreenPaint, done by subclasses) from the chrome drawn by
// FramedDlg around it.
class BufferedDrawDlg : public DrawDlg {
Q_OBJECT
public:
explicit BufferedDrawDlg(QWidget *parent = nullptr);
WindowMode windowMode() const { return m_windowMode; }
void showNewContent(WindowMode newMode, bool forceClose = false);
void smartUpdateContent(bool immediateUpdate = false);
int userLeft = 0;
int userTop = 0;
int usedOffscreenWidth = 0;
int usedOffscreenHeight = 0;
Dpi::Bitmap offscreen;
// Hook for the F1/help key, mirrors the global ShowNewContentProc in
// BaseWin.pas.
static std::function<void(WindowMode, const QString &)> showNewContentHook;
protected:
WindowMode m_windowMode = WindowMode::None;
int modalFrameIndent = 45;
QString helpContext = QStringLiteral("CONCEPTS");
void markUsedOffscreen(int xMax, int yMax);
virtual void offscreenPaint();
virtual void vpaint(Dpi::Canvas &canvas);
void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
};
// TFramedDlg equivalent: the ornate beveled window chrome (title bar,
// corners, button frames) drawn around a BufferedDrawDlg's content.
class FramedDlg : public BufferedDrawDlg {
Q_OBJECT
public:
explicit FramedDlg(QWidget *parent = nullptr);
void smartInvalidate() override;
protected:
int captionLeft = 0;
int captionRight = 0xFFFF;
bool wideBottom = false;
bool fullCaption = true;
bool texOverride = false;
bool modalIndication = true;
int innerWidth = 0;
int innerHeight = 0;
void vpaint(Dpi::Canvas &canvas) override;
void fillOffscreen(int left, int top, int w, int h);
void resizeEvent(QResizeEvent *event) override;
// Clips the widget to a non-rectangular region when fullCaption is
// false (narrow title bar with visible corners of the content below).
void initWindowRegion();
};
} // namespace Cevo
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
// TButtonA equivalent: a 100x25 captioned button painted from the system
// sprite sheet.
class ButtonA : public ButtonBase {
Q_OBJECT
public:
explicit ButtonA(QWidget *parent = nullptr);
QString caption() const { return m_caption; }
void setCaption(const QString &text);
void setFont(const Dpi::Font &font);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
QString m_caption;
Dpi::Font m_font;
};
} // namespace Cevo
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
// TButtonB equivalent: a 25x25 button whose sprite is cut out with a mask
// (SRCAND) and painted in (SRCPAINT) over the background, selected by
// ButtonIndex from a 12-columns-wide grid.
class ButtonB : public ButtonBase {
Q_OBJECT
public:
explicit ButtonB(QWidget *parent = nullptr);
Dpi::Bitmap *mask() const { return m_mask; }
void setMask(Dpi::Bitmap *value) { m_mask = value; }
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
Dpi::Bitmap *m_mask = nullptr;
int m_index = -1;
Dpi::Bitmap m_buffer;
};
} // namespace Cevo
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QWidget>
#include <functional>
namespace Cevo {
// TButtonBase equivalent: a lightweight, sprite-painted push button with
// manual mouse tracking (no native QAbstractButton state machine), matching
// the original TGraphicControl-based design and its Down/Permanent model.
class ButtonBase : public QWidget {
Q_OBJECT
public:
explicit ButtonBase(QWidget *parent = nullptr);
bool down() const { return m_down; }
void setDown(bool value);
bool permanent() const { return m_permanent; }
void setPermanent(bool value) { m_permanent = value; }
Dpi::Bitmap *graphic() const { return m_graphic; }
void setGraphic(Dpi::Bitmap *value) { m_graphic = value; }
std::function<void()> onClick;
std::function<void()> onDownChanged;
protected:
virtual void paint(Dpi::Canvas &canvas) { Q_UNUSED(canvas); }
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
Dpi::Bitmap *m_graphic = nullptr;
bool m_down = false;
private:
void paintEvent(QPaintEvent *event) override final;
void trackMouse(const QPoint &pos, bool leftPressed);
void setDownState(bool value);
bool m_permanent = false;
bool m_active = false;
};
} // namespace Cevo
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
// TButtonC equivalent: a 12x12 icon button, selected by ButtonIndex from a
// single-column grid.
class ButtonC : public ButtonBase {
Q_OBJECT
public:
explicit ButtonC(QWidget *parent = nullptr);
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
int m_index = 0;
};
} // namespace Cevo
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
#include "Cevo/CevoGraphicSet.h"
namespace Cevo {
// TButtonG equivalent: a button whose background and glyph are looked up by
// index or name in a GraphicSet (used for the city/government icon
// buttons), instead of fixed sprite-sheet coordinates.
class ButtonG : public ButtonBase {
Q_OBJECT
public:
explicit ButtonG(QWidget *parent = nullptr);
GraphicSet *graphicSet() const { return m_graphicSet; }
void setGraphicSet(GraphicSet *value) { m_graphicSet = value; }
int backgroundUpIndex() const { return m_backgroundUpIndex; }
void setBackgroundUpIndex(int value);
QString backgroundUpName() const { return m_backgroundUpName; }
void setBackgroundUpName(const QString &value);
int backgroundDownIndex() const { return m_backgroundDownIndex; }
void setBackgroundDownIndex(int value);
QString backgroundDownName() const { return m_backgroundDownName; }
void setBackgroundDownName(const QString &value);
int glyphIndex() const { return m_glyphIndex; }
void setGlyphIndex(int value);
QString glyphName() const { return m_glyphName; }
void setGlyphName(const QString &value);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
GraphicSetItem *resolveItem(int index, const QString &name) const;
GraphicSet *m_graphicSet = nullptr;
int m_backgroundUpIndex = -1;
QString m_backgroundUpName;
int m_backgroundDownIndex = -1;
QString m_backgroundDownName;
int m_glyphIndex = -1;
QString m_glyphName;
};
} // namespace Cevo
+52
View File
@@ -0,0 +1,52 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QWidget>
#include <functional>
namespace Cevo {
// TButtonN equivalent: a 42x42 unit-selection button with its own
// Possible/Lit toggle model (distinct from ButtonBase's Down/Permanent),
// so it is a standalone widget rather than a ButtonBase subclass.
class ButtonN : public QWidget {
Q_OBJECT
public:
explicit ButtonN(QWidget *parent = nullptr);
bool possible() const { return m_possible; }
void setPossible(bool value);
bool lit() const { return m_lit; }
void setLit(bool value);
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
QString smartHint() const { return m_smartHint; }
void setSmartHint(const QString &value);
Dpi::Bitmap *graphic() const { return m_graphic; }
void setGraphic(Dpi::Bitmap *value) { m_graphic = value; }
Dpi::Bitmap *mask() const { return m_mask; }
void setMask(Dpi::Bitmap *value) { m_mask = value; }
Dpi::Bitmap *backGraphic() const { return m_backGraphic; }
void setBackGraphic(Dpi::Bitmap *value) { m_backGraphic = value; }
std::function<void()> onClick;
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
private:
Dpi::Bitmap *m_graphic = nullptr;
Dpi::Bitmap *m_mask = nullptr;
Dpi::Bitmap *m_backGraphic = nullptr;
bool m_possible = true;
bool m_lit = false;
int m_index = -1;
int m_backIndex = 1;
QString m_smartHint;
Dpi::Bitmap m_buffer;
};
} // namespace Cevo
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include "Dpi/DpiForms.h"
#include <QPoint>
#include <QString>
namespace Cevo {
// TDrawDlg equivalent: a borderless, custom-painted dialog that can be
// dragged by its title area and closed with Escape.
class DrawDlg : public Dpi::Form {
Q_OBJECT
public:
explicit DrawDlg(QWidget *parent = nullptr);
virtual void smartInvalidate();
void centerToScreen();
void centerToScreen(int w, int h);
protected:
int titleHeight = 0; // area (from the top) that can be used to drag the window
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void leaveEvent(QEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private:
QPoint m_moveFormPos;
QPoint m_moveMousePos;
bool m_moveActive = false;
};
// TBaseMessgDlg equivalent: a simple word-wrapped message box drawn with the
// game's own frame/background style.
class BaseMessgDlg : public DrawDlg {
Q_OBJECT
public:
explicit BaseMessgDlg(QWidget *parent = nullptr);
QString messageText;
protected:
static constexpr int Border = 3;
static constexpr int MessageLineSpacing = 20;
int lines = 0;
int topSpace = 0;
void paintEvent(QPaintEvent *event) override;
// Pass preview=true to just measure how many lines the text needs
// (fills `lines`) without drawing anything.
void splitText(bool preview);
void correctHeight();
};
} // namespace Cevo
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
enum {
eotBlinkOff = -1,
eotCancel = 0,
eotGray = 1,
eotBlinkOn = 2,
eotBackToNego = 3,
};
// TEOTButton equivalent: the End-Of-Turn button, animated by swapping
// ButtonIndex between the eot* states above.
class EOTButton : public ButtonBase {
Q_OBJECT
public:
explicit EOTButton(QWidget *parent = nullptr);
Dpi::Bitmap *tmpl() const { return m_template; }
void setTemplate(Dpi::Bitmap *value) { m_template = value; }
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
// Immediately repaints (bypassing the event queue) if the index changed,
// mirroring SetButtonIndexFast's use during time-critical animation.
void setButtonIndexFast(int value);
void setBack(Dpi::Canvas &canvas, int x, int y);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
Dpi::Bitmap *m_template = nullptr;
int m_index = -1;
Dpi::Bitmap m_buffer;
Dpi::Bitmap m_back;
};
} // namespace Cevo
+60
View File
@@ -0,0 +1,60 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QList>
#include <QRect>
#include <QString>
namespace Cevo {
class GraphicSet;
// TGraphicSetItem equivalent: one named sub-rectangle of a GraphicSet's
// sprite sheet.
class GraphicSetItem {
public:
QString name;
int left = 0;
int top = 0;
int width = 0;
int height = 0;
GraphicSet *graphicSet = nullptr;
QRect boundsRect() const { return QRect(left, top, width, height); }
void setBoundsRect(const QRect &rect);
};
// TGraphicSet equivalent: a sprite sheet (data) with its transparency mask
// (mask), plus a set of named item rectangles. Persisted as XML, though not
// in the same node layout as the original (custom WriteString/WriteInteger
// helper), so files are not binary-compatible with the original .grs format.
class GraphicSet {
public:
GraphicSet() = default;
~GraphicSet();
GraphicSet(const GraphicSet &) = delete;
GraphicSet &operator=(const GraphicSet &) = delete;
QString name;
Dpi::Bitmap data;
Dpi::Bitmap mask;
// Looks up by index first, falling back to name; nullptr (with a
// warning) if neither resolves to an item.
GraphicSetItem *item(const QString &itemName) const;
GraphicSetItem *searchByName(const QString &itemName) const;
GraphicSetItem *addNew(const QString &itemName);
const QList<GraphicSetItem *> &items() const { return m_items; }
void loadFromFile(const QString &fileName);
void saveToFile(const QString &fileName) const;
private:
QList<GraphicSetItem *> m_items;
};
constexpr const char *GraphicSetFileRootNode = "GraphicSet";
constexpr const char *GraphicSetFileExt = ".grs";
} // namespace Cevo
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include "Dpi/DpiStdCtrls.h"
#include <QStyledItemDelegate>
namespace Cevo {
// Paints the C-evo orange-on-black / blue-selection list style, since Qt's
// QListWidget has no OnDrawItem-style callback like TCustomListBox.
class ListBoxExDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
using QStyledItemDelegate::QStyledItemDelegate;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
// TListBoxEx equivalent.
class ListBoxEx : public Dpi::ListBox {
Q_OBJECT
public:
explicit ListBoxEx(QWidget *parent = nullptr);
};
} // namespace Cevo
+95
View File
@@ -0,0 +1,95 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QColor>
#include <QPoint>
#include <QRect>
#include <QString>
#include <array>
namespace Cevo {
class Texture;
class GraphicSet;
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);
enum class FontType { Normal, Small, Tiny, Caption, Button, Count };
// 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
// 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;
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);
// 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);
void btnFrame(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());
void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int height,
int formWidth = 0, int formHeight = 0);
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);
} // namespace Cevo
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QColor>
namespace Cevo {
// TTexture equivalent: a tiled background bitmap plus the UI palette colors
// associated with a given "age" (the game's tech-era visual theme), looked
// up from the Colors palette bitmap.
class Texture {
public:
Texture();
int age() const { return m_age; }
// Updates the palette colors from Cevo::Colors; does not (re)load the
// per-age background image, that stays an application-level concern
// (Directories::getGraphicsDir() + image()->loadFromFile() is not
// ported here). Call image().loadFromFile() explicitly afterwards.
void setAge(int value);
int width() const { return m_image.width(); }
int height() const { return m_image.height(); }
Dpi::Bitmap &image() { return m_image; }
Dpi::Canvas &canvas() { return m_image.canvas(); }
void assign(const Texture &source);
QColor colorBevelLight = Qt::black;
QColor colorBevelShade = Qt::black;
QColor colorTextLight = Qt::black;
QColor colorTextShade = Qt::black;
QColor colorLitText = Qt::black;
QColor colorMark = Qt::black;
QColor colorPage = Qt::black;
QColor colorCover = Qt::black;
private:
int m_age = -2;
Dpi::Bitmap m_image;
};
} // namespace Cevo
+19
View File
@@ -0,0 +1,19 @@
#pragma once
// Convenience umbrella header mirroring CevoComponents.pas: pulls in every
// Cevo:: widget so application code can simply `#include <Cevo/CevoWidgets.h>`.
#include "Cevo/CevoArea.h"
#include "Cevo/CevoBaseWin.h"
#include "Cevo/CevoButtonA.h"
#include "Cevo/CevoButtonB.h"
#include "Cevo/CevoButtonBase.h"
#include "Cevo/CevoButtonC.h"
#include "Cevo/CevoButtonG.h"
#include "Cevo/CevoButtonN.h"
#include "Cevo/CevoDrawDlg.h"
#include "Cevo/CevoEOTButton.h"
#include "Cevo/CevoGraphicSet.h"
#include "Cevo/CevoListBoxEx.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"