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.

155 lines
3.6 KiB

  1. #include "stdafx.h"
  2. #include "mapdoc.h"
  3. #include "mapview.h"
  4. #include <wintab.h>
  5. #define PACKETDATA PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE
  6. #define PACKETMODE 0
  7. #include <pktdef.h>
  8. #define MAX_PACKETS 1000
  9. static LOGCONTEXT LogContext;
  10. static HCTX hGlobalContext;
  11. static AXIS NormalAxis;
  12. static float m_flLastPressure;
  13. static bool bWinTabAvailable = false;
  14. static bool bWinTabOpened = false;
  15. static bool bLMBDown = false;
  16. static DWORD nLastTime = 0;
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. // Input :
  20. // Output :
  21. //-----------------------------------------------------------------------------
  22. bool WinTab_Init( )
  23. {
  24. WORD errmode;
  25. errmode = SetErrorMode( SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS );
  26. bWinTabAvailable = WTInfo( 0, 0, NULL ) != 0;
  27. SetErrorMode( errmode );
  28. m_flLastPressure = 1.0f;
  29. return bWinTabAvailable;
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. // Input :
  34. // Output :
  35. //-----------------------------------------------------------------------------
  36. void WinTab_Open( HWND hWnd )
  37. {
  38. if ( bWinTabAvailable == false )
  39. {
  40. return;
  41. }
  42. // pWTMutex = new CMutex( TRUE, NULL, NULL );
  43. memset( &LogContext, 0, sizeof( LogContext ) );
  44. // Get default context information
  45. WTInfo( WTI_DEFCONTEXT, 0, &LogContext );
  46. // Open the context
  47. LogContext.lcPktData = PACKETDATA;
  48. LogContext.lcPktMode = PACKETMODE;
  49. LogContext.lcOptions = CXO_MESSAGES | CXO_SYSTEM;
  50. hGlobalContext = WTOpen( hWnd, &LogContext, TRUE );
  51. bWinTabOpened = true;
  52. WTInfo( WTI_DEVICES + LogContext.lcDevice, DVC_NPRESSURE, &NormalAxis );
  53. WTQueueSizeSet( hGlobalContext, MAX_PACKETS );
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. // Input :
  58. // Output :
  59. //-----------------------------------------------------------------------------
  60. void WinTab_Packet( WPARAM wSerial, LPARAM hContext )
  61. {
  62. // CSingleLock lock( pWTMutex, TRUE );
  63. PACKET WTPacketData[ MAX_PACKETS ];
  64. int nCount = WTPacketsGet( ( HCTX )hContext, MAX_PACKETS, WTPacketData );
  65. if ( nCount == 0 )
  66. {
  67. return;
  68. }
  69. m_flLastPressure = ( float )WTPacketData[ 0 ].pkNormalPressure / ( float )NormalAxis.axMax;
  70. // Msg( "%d %d %d %d %d %g\n", WTPacketData.pkTime, WTPacketData.pkButtons, WTPacketData.pkX, WTPacketData.pkY, WTPacketData.pkNormalPressure, m_flLastPressure );
  71. CMapDoc *pMapDoc = CMapDoc::GetActiveMapDoc();
  72. if ( pMapDoc != NULL )
  73. {
  74. CMapView *pMapView = pMapDoc->GetActiveMapView();
  75. if ( pMapView != NULL )
  76. {
  77. POINT MousePosition;
  78. GetCursorPos( &MousePosition );
  79. AfxGetApp()->m_pMainWnd->ScreenToClient( &MousePosition );
  80. if ( m_flLastPressure >= 0.05f && bLMBDown == false )
  81. {
  82. bLMBDown = true;
  83. // SendMessage( pMapView->GetViewWnd()->m_hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM( MousePosition.x, MousePosition.y ) );
  84. }
  85. if ( m_flLastPressure < 0.02f && bLMBDown == true )
  86. {
  87. bLMBDown = false;
  88. // SendMessage( pMapView->GetViewWnd()->m_hWnd, WM_LBUTTONUP, 0, MAKELPARAM( MousePosition.x, MousePosition.y ) );
  89. }
  90. }
  91. }
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. // Input :
  96. // Output :
  97. //-----------------------------------------------------------------------------
  98. float WinTab_GetPressure( )
  99. {
  100. if ( bLMBDown == true )
  101. {
  102. return m_flLastPressure;
  103. }
  104. return 1.0f;
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose:
  108. // Input :
  109. // Output :
  110. //-----------------------------------------------------------------------------
  111. bool WinTab_Opened( )
  112. {
  113. return bWinTabOpened;
  114. }