You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.3 KiB
C++
126 lines
3.3 KiB
C++
#include "StdAfx.h"
|
|
#include ".\recttrackerex.h"
|
|
|
|
CRectTrackerEx::CRectTrackerEx(void)
|
|
: CRectTracker()
|
|
{
|
|
//// create the hatch pattern + bitmap
|
|
//WORD hatchPattern[8];
|
|
//WORD wPattern = 0x1111;
|
|
//for (int i = 0; i < 4; i++)
|
|
//{
|
|
// hatchPattern[i] = wPattern;
|
|
// hatchPattern[i+4] = wPattern;
|
|
// wPattern <<= 1;
|
|
//}
|
|
//CBitmap bm;
|
|
//if(bm.CreateBitmap(8, 8, 1, 1, &hatchPattern))
|
|
//{
|
|
// m_hHatchBrush.CreatePatternBrush(&bm);
|
|
// bm.DeleteObject();
|
|
//}
|
|
}
|
|
|
|
CRectTrackerEx::CRectTrackerEx(LPCRECT lpSrcRect, UINT nStyle)
|
|
: CRectTracker(lpSrcRect, nStyle)
|
|
{
|
|
}
|
|
|
|
CRectTrackerEx::~CRectTrackerEx(void)
|
|
{
|
|
}
|
|
|
|
void CRectTrackerEx::Draw(CDC* pDC, COLORREF color)
|
|
{
|
|
// set initial DC state
|
|
VERIFY(pDC->SaveDC() != 0);
|
|
pDC->SetMapMode(MM_TEXT);
|
|
pDC->SetViewportOrg(0, 0);
|
|
pDC->SetWindowOrg(0, 0);
|
|
|
|
CPen m_hDottedPen;
|
|
CPen m_hSolidPen;
|
|
m_hDottedPen.CreatePen(PS_SOLID, 0, color);
|
|
m_hSolidPen.CreatePen(PS_SOLID, 0, color);
|
|
CBrush m_hHatchBrush;
|
|
m_hHatchBrush.CreateHatchBrush(HS_BDIAGONAL, color);
|
|
|
|
// get normalized rectangle
|
|
CRect rect = m_rect;
|
|
rect.NormalizeRect();
|
|
|
|
CPen* pOldPen = NULL;
|
|
CBrush* pOldBrush = NULL;
|
|
CGdiObject* pTemp;
|
|
int nOldROP;
|
|
|
|
// draw lines
|
|
if ((m_nStyle & (dottedLine|solidLine)) != 0)
|
|
{
|
|
if (m_nStyle & dottedLine)
|
|
pOldPen = pDC->SelectObject(&m_hDottedPen);
|
|
else
|
|
pOldPen = pDC->SelectObject(&m_hSolidPen);
|
|
pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
|
|
nOldROP = pDC->SetROP2(R2_NOTXORPEN);
|
|
rect.InflateRect(+1, +1); // borders are one pixel outside
|
|
pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);
|
|
pDC->SetROP2(nOldROP);
|
|
}
|
|
|
|
// if hatchBrush is going to be used, need to unrealize it
|
|
if ((m_nStyle & (hatchInside|hatchedBorder)) != 0)
|
|
UnrealizeObject(m_hHatchBrush.GetSafeHandle());
|
|
|
|
// hatch inside
|
|
if ((m_nStyle & hatchInside) != 0)
|
|
{
|
|
pTemp = pDC->SelectStockObject(NULL_PEN);
|
|
if (pOldPen == NULL) pOldPen = (CPen*)pTemp;
|
|
pTemp = (CGdiObject*)pDC->SelectObject(&m_hHatchBrush);
|
|
if (pOldBrush == NULL) pOldBrush = (CBrush*)pTemp;
|
|
pDC->SetBkMode(TRANSPARENT);
|
|
nOldROP = pDC->SetROP2(R2_NOTXORPEN);
|
|
pDC->Rectangle(rect.left+1, rect.top+1, rect.right, rect.bottom);
|
|
pDC->SetROP2(nOldROP);
|
|
}
|
|
|
|
// draw hatched border
|
|
if ((m_nStyle & hatchedBorder) != 0)
|
|
{
|
|
pTemp = (CGdiObject*)pDC->SelectObject(&m_hHatchBrush);
|
|
if (pOldBrush == NULL) pOldBrush = (CBrush*)pTemp;
|
|
pDC->SetBkMode(OPAQUE);
|
|
CRect rectTrue;
|
|
GetTrueRect(&rectTrue);
|
|
pDC->PatBlt(rectTrue.left, rectTrue.top, rectTrue.Width(), rect.top-rectTrue.top, 0x000F0001 /* Pn */);
|
|
pDC->PatBlt(rectTrue.left, rect.bottom, rectTrue.Width(), rectTrue.bottom-rect.bottom, 0x000F0001 /* Pn */);
|
|
pDC->PatBlt(rectTrue.left, rect.top, rect.left-rectTrue.left, rect.Height(), 0x000F0001 /* Pn */);
|
|
pDC->PatBlt(rect.right, rect.top, rectTrue.right-rect.right, rect.Height(), 0x000F0001 /* Pn */);
|
|
}
|
|
|
|
// draw resize handles
|
|
if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
|
|
{
|
|
UINT mask = GetHandleMask();
|
|
for (int i = 0; i < 8; ++i)
|
|
{
|
|
if (mask & (1<<i))
|
|
{
|
|
GetHandleRect((TrackerHit)i, &rect);
|
|
pDC->FillSolidRect(rect, color);
|
|
}
|
|
}
|
|
}
|
|
|
|
// cleanup pDC state
|
|
if (pOldPen != NULL) pDC->SelectObject(pOldPen);
|
|
if (pOldBrush != NULL) pDC->SelectObject(pOldBrush);
|
|
|
|
m_hDottedPen.DeleteObject();
|
|
m_hSolidPen.DeleteObject();
|
|
m_hHatchBrush.DeleteObject();
|
|
|
|
VERIFY(pDC->RestoreDC(-1));
|
|
}
|