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.

826 lines
22 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 09/04/2000
  5. // Last modification: 30/10/2002
  6. // Project Intruder Position Indicator
  7. // SUBSYSTEM: Locator
  8. // FILE: Locator.cpp
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of implementation of class CLocator
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. #include "..\LgLib\LgImageDIB.h"
  17. #include "Locator.h"
  18. #define _PI_ 3.1415926535897932384626433832795
  19. CLocator::CLocator()
  20. {
  21. ZeroMemory(this, sizeof(*this));
  22. m_OldEditPoint.x = m_OldEditPoint.y = -1;
  23. m_Scale = 0.5859375;//?1.0;
  24. m_pProfile = FALSE;
  25. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLocator::CLocator" );
  26. }
  27. CLocator::~CLocator()
  28. {
  29. if(m_hFont)
  30. ::DeleteObject(m_hFont);
  31. if(m_pCurPolygon)
  32. {
  33. delete m_pCurPolygon;
  34. m_pCurPolygon = NULL;
  35. }
  36. if(m_hBitmap)
  37. {
  38. ::DestroyWindow(m_hWnd);
  39. ::SelectObject(m_hMemDC2, m_hBitmapScalesOld);
  40. ::DeleteObject(m_hBitmapScales[0]);
  41. ::DeleteObject(m_hBitmapScales[1]);
  42. ::DeleteObject(m_hBitmapScales[2]);
  43. ::DeleteObject(m_hBitmap);
  44. ::DeleteDC(m_hMemDC2);
  45. ::DeleteDC(m_hMemDC1);
  46. }
  47. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLocator::~CLocator" );
  48. }
  49. LRESULT CLocator::WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
  50. {
  51. POINT pt;
  52. HDC hDC;
  53. PAINTSTRUCT ps;
  54. LRESULT bResult;
  55. RECT rect;
  56. SIZE size;
  57. switch(Msg)
  58. {
  59. case WM_CREATE:
  60. return OnWmCreate( hWnd, (LPCREATESTRUCT)lParam );
  61. case WM_LBUTTONDOWN:
  62. ::GetClientRect( hWnd, &rect );
  63. pt.x = (SHORT)(LOWORD(lParam)) - ((rect.right-rect.left) >> 1);
  64. pt.y = (SHORT)(HIWORD(lParam)) - ((rect.bottom-rect.top) >> 1);
  65. // if(sqrt(pt.x * pt.x + pt.y * pt.y) <= ((rect.right-rect.left) >> 1))
  66. OnLButtonDown(pt);
  67. return 0L;
  68. case WM_RBUTTONDOWN:
  69. ::GetClientRect( hWnd, &rect );
  70. pt.x = (SHORT)(LOWORD(lParam)) - ((rect.right-rect.left) >> 1);
  71. pt.y = (SHORT)(HIWORD(lParam)) - ((rect.bottom-rect.top) >> 1);
  72. OnRButtonDown(pt);
  73. return 0L;
  74. case WM_MOUSEMOVE:
  75. ::GetClientRect( hWnd, &rect );
  76. pt.x = (SHORT)(LOWORD(lParam)) - ((rect.right-rect.left) >> 1);
  77. pt.y = (SHORT)(HIWORD(lParam)) - ((rect.bottom-rect.top) >> 1);
  78. OnMouseMove(pt);
  79. return 0L;
  80. case WM_PAINT:
  81. hDC = ::BeginPaint( hWnd, &ps );
  82. bResult = OnWmPaint( hWnd, hDC );
  83. ::EndPaint( hWnd, &ps );
  84. return bResult;
  85. case WM_SIZE:
  86. size.cx = (SHORT)(LOWORD(lParam));
  87. size.cy = (SHORT)(HIWORD(lParam));
  88. return OnWmSize( hWnd, wParam, &size );
  89. }
  90. return ::DefWindowProc(hWnd, Msg, wParam, lParam);
  91. }
  92. LRESULT CLocator::OnWmCreate( HWND hWnd, LPCREATESTRUCT pCreateStruct )
  93. {
  94. return 0UL;
  95. }
  96. LRESULT CLocator::OnWmPaint( HWND, HDC hDC )
  97. {
  98. if( !m_hBitmap )
  99. return 1UL;
  100. // get bitmap dimensions
  101. DIBSECTION DibSection;
  102. if( !::GetObject( m_hBitmap, sizeof(DibSection), &DibSection ) )
  103. return 1UL;
  104. // draw bitmap onto screen
  105. HBITMAP hOldBitmap = (HBITMAP)::SelectObject( m_hMemDC1, m_hBitmap );
  106. ::StretchBlt( hDC, 0, 0, m_Size.cx, m_Size.cy, m_hMemDC1, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmWidth, SRCCOPY );
  107. ::SelectObject( m_hMemDC1, hOldBitmap );
  108. return 0UL;
  109. }
  110. LRESULT CLocator::OnWmSize( HWND hWnd, WPARAM, LPSIZE pSize )
  111. {
  112. // delete old bitmap
  113. if( m_hBitmap )
  114. {
  115. ::DeleteObject( m_hBitmap );
  116. m_hBitmap = NULL;
  117. }
  118. // allocate new bitmap
  119. HDC hDC = GetDC( hWnd );
  120. if( hDC )
  121. {
  122. m_hBitmap = ::CreateCompatibleBitmap( hDC, pSize->cx, pSize->cy );
  123. ::ReleaseDC( hWnd, hDC );
  124. }
  125. // clear bitmap
  126. if( m_hBitmap )
  127. {
  128. HBITMAP hOldBmp = (HBITMAP)::SelectObject( m_hMemDC1, m_hBitmap );
  129. RECT rect = { 0, 0, pSize->cx, pSize->cy };
  130. ::FillRect( m_hMemDC1, &rect, (HBRUSH)::GetStockObject(BLACK_BRUSH) );
  131. ::SelectObject( m_hMemDC1, hOldBmp );
  132. }
  133. // remember size
  134. m_Size = *pSize;
  135. // move static window
  136. ::MoveWindow( m_hIconWnd, m_Size.cx - 32, m_Size.cy - 32, m_Size.cx, m_Size.cy, TRUE );
  137. return 0UL;
  138. }
  139. LRESULT CALLBACK CLocator::WndProc_(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  140. {
  141. CLocator* pLocator = (CLocator*)::GetWindowLong( hWnd, GWL_USERDATA );
  142. if( pLocator )
  143. return pLocator->WndProc( hWnd, Msg, wParam, lParam );
  144. if( Msg == WM_CREATE )
  145. {
  146. CLocator *pLocator = (CLocator*)((LPCREATESTRUCT)lParam)->lpCreateParams;
  147. if( pLocator )
  148. {
  149. ::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pLocator );
  150. return pLocator->WndProc( hWnd, Msg, wParam, lParam );
  151. }
  152. }
  153. return ::DefWindowProc( hWnd, Msg, wParam, lParam );
  154. }
  155. bool CLocator::Create( HWND hWnd, CProfile* pProfile, CPolygons* pPolygons, LPPOINT pPoint, LPSIZE pSize )
  156. {
  157. static const POINT p = { 0, 0 };
  158. static const SIZE s = {300, 300 };//{ 513, 513 };
  159. LOGFONT lf = {0};
  160. // RECT rect = { 0, 0, m_Size.cx, m_Size.cy };
  161. if(!pPoint)
  162. pPoint = (LPPOINT)&p;
  163. if(!pSize)
  164. pSize = (LPSIZE)&s;
  165. m_pPolygons = pPolygons;
  166. m_pProfile = pProfile;
  167. WNDCLASS wc;
  168. wc.cbClsExtra = 0;
  169. wc.cbWndExtra = 0;
  170. wc.hbrBackground = NULL;
  171. wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  172. wc.hIcon = NULL;
  173. wc.hInstance = (HINSTANCE)::GetWindowLong(hWnd, GWL_HINSTANCE);
  174. wc.lpfnWndProc = WndProc_;
  175. wc.lpszClassName = "LocatorWndClass";
  176. wc.lpszMenuName = NULL;
  177. wc.style = CS_HREDRAW | CS_VREDRAW;
  178. if( !::RegisterClass( &wc ) )
  179. return FALSE;
  180. m_hWnd = ::CreateWindow( wc.lpszClassName, NULL, WS_CHILD | SS_BITMAP | SS_NOTIFY, pPoint->x, pPoint->y,
  181. pSize->cx, pSize->cy, hWnd, NULL, wc.hInstance, this );
  182. // create notification icon wnd
  183. m_hIconWnd = ::CreateWindowEx( WS_EX_CLIENTEDGE, "STATIC", NULL, SS_ICON | WS_CHILD | WS_VISIBLE, 0, 0, 32, 32, m_hWnd, NULL, wc.hInstance, 0 );
  184. ::MoveWindow( m_hIconWnd, m_Size.cx - 40, m_Size.cy - 40, m_Size.cx, m_Size.cy, TRUE );
  185. m_hCursorNormal = (HCURSOR)::GetClassLong(m_hWnd, GCL_HCURSOR);
  186. m_hCursorEdit = (HCURSOR)::LoadCursor(NULL, IDC_CROSS);
  187. // m_Size = *pSize;
  188. m_Range = pProfile->LgsRange();
  189. m_North = pProfile->LgsNorth();
  190. HDC hDC = ::GetDC(m_hWnd);
  191. m_hMemDC1 = ::CreateCompatibleDC(hDC);
  192. m_hMemDC2 = ::CreateCompatibleDC(hDC);
  193. // m_hBitmap = ::CreateCompatibleBitmap(hDC, m_Size.cx, m_Size.cy);
  194. ::ReleaseDC(m_hWnd, hDC);
  195. LoadBitmaps(pProfile);
  196. DrawNorth();
  197. ZeroMemory(&lf, sizeof(lf));
  198. lf.lfHeight = 14;
  199. lf.lfCharSet = ANSI_CHARSET;
  200. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  201. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  202. lf.lfQuality = DEFAULT_QUALITY;
  203. lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
  204. _tcscpy(lf.lfFaceName, _T("Courier"));
  205. m_hFont = ::CreateFontIndirect(&lf);
  206. ::SendMessage(m_hWnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)m_hBitmap);
  207. SetScale(2);
  208. return true;
  209. }
  210. void CLocator::AddTarget(const TARGET_DESCRIPTION& td)
  211. {
  212. const float RTOD = 0.01745329252F;
  213. if(td.range <= m_Range * m_Scale)
  214. {
  215. HBITMAP hOldBmp = (HBITMAP)::SelectObject(m_hMemDC1, m_hBitmap);
  216. COLORREF color;
  217. switch(td.master)
  218. {
  219. case 'b':
  220. color = m_bDebugMode ? 0x00FFFFFF : 0x0000FFFF;
  221. break;
  222. case 'a':
  223. color = 0x0000FFFF;
  224. break;
  225. case 'f':
  226. color = 0x00FF0000;
  227. break;
  228. case 'w':
  229. // color = 0x000000FF;
  230. color = m_bDebugMode ? 0x000000FF : 0x0000FFFF;
  231. break;
  232. }
  233. HPEN hPen = ::CreatePen(PS_SOLID, 1, color);
  234. HPEN hOldPen = (HPEN)::SelectObject(m_hMemDC1, hPen);
  235. HBRUSH hBrush = ::CreateSolidBrush(color);
  236. HBRUSH hOldBrush = (HBRUSH)::SelectObject(m_hMemDC1, hBrush);
  237. // 24/05/2001
  238. int x = (INT)( cos(td.angle * RTOD) * td.range * (m_Size.cx >> 1) / (m_Scale * m_Range)) + (m_Size.cx >> 1);
  239. int y = (INT)(-sin(td.angle * RTOD) * td.range * (m_Size.cy >> 1) / (m_Scale * m_Range)) + (m_Size.cy >> 1);
  240. ::Ellipse(m_hMemDC1, x - (m_Size.cx >> 7), y - (m_Size.cy >> 7),
  241. x + (m_Size.cx >> 7), y + (m_Size.cy >> 7) );// change from 3 to 2
  242. ::SelectObject(m_hMemDC1, hOldPen);
  243. ::SelectObject(m_hMemDC1, hOldBrush);
  244. ::DeleteObject(hPen);
  245. ::DeleteObject(hBrush);
  246. ::SelectObject(m_hMemDC1, hOldBmp);
  247. RECT rect = { x - 4, y - 4, x + 4, y + 4 };
  248. ::InvalidateRect( m_hWnd, &rect, FALSE );
  249. ::UpdateWindow( m_hWnd );
  250. } // end of if(td.range <= m_Range * m_Scale)
  251. }
  252. void CLocator::DrawProgress( LPCTSTR pText, INT nSize )
  253. {
  254. HDC hDC = ::GetDC( m_hWnd );
  255. RECT rect = { 0, m_Size.cy - 20, 90, m_Size.cy };
  256. ::SetTextColor( hDC, 0x00FFFFFF );
  257. ::SetBkColor( hDC, 0 );
  258. HFONT hFontOld = (HFONT)::SelectObject( hDC, m_hFont );
  259. ::TextOut( hDC, rect.left, rect.top, pText, nSize );
  260. ::SelectObject( hDC, hFontOld );
  261. ::ReleaseDC( m_hWnd, hDC );
  262. }
  263. void CLocator::Reset()
  264. {
  265. POINT p = { m_Size.cx >> 1, m_Size.cy >> 1 };
  266. HBITMAP hOldBmp = (HBITMAP)::SelectObject(m_hMemDC1, m_hBitmap);
  267. // get bitmap dimensions
  268. DIBSECTION DibSection;
  269. ::GetObject( m_hBitmapScales[0], sizeof(DibSection), &DibSection );
  270. // draw bitmap onto screen
  271. ::StretchBlt( m_hMemDC1, 0, 0, m_Size.cx, m_Size.cy, m_hMemDC2, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmWidth, SRCCOPY );
  272. // ::BitBlt(m_hMemDC1, 0, 0, m_Size.cx, m_Size.cy, m_hMemDC2, 0, 0, SRCCOPY);
  273. HRGN hRgn = ::CreateEllipticRgn(0, 0, m_Size.cx, m_Size.cy);
  274. ::SelectClipRgn(m_hMemDC1, hRgn);
  275. ::DeleteObject(hRgn); // It can be deleted
  276. m_pPolygons->Draw( m_hMemDC1, p, (m_Size.cx >> 1) / (m_Range * m_Scale) );
  277. if(m_bEditorMode)
  278. m_pPolygons->ProduceHiddenZones(m_hMemDC1, p, m_Range, (m_Size.cx >> 1) / (m_Range * m_Scale));
  279. ::SelectClipRgn(m_hMemDC1, NULL);
  280. ::SelectObject(m_hMemDC1, hOldBmp);
  281. RECT rect = { 0, 0, m_Size.cx, m_Size.cy };
  282. ::InvalidateRect(m_hWnd, &rect, FALSE);
  283. ::UpdateWindow(m_hWnd);
  284. }
  285. bool CLocator::StoreImage( LPCTSTR pPathName )
  286. {
  287. CLgImageDIB dib;
  288. if( dib.Create( m_hBitmap ) )
  289. {
  290. dib.Save( pPathName );
  291. }
  292. return true;
  293. /*
  294. HANDLE hFile = ::CreateFile( pPathName, GENERIC_WRITE,
  295. FILE_SHARE_READ, NULL, OPEN_ALWAYS,
  296. FILE_ATTRIBUTE_NORMAL, NULL);
  297. if(hFile != INVALID_HANDLE_VALUE)
  298. {
  299. BITMAPFILEHEADER bfh;
  300. BITMAPINFO bmi;
  301. DWORD dwWrite;
  302. ZeroMemory(&bmi, sizeof(bmi));
  303. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  304. ::GetDIBits(m_hMemDC1, m_hBitmap, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
  305. bmi.bmiHeader.biCompression = 0;
  306. bmi.bmiHeader.biBitCount = 16;
  307. bmi.bmiHeader.biSizeImage = WIDTHBYTES( bmi.bmiHeader.biWidth * bmi.bmiHeader.biBitCount ) * bmi.bmiHeader.biHeight;
  308. LPBYTE pByte = new BYTE[bmi.bmiHeader.biSizeImage];
  309. ::GetDIBits( m_hMemDC1, m_hBitmap, 0, bmi.bmiHeader.biHeight, pByte, &bmi, DIB_RGB_COLORS);
  310. bfh.bfType = (((WORD)'M') << 8) + 'B';
  311. bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmi.bmiHeader.biSizeImage;
  312. bfh.bfReserved1 = 0;
  313. bfh.bfReserved2 = 0;
  314. bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  315. ::WriteFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwWrite, NULL);
  316. ::WriteFile(hFile, &bmi, sizeof(BITMAPINFOHEADER), &dwWrite, NULL);
  317. ::WriteFile(hFile, pByte, bmi.bmiHeader.biSizeImage, &dwWrite, NULL);
  318. delete[] pByte; // Added delete[] 12/03/2001
  319. ::CloseHandle(hFile);
  320. return true;
  321. }
  322. return false;
  323. */
  324. }
  325. void CLocator::LoadBitmaps(CProfile *pProfile)
  326. {
  327. if(m_hBitmapScalesOld)
  328. ::SelectObject(m_hMemDC2, m_hBitmapScalesOld);
  329. for(int i = 0; i < 3; i++)
  330. {
  331. if(m_hBitmapScales[i])
  332. {
  333. ::DeleteObject(m_hBitmapScales[i]);
  334. m_hBitmapScales[i] = NULL;
  335. }
  336. }
  337. m_hBitmapScales[0] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
  338. pProfile->SettingsScreen020(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
  339. // If no exist bitmap load from resource 13/03/2001
  340. if(m_hBitmapScales[0] == NULL)
  341. m_hBitmapScales[0] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
  342. MAKEINTRESOURCE(IDB_BITMAP_SCREEN), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
  343. m_hBitmapScales[1] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
  344. pProfile->SettingsScreen050(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_DEFAULTSIZE);
  345. // If no exist bitmap load from resource 13/03/2001
  346. if(m_hBitmapScales[1] == NULL)
  347. m_hBitmapScales[1] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
  348. MAKEINTRESOURCE(IDB_BITMAP_SCREEN), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
  349. m_hBitmapScales[2] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
  350. pProfile->SettingsScreen100(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
  351. // If no exist bitmap load from resource 13/03/2001
  352. if(m_hBitmapScales[2] == NULL)
  353. m_hBitmapScales[2] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
  354. MAKEINTRESOURCE(IDB_BITMAP_SCREEN), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
  355. // draw fixed video regions
  356. double scale[] = { 0.2, 0.5, 1.0 };
  357. for( i = 0; i < 3; i++ )
  358. {
  359. DIBSECTION DibSection;
  360. ::GetObject( m_hBitmapScales[i], sizeof(DibSection), &DibSection );
  361. RECT rect = { 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmHeight };
  362. HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC2, m_hBitmapScales[i] );
  363. DrawFixedVideo( m_hMemDC2, rect, 1.0 / scale[i] );
  364. (HBITMAP)::SelectObject( m_hMemDC2, hBitmap );
  365. }
  366. m_hBitmapScalesOld = (HBITMAP)::SelectObject(m_hMemDC2, m_hBitmapScales[0]);
  367. }
  368. void CLocator::DrawFixedVideo( HDC hDC, RECT& rect, double scale )
  369. {
  370. // fixed video enabled
  371. if( !m_pProfile->FixedVideoEnable() ||
  372. !m_pProfile->GetFixedVideoRegionArray().GetCount() )
  373. return;
  374. SIZE size = { rect.right - rect.left, rect.bottom - rect.top };
  375. // create refference bitmap & DC
  376. HDC hSrcDC = ::CreateCompatibleDC( hDC );
  377. HBITMAP hSrcBmp = ::CreateCompatibleBitmap( hDC, size.cx, size.cy );
  378. HBITMAP hBitmap = (HBITMAP) ::SelectObject( hSrcDC, hSrcBmp );
  379. // initialize pen and brush
  380. HPEN hPen = ::CreatePen( PS_SOLID, 1, RGB(255,0,0) );
  381. HPEN hPenOld = (HPEN)::SelectObject( hSrcDC, hPen );
  382. HBRUSH hBrush = ::CreateSolidBrush( RGB(255,100,100) );
  383. HBRUSH hBrushOld = (HBRUSH)::SelectObject( hSrcDC, hBrush );
  384. // prepare pointer to new region
  385. HRGN hRgn = NULL;
  386. // draw regions
  387. CLocatorRegionArray& array = m_pProfile->GetFixedVideoRegionArray();
  388. for( INT i = 0; i < array.GetCount(); i++ )
  389. {
  390. CLocatorRegion& region = array[i];
  391. // allocate points for region points
  392. LPPOINT pPoint = new POINT[ region.GetCount() ];
  393. if( !pPoint )
  394. continue;
  395. // convert region points to dc points
  396. for( INT i = 0; i < region.GetCount(); i++ )
  397. {
  398. CLgDPoint& dp = region[i];
  399. pPoint[i].x = size.cx * ( 1.0 + scale * dp.x ) / 2.0;
  400. pPoint[i].y = size.cy * ( 1.0 + scale * dp.y ) / 2.0;
  401. }
  402. // draw region
  403. ::Polygon( hSrcDC, pPoint, region.GetCount() );
  404. // accumulate region
  405. if( !hRgn )
  406. hRgn = ::CreatePolygonRgn( pPoint, region.GetCount(), WINDING );
  407. else
  408. {
  409. HRGN hTempRgn = ::CreatePolygonRgn( pPoint, region.GetCount(), WINDING );
  410. ::CombineRgn( hRgn, hRgn, hTempRgn, RGN_OR );
  411. ::DeleteObject( hTempRgn );
  412. }
  413. // delete array
  414. delete pPoint;
  415. }
  416. // clip regions with circle
  417. HRGN hTempRgn = ::CreateEllipticRgn( rect.left, rect.top, rect.right, rect.bottom );
  418. ::CombineRgn( hRgn, hRgn, hTempRgn, RGN_AND );
  419. ::DeleteObject( hTempRgn );
  420. // store old clipping region
  421. HRGN hRgnOld = ::CreateRectRgn(0,0,1,1);
  422. INT nRgnOld = ::GetClipRgn( hDC, hRgnOld );
  423. // set new clip region
  424. ::SelectClipRgn( hDC, hRgn );
  425. // copy image to distanation
  426. BLENDFUNCTION bf;
  427. bf.BlendOp = AC_SRC_OVER;
  428. bf.BlendFlags = 0;
  429. bf.AlphaFormat = 0;
  430. bf.SourceConstantAlpha = 100;
  431. ::AlphaBlend( hDC, 0, 0, size.cx, size.cy, hSrcDC, 0, 0, size.cx, size.cy, bf );
  432. // restore old clip region
  433. switch( nRgnOld )
  434. {
  435. case 0: ::SelectClipRgn( hDC, NULL ); break;
  436. case 1: ::SelectClipRgn( hDC, hRgnOld ); break;
  437. }
  438. // delete created regions
  439. ::DeleteObject( hRgn );
  440. ::DeleteObject( hRgnOld );
  441. // return old pen and brush parameters
  442. ::SelectObject( hSrcDC, hPenOld );
  443. ::SelectObject( hSrcDC, hBrushOld );
  444. // delete refference bitmap & DC
  445. ::SelectObject( hSrcDC, hBitmap );
  446. ::DeleteObject( hSrcDC );
  447. ::DeleteDC( hSrcDC );
  448. }
  449. void CLocator::SetScale(INT nScale)
  450. {
  451. switch(nScale)
  452. {
  453. case 0:
  454. m_Scale = 0.20;
  455. break;
  456. case 1:
  457. m_Scale = 0.50;
  458. break;
  459. case 2:
  460. m_Scale = 1.00;
  461. }
  462. ::SelectObject(m_hMemDC2, m_hBitmapScales[nScale]);
  463. Reset();
  464. }
  465. void CLocator::DrawNorth()
  466. {
  467. if(m_North != -1)
  468. {
  469. POINT pN[4] = { { (INT)( cos(m_North * _PI_/180.0) * 1.0 * m_Size.cx / 2 ) + m_Size.cx / 2,
  470. (INT)(-sin(m_North * _PI_/180.0) * 1.0 * m_Size.cy / 2 ) + m_Size.cy / 2 },
  471. { (INT)( cos((m_North + 2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
  472. (INT)(-sin((m_North + 2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 },
  473. { (INT)( cos(m_North * _PI_/180.0) * 0.93 * m_Size.cx / 2 ) + m_Size.cx / 2,
  474. (INT)(-sin(m_North * _PI_/180.0) * 0.93 * m_Size.cy / 2 ) + m_Size.cy / 2 },
  475. { (INT)( cos((m_North - 2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
  476. (INT)(-sin((m_North - 2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 } };
  477. POINT pS[4] = { { (INT)( cos((m_North + 180)*_PI_/180.0) * 1.0 * m_Size.cx / 2 ) + m_Size.cx / 2,
  478. (INT)(-sin((m_North + 180)*_PI_/180.0) * 1.0 * m_Size.cy / 2 ) + m_Size.cy / 2 },
  479. { (INT)( cos(((m_North + 180)+2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
  480. (INT)(-sin(((m_North + 180)+2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 },
  481. { (INT)( cos((m_North + 180)*_PI_/180.0) * 0.93 * m_Size.cx / 2 ) + m_Size.cx / 2,
  482. (INT)(-sin((m_North + 180)*_PI_/180.0) * 0.93 * m_Size.cy / 2 ) + m_Size.cy / 2 },
  483. { (INT)( cos(((m_North + 180)-2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
  484. (INT)(-sin(((m_North + 180)-2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 } };
  485. RECT rN = { pN[2].x - 10, pN[2].y - 10, pN[2].x + 10, pN[2].y + 10 };
  486. RECT rS = { pS[2].x - 10, pS[2].y - 10, pS[2].x + 10, pS[2].y + 10 };
  487. for(int i = 0; i < 3; i++)
  488. {
  489. if(m_hBitmapScales[i] != NULL)
  490. {
  491. HBITMAP hOldBmp = (HBITMAP)::SelectObject(m_hMemDC1, m_hBitmapScales[i]);
  492. HPEN hPen = ::CreatePen(PS_SOLID, 1, RGB(0xFF, 0xFF, 0xFF));
  493. HPEN hOldPen = (HPEN)::SelectObject(m_hMemDC1, hPen);
  494. ::SetBkMode(m_hMemDC1, TRANSPARENT);
  495. HBRUSH hBrush = ::CreateSolidBrush(RGB(0x00, 0x00, 0xFF));
  496. HBRUSH hOldBrush = (HBRUSH)::SelectObject(m_hMemDC1, hBrush);
  497. ::Polygon(m_hMemDC1, pN, 4);
  498. ::SelectObject(m_hMemDC1, hOldBrush);
  499. ::DeleteObject(hBrush );
  500. hBrush = ::CreateSolidBrush(RGB( 0xFF, 0x00, 0x00));
  501. hOldBrush = (HBRUSH)::SelectObject(m_hMemDC1, hBrush);
  502. ::Polygon(m_hMemDC1, pS, 4);
  503. ::SelectObject(m_hMemDC1, hOldBrush );
  504. ::DeleteObject(hBrush );
  505. ::SetBkMode(m_hMemDC1, OPAQUE);
  506. ::MoveToEx(m_hMemDC1, pN[2].x, pN[2].y, NULL);
  507. ::LineTo(m_hMemDC1, pS[2].x, pS[2].y);
  508. ::SelectObject(m_hMemDC1, hOldPen);
  509. ::DeleteObject(hPen);
  510. ::SelectObject(m_hMemDC1, hOldBmp);
  511. }
  512. }
  513. }
  514. }
  515. void CLocator::SetEditorMode(bool fEditor)
  516. {
  517. m_bEditorMode = fEditor;
  518. if(!fEditor)
  519. {
  520. Reset();
  521. if(m_pCurPolygon)
  522. {
  523. delete m_pCurPolygon;
  524. m_pCurPolygon = NULL;
  525. }
  526. ::SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hCursorNormal);
  527. ::ReleaseCapture();
  528. m_OldEditPoint.x = m_OldEditPoint.y = -1;
  529. }
  530. else
  531. {
  532. m_bChanged = false;
  533. Reset();
  534. }
  535. }
  536. LRESULT CLocator::OnRButtonDown(POINT pt)
  537. {
  538. if(m_bEditorMode)
  539. {
  540. POINT sp = { (long)(pt.x * m_Range * m_Scale / (m_Size.cx >> 1) ),
  541. (long)(pt.y * m_Range * m_Scale / (m_Size.cy >> 1) ) };
  542. if(m_pPolygons->Delete(sp))
  543. m_bChanged = m_Type == 0 ? true : m_bChanged;
  544. Reset();
  545. if(m_pCurPolygon)
  546. {
  547. delete m_pCurPolygon;
  548. m_pCurPolygon = NULL;
  549. }
  550. m_OldEditPoint.x = m_OldEditPoint.y = -1;
  551. }
  552. return 0UL;
  553. }
  554. LRESULT CLocator::OnLButtonDown(POINT pt)
  555. {
  556. if(m_bEditorMode)
  557. {
  558. HDC hDC = ::GetDC(m_hWnd);
  559. if(!m_pCurPolygon)
  560. m_pCurPolygon = new CPolygon(m_Type); /***/
  561. POINT sp = { (long)(pt.x * m_Range * m_Scale / (m_Size.cx >> 1) ),
  562. (long)(pt.y * m_Range * m_Scale / (m_Size.cy >> 1) ) };
  563. if(m_pCurPolygon->AddPoint(&sp, 5 * m_Range * m_Scale / ( m_Size.cy >> 1)))
  564. {
  565. if(m_pCurPolygon->GetCount() > 2)
  566. {
  567. m_pPolygons->AddPolygon(m_pCurPolygon);
  568. m_bChanged = m_Type == 0 ? true : m_bChanged;
  569. }
  570. else
  571. delete m_pCurPolygon;
  572. Reset();
  573. m_pCurPolygon = NULL;
  574. m_OldEditPoint.x = m_OldEditPoint.y = -1;
  575. ::ReleaseDC(m_hWnd, hDC);
  576. return true;
  577. }
  578. pt.x += m_Size.cx >> 1;
  579. pt.y += m_Size.cy >> 1;
  580. if(m_OldEditPoint.x != -1)
  581. {
  582. ::MoveToEx(hDC, m_OldEditPoint.x, m_OldEditPoint.y, NULL);
  583. ::LineTo(hDC, pt.x, pt.y);
  584. }
  585. ::Ellipse(hDC, pt.x - 2, pt.y - 2, pt.x + 2, pt.y + 2);
  586. m_OldEditPoint = pt;
  587. ::ReleaseDC(m_hWnd, hDC);
  588. }
  589. return 0UL;
  590. }
  591. LRESULT CLocator::OnMouseMove( POINT & pt )
  592. {
  593. if(m_bEditorMode)
  594. {
  595. HDC hDC = ::GetDC( m_hWnd );
  596. RECT rect = { m_Size.cx - 78, 0, m_Size.cx, 20 };
  597. ::FillRect(hDC, &rect, (HBRUSH)::GetStockObject(BLACK_BRUSH));
  598. ::SetTextColor(hDC, 0x00FFFFFF);
  599. ::SetBkMode(hDC, TRANSPARENT);
  600. double r = sqrt(pt.x * pt.x + pt.y * pt.y);
  601. // if(r <= ((m_Size.cx >> 1) + 1))
  602. const c = 10;
  603. if( pt.x >= -m_Size.cx / 2 - c && pt.x <= m_Size.cx / 2 + c &&
  604. pt.y >= -m_Size.cy / 2 - c && pt.y <= m_Size.cy / 2 + c )
  605. {
  606. ::SetCapture(m_hWnd);
  607. ::SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hCursorEdit);
  608. ::SetCursor(m_hCursorEdit);
  609. pt.x = (INT)(atan2((double)-pt.y , (double)pt.x) * 180.0 / _PI_);
  610. if(pt.x < 0 )
  611. pt.x += 360;
  612. CHAR pText[0x500];
  613. INT nCount = sprintf(pText, "%3d�%3dm", pt.x, (INT)(r * m_Scale * m_Range / ( m_Size.cx >> 1)));
  614. HFONT hFontOld = (HFONT)::SelectObject(hDC, m_hFont);
  615. ::TextOut(hDC, m_Size.cx - 78, 0, pText, nCount);
  616. ::SelectObject( hDC, hFontOld );
  617. }
  618. else
  619. {
  620. ::ReleaseCapture();
  621. ::SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hCursorNormal);
  622. ::SetCursor(m_hCursorNormal);
  623. }
  624. ::ReleaseDC( m_hWnd, hDC );
  625. }
  626. return 0UL;
  627. }