📄 aseview.cpp
字号:
CRect rect(x*ASE_GRIDSIZE, y*ASE_GRIDSIZE,
x*ASE_GRIDSIZE+ASE_GRIDSIZE+1,
y*ASE_GRIDSIZE+ASE_GRIDSIZE+1);
pDC->FillSolidRect(rect, cr);
pDC->FrameRect(&rect, &br);
}
void CAseView::DrawRectangleNB(int x, int y, CDC *pDC, COLORREF cr)
{
CRect rect(x*ASE_GRIDSIZE, y*ASE_GRIDSIZE,
x*ASE_GRIDSIZE+ASE_GRIDSIZE+1,
y*ASE_GRIDSIZE+ASE_GRIDSIZE+1);
pDC->FillSolidRect(rect, cr);
}
void CAseView::DrawCircle(int x, int y, CDC *pDC, COLORREF cr)
{
CBrush br(cr), *oldbrush;
CPen pen(PS_SOLID, 0, RGB(0,0,0)), *oldpen;
CRect rect(x*ASE_GRIDSIZE, y*ASE_GRIDSIZE,
x*ASE_GRIDSIZE+ASE_GRIDSIZE+1,
y*ASE_GRIDSIZE+ASE_GRIDSIZE+1);
oldbrush = pDC->SelectObject(&br);
oldpen = pDC->SelectObject(&pen);
pDC->Ellipse(rect);
pDC->SelectObject(oldbrush);
pDC->SelectObject(oldpen);
}
void CAseView::DrawRoute(CDC *pDC)
{
CAseDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPen pen(PS_SOLID,1,RGB(0,0,0)),*oldpen;
oldpen = pDC->SelectObject(&pen);
CAStar *astar = pDoc->GetPathFinder();
_asNode *best = astar->GetBestNode();
int x,y,px,py;
if (best) {
x = best->GetX();
y = best->GetY();
px = x * ASE_GRIDSIZE + (ASE_GRIDSIZE / 2);
py = y * ASE_GRIDSIZE + (ASE_GRIDSIZE / 2);
pDC->MoveTo(px,py);
best = best->GetParent();
}
while (best) {
x = best->GetX();
y = best->GetY();
px = x * ASE_GRIDSIZE + (ASE_GRIDSIZE / 2);
py = y * ASE_GRIDSIZE + (ASE_GRIDSIZE / 2);
pDC->LineTo(px,py);
best = best->GetParent();
}
pDC->SetPixel(px,py, RGB(0,0,128));
pDC->SelectObject(oldpen);
}
void CAseView::HighlightNode(_asNode *node, bool drawKidsConnections)
{
if (!node) {
m_cHilight.x = -1;
m_cHilightNode = NULL;
} else {
m_cHilight.x = node->GetX();
m_cHilight.y = node->GetY();
m_cHilightNode = node;
}
Invalidate(false);
}
void CAseView::RemoveHighlight()
{
m_cHilight.x = -1;
m_cHilightNode = NULL;
}
void CAseView::OnInitialUpdate()
{
CView::OnInitialUpdate();
m_cHilight.x = -1;
m_cHilightNode = NULL;
GetDocument()->GetStartEnd(m_cStart, m_cEnd);
}
/////////////////////////////////////////////////////////////////////////////
// CAseView diagnostics
#ifdef _DEBUG
void CAseView::AssertValid() const
{
CView::AssertValid();
}
void CAseView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CAseDoc* CAseView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAseDoc)));
return (CAseDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAseView message handlers
void CAseView::OnLButtonDown(UINT nFlags, CPoint point)
{
CAseDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
MouseToPoint(point, m_uBrushType);
if (m_uBrushType < 4) m_bDragging = true;
CView::OnLButtonDown(nFlags, point);
}
void CAseView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bDragging = false;
GetDocument()->NotifyClick();
CView::OnLButtonUp(nFlags, point);
}
void CAseView::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bDragging) {
MouseToPoint(point, m_uBrushType);
}
CView::OnMouseMove(nFlags, point);
}
void CAseView::MouseToPoint(CPoint point, UINT brush)
{
CClientDC dc(this);
int px = point.x/8, py = point.y/8;
CPoint round(px*ASE_GRIDSIZE, py*ASE_GRIDSIZE),temp;
GetDocument()->GetStartEnd(m_cStart, m_cEnd);
// If start or end
if (brush == 4) {
temp.x = m_cStart.x * ASE_GRIDSIZE;
temp.y = m_cStart.y * ASE_GRIDSIZE;
m_cStart.x = px;
m_cStart.y = py;
InvalidateRect(CRect(round,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
InvalidateRect(CRect(temp,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
} else if (brush == 5) {
temp.x = m_cEnd.x * ASE_GRIDSIZE;
temp.y = m_cEnd.y * ASE_GRIDSIZE;
m_cEnd.x = px;
m_cEnd.y = py;
InvalidateRect(CRect(round,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
InvalidateRect(CRect(temp,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
}
else if (brush == -1)
{
CPoint bp = GetDocument()->GetBreakpoint();
temp.x = bp.x * ASE_GRIDSIZE;
temp.y = bp.y * ASE_GRIDSIZE;
bp.x = px;
bp.y = py;
GetDocument()->SetBreakpoint(bp);
InvalidateRect(CRect(round,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
InvalidateRect(CRect(temp,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
}
else if (brush == 6) // threat position
{
GetDocument()->GetThreatBoard()->MarkThreatPosition(px, py);
GetDocument()->GetLOSApproximationBoard()->ApplyThreatModification(px, py);
if ( GetDocument()->DoesDisplayApproximatedLinesOfFire() )
{
DisplayWaitCursor();
GetDocument()->GetLOSApproximationBoard()->ComputeLinesOfFireApproximation();
DisplayDefaultCursor();
}
//! \todo make a bit smarter, since only the rectangles within a radius are affected
Invalidate();
}
else if (brush == 0) // clearing position
{
// check whether threats are visible and if threat needs to be removed (first)
if ( ( GetDocument()->DoesDisplayThreatPositions() )
&& ( GetDocument()->GetThreatBoard()->IsThreatPosition(px, py) )
)
{
GetDocument()->GetThreatBoard()->ClearThreatPosition(px, py);
GetDocument()->GetLOSApproximationBoard()->ApplyThreatModification(px, py);
if ( GetDocument()->DoesDisplayApproximatedLinesOfFire() )
{
DisplayWaitCursor();
GetDocument()->GetLOSApproximationBoard()->ComputeLinesOfFireApproximation();
DisplayDefaultCursor();
}
//! \todo make a bit smarter, since only the rectangles within a radius are affected
Invalidate();
}
else
{
bool bFullRedraw;
bFullRedraw = GetDocument()->GetTerrainBoard()->IsLocationImpassable(px, py);
GetDocument()->GetTerrainBoard()->SetCellValue(px, py, 0);
if ( bFullRedraw )
{
DisplayWaitCursor();
GetDocument()->GetThreatBoard()->ComputeLinesOfFire();
GetDocument()->GetLOSApproximationBoard()->ApplyTerrainModification(px, py);
if ( GetDocument()->DoesDisplayApproximatedLinesOfFire() )
{
GetDocument()->GetLOSApproximationBoard()->ComputeLinesOfFireApproximation();
}
DisplayDefaultCursor();
Invalidate();
}
else
{
InvalidateRect(CRect(round,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
}
}
}
else if (brush == 3) // impassable terrain
{
// clear threat, if necessary
GetDocument()->GetTerrainBoard()->SetCellValue(px, py, 3);
GetDocument()->GetThreatBoard()->ClearThreatPosition(px, py);
GetDocument()->GetLOSApproximationBoard()->ApplyTerrainModification(px, py);
if ( GetDocument()->DoesDisplayApproximatedLinesOfFire() )
{
DisplayWaitCursor();
GetDocument()->GetLOSApproximationBoard()->ComputeLinesOfFireApproximation();
DisplayDefaultCursor();
}
Invalidate();
}
else // terrain weights
{
//! \todo handle invalidation after painting impassable terrain, since
// it may block lof
GetDocument()->GetTerrainBoard()->SetCellValue(px, py, brush);
GetDocument()->GetLOSApproximationBoard()->ApplyTerrainModification(px, py);
if ( GetDocument()->DoesDisplayApproximatedLinesOfFire() )
{
DisplayWaitCursor();
GetDocument()->GetLOSApproximationBoard()->ComputeLinesOfFireApproximation();
DisplayDefaultCursor();
}
assert( GetDocument()->GetTerrainBoard()->GetCellValue(px, py) == brush );
InvalidateRect(CRect(round,CSize(ASE_GRIDSIZE+1,ASE_GRIDSIZE+1)), false);
}
GetDocument()->SetModifiedFlag();
GetDocument()->SetStartEnd(m_cStart, m_cEnd);
}
BOOL CAseView::OnEraseBkgnd(CDC* pDC)
{
return false;
return CView::OnEraseBkgnd(pDC);
}
void CAseView::OnRButtonDblClk(UINT nFlags, CPoint point)
{
MouseToPoint(point, -1);
CView::OnRButtonDblClk(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -