#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->highlightHoveredObject(); editManager->setSelectedObject(NULL); } bool ToolGrab::buttonPress(unsigned int button, const Vertex *v) { if(button != 1 || !editManager->getHoveredObject()) return false; pressed = true; grabbedVertex = *v; editManager->setSelectedObject(editManager->getHoveredObject()); editManager->redraw(); sidebar.update(); return true; } bool ToolGrab::buttonRelease(unsigned int button, const Vertex *v) { if(button != 1) return false; pressed = false; editManager->setSelectedObject(NULL); editManager->redraw(); sidebar.update(); return true; } bool ToolGrab::motion(const Vertex *v) { if(!pressed) { editManager->highlightHoveredObject(); return true; } if(!v) return false; editManager->getSelectedObject()->move(v->getX()-grabbedVertex.getX(), v->getY()-grabbedVertex.getY()); grabbedVertex = *v; return true; }