Exemple #1
0
void CMapView::DrawMegaTile(CDC* pDC, int x, int y)
{
    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    int r = y * pDoc->GetWidth() + x;
    CTile Tile = pDoc->GetTile(r);

    if (m_ViewMode == VIEW_MODE_TILES)
    {
        for (int ye = 0; ye < 4; ye++)
        {
            for (int xe = 0; xe < 4; xe++)
            {
                DrawTile(pDC, x,y,xe,ye, Tile);
            }
        }
    }
    else
    {
        ASSERT(m_ViewMode == VIEW_MODE_ELEVATION);

        BYTE v = (BYTE)(Tile.Elevation);
        v = (BYTE)min(255, v*5); // make difference in color more noticable
        pDC->FillSolidRect(x*40, y*40, 40,40, RGB(v,v,v));
    }
}
Exemple #2
0
void CMapView::OnRButtonDown(UINT, CPoint point)
{
    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;

        CTile Tile = pDoc->GetTile(r);
        g_Tile = Tile.E[e];
        g_Elevation = Tile.Elevation;

        CString str;
        str.Format("Select %s (%dm) from %d [%d]", g_App.m_Elements[g_Tile].Name, g_Elevation, r,e);
        g_App.PrintStatus(str);
    }
}
Exemple #3
0
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);
}
Exemple #4
0
void CMapView::OnInitialUpdate()
{
    Inherited::OnInitialUpdate();

    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    int h = pDoc->GetHeight();
    int w = pDoc->GetWidth();

    SetScrollSizes(MM_TEXT, CSize(w*40, h*40));
}
Exemple #5
0
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);
    }
}
Exemple #6
0
void CMapView::OnDraw(CDC* pDC)
{
    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    int h = pDoc->GetHeight();
    int w = pDoc->GetWidth();

    CRect r;
    pDC->GetClipBox(&r);
    pDC->FillSolidRect(r, GetSysColor(COLOR_3DFACE));

    if (w > 0 && h > 0)
    {
        // calculate the bounding box that is needed to be draw
        CRect r;
        pDC->GetClipBox(&r);
        int ys = r.top    / 40;
        int ye = r.bottom / 40;
        int xs = r.left   / 40;
        int xe = r.right  / 40;
        ye = min(ye+1,h);
        xe = min(xe+1,w);

        if (m_ViewMode == VIEW_MODE_GRAPHICS)
        {
			if (pDoc->m_pMapImage)
			{
				pDC->SetStretchBltMode(COLORONCOLOR);
				CRect r(0,0,pDoc->m_pMapImage->GetWidth(), pDoc->m_pMapImage->GetHeight());
				pDoc->m_pMapImage->Draw(pDC, r,r);
			}
        }
        else
        {
            for (int y = ys; y < ye; y++)
            {
                for (int x = xs; x < xe; x++)
                {
                    DrawMegaTile(pDC, x,y);
                }
            }
        }

        if (m_GridMode)
        {
            // draw major grid lines
            {
                CPen Pen;
                Pen.CreateStockObject(BLACK_PEN);
                CPen* pOldPen = pDC->SelectObject(&Pen);
                for (int y = ys; y <= ye; y++)
                {
                    pDC->MoveTo(xs*40,y*40);
                    pDC->LineTo(xe*40,y*40);

                }
                for (int x = xs; x <= xe; x++)
                {
                    pDC->MoveTo(x*40,ys*40);
                    pDC->LineTo(x*40,ye*40);
                }
                pDC->SelectObject(pOldPen);
            }
        }
    }
}