Files
c-evo-evo/widget/include/Cevo/CevoGraphicSet.h
T

61 lines
1.7 KiB
C++

#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