summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2008-02-15 23:44:03 +0100
committerneoraider <devnull@localhost>2008-02-15 23:44:03 +0100
commit77b187b8eba7598fb6154da5d3d62ad0920eac15 (patch)
treeaa5c147510fe6c6c8b0b8433380dafbf3d0d60a7
parent0ea1d388651217697d49029820b02b4f002f1ac0 (diff)
downloadzoomedit-77b187b8eba7598fb6154da5d3d62ad0920eac15.tar
zoomedit-77b187b8eba7598fb6154da5d3d62ad0920eac15.zip
zoomedit: Changed some interfaces.
-rw-r--r--Drawer.cpp15
-rw-r--r--EventHandler.h10
-rw-r--r--LevelObject.h6
-rw-r--r--PlayerStart.h2
-rw-r--r--Portal.h2
-rw-r--r--Room.h2
-rw-r--r--ToolAddPolygon.cpp8
-rw-r--r--ToolAddPolygon.h2
-rw-r--r--ToolAddRect.cpp12
-rw-r--r--ToolAddRect.h4
-rw-r--r--ToolGrab.cpp10
-rw-r--r--ToolGrab.h6
-rw-r--r--ToolRotate.cpp26
-rw-r--r--ToolRotate.h8
-rw-r--r--ToolSelector.cpp2
-rw-r--r--ToolSelector.h4
16 files changed, 63 insertions, 56 deletions
diff --git a/Drawer.cpp b/Drawer.cpp
index 8de3640..9c8405a 100644
--- a/Drawer.cpp
+++ b/Drawer.cpp
@@ -38,25 +38,30 @@ gboolean Drawer::eventHandler(GtkWidget *widget, GdkEvent *event, Drawer *drawer
case GDK_MOTION_NOTIFY:
drawer->updateHoveredPoint(event->motion.x, event->motion.y);
- drawer->window->getActiveTool()->getEventHandler()->motion();
+ drawer->window->getActiveTool()->getEventHandler()->motion(
+ drawer->window->getEditManager().getHoveredVertex(), drawer->scale);
return TRUE;
case GDK_ENTER_NOTIFY:
drawer->updateHoveredPoint(event->crossing.x, event->crossing.y);
- drawer->window->getActiveTool()->getEventHandler()->motion();
+ drawer->window->getActiveTool()->getEventHandler()->motion(
+ drawer->window->getEditManager().getHoveredVertex(), drawer->scale);
return TRUE;
case GDK_LEAVE_NOTIFY:
drawer->window->getEditManager().setHoveredVertex(NULL, drawer->scale);
- drawer->window->getActiveTool()->getEventHandler()->motion();
+ drawer->window->getActiveTool()->getEventHandler()->motion(
+ drawer->window->getEditManager().getHoveredVertex(), drawer->scale);
return TRUE;
case GDK_BUTTON_PRESS:
- drawer->window->getActiveTool()->getEventHandler()->buttonPress(event->button.button);
+ drawer->window->getActiveTool()->getEventHandler()->buttonPress(event->button.button,
+ drawer->window->getEditManager().getHoveredVertex());
return TRUE;
case GDK_BUTTON_RELEASE:
- drawer->window->getActiveTool()->getEventHandler()->buttonRelease(event->button.button);
+ drawer->window->getActiveTool()->getEventHandler()->buttonRelease(event->button.button,
+ drawer->window->getEditManager().getHoveredVertex());
return TRUE;
case GDK_SCROLL:
diff --git a/EventHandler.h b/EventHandler.h
index dabb25b..7676de1 100644
--- a/EventHandler.h
+++ b/EventHandler.h
@@ -1,13 +1,17 @@
#ifndef EVENTHANDLER_H_
#define EVENTHANDLER_H_
+#include "Vertex.h"
+
+
class EventHandler {
public:
virtual ~EventHandler() {}
- virtual bool buttonPress(unsigned int button) {return false;}
- virtual bool buttonRelease(unsigned int button) {return false;}
- virtual bool motion() {return false;}
+ virtual bool buttonPress(unsigned int button, const Vertex *v) {return false;}
+ virtual bool buttonRelease(unsigned int button, const Vertex *v) {return false;}
+ virtual bool motion(const Vertex *v) {return false;}
+ virtual bool motion(const Vertex *v, float scale) {return motion(v);}
};
#endif /*EVENTHANDLER_H_*/
diff --git a/LevelObject.h b/LevelObject.h
index f3360e1..c774352 100644
--- a/LevelObject.h
+++ b/LevelObject.h
@@ -11,8 +11,7 @@ class LevelObject : public Object {
LevelObject *parent;
public:
- LevelObject() : parent(NULL) {}
- LevelObject(LevelObject *p) : parent(p) {}
+ LevelObject(LevelObject *p = NULL) : parent(p) {}
virtual ~LevelObject() {}
LevelObject* getParent() const {
@@ -23,7 +22,8 @@ class LevelObject : public Object {
return std::vector<SharedPtr<LevelObject> >();
}
- virtual bool hit(const Vertex &v, float scale) const = 0;
+ virtual bool hit(const Vertex &v) const {return false;}
+ virtual bool hit(const Vertex &v, float scale) const {return hit(v);};
virtual int getPriority() const {return 0;}
virtual void move(float x, float y) {}
diff --git a/PlayerStart.h b/PlayerStart.h
index ed39fd2..b40b49e 100644
--- a/PlayerStart.h
+++ b/PlayerStart.h
@@ -7,7 +7,7 @@
class PlayerStart : public Vertex3d, public LevelObject {
public:
- virtual bool hit(const Vertex &v, float scale) const {
+ virtual bool hit(const Vertex &v) const {
return (v.distanceSq(Vertex(getX(), getZ())) < 0.09);
}
diff --git a/Portal.h b/Portal.h
index 6acd1f3..8cb91c9 100644
--- a/Portal.h
+++ b/Portal.h
@@ -76,7 +76,7 @@ class Portal : public LevelObject, public VertexProvider {
return children;
}
- virtual bool hit(const Vertex &v, float scale) const {return createPolygon().contains(v);}
+ virtual bool hit(const Vertex &v) const {return createPolygon().contains(v);}
virtual int getPriority() const {return 1;}
virtual const char* getType() const {
diff --git a/Room.h b/Room.h
index 855a00c..e1fdd92 100644
--- a/Room.h
+++ b/Room.h
@@ -39,7 +39,7 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
const Polygon& getPolygon() const {return polygon;}
- virtual bool hit(const Vertex &v, float scale) const {return polygon.contains(v);}
+ virtual bool hit(const Vertex &v) const {return polygon.contains(v);}
virtual int getPriority() const {return 0;}
virtual std::vector<SharedPtr<LevelObject> > getChildren();
diff --git a/ToolAddPolygon.cpp b/ToolAddPolygon.cpp
index 4ede1a3..47259d7 100644
--- a/ToolAddPolygon.cpp
+++ b/ToolAddPolygon.cpp
@@ -49,17 +49,17 @@ void ToolAddPolygon::render(const Level &level, const Rectangle &rect, float sca
}
}
-bool ToolAddPolygon::buttonPress(unsigned int button) {
+bool ToolAddPolygon::buttonPress(unsigned int button, const Vertex *v) {
if(button != 1)
return false;
- if(!editManager->getHoveredVertex())
+ if(!v)
return false;
- if(!editManager->vertexOk(*editManager->getHoveredVertex(), &newRoom))
+ if(!editManager->vertexOk(*v, &newRoom))
return false;
- newRoom.addVertex(*editManager->getHoveredVertex());
+ newRoom.addVertex(*v);
editManager->redraw();
sidebar.update();
diff --git a/ToolAddPolygon.h b/ToolAddPolygon.h
index 59a4bb6..eaa2661 100644
--- a/ToolAddPolygon.h
+++ b/ToolAddPolygon.h
@@ -53,7 +53,7 @@ class ToolAddPolygon : public Tool, private EventHandler, private Renderer {
virtual void render(const Level &level, const Rectangle &rect, float scale);
- virtual bool buttonPress(unsigned int button);
+ virtual bool buttonPress(unsigned int button, const Vertex *v);
virtual Sidebar* getSidebar() {
return &sidebar;
diff --git a/ToolAddRect.cpp b/ToolAddRect.cpp
index 08367ff..39fad6d 100644
--- a/ToolAddRect.cpp
+++ b/ToolAddRect.cpp
@@ -50,18 +50,18 @@ void ToolAddRect::render(const Level &level, const Rectangle &rect, float scale)
drawPolygon(room.getPolygon());
}
-bool ToolAddRect::buttonPress(unsigned int button) {
+bool ToolAddRect::buttonPress(unsigned int button, const Vertex *v) {
if(button != 1)
return false;
- if(!editManager->getHoveredVertex())
+ if(!v)
return false;
- if(!editManager->vertexOk(*editManager->getHoveredVertex()))
+ if(!editManager->vertexOk(*v))
return false;
pressed = true;
- v1 = *editManager->getHoveredVertex();
+ v1 = *v;
editManager->redraw();
sidebar.update();
@@ -69,13 +69,13 @@ bool ToolAddRect::buttonPress(unsigned int button) {
return true;
}
-bool ToolAddRect::buttonRelease(unsigned int button) {
+bool ToolAddRect::buttonRelease(unsigned int button, const Vertex *v) {
if(button != 1 || !pressed)
return false;
pressed = false;
- if(editManager->getHoveredVertex()) {
+ if(v) {
Room room = createRoom();
if(editManager->polygonOk(room.getPolygon())) {
diff --git a/ToolAddRect.h b/ToolAddRect.h
index ee915fa..b6b20a9 100644
--- a/ToolAddRect.h
+++ b/ToolAddRect.h
@@ -54,8 +54,8 @@ class ToolAddRect : public Tool, public EventHandler, public Renderer {
virtual void render(const Level &level, const Rectangle &rect, float scale);
- virtual bool buttonPress(unsigned int button);
- virtual bool buttonRelease(unsigned int button);
+ virtual bool buttonPress(unsigned int button, const Vertex *v);
+ virtual bool buttonRelease(unsigned int button, const Vertex *v);
virtual Sidebar* getSidebar() {
return &sidebar;
diff --git a/ToolGrab.cpp b/ToolGrab.cpp
index 54543fd..b212308 100644
--- a/ToolGrab.cpp
+++ b/ToolGrab.cpp
@@ -19,12 +19,12 @@ void ToolGrab::activate() {
editManager->setSelectedObject(NULL);
}
-bool ToolGrab::buttonPress(unsigned int button) {
+bool ToolGrab::buttonPress(unsigned int button, const Vertex *v) {
if(button != 1 || !editManager->getHoveredObject())
return false;
pressed = true;
- grabbedVertex = *editManager->getHoveredVertex();
+ grabbedVertex = *v;
editManager->setSelectedObject(editManager->getHoveredObject());
@@ -34,7 +34,7 @@ bool ToolGrab::buttonPress(unsigned int button) {
return true;
}
-bool ToolGrab::buttonRelease(unsigned int button) {
+bool ToolGrab::buttonRelease(unsigned int button, const Vertex *v) {
if(button != 1)
return false;
@@ -48,14 +48,12 @@ bool ToolGrab::buttonRelease(unsigned int button) {
return true;
}
-bool ToolGrab::motion() {
+bool ToolGrab::motion(const Vertex *v) {
if(!pressed) {
editManager->highlightHoveredObject();
return true;
}
- const Vertex *v = editManager->getHoveredVertex();
-
if(!v)
return false;
diff --git a/ToolGrab.h b/ToolGrab.h
index ec9f110..80ecc0a 100644
--- a/ToolGrab.h
+++ b/ToolGrab.h
@@ -47,9 +47,9 @@ class ToolGrab : public Tool, public EventHandler {
return this;
}
- virtual bool buttonPress(unsigned int button);
- virtual bool buttonRelease(unsigned int button);
- virtual bool motion();
+ virtual bool buttonPress(unsigned int button, const Vertex *v);
+ virtual bool buttonRelease(unsigned int button, const Vertex *v);
+ virtual bool motion(const Vertex *v);
virtual Sidebar* getSidebar() {
return &sidebar;
diff --git a/ToolRotate.cpp b/ToolRotate.cpp
index 65bf334..d933882 100644
--- a/ToolRotate.cpp
+++ b/ToolRotate.cpp
@@ -21,13 +21,13 @@ void ToolRotate::activate() {
editManager->setSelectedObject(NULL);
}
-bool ToolRotate::buttonPress(unsigned int button) {
- if(button != 1 || !editManager->getHoveredObject())
+bool ToolRotate::buttonPress(unsigned int button, const Vertex *v) {
+ if(button != 1 || !v)
return false;
pressed = true;
valid = false;
- v0 = v = *editManager->getHoveredVertex();
+ vertexRot = vertex = *v;
editManager->setSelectedObject(editManager->getHoveredObject());
@@ -37,7 +37,7 @@ bool ToolRotate::buttonPress(unsigned int button) {
return true;
}
-bool ToolRotate::buttonRelease(unsigned int button) {
+bool ToolRotate::buttonRelease(unsigned int button, const Vertex *v) {
if(button != 1)
return false;
@@ -51,22 +51,22 @@ bool ToolRotate::buttonRelease(unsigned int button) {
return true;
}
-bool ToolRotate::motion() {
+bool ToolRotate::motion(const Vertex *v, float scale) {
if(!pressed) {
editManager->highlightHoveredObject();
return true;
}
- if(!editManager->getHoveredVertex())
+ if(!v)
return false;
- v = *editManager->getHoveredVertex();
+ vertex = *v;
- float a = atan2((v-v0).getY(), (v-v0).getX());
+ float a = atan2((vertex-vertexRot).getY(), (vertex-vertexRot).getX());
- if(v0.distanceSq(v) > 0.04f) {
+ if(vertexRot.distanceSq(vertex) > (10*10)/(scale*scale)) {
if(valid)
- editManager->getSelectedObject()->rotate(v0, a-angle);
+ editManager->getSelectedObject()->rotate(vertexRot, a-angle);
else
valid = true;
@@ -85,14 +85,14 @@ void ToolRotate::render(const Level &level, const Rectangle &rect, float scale)
if(pressed && valid) {
glLineWidth(1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 0.7f);
- drawCircleDotted(v0, v0.distance(v), 64, 16, angle);
+ drawCircleDotted(vertexRot, vertexRot.distance(vertex), 64, 16, angle);
glLineWidth(2.0f);
glBegin(GL_LINES);
- glVertex2f(v0.getX(), v0.getY());
- glVertex2f(v.getX(), v.getY());
+ glVertex2f(vertexRot.getX(), vertexRot.getY());
+ glVertex2f(vertex.getX(), vertex.getY());
glEnd();
}
diff --git a/ToolRotate.h b/ToolRotate.h
index 27491fb..4037b58 100644
--- a/ToolRotate.h
+++ b/ToolRotate.h
@@ -15,7 +15,7 @@ class ToolRotate : public Tool, private EventHandler, private Renderer {
bool pressed, valid;
float angle;
- Vertex v0, v;
+ Vertex vertexRot, vertex;
// prevent shallow copy
ToolRotate(const ToolRotate &t);
@@ -47,9 +47,9 @@ class ToolRotate : public Tool, private EventHandler, private Renderer {
return this;
}
- virtual bool buttonPress(unsigned int button);
- virtual bool buttonRelease(unsigned int button);
- virtual bool motion();
+ virtual bool buttonPress(unsigned int button, const Vertex *v);
+ virtual bool buttonRelease(unsigned int button, const Vertex *v);
+ virtual bool motion(const Vertex *v, float scale);
virtual Renderer *getRenderer() {
return this;
diff --git a/ToolSelector.cpp b/ToolSelector.cpp
index 46ee6d2..953487a 100644
--- a/ToolSelector.cpp
+++ b/ToolSelector.cpp
@@ -12,7 +12,7 @@ ToolSelector::~ToolSelector() {
g_object_unref(G_OBJECT(image));
}
-bool ToolSelector::buttonPress(unsigned int button) {
+bool ToolSelector::buttonPress(unsigned int button, const Vertex *v) {
if(button != 1)
return false;
diff --git a/ToolSelector.h b/ToolSelector.h
index 7f38d81..e3c77af 100644
--- a/ToolSelector.h
+++ b/ToolSelector.h
@@ -46,9 +46,9 @@ class ToolSelector : public Tool, public EventHandler {
return this;
}
- virtual bool buttonPress(unsigned int button);
+ virtual bool buttonPress(unsigned int button, const Vertex *v);
- virtual bool motion() {
+ virtual bool motion(const Vertex *v) {
editManager->highlightHoveredObject();
return true;