void CMapView::OnLButtonDown(UINT nFlags, CPoint point) { if (m_HandDown) { m_Tracking = true; SetCapture(); m_LastPoint = point; } else { CPoint pt = point + GetScrollPosition(); int x = pt.x / 40; int y = pt.y / 40; int xe = (pt.x % 40) / 10; int ye = (pt.y % 40) / 10; CMapDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); int w = pDoc->GetWidth(); int h = pDoc->GetHeight(); if (w > 0 && h > 0 && x >= 0 && y >= 0 && x < w && y < h && xe >= 0 && xe < 4 && ye >= 0 && ye < 4) { int r = y*w + x; int e = ye*4 + xe; if (m_ViewMode == VIEW_MODE_ELEVATION) { pDoc->SetTileElevation(r, g_Elevation); CString str; str.Format("Change %d to %dm", r, g_Elevation); g_App.PrintStatus(str); CRect rect(CPoint(x*40, y*40), CSize(40,40)); rect.OffsetRect(-GetScrollPosition()); InvalidateRect(rect, FALSE); } else { pDoc->SetTile(r,e, g_Tile); CString str; str.Format("Change %d [%d] to %s", r,e, g_App.m_Elements[g_Tile].Name); g_App.PrintStatus(str); CRect rect(CPoint(x*40 + xe*10, y*40 + ye*10), CSize(10,10)); rect.OffsetRect(-GetScrollPosition()); InvalidateRect(rect, FALSE); } m_Tracking = true; SetCapture(); } } Inherited::OnLButtonDown(nFlags, point); }
void CMapView::OnMouseMove(UINT, CPoint point) { if (m_HandDown && m_Tracking) { CPoint Delta = m_LastPoint - point; CPoint NewPoint = GetScrollPosition() + Delta; ScrollToPosition(NewPoint); m_LastPoint = point; } else { point += GetScrollPosition(); int x = point.x / 40; int y = point.y / 40; int xe = (point.x % 40) / 10; int ye = (point.y % 40) / 10; CMapDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); int w = pDoc->GetWidth(); int h = pDoc->GetHeight(); CString str; if (w > 0 && h > 0 && x >= 0 && y >= 0 && x < w && y < h && xe >= 0 && xe < 4 && ye >= 0 && ye < 4) { int r = y*w + x; int e = ye*4 + xe; CTile Tile = pDoc->GetTile(r); int Elevation = Tile.Elevation; CElement Element = g_App.m_Elements[Tile.E[e]]; str.Format("%s (%d)", Element.Name, Element.Type); g_App.PrintStatus(str,1); str.Format("%dm", Elevation); g_App.PrintStatus(str,2); str.Format("%d,%d (%d,%d)", x,y, xe,ye); g_App.PrintStatus(str,3); str.Format("%d E%d", r,e); g_App.PrintStatus(str,4); if (m_Tracking) { if (m_ViewMode == VIEW_MODE_ELEVATION) { pDoc->SetTileElevation(r, g_Elevation); CString str; str.Format("Change %d to %dm", r, g_Elevation); g_App.PrintStatus(str); CRect rect(CPoint(x*40, y*40), CSize(40,40)); rect.OffsetRect(-GetScrollPosition()); InvalidateRect(rect, FALSE); } else { pDoc->SetTile(r,e, g_Tile); CString str; str.Format("Change %d [%d] to %s", r,e, g_App.m_Elements[g_Tile].Name); g_App.PrintStatus(str); CRect rect(CPoint(x*40 + xe*10, y*40 + ye*10), CSize(10,10)); rect.OffsetRect(-GetScrollPosition()); InvalidateRect(rect, FALSE); } } } else { str.Empty(); g_App.PrintStatus(str,1); g_App.PrintStatus(str,2); g_App.PrintStatus(str,3); g_App.PrintStatus(str,4); } str.Format("%d,%d", point.x,point.y); g_App.PrintStatus(str,5,true); } }