blob: 54543fd569118fccc6b1a51f5570ea4ef8d4f376 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#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) {
if(button != 1 || !editManager->getHoveredObject())
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) {
editManager->highlightHoveredObject();
return true;
}
const Vertex *v = editManager->getHoveredVertex();
if(!v)
return false;
editManager->getSelectedObject()->move(v->getX()-grabbedVertex.getX(), v->getY()-grabbedVertex.getY());
grabbedVertex = *v;
return true;
}
|