MinetestMapperGUI/geometry.h

63 lines
1.7 KiB
C
Raw Normal View History

2016-12-14 01:00:35 -08:00
#ifndef GEOMETRY_H
#define GEOMETRY_H
2017-03-06 01:00:41 -08:00
#include <QDebug>
2016-12-14 01:00:35 -08:00
#include <QMap>
#include <QMetaEnum>
#include <QObject>
2016-12-14 01:00:35 -08:00
#include <QRegularExpression>
class Geometry : public QObject
2016-12-14 01:00:35 -08:00
{
Q_OBJECT
2016-12-14 01:00:35 -08:00
public:
enum Format
{
FormatKeep = -2, // Special value used when setting geometry: don't change current format.
2016-12-14 01:00:35 -08:00
FormatUnknown = -1,
FormatNone = 0,
CenterDimensions = 1,
CornerDimensions = 2,
Corners = 3,
FormatCustom,
FormatMax
};
Q_ENUM(Format)
static const QMetaEnum metaEnumFormat;
2016-12-14 01:00:35 -08:00
static const char *formatName(Geometry::Format id);
2016-12-14 01:00:35 -08:00
static Geometry::Format formatId(const QString &name);
static Geometry::Format formatId(const char *name);
2016-12-14 01:00:35 -08:00
int center[2];
int dimension[2];
int corner[2][2];
Geometry(void) { setMax(); }
Geometry(const char *s) { set(s); }
Geometry(const QString &s) { set(s); }
// Geometry(const Geometry &g);
2016-12-14 01:00:35 -08:00
2017-03-06 01:00:41 -08:00
Geometry::Format set(const QString &str);
2016-12-14 01:00:35 -08:00
void setMax(void);
void setCenterDimensions(int cx, int cy, int dx, int dy);
void setCornerDimensions(int cx, int cy, int dx, int dy);
void setCorners(int c0x, int c0y, int c1x, int c1y);
QString getString(Geometry::Format format = Geometry::FormatNone);
2016-12-14 01:00:35 -08:00
private:
static const QRegularExpression corners;
static const QRegularExpression centerDimension;
static const QRegularExpression cornerDimension;
static const QRegularExpression cornerDimensionAlternate;
2016-12-14 01:00:35 -08:00
bool adjustCorners(void);
void computeCorner0(void);
void computeCorner1(void);
void computeCenter(void); // Depends dimensions to be correct !
2016-12-14 01:00:35 -08:00
void computeDimensions(void);
2017-01-04 02:08:11 -08:00
Format format = FormatNone;
2016-12-14 01:00:35 -08:00
};
#endif // GEOMETRY_H