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.

104 lines
2.5 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmemouseinput.h"
  7. #include "movieobjects_interfaces.h"
  8. #include "datamodel/dmelementfactoryhelper.h"
  9. #include "vgui/iinput.h"
  10. #include "vgui/ipanel.h"
  11. #include "tier3/tier3.h"
  12. #include "tier0/dbg.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Expose this class to the scene database
  17. //-----------------------------------------------------------------------------
  18. IMPLEMENT_ELEMENT_FACTORY( DmeMouseInput, CDmeMouseInput );
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. void CDmeMouseInput::OnConstruction()
  23. {
  24. m_x.Init( this, "x" );
  25. m_y.Init( this, "y" );
  26. m_xOrigin = 0.0f;
  27. m_yOrigin = 0.0f;
  28. }
  29. void CDmeMouseInput::OnDestruction()
  30. {
  31. }
  32. //-----------------------------------------------------------------------------
  33. // IsDirty - ie needs to operate
  34. //-----------------------------------------------------------------------------
  35. bool CDmeMouseInput::IsDirty()
  36. {
  37. float flX, flY;
  38. GetNormalizedCursorPos( flX, flY );
  39. flX -= m_xOrigin;
  40. flY -= m_yOrigin;
  41. return ( flX != GetValue< float >( "x" ) ) || ( flY != GetValue< float >( "y" ) );
  42. }
  43. void CDmeMouseInput::Operate()
  44. {
  45. float flX, flY;
  46. GetNormalizedCursorPos( flX, flY );
  47. SetValue( "x", flX - m_xOrigin );
  48. SetValue( "y", flY - m_yOrigin );
  49. // Msg( "CDmeMouseInput::Operate() at <%f, %f>\n", flX, flY );
  50. }
  51. void CDmeMouseInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  52. {
  53. }
  54. void CDmeMouseInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  55. {
  56. attrs.AddToTail( GetAttribute( "x" ) );
  57. attrs.AddToTail( GetAttribute( "y" ) );
  58. }
  59. void CDmeMouseInput::ResetOrigin( float dx, float dy )
  60. {
  61. GetNormalizedCursorPos( m_xOrigin, m_yOrigin );
  62. m_xOrigin += dx;
  63. m_yOrigin += dy;
  64. }
  65. void CDmeMouseInput::GetNormalizedCursorPos( float &flX, float &flY )
  66. {
  67. int x, y;
  68. g_pVGuiInput->GetCursorPos( x, y );
  69. vgui::VPANEL vpanel = g_pVGuiInput->GetFocus();
  70. if ( !vpanel )
  71. {
  72. flX = flY = 0.0f;
  73. return;
  74. }
  75. int x0, y0;
  76. g_pVGuiPanel->GetPos( vpanel, x0, y0 );
  77. int w, h;
  78. g_pVGuiPanel->GetSize( vpanel, w, h );
  79. flX = ( x - x0 ) / float(w);
  80. flY = ( y - y0 ) / float(h);
  81. }