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
826 lines
22 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 09/04/2000
|
|
// Last modification: 30/10/2002
|
|
// Project Intruder Position Indicator
|
|
// SUBSYSTEM: Locator
|
|
// FILE: Locator.cpp
|
|
// AUTHOR: Chizhevskiy Sergey
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of implementation of class CLocator
|
|
//----------------------------------------------------------------------------
|
|
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
#include "..\LgLib\LgImageDIB.h"
|
|
|
|
#include "Locator.h"
|
|
|
|
#define _PI_ 3.1415926535897932384626433832795
|
|
|
|
CLocator::CLocator()
|
|
{
|
|
ZeroMemory(this, sizeof(*this));
|
|
|
|
m_OldEditPoint.x = m_OldEditPoint.y = -1;
|
|
m_Scale = 0.5859375;//?1.0;
|
|
m_pProfile = FALSE;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLocator::CLocator" );
|
|
}
|
|
|
|
CLocator::~CLocator()
|
|
{
|
|
if(m_hFont)
|
|
::DeleteObject(m_hFont);
|
|
|
|
if(m_pCurPolygon)
|
|
{
|
|
delete m_pCurPolygon;
|
|
|
|
m_pCurPolygon = NULL;
|
|
}
|
|
|
|
if(m_hBitmap)
|
|
{
|
|
::DestroyWindow(m_hWnd);
|
|
|
|
::SelectObject(m_hMemDC2, m_hBitmapScalesOld);
|
|
|
|
::DeleteObject(m_hBitmapScales[0]);
|
|
::DeleteObject(m_hBitmapScales[1]);
|
|
::DeleteObject(m_hBitmapScales[2]);
|
|
::DeleteObject(m_hBitmap);
|
|
|
|
::DeleteDC(m_hMemDC2);
|
|
::DeleteDC(m_hMemDC1);
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLocator::~CLocator" );
|
|
}
|
|
|
|
LRESULT CLocator::WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
POINT pt;
|
|
HDC hDC;
|
|
PAINTSTRUCT ps;
|
|
LRESULT bResult;
|
|
RECT rect;
|
|
SIZE size;
|
|
|
|
switch(Msg)
|
|
{
|
|
case WM_CREATE:
|
|
return OnWmCreate( hWnd, (LPCREATESTRUCT)lParam );
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
::GetClientRect( hWnd, &rect );
|
|
pt.x = (SHORT)(LOWORD(lParam)) - ((rect.right-rect.left) >> 1);
|
|
pt.y = (SHORT)(HIWORD(lParam)) - ((rect.bottom-rect.top) >> 1);
|
|
|
|
// if(sqrt(pt.x * pt.x + pt.y * pt.y) <= ((rect.right-rect.left) >> 1))
|
|
OnLButtonDown(pt);
|
|
return 0L;
|
|
|
|
case WM_RBUTTONDOWN:
|
|
::GetClientRect( hWnd, &rect );
|
|
pt.x = (SHORT)(LOWORD(lParam)) - ((rect.right-rect.left) >> 1);
|
|
pt.y = (SHORT)(HIWORD(lParam)) - ((rect.bottom-rect.top) >> 1);
|
|
|
|
OnRButtonDown(pt);
|
|
return 0L;
|
|
|
|
case WM_MOUSEMOVE:
|
|
::GetClientRect( hWnd, &rect );
|
|
pt.x = (SHORT)(LOWORD(lParam)) - ((rect.right-rect.left) >> 1);
|
|
pt.y = (SHORT)(HIWORD(lParam)) - ((rect.bottom-rect.top) >> 1);
|
|
|
|
OnMouseMove(pt);
|
|
return 0L;
|
|
|
|
case WM_PAINT:
|
|
hDC = ::BeginPaint( hWnd, &ps );
|
|
bResult = OnWmPaint( hWnd, hDC );
|
|
::EndPaint( hWnd, &ps );
|
|
return bResult;
|
|
|
|
case WM_SIZE:
|
|
size.cx = (SHORT)(LOWORD(lParam));
|
|
size.cy = (SHORT)(HIWORD(lParam));
|
|
return OnWmSize( hWnd, wParam, &size );
|
|
}
|
|
|
|
return ::DefWindowProc(hWnd, Msg, wParam, lParam);
|
|
}
|
|
|
|
LRESULT CLocator::OnWmCreate( HWND hWnd, LPCREATESTRUCT pCreateStruct )
|
|
{
|
|
return 0UL;
|
|
}
|
|
|
|
LRESULT CLocator::OnWmPaint( HWND, HDC hDC )
|
|
{
|
|
if( !m_hBitmap )
|
|
return 1UL;
|
|
|
|
// get bitmap dimensions
|
|
DIBSECTION DibSection;
|
|
if( !::GetObject( m_hBitmap, sizeof(DibSection), &DibSection ) )
|
|
return 1UL;
|
|
|
|
// draw bitmap onto screen
|
|
HBITMAP hOldBitmap = (HBITMAP)::SelectObject( m_hMemDC1, m_hBitmap );
|
|
::StretchBlt( hDC, 0, 0, m_Size.cx, m_Size.cy, m_hMemDC1, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmWidth, SRCCOPY );
|
|
::SelectObject( m_hMemDC1, hOldBitmap );
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
LRESULT CLocator::OnWmSize( HWND hWnd, WPARAM, LPSIZE pSize )
|
|
{
|
|
// delete old bitmap
|
|
if( m_hBitmap )
|
|
{
|
|
::DeleteObject( m_hBitmap );
|
|
m_hBitmap = NULL;
|
|
}
|
|
|
|
// allocate new bitmap
|
|
HDC hDC = GetDC( hWnd );
|
|
if( hDC )
|
|
{
|
|
m_hBitmap = ::CreateCompatibleBitmap( hDC, pSize->cx, pSize->cy );
|
|
::ReleaseDC( hWnd, hDC );
|
|
}
|
|
|
|
// clear bitmap
|
|
if( m_hBitmap )
|
|
{
|
|
HBITMAP hOldBmp = (HBITMAP)::SelectObject( m_hMemDC1, m_hBitmap );
|
|
RECT rect = { 0, 0, pSize->cx, pSize->cy };
|
|
::FillRect( m_hMemDC1, &rect, (HBRUSH)::GetStockObject(BLACK_BRUSH) );
|
|
::SelectObject( m_hMemDC1, hOldBmp );
|
|
}
|
|
|
|
// remember size
|
|
m_Size = *pSize;
|
|
|
|
// move static window
|
|
::MoveWindow( m_hIconWnd, m_Size.cx - 32, m_Size.cy - 32, m_Size.cx, m_Size.cy, TRUE );
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
LRESULT CALLBACK CLocator::WndProc_(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
CLocator* pLocator = (CLocator*)::GetWindowLong( hWnd, GWL_USERDATA );
|
|
|
|
if( pLocator )
|
|
return pLocator->WndProc( hWnd, Msg, wParam, lParam );
|
|
|
|
if( Msg == WM_CREATE )
|
|
{
|
|
CLocator *pLocator = (CLocator*)((LPCREATESTRUCT)lParam)->lpCreateParams;
|
|
if( pLocator )
|
|
{
|
|
::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pLocator );
|
|
return pLocator->WndProc( hWnd, Msg, wParam, lParam );
|
|
}
|
|
}
|
|
|
|
return ::DefWindowProc( hWnd, Msg, wParam, lParam );
|
|
}
|
|
|
|
bool CLocator::Create( HWND hWnd, CProfile* pProfile, CPolygons* pPolygons, LPPOINT pPoint, LPSIZE pSize )
|
|
{
|
|
static const POINT p = { 0, 0 };
|
|
static const SIZE s = {300, 300 };//{ 513, 513 };
|
|
|
|
LOGFONT lf = {0};
|
|
// RECT rect = { 0, 0, m_Size.cx, m_Size.cy };
|
|
|
|
if(!pPoint)
|
|
pPoint = (LPPOINT)&p;
|
|
|
|
if(!pSize)
|
|
pSize = (LPSIZE)&s;
|
|
|
|
m_pPolygons = pPolygons;
|
|
m_pProfile = pProfile;
|
|
|
|
WNDCLASS wc;
|
|
wc.cbClsExtra = 0;
|
|
wc.cbWndExtra = 0;
|
|
wc.hbrBackground = NULL;
|
|
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
|
|
wc.hIcon = NULL;
|
|
wc.hInstance = (HINSTANCE)::GetWindowLong(hWnd, GWL_HINSTANCE);
|
|
wc.lpfnWndProc = WndProc_;
|
|
wc.lpszClassName = "LocatorWndClass";
|
|
wc.lpszMenuName = NULL;
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
if( !::RegisterClass( &wc ) )
|
|
return FALSE;
|
|
|
|
m_hWnd = ::CreateWindow( wc.lpszClassName, NULL, WS_CHILD | SS_BITMAP | SS_NOTIFY, pPoint->x, pPoint->y,
|
|
pSize->cx, pSize->cy, hWnd, NULL, wc.hInstance, this );
|
|
|
|
// create notification icon wnd
|
|
m_hIconWnd = ::CreateWindowEx( WS_EX_CLIENTEDGE, "STATIC", NULL, SS_ICON | WS_CHILD | WS_VISIBLE, 0, 0, 32, 32, m_hWnd, NULL, wc.hInstance, 0 );
|
|
::MoveWindow( m_hIconWnd, m_Size.cx - 40, m_Size.cy - 40, m_Size.cx, m_Size.cy, TRUE );
|
|
|
|
m_hCursorNormal = (HCURSOR)::GetClassLong(m_hWnd, GCL_HCURSOR);
|
|
m_hCursorEdit = (HCURSOR)::LoadCursor(NULL, IDC_CROSS);
|
|
|
|
// m_Size = *pSize;
|
|
|
|
m_Range = pProfile->LgsRange();
|
|
m_North = pProfile->LgsNorth();
|
|
|
|
HDC hDC = ::GetDC(m_hWnd);
|
|
|
|
m_hMemDC1 = ::CreateCompatibleDC(hDC);
|
|
m_hMemDC2 = ::CreateCompatibleDC(hDC);
|
|
// m_hBitmap = ::CreateCompatibleBitmap(hDC, m_Size.cx, m_Size.cy);
|
|
|
|
::ReleaseDC(m_hWnd, hDC);
|
|
|
|
LoadBitmaps(pProfile);
|
|
|
|
DrawNorth();
|
|
|
|
ZeroMemory(&lf, sizeof(lf));
|
|
|
|
lf.lfHeight = 14;
|
|
lf.lfCharSet = ANSI_CHARSET;
|
|
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
|
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
|
lf.lfQuality = DEFAULT_QUALITY;
|
|
lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
|
|
_tcscpy(lf.lfFaceName, _T("Courier"));
|
|
|
|
m_hFont = ::CreateFontIndirect(&lf);
|
|
|
|
::SendMessage(m_hWnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)m_hBitmap);
|
|
|
|
SetScale(2);
|
|
|
|
return true;
|
|
}
|
|
|
|
void CLocator::AddTarget(const TARGET_DESCRIPTION& td)
|
|
{
|
|
const float RTOD = 0.01745329252F;
|
|
|
|
if(td.range <= m_Range * m_Scale)
|
|
{
|
|
HBITMAP hOldBmp = (HBITMAP)::SelectObject(m_hMemDC1, m_hBitmap);
|
|
|
|
COLORREF color;
|
|
|
|
switch(td.master)
|
|
{
|
|
case 'b':
|
|
color = m_bDebugMode ? 0x00FFFFFF : 0x0000FFFF;
|
|
break;
|
|
|
|
case 'a':
|
|
color = 0x0000FFFF;
|
|
break;
|
|
|
|
case 'f':
|
|
color = 0x00FF0000;
|
|
break;
|
|
|
|
case 'w':
|
|
// color = 0x000000FF;
|
|
color = m_bDebugMode ? 0x000000FF : 0x0000FFFF;
|
|
break;
|
|
}
|
|
|
|
HPEN hPen = ::CreatePen(PS_SOLID, 1, color);
|
|
HPEN hOldPen = (HPEN)::SelectObject(m_hMemDC1, hPen);
|
|
|
|
HBRUSH hBrush = ::CreateSolidBrush(color);
|
|
HBRUSH hOldBrush = (HBRUSH)::SelectObject(m_hMemDC1, hBrush);
|
|
// 24/05/2001
|
|
int x = (INT)( cos(td.angle * RTOD) * td.range * (m_Size.cx >> 1) / (m_Scale * m_Range)) + (m_Size.cx >> 1);
|
|
int y = (INT)(-sin(td.angle * RTOD) * td.range * (m_Size.cy >> 1) / (m_Scale * m_Range)) + (m_Size.cy >> 1);
|
|
|
|
::Ellipse(m_hMemDC1, x - (m_Size.cx >> 7), y - (m_Size.cy >> 7),
|
|
x + (m_Size.cx >> 7), y + (m_Size.cy >> 7) );// change from 3 to 2
|
|
|
|
::SelectObject(m_hMemDC1, hOldPen);
|
|
::SelectObject(m_hMemDC1, hOldBrush);
|
|
::DeleteObject(hPen);
|
|
::DeleteObject(hBrush);
|
|
|
|
::SelectObject(m_hMemDC1, hOldBmp);
|
|
|
|
RECT rect = { x - 4, y - 4, x + 4, y + 4 };
|
|
|
|
::InvalidateRect( m_hWnd, &rect, FALSE );
|
|
::UpdateWindow( m_hWnd );
|
|
} // end of if(td.range <= m_Range * m_Scale)
|
|
}
|
|
|
|
void CLocator::DrawProgress( LPCTSTR pText, INT nSize )
|
|
{
|
|
HDC hDC = ::GetDC( m_hWnd );
|
|
|
|
RECT rect = { 0, m_Size.cy - 20, 90, m_Size.cy };
|
|
|
|
::SetTextColor( hDC, 0x00FFFFFF );
|
|
::SetBkColor( hDC, 0 );
|
|
|
|
HFONT hFontOld = (HFONT)::SelectObject( hDC, m_hFont );
|
|
|
|
::TextOut( hDC, rect.left, rect.top, pText, nSize );
|
|
|
|
::SelectObject( hDC, hFontOld );
|
|
|
|
::ReleaseDC( m_hWnd, hDC );
|
|
}
|
|
|
|
void CLocator::Reset()
|
|
{
|
|
POINT p = { m_Size.cx >> 1, m_Size.cy >> 1 };
|
|
|
|
HBITMAP hOldBmp = (HBITMAP)::SelectObject(m_hMemDC1, m_hBitmap);
|
|
|
|
// get bitmap dimensions
|
|
DIBSECTION DibSection;
|
|
::GetObject( m_hBitmapScales[0], sizeof(DibSection), &DibSection );
|
|
|
|
// draw bitmap onto screen
|
|
::StretchBlt( m_hMemDC1, 0, 0, m_Size.cx, m_Size.cy, m_hMemDC2, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmWidth, SRCCOPY );
|
|
// ::BitBlt(m_hMemDC1, 0, 0, m_Size.cx, m_Size.cy, m_hMemDC2, 0, 0, SRCCOPY);
|
|
|
|
HRGN hRgn = ::CreateEllipticRgn(0, 0, m_Size.cx, m_Size.cy);
|
|
|
|
::SelectClipRgn(m_hMemDC1, hRgn);
|
|
::DeleteObject(hRgn); // It can be deleted
|
|
|
|
m_pPolygons->Draw( m_hMemDC1, p, (m_Size.cx >> 1) / (m_Range * m_Scale) );
|
|
|
|
if(m_bEditorMode)
|
|
m_pPolygons->ProduceHiddenZones(m_hMemDC1, p, m_Range, (m_Size.cx >> 1) / (m_Range * m_Scale));
|
|
|
|
::SelectClipRgn(m_hMemDC1, NULL);
|
|
|
|
::SelectObject(m_hMemDC1, hOldBmp);
|
|
|
|
RECT rect = { 0, 0, m_Size.cx, m_Size.cy };
|
|
|
|
::InvalidateRect(m_hWnd, &rect, FALSE);
|
|
::UpdateWindow(m_hWnd);
|
|
}
|
|
|
|
bool CLocator::StoreImage( LPCTSTR pPathName )
|
|
{
|
|
CLgImageDIB dib;
|
|
if( dib.Create( m_hBitmap ) )
|
|
{
|
|
dib.Save( pPathName );
|
|
}
|
|
|
|
return true;
|
|
/*
|
|
HANDLE hFile = ::CreateFile( pPathName, GENERIC_WRITE,
|
|
FILE_SHARE_READ, NULL, OPEN_ALWAYS,
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
BITMAPFILEHEADER bfh;
|
|
BITMAPINFO bmi;
|
|
DWORD dwWrite;
|
|
|
|
ZeroMemory(&bmi, sizeof(bmi));
|
|
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
::GetDIBits(m_hMemDC1, m_hBitmap, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
|
|
|
|
bmi.bmiHeader.biCompression = 0;
|
|
bmi.bmiHeader.biBitCount = 16;
|
|
bmi.bmiHeader.biSizeImage = WIDTHBYTES( bmi.bmiHeader.biWidth * bmi.bmiHeader.biBitCount ) * bmi.bmiHeader.biHeight;
|
|
|
|
LPBYTE pByte = new BYTE[bmi.bmiHeader.biSizeImage];
|
|
::GetDIBits( m_hMemDC1, m_hBitmap, 0, bmi.bmiHeader.biHeight, pByte, &bmi, DIB_RGB_COLORS);
|
|
|
|
bfh.bfType = (((WORD)'M') << 8) + 'B';
|
|
bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmi.bmiHeader.biSizeImage;
|
|
bfh.bfReserved1 = 0;
|
|
bfh.bfReserved2 = 0;
|
|
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
|
|
|
::WriteFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwWrite, NULL);
|
|
::WriteFile(hFile, &bmi, sizeof(BITMAPINFOHEADER), &dwWrite, NULL);
|
|
::WriteFile(hFile, pByte, bmi.bmiHeader.biSizeImage, &dwWrite, NULL);
|
|
|
|
delete[] pByte; // Added delete[] 12/03/2001
|
|
|
|
::CloseHandle(hFile);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
*/
|
|
}
|
|
|
|
void CLocator::LoadBitmaps(CProfile *pProfile)
|
|
{
|
|
if(m_hBitmapScalesOld)
|
|
::SelectObject(m_hMemDC2, m_hBitmapScalesOld);
|
|
|
|
for(int i = 0; i < 3; i++)
|
|
{
|
|
if(m_hBitmapScales[i])
|
|
{
|
|
::DeleteObject(m_hBitmapScales[i]);
|
|
m_hBitmapScales[i] = NULL;
|
|
}
|
|
}
|
|
|
|
m_hBitmapScales[0] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
|
|
pProfile->SettingsScreen020(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
|
|
// If no exist bitmap load from resource 13/03/2001
|
|
if(m_hBitmapScales[0] == NULL)
|
|
m_hBitmapScales[0] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
|
|
MAKEINTRESOURCE(IDB_BITMAP_SCREEN), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
|
|
m_hBitmapScales[1] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
|
|
pProfile->SettingsScreen050(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_DEFAULTSIZE);
|
|
// If no exist bitmap load from resource 13/03/2001
|
|
if(m_hBitmapScales[1] == NULL)
|
|
m_hBitmapScales[1] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
|
|
MAKEINTRESOURCE(IDB_BITMAP_SCREEN), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
|
|
m_hBitmapScales[2] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
|
|
pProfile->SettingsScreen100(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
|
|
// If no exist bitmap load from resource 13/03/2001
|
|
if(m_hBitmapScales[2] == NULL)
|
|
m_hBitmapScales[2] = (HBITMAP)::LoadImage((HINSTANCE)::GetWindowLong(m_hWnd, GWL_HINSTANCE),
|
|
MAKEINTRESOURCE(IDB_BITMAP_SCREEN), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
|
|
|
|
// draw fixed video regions
|
|
double scale[] = { 0.2, 0.5, 1.0 };
|
|
for( i = 0; i < 3; i++ )
|
|
{
|
|
DIBSECTION DibSection;
|
|
::GetObject( m_hBitmapScales[i], sizeof(DibSection), &DibSection );
|
|
|
|
RECT rect = { 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmHeight };
|
|
|
|
HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC2, m_hBitmapScales[i] );
|
|
|
|
DrawFixedVideo( m_hMemDC2, rect, 1.0 / scale[i] );
|
|
|
|
(HBITMAP)::SelectObject( m_hMemDC2, hBitmap );
|
|
}
|
|
|
|
m_hBitmapScalesOld = (HBITMAP)::SelectObject(m_hMemDC2, m_hBitmapScales[0]);
|
|
}
|
|
|
|
void CLocator::DrawFixedVideo( HDC hDC, RECT& rect, double scale )
|
|
{
|
|
// fixed video enabled
|
|
if( !m_pProfile->FixedVideoEnable() ||
|
|
!m_pProfile->GetFixedVideoRegionArray().GetCount() )
|
|
return;
|
|
|
|
SIZE size = { rect.right - rect.left, rect.bottom - rect.top };
|
|
|
|
// create refference bitmap & DC
|
|
HDC hSrcDC = ::CreateCompatibleDC( hDC );
|
|
HBITMAP hSrcBmp = ::CreateCompatibleBitmap( hDC, size.cx, size.cy );
|
|
HBITMAP hBitmap = (HBITMAP) ::SelectObject( hSrcDC, hSrcBmp );
|
|
|
|
// initialize pen and brush
|
|
HPEN hPen = ::CreatePen( PS_SOLID, 1, RGB(255,0,0) );
|
|
HPEN hPenOld = (HPEN)::SelectObject( hSrcDC, hPen );
|
|
HBRUSH hBrush = ::CreateSolidBrush( RGB(255,100,100) );
|
|
HBRUSH hBrushOld = (HBRUSH)::SelectObject( hSrcDC, hBrush );
|
|
|
|
// prepare pointer to new region
|
|
HRGN hRgn = NULL;
|
|
|
|
// draw regions
|
|
CLocatorRegionArray& array = m_pProfile->GetFixedVideoRegionArray();
|
|
for( INT i = 0; i < array.GetCount(); i++ )
|
|
{
|
|
CLocatorRegion& region = array[i];
|
|
|
|
// allocate points for region points
|
|
LPPOINT pPoint = new POINT[ region.GetCount() ];
|
|
if( !pPoint )
|
|
continue;
|
|
|
|
// convert region points to dc points
|
|
for( INT i = 0; i < region.GetCount(); i++ )
|
|
{
|
|
CLgDPoint& dp = region[i];
|
|
|
|
pPoint[i].x = size.cx * ( 1.0 + scale * dp.x ) / 2.0;
|
|
pPoint[i].y = size.cy * ( 1.0 + scale * dp.y ) / 2.0;
|
|
}
|
|
|
|
// draw region
|
|
::Polygon( hSrcDC, pPoint, region.GetCount() );
|
|
|
|
// accumulate region
|
|
if( !hRgn )
|
|
hRgn = ::CreatePolygonRgn( pPoint, region.GetCount(), WINDING );
|
|
else
|
|
{
|
|
HRGN hTempRgn = ::CreatePolygonRgn( pPoint, region.GetCount(), WINDING );
|
|
::CombineRgn( hRgn, hRgn, hTempRgn, RGN_OR );
|
|
::DeleteObject( hTempRgn );
|
|
}
|
|
|
|
// delete array
|
|
delete pPoint;
|
|
}
|
|
|
|
// clip regions with circle
|
|
HRGN hTempRgn = ::CreateEllipticRgn( rect.left, rect.top, rect.right, rect.bottom );
|
|
::CombineRgn( hRgn, hRgn, hTempRgn, RGN_AND );
|
|
::DeleteObject( hTempRgn );
|
|
|
|
// store old clipping region
|
|
HRGN hRgnOld = ::CreateRectRgn(0,0,1,1);
|
|
INT nRgnOld = ::GetClipRgn( hDC, hRgnOld );
|
|
|
|
// set new clip region
|
|
::SelectClipRgn( hDC, hRgn );
|
|
|
|
// copy image to distanation
|
|
BLENDFUNCTION bf;
|
|
bf.BlendOp = AC_SRC_OVER;
|
|
bf.BlendFlags = 0;
|
|
bf.AlphaFormat = 0;
|
|
bf.SourceConstantAlpha = 100;
|
|
::AlphaBlend( hDC, 0, 0, size.cx, size.cy, hSrcDC, 0, 0, size.cx, size.cy, bf );
|
|
|
|
// restore old clip region
|
|
switch( nRgnOld )
|
|
{
|
|
case 0: ::SelectClipRgn( hDC, NULL ); break;
|
|
case 1: ::SelectClipRgn( hDC, hRgnOld ); break;
|
|
}
|
|
|
|
// delete created regions
|
|
::DeleteObject( hRgn );
|
|
::DeleteObject( hRgnOld );
|
|
|
|
// return old pen and brush parameters
|
|
::SelectObject( hSrcDC, hPenOld );
|
|
::SelectObject( hSrcDC, hBrushOld );
|
|
|
|
// delete refference bitmap & DC
|
|
::SelectObject( hSrcDC, hBitmap );
|
|
::DeleteObject( hSrcDC );
|
|
::DeleteDC( hSrcDC );
|
|
}
|
|
|
|
void CLocator::SetScale(INT nScale)
|
|
{
|
|
switch(nScale)
|
|
{
|
|
case 0:
|
|
m_Scale = 0.20;
|
|
break;
|
|
|
|
case 1:
|
|
m_Scale = 0.50;
|
|
break;
|
|
|
|
case 2:
|
|
m_Scale = 1.00;
|
|
}
|
|
|
|
::SelectObject(m_hMemDC2, m_hBitmapScales[nScale]);
|
|
|
|
Reset();
|
|
}
|
|
|
|
void CLocator::DrawNorth()
|
|
{
|
|
if(m_North != -1)
|
|
{
|
|
POINT pN[4] = { { (INT)( cos(m_North * _PI_/180.0) * 1.0 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin(m_North * _PI_/180.0) * 1.0 * m_Size.cy / 2 ) + m_Size.cy / 2 },
|
|
{ (INT)( cos((m_North + 2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin((m_North + 2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 },
|
|
{ (INT)( cos(m_North * _PI_/180.0) * 0.93 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin(m_North * _PI_/180.0) * 0.93 * m_Size.cy / 2 ) + m_Size.cy / 2 },
|
|
{ (INT)( cos((m_North - 2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin((m_North - 2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 } };
|
|
|
|
POINT pS[4] = { { (INT)( cos((m_North + 180)*_PI_/180.0) * 1.0 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin((m_North + 180)*_PI_/180.0) * 1.0 * m_Size.cy / 2 ) + m_Size.cy / 2 },
|
|
{ (INT)( cos(((m_North + 180)+2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin(((m_North + 180)+2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 },
|
|
{ (INT)( cos((m_North + 180)*_PI_/180.0) * 0.93 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin((m_North + 180)*_PI_/180.0) * 0.93 * m_Size.cy / 2 ) + m_Size.cy / 2 },
|
|
{ (INT)( cos(((m_North + 180)-2)*_PI_/180.0) * 0.9 * m_Size.cx / 2 ) + m_Size.cx / 2,
|
|
(INT)(-sin(((m_North + 180)-2)*_PI_/180.0) * 0.9 * m_Size.cy / 2 ) + m_Size.cy / 2 } };
|
|
|
|
RECT rN = { pN[2].x - 10, pN[2].y - 10, pN[2].x + 10, pN[2].y + 10 };
|
|
RECT rS = { pS[2].x - 10, pS[2].y - 10, pS[2].x + 10, pS[2].y + 10 };
|
|
|
|
for(int i = 0; i < 3; i++)
|
|
{
|
|
if(m_hBitmapScales[i] != NULL)
|
|
{
|
|
HBITMAP hOldBmp = (HBITMAP)::SelectObject(m_hMemDC1, m_hBitmapScales[i]);
|
|
|
|
HPEN hPen = ::CreatePen(PS_SOLID, 1, RGB(0xFF, 0xFF, 0xFF));
|
|
HPEN hOldPen = (HPEN)::SelectObject(m_hMemDC1, hPen);
|
|
|
|
::SetBkMode(m_hMemDC1, TRANSPARENT);
|
|
|
|
HBRUSH hBrush = ::CreateSolidBrush(RGB(0x00, 0x00, 0xFF));
|
|
HBRUSH hOldBrush = (HBRUSH)::SelectObject(m_hMemDC1, hBrush);
|
|
|
|
::Polygon(m_hMemDC1, pN, 4);
|
|
::SelectObject(m_hMemDC1, hOldBrush);
|
|
::DeleteObject(hBrush );
|
|
|
|
hBrush = ::CreateSolidBrush(RGB( 0xFF, 0x00, 0x00));
|
|
hOldBrush = (HBRUSH)::SelectObject(m_hMemDC1, hBrush);
|
|
|
|
::Polygon(m_hMemDC1, pS, 4);
|
|
::SelectObject(m_hMemDC1, hOldBrush );
|
|
::DeleteObject(hBrush );
|
|
|
|
::SetBkMode(m_hMemDC1, OPAQUE);
|
|
|
|
::MoveToEx(m_hMemDC1, pN[2].x, pN[2].y, NULL);
|
|
::LineTo(m_hMemDC1, pS[2].x, pS[2].y);
|
|
|
|
::SelectObject(m_hMemDC1, hOldPen);
|
|
::DeleteObject(hPen);
|
|
|
|
::SelectObject(m_hMemDC1, hOldBmp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CLocator::SetEditorMode(bool fEditor)
|
|
{
|
|
m_bEditorMode = fEditor;
|
|
|
|
if(!fEditor)
|
|
{
|
|
Reset();
|
|
|
|
if(m_pCurPolygon)
|
|
{
|
|
delete m_pCurPolygon;
|
|
m_pCurPolygon = NULL;
|
|
}
|
|
|
|
::SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hCursorNormal);
|
|
::ReleaseCapture();
|
|
|
|
m_OldEditPoint.x = m_OldEditPoint.y = -1;
|
|
}
|
|
else
|
|
{
|
|
m_bChanged = false;
|
|
|
|
Reset();
|
|
}
|
|
}
|
|
|
|
LRESULT CLocator::OnRButtonDown(POINT pt)
|
|
{
|
|
if(m_bEditorMode)
|
|
{
|
|
POINT sp = { (long)(pt.x * m_Range * m_Scale / (m_Size.cx >> 1) ),
|
|
(long)(pt.y * m_Range * m_Scale / (m_Size.cy >> 1) ) };
|
|
|
|
if(m_pPolygons->Delete(sp))
|
|
m_bChanged = m_Type == 0 ? true : m_bChanged;
|
|
|
|
Reset();
|
|
|
|
if(m_pCurPolygon)
|
|
{
|
|
delete m_pCurPolygon;
|
|
|
|
m_pCurPolygon = NULL;
|
|
}
|
|
|
|
m_OldEditPoint.x = m_OldEditPoint.y = -1;
|
|
}
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
LRESULT CLocator::OnLButtonDown(POINT pt)
|
|
{
|
|
if(m_bEditorMode)
|
|
{
|
|
HDC hDC = ::GetDC(m_hWnd);
|
|
|
|
if(!m_pCurPolygon)
|
|
m_pCurPolygon = new CPolygon(m_Type); /***/
|
|
|
|
POINT sp = { (long)(pt.x * m_Range * m_Scale / (m_Size.cx >> 1) ),
|
|
(long)(pt.y * m_Range * m_Scale / (m_Size.cy >> 1) ) };
|
|
|
|
if(m_pCurPolygon->AddPoint(&sp, 5 * m_Range * m_Scale / ( m_Size.cy >> 1)))
|
|
{
|
|
if(m_pCurPolygon->GetCount() > 2)
|
|
{
|
|
m_pPolygons->AddPolygon(m_pCurPolygon);
|
|
|
|
m_bChanged = m_Type == 0 ? true : m_bChanged;
|
|
}
|
|
else
|
|
delete m_pCurPolygon;
|
|
|
|
Reset();
|
|
|
|
m_pCurPolygon = NULL;
|
|
m_OldEditPoint.x = m_OldEditPoint.y = -1;
|
|
|
|
::ReleaseDC(m_hWnd, hDC);
|
|
|
|
return true;
|
|
}
|
|
|
|
pt.x += m_Size.cx >> 1;
|
|
pt.y += m_Size.cy >> 1;
|
|
|
|
if(m_OldEditPoint.x != -1)
|
|
{
|
|
::MoveToEx(hDC, m_OldEditPoint.x, m_OldEditPoint.y, NULL);
|
|
::LineTo(hDC, pt.x, pt.y);
|
|
}
|
|
|
|
::Ellipse(hDC, pt.x - 2, pt.y - 2, pt.x + 2, pt.y + 2);
|
|
|
|
m_OldEditPoint = pt;
|
|
|
|
::ReleaseDC(m_hWnd, hDC);
|
|
}
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
LRESULT CLocator::OnMouseMove( POINT & pt )
|
|
{
|
|
if(m_bEditorMode)
|
|
{
|
|
HDC hDC = ::GetDC( m_hWnd );
|
|
RECT rect = { m_Size.cx - 78, 0, m_Size.cx, 20 };
|
|
|
|
::FillRect(hDC, &rect, (HBRUSH)::GetStockObject(BLACK_BRUSH));
|
|
::SetTextColor(hDC, 0x00FFFFFF);
|
|
::SetBkMode(hDC, TRANSPARENT);
|
|
|
|
double r = sqrt(pt.x * pt.x + pt.y * pt.y);
|
|
|
|
// if(r <= ((m_Size.cx >> 1) + 1))
|
|
const c = 10;
|
|
if( pt.x >= -m_Size.cx / 2 - c && pt.x <= m_Size.cx / 2 + c &&
|
|
pt.y >= -m_Size.cy / 2 - c && pt.y <= m_Size.cy / 2 + c )
|
|
{
|
|
::SetCapture(m_hWnd);
|
|
::SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hCursorEdit);
|
|
::SetCursor(m_hCursorEdit);
|
|
|
|
pt.x = (INT)(atan2((double)-pt.y , (double)pt.x) * 180.0 / _PI_);
|
|
|
|
if(pt.x < 0 )
|
|
pt.x += 360;
|
|
|
|
CHAR pText[0x500];
|
|
|
|
INT nCount = sprintf(pText, "%3d°%3dm", pt.x, (INT)(r * m_Scale * m_Range / ( m_Size.cx >> 1)));
|
|
|
|
HFONT hFontOld = (HFONT)::SelectObject(hDC, m_hFont);
|
|
|
|
::TextOut(hDC, m_Size.cx - 78, 0, pText, nCount);
|
|
|
|
::SelectObject( hDC, hFontOld );
|
|
}
|
|
else
|
|
{
|
|
::ReleaseCapture();
|
|
::SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hCursorNormal);
|
|
::SetCursor(m_hCursorNormal);
|
|
}
|
|
|
|
::ReleaseDC( m_hWnd, hDC );
|
|
}
|
|
|
|
return 0UL;
|
|
}
|