CrossSplitter.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #include "Gwen/Gwen.h"
  2. #include "Gwen/Controls/CrossSplitter.h"
  3. #include "Gwen/Controls/Button.h"
  4. using namespace Gwen;
  5. using namespace Controls;
  6. GWEN_CONTROL_CONSTRUCTOR( CrossSplitter )
  7. {
  8. m_VSplitter = new SplitterBar( this );
  9. m_VSplitter->SetPos( 0, 128 );
  10. m_VSplitter->onDragged.Add( this, &CrossSplitter::OnVerticalMoved );
  11. m_VSplitter->SetCursor( Gwen::CursorType::SizeNS );
  12. m_HSplitter = new SplitterBar( this );
  13. m_HSplitter->SetPos( 128, 0 );
  14. m_HSplitter->onDragged.Add( this, &CrossSplitter::OnHorizontalMoved );
  15. m_HSplitter->SetCursor( Gwen::CursorType::SizeWE );
  16. m_CSplitter = new SplitterBar( this );
  17. m_CSplitter->SetPos( 128, 128 );
  18. m_CSplitter->onDragged.Add( this, &CrossSplitter::OnCenterMoved );
  19. m_CSplitter->SetCursor( Gwen::CursorType::SizeAll );
  20. m_fHVal = 0.5f;
  21. m_fVVal = 0.5f;
  22. SetPanel( 0, NULL );
  23. SetPanel( 1, NULL );
  24. SetPanel( 2, NULL );
  25. SetPanel( 3, NULL );
  26. SetSplitterSize( 5 );
  27. SetSplittersVisible( false );
  28. m_iZoomedSection = -1;
  29. }
  30. void CrossSplitter::UpdateVSplitter()
  31. {
  32. m_VSplitter->MoveTo( m_VSplitter->X(), ( Height() - m_VSplitter->Height() ) * ( m_fVVal ));
  33. }
  34. void CrossSplitter::UpdateHSplitter()
  35. {
  36. m_HSplitter->MoveTo( ( Width() - m_HSplitter->Width() ) * ( m_fHVal ), m_HSplitter->Y() );
  37. }
  38. void CrossSplitter::OnCenterMoved( Controls::Base * /*control*/ )
  39. {
  40. //Move the other two bars into position
  41. CalculateValueCenter();
  42. Invalidate();
  43. }
  44. void CrossSplitter::UpdateCSplitter()
  45. {
  46. m_CSplitter->MoveTo( ( Width() - m_CSplitter->Width() ) * ( m_fHVal ), ( Height() - m_CSplitter->Height() ) * ( m_fVVal ));
  47. }
  48. void CrossSplitter::OnHorizontalMoved( Controls::Base * /*control*/ )
  49. {
  50. m_fHVal = CalculateValueHorizontal();
  51. Invalidate();
  52. }
  53. void CrossSplitter::OnVerticalMoved( Controls::Base * /*control*/ )
  54. {
  55. m_fVVal = CalculateValueVertical();
  56. Invalidate();
  57. }
  58. void CrossSplitter::CalculateValueCenter()
  59. {
  60. m_fHVal = (float)m_CSplitter->X() / (float)( Width() - m_CSplitter->Width() );
  61. m_fVVal = (float)m_CSplitter->Y() / (float)( Height() - m_CSplitter->Height() );
  62. }
  63. float CrossSplitter::CalculateValueHorizontal()
  64. {
  65. return (float)m_HSplitter->X() / (float)( Width() - m_HSplitter->Width() );
  66. }
  67. float CrossSplitter::CalculateValueVertical()
  68. {
  69. return (float)m_VSplitter->Y() / (float)( Height() - m_VSplitter->Height() );
  70. }
  71. void CrossSplitter::Layout( Skin::Base* /*skin*/ )
  72. {
  73. m_VSplitter->SetSize( Width(), m_fBarSize );
  74. m_HSplitter->SetSize( m_fBarSize, Height() );
  75. m_CSplitter->SetSize( m_fBarSize, m_fBarSize );
  76. UpdateVSplitter();
  77. UpdateHSplitter();
  78. UpdateCSplitter();
  79. if ( m_iZoomedSection == -1 )
  80. {
  81. if ( m_Sections[0] )
  82. m_Sections[0]->SetBounds( 0, 0, m_HSplitter->X(), m_VSplitter->Y() );
  83. if ( m_Sections[1] )
  84. m_Sections[1]->SetBounds( m_HSplitter->X() + m_fBarSize, 0, Width() - ( m_HSplitter->X() + m_fBarSize ), m_VSplitter->Y() );
  85. if ( m_Sections[2] )
  86. m_Sections[2]->SetBounds( 0, m_VSplitter->Y() + m_fBarSize, m_HSplitter->X(), Height() - ( m_VSplitter->Y() + m_fBarSize ) );
  87. if ( m_Sections[3] )
  88. m_Sections[3]->SetBounds( m_HSplitter->X() + m_fBarSize, m_VSplitter->Y() + m_fBarSize, Width() - ( m_HSplitter->X() + m_fBarSize ), Height() - ( m_VSplitter->Y() + m_fBarSize ) );
  89. }
  90. else
  91. {
  92. //This should probably use Fill docking instead
  93. m_Sections[(int)m_iZoomedSection]->SetBounds( 0, 0, Width(), Height() );
  94. }
  95. }
  96. void CrossSplitter::SetPanel( int index, Controls::Base* pPanel)
  97. {
  98. Debug::AssertCheck( index >= 0 && index <= 3, "CrossSplitter::SetPanel out of range" );
  99. m_Sections[index] = pPanel;
  100. if ( pPanel )
  101. {
  102. pPanel->Dock( Pos::None );
  103. pPanel->SetParent( this );
  104. }
  105. Invalidate();
  106. }
  107. Controls::Base* CrossSplitter::GetPanel( int i )
  108. {
  109. return m_Sections[i];
  110. }
  111. void CrossSplitter::ZoomChanged()
  112. {
  113. onZoomChange.Call( this );
  114. if ( m_iZoomedSection == -1 )
  115. {
  116. onUnZoomed.Call( this );
  117. }
  118. else
  119. {
  120. onZoomed.Call( this );
  121. }
  122. }
  123. void CrossSplitter::Zoom( int section )
  124. {
  125. UnZoom();
  126. if ( m_Sections[section] )
  127. {
  128. for (int i = 0; i < 4; i++)
  129. {
  130. if ( i != section && m_Sections[i] )
  131. m_Sections[i]->SetHidden( true );
  132. }
  133. m_iZoomedSection = section;
  134. Invalidate();
  135. }
  136. ZoomChanged();
  137. }
  138. void CrossSplitter::UnZoom()
  139. {
  140. m_iZoomedSection = -1;
  141. for ( int i = 0; i < 4; i++ )
  142. {
  143. if ( m_Sections[i] )
  144. m_Sections[i]->SetHidden( false );
  145. }
  146. Invalidate();
  147. ZoomChanged();
  148. }