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.

179 lines
3.8 KiB

  1. // MFC_DEMOView.cpp : implementation of the CMFC_DEMOView class
  2. //
  3. #include "stdafx.h"
  4. #include "MFC_DEMO.h"
  5. #include "DEMODoc.h"
  6. #include "DEMOView.h"
  7. #include <wintab.h>
  8. #define PACKETDATA PK_X | PK_Y | PK_BUTTONS
  9. #define PACKETMODE 0
  10. #include <pktdef.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMFC_DEMOView
  18. IMPLEMENT_DYNCREATE(CMFC_DEMOView, CView)
  19. BEGIN_MESSAGE_MAP(CMFC_DEMOView, CView)
  20. ON_MESSAGE(WT_PACKET, OnWTPacket)
  21. //{{AFX_MSG_MAP(CMFC_DEMOView)
  22. ON_WM_CREATE()
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMFC_DEMOView construction/destruction
  27. CMFC_DEMOView::CMFC_DEMOView()
  28. {
  29. csr.x = -1;
  30. prev_pkButtons = 0;
  31. pWTMutex = new CMutex( TRUE, NULL, NULL );
  32. hCtx = 0;
  33. }
  34. CMFC_DEMOView::~CMFC_DEMOView()
  35. {
  36. delete pWTMutex;
  37. if( hCtx )
  38. WTClose( hCtx );
  39. }
  40. BOOL CMFC_DEMOView::PreCreateWindow(CREATESTRUCT& cs)
  41. {
  42. return CView::PreCreateWindow(cs);
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CMFC_DEMOView drawing
  46. void CMFC_DEMOView::OnDraw(CDC* pDC)
  47. {
  48. CMFC_DEMODoc* pDoc = GetDocument();
  49. ASSERT_VALID(pDoc);
  50. csr.x = -1;
  51. list<point> * lst = pDoc->GetLst();
  52. list<point>::iterator i = lst->begin();
  53. while( i != lst->end() ) {
  54. if( i->x >= 0 )
  55. pDC->LineTo(i->x,i->y);
  56. else
  57. pDC->MoveTo(abs(i->x),abs(i->y));
  58. i++;
  59. }
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CMFC_DEMOView diagnostics
  63. #ifdef _DEBUG
  64. void CMFC_DEMOView::AssertValid() const
  65. {
  66. CView::AssertValid();
  67. }
  68. void CMFC_DEMOView::Dump(CDumpContext& dc) const
  69. {
  70. CView::Dump(dc);
  71. }
  72. CMFC_DEMODoc* CMFC_DEMOView::GetDocument() // non-debug version is inline
  73. {
  74. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFC_DEMODoc)));
  75. return (CMFC_DEMODoc*)m_pDocument;
  76. }
  77. #endif //_DEBUG
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CMFC_DEMOView message handlers
  80. LRESULT CMFC_DEMOView::OnWTPacket(WPARAM wSerial, LPARAM hCtx)
  81. {
  82. // Read the packet
  83. PACKET pkt;
  84. WTPacket( (HCTX)hCtx, wSerial, &pkt );
  85. // Process packets in order, one at a time
  86. CSingleLock lock( pWTMutex, TRUE );
  87. CDC *pDC = GetDC();
  88. // Get window size
  89. RECT window_rect;
  90. GetWindowRect( &window_rect );
  91. POINT size;
  92. size.x = window_rect.right - window_rect.left;
  93. size.y = window_rect.bottom - window_rect.top;
  94. // Erase the old cursor
  95. if( csr.x >= 0 ) {
  96. CRgn r;
  97. r.CreateRectRgn( csr.x - 2, csr.y - 2, csr.x + 2, csr.y + 2 );
  98. pDC->InvertRgn( &r );
  99. }
  100. csr.x = (size.x * pkt.pkX) / lc.lcInExtX;
  101. csr.y = size.y - (size.y * pkt.pkY) / lc.lcInExtY;
  102. if( pkt.pkButtons ) {
  103. CMFC_DEMODoc *pDoc = GetDocument();
  104. list<point> * lst = pDoc->GetLst();
  105. if( prev_pkButtons ) {
  106. list<point>::iterator i = lst->end();
  107. i--;
  108. pDC->MoveTo(abs(i->x),abs(i->y));
  109. lst->push_back(csr);
  110. pDC->LineTo(csr);
  111. } else {
  112. POINT pt;
  113. pt.x = -csr.x;
  114. pt.y = -csr.y;
  115. lst->push_back(pt);
  116. }
  117. }
  118. prev_pkButtons = pkt.pkButtons;
  119. // Draw a new cursor
  120. CRgn r;
  121. r.CreateRectRgn( csr.x - 2, csr.y - 2, csr.x + 2, csr.y + 2 );
  122. pDC->InvertRgn( &r );
  123. ReleaseDC( pDC );
  124. return TRUE;
  125. }
  126. int CMFC_DEMOView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  127. {
  128. if (CView::OnCreate(lpCreateStruct) == -1)
  129. return -1;
  130. // Open a Wintab context
  131. // Get default context information
  132. WTInfo( WTI_DEFCONTEXT, 0, &lc );
  133. // Open the context
  134. lc.lcPktData = PACKETDATA;
  135. lc.lcPktMode = PACKETMODE;
  136. lc.lcOptions = CXO_MESSAGES;
  137. //hCtx = WTOpen( m_hWnd, &lc, TRUE );
  138. hCtx = WTOpen( m_hWnd, &lc, TRUE );
  139. return 0;
  140. }