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.

289 lines
9.2 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef ATTRIBUTESLIDER_H
  7. #define ATTRIBUTESLIDER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/EditablePanel.h"
  12. #include "movieobjects/animsetattributevalue.h"
  13. #include "movieobjects/dmelog.h"
  14. #include "datamodel/dmehandle.h"
  15. using namespace vgui;
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. class CBaseAnimSetAttributeSliderPanel;
  20. class CDmElement;
  21. class CAttributeSliderTextEntry;
  22. class CSubRectImage;
  23. //-----------------------------------------------------------------------------
  24. // CAttributeSlider
  25. //-----------------------------------------------------------------------------
  26. // THIS CODE IS KIND OF A MESS WRT THE VARIOUS STATES WE CAN BE IN:
  27. // we can be driven by the preset pane or by dragging on any individual control
  28. // we can also be driven by ctrl hovering over the preset pane or an individual control
  29. // if we move from control to control in the preset or here, we need to be able to decay into/out of the various individual sliders
  30. class CAttributeSlider : public EditablePanel
  31. {
  32. DECLARE_CLASS_SIMPLE( CAttributeSlider, EditablePanel );
  33. // Overridden methods of EditablePanel
  34. public:
  35. virtual void Paint();
  36. virtual void PaintBackground();
  37. virtual void ApplySchemeSettings( IScheme *scheme );
  38. virtual void PerformLayout();
  39. virtual void OnCursorMoved(int x, int y);
  40. virtual void OnMousePressed(MouseCode code);
  41. virtual void OnMouseDoublePressed(MouseCode code);
  42. virtual void OnMouseReleased(MouseCode code);
  43. virtual void OnCursorEntered();
  44. virtual void OnCursorExited();
  45. virtual void OnKeyCodeTyped( KeyCode code );
  46. // Other public methods
  47. public:
  48. CAttributeSlider( CBaseAnimSetAttributeSliderPanel *parent );
  49. virtual ~CAttributeSlider();
  50. void Init( CDmElement *control, bool bOrientation );
  51. // Things that rely on a specific type
  52. void SetValue( AnimationControlType_t type, float flValue );
  53. void SetValue( AnimationControlType_t type, const Vector &vec );
  54. void SetValue( AnimationControlType_t type, const Quaternion &quat );
  55. float GetValue( AnimationControlType_t type ) const;
  56. void GetValue( AnimationControlType_t type, Vector &vec ) const;
  57. void GetValue( AnimationControlType_t type, Quaternion &quat ) const;
  58. float GetPreview( AnimationControlType_t type ) const;
  59. void GetPreview( AnimationControlType_t type, Vector &vec ) const;
  60. void GetPreview( AnimationControlType_t type, Quaternion &quat ) const;
  61. // Estimates the value of the control given a local coordinate
  62. float EstimateValueAtPos( int nLocalX, int nLocalY ) const;
  63. // Returns the control we're modifying
  64. CDmElement *GetControl();
  65. const CDmElement *GetControl() const;
  66. // sets internal state to dme control's value
  67. void InitControls();
  68. // Gets/sets the slider value.
  69. // NOTE: This may not match the value pushed into the control because of fading
  70. void SetValue( const AttributeValue_t& value );
  71. const AttributeValue_t& GetValue() const;
  72. // Is this slider manipulating a transform control?
  73. // [NOTE: This is a utility method; the control contains these states]
  74. bool IsTransform() const;
  75. bool IsOrientation() const;
  76. bool IsStereo() const;
  77. // Are we dragging?
  78. bool IsDragging() const;
  79. // Are we in text entry mode?
  80. bool IsInTextEntry() const;
  81. void SetPreview( const AttributeValue_t &value, const AttributeValue_t &full );
  82. const AttributeValue_t &GetPreview() const;
  83. const AttributeValue_t &GetPreviewFull() const;
  84. void UpdateFaderAmount( float amount );
  85. void SetVisibleComponents( LogComponents_t componentFlags );
  86. LogComponents_t VisibleComponents() const;
  87. // Slider dependency functions, provide information about which other sliders on which the function of this slider depends
  88. void ClearDependencies();
  89. bool AddDependency( const CAttributeSlider* pSlider );
  90. bool IsDependent( const CAttributeSlider* pSlider ) const;
  91. void SetDependent( bool dependent );
  92. MESSAGE_FUNC( OnSetToDefault, "SetToDefault" );
  93. MESSAGE_FUNC( OnEditMinMaxDefault, "EditMinMaxDefault" );
  94. MESSAGE_FUNC_PARAMS( OnInputCompleted, "InputCompleted", params );
  95. protected:
  96. KEYBINDING_FUNC( ts_curve_1, KEY_1, 0, OnCurve1, "#ts_curve1_help", 0 );
  97. KEYBINDING_FUNC( ts_curve_2, KEY_2, 0, OnCurve2, "#ts_curve2_help", 0 );
  98. KEYBINDING_FUNC( ts_curve_3, KEY_3, 0, OnCurve3, "#ts_curve3_help", 0 );
  99. KEYBINDING_FUNC( ts_curve_4, KEY_4, 0, OnCurve4, "#ts_curve4_help", 0 );
  100. private:
  101. // Various slider modes
  102. enum SliderMode_t
  103. {
  104. SLIDER_MODE_NONE,
  105. SLIDER_MODE_TEXT,
  106. SLIDER_MODE_DRAG_VALUE, // scalar, position or orientation
  107. };
  108. private:
  109. // Things that rely on type
  110. // Called by the text entry code to enter the value into the logs
  111. void StampValueIntoLogs( AnimationControlType_t type, float flValue );
  112. void StampValueIntoLogs( AnimationControlType_t type, const Vector &vecValue );
  113. void StampValueIntoLogs( AnimationControlType_t type, const Quaternion &qValue );
  114. void DrawValueLabel();
  115. // Other stuff
  116. void ActivateControl( AnimationControlType_t type, bool bActive );
  117. // Returns the location of a particular control
  118. void GetControlRect( Rect_t *pRect ) const;
  119. // Methods related to rendering
  120. void DrawMidpoint( int x, int ty, int ttall );
  121. void DrawTick( const Color& clr, const AttributeValue_t &value, int width, int inset );
  122. void DrawNameLabel();
  123. void PaintSliderBackGround();
  124. float GetPreviewAlphaScale() const;
  125. // Methods related to text entry mode
  126. void EnterTextEntryMode( bool bRelatchValues );
  127. void AcceptTextEntryValue();
  128. void DiscardTextEntryValue();
  129. void SetupTextFieldForTextEntryMode( CAttributeSliderTextEntry *&pTextField, const char *pText, bool bRequestFocus );
  130. void SetToDefault();
  131. private:
  132. CBaseAnimSetAttributeSliderPanel *m_pParent;
  133. TextImage *m_pName;
  134. TextImage *m_pValues[ 4 ];
  135. // This is the control we're modifying
  136. CDmeHandle< CDmElement > m_hControl;
  137. // The current mode of the slider
  138. SliderMode_t m_SliderMode;
  139. // The slider value; it may not match the control attribute value due to blending
  140. AttributeValue_t m_Control;
  141. // Info used when in text entry mode
  142. AttributeValue_t m_InitialTextEntryValue;
  143. CAttributeSliderTextEntry *m_pTextField; // if this is a stereo control, then this will be the left text field
  144. CAttributeSliderTextEntry *m_pRightTextField;
  145. AttributeValue_t m_PreviewCurrent;
  146. AttributeValue_t m_PreviewFull;
  147. float m_flFaderAmount;
  148. // Fields used to help with drag
  149. int m_nDragStartPosition[2]; // Where was the mouse clicked?
  150. int m_nAccum[2]; // What's the total mouse movement during the drag?
  151. AttributeValue_t m_dragStartValues; // What was the value of the slider before the drag started?
  152. LogComponents_t m_nVisibleComponents; // Flags used to specify specific components that are visible
  153. bool m_bTransform : 1;
  154. bool m_bOrientation : 1;
  155. bool m_bStereo : 1;
  156. bool m_bDependent : 1;
  157. CUtlVector< const CAttributeSlider* > m_Dependenices; // List of sliders that the operation of this slider depends on
  158. vgui::DHANDLE< vgui::Menu > m_hContextMenu;
  159. friend class CAttributeSliderTextEntry;
  160. };
  161. /*
  162. class CAttributeSliderData
  163. {
  164. // CDmeHandle< CDmElement > m_hControl;
  165. int m_nIndex; // its index, the control's index, and the slider's index
  166. AttributeValue_t m_Control;
  167. AttributeValue_t m_InitialTextEntryValue;
  168. AttributeValue_t m_dragStartValues;
  169. AttributeValue_t m_PreviewCurrent;
  170. AttributeValue_t m_PreviewFull;
  171. AttributeValue_t m_CurrentValue;
  172. AttributeValue_t m_SavedValue;
  173. AttributeValue_t m_FullPresetValue;
  174. float m_flFaderAmount;
  175. unsigned int m_nVisibleComponents;
  176. CUtlVector< const CAttributeSliderData* > m_Dependenices;
  177. };
  178. */
  179. //-----------------------------------------------------------------------------
  180. // Inline methods
  181. //-----------------------------------------------------------------------------
  182. //-----------------------------------------------------------------------------
  183. // Returns the control
  184. //-----------------------------------------------------------------------------
  185. inline CDmElement *CAttributeSlider::GetControl()
  186. {
  187. return m_hControl;
  188. }
  189. inline const CDmElement *CAttributeSlider::GetControl() const
  190. {
  191. return m_hControl;
  192. }
  193. //-----------------------------------------------------------------------------
  194. // Returns information about the control
  195. //-----------------------------------------------------------------------------
  196. inline bool CAttributeSlider::IsTransform() const
  197. {
  198. return m_bTransform;
  199. }
  200. inline bool CAttributeSlider::IsOrientation() const
  201. {
  202. return m_bOrientation;
  203. }
  204. inline bool CAttributeSlider::IsStereo() const
  205. {
  206. return m_bStereo;
  207. }
  208. //-----------------------------------------------------------------------------
  209. // Are we dragging?
  210. //-----------------------------------------------------------------------------
  211. inline bool CAttributeSlider::IsDragging() const
  212. {
  213. return m_SliderMode == SLIDER_MODE_DRAG_VALUE;
  214. }
  215. //-----------------------------------------------------------------------------
  216. // Are we in text entry mode?
  217. //-----------------------------------------------------------------------------
  218. inline bool CAttributeSlider::IsInTextEntry() const
  219. {
  220. return m_SliderMode == SLIDER_MODE_TEXT;
  221. }
  222. #endif // ATTRIBUTESLIDER_H