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

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: PropertyLGSWnd.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of PropertyLGSWnd.cpp
//----------------------------------------------------------------------------
// PropertyLGSWnd.cpp : implementation file
//
#include "stdafx.h"
#include "PropertyLGSWnd.h"
#include "..\..\LgLib\Version.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPropertyLGSWnd
CPropertyLGSWnd::CPropertyLGSWnd()
{
m_bInverse = FALSE;
m_pSensor = NULL;
m_vPoint = CPoint(0,0);
m_bUseVZ = FALSE;
}
CPropertyLGSWnd::~CPropertyLGSWnd()
{
m_vRgn.DeleteObject();
}
BEGIN_MESSAGE_MAP(CPropertyLGSWnd, CWnd)
//{{AFX_MSG_MAP(CPropertyLGSWnd)
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPropertyLGSWnd message handlers
void CPropertyLGSWnd::OnPaint()
{
CPaintDC dc(this);
Draw( &dc );
}
void CPropertyLGSWnd::OnTimer(UINT nIDEvent)
{
m_bInverse = nIDEvent;
CClientDC dc(this);
Draw( &dc );
CWnd::OnTimer(nIDEvent);
}
void CPropertyLGSWnd::SetSensor(CSensorLGS *pSensor)
{
m_pSensor = pSensor;
CClientDC dc(this);
Draw( &dc );
}
void CPropertyLGSWnd::Draw(CDC *pDC)
{
if( m_pSensor && IsWindowVisible() )
{
CRect rect;
GetClientRect( &rect );
CSurfaceLGS *pSurface = m_pSensor->GetSurface();
m_MemDC.StretchBlt( rect.left, rect.top, rect.Width(), rect.Height(),
pSurface, 0, 0, pSurface->GetSize().cx, pSurface->GetSize().cy, SRCCOPY );
if( m_bUseVZ )
{
CBrush brush( HS_DIAGCROSS, RGB(0,0,0) );
m_MemDC.SetBkMode( TRANSPARENT );
m_MemDC.FillRgn( &m_vRgn, &brush );
int r = rect.Width() / 20;
int x = rect.Width() / 2 + m_vPoint.x;
int y = rect.Height() / 2 + m_vPoint.y;
m_MemDC.Arc( x - r, y - r, x + r, y + r, 0,0,0,0 );
}
pDC->BitBlt( 0, 0, rect.Width(), rect.Height(), &m_MemDC, 0, 0, SRCCOPY );
}
}
BOOL CPropertyLGSWnd::Create( CWnd *pParentWnd, int x, int y, int cx, int cy )
{
CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_CROSS ), NULL, NULL );
CRect rect( x, y, x + cx, y + cy );
if( CWnd::Create( strClassName, NULL, WS_CHILD, rect, pParentWnd, 0 ) )
{
m_MemDC.Create( cx, cy );
CRect rect;
GetClientRect( &rect );
CPoint point( rect.Width() / 2, rect.Height() / 2 );
CreateRgn( rect, point );
return TRUE;
}
return FALSE;
}
void CPropertyLGSWnd::OnLButtonDown( UINT nFlags, CPoint point )
{
CRect rect;
GetClientRect( &rect );
CreateRgn( rect, point );
CWnd::OnLButtonDown( nFlags, point );
}
void CPropertyLGSWnd::CreateRgn( CRect &rect, CPoint &point )
{
// if( m_vRgn.GetSafeHandle() )
m_vRgn.DeleteObject();
m_vPoint = point - CPoint( rect.Width() / 2, rect.Height() / 2 );
int r = rect.Width() / 20;
int x = rect.Width() / 2 + m_vPoint.x;
int y = rect.Height() / 2 + m_vPoint.y;
CRgn rgn;
rgn.CreateRectRgnIndirect( &rect );
m_vRgn.CreateEllipticRgn( x - r, y - r, x + r, y + r );
m_vRgn.CombineRgn( &rgn, &m_vRgn, RGN_DIFF );
rgn.DeleteObject();
}
void CPropertyLGSWnd::UseVisibleZone(BOOL bUse)
{
m_bUseVZ = bUse;
}
BOOL CPropertyLGSWnd::GetFilter( double &x, double &y, double &r )
{
if( m_bUseVZ )
{
CRect rect;
GetClientRect( &rect );
x = ((double)m_vPoint.x) / ( rect.Width() / 2 );
y = ((double)m_vPoint.y) / ( rect.Height() / 2 );
r = ( ((double)rect.Width()) / 20.0 ) / ( rect.Width() / 2 );
return TRUE;
}
return FALSE;
}