#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; }