summaryrefslogtreecommitdiffstats
path: root/ToolGrab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ToolGrab.cpp')
-rw-r--r--ToolGrab.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/ToolGrab.cpp b/ToolGrab.cpp
new file mode 100644
index 0000000..2d2467a
--- /dev/null
+++ b/ToolGrab.cpp
@@ -0,0 +1,64 @@
+#include "ToolGrab.h"
+
+ToolGrab::ToolGrab(EditManager *editManager) : sidebar(editManager) {
+ this->editManager = editManager;
+
+ pressed = false;
+
+ image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON);
+ g_object_ref_sink(G_OBJECT(image));
+}
+
+ToolGrab::~ToolGrab() {
+ g_object_unref(G_OBJECT(image));
+}
+
+void ToolGrab::activate() {
+ pressed = false;
+ editManager->setSelectedObject(NULL);
+}
+
+bool ToolGrab::buttonPress(unsigned int button) {
+ if(button != 1)
+ return false;
+
+ pressed = true;
+ grabbedVertex = *editManager->getHoveredVertex();
+
+ editManager->setSelectedObject(editManager->getHoveredObject());
+
+ editManager->redraw();
+ sidebar.update();
+
+ return true;
+}
+
+bool ToolGrab::buttonRelease(unsigned int button) {
+ if(button != 1)
+ return false;
+
+ pressed = false;
+
+ editManager->setSelectedObject(NULL);
+
+ editManager->redraw();
+ sidebar.update();
+
+ return true;
+}
+
+bool ToolGrab::motion() {
+ if(!pressed)
+ return false;
+
+ Vertex *v = editManager->getHoveredVertex();
+
+ if(!v)
+ return false;
+
+ editManager->getSelectedObject()->move(v->getX()-grabbedVertex.getX(), v->getY()-grabbedVertex.getY());
+
+ grabbedVertex = *v;
+
+ return true;
+}