Old fashion design for PC-104
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.

156 lines
4.4 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: CameraPositionWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of CameraPositionWnd.cpp
  13. //----------------------------------------------------------------------------
  14. // CameraPositionWnd.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "multiipiclient.h"
  18. #include "CameraPositionWnd.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CCameraPositionWnd
  26. CCameraPositionWnd::CCameraPositionWnd()
  27. {
  28. m_PTZ.dPan = m_PTZ.dTilt = m_PTZ.dZoom = 0;
  29. m_bSynchronized = FALSE;
  30. }
  31. CCameraPositionWnd::~CCameraPositionWnd()
  32. {
  33. }
  34. BEGIN_MESSAGE_MAP(CCameraPositionWnd, CWnd)
  35. //{{AFX_MSG_MAP(CCameraPositionWnd)
  36. ON_WM_PAINT()
  37. ON_WM_SIZE()
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. BOOL CCameraPositionWnd::Create( CWnd* pParentWnd, CRect &rect )
  41. {
  42. CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, LoadCursor( NULL, IDC_ARROW ), NULL, NULL );
  43. if( !CWnd::Create( strClassName, NULL, WS_CHILD | WS_VISIBLE, rect, pParentWnd, 0 ) )
  44. return FALSE;
  45. return TRUE;
  46. }
  47. void CCameraPositionWnd::OnPaint()
  48. {
  49. CPaintDC dc(this); // device context for painting
  50. OnDraw( &m_MemoryDC );
  51. CRect rect;
  52. GetClientRect( &rect );
  53. dc.BitBlt( 0, 0, rect.Width(), rect.Height(), &m_MemoryDC, 0, 0, SRCCOPY );
  54. }
  55. void CCameraPositionWnd::OnDraw( CDC *pDC )
  56. {
  57. CRect rect;
  58. GetClientRect( &rect );
  59. rect.left -= rect.Width() * 2 / 5;
  60. rect.top -= rect.Height() * 2 / 5;
  61. // calculate positions
  62. double d = 3.0 + (1.0 - m_PTZ.dZoom) * 21.0;
  63. INT w = rect.Width() / 2;
  64. INT h = rect.Height() / 2;
  65. double r = h;// * ( 0.2 + m_PTZ.dZoom * 0.8 );
  66. INT x1 = (INT)( ( cos( ( m_PTZ.dTilt + d ) / 360.0 * 6.2831 ) ) * r + w ) + rect.left;
  67. INT y1 = (INT)( ( sin( ( m_PTZ.dTilt + d ) / 360.0 * 6.2831 ) ) * r + h ) + rect.top;
  68. INT x2 = (INT)( ( cos( ( m_PTZ.dTilt - d ) / 360.0 * 6.2831 ) ) * r + w ) + rect.left;
  69. INT y2 = (INT)( ( sin( ( m_PTZ.dTilt - d ) / 360.0 * 6.2831 ) ) * r + h ) + rect.top;
  70. // redraw
  71. pDC->FillSolidRect( rect, RGB(0,0,0) );
  72. // draw
  73. POINT p[] = { { x1, y1 }, { x2, y2 }, { w, h } };
  74. // pDC->Polygon( p, 3 );
  75. // pDC->MoveTo( x1, y1 );
  76. // pDC->LineTo( w, h );
  77. // pDC->LineTo( x2, y2 );
  78. // POINT p[] = { { x1, y1 }, { x2, y2 } };
  79. COLORREF color = m_bSynchronized ? RGB(0,255,0) : RGB(255,0,0);
  80. CBrush brush( color );
  81. CPen pen( PS_SOLID, 1, color );
  82. CBrush *pBrush = pDC->SelectObject( &brush );
  83. CPen *pPen = pDC->SelectObject( &pen );
  84. rect.SetRect( (INT)(w-r+rect.top), (INT)(h-r+rect.top), (INT)(w+r+rect.top), (INT)(h+r+rect.top) );
  85. pDC->Pie( &rect, p[0], p[1] );
  86. // select old pen
  87. // pDC->SelectObject( pPen );
  88. // CPen pen1( PS_SOLID, 10, RGB(0xFF,0xFF,0xFF) );
  89. // pPen = pDC->SelectObject( &pen1 );
  90. /*
  91. GetClientRect( &rect );
  92. double l = ( sqrt( pow( rect.Width(), 2 ) + pow( rect.Height(), 2 ) ) - rect.Width() ) / 4;
  93. w = l;
  94. h = l;
  95. r = h * ( 0.2 + m_PTZ.dZoom * 0.8 ) * 2;
  96. x1 = (INT)( ( cos( ( m_PTZ.dTilt + d ) / 360.0 * 6.2831 ) ) * r + w );
  97. y1 = (INT)( ( sin( ( m_PTZ.dTilt + d ) / 360.0 * 6.2831 ) ) * r + h );
  98. x2 = (INT)( ( cos( ( m_PTZ.dTilt - d ) / 360.0 * 6.2831 ) ) * r + w );
  99. y2 = (INT)( ( sin( ( m_PTZ.dTilt - d ) / 360.0 * 6.2831 ) ) * r + h );
  100. POINT p1[] = { { x1, y1 }, { x2, y2 }, { w, h } };
  101. rect.SetRect( (INT)(-r), (INT)(rect.Height()-r*2), (INT)(r), (INT)(rect.Height()) );
  102. pDC->Pie( &rect, p1[0], p1[1] );
  103. */
  104. /*
  105. pDC->MoveTo( 0, rect.bottom - (INT)l );
  106. x1 = (INT)( ( cos( m_PTZ.dTilt / 360.0 * 6.2831 ) ) * l );
  107. y1 = (INT)( ( sin( m_PTZ.dTilt / 360.0 * 6.2831 ) ) * l ) + rect.bottom - (INT)l;
  108. pDC->LineTo( x1, y1 );
  109. */
  110. pDC->SelectObject( pPen );
  111. pDC->SelectObject( pBrush );
  112. }
  113. void CCameraPositionWnd::OnSize(UINT nType, int cx, int cy)
  114. {
  115. CWnd::OnSize(nType, cx, cy);
  116. m_MemoryDC.Create( cx, cy );
  117. }
  118. void CCameraPositionWnd::SetPosition( double pan, double tilt, double zoom, BOOL bSynch )
  119. {
  120. m_PTZ.dPan = pan;
  121. m_PTZ.dTilt = tilt;
  122. m_PTZ.dZoom = zoom;
  123. m_bSynchronized = bSynch;
  124. if( GetSafeHwnd() )
  125. InvalidateRect( NULL );
  126. }