zoomedit:
* New data interfaces, yay! Levels should now be completely editable * Fixed some -Wextra warnings
This commit is contained in:
parent
7fa8e4b4fa
commit
184c6305a6
10 changed files with 189 additions and 95 deletions
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "Gate.h"
|
||||
#include "Triangle.h"
|
||||
|
||||
namespace ZoomEdit {
|
||||
namespace Data {
|
||||
|
@ -29,7 +30,7 @@ Gate::Gate(xmlpp::Element *node) : gateNode(node) {
|
|||
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
|
||||
|
||||
if(tNode)
|
||||
triangles.push_back(Triangle(tNode));
|
||||
triangles.push_back(new Triangle(tNode));
|
||||
}
|
||||
|
||||
id = node->get_attribute_value("id");
|
||||
|
@ -37,5 +38,40 @@ Gate::Gate(xmlpp::Element *node) : gateNode(node) {
|
|||
room2 = node->get_attribute_value("room2");
|
||||
}
|
||||
|
||||
Gate::~Gate() {
|
||||
for(std::list<Triangle*>::iterator t = triangles.begin(); t != triangles.end(); ++t)
|
||||
delete *t;
|
||||
}
|
||||
|
||||
Triangle* Gate::addTriangle() {
|
||||
xmlpp::Element *tNode = gateNode->add_child("triangle");
|
||||
|
||||
xmlpp::Element *node = tNode->add_child("vertex");
|
||||
node->set_attribute("x", "0.0");
|
||||
node->set_attribute("y", "0.0");
|
||||
node->set_attribute("z", "0.0");
|
||||
|
||||
node = tNode->add_child("vertex");
|
||||
node->set_attribute("x", "0.0");
|
||||
node->set_attribute("y", "0.0");
|
||||
node->set_attribute("z", "0.0");
|
||||
|
||||
node = tNode->add_child("vertex");
|
||||
node->set_attribute("x", "0.0");
|
||||
node->set_attribute("y", "0.0");
|
||||
node->set_attribute("z", "0.0");
|
||||
|
||||
Triangle *t = new Triangle(tNode);
|
||||
triangles.push_back(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void Gate::removeTriangle(Triangle *t) {
|
||||
gateNode->remove_child(t->getNode());
|
||||
triangles.remove(t);
|
||||
delete t;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,27 +20,37 @@
|
|||
#ifndef ZOOMEDIT_DATA_GATE_H_
|
||||
#define ZOOMEDIT_DATA_GATE_H_
|
||||
|
||||
#include "Triangle.h"
|
||||
#include <list>
|
||||
#include <libxml++/nodes/element.h>
|
||||
|
||||
namespace ZoomEdit {
|
||||
namespace Data {
|
||||
|
||||
class Triangle;
|
||||
|
||||
class Gate {
|
||||
private:
|
||||
std::list<Triangle> triangles;
|
||||
std::list<Triangle*> triangles;
|
||||
xmlpp::Element *gateNode;
|
||||
|
||||
Glib::ustring id;
|
||||
Glib::ustring room1, room2;
|
||||
|
||||
// Prevent shallow copy
|
||||
Gate(const Gate &o);
|
||||
Gate& operator=(const Gate &o);
|
||||
|
||||
public:
|
||||
Gate(xmlpp::Element *node);
|
||||
virtual ~Gate();
|
||||
|
||||
const std::list<Triangle>& getTriangles() {
|
||||
const std::list<Triangle*>& getTriangles() {
|
||||
return triangles;
|
||||
}
|
||||
|
||||
Triangle* addTriangle();
|
||||
void removeTriangle(Triangle *t);
|
||||
|
||||
const Glib::ustring& getId() const {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
|
||||
#include "Level.h"
|
||||
#include "Room.h"
|
||||
#include "Gate.h"
|
||||
#include "Texture.h"
|
||||
|
||||
namespace ZoomEdit {
|
||||
namespace Data {
|
||||
|
@ -32,11 +35,8 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
|
|||
for(xmlpp::Node::NodeList::iterator room = nodeList.begin(); room != nodeList.end(); ++room) {
|
||||
xmlpp::Element *roomNode = dynamic_cast<xmlpp::Element*>(*room);
|
||||
|
||||
if(roomNode) {
|
||||
Room room(roomNode);
|
||||
|
||||
rooms.insert(std::make_pair(room.getId(), room));
|
||||
}
|
||||
if(roomNode)
|
||||
rooms.push_back(new Room(roomNode));
|
||||
}
|
||||
|
||||
nodeList = gatesNode->get_children("gate");
|
||||
|
@ -44,11 +44,8 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
|
|||
for(xmlpp::Node::NodeList::iterator gate = nodeList.begin(); gate != nodeList.end(); ++gate) {
|
||||
xmlpp::Element *gateNode = dynamic_cast<xmlpp::Element*>(*gate);
|
||||
|
||||
if(gateNode) {
|
||||
Gate gate(gateNode);
|
||||
|
||||
gates.insert(std::make_pair(gate.getId(), gate));
|
||||
}
|
||||
if(gateNode)
|
||||
gates.push_back(new Gate(gateNode));
|
||||
}
|
||||
|
||||
nodeList = texturesNode->get_children("texture");
|
||||
|
@ -56,22 +53,23 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
|
|||
for(xmlpp::Node::NodeList::iterator tex = nodeList.begin(); tex != nodeList.end(); ++tex) {
|
||||
xmlpp::Element *texNode = dynamic_cast<xmlpp::Element*>(*tex);
|
||||
|
||||
if(texNode) {
|
||||
Texture tex(texNode);
|
||||
|
||||
textures.insert(std::make_pair(tex.getId(), tex));
|
||||
}
|
||||
if(texNode)
|
||||
textures.push_back(new Texture(texNode));
|
||||
}
|
||||
}
|
||||
|
||||
Room* Level::getRoom(const Glib::ustring &id) {
|
||||
std::map<Glib::ustring,Room>::iterator room = rooms.find(id);
|
||||
return (room != rooms.end()) ? &room->second : NULL;
|
||||
Level::~Level() {
|
||||
for(std::list<Room*>::iterator room = rooms.begin(); room != rooms.end(); ++room)
|
||||
delete *room;
|
||||
}
|
||||
|
||||
const Room* Level::getRoom(const Glib::ustring &id) const {
|
||||
std::map<Glib::ustring,Room>::const_iterator room = rooms.find(id);
|
||||
return (room != rooms.end()) ? &room->second : NULL;
|
||||
Room* Level::getRoom(const Glib::ustring &id) const {
|
||||
for(std::list<Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) {
|
||||
if((*room)->getId() == id)
|
||||
return *room;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Room* Level::addRoom(const Glib::ustring &id) {
|
||||
|
@ -79,26 +77,25 @@ Room* Level::addRoom(const Glib::ustring &id) {
|
|||
|
||||
node->set_attribute("id", id);
|
||||
|
||||
return &rooms.insert(std::make_pair(id, Room(node))).first->second;
|
||||
}
|
||||
|
||||
void Level::removeRoom(const Glib::ustring &id) {
|
||||
Room *room = getRoom(id);
|
||||
if(!room)
|
||||
return;
|
||||
Room *room = new Room(node);
|
||||
rooms.push_back(room);
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
void Level::removeRoom(Room *room) {
|
||||
roomsNode->remove_child(room->getNode());
|
||||
rooms.erase(id);
|
||||
rooms.remove(room);
|
||||
delete room;
|
||||
}
|
||||
|
||||
Gate* Level::getGate(const Glib::ustring &id) {
|
||||
std::map<Glib::ustring,Gate>::iterator gate = gates.find(id);
|
||||
return (gate != gates.end()) ? &gate->second : NULL;
|
||||
}
|
||||
|
||||
const Gate* Level::getGate(const Glib::ustring &id) const {
|
||||
std::map<Glib::ustring,Gate>::const_iterator gate = gates.find(id);
|
||||
return (gate != gates.end()) ? &gate->second : NULL;
|
||||
Gate* Level::getGate(const Glib::ustring &id) const {
|
||||
for(std::list<Gate*>::const_iterator gate = gates.begin(); gate != gates.end(); ++gate) {
|
||||
if((*gate)->getId() == id)
|
||||
return *gate;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Gate* Level::addGate(const Glib::ustring &id) {
|
||||
|
@ -108,26 +105,25 @@ Gate* Level::addGate(const Glib::ustring &id) {
|
|||
node->set_attribute("room1", "");
|
||||
node->set_attribute("room2", "");
|
||||
|
||||
return &gates.insert(std::make_pair(id, Gate(node))).first->second;
|
||||
}
|
||||
|
||||
void Level::removeGate(const Glib::ustring &id) {
|
||||
Gate *gate = getGate(id);
|
||||
if(!gate)
|
||||
return;
|
||||
Gate *gate = new Gate(node);
|
||||
gates.push_back(gate);
|
||||
|
||||
return gate;
|
||||
}
|
||||
|
||||
void Level::removeGate(Gate *gate) {
|
||||
gatesNode->remove_child(gate->getNode());
|
||||
gates.erase(id);
|
||||
gates.remove(gate);
|
||||
delete gate;
|
||||
}
|
||||
|
||||
Texture* Level::getTexture(const Glib::ustring &id) {
|
||||
std::map<Glib::ustring,Texture>::iterator tex = textures.find(id);
|
||||
return (tex != textures.end()) ? &tex->second : NULL;
|
||||
}
|
||||
|
||||
const Texture* Level::getTexture(const Glib::ustring &id) const {
|
||||
std::map<Glib::ustring,Texture>::const_iterator tex = textures.find(id);
|
||||
return (tex != textures.end()) ? &tex->second : NULL;
|
||||
Texture* Level::getTexture(const Glib::ustring &id) const {
|
||||
for(std::list<Texture*>::const_iterator tex = textures.begin(); tex != textures.end(); ++tex) {
|
||||
if((*tex)->getId() == id)
|
||||
return *tex;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Texture* Level::addTexture(const Glib::ustring &id) {
|
||||
|
@ -136,16 +132,16 @@ Texture* Level::addTexture(const Glib::ustring &id) {
|
|||
node->set_attribute("id", id);
|
||||
node->set_attribute("name", "");
|
||||
|
||||
return &textures.insert(std::make_pair(id, Texture(node))).first->second;
|
||||
}
|
||||
|
||||
void Level::removeTexture(const Glib::ustring &id) {
|
||||
Texture *tex = getTexture(id);
|
||||
if(!tex)
|
||||
return;
|
||||
Texture *tex = new Texture(node);
|
||||
textures.push_back(tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
void Level::removeTexture(Texture *tex) {
|
||||
texturesNode->remove_child(tex->getNode());
|
||||
textures.erase(id);
|
||||
textures.remove(tex);
|
||||
delete tex;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,54 +21,56 @@
|
|||
#define ZOOMEDIT_DATA_LEVEL_H_
|
||||
|
||||
#include "Info.h"
|
||||
#include "Room.h"
|
||||
#include "Gate.h"
|
||||
#include "Texture.h"
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
namespace ZoomEdit {
|
||||
namespace Data {
|
||||
|
||||
class Room;
|
||||
class Gate;
|
||||
class Texture;
|
||||
|
||||
class Level {
|
||||
private:
|
||||
Info info;
|
||||
|
||||
std::map<Glib::ustring,Room> rooms;
|
||||
std::list<Room*> rooms;
|
||||
xmlpp::Element *roomsNode;
|
||||
|
||||
std::map<Glib::ustring,Gate> gates;
|
||||
std::list<Gate*> gates;
|
||||
xmlpp::Element *gatesNode;
|
||||
|
||||
std::map<Glib::ustring,Texture> textures;
|
||||
std::list<Texture*> textures;
|
||||
xmlpp::Element *texturesNode;
|
||||
|
||||
// Prevent shallow copy
|
||||
Level(const Level &o);
|
||||
Level& operator=(const Level &o);
|
||||
|
||||
public:
|
||||
Level(xmlpp::Element *levelNode);
|
||||
virtual ~Level();
|
||||
|
||||
const std::map<Glib::ustring,Room>& getRooms() const {return rooms;}
|
||||
const std::list<Room*>& getRooms() const {return rooms;}
|
||||
|
||||
Room* getRoom(const Glib::ustring &id);
|
||||
const Room* getRoom(const Glib::ustring &id) const;
|
||||
Room* getRoom(const Glib::ustring &id) const;
|
||||
|
||||
Room* addRoom(const Glib::ustring &id);
|
||||
void removeRoom(const Glib::ustring &id);
|
||||
void removeRoom(Room *room);
|
||||
|
||||
const std::map<Glib::ustring,Gate>& getGates() const {return gates;}
|
||||
const std::list<Gate*>& getGates() const {return gates;}
|
||||
|
||||
Gate* getGate(const Glib::ustring &id);
|
||||
const Gate* getGate(const Glib::ustring &id) const;
|
||||
Gate* getGate(const Glib::ustring &id) const;
|
||||
|
||||
Gate* addGate(const Glib::ustring &id);
|
||||
void removeGate(const Glib::ustring &id);
|
||||
void removeGate(Gate *gate);
|
||||
|
||||
const std::map<Glib::ustring,Texture>& getTextures() const {return textures;}
|
||||
const std::list<Texture*>& getTextures() const {return textures;}
|
||||
|
||||
Texture* getTexture(const Glib::ustring &id);
|
||||
const Texture* getTexture(const Glib::ustring &id) const;
|
||||
Texture* getTexture(const Glib::ustring &id) const;
|
||||
|
||||
Texture* addTexture(const Glib::ustring &id);
|
||||
void removeTexture(const Glib::ustring &id);
|
||||
void removeTexture(Texture *tex);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "Room.h"
|
||||
#include "Triangle.h"
|
||||
|
||||
namespace ZoomEdit {
|
||||
namespace Data {
|
||||
|
@ -29,11 +30,46 @@ Room::Room(xmlpp::Element *node) : roomNode(node) {
|
|||
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
|
||||
|
||||
if(tNode)
|
||||
triangles.push_back(Triangle(tNode));
|
||||
triangles.push_back(new Triangle(tNode));
|
||||
}
|
||||
|
||||
id = node->get_attribute_value("id");
|
||||
}
|
||||
|
||||
Room::~Room() {
|
||||
for(std::list<Triangle*>::iterator t = triangles.begin(); t != triangles.end(); ++t)
|
||||
delete *t;
|
||||
}
|
||||
|
||||
Triangle* Room::addTriangle() {
|
||||
xmlpp::Element *tNode = roomNode->add_child("triangle");
|
||||
|
||||
xmlpp::Element *node = tNode->add_child("vertex");
|
||||
node->set_attribute("x", "0.0");
|
||||
node->set_attribute("y", "0.0");
|
||||
node->set_attribute("z", "0.0");
|
||||
|
||||
node = tNode->add_child("vertex");
|
||||
node->set_attribute("x", "0.0");
|
||||
node->set_attribute("y", "0.0");
|
||||
node->set_attribute("z", "0.0");
|
||||
|
||||
node = tNode->add_child("vertex");
|
||||
node->set_attribute("x", "0.0");
|
||||
node->set_attribute("y", "0.0");
|
||||
node->set_attribute("z", "0.0");
|
||||
|
||||
Triangle *t = new Triangle(tNode);
|
||||
triangles.push_back(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void Room::removeTriangle(Triangle *t) {
|
||||
roomNode->remove_child(t->getNode());
|
||||
triangles.remove(t);
|
||||
delete t;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,26 +20,36 @@
|
|||
#ifndef ZOOMEDIT_DATA_ROOM_H_
|
||||
#define ZOOMEDIT_DATA_ROOM_H_
|
||||
|
||||
#include "Triangle.h"
|
||||
#include <list>
|
||||
#include <libxml++/nodes/element.h>
|
||||
|
||||
namespace ZoomEdit {
|
||||
namespace Data {
|
||||
|
||||
class Triangle;
|
||||
|
||||
class Room {
|
||||
private:
|
||||
std::list<Triangle> triangles;
|
||||
std::list<Triangle*> triangles;
|
||||
xmlpp::Element *roomNode;
|
||||
|
||||
Glib::ustring id;
|
||||
|
||||
// Prevent shallow copy
|
||||
Room(const Room &o);
|
||||
Room& operator=(const Room &o);
|
||||
|
||||
public:
|
||||
Room(xmlpp::Element *node);
|
||||
virtual ~Room();
|
||||
|
||||
const std::list<Triangle>& getTriangles() const {
|
||||
const std::list<Triangle*>& getTriangles() const {
|
||||
return triangles;
|
||||
}
|
||||
|
||||
Triangle* addTriangle();
|
||||
void removeTriangle(Triangle *t);
|
||||
|
||||
const Glib::ustring& getId() const {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ class Texture {
|
|||
return id;
|
||||
}
|
||||
|
||||
void setId(const Glib::ustring &nid) {
|
||||
id = nid;
|
||||
texNode->set_attribute("id", nid);
|
||||
void setId(const Glib::ustring &id0) {
|
||||
id = id0;
|
||||
texNode->set_attribute("id", id0);
|
||||
}
|
||||
|
||||
const Glib::ustring& getName() const {
|
||||
|
|
|
@ -78,6 +78,10 @@ class Triangle {
|
|||
visible = vis;
|
||||
triangleNode->set_attribute("visible", vis ? "true" : "false");
|
||||
}
|
||||
|
||||
xmlpp::Element* getNode() const {
|
||||
return triangleNode;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -84,12 +84,12 @@ void RenderArea::onRealize() {
|
|||
gdkGLEnd();
|
||||
}
|
||||
|
||||
bool RenderArea::onConfigureEvent(GdkEventConfigure *event) {
|
||||
bool RenderArea::onConfigureEvent(GdkEventConfigure*) {
|
||||
updateViewport();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderArea::onExposeEvent(GdkEventExpose *event) {
|
||||
bool RenderArea::onExposeEvent(GdkEventExpose*) {
|
||||
if(!gdkGLBegin())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ class RenderArea : public Gtk::DrawingArea {
|
|||
float scale;
|
||||
|
||||
void onRealize();
|
||||
bool onConfigureEvent(GdkEventConfigure *event);
|
||||
bool onExposeEvent(GdkEventExpose *event);
|
||||
bool onConfigureEvent(GdkEventConfigure*);
|
||||
bool onExposeEvent(GdkEventExpose*);
|
||||
bool onScrollEvent(GdkEventScroll *event);
|
||||
|
||||
void zoom(int zoom, float x = 0.5f, float y = 0.5f);
|
||||
|
|
Reference in a new issue