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.

175 lines
4.0 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: PropertyLGSWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of PropertyLGSWnd.cpp
  13. //----------------------------------------------------------------------------
  14. // PropertyLGSWnd.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "PropertyLGSWnd.h"
  18. #include "..\..\LgLib\Version.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CPropertyLGSWnd
  26. CPropertyLGSWnd::CPropertyLGSWnd()
  27. {
  28. m_bInverse = FALSE;
  29. m_pSensor = NULL;
  30. m_vPoint = CPoint(0,0);
  31. m_bUseVZ = FALSE;
  32. }
  33. CPropertyLGSWnd::~CPropertyLGSWnd()
  34. {
  35. m_vRgn.DeleteObject();
  36. }
  37. BEGIN_MESSAGE_MAP(CPropertyLGSWnd, CWnd)
  38. //{{AFX_MSG_MAP(CPropertyLGSWnd)
  39. ON_WM_PAINT()
  40. ON_WM_TIMER()
  41. ON_WM_LBUTTONDOWN()
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CPropertyLGSWnd message handlers
  46. void CPropertyLGSWnd::OnPaint()
  47. {
  48. CPaintDC dc(this);
  49. Draw( &dc );
  50. }
  51. void CPropertyLGSWnd::OnTimer(UINT nIDEvent)
  52. {
  53. m_bInverse = nIDEvent;
  54. CClientDC dc(this);
  55. Draw( &dc );
  56. CWnd::OnTimer(nIDEvent);
  57. }
  58. void CPropertyLGSWnd::SetSensor(CSensorLGS *pSensor)
  59. {
  60. m_pSensor = pSensor;
  61. CClientDC dc(this);
  62. Draw( &dc );
  63. }
  64. void CPropertyLGSWnd::Draw(CDC *pDC)
  65. {
  66. if( m_pSensor && IsWindowVisible() )
  67. {
  68. CRect rect;
  69. GetClientRect( &rect );
  70. CSurfaceLGS *pSurface = m_pSensor->GetSurface();
  71. m_MemDC.StretchBlt( rect.left, rect.top, rect.Width(), rect.Height(),
  72. pSurface, 0, 0, pSurface->GetSize().cx, pSurface->GetSize().cy, SRCCOPY );
  73. if( m_bUseVZ )
  74. {
  75. CBrush brush( HS_DIAGCROSS, RGB(0,0,0) );
  76. m_MemDC.SetBkMode( TRANSPARENT );
  77. m_MemDC.FillRgn( &m_vRgn, &brush );
  78. int r = rect.Width() / 20;
  79. int x = rect.Width() / 2 + m_vPoint.x;
  80. int y = rect.Height() / 2 + m_vPoint.y;
  81. m_MemDC.Arc( x - r, y - r, x + r, y + r, 0,0,0,0 );
  82. }
  83. pDC->BitBlt( 0, 0, rect.Width(), rect.Height(), &m_MemDC, 0, 0, SRCCOPY );
  84. }
  85. }
  86. BOOL CPropertyLGSWnd::Create( CWnd *pParentWnd, int x, int y, int cx, int cy )
  87. {
  88. CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_CROSS ), NULL, NULL );
  89. CRect rect( x, y, x + cx, y + cy );
  90. if( CWnd::Create( strClassName, NULL, WS_CHILD, rect, pParentWnd, 0 ) )
  91. {
  92. m_MemDC.Create( cx, cy );
  93. CRect rect;
  94. GetClientRect( &rect );
  95. CPoint point( rect.Width() / 2, rect.Height() / 2 );
  96. CreateRgn( rect, point );
  97. return TRUE;
  98. }
  99. return FALSE;
  100. }
  101. void CPropertyLGSWnd::OnLButtonDown( UINT nFlags, CPoint point )
  102. {
  103. CRect rect;
  104. GetClientRect( &rect );
  105. CreateRgn( rect, point );
  106. CWnd::OnLButtonDown( nFlags, point );
  107. }
  108. void CPropertyLGSWnd::CreateRgn( CRect &rect, CPoint &point )
  109. {
  110. // if( m_vRgn.GetSafeHandle() )
  111. m_vRgn.DeleteObject();
  112. m_vPoint = point - CPoint( rect.Width() / 2, rect.Height() / 2 );
  113. int r = rect.Width() / 20;
  114. int x = rect.Width() / 2 + m_vPoint.x;
  115. int y = rect.Height() / 2 + m_vPoint.y;
  116. CRgn rgn;
  117. rgn.CreateRectRgnIndirect( &rect );
  118. m_vRgn.CreateEllipticRgn( x - r, y - r, x + r, y + r );
  119. m_vRgn.CombineRgn( &rgn, &m_vRgn, RGN_DIFF );
  120. rgn.DeleteObject();
  121. }
  122. void CPropertyLGSWnd::UseVisibleZone(BOOL bUse)
  123. {
  124. m_bUseVZ = bUse;
  125. }
  126. BOOL CPropertyLGSWnd::GetFilter( double &x, double &y, double &r )
  127. {
  128. if( m_bUseVZ )
  129. {
  130. CRect rect;
  131. GetClientRect( &rect );
  132. x = ((double)m_vPoint.x) / ( rect.Width() / 2 );
  133. y = ((double)m_vPoint.y) / ( rect.Height() / 2 );
  134. r = ( ((double)rect.Width()) / 20.0 ) / ( rect.Width() / 2 );
  135. return TRUE;
  136. }
  137. return FALSE;
  138. }