1 /*
2 GWEN
3 Copyright (c) 2010 Facepunch Studios
4 See license in Gwen.h
5 */
6
7 #include "Gwen/Controls/Dragger.h"
8
9 using namespace Gwen;
10 using namespace Gwen::ControlsInternal;
11
GWEN_CONTROL_CONSTRUCTOR(Dragger)12 GWEN_CONTROL_CONSTRUCTOR(Dragger)
13 {
14 m_pTarget = NULL;
15 SetMouseInputEnabled(true);
16 m_bDepressed = false;
17 }
18
OnMouseClickLeft(int x,int y,bool bDown)19 void Dragger::OnMouseClickLeft(int x, int y, bool bDown)
20 {
21 if (!m_pTarget) return;
22
23 if (bDown)
24 {
25 m_bDepressed = true;
26 m_HoldPos = m_pTarget->CanvasPosToLocal(Gwen::Point(x, y));
27 Gwen::MouseFocus = this;
28 }
29 else
30 {
31 m_bDepressed = false;
32
33 Gwen::MouseFocus = NULL;
34 }
35 }
36
OnMouseMoved(int x,int y,int,int)37 void Dragger::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
38 {
39 if (!m_pTarget) return;
40 if (!m_bDepressed) return;
41
42 Gwen::Point p = Gwen::Point(x - m_HoldPos.x, y - m_HoldPos.y);
43
44 // Translate to parent
45 if (m_pTarget->GetParent())
46 p = m_pTarget->GetParent()->CanvasPosToLocal(p);
47
48 //m_pTarget->SetPosition( p.x, p.y );
49 m_pTarget->MoveTo(p.x, p.y);
50 onDragged.Call(this);
51 }
52
Render(Skin::Base *)53 void Dragger::Render(Skin::Base* /*skin*/)
54 {
55 //skin->DrawButton(this,false,false);
56 }
57