]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/draghandle.cpp
Add DragHandle widget
[libs/gltk.git] / source / draghandle.cpp
diff --git a/source/draghandle.cpp b/source/draghandle.cpp
new file mode 100644 (file)
index 0000000..067a515
--- /dev/null
@@ -0,0 +1,44 @@
+#include "container.h"
+#include "draghandle.h"
+
+namespace Msp {
+namespace GLtk {
+
+DragHandle::DragHandle():
+       dragging(false),
+       drag_x(0),
+       drag_y(0)
+{ }
+
+void DragHandle::button_press(int x, int y, unsigned btn)
+{
+       if(btn==1 && parent)
+       {
+               dragging = true;
+               drag_x = x;
+               drag_y = y;
+       }
+}
+
+void DragHandle::button_release(int, int, unsigned btn)
+{
+       if(btn==1)
+               dragging = false;
+}
+
+void DragHandle::pointer_motion(int x, int y)
+{
+       if(dragging)
+       {
+               const Geometry &pgeom = parent->get_geometry();
+               parent->set_position(pgeom.x+x-drag_x, pgeom.y+y-drag_y);
+       }
+}
+
+void DragHandle::on_reparent()
+{
+       dragging = false;
+}
+
+} // namespace GLtk
+} // namespace Msp