summaryrefslogtreecommitdiffstats
path: root/sigmod
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-03-19 18:02:23 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-03-19 18:02:23 -0400
commitb318d695fddbfaa71755cec4c7d85e9e9bdca8f2 (patch)
tree887d32cc0e60babfc49cd1420bd19c12dc4a7070 /sigmod
parent86f5c9c6b4a3b76dd89e032f241e27508eaadf77 (diff)
downloadsigen-b318d695fddbfaa71755cec4c7d85e9e9bdca8f2.tar.gz
sigen-b318d695fddbfaa71755cec4c7d85e9e9bdca8f2.tar.xz
sigen-b318d695fddbfaa71755cec4c7d85e9e9bdca8f2.zip
Use QPainterPath for Effects and Warps on maps
Diffstat (limited to 'sigmod')
-rw-r--r--sigmod/CMakeLists.txt2
-rw-r--r--sigmod/MapEffect.cpp17
-rw-r--r--sigmod/MapEffect.h15
-rw-r--r--sigmod/MapWarp.cpp15
-rw-r--r--sigmod/MapWarp.h10
-rw-r--r--sigmod/Object.h20
6 files changed, 32 insertions, 47 deletions
diff --git a/sigmod/CMakeLists.txt b/sigmod/CMakeLists.txt
index 8863d037..e25af733 100644
--- a/sigmod/CMakeLists.txt
+++ b/sigmod/CMakeLists.txt
@@ -87,11 +87,13 @@ set_target_properties(sigmod
)
target_link_libraries(sigmod
${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
${QT_QTXML_LIBRARY}
sigcore
)
target_link_libraries(sigmod LINK_INTERFACE_LIBRARIES
${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
${QT_QTXML_LIBRARY}
sigcore
)
diff --git a/sigmod/MapEffect.cpp b/sigmod/MapEffect.cpp
index 411a52e1..dff6a370 100644
--- a/sigmod/MapEffect.cpp
+++ b/sigmod/MapEffect.cpp
@@ -39,7 +39,7 @@ MapEffect::MapEffect(const MapEffect& effect) :
MapEffect::MapEffect(const Map* parent, const int id) :
Object(parent, id),
m_name(""),
- m_area(0, 0, 32, 32),
+ m_area(),
m_skin(-1),
m_isGhost(false),
m_script("", "")
@@ -64,8 +64,7 @@ void MapEffect::validate()
TEST_BEGIN();
if (m_name.isEmpty())
emit(error("Name is empty"));
- TEST(area);
- if (m_area.height() || m_area.width())
+ if (m_area.isEmpty())
TEST(skin);
TEST_END();
}
@@ -92,25 +91,19 @@ QDomElement MapEffect::save() const
}
SETTER(MapEffect, QString&, Name, name)
-SETTER(MapEffect, QRect&, Area, area)
+SETTER(MapEffect, QPainterPath&, Area, area)
SETTER(MapEffect, int, Skin, skin)
SETTER(MapEffect, bool, IsGhost, isGhost)
SETTER(MapEffect, Script&, Script, script)
GETTER(MapEffect, QString, name)
-GETTER(MapEffect, QRect, area)
+GETTER(MapEffect, QPainterPath, area)
GETTER(MapEffect, int, skin)
GETTER(MapEffect, bool, isGhost)
GETTER(MapEffect, Script, script)
CHECK(MapEffect, QString&, name)
-CHECK_BEGIN(MapEffect, QRect&, area)
- const Map* map = qobject_cast<const Map*>(parent());
- TBOUNDS_MOD(area_x, 0, map->width() - 1, area.x())
- TBOUNDS_MOD(area_y, 0, map->height() - 1, area.y())
- TBOUNDS_MOD(area_width, 0, map->width() - area.x(), area.width())
- TBOUNDS_MOD(area_height, 0, map->height() - area.y(), area.height())
-CHECK_END()
+CHECK(MapEffect, QPainterPath&, area)
CHECK_INDEX(MapEffect, int, skin, game(), skin)
CHECK(MapEffect, bool, isGhost)
CHECK(MapEffect, Script&, script)
diff --git a/sigmod/MapEffect.h b/sigmod/MapEffect.h
index c00684bd..9c8f3a24 100644
--- a/sigmod/MapEffect.h
+++ b/sigmod/MapEffect.h
@@ -29,7 +29,7 @@
#include "Object.h"
// Qt includes
-#include <QtCore/QPoint>
+#include <QtGui/QPainterPath>
namespace Sigmod
{
@@ -105,12 +105,11 @@ class SIGMOD_EXPORT MapEffect : public Object
*/
void setName(const QString& name);
/**
- * Sets the area of the map the effect takes up. If the size is set to (0, 0),
- * the skin determines its size.
+ * Sets the area of the map the effect takes up. It is only used if the skin is not valid.
*
* \param area The area of the map the effect takes up.
*/
- void setArea(const QRect& area);
+ void setArea(const QPainterPath& area);
/**
* Sets the id of the skin used to represent the effect on the map.
*
@@ -144,9 +143,9 @@ class SIGMOD_EXPORT MapEffect : public Object
/**
* \sa setArea
*
- * \return The starting position of the effect.
+ * \return The area of the effect.
*/
- QRect area() const;
+ QPainterPath area() const;
/**
* \sa setSkin
*
@@ -167,7 +166,7 @@ class SIGMOD_EXPORT MapEffect : public Object
Sigcore::Script script() const;
bool nameCheck(const QString& name) const;
- bool areaCheck(const QRect& area) const;
+ bool areaCheck(const QPainterPath& area) const;
bool skinCheck(const int skin) const;
bool isGhostCheck(const bool isGhost) const;
bool scriptCheck(const Sigcore::Script& script) const;
@@ -175,7 +174,7 @@ class SIGMOD_EXPORT MapEffect : public Object
MapEffect& operator=(const MapEffect& rhs);
private:
QString m_name;
- QRect m_area;
+ QPainterPath m_area;
int m_skin;
bool m_isGhost;
Sigcore::Script m_script;
diff --git a/sigmod/MapWarp.cpp b/sigmod/MapWarp.cpp
index ac3906b1..b57edbd7 100644
--- a/sigmod/MapWarp.cpp
+++ b/sigmod/MapWarp.cpp
@@ -41,7 +41,7 @@ MapWarp::MapWarp(const MapWarp& warp) :
MapWarp::MapWarp(const Map* parent, const int id) :
Object(parent, id),
m_name(""),
- m_area(0, 0, 32, 32),
+ m_area(),
m_type(Door),
m_toMap(INT_MAX),
m_toWarp(INT_MAX),
@@ -67,7 +67,6 @@ void MapWarp::validate()
TEST_BEGIN();
if (m_name.isEmpty())
emit(error("Name is empty"));
- TEST(area);
TEST(toMap);
TEST(toWarp);
TEST_END();
@@ -97,27 +96,21 @@ QDomElement MapWarp::save() const
}
SETTER(MapWarp, QString&, Name, name)
-SETTER(MapWarp, QRect&, Area, area)
+SETTER(MapWarp, QPainterPath&, Area, area)
SETTER(MapWarp, Type, Type, type)
SETTER(MapWarp, int, ToMap, toMap)
SETTER(MapWarp, int, ToWarp, toWarp)
SETTER(MapWarp, Script&, Script, script)
GETTER(MapWarp, QString, name)
-GETTER(MapWarp, QRect, area)
+GETTER(MapWarp, QPainterPath, area)
GETTER(MapWarp, MapWarp::Type, type)
GETTER(MapWarp, int, toMap)
GETTER(MapWarp, int, toWarp)
GETTER(MapWarp, Script, script)
CHECK(MapWarp, QString&, name)
-CHECK_BEGIN(MapWarp, QRect&, area)
- const Map* map = qobject_cast<const Map*>(parent());
- TBOUNDS_MOD(area_x, 0, map->width() - 1, area.x())
- TBOUNDS_MOD(area_y, 0, map->height() - 1, area.y())
- TBOUNDS_MOD(area_width, 1, map->width() - area.x(), area.width())
- TBOUNDS_MOD(area_height, 1, map->height() - area.y(), area.height())
-CHECK_END()
+CHECK(MapWarp, QPainterPath&, area)
CHECK(MapWarp, Type, type)
CHECK_INDEX(MapWarp, int, toMap, game(), map)
CHECK_BEGIN(MapWarp, int, toWarp)
diff --git a/sigmod/MapWarp.h b/sigmod/MapWarp.h
index 9009d7bc..f8d13a6e 100644
--- a/sigmod/MapWarp.h
+++ b/sigmod/MapWarp.h
@@ -29,7 +29,7 @@
#include "Object.h"
// Qt includes
-#include <QtCore/QRect>
+#include <QtGui/QPainterPath>
namespace Sigmod
{
@@ -126,7 +126,7 @@ class SIGMOD_EXPORT MapWarp : public Object
*
* \param area The area of the map the warp takes up.
*/
- void setArea(const QRect& area);
+ void setArea(const QPainterPath& area);
/**
* Sets the type of the warp.
*
@@ -169,7 +169,7 @@ class SIGMOD_EXPORT MapWarp : public Object
*
* \return The area that the warp takes up.
*/
- QRect area() const;
+ QPainterPath area() const;
/**
* \sa setType
*
@@ -196,7 +196,7 @@ class SIGMOD_EXPORT MapWarp : public Object
Sigcore::Script script() const;
bool nameCheck(const QString& name) const;
- bool areaCheck(const QRect& area) const;
+ bool areaCheck(const QPainterPath& area) const;
bool typeCheck(const Type type) const;
bool toMapCheck(const int toMap) const;
bool toWarpCheck(const int toWarp) const;
@@ -205,7 +205,7 @@ class SIGMOD_EXPORT MapWarp : public Object
MapWarp& operator=(const MapWarp& rhs);
private:
QString m_name;
- QRect m_area;
+ QPainterPath m_area;
Type m_type;
int m_toMap;
int m_toWarp;
diff --git a/sigmod/Object.h b/sigmod/Object.h
index b96c2fc9..e7e0b4d1 100644
--- a/sigmod/Object.h
+++ b/sigmod/Object.h
@@ -34,10 +34,10 @@
#include <QtCore/QBuffer>
#include <QtCore/QObject>
#include <QtCore/QPoint>
-#include <QtCore/QRect>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtCore/QVarLengthArray>
+#include <QtGui/QPainterPath>
#include <QtXml/QDomElement>
// C includes
@@ -199,12 +199,10 @@ template<> inline void loadValue<QPoint>(const QDomElement& xml, QPoint* value)
value->setY(xml.attribute("y", "0").toInt());
}
-template<> inline void loadValue<QRect>(const QDomElement& xml, QRect* value)
+template<> inline void loadValue<QPainterPath>(const QDomElement& xml, QPainterPath* value)
{
- value->setX(xml.attribute("x", "0").toInt());
- value->setY(xml.attribute("y", "0").toInt());
- value->setWidth(xml.attribute("width", "0").toInt());
- value->setHeight(xml.attribute("height", "0").toInt());
+ QDataStream stream(QByteArray::fromBase64(xml.firstChild().toText().data().toUtf8()));
+ stream >> *value;
}
template<> inline void loadValue<QByteArray>(const QDomElement& xml, QByteArray* value)
@@ -322,13 +320,13 @@ template<> inline QDomElement saveValue<QPoint>(const QString& name, const QPoin
return element;
}
-template<> inline QDomElement saveValue<QRect>(const QString& name, const QRect& value)
+template<> inline QDomElement saveValue<QPainterPath>(const QString& name, const QPainterPath& value)
{
+ QByteArray array;
+ QDataStream stream(&array, QIODevice::WriteOnly);
+ stream << value;
QDomElement element = QDomDocument().createElement(name);
- element.setAttribute("x", value.x());
- element.setAttribute("y", value.y());
- element.setAttribute("width", value.width());
- element.setAttribute("height", value.height());
+ element.appendChild(QDomDocument().createTextNode(array.toBase64()));
return element;
}