Dragger.cpp 1.1 KB

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