WindowControl.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #include "Gwen/Controls/WindowControl.h"
  7. #include "Gwen/Controls/ImagePanel.h"
  8. #include "Gwen/Controls/Label.h"
  9. #include "Gwen/Controls/Modal.h"
  10. using namespace Gwen;
  11. using namespace Gwen::Controls;
  12. using namespace Gwen::ControlsInternal;
  13. GWEN_CONTROL_CONSTRUCTOR( WindowControl )
  14. {
  15. m_Modal = NULL;
  16. m_bInFocus = false;
  17. m_bDeleteOnClose = false;
  18. m_TitleBar = new Dragger( this );
  19. m_TitleBar->Dock( Pos::Top );
  20. m_TitleBar->SetHeight( 18 );
  21. m_TitleBar->SetPadding( Padding( 0, 0, 0, 5 ) );
  22. m_TitleBar->SetTarget( this );
  23. m_Title = new Label( m_TitleBar );
  24. m_Title->SetAlignment( Pos::Center );
  25. m_Title->SetText( "Window" );
  26. m_Title->SetTextColor(Gwen::Colors::White);
  27. m_Title->Dock( Pos::Fill );
  28. m_CloseButton = new Button( m_TitleBar );
  29. m_CloseButton->SetText( "" );
  30. m_CloseButton->SetSize( m_TitleBar->Height(), m_TitleBar->Height() );
  31. m_CloseButton->Dock(Pos::Right);
  32. m_CloseButton->onPress.Add( this, &WindowControl::CloseButtonPressed );
  33. m_CloseButton->SetTabable( false );
  34. m_CloseButton->SetName( "closeButton" );
  35. //Create a blank content control, dock it to the top - Should this be a ScrollControl?
  36. m_InnerPanel = new Base( this );
  37. m_InnerPanel->Dock( Pos::Fill );
  38. BringToFront();
  39. SetTabable( false );
  40. Focus();
  41. SetMinimumSize( Gwen::Point( 100, 40 ) );
  42. SetClampMovement( true );
  43. SetKeyboardInputEnabled( false );
  44. }
  45. WindowControl::~WindowControl()
  46. {
  47. if ( m_Modal )
  48. {
  49. m_Modal->DelayedDelete();
  50. }
  51. }
  52. void WindowControl::MakeModal( bool invisible )
  53. {
  54. if ( m_Modal ) return;
  55. m_Modal = new ControlsInternal::Modal( GetCanvas() );
  56. SetParent( m_Modal );
  57. if ( invisible )
  58. {
  59. m_Modal->SetShouldDrawBackground( false );
  60. }
  61. }
  62. bool WindowControl::IsOnTop()
  63. {
  64. for (Base::List::reverse_iterator iter = GetParent()->Children.rbegin(); iter != GetParent()->Children.rend(); ++iter)
  65. {
  66. if (!*iter)
  67. continue;
  68. WindowControl* pWindow = (*iter)->DynamicCastWindowControl();
  69. if ( !pWindow )
  70. continue;
  71. if ( pWindow == this )
  72. return true;
  73. return false;
  74. }
  75. return false;
  76. }
  77. void WindowControl::Render( Skin::Base* skin )
  78. {
  79. //This should use m_bInFocus but I need to figure out best way to make layout happen
  80. skin->DrawWindow( this, m_TitleBar->Bottom(), IsOnTop() );
  81. }
  82. void WindowControl::RenderUnder( Skin::Base* skin )
  83. {
  84. BaseClass::RenderUnder( skin );
  85. skin->DrawShadow( this );
  86. }
  87. void WindowControl::SetTitle(Gwen::UnicodeString title)
  88. {
  89. m_Title->SetText( title );
  90. }
  91. void WindowControl::SetClosable(bool closeable)
  92. {
  93. m_CloseButton->SetHidden( !closeable );
  94. }
  95. void WindowControl::SetHidden(bool hidden)
  96. {
  97. if ( !hidden )
  98. BringToFront();
  99. BaseClass::SetHidden(hidden);
  100. }
  101. void WindowControl::Touch()
  102. {
  103. BaseClass::Touch();
  104. BringToFront();
  105. m_bInFocus = IsOnTop();
  106. //If Keyboard focus isn't one of our children, make it us
  107. }
  108. void WindowControl::CloseButtonPressed( Gwen::Controls::Base* /*pFromPanel*/ )
  109. {
  110. SetHidden( true );
  111. if ( m_bDeleteOnClose )
  112. DelayedDelete();
  113. }
  114. void WindowControl::RenderFocus( Gwen::Skin::Base* /*skin*/ )
  115. {
  116. }