Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
5.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "vcontrolslistpanel.h"
  8. #include "gameui_interface.h"
  9. #include "engineinterface.h"
  10. #include <vgui/IInput.h>
  11. #include <vgui/IScheme.h>
  12. #include <vgui/ISurface.h>
  13. #include <vgui/IVGui.h>
  14. #include <vgui/Cursor.h>
  15. #include <keyvalues.h>
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include <tier0/memdbgon.h>
  18. using namespace vgui;
  19. //-----------------------------------------------------------------------------
  20. // Purpose: panel used for inline editing of key bindings
  21. //-----------------------------------------------------------------------------
  22. class CInlineEditPanel : public vgui::Panel
  23. {
  24. public:
  25. CInlineEditPanel() : vgui::Panel(NULL, "InlineEditPanel")
  26. {
  27. }
  28. virtual void Paint()
  29. {
  30. int x = 0, y = 0, wide, tall;
  31. GetSize(wide, tall);
  32. // Draw a white rectangle around that cell
  33. vgui::surface()->DrawSetColor( 255, 165, 0, 255 );
  34. vgui::surface()->DrawFilledRect( x, y, x + wide, y + tall );
  35. }
  36. virtual void OnKeyCodeTyped(KeyCode code)
  37. {
  38. // forward up
  39. if (GetParent())
  40. {
  41. GetParent()->OnKeyCodeTyped(code);
  42. }
  43. }
  44. virtual void ApplySchemeSettings(IScheme *pScheme)
  45. {
  46. Panel::ApplySchemeSettings(pScheme);
  47. SetBorder(pScheme->GetBorder("DepressedButtonBorder"));
  48. }
  49. void OnMousePressed(vgui::MouseCode code)
  50. {
  51. // forward up mouse pressed messages to be handled by the key options
  52. if (GetParent())
  53. {
  54. GetParent()->OnMousePressed(code);
  55. }
  56. }
  57. };
  58. //-----------------------------------------------------------------------------
  59. // Purpose: Construction
  60. //-----------------------------------------------------------------------------
  61. VControlsListPanel::VControlsListPanel( vgui::Panel *parent, const char *listName ) : vgui::SectionedListPanel( parent, listName )
  62. {
  63. m_bCaptureMode = false;
  64. m_nClickRow = 0;
  65. m_pInlineEditPanel = new CInlineEditPanel();
  66. m_hFont = INVALID_FONT;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose: Destructor
  70. //-----------------------------------------------------------------------------
  71. VControlsListPanel::~VControlsListPanel()
  72. {
  73. m_pInlineEditPanel->MarkForDeletion();
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. //-----------------------------------------------------------------------------
  78. void VControlsListPanel::ApplySchemeSettings(IScheme *pScheme )
  79. {
  80. BaseClass::ApplySchemeSettings( pScheme );
  81. m_hFont = pScheme->GetFont("Default", IsProportional() );
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose: Start capture prompt display
  85. //-----------------------------------------------------------------------------
  86. void VControlsListPanel::StartCaptureMode( HCursor hCursor )
  87. {
  88. m_bCaptureMode = true;
  89. EnterEditMode(m_nClickRow, 1, m_pInlineEditPanel);
  90. input()->SetMouseFocus(m_pInlineEditPanel->GetVPanel());
  91. input()->SetMouseCapture(m_pInlineEditPanel->GetVPanel());
  92. engine->StartKeyTrapMode();
  93. if (hCursor)
  94. {
  95. m_pInlineEditPanel->SetCursor(hCursor);
  96. // save off the cursor position so we can restore it
  97. vgui::input()->GetCursorPos( m_iMouseX, m_iMouseY );
  98. }
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose: Finish capture prompt display
  102. //-----------------------------------------------------------------------------
  103. void VControlsListPanel::EndCaptureMode( HCursor hCursor )
  104. {
  105. m_bCaptureMode = false;
  106. input()->SetMouseCapture(NULL);
  107. LeaveEditMode();
  108. RequestFocus();
  109. input()->SetMouseFocus(GetVPanel());
  110. if (hCursor)
  111. {
  112. m_pInlineEditPanel->SetCursor(hCursor);
  113. surface()->SetCursor(hCursor);
  114. if ( hCursor != dc_none )
  115. {
  116. vgui::input()->SetCursorPos ( m_iMouseX, m_iMouseY );
  117. }
  118. }
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose: Set active row column
  122. //-----------------------------------------------------------------------------
  123. void VControlsListPanel::SetItemOfInterest(int itemID)
  124. {
  125. m_nClickRow = itemID;
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose: Retrieve row, column of interest
  129. //-----------------------------------------------------------------------------
  130. int VControlsListPanel::GetItemOfInterest()
  131. {
  132. return m_nClickRow;
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Purpose: returns true if we're currently waiting to capture a key
  136. //-----------------------------------------------------------------------------
  137. bool VControlsListPanel::IsCapturing( void )
  138. {
  139. return m_bCaptureMode;
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Purpose: Forwards mouse pressed message up to keyboard page when in capture
  143. //-----------------------------------------------------------------------------
  144. void VControlsListPanel::OnMousePressed(vgui::MouseCode code)
  145. {
  146. if (IsCapturing())
  147. {
  148. // forward up mouse pressed messages to be handled by the key options
  149. if (GetParent())
  150. {
  151. GetParent()->OnMousePressed(code);
  152. }
  153. }
  154. else
  155. {
  156. BaseClass::OnMousePressed(code);
  157. }
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose: input handler
  161. //-----------------------------------------------------------------------------
  162. void VControlsListPanel::OnMouseDoublePressed( vgui::MouseCode code )
  163. {
  164. if (IsItemIDValid(GetSelectedItem()))
  165. {
  166. // enter capture mode
  167. OnKeyCodePressed(KEY_ENTER);
  168. }
  169. else
  170. {
  171. BaseClass::OnMouseDoublePressed(code);
  172. }
  173. }