summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Drawer.cpp2
-rw-r--r--EditManager.cpp5
-rw-r--r--EditManager.h17
-rw-r--r--Renderer.cpp16
-rw-r--r--Renderer.h6
-rw-r--r--ToolAddPolygon.cpp1
-rw-r--r--ToolAddRect.cpp3
-rw-r--r--ToolGrab.cpp9
-rw-r--r--ToolSelector.h10
9 files changed, 50 insertions, 19 deletions
diff --git a/Drawer.cpp b/Drawer.cpp
index 8bcfe4a..bea6a59 100644
--- a/Drawer.cpp
+++ b/Drawer.cpp
@@ -43,10 +43,12 @@ gboolean Drawer::eventHandler(GtkWidget *widget, GdkEvent *event, Drawer *drawer
case GDK_ENTER_NOTIFY:
drawer->updateHoveredPoint(event->crossing.x, event->crossing.y);
+ drawer->window->getActiveTool()->getEventHandler()->motion();
return TRUE;
case GDK_LEAVE_NOTIFY:
drawer->window->getEditManager().setHoveredVertex(NULL);
+ drawer->window->getActiveTool()->getEventHandler()->motion();
return TRUE;
case GDK_BUTTON_PRESS:
diff --git a/EditManager.cpp b/EditManager.cpp
index 9c44a27..0052c8f 100644
--- a/EditManager.cpp
+++ b/EditManager.cpp
@@ -31,6 +31,7 @@ EditManager::EditManager(Window *window) {
this->window = window;
hoveredObject = NULL;
+ highlightedObject = NULL;
selectedObject = NULL;
hasHoveredVertex = false;
@@ -56,12 +57,12 @@ bool EditManager::addRoom(const Room &newRoom) {
return false;
}
-Vertex* EditManager::getHoveredVertex() {
+const Vertex* EditManager::getHoveredVertex() const {
if(hasHoveredVertex) return &hoveredVertex;
else return NULL;
}
-void EditManager::setHoveredVertex(Vertex *v) {
+void EditManager::setHoveredVertex(const Vertex *v) {
if(v) {
hasHoveredVertex = true;
hoveredVertex = *v;
diff --git a/EditManager.h b/EditManager.h
index 44e1e11..bd33c9d 100644
--- a/EditManager.h
+++ b/EditManager.h
@@ -16,6 +16,7 @@ class EditManager {
Window *window;
LevelObject *hoveredObject;
+ LevelObject *highlightedObject;
LevelObject *selectedObject;
Vertex hoveredVertex;
@@ -32,6 +33,18 @@ class EditManager {
return hoveredObject;
}
+ void setHighlightedObject(LevelObject *object) {
+ highlightedObject = object;
+ }
+
+ LevelObject* getHighlightedObject() {
+ return highlightedObject;
+ }
+
+ void highlightHoveredObject() {
+ highlightedObject = hoveredObject;
+ }
+
void setSelectedObject(LevelObject *object) {
selectedObject = object;
}
@@ -42,8 +55,8 @@ class EditManager {
bool addRoom(const Room &room);
- Vertex* getHoveredVertex();
- void setHoveredVertex(Vertex *v);
+ const Vertex* getHoveredVertex() const;
+ void setHoveredVertex(const Vertex *v);
bool vertexOk(const Vertex &v, const Room *newRoom = NULL) const;
bool polygonOk(const Polygon &polygon) const;
diff --git a/Renderer.cpp b/Renderer.cpp
index be00732..4954133 100644
--- a/Renderer.cpp
+++ b/Renderer.cpp
@@ -107,14 +107,14 @@ void Renderer::drawCross(const Vertex &m, float r) {
glEnd();
}
-void Renderer::renderObject(const LevelObject &object, bool selected, bool hovered, float scale) {
+void Renderer::renderObject(const LevelObject &object, bool selected, bool highlighted, float scale) {
if(object.isOfType("Room"))
- renderRoom(*(Room*)&object, selected, hovered, scale);
+ renderRoom(*(Room*)&object, selected, highlighted, scale);
else if(object.isOfType("PlayerStart"))
- renderPlayerStart(*(PlayerStart*)&object, selected, hovered, scale);
+ renderPlayerStart(*(PlayerStart*)&object, selected, highlighted, scale);
}
-void Renderer::renderRoom(const Room &room, bool selected, bool hovered, float scale) {
+void Renderer::renderRoom(const Room &room, bool selected, bool highlighted, float scale) {
if(selected)
glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
else
@@ -126,7 +126,7 @@ void Renderer::renderRoom(const Room &room, bool selected, bool hovered, float s
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(hovered) {
+ else if(highlighted) {
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
glLineWidth(2.0f);
}
@@ -138,12 +138,12 @@ void Renderer::renderRoom(const Room &room, bool selected, bool hovered, float s
drawPolygon(room);
}
-void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale) {
+void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool highlighted, float scale) {
if(selected) {
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(hovered) {
+ else if(highlighted) {
glColor4f(0.0f, 0.7f, 0.7f, 0.7f);
glLineWidth(2.0f);
}
@@ -168,6 +168,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->getHoveredObject()), scale);
+ (&**object == editManager->getHighlightedObject()), scale);
}
}
diff --git a/Renderer.h b/Renderer.h
index 1637904..76221b8 100644
--- a/Renderer.h
+++ b/Renderer.h
@@ -21,10 +21,10 @@ class Renderer {
void drawCircle(const Vertex &m, float r, int n);
void drawCross(const Vertex &m, float r);
- void renderObject(const LevelObject &object, bool selected, bool hovered, float scale);
+ void renderObject(const LevelObject &object, 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 renderRoom(const Room &room, bool selected, bool highlighted, float scale);
+ void renderPlayerStart(const PlayerStart &start, bool selected, bool highlighted, float scale);
public:
Renderer(EditManager *editManager) {
diff --git a/ToolAddPolygon.cpp b/ToolAddPolygon.cpp
index 0ef7225..0ac8fea 100644
--- a/ToolAddPolygon.cpp
+++ b/ToolAddPolygon.cpp
@@ -16,6 +16,7 @@ ToolAddPolygon::~ToolAddPolygon() {
void ToolAddPolygon::activate() {
newRoom = Room();
+ editManager->setHighlightedObject(NULL);
editManager->setSelectedObject(NULL);
}
diff --git a/ToolAddRect.cpp b/ToolAddRect.cpp
index 6551be6..a4a153b 100644
--- a/ToolAddRect.cpp
+++ b/ToolAddRect.cpp
@@ -3,7 +3,7 @@
Room ToolAddRect::createRoom() {
- Vertex *v2 = editManager->getHoveredVertex();
+ const Vertex *v2 = editManager->getHoveredVertex();
Room room;
room.push_back(v1);
@@ -28,6 +28,7 @@ ToolAddRect::~ToolAddRect() {
}
void ToolAddRect::activate() {
+ editManager->setHighlightedObject(NULL);
editManager->setSelectedObject(NULL);
}
diff --git a/ToolGrab.cpp b/ToolGrab.cpp
index 2d2467a..ed27c05 100644
--- a/ToolGrab.cpp
+++ b/ToolGrab.cpp
@@ -15,6 +15,7 @@ ToolGrab::~ToolGrab() {
void ToolGrab::activate() {
pressed = false;
+ editManager->highlightHoveredObject();
editManager->setSelectedObject(NULL);
}
@@ -48,10 +49,12 @@ bool ToolGrab::buttonRelease(unsigned int button) {
}
bool ToolGrab::motion() {
- if(!pressed)
- return false;
+ if(!pressed) {
+ editManager->highlightHoveredObject();
+ return true;
+ }
- Vertex *v = editManager->getHoveredVertex();
+ const Vertex *v = editManager->getHoveredVertex();
if(!v)
return false;
diff --git a/ToolSelector.h b/ToolSelector.h
index 5ba2bcd..7f38d81 100644
--- a/ToolSelector.h
+++ b/ToolSelector.h
@@ -26,6 +26,10 @@ class ToolSelector : public Tool, public EventHandler {
return "ToolSelector";
}
+ virtual void activate() {
+ editManager->highlightHoveredObject();
+ }
+
virtual const char *getName() const {
return "Select";
}
@@ -44,6 +48,12 @@ class ToolSelector : public Tool, public EventHandler {
virtual bool buttonPress(unsigned int button);
+ virtual bool motion() {
+ editManager->highlightHoveredObject();
+
+ return true;
+ }
+
virtual Sidebar* getSidebar() {
return &sidebar;
}