// DefectMap.cpp: implementation of the CDefectMap class.
|
//
|
//////////////////////////////////////////////////////////////////////
|
|
#include "stdafx.h"
|
#include "DefectMap.h"
|
|
//////////////////////////////////////////////////////////////////////
|
// Construction/Destruction
|
//////////////////////////////////////////////////////////////////////
|
#ifdef _DEBUG
|
#define new DEBUG_NEW
|
#undef THIS_FILE
|
static char THIS_FILE[] = __FILE__;
|
#endif
|
|
#define ID_TIMER_BLINK 9001
|
|
CDefectMap::CDefectMap()
|
{
|
m_pParentWnd = NULL;
|
m_nMapWidth = 0;
|
m_nMapHeight = 0;
|
|
m_OriginDir = OD_LeftBottom;
|
m_nUnitSize = 0;
|
|
m_bShowShot = FALSE;
|
|
m_hDrawingSurface = NULL;
|
m_RectDrawingSurface = CRect(0, 0, 0, 0);
|
memset(&m_BMIH, 0, sizeof(BITMAPINFOHEADER));
|
m_pDrawingSurfaceBits = NULL;
|
|
m_dRatio = 1.0;
|
m_RectWnd.SetRect(0, 0, 0, 0);
|
m_RectMap.SetRect(0, 0, 0, 0);
|
m_PointWindowStart.x = 0;
|
m_PointWindowStart.y = 0;
|
m_bDragMove = FALSE;
|
m_bIsMiniMap = FALSE;
|
m_PointGlassStart.x = 0;
|
m_PointGlassStart.y = 0;
|
m_PointGlassEnd.x = 0;
|
m_PointGlassEnd.y = 0;
|
m_nCoordGabX = 2;
|
m_nCoordGabY = 2;
|
|
m_nCCutSize = 20;
|
|
m_dWidthRatio = 0.;
|
m_dHeightRatio = 0.;
|
}
|
|
CDefectMap::~CDefectMap()
|
{
|
DeinitGlass();
|
}
|
|
BEGIN_MESSAGE_MAP(CDefectMap, CStatic)
|
//{{AFX_MSG_MAP(CDefectMap)
|
ON_WM_PAINT()
|
ON_WM_TIMER()
|
ON_WM_LBUTTONDBLCLK()
|
ON_WM_LBUTTONDOWN()
|
ON_WM_RBUTTONDOWN()
|
ON_WM_LBUTTONUP()
|
ON_WM_MOUSEMOVE()
|
//}}AFX_MSG_MAP
|
END_MESSAGE_MAP()
|
|
void CDefectMap::InitGlass(CWnd* pParent, int nMapWidth, int nMapHeight, int nMapMargin)
|
{
|
if (!pParent || nMapWidth <= 0 || nMapHeight <= 0)
|
return;
|
|
m_pParentWnd = pParent;
|
m_nMapWidth = nMapWidth;
|
m_nMapHeight = nMapHeight;
|
|
GetClientRect(m_RectWnd);
|
|
m_nUnitSize = m_nMapWidth / m_RectWnd.Width();
|
|
m_dWidthRatio = static_cast<double>(m_RectWnd.Width())/static_cast<double>(m_nMapWidth);
|
m_dHeightRatio = static_cast<double>(m_RectWnd.Height())/static_cast<double>(m_nMapHeight);
|
|
m_RectMap.SetRect(0, 0, m_nMapWidth, m_nMapHeight);
|
|
// Review Map ÀúÀåÀ» À§ÇÑ Áغñ
|
GetWindowRect(&m_RectDrawingSurface);
|
ScreenToClient(&m_RectDrawingSurface);
|
CDC* pDC = GetDC();
|
if(pDC != NULL)
|
{
|
// 20101019 Bugfix ´ë¹Ú..-_- ¿©±â°¡ °¡»ó¸Þ¸ð¸® ´©¼öÀÇ ÁÖ¹ü. ( ·¹½ÃÇÇ Ã¼ÀÎÁö½Ã ¸Þ¸ð¸® ´©¶ô ºÎºÐ )
|
if( m_hDrawingSurface != NULL )
|
{
|
::DeleteObject(m_hDrawingSurface);
|
m_hDrawingSurface = NULL;
|
}
|
|
m_BMIH.biSize = sizeof(BITMAPINFOHEADER);
|
m_BMIH.biBitCount = 24;
|
m_BMIH.biPlanes = 1;
|
m_BMIH.biCompression = BI_RGB;
|
m_BMIH.biWidth = m_RectDrawingSurface.Width();
|
m_BMIH.biHeight = m_RectDrawingSurface.Height();
|
m_BMIH.biSizeImage = ((((m_BMIH.biWidth * m_BMIH.biBitCount) + 31) & ~31) >> 3) * m_BMIH.biHeight;
|
m_hDrawingSurface = CreateDIBSection(pDC->GetSafeHdc(), (CONST BITMAPINFO*)&m_BMIH, DIB_RGB_COLORS
|
, (void**)&m_pDrawingSurfaceBits, NULL, 0);
|
ReleaseDC(pDC);
|
}
|
}
|
|
void CDefectMap::DeinitGlass()
|
{
|
if (m_hDrawingSurface != NULL)
|
{
|
DeleteObject(m_hDrawingSurface);
|
m_hDrawingSurface = NULL;
|
}
|
}
|
|
void CDefectMap::IncreaseRatio()
|
{
|
if (!m_bIsMiniMap)
|
{
|
m_dRatio = m_dRatio + 0.5;
|
if (m_dRatio > 4.0)
|
m_dRatio = 4.0;
|
|
// °¡¿îµ¥¸¦ ±âÁØÀ¸·Î ¿Å±ä´Ù.
|
m_PointWindowStart.x = static_cast<int>((m_RectWnd.right * m_dRatio - m_RectWnd.Width()) / 2) * -1;
|
m_PointWindowStart.y = static_cast<int>((m_RectWnd.bottom * m_dRatio - m_RectWnd.Height()) / 2) * -1;
|
|
// ¿µ¿ªÀÌ ¹þ¾î³ªÁö ¾Êµµ·Ï ¿¹¿Üó¸®.
|
if (m_PointWindowStart.x > 0)
|
m_PointWindowStart.x = 0;
|
else if (m_PointWindowStart.x < m_RectWnd.right * m_dRatio * -1 + m_RectWnd.Width())
|
m_PointWindowStart.x = static_cast<int>(m_RectWnd.right * m_dRatio) * -1 + m_RectWnd.Width();
|
if (m_PointWindowStart.y > 0)
|
m_PointWindowStart.y = 0;
|
else if (m_PointWindowStart.y < m_RectWnd.bottom * m_dRatio * -1 + m_RectWnd.Height())
|
m_PointWindowStart.y = static_cast<int>(m_RectWnd.bottom * m_dRatio) * -1 + m_RectWnd.Height();
|
|
// m_PointGlassStart = SetWindowToGlass(CPoint(0, 0));
|
// m_PointGlassEnd = SetWindowToGlass(CPoint(m_RectWnd.right, m_RectWnd.bottom));
|
|
if (m_pParentWnd)
|
m_pParentWnd->PostMessage(UM_MAP_CHANGED, 0, 0);
|
|
Invalidate();
|
}
|
}
|
|
void CDefectMap::DecreaseRatio()
|
{
|
if (!m_bIsMiniMap)
|
{
|
m_dRatio = m_dRatio - 0.5;
|
if (m_dRatio < 1)
|
m_dRatio = 1.0;
|
|
// °¡¿îµ¥¸¦ ±âÁØÀ¸·Î ¿Å±ä´Ù.
|
m_PointWindowStart.x = static_cast<int>((m_RectWnd.right * m_dRatio - m_RectWnd.Width()) / 2) * -1;
|
m_PointWindowStart.y = static_cast<int>((m_RectWnd.bottom * m_dRatio - m_RectWnd.Height()) / 2) * -1;
|
|
// ¿µ¿ªÀÌ ¹þ¾î³ªÁö ¾Êµµ·Ï ¿¹¿Üó¸®.
|
if (m_PointWindowStart.x > 0)
|
m_PointWindowStart.x = 0;
|
else if (m_PointWindowStart.x < m_RectWnd.right * m_dRatio * -1 + m_RectWnd.Width())
|
m_PointWindowStart.x = static_cast<int>(m_RectWnd.right * m_dRatio) * -1 + m_RectWnd.Width();
|
if (m_PointWindowStart.y > 0)
|
m_PointWindowStart.y = 0;
|
else if (m_PointWindowStart.y < m_RectWnd.bottom * m_dRatio * -1 + m_RectWnd.Height())
|
m_PointWindowStart.y = static_cast<int>(m_RectWnd.bottom * m_dRatio) * -1 + m_RectWnd.Height();
|
|
// m_PointGlassStart = SetWindowToGlass(CPoint(0, 0));
|
// m_PointGlassEnd = SetWindowToGlass(CPoint(m_RectWnd.right, m_RectWnd.bottom));
|
|
if (m_pParentWnd)
|
m_pParentWnd->PostMessage(UM_MAP_CHANGED, 0, 0);
|
|
Invalidate();
|
}
|
}
|
|
void CDefectMap::ResetRatio()
|
{
|
if (!m_bIsMiniMap)
|
{
|
m_dRatio = 1.0;
|
|
m_PointWindowStart.x = 0;
|
m_PointWindowStart.y = 0;
|
|
// m_PointGlassStart = SetWindowToGlass(CPoint(0, 0));
|
// m_PointGlassEnd = SetWindowToGlass(CPoint(m_RectWnd.right, m_RectWnd.bottom));
|
|
if (m_pParentWnd)
|
m_pParentWnd->PostMessage(UM_MAP_CHANGED, 0, 0);
|
|
Invalidate();
|
}
|
}
|
|
void CDefectMap::SetDisplayRect(CPoint& PointStart, CPoint& PointEnd)
|
{
|
m_PointGlassStart = PointStart;
|
m_PointGlassEnd = PointEnd;
|
}
|
|
void CDefectMap::OnPaint()
|
{
|
CPaintDC dc(this); // device context for painting
|
|
|
DrawGlass(&dc);
|
|
// º¸¿©Áֱ⠿µ¿ª »ç°¢Çü ±×¸®±â.
|
if (m_bIsMiniMap)
|
{
|
CBrush BrushDisplay;
|
CPen PenShow(PS_SOLID, 1, RGB(255,0,0));
|
CPen* pOldPen = (CPen*)dc.SelectObject(&PenShow);
|
BrushDisplay.CreateStockObject(NULL_BRUSH);
|
CBrush* pOldBrush = (CBrush*)dc.SelectObject(&BrushDisplay);
|
dc.Rectangle(CRect(m_PointGlassStart.x + m_RectMap.left, m_PointGlassStart.y + m_RectMap.top
|
, m_PointGlassEnd.x + m_RectMap.left, m_PointGlassEnd.y + m_RectMap.top));
|
dc.SelectObject(pOldPen);
|
dc.SelectObject(pOldBrush);
|
}
|
}
|
|
void CDefectMap::OnLButtonDblClk(UINT nFlags, CPoint point)
|
{
|
// TODO: Add your message handler code here and/or call default
|
MouseLBtnDblClk(point);
|
|
CStatic::OnLButtonDblClk(nFlags, point);
|
}
|
|
void CDefectMap::OnRButtonDown(UINT nFlags, CPoint point)
|
{
|
MouseRBtnDwn(point);
|
|
CStatic::OnRButtonDown(nFlags, point);
|
}
|
|
void CDefectMap::OnLButtonDown(UINT nFlags, CPoint point)
|
{
|
// TODO: Add your message handler code here and/or call default
|
m_bDragMove = TRUE;
|
m_PointDragStart = point;
|
MouseLBtnDwn(point);
|
|
CStatic::OnLButtonDown(nFlags, point);
|
}
|
|
void CDefectMap::OnLButtonUp(UINT nFlags, CPoint point)
|
{
|
// TODO: Add your message handler code here and/or call default
|
m_bDragMove = FALSE;
|
MouseLBtnUp(point);
|
|
CStatic::OnLButtonUp(nFlags, point);
|
}
|
|
void CDefectMap::OnMouseMove(UINT nFlags, CPoint point)
|
{
|
// TODO: Add your message handler code here and/or call default
|
|
MouseLBtnMove(point);
|
|
CStatic::OnMouseMove(nFlags, point);
|
}
|
|
void CDefectMap::OnTimer(UINT_PTR nIDEvent)
|
{
|
// TODO: Add your message handler code here and/or call default
|
Timer(nIDEvent);
|
|
CStatic::OnTimer(nIDEvent);
|
}
|
|
void CDefectMap::SaveMapToFile(CString strFileName)
|
{
|
FILE *pFile;
|
_wfopen_s(&pFile, strFileName, _T("wb"));
|
if(pFile == NULL)
|
return;
|
|
BITMAPFILEHEADER bmfh;
|
int nBitsOffset = sizeof(BITMAPFILEHEADER) + m_BMIH.biSize;
|
LONG lImageSize = m_BMIH.biSizeImage;
|
LONG lFileSize = nBitsOffset + lImageSize;
|
bmfh.bfType = 'B'+('M'<<8);
|
bmfh.bfOffBits = nBitsOffset;
|
bmfh.bfSize = lFileSize;
|
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
|
//Write the bitmap file header
|
UINT nWrittenFileHeaderSize = static_cast<UINT>(fwrite(&bmfh, 1, sizeof(BITMAPFILEHEADER), pFile));
|
//And then the bitmap info header
|
UINT nWrittenInfoHeaderSize = static_cast<UINT>(fwrite(&m_BMIH, 1, sizeof(BITMAPINFOHEADER), pFile));
|
//Finally, write the image data itself -- the data represents our drawing
|
UINT nWrittenDIBDataSize = static_cast<UINT>(fwrite(m_pDrawingSurfaceBits, 1, lImageSize, pFile));
|
|
fclose(pFile);
|
}
|
|
void CDefectMap::ConvertGlassToView(CRect &rect)
|
{
|
if(m_dWidthRatio <= 0 || m_dHeightRatio <= 0)
|
return;
|
|
rect.left = static_cast<int>(static_cast<double>(rect.left)*m_dWidthRatio);
|
rect.right = static_cast<int>(static_cast<double>(rect.right)*m_dWidthRatio);
|
rect.top = static_cast<int>(static_cast<double>(rect.top)*m_dHeightRatio);
|
rect.bottom = static_cast<int>(static_cast<double>(rect.bottom)*m_dHeightRatio);
|
}
|
|
void CDefectMap::ConvertGlassToView(CPoint &pt)
|
{
|
if(m_dWidthRatio <= 0 || m_dHeightRatio <= 0)
|
return;
|
|
pt.x = static_cast<int>(static_cast<double>(pt.x)*m_dWidthRatio);
|
pt.y = static_cast<int>(static_cast<double>(pt.y)*m_dHeightRatio);
|
}
|
|
CPoint CDefectMap::ConvertViewToGlass(CPoint &pt)
|
{
|
if(m_dWidthRatio <= 0 || m_dHeightRatio <= 0)
|
return pt;
|
|
pt.x = static_cast<int>(static_cast<double>(pt.x)/m_dWidthRatio);
|
pt.y = static_cast<int>(static_cast<double>(pt.y)/m_dHeightRatio);
|
|
return pt;
|
}
|
|
CRect CDefectMap::ConvertViewToGlass(CRect &rect)
|
{
|
if(m_dWidthRatio <= 0 || m_dHeightRatio <= 0)
|
return rect;
|
|
rect.left = static_cast<int>(static_cast<double>(rect.left)/m_dWidthRatio);
|
rect.right = static_cast<int>(static_cast<double>(rect.right)/m_dWidthRatio);
|
rect.top = static_cast<int>(static_cast<double>(rect.top)/m_dHeightRatio);
|
rect.bottom = static_cast<int>(static_cast<double>(rect.bottom)/m_dHeightRatio);
|
|
return rect;
|
}
|