summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--EditManager.cpp4
-rw-r--r--EditManager.h13
-rw-r--r--LevelObject.h2
-rw-r--r--LevelVertex.h3
-rw-r--r--PlayerStart.h2
-rw-r--r--Portal.h17
-rw-r--r--Renderer.cpp36
-rw-r--r--Renderer.h12
-rw-r--r--Room.h4
-rw-r--r--Tool.h2
-rw-r--r--ToolAddPolygon.cpp1
-rw-r--r--ToolAddPolygon.h8
-rw-r--r--ToolAddRect.cpp1
-rw-r--r--ToolAddRect.h4
-rw-r--r--ToolGrab.cpp7
-rw-r--r--ToolGrab.h6
-rw-r--r--ToolRotate.cpp9
-rw-r--r--ToolRotate.h4
-rw-r--r--ToolSelector.h14
-rw-r--r--VertexProvider.h3
20 files changed, 90 insertions, 62 deletions
diff --git a/EditManager.cpp b/EditManager.cpp
index 2697612..31a800a 100644
--- a/EditManager.cpp
+++ b/EditManager.cpp
@@ -31,7 +31,6 @@ EditManager::EditManager(Window *window) {
this->window = window;
hoveredObject = NULL;
- highlightedObject = NULL;
selectedObject = NULL;
hasHoveredVertex = false;
@@ -70,6 +69,9 @@ void EditManager::setHoveredVertex(const Vertex *v, float scale) {
hoveredObject = NULL;
for(Level::iterator object = window->getLevel().begin(); object != window->getLevel().end(); object++) {
+ if(!window->getActiveTool()->hoverFilter(**object))
+ continue;
+
if((*object)->hit(*v, scale)) {
if(hoveredObject && (*object)->getPriority() < hoveredObject->getPriority())
continue;
diff --git a/EditManager.h b/EditManager.h
index c3bc03d..df35b74 100644
--- a/EditManager.h
+++ b/EditManager.h
@@ -16,7 +16,6 @@ class EditManager {
Window *window;
LevelObject *hoveredObject;
- LevelObject *highlightedObject;
LevelObject *selectedObject;
Vertex hoveredVertex;
@@ -33,18 +32,6 @@ class EditManager {
return hoveredObject;
}
- void setHighlightedObject(LevelObject *object) {
- highlightedObject = object;
- }
-
- LevelObject* getHighlightedObject() {
- return highlightedObject;
- }
-
- void highlightHoveredObject() {
- highlightedObject = hoveredObject;
- }
-
void setSelectedObject(LevelObject *object) {
selectedObject = object;
}
diff --git a/LevelObject.h b/LevelObject.h
index c774352..50f470e 100644
--- a/LevelObject.h
+++ b/LevelObject.h
@@ -26,7 +26,9 @@ class LevelObject : public Object {
virtual bool hit(const Vertex &v, float scale) const {return hit(v);};
virtual int getPriority() const {return 0;}
+ virtual bool canMove() const {return false;}
virtual void move(float x, float y) {}
+ virtual bool canRotate() const {return false;}
virtual void rotate(Vertex m, float a) {}
};
diff --git a/LevelVertex.h b/LevelVertex.h
index 4834c06..a721293 100644
--- a/LevelVertex.h
+++ b/LevelVertex.h
@@ -34,6 +34,9 @@ class LevelVertex : public LevelObject {
provider->rotateVertex(id, m, a);
}
+ virtual bool canConnect() const {return provider->canConnectVertex(id);}
+ virtual void connect() {provider->connectVertex(id);}
+
const Vertex* operator->() const {return provider->getVertex(id);}
const Vertex& operator*() const {return *provider->getVertex(id);}
};
diff --git a/PlayerStart.h b/PlayerStart.h
index b40b49e..8b08274 100644
--- a/PlayerStart.h
+++ b/PlayerStart.h
@@ -17,6 +17,8 @@ class PlayerStart : public Vertex3d, public LevelObject {
return "PlayerStart";
}
+ virtual bool canMove() const {return true;}
+
virtual void move(float x, float y) {
setX(getX()+x);
setZ(getZ()+y);
diff --git a/Portal.h b/Portal.h
index 8cb91c9..3596bc2 100644
--- a/Portal.h
+++ b/Portal.h
@@ -16,6 +16,7 @@ class Portal : public LevelObject, public VertexProvider {
Vertex vertices[4];
float s, c;
+ bool connected[4];
void updateVertices() {
@@ -54,6 +55,10 @@ class Portal : public LevelObject, public VertexProvider {
orient = 0;
+ for(int i = 0; i < 4; i++) {
+ connected[i] = false;
+ }
+
updateOrient();
}
@@ -109,13 +114,25 @@ class Portal : public LevelObject, public VertexProvider {
return 1;
}
+ virtual bool canMove() const {return true;}
+
virtual void moveVertex(size_t id, float x, float y) {
move(x, y);
}
+ virtual bool canRotate() const {return true;}
+
virtual void rotateVertex(size_t id, Vertex m, float a) {
rotate(m, a);
}
+
+ virtual bool canConnectVertex(size_t id) const {
+ return !connected[id];
+ }
+
+ virtual void connectVertex(size_t id) {
+ connected[id] = true;
+ }
};
#endif /*PORTAL_H_*/
diff --git a/Renderer.cpp b/Renderer.cpp
index c95779a..40150df 100644
--- a/Renderer.cpp
+++ b/Renderer.cpp
@@ -104,39 +104,39 @@ void Renderer::drawCross(const Vertex &m, float r) {
glEnd();
}
-void Renderer::renderObject(const LevelObject &object, bool selected, bool highlighted, float scale) {
+void Renderer::renderObject(const LevelObject &object, bool selected, bool hovered, float scale) {
if(object.isOfType("LevelVertex"))
- renderLevelVertex(*(LevelVertex*)&object, selected, highlighted, scale);
+ renderLevelVertex(*(LevelVertex*)&object, selected, hovered, scale);
else if(object.isOfType("LevelEdge"))
- renderLevelEdge(*(LevelEdge*)&object, selected, highlighted, scale);
+ renderLevelEdge(*(LevelEdge*)&object, selected, hovered, scale);
else if(object.isOfType("Room"))
- renderRoom(*(Room*)&object, selected, highlighted, scale);
+ renderRoom(*(Room*)&object, selected, hovered, scale);
else if(object.isOfType("PlayerStart"))
- renderPlayerStart(*(PlayerStart*)&object, selected, highlighted, scale);
+ renderPlayerStart(*(PlayerStart*)&object, selected, hovered, scale);
else if(object.isOfType("Portal"))
- renderPortal(*(Portal*)&object, selected, highlighted, scale);
+ renderPortal(*(Portal*)&object, selected, hovered, scale);
}
-void Renderer::renderLevelVertex(const LevelVertex &vertex, bool selected, bool highlighted, float scale) {
- if(!selected && !highlighted) return;
+void Renderer::renderLevelVertex(const LevelVertex &vertex, bool selected, bool hovered, float scale) {
+ if(!selected && !hovered) return;
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
fillCircle(*vertex, 3.5f/scale, 16);
glLineWidth(1.0f);
- if(highlighted)
+ if(hovered)
glColor4f(1.0f, 0.9f, 0.0f, 0.9f);
else
glColor4f(1.0f, 0.7f, 0.0f, 0.9f);
drawCircle(*vertex, 3.5f/scale, 16);
}
-void Renderer::renderLevelEdge(const LevelEdge &edge, bool selected, bool highlighted, float scale) {
+void Renderer::renderLevelEdge(const LevelEdge &edge, bool selected, bool hovered, float scale) {
if(selected) {
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(highlighted) {
+ else if(hovered) {
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
glLineWidth(2.0f);
}
@@ -151,7 +151,7 @@ void Renderer::renderLevelEdge(const LevelEdge &edge, bool selected, bool highli
glEnd();
}
-void Renderer::renderRoom(const Room &room, bool selected, bool highlighted, float scale) {
+void Renderer::renderRoom(const Room &room, bool selected, bool hovered, float scale) {
if(selected)
glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
else
@@ -163,7 +163,7 @@ void Renderer::renderRoom(const Room &room, bool selected, bool highlighted, flo
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(highlighted) {
+ else if(hovered) {
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
glLineWidth(2.0f);
}
@@ -175,12 +175,12 @@ void Renderer::renderRoom(const Room &room, bool selected, bool highlighted, flo
drawPolygon(room.getPolygon());
}
-void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool highlighted, float scale) {
+void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale) {
if(selected) {
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(highlighted) {
+ else if(hovered) {
glColor4f(0.0f, 0.7f, 0.7f, 0.7f);
glLineWidth(2.0f);
}
@@ -195,12 +195,12 @@ void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool h
drawCross(Vertex(start.getX(), start.getZ()), 0.5f/sqrtf(scale));
}
-void Renderer::renderPortal(const Portal &portal, bool selected, bool highlighted, float scale) {
+void Renderer::renderPortal(const Portal &portal, bool selected, bool hovered, float scale) {
if(selected) {
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(highlighted) {
+ else if(hovered) {
glColor4f(0.0f, 0.7f, 0.7f, 0.7f);
glLineWidth(2.0f);
}
@@ -242,6 +242,6 @@ void Renderer::render(const Level &level, const Rectangle &rect, float scale) {
for(Level::const_iterator object = level.begin(); object != level.end(); object++) {
renderObject(**object, (&**object == editManager->getSelectedObject()),
- (&**object == editManager->getHighlightedObject()), scale);
+ (&**object == editManager->getHoveredObject()), scale);
}
}
diff --git a/Renderer.h b/Renderer.h
index 0432fe5..d4e5ba0 100644
--- a/Renderer.h
+++ b/Renderer.h
@@ -25,14 +25,14 @@ class Renderer {
void drawCircleDotted(const Vertex &m, float r, int n = 64, int d = 8, float rot = 0);
void drawCross(const Vertex &m, float r);
- void renderObject(const LevelObject &object, bool selected, bool highlighted, float scale);
+ void renderObject(const LevelObject &object, bool selected, bool hovered, float scale);
- void renderLevelVertex(const LevelVertex &vertex, bool selected, bool highlighted, float scale);
- void renderLevelEdge(const LevelEdge &edge, bool selected, bool highlighted, float scale);
+ void renderLevelVertex(const LevelVertex &vertex, bool selected, bool hovered, float scale);
+ void renderLevelEdge(const LevelEdge &edge, bool selected, bool hovered, float scale);
- void renderRoom(const Room &room, bool selected, bool highlighted, float scale);
- void renderPlayerStart(const PlayerStart &start, bool selected, bool highlighted, float scale);
- void renderPortal(const Portal &portal, bool selected, bool highlighted, float scale);
+ void renderRoom(const Room &room, bool selected, bool hovered, float scale);
+ void renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale);
+ void renderPortal(const Portal &portal, bool selected, bool hovered, float scale);
public:
Renderer(EditManager *editManager) {
diff --git a/Room.h b/Room.h
index e1fdd92..6a5f15d 100644
--- a/Room.h
+++ b/Room.h
@@ -48,6 +48,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
return "Room";
}
+ virtual bool canMove() const {return true;}
+
virtual void move(float x, float y) {
Vertex m(x, y);
@@ -55,6 +57,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
*v += m;
}
+ virtual bool canRotate() const {return true;}
+
virtual void rotate(Vertex m, float a);
virtual const Vertex* getVertex(size_t id) const {
diff --git a/Tool.h b/Tool.h
index 8cabfdf..a6c0ee0 100644
--- a/Tool.h
+++ b/Tool.h
@@ -22,6 +22,8 @@ class Tool : public Object {
virtual GtkWidget* getImage() = 0;
virtual bool isSensitive() = 0;
+ virtual bool hoverFilter(const LevelObject &object) const = 0;
+
virtual EventHandler* getEventHandler() = 0;
virtual Sidebar* getSidebar() = 0;
virtual Renderer* getRenderer() {return NULL;}
diff --git a/ToolAddPolygon.cpp b/ToolAddPolygon.cpp
index 47259d7..3c63fb7 100644
--- a/ToolAddPolygon.cpp
+++ b/ToolAddPolygon.cpp
@@ -16,7 +16,6 @@ ToolAddPolygon::~ToolAddPolygon() {
void ToolAddPolygon::activate() {
newRoom = Room();
- editManager->setHighlightedObject(NULL);
editManager->setSelectedObject(NULL);
}
diff --git a/ToolAddPolygon.h b/ToolAddPolygon.h
index eaa2661..b63f78e 100644
--- a/ToolAddPolygon.h
+++ b/ToolAddPolygon.h
@@ -4,6 +4,7 @@
#include "Tool.h"
#include "EditManager.h"
#include "SidebarAdd.h"
+#include "LevelVertex.h"
class ToolAddPolygon : public Tool, private EventHandler, private Renderer {
@@ -43,6 +44,13 @@ class ToolAddPolygon : public Tool, private EventHandler, private Renderer {
return image;
}
+ virtual bool hoverFilter(const LevelObject &object) const {
+ if(!object.isOfType("LevelVertex"))
+ return false;
+
+ return ((LevelVertex*)&object)->canConnect();
+ }
+
virtual EventHandler* getEventHandler() {
return this;
}
diff --git a/ToolAddRect.cpp b/ToolAddRect.cpp
index 39fad6d..888205d 100644
--- a/ToolAddRect.cpp
+++ b/ToolAddRect.cpp
@@ -28,7 +28,6 @@ ToolAddRect::~ToolAddRect() {
}
void ToolAddRect::activate() {
- editManager->setHighlightedObject(NULL);
editManager->setSelectedObject(NULL);
}
diff --git a/ToolAddRect.h b/ToolAddRect.h
index b6b20a9..8c777f4 100644
--- a/ToolAddRect.h
+++ b/ToolAddRect.h
@@ -44,6 +44,10 @@ class ToolAddRect : public Tool, public EventHandler, public Renderer {
return image;
}
+ virtual bool hoverFilter(const LevelObject &object) const {
+ return false;
+ }
+
virtual EventHandler* getEventHandler() {
return this;
}
diff --git a/ToolGrab.cpp b/ToolGrab.cpp
index b212308..7d6a4d1 100644
--- a/ToolGrab.cpp
+++ b/ToolGrab.cpp
@@ -15,7 +15,6 @@ ToolGrab::~ToolGrab() {
void ToolGrab::activate() {
pressed = false;
- editManager->highlightHoveredObject();
editManager->setSelectedObject(NULL);
}
@@ -49,10 +48,8 @@ bool ToolGrab::buttonRelease(unsigned int button, const Vertex *v) {
}
bool ToolGrab::motion(const Vertex *v) {
- if(!pressed) {
- editManager->highlightHoveredObject();
- return true;
- }
+ if(!pressed)
+ return false;
if(!v)
return false;
diff --git a/ToolGrab.h b/ToolGrab.h
index 80ecc0a..d0a6091 100644
--- a/ToolGrab.h
+++ b/ToolGrab.h
@@ -6,7 +6,7 @@
#include "SidebarView.h"
-class ToolGrab : public Tool, public EventHandler {
+class ToolGrab : public Tool, private EventHandler {
private:
GtkWidget *image;
@@ -43,6 +43,10 @@ class ToolGrab : public Tool, public EventHandler {
return image;
}
+ virtual bool hoverFilter(const LevelObject &object) const {
+ return object.canMove();
+ }
+
virtual EventHandler* getEventHandler() {
return this;
}
diff --git a/ToolRotate.cpp b/ToolRotate.cpp
index d933882..342ae2e 100644
--- a/ToolRotate.cpp
+++ b/ToolRotate.cpp
@@ -17,12 +17,11 @@ ToolRotate::~ToolRotate() {
void ToolRotate::activate() {
pressed = false;
- editManager->highlightHoveredObject();
editManager->setSelectedObject(NULL);
}
bool ToolRotate::buttonPress(unsigned int button, const Vertex *v) {
- if(button != 1 || !v)
+ if(button != 1 || !editManager->getHoveredObject())
return false;
pressed = true;
@@ -52,10 +51,8 @@ bool ToolRotate::buttonRelease(unsigned int button, const Vertex *v) {
}
bool ToolRotate::motion(const Vertex *v, float scale) {
- if(!pressed) {
- editManager->highlightHoveredObject();
- return true;
- }
+ if(!pressed)
+ return false;
if(!v)
return false;
diff --git a/ToolRotate.h b/ToolRotate.h
index 4037b58..0a3ea0b 100644
--- a/ToolRotate.h
+++ b/ToolRotate.h
@@ -43,6 +43,10 @@ class ToolRotate : public Tool, private EventHandler, private Renderer {
return image;
}
+ virtual bool hoverFilter(const LevelObject &object) const {
+ return object.canRotate();
+ }
+
virtual EventHandler* getEventHandler() {
return this;
}
diff --git a/ToolSelector.h b/ToolSelector.h
index e3c77af..e2ce48a 100644
--- a/ToolSelector.h
+++ b/ToolSelector.h
@@ -26,10 +26,6 @@ class ToolSelector : public Tool, public EventHandler {
return "ToolSelector";
}
- virtual void activate() {
- editManager->highlightHoveredObject();
- }
-
virtual const char *getName() const {
return "Select";
}
@@ -42,18 +38,16 @@ class ToolSelector : public Tool, public EventHandler {
return image;
}
+ virtual bool hoverFilter(const LevelObject &object) const {
+ return true;
+ }
+
virtual EventHandler *getEventHandler() {
return this;
}
virtual bool buttonPress(unsigned int button, const Vertex *v);
- virtual bool motion(const Vertex *v) {
- editManager->highlightHoveredObject();
-
- return true;
- }
-
virtual Sidebar* getSidebar() {
return &sidebar;
}
diff --git a/VertexProvider.h b/VertexProvider.h
index 2f4b3be..101098e 100644
--- a/VertexProvider.h
+++ b/VertexProvider.h
@@ -13,6 +13,9 @@ class VertexProvider {
virtual void moveVertex(size_t id, float x, float y) {}
virtual void rotateVertex(size_t id, Vertex m, float a) {}
+
+ virtual bool canConnectVertex(size_t id) const {return false;}
+ virtual void connectVertex(size_t id) {}
};
#endif /*VERTEXPROVIDER_H_*/