]> git.tdb.fi Git - libs/gltk.git/blob - source/draghandle.cpp
Rework how widget ownership works in Container
[libs/gltk.git] / source / draghandle.cpp
1 #include "container.h"
2 #include "draghandle.h"
3
4 namespace Msp {
5 namespace GLtk {
6
7 DragHandle::DragHandle():
8         dragging(false),
9         drag_x(0),
10         drag_y(0)
11 { }
12
13 void DragHandle::button_press(int x, int y, unsigned btn)
14 {
15         if(btn==1 && parent)
16         {
17                 dragging = true;
18                 drag_x = x;
19                 drag_y = y;
20         }
21 }
22
23 void DragHandle::button_release(int, int, unsigned btn)
24 {
25         if(btn==1)
26                 dragging = false;
27 }
28
29 void DragHandle::pointer_motion(int x, int y)
30 {
31         if(dragging)
32         {
33                 const Geometry &pgeom = parent->get_geometry();
34                 parent->set_position(pgeom.x+x-drag_x, pgeom.y+y-drag_y);
35         }
36 }
37
38 void DragHandle::on_reparent()
39 {
40         dragging = false;
41 }
42
43 } // namespace GLtk
44 } // namespace Msp