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.

239 lines
5.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #if defined( _OSX )
  9. //#include "appframework/icocoamgr.h"
  10. //extern ICocoaMgr *g_extCocoaMgr;
  11. #endif
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include <tier0/memdbgon.h>
  14. using namespace SF::GFx;
  15. ConVar sfcursortimeout( "cursortimeout", "60.0", FCVAR_ARCHIVE, "Seconds before mouse cursor hides itself due to inactivity" );
  16. void ScaleformUIImpl::InitCursorImpl( void )
  17. {
  18. m_fCursorTimeUntilHide = sfcursortimeout.GetFloat();
  19. m_iWantCursorShown = 0;
  20. m_loadedCursorImage = CURSOR_IMAGE_NONE;
  21. m_isCursorForced = false;
  22. }
  23. void ScaleformUIImpl::ShutdownCursorImpl( void )
  24. {
  25. }
  26. void ScaleformUIImpl::InitCursor( const char* cursorMovie )
  27. {
  28. // gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
  29. //m_SlotMutexes[SF_RESERVED_CURSOR_SLOT].Lock();
  30. if ( !m_SlotPtrs[SF_RESERVED_CURSOR_SLOT] )
  31. {
  32. CursorSlot* slotPtr = new CursorSlot();
  33. m_SlotPtrs[SF_RESERVED_CURSOR_SLOT] = slotPtr;
  34. slotPtr->Init( cursorMovie, SF_RESERVED_CURSOR_SLOT );
  35. if ( ConsumesInputEvents() )
  36. {
  37. slotPtr->Hide();
  38. slotPtr->Show();
  39. m_fCursorTimeUntilHide = sfcursortimeout.GetFloat();
  40. }
  41. else
  42. {
  43. slotPtr->Show();
  44. slotPtr->Hide();
  45. m_fCursorTimeUntilHide = 0;
  46. }
  47. }
  48. else
  49. {
  50. m_SlotPtrs[SF_RESERVED_CURSOR_SLOT]->AddRef();
  51. }
  52. // gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
  53. //m_SlotMutexes[SF_RESERVED_CURSOR_SLOT].Unlock();
  54. }
  55. void ScaleformUIImpl::SetCursorViewport( int x, int y, int width, int height )
  56. {
  57. SetSlotViewport( SF_RESERVED_CURSOR_SLOT, x, y, width, height );
  58. }
  59. void ScaleformUIImpl::ReleaseCursor( void )
  60. {
  61. SlotRelease( SF_RESERVED_CURSOR_SLOT );
  62. }
  63. bool ScaleformUIImpl::IsCursorVisible( void )
  64. {
  65. bool result = false;
  66. CursorSlot* pslot = ( CursorSlot* )m_SlotPtrs[ SF_RESERVED_CURSOR_SLOT ];
  67. if ( pslot )
  68. {
  69. result = pslot->IsVisible();
  70. }
  71. return result;
  72. }
  73. void ScaleformUIImpl::RenderCursor( void )
  74. {
  75. RenderSlot( SF_RESERVED_CURSOR_SLOT );
  76. }
  77. void ScaleformUIImpl::AdvanceCursor( void )
  78. {
  79. AdvanceSlot( SF_RESERVED_CURSOR_SLOT );
  80. }
  81. void ScaleformUIImpl::SetCursorShape( int shapeIndex )
  82. {
  83. CursorSlot* pslot = ( CursorSlot* ) LockSlotPtr( SF_RESERVED_CURSOR_SLOT );
  84. if ( pslot )
  85. {
  86. pslot->SetCursorShape( shapeIndex );
  87. }
  88. UnlockSlotPtr( SF_RESERVED_CURSOR_SLOT );
  89. }
  90. void ScaleformUIImpl::UpdateCursorWaitTime( float newTime )
  91. {
  92. if ( ( m_fCursorTimeUntilHide > 0 ) != ( newTime > 0 ) )
  93. {
  94. if ( ( newTime > 0 ) )
  95. {
  96. if ( m_iWantCursorShown )
  97. InnerShowCursor();
  98. }
  99. else
  100. InnerHideCursor();
  101. }
  102. m_fCursorTimeUntilHide = newTime;
  103. }
  104. void ScaleformUIImpl::CursorMoved( void )
  105. {
  106. UpdateCursorWaitTime( sfcursortimeout.GetFloat() );
  107. }
  108. void ScaleformUIImpl::ControllerMoved( void )
  109. {
  110. // the motion calibration screen requires the cursor to remain visible even though it is a 'controller'
  111. if ( !m_isCursorForced )
  112. {
  113. UpdateCursorWaitTime( 0 );
  114. }
  115. }
  116. void ScaleformUIImpl::UpdateCursorLazyHide( float time )
  117. {
  118. UpdateCursorWaitTime( m_fCursorTimeUntilHide - time );
  119. }
  120. void ScaleformUIImpl::InnerShowCursor( void )
  121. {
  122. #if defined( USE_SDL ) || defined( OSX )
  123. m_pLauncherMgr->SetMouseVisible( true );
  124. #endif
  125. m_fCursorTimeUntilHide = sfcursortimeout.GetFloat();
  126. #if defined( _PS3 )
  127. // use hardware cursor, and skip the show call for the standard scaleform cursor
  128. g_pInputSystem->EnableHardwareCursor();
  129. #else
  130. CursorSlot* pslot = ( CursorSlot* ) LockSlotPtr( SF_RESERVED_CURSOR_SLOT );
  131. if ( pslot )
  132. {
  133. pslot->Show();
  134. }
  135. UnlockSlotPtr( SF_RESERVED_CURSOR_SLOT );
  136. #endif
  137. }
  138. void ScaleformUIImpl::InnerHideCursor( void )
  139. {
  140. #if defined( USE_SDL ) || defined( OSX )
  141. m_pLauncherMgr->SetMouseVisible( false );
  142. #endif
  143. MouseEvent mevent( Event::MouseMove, 0, -100, -100 );
  144. DistributeEvent( mevent, 0, true, false );
  145. CursorSlot* pslot = ( CursorSlot* ) LockSlotPtr( SF_RESERVED_CURSOR_SLOT );
  146. if ( pslot )
  147. {
  148. pslot->Hide();
  149. }
  150. #if defined( _OSX )
  151. // [will] - Grab the delta to clear the mouse delta accumulator.
  152. // int x, y;
  153. // g_extCocoaMgr->GetMouseDelta( x, y, true );
  154. #endif
  155. UnlockSlotPtr( SF_RESERVED_CURSOR_SLOT );
  156. }
  157. void ScaleformUIImpl::ShowCursor( void )
  158. {
  159. m_iWantCursorShown++;
  160. ConVarRef cl_mouseenable( "cl_mouseenable" );
  161. cl_mouseenable.SetValue( false );
  162. if ( m_iWantCursorShown && m_fCursorTimeUntilHide > 0 )
  163. {
  164. InnerShowCursor();
  165. SFDevMsg( "ScaleformUIImpl::ShowCursor want=%d cl_mouseenable=false InnerShowCursor\n", m_iWantCursorShown);
  166. }
  167. else
  168. {
  169. SFDevMsg( "ScaleformUIImpl::ShowCursor want=%d cl_mouseenable=false\n", m_iWantCursorShown);
  170. }
  171. }
  172. void ScaleformUIImpl::HideCursor( void )
  173. {
  174. Assert( m_iWantCursorShown > 0 );
  175. m_iWantCursorShown--;
  176. if ( !m_iWantCursorShown )
  177. {
  178. ConVarRef cl_mouseenable( "cl_mouseenable" );
  179. cl_mouseenable.SetValue( true );
  180. InnerHideCursor();
  181. SFDevMsg( "ScaleformUIImpl::HideCursor want=%d cl_mouseenable=true InnerHideCursor\n", m_iWantCursorShown);
  182. }
  183. else
  184. {
  185. ConVarRef cl_mouseenable( "cl_mouseenable" );
  186. SFDevMsg( "ScaleformUIImpl::HideCursor want=%d cl_mouseenable=%s\n", m_iWantCursorShown, cl_mouseenable.GetBool() ? "TRUE" : "FALSE");
  187. }
  188. }