Team Fortress 2 Source Code as on 22/4/2020
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.

207 lines
5.9 KiB

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