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

+90
View File
@@ -0,0 +1,90 @@
#pragma once
#include <QSplitter>
#include <QTabWidget>
#include <QToolBar>
#include <QTreeWidget>
#include <functional>
namespace Dpi {
enum class ViewStyle { Icon, List, Report, SmallIcon };
// TListView equivalent, backed by QTreeWidget: root-level items act as rows
// and the header provides Columns; OnColumnClick maps to the header's
// sectionClicked signal.
class ListView : public QTreeWidget {
Q_OBJECT
public:
explicit ListView(QWidget *parent = nullptr);
ViewStyle viewStyle() const { return m_viewStyle; }
void setViewStyle(ViewStyle value);
bool checkboxes() const { return m_checkboxes; }
void setCheckboxes(bool value);
// Mirrors Dpi.ComCtrls.TDpiLVCustomDrawItemEvent.
std::function<void(QTreeWidgetItem *, bool &defaultDraw)> onCustomDrawItem;
signals:
void columnClicked(int column);
void selectionChanged();
private:
ViewStyle m_viewStyle = ViewStyle::Report;
bool m_checkboxes = false;
};
// TToolBar equivalent.
class ToolBar : public QToolBar {
Q_OBJECT
public:
explicit ToolBar(QWidget *parent = nullptr);
int buttonHeight() const;
void setButtonHeight(int value);
int buttonWidth() const;
void setButtonWidth(int value);
};
// TCoolBand equivalent: per-band size constraints applied to a child widget
// hosted in a CoolBar.
struct CoolBand {
QWidget *widget = nullptr;
int minWidth = 100;
int minHeight = 25;
};
// TCoolBar equivalent. Qt has no direct "rebar" control; a horizontal
// QSplitter with one segment per band gives the closest user-draggable,
// resizable band behavior.
class CoolBar : public QSplitter {
Q_OBJECT
public:
explicit CoolBar(QWidget *parent = nullptr);
void addBand(const CoolBand &band);
int bandCount() const { return count(); }
bool themed() const { return m_themed; }
void setThemed(bool value) { m_themed = value; }
void beginUpdate();
void endUpdate();
private:
bool m_themed = true;
};
// TPageControl equivalent.
class PageControl : public QTabWidget {
Q_OBJECT
public:
explicit PageControl(QWidget *parent = nullptr);
int pageCount() const { return count(); }
QWidget *page(int index) const { return widget(index); }
};
} // namespace Dpi
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include <QPoint>
#include <QRect>
#include <QSize>
#include <QString>
namespace Dpi {
// Mirrors the role of Dpi.Common.pas / its ScreenInfo record: conversion
// between the DPI-independent coordinate space used for widget geometry
// (Qt's logical / device-independent pixels) and the native physical pixel
// space used by raw pixel buffers (QImage scanlines, screen grabs, etc.).
// Qt widgets already scale logical pixels to the physical display
// automatically, so these helpers are only needed where code must address
// physical pixels directly (e.g. custom raster rendering).
class ScreenInfo {
public:
// Effective DPI of the primary screen (96 == 100% scaling), kept for API
// parity with the Pascal ScreenInfo.Dpi property.
static int dpi();
// Multiplier from DPI-independent to native/physical pixels.
static double toNative();
// Multiplier from native/physical to DPI-independent pixels.
static double fromNative();
};
int scaleToNative(int value);
int scaleFromNative(int value);
int scaleToNativeDist(int base, int value);
QPoint scalePointToNative(const QPoint &value);
QPoint scalePointFromNative(const QPoint &value);
QSize scaleSizeToNative(const QSize &value);
QSize scaleSizeFromNative(const QSize &value);
QRect scaleRectToNative(const QRect &value);
QRect scaleRectFromNative(const QRect &value);
double scaleFloatToNative(double value);
double scaleFloatFromNative(double value);
void writeLog(const QString &text);
} // namespace Dpi
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include <QIcon>
#include <QList>
#include <QPoint>
#include <Qt>
namespace Dpi {
// Type aliases kept for parity with Dpi.Controls.pas; Qt's own enums already
// cover these concepts so no custom type is introduced for them.
using Align = Qt::Alignment;
enum class BorderStyle {
None,
Single,
};
// TImageList equivalent: a simple named collection of icons at a given size.
class ImageList {
public:
explicit ImageList(int width = 16, int height = 16) : m_width(width), m_height(height) {}
int width() const { return m_width; }
void setWidth(int value) { m_width = value; }
int height() const { return m_height; }
void setHeight(int value) { m_height = value; }
int count() const { return m_icons.count(); }
int add(const QIcon &icon);
QIcon icon(int index) const;
void clear() { m_icons.clear(); }
private:
int m_width;
int m_height;
QList<QIcon> m_icons;
};
// TMouse equivalent.
class Mouse {
public:
static QPoint cursorPos();
static void setCursorPos(const QPoint &value);
};
} // namespace Dpi
+56
View File
@@ -0,0 +1,56 @@
#pragma once
#include <QFrame>
#include <QLabel>
#include <QPixmap>
#include <QTimer>
#include <QWidget>
#include <functional>
namespace Dpi {
class Canvas;
// TTimer equivalent: QTimer already matches the VCL API closely.
using Timer = QTimer;
// TPanel equivalent.
class Panel : public QFrame {
Q_OBJECT
public:
explicit Panel(QWidget *parent = nullptr);
};
// TPaintBox equivalent: a plain widget exposing an OnPaint callback bound to
// a Dpi::Canvas, since custom drawing in Qt happens through QPainter in
// paintEvent rather than through a persistent handle-based canvas.
class PaintBox : public QWidget {
Q_OBJECT
public:
explicit PaintBox(QWidget *parent = nullptr);
std::function<void(Canvas &)> onPaint;
protected:
void paintEvent(QPaintEvent *event) override;
};
// TImage equivalent.
class Image : public QLabel {
Q_OBJECT
public:
explicit Image(QWidget *parent = nullptr);
bool stretch() const { return m_stretch; }
void setStretch(bool value);
void setPicture(const QPixmap &pixmap);
private:
void updatePixmap();
bool m_stretch = false;
QPixmap m_source;
};
} // namespace Dpi
+106
View File
@@ -0,0 +1,106 @@
#pragma once
#include <QRect>
#include <QString>
#include <QWidget>
#include <functional>
class QCloseEvent;
class QShowEvent;
class QHideEvent;
class QEventLoop;
class QScreen;
namespace Dpi {
// Modal result constants equivalent (mrNone, mrOk, mrCancel, ...).
enum class ModalResult {
None,
Ok,
Cancel,
Abort,
Retry,
Ignore,
Yes,
No,
All,
NoToAll,
YesToAll,
Close,
};
// TForm equivalent. Subclass this the same way game windows subclassed
// Dpi.Forms.TForm; ShowModal()/close handling mirror the VCL/LCL semantics.
class Form : public QWidget {
Q_OBJECT
public:
explicit Form(QWidget *parent = nullptr);
~Form() override;
ModalResult showModal();
ModalResult modalResult() const { return m_modalResult; }
void setModalResult(ModalResult value) { m_modalResult = value; }
// TNotifyEvent / TCloseEvent equivalents.
std::function<void()> onShow;
std::function<void()> onHide;
std::function<void()> onActivate;
std::function<void()> onDeactivate;
std::function<bool()> onCloseQuery; // return false to veto the close
std::function<void()> onClose;
protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
void closeEvent(QCloseEvent *event) override;
bool event(QEvent *event) override;
private:
ModalResult m_modalResult = ModalResult::None;
QEventLoop *m_modalLoop = nullptr;
};
// TApplication equivalent: thin facade over QApplication.
class Application {
public:
static void run();
static void processMessages();
static void terminate();
static Form *mainForm() { return s_mainForm; }
static void setMainForm(Form *form) { s_mainForm = form; }
static QString title();
static void setTitle(const QString &value);
static QString exeName();
private:
static Form *s_mainForm;
};
// TMonitor equivalent.
class Monitor {
public:
explicit Monitor(QScreen *screen) : m_screen(screen) {}
int left() const;
int top() const;
int width() const;
int height() const;
QRect boundsRect() const;
private:
QScreen *m_screen;
};
// TScreen equivalent: thin facade over QGuiApplication screen state.
class Screen {
public:
static int formCount();
static Form *activeForm();
static int dpi();
static int pixelsPerInch();
static int width();
static int height();
static QRect desktopRect();
static Monitor primaryMonitor();
};
} // namespace Dpi
+204
View File
@@ -0,0 +1,204 @@
#pragma once
#include <QBrush>
#include <QColor>
#include <QFont>
#include <QImage>
#include <QPaintDevice>
#include <QPainter>
#include <QPen>
#include <QPolygon>
#include <QSize>
#include <QString>
#include <functional>
namespace Dpi {
// TFont equivalent. Qt already renders fonts DPI-correctly, so sizes here are
// plain point sizes with no extra scaling applied.
class Font {
public:
Font();
QString name() const;
void setName(const QString &value);
bool bold() const;
void setBold(bool value);
bool italic() const;
void setItalic(bool value);
bool underline() const;
void setUnderline(bool value);
int size() const;
void setSize(int value);
int height() const;
void setHeight(int value);
QColor color() const;
void setColor(const QColor &value);
QSize getTextSize(const QString &text) const;
int getTextWidth(const QString &text) const;
int getTextHeight(const QString &text) const;
void assign(const Font &source);
QFont toQFont() const { return m_font; }
// TNotifyEvent equivalent.
std::function<void()> onChange;
private:
void changed();
QFont m_font;
QColor m_color;
};
// TPen equivalent.
class Pen {
public:
Pen();
QColor color() const { return m_color; }
void setColor(const QColor &value) { m_color = value; }
Qt::PenStyle style() const { return m_style; }
void setStyle(Qt::PenStyle value) { m_style = value; }
int width() const { return m_width; }
void setWidth(int value) { m_width = value; }
void assign(const Pen &source);
QPen toQPen() const;
private:
QColor m_color;
Qt::PenStyle m_style;
int m_width;
};
// TBrush equivalent.
class Brush {
public:
Brush();
QColor color() const { return m_color; }
void setColor(const QColor &value) { m_color = value; }
Qt::BrushStyle style() const { return m_style; }
void setStyle(Qt::BrushStyle value) { m_style = value; }
void assign(const Brush &source);
QBrush toQBrush() const;
private:
QColor m_color;
Qt::BrushStyle m_style;
};
// TCanvas equivalent, bound to a QPaintDevice (widget, pixmap or image).
// Unlike VCL/LCL, Qt only allows painting through a QPainter that is either
// explicitly begin()/end()-ed (for off-screen devices such as QImage) or
// handed to us already active from within a paintEvent (see bind()).
class Canvas {
public:
Canvas();
explicit Canvas(QPaintDevice *device);
~Canvas();
void setDevice(QPaintDevice *device);
QPaintDevice *device() const { return m_device; }
void begin();
void end();
bool active() const { return m_painter != nullptr; }
// Use an already-active, externally owned painter (typically supplied by
// QWidget::paintEvent). The canvas does not take ownership of it.
void bind(QPainter *painter);
void unbind();
Pen &pen() { return m_pen; }
Brush &brush() { return m_brush; }
Font &font() { return m_font; }
int width() const;
int height() const;
QColor pixel(int x, int y) const;
void setPixel(int x, int y, const QColor &color);
void moveTo(int x, int y);
void lineTo(int x, int y);
void line(int x1, int y1, int x2, int y2);
void rectangle(int x1, int y1, int x2, int y2);
void ellipse(int x1, int y1, int x2, int y2);
void roundRect(int x1, int y1, int x2, int y2, int rx, int ry);
void polygon(const QPolygon &points);
void polyline(const QPolygon &points);
void textOut(int x, int y, const QString &text);
int textWidth(const QString &text) const;
int textHeight(const QString &text) const;
QSize textExtent(const QString &text) const;
void fillRect(const QRect &rect);
void frameRect(const QRect &rect);
void draw(int x, int y, const QImage &image);
void stretchDraw(const QRect &rect, const QImage &image);
void copyRect(const QRect &dest, Canvas &source, const QRect &sourceRect);
private:
QPainter *painter();
void applyPenBrush();
QPaintDevice *m_device = nullptr;
QPainter *m_painter = nullptr;
bool m_ownsPainter = false;
QPoint m_penPos;
Pen m_pen;
Brush m_brush;
Font m_font;
};
// TBitmap equivalent, backed by a QImage in ARGB32 format for transparency
// support.
class Bitmap {
public:
Bitmap();
Bitmap(int width, int height);
void setSize(int width, int height);
int width() const { return m_image.width(); }
int height() const { return m_image.height(); }
QImage &image() { return m_image; }
const QImage &image() const { return m_image; }
Canvas &canvas() { return m_canvas; }
bool transparent() const { return m_transparent; }
void setTransparent(bool value) { m_transparent = value; }
QColor transparentColor() const { return m_transparentColor; }
void setTransparentColor(const QColor &value);
void loadFromFile(const QString &fileName);
void saveToFile(const QString &fileName) const;
void assign(const Bitmap &source);
private:
QImage m_image;
Canvas m_canvas;
bool m_transparent = false;
QColor m_transparentColor;
};
// TPicture equivalent: a simple container that owns a Bitmap.
class Picture {
public:
Bitmap &bitmap() { return m_bitmap; }
const Bitmap &bitmap() const { return m_bitmap; }
void loadFromFile(const QString &fileName);
private:
Bitmap m_bitmap;
};
} // namespace Dpi
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <QTableWidget>
namespace Dpi {
// TStringGrid equivalent.
class StringGrid : public QTableWidget {
Q_OBJECT
public:
explicit StringGrid(QWidget *parent = nullptr);
QString cell(int col, int row) const;
void setCell(int col, int row, const QString &value);
int fixedRows() const { return m_fixedRows; }
void setFixedRows(int value);
int fixedCols() const { return m_fixedCols; }
void setFixedCols(int value) { m_fixedCols = value; }
QRect cellRect(int col, int row) const;
private:
int m_fixedRows = 0;
int m_fixedCols = 0;
};
} // namespace Dpi
+96
View File
@@ -0,0 +1,96 @@
#pragma once
#include <QAction>
#include <QKeySequence>
#include <QList>
#include <QMenu>
#include <QMenuBar>
#include <QObject>
#include <QPoint>
#include <functional>
namespace Dpi {
// TMenuItem equivalent: wraps a QAction and, lazily, a QMenu used to host
// child items when the item acts as a submenu.
class MenuItem : public QObject {
Q_OBJECT
public:
explicit MenuItem(const QString &caption = QString(), QObject *parent = nullptr);
// Wraps an existing QMenu (e.g. one returned by QMenuBar::addMenu). When
// ownsMenu is true, this item deletes the menu on destruction.
explicit MenuItem(QMenu *existingMenu, bool ownsMenu = false, QObject *parent = nullptr);
// Root item for a QMenuBar: add() creates top-level bar menus.
explicit MenuItem(QMenuBar *bar, QObject *parent = nullptr);
~MenuItem() override;
QAction *action() const { return m_action; }
QMenu *submenu();
QString caption() const { return m_action ? m_action->text() : QString(); }
void setCaption(const QString &value) { if (m_action) m_action->setText(value); }
bool enabled() const { return m_action ? m_action->isEnabled() : true; }
void setEnabled(bool value) { if (m_action) m_action->setEnabled(value); }
bool visible() const { return m_action ? m_action->isVisible() : true; }
void setVisible(bool value) { if (m_action) m_action->setVisible(value); }
bool checked() const { return m_action && m_action->isChecked(); }
void setChecked(bool value) { if (m_action) m_action->setChecked(value); }
bool radioItem() const { return m_radioItem; }
void setRadioItem(bool value);
int groupIndex() const { return m_groupIndex; }
void setGroupIndex(int value) { m_groupIndex = value; }
QKeySequence shortCut() const { return m_action ? m_action->shortcut() : QKeySequence(); }
void setShortCut(const QKeySequence &value) { if (m_action) m_action->setShortcut(value); }
MenuItem *add(const QString &caption);
void insert(int index, MenuItem *item);
void remove(MenuItem *item);
void deleteItem(int index);
void clear();
int indexOf(MenuItem *item) const { return m_items.indexOf(item); }
int count() const { return m_items.count(); }
MenuItem *items(int index) const { return m_items.value(index); }
void click();
// TNotifyEvent equivalent.
std::function<void()> onClick;
private:
QAction *m_action = nullptr;
QMenu *m_submenu = nullptr;
QMenuBar *m_bar = nullptr;
bool m_ownsSubmenu = false;
QList<MenuItem *> m_items;
bool m_radioItem = false;
int m_groupIndex = 0;
};
// TMenu equivalent (a window's main menu bar).
class Menu {
public:
explicit Menu(QMenuBar *bar) : m_root(new MenuItem(bar)) {}
~Menu() { delete m_root; }
MenuItem &items() { return *m_root; }
private:
MenuItem *m_root;
};
// TPopupMenu equivalent.
class PopupMenu : public MenuItem {
Q_OBJECT
public:
explicit PopupMenu(QObject *parent = nullptr);
bool autoPopup() const { return m_autoPopup; }
void setAutoPopup(bool value) { m_autoPopup = value; }
void popup(const QPoint &pos);
private:
bool m_autoPopup = true;
};
QKeySequence shortCut(int key, Qt::KeyboardModifiers modifiers);
} // namespace Dpi
+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include <QImage>
namespace Dpi {
// Mirrors Dpi.PixelPointer.pas / NativePixelPointer.pas: a cursor for fast
// pixel-by-pixel iteration over a 32-bit ARGB QImage, addressing native
// (physical) pixels directly. The image must use QImage::Format_ARGB32 (or
// Format_ARGB32_Premultiplied) for the scanline arithmetic below to be valid.
class PixelPointer {
public:
PixelPointer() = default;
PixelPointer(QImage *image, int baseX, int baseY);
void setXY(int x, int y);
void setX(int x);
void nextPixel();
void previousPixel();
void nextLine();
void previousLine();
bool posValid() const;
QRgb pixelARGB() const;
void setPixelARGB(QRgb value);
QRgb pixelRGB() const; // alpha forced to 0xFF
void setPixelRGB(QRgb value);
int x() const { return m_x; }
int y() const { return m_y; }
private:
QImage *m_image = nullptr;
int m_x = 0;
int m_y = 0;
int m_width = 0;
int m_height = 0;
};
} // namespace Dpi
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <QSpinBox>
namespace Dpi {
// TDpiSpinEdit equivalent.
class SpinEdit : public QSpinBox {
Q_OBJECT
public:
using QSpinBox::QSpinBox;
};
} // namespace Dpi
+77
View File
@@ -0,0 +1,77 @@
#pragma once
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QListWidget>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollBar>
#include <QStringList>
namespace Dpi {
// TEdit equivalent.
class Edit : public QLineEdit {
Q_OBJECT
public:
using QLineEdit::QLineEdit;
};
// TMemo equivalent; adds a TStrings-like Lines accessor over QPlainTextEdit.
class Memo : public QPlainTextEdit {
Q_OBJECT
public:
using QPlainTextEdit::QPlainTextEdit;
QStringList lines() const;
void setLines(const QStringList &value);
};
// TComboBox equivalent.
class ComboBox : public QComboBox {
Q_OBJECT
public:
using QComboBox::QComboBox;
};
// TCheckBox equivalent.
class CheckBox : public QCheckBox {
Q_OBJECT
public:
using QCheckBox::QCheckBox;
};
// TRadioButton equivalent.
class RadioButton : public QRadioButton {
Q_OBJECT
public:
using QRadioButton::QRadioButton;
};
// TButton equivalent.
class Button : public QPushButton {
Q_OBJECT
public:
using QPushButton::QPushButton;
};
// TListBox equivalent.
class ListBox : public QListWidget {
Q_OBJECT
public:
using QListWidget::QListWidget;
QStringList items() const;
void setItems(const QStringList &value);
};
// TScrollBar equivalent.
class ScrollBar : public QScrollBar {
Q_OBJECT
public:
using QScrollBar::QScrollBar;
};
} // namespace Dpi
+18
View File
@@ -0,0 +1,18 @@
#pragma once
// Convenience umbrella header mirroring the DpiControls.lpk package: pulls in
// every Dpi:: widget/graphics wrapper so application code can simply
// `#include <Dpi/DpiWidgets.h>`, the same way Pascal units did `uses
// DpiControls, Dpi.StdCtrls, ...`.
#include "Dpi/DpiCommon.h"
#include "Dpi/DpiComCtrls.h"
#include "Dpi/DpiControls.h"
#include "Dpi/DpiExtCtrls.h"
#include "Dpi/DpiForms.h"
#include "Dpi/DpiGraphics.h"
#include "Dpi/DpiGrids.h"
#include "Dpi/DpiMenus.h"
#include "Dpi/DpiPixelPointer.h"
#include "Dpi/DpiSpin.h"
#include "Dpi/DpiStdCtrls.h"