#pragma once #include "Dpi/DpiGraphics.h" #include #include #include 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 &items() const { return m_items; } void loadFromFile(const QString &fileName); void saveToFile(const QString &fileName) const; private: QList m_items; }; constexpr const char *GraphicSetFileRootNode = "GraphicSet"; constexpr const char *GraphicSetFileExt = ".grs"; } // namespace Cevo