initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSpinBox>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
// TDpiSpinEdit equivalent.
|
||||
class SpinEdit : public QSpinBox {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QSpinBox::QSpinBox;
|
||||
};
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -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
|
||||
@@ -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"
|
||||
Reference in new issue
Block a user