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.

232 lines
6.2 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: 27/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgSubSiteDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgSubSiteDlg.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "lglibreport.h"
  16. #include "LgSubSiteDlg.h"
  17. #include "LgReportDlg.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. CLgSubSiteDlg::CLgSubSiteDlg(CWnd* pParent /*=NULL*/)
  24. : CDialog(CLgSubSiteDlg::IDD, pParent)
  25. {
  26. //{{AFX_DATA_INIT(CLgSubSiteDlg)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. m_pReportDlg = NULL;
  30. m_bPosition = FALSE;
  31. m_bDirty = TRUE;
  32. }
  33. void CLgSubSiteDlg::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CDialog::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CLgSubSiteDlg)
  37. // NOTE: the ClassWizard will add DDX and DDV calls here
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CLgSubSiteDlg, CDialog)
  41. //{{AFX_MSG_MAP(CLgSubSiteDlg)
  42. ON_WM_PAINT()
  43. ON_WM_SIZE()
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CLgSubSiteDlg message handlers
  48. BOOL CLgSubSiteDlg::Create(CLgReportDlg *pReportDlg, CWnd *pParentWnd, CRect *pRect )
  49. {
  50. m_pReportDlg = pReportDlg;
  51. if( !CDialog::Create( IDD, pParentWnd ) )
  52. return FALSE;
  53. ShowWindow( SW_SHOW );
  54. CRect rect;
  55. if( pRect )
  56. rect = *pRect;
  57. else
  58. pParentWnd->GetClientRect( &rect );
  59. MoveWindow( &rect );
  60. return TRUE;
  61. }
  62. void CLgSubSiteDlg::OnPaint()
  63. {
  64. CPaintDC dc(this);
  65. dc.BitBlt( 0, 0, m_MemoryDC.GetSize().cx, m_MemoryDC.GetSize().cy, &m_MemoryDC, 0, 0, SRCCOPY );
  66. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgSubSiteDlg::OnPaint"), _T("") );
  67. }
  68. void CLgSubSiteDlg::OnSize(UINT nType, int cx, int cy)
  69. {
  70. CDialog::OnSize(nType, cx, cy);
  71. m_MemoryDC.Create( cx, cy );
  72. m_MemoryOriginalDC.Create( cx, cy );
  73. m_Rect.SetRect( 0, 0, cx, cy );
  74. m_bPosition = FALSE;
  75. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgSubSiteDlg::OnSize"), _T("") );
  76. }
  77. BOOL CLgSubSiteDlg::Draw( CLgImageJPEG *pJpeg )
  78. {
  79. if( !pJpeg && !m_bDirty )
  80. return TRUE;
  81. CSize size = m_MemoryDC.GetSize();
  82. m_MemoryOriginalDC.Create( size.cx, size.cy );
  83. m_Rect.SetRect( 0, 0, size.cx, size.cy );
  84. if( pJpeg )
  85. {
  86. CLgImageDIB dib;
  87. if( dib.Create( pJpeg ) )
  88. {
  89. CSize bgSize( static_cast<LPBITMAPINFOHEADER>(dib)->biWidth,
  90. static_cast<LPBITMAPINFOHEADER>(dib)->biHeight );
  91. double dAspectSrc = (double)bgSize.cx / (double)bgSize.cy;
  92. double dAspectDst = (double)size.cx / (double)size.cy;
  93. if( dAspectSrc < dAspectDst ) m_Rect.SetRect( 0, 0, (INT)( size.cy * dAspectSrc ), size.cy );
  94. else m_Rect.SetRect( 0, 0, size.cx, (INT)( size.cx / dAspectSrc ) );
  95. INT nDeltaX = size.cx - m_Rect.Width();
  96. INT nDeltaY = size.cy - m_Rect.Height();
  97. m_Rect.OffsetRect( nDeltaX / 2, nDeltaY / 2 );
  98. dib.Draw( m_MemoryOriginalDC.GetSafeHdc(), &m_Rect );
  99. m_bDirty = TRUE;
  100. }
  101. }
  102. m_MemoryDC.BitBlt( 0, 0, size.cx, size.cy, &m_MemoryOriginalDC, 0, 0, SRCCOPY );
  103. m_Position.x = m_Position.y = 0;
  104. CClientDC dc( this );
  105. dc.BitBlt( 0, 0, m_MemoryDC.GetSize().cx, m_MemoryDC.GetSize().cy, &m_MemoryDC, 0, 0, SRCCOPY );
  106. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgSubSiteDlg::Draw"), _T("") );
  107. return TRUE;
  108. }
  109. #define TARGET_SIZE 4
  110. BOOL CLgSubSiteDlg::DrawPosition( REPORT_EVENT_BASE *pEvent )
  111. {
  112. CClientDC dc( this );
  113. // restore background after cross
  114. if( m_bPosition )
  115. {
  116. dc.BitBlt( m_Position.x - TARGET_SIZE - 1, m_Position.y - TARGET_SIZE - 1, TARGET_SIZE * 2 + 2, TARGET_SIZE * 2 + 2,
  117. &m_MemoryDC, m_Position.x - TARGET_SIZE - 1, m_Position.y - TARGET_SIZE - 1, SRCCOPY );
  118. m_bPosition = FALSE;
  119. }
  120. if( !pEvent || !pEvent->bPositionValid )
  121. return TRUE;
  122. m_bPosition = TRUE;
  123. m_Position.x = (INT)( pEvent->fPositionX * m_Rect.Width() ) + m_Rect.left;
  124. m_Position.y = (INT)( pEvent->fPositionY * m_Rect.Height() ) + m_Rect.top;
  125. DrawCross();
  126. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgSubSiteDlg::DrawPosition"), _T("") );
  127. return TRUE;
  128. }
  129. BOOL CLgSubSiteDlg::DrawTarget( REPORT_EVENT_BASE *pEvent )
  130. {
  131. if( !pEvent || !pEvent->bPositionValid )
  132. return TRUE;
  133. INT x = (INT)( pEvent->fPositionX * m_Rect.Width() ) + m_Rect.left;
  134. INT y = (INT)( pEvent->fPositionY * m_Rect.Height() ) + m_Rect.top;
  135. CPen pen( PS_SOLID, 2, RGB( 0xFF,0x3F,0x3F ) );
  136. CPen *pPen = m_MemoryDC.SelectObject( &pen );
  137. m_MemoryDC.Rectangle( x - 1, y - 1, x + 1, y + 1 );
  138. m_MemoryDC.SelectObject( pPen );
  139. CClientDC dc( this );
  140. dc.BitBlt( x - 1, y - 1, 2 + 1, 2 + 1, &m_MemoryDC, x - 1, y - 1, SRCCOPY );
  141. DrawCross();
  142. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgSubSiteDlg::DrawTarget"), _T("") );
  143. return TRUE;
  144. }
  145. BOOL CLgSubSiteDlg::ClearTarget()
  146. {
  147. CClientDC dc( this );
  148. if( !m_MemoryDC.BitBlt( 0, 0, m_MemoryOriginalDC.GetSize().cx, m_MemoryOriginalDC.GetSize().cy, &m_MemoryOriginalDC, 0, 0, SRCCOPY ) )
  149. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgSubSiteDlg::ClearTarget"), _T("Restore orinal failed") );
  150. if( !dc.BitBlt( 0, 0, m_MemoryOriginalDC.GetSize().cx, m_MemoryOriginalDC.GetSize().cy, &m_MemoryOriginalDC, 0, 0, SRCCOPY ) )
  151. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgSubSiteDlg::ClearTarget"), _T("Paint orinal failed") );
  152. m_bPosition = FALSE;
  153. return TRUE;
  154. }
  155. BOOL CLgSubSiteDlg::DrawCross()
  156. {
  157. if( !m_bPosition )
  158. return FALSE;
  159. CClientDC dc( this );
  160. CPen pen( PS_SOLID, 2, RGB( 0xFF,0xFF,0xFF ) );
  161. CPen *pPen = dc.SelectObject( &pen );
  162. dc.MoveTo( m_Position.x - TARGET_SIZE, m_Position.y - TARGET_SIZE );
  163. dc.LineTo( m_Position.x + TARGET_SIZE, m_Position.y + TARGET_SIZE );
  164. dc.MoveTo( m_Position.x + TARGET_SIZE, m_Position.y - TARGET_SIZE );
  165. dc.LineTo( m_Position.x - TARGET_SIZE, m_Position.y + TARGET_SIZE );
  166. dc.SelectObject( pPen );
  167. return TRUE;
  168. }