📄 designview.cpp
字号:
ClientDC.SelectObject(&m_PenDotted);
ClientDC.SetBkMode(TRANSPARENT);
ClientDC.SelectStockObject(NULL_BRUSH);
////// delete previously drawn rectangle (for Door or Window)
switch (pDoc->m_CurrentElement)
{
case ID_ELEMENT_DOOR:
ClientDC.Rectangle(m_PointOld.x - 24, m_PointOld.y - 24, m_PointOld.x, m_PointOld.y);
break;
case ID_ELEMENT_WINDOW:
ClientDC.Rectangle(m_PointOld.x - 24, m_PointOld.y - 24, m_PointOld.x, m_PointOld.y);
break;
}
////// Snap to grid
int x = point.x;
int y = point.y;
x = (point.x/8)*8;
y = (point.y/8)*8;
CPoint npoint(x, y);
////// Do nothing in these cases
if (pDoc->m_CurrentElement == ID_ELEMENT_CURSOR) //if cursor is selected
return;
if ((m_PointOld == m_PointOrigin) && (pDoc->m_CurrentElement == ID_ELEMENT_ROOM)) // if two points are the same
return;
CElement *pElement;
int NumElem = pDoc->GetNumElem();
int i;
CRect Temprect;
////// create new element
switch (pDoc->m_CurrentElement)
{
////// create new room
case ID_ELEMENT_ROOM:
{
////////// Prevent drawing into existing room; only for ROOM
CRect Currentrect( min(m_PointOrigin.x, x),
min(m_PointOrigin.y, y),
max(m_PointOrigin.x, x),
max(m_PointOrigin.y, y));
ASSERT_VALID(pDoc);
for (i = 0; i < NumElem; ++i) // check existing rooms
{
pElement = pDoc->GetElem(i);
if (pElement->m_ElemType == ROOM) // if it is a room
{
Temprect = pElement->GetDimRect();
Temprect.DeflateRect(1,1);
CRect IntRect;
if (IntRect.IntersectRect(Temprect, Currentrect))
{
npoint = m_PointOld;
}
}
}
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x, m_PointOld.y);
pElement = new CRoom(m_PointOrigin.x, m_PointOrigin.y, npoint.x, npoint.y, pDoc->m_Color, pDoc->m_Thickness);
}
break;
case ID_ELEMENT_DOOR:
{
////// create new door
BOOL intersectdoor = FALSE;
CPoint pointa, pointb;
////////////// Check if there is intersection between wall and door
for (i = 0; ((i < NumElem) && (intersectdoor == FALSE)); ++i)
{
pElement = pDoc->GetElem(i);
if (pElement->m_ElemType == ROOM)
{
Temprect = pElement->GetDimRect();
int top = (Temprect.TopLeft()).y;
int left = (Temprect.TopLeft()).x;
int bottom = (Temprect.BottomRight()).y;
int right = (Temprect.BottomRight()).x;
if (npoint.x < 24)
npoint.x = 24;
if (npoint.y < 24)
npoint.y = 24;
if ((npoint.x > left) && (npoint.x - 24 < left) && (npoint.y < bottom) && (npoint.y > top + 24))
{
pointa.x = left - 8;
pointb.x = left + 8;
pointa.y = npoint.y - 24;
pointb.y = npoint.y;
intersectdoor = TRUE;
}
else if ((npoint.x > right) && (npoint.x - 24 < right) && (npoint.y < bottom) && (npoint.y > top + 24))
{
pointa.x = right - 8;
pointb.x = right + 8;
pointa.y = npoint.y - 24;
pointb.y = npoint.y;
intersectdoor = TRUE;
}
else if ((npoint.y > bottom) && (npoint.y - 24 < bottom) && (npoint.x < right) && (npoint.x > left + 24))
{
pointa.x = npoint.x -24;
pointb.x = npoint.x;
pointa.y = bottom - 8;
pointb.y = bottom + 8;
intersectdoor = TRUE;
}
else if ((npoint.y > top) && (npoint.y - 24 < top) && (npoint.x < right) && (npoint.x > left + 24))
{
pointa.x = npoint.x -24;
pointb.x = npoint.x;
pointa.y = top - 8;
pointb.y = top + 8;
intersectdoor = TRUE;
}
}
}
if (intersectdoor == FALSE)
return;
CRect intersect;
CRect Temprect2(pointa.x, pointa.y, pointb.x, pointb.y);
for (i = 0; i < NumElem; ++i)
{
pElement = pDoc->GetElem(i);
if ((pElement->m_ElemType == DOOR) || (pElement->m_ElemType == WINDOW))
{
Temprect = pElement->GetDimRect();
intersectdoor = !intersect.IntersectRect(Temprect, Temprect2);
if (intersectdoor == FALSE)
return;
}
}
pElement = new CDoor(pointa.x, pointa.y, pointb.x, pointb.y, pDoc->m_Color, pDoc->m_Thickness);
}
break;
case ID_ELEMENT_WINDOW:
{
// ClientDC.Rectangle(m_PointOld.x - 24, m_PointOld.y - 24, m_PointOld.x, m_PointOld.y);
BOOL intersectwindow = FALSE;
CPoint pointa, pointb;
int outxy;
////////////// Check if there is intersection between wall and door
for (i = 0; ((i < NumElem) && (intersectwindow == FALSE)); ++i)
{
pElement = pDoc->GetElem(i);
if (pElement->m_ElemType == ROOM)
{
Temprect = pElement->GetDimRect();
int top = (Temprect.TopLeft()).y;
int left = (Temprect.TopLeft()).x;
int bottom = (Temprect.BottomRight()).y;
int right = (Temprect.BottomRight()).x;
if (npoint.x < 24)
npoint.x = 24;
if (npoint.y < 24)
npoint.y = 24;
if ((npoint.x > left) && (npoint.x - 24 < left) && (npoint.y < bottom) && (npoint.y > top + 24))
{
pointa.x = left - 8;
pointb.x = left + 8;
pointa.y = npoint.y - 24;
pointb.y = npoint.y;
outxy = OPENLEFT;
intersectwindow = TRUE;
}
else if ((npoint.x > right) && (npoint.x - 24 < right) && (npoint.y < bottom) && (npoint.y > top + 24))
{
pointa.x = right - 8;
pointb.x = right + 8;
pointa.y = npoint.y - 24;
pointb.y = npoint.y;
outxy = OPENRIGHT;
intersectwindow = TRUE;
}
else if ((npoint.y > bottom) && (npoint.y - 24 < bottom) && (npoint.x < right) && (npoint.x > left + 24))
{
pointa.x = npoint.x -24;
pointb.x = npoint.x;
pointa.y = bottom - 8;
pointb.y = bottom + 8;
outxy = OPENDOWN;
intersectwindow = TRUE;
}
else if ((npoint.y > top) && (npoint.y - 24 < top) && (npoint.x < right) && (npoint.x > left + 24))
{
pointa.x = npoint.x -24;
pointb.x = npoint.x;
pointa.y = top - 8;
pointb.y = top + 8;
outxy = OPENUP;
intersectwindow = TRUE;
}
}
}
if (intersectwindow == FALSE)
return;
CRect intersect;
CRect Temprect2(pointa.x, pointa.y, pointb.x, pointb.y);
for (i = 0; i < NumElem; ++i)
{
pElement = pDoc->GetElem(i);
if ((pElement->m_ElemType == DOOR) || (pElement->m_ElemType == WINDOW))
{
Temprect = pElement->GetDimRect();
intersectwindow = !intersect.IntersectRect(Temprect, Temprect2);
if (intersectwindow == FALSE)
return;
}
}
pElement = new CWindow(pointa.x, pointa.y, pointb.x, pointb.y, outxy, pDoc->m_Color, pDoc->m_Thickness);
}
break;
case ID_ELEMENT_ROOF:
{
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x, m_PointOld.y);
////////// Prevent drawing outside a room
BOOL intersect = FALSE;
CRect Currentrect( min(m_PointOrigin.x, x),
min(m_PointOrigin.y, y),
max(m_PointOrigin.x, x),
max(m_PointOrigin.y, y));
ASSERT_VALID(pDoc);
for (i = 0; i < NumElem; ++i) // check existing roofs
{
pElement = pDoc->GetElem(i);
if (pElement->m_ElemType == ROOF) // if it is a roof, use Old Point
{
Temprect = pElement->GetDimRect();
Temprect.DeflateRect(1,1);
CRect IntRect;
if (IntRect.IntersectRect(Temprect, Currentrect))
{
npoint = m_PointOld;
}
}
}
Currentrect.SetRect( min(m_PointOrigin.x, npoint.x),
min(m_PointOrigin.y, npoint.y),
max(m_PointOrigin.x, npoint.x),
max(m_PointOrigin.y, npoint.y));
for (i = 0; ((i < NumElem) && (intersect == FALSE)); ++i) // check existing rooms
{
pElement = pDoc->GetElem(i);
if (pElement->m_ElemType == ROOM) // if it is a room, return
{
Temprect = pElement->GetDimRect();
Temprect.DeflateRect(1,1);
CRect IntRect;
if (IntRect.IntersectRect(Temprect, Currentrect))
{
intersect = TRUE;
}
}
}
if (intersect == FALSE)
return;
////////// Choose which side it should slope towards
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x, m_PointOld.y);
CSlopeDlg dlg;
if (dlg.DoModal() == IDOK)
{
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x, m_PointOld.y);
pElement = new CRoof(m_PointOrigin.x, m_PointOrigin.y, npoint.x, npoint.y, pDoc->m_Color, pDoc->m_Thickness, dlg.m_type);
}
else
{
/////////////// Cancel button is pressed
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x, m_PointOld.y);
return;
}
}
break;
}
ClientDC.SetROP2(R2_COPYPEN);
CDesignDoc* PDoc = GetDocument();
PDoc->AddElem(pElement);
pDoc->UpdateAllViews(NULL, 0, pElement);
CScrollView::OnLButtonUp(nFlags, point);
}
void CDesignView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC ClientDC(this);
OnPrepareDC (&ClientDC);
ClientDC.DPtoLP(&point);
m_CurPos.x = point.x/8;
m_CurPos.y = point.y/8;
CDesignDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
UINT currentelem = pDoc->m_CurrentElement;
if (!m_Dragging)
{
CSize ScrollSize = GetTotalSize();
CRect ScrollRect(0,0, ScrollSize.cx, ScrollSize.cy);
if ((!ScrollRect.PtInRect(point)) || (currentelem == ID_ELEMENT_CURSOR))
::SetCursor(m_HArrow);
else
::SetCursor(m_HCross);
return;
}
ClientDC.SetROP2(R2_NOT);
ClientDC.SelectObject(&m_PenDotted);
ClientDC.SetBkMode(TRANSPARENT);
ClientDC.SelectStockObject(NULL_BRUSH);
int x = point.x;
int y = point.y;
//////Snap to grid
x = (point.x/8)*8;
y = (point.y/8)*8;
CPoint npoint(x, y);
CRect Currentrect( min(m_PointOrigin.x, x),
min(m_PointOrigin.y, y),
max(m_PointOrigin.x, x),
max(m_PointOrigin.y, y));
ASSERT_VALID(pDoc);
CElement *pElement;
CRect Temprect;
////// Same as IsRectNull--check if the current rectangle's null
if (((npoint.x == m_PointOrigin.x) || (npoint.y == m_PointOrigin.y)) && (currentelem == ID_ELEMENT_ROOM))
return;
if ((currentelem == ID_ELEMENT_DOOR) || (currentelem == ID_ELEMENT_WINDOW))
{
if (npoint.x < 24)
npoint.x = 24;
if (npoint.y < 24)
npoint.y = 24;
}
////// Select element
switch(currentelem)
{
case ID_ELEMENT_ROOM:
{
////////// prevent drawing into existing room (only for ROOM element)
int NumElem = pDoc->GetNumElem();
for (int i = 0; i < NumElem; ++i)
{
pElement = pDoc->GetElem(i);
if (pElement->m_ElemType == ROOM) // if it is a room
{
Temprect = pElement->GetDimRect();
Temprect.DeflateRect(1,1);
CRect IntRect;
if (IntRect.IntersectRect(Temprect, Currentrect))
{
return;
}
}
}
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x, m_PointOld.y);
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, npoint.x, npoint.y);
}
break;
case ID_ELEMENT_DOOR:
ClientDC.Rectangle(m_PointOld.x - 24, m_PointOld.y - 24, m_PointOld.x, m_PointOld.y);
ClientDC.Rectangle(npoint.x - 24, npoint.y - 24, npoint.x, npoint.y);
break;
case ID_ELEMENT_WINDOW:
ClientDC.Rectangle(m_PointOld.x - 24, m_PointOld.y - 24, m_PointOld.x, m_PointOld.y);
ClientDC.Rectangle(npoint.x - 24, npoint.y - 24, npoint.x, npoint.y);
break;
case ID_ELEMENT_ROOF:
{
int NumElem = pDoc->GetNumElem();
for (int i = 0; i < NumElem; ++i)
{
pElement = pDoc->GetElem(i);
if (pElement->m_ElemType == ROOF) // if it is a room
{
Temprect = pElement->GetDimRect();
Temprect.DeflateRect(1,1);
CRect IntRect;
if (IntRect.IntersectRect(Temprect, Currentrect))
{
return;
}
}
}
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x, m_PointOld.y);
ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, npoint.x, npoint.y);
}
break;
}
m_PointOld = npoint;
CScrollView::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -