TabButton.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #include "Gwen/Gwen.h"
  7. #include "Gwen/Skin.h"
  8. #include "Gwen/Controls/TabButton.h"
  9. #include "Gwen/Controls/TabControl.h"
  10. #include "Gwen/Controls/Highlight.h"
  11. #include "Gwen/DragAndDrop.h"
  12. using namespace Gwen;
  13. using namespace Gwen::Controls;
  14. GWEN_CONTROL_CONSTRUCTOR( TabButton )
  15. {
  16. m_Page = NULL;
  17. m_Control = NULL;
  18. SetPadding( Padding( 2, 2, 2, 2 ) );
  19. DragAndDrop_SetPackage( true, "TabButtonMove" );
  20. SetAlignment( Pos::Top | Pos::Left );
  21. SetTextPadding( Padding( 5, 3, 3, 3 ) );
  22. }
  23. void TabButton::Render( Skin::Base* skin )
  24. {
  25. skin->DrawTabButton( this, m_Page && m_Page->Visible() );
  26. }
  27. void TabButton::SetTabControl( TabControl* ctrl )
  28. {
  29. if ( m_Control == ctrl ) return;
  30. if ( m_Control )
  31. {
  32. m_Control->OnLoseTab( this );
  33. }
  34. m_Control = ctrl;
  35. }
  36. bool TabButton::DragAndDrop_ShouldStartDrag()
  37. {
  38. return m_Control->DoesAllowDrag();
  39. }
  40. bool TabButton::OnKeyUp( bool bDown )
  41. {
  42. OnKeyLeft( bDown );
  43. return true;
  44. }
  45. bool TabButton::OnKeyDown( bool bDown )
  46. {
  47. OnKeyRight( bDown );
  48. return true;
  49. }
  50. bool TabButton::OnKeyLeft( bool bDown )
  51. {
  52. if ( bDown )
  53. {
  54. Base::List::reverse_iterator it = std::find( m_Parent->Children.rbegin(), m_Parent->Children.rend(), this );
  55. if ( it != m_Parent->Children.rend() && (++it != m_Parent->Children.rend()) )
  56. {
  57. Base* pNextTab = *it;
  58. GetTabControl()->OnTabPressed( pNextTab );
  59. Gwen::KeyboardFocus = pNextTab;
  60. }
  61. }
  62. return true;
  63. }
  64. bool TabButton::OnKeyRight( bool bDown )
  65. {
  66. if ( bDown )
  67. {
  68. Base::List::iterator it = std::find( m_Parent->Children.begin(), m_Parent->Children.end(), this );
  69. if ( it != m_Parent->Children.end() && (++it != m_Parent->Children.end()) )
  70. {
  71. Base* pNextTab = *it;
  72. GetTabControl()->OnTabPressed( pNextTab );
  73. Gwen::KeyboardFocus = pNextTab;
  74. }
  75. }
  76. return true;
  77. }