예제 #1
0
파일: MazeMap.c 프로젝트: maksverver/Amazes
void mm_look(MazeMap *mm, const char *line, RelDir rel_dir)
{
    Dir front = TURN(mm->dir, rel_dir),
        left  = TURN(front, LEFT),
        right = TURN(front, RIGHT),
        back  = TURN(front, BACK);

    int r = mm->loc.r,
        c = mm->loc.c;

    while (*line)
    {
        bool open_left = false, open_right = false;
        switch (*line++)
        {
        case 'B':  /* opening on both sides */
            open_left = open_right = true;
            break;
        case 'L':  /* opening on left side */
            open_left = true;
            break;
        case 'R':   /* opening on right side */
            open_right = true;
            break;
        case 'N':   /* no opening on either side */
            break;
        case 'W':  /* wall immediately ahead: */
            SET_WALL(mm, r, c, front, PRESENT);
            assert(*line == '\0');
            return;
        default:  /* invalid char */
            assert(0);
        }

        push_border(mm, r, c, front);
        r = RDR(r, front);
        c = CDC(c, front);

        SET_SQUARE(mm, r, c, PRESENT);
        SET_WALL(mm, r, c, back, ABSENT);
        SET_WALL(mm, r, c, left, open_left ? ABSENT : PRESENT);
        SET_WALL(mm, r, c, right, open_right ? ABSENT : PRESENT);

        if (open_left)
        {
            SET_SQUARE(mm, RDR(r, left), CDC(c, left), PRESENT);
            push_border(mm, r, c, left);
        }

        if (open_right)
        {
            SET_SQUARE(mm, RDR(r, right), CDC(c, right), PRESENT);
            push_border(mm, r, c, right);
        }
    }

    assert(0); /* shouldn't get here: every line must end with W */
    return;
}
예제 #2
0
파일: mapview.cpp 프로젝트: Mileslee/wxgis
void wxGISMapView::RotateBy(wxPoint MouseLocation)
{
	if(m_nDrawingState == enumGISMapRotating)
	{
		if(m_pGISDisplay)
		{
			//compute angle
			double dX = m_FrameCenter.x - MouseLocation.x;
			double dY = m_FrameCenter.y - MouseLocation.y;
			double dAngle = atan2(dY, dX);
			dAngle -= m_dOriginAngle;
			if(dAngle < 0)
				dAngle += 2 * M_PI;

			wxClientDC CDC(this);
			m_pGISDisplay->RotatingDraw(dAngle, &CDC);

			m_dCurrentAngle = DOUBLEPI - m_pGISDisplay->GetRotate() - dAngle;
			if(m_dCurrentAngle >= DOUBLEPI)
				m_dCurrentAngle -= DOUBLEPI;
			if(m_dCurrentAngle < 0)
				m_dCurrentAngle += DOUBLEPI;
			DrawToolTip(CDC, wxString::Format(_("%.4f degree"), m_dCurrentAngle * DEGPI));
		}
	}
}
예제 #3
0
파일: AI.c 프로젝트: maksverver/Amazes
static Point explore(MazeMap *mm)
{
    Point res;
    int r, c, dir;
    int best_v = 0, best_dist = 0;
    for (r = 0; r < HEIGHT; ++r)
    {
        for (c = 0; c < WIDTH; ++c)
        {
            if (dist[r][c] != -1)
            {
                int v = 0;
                for (dir = 0; dir < 4; ++dir)
                {
                    if (SQUARE(mm, RDR(r, dir), CDC(c, dir)) == UNKNOWN &&
                        WALL(mm, r, c, dir) != PRESENT) ++v;
                }
                if (v > best_v || (v == best_v && dist[r][c] < best_dist))
                {
                    best_v = v;
                    best_dist = dist[r][c];
                    res.r = r;
                    res.c = c;
                }
            }
        }
    }
    assert(best_v > 0);
    return res;
}
예제 #4
0
파일: mapview.cpp 프로젝트: jacklibj/r5
void *wxDrawingThread::Entry()
{
	wxClientDC CDC(m_pView);

	for(size_t i = 0; i < m_Layers.size(); i++)
	{
		if(m_pTrackCancel && !m_pTrackCancel->Continue())
			break;
		if(m_pGISScreenDisplay->IsCacheDerty(m_Layers[i]->GetCacheID()) && m_Layers[i]->GetVisible())
		{
			size_t CacheIDCurrent, CacheIDPrevious;
			if(i == 0)
				CacheIDPrevious = 0;
			else
				CacheIDPrevious = m_Layers[i - 1]->GetCacheID();

			CacheIDCurrent = m_Layers[i]->GetCacheID();

			if(CacheIDCurrent != CacheIDPrevious)				
			{
				m_pGISScreenDisplay->MergeCaches(CacheIDPrevious, CacheIDCurrent);
				m_pGISScreenDisplay->SetCacheDerty(CacheIDCurrent, false);
			}

			if(m_pTrackCancel && !m_pTrackCancel->Continue())
				break;
			m_Layers[i]->Draw(wxGISDPGeography, m_pGISScreenDisplay, m_pTrackCancel);
		}
	}
	m_pGISScreenDisplay->SetDerty(false);
	m_pGISScreenDisplay->OnDraw(CDC);

	return NULL;
}
예제 #5
0
파일: mapview.cpp 프로젝트: jacklibj/r5
void wxGISMapView::OnSize(wxSizeEvent & event)
{
	m_pTrackCancel->Cancel();
	if(m_pThread)
		m_pThread->Delete();

	wxClientDC CDC(this);
	IDisplayTransformation* pDisplayTransformation = pGISScreenDisplay->GetDisplayTransformation();
	pDisplayTransformation->SetPPI(CDC.GetPPI());

	wxMouseState state = wxGetMouseState();
	if(state.LeftDown())
	{
		wxRect rc = GetClientRect();
		pGISScreenDisplay->OnStretchDraw(CDC, rc.width, rc.height);
		m_MouseState |= enumGISMouseLeftDown;
		m_timer.Start(300);
	}
	else
	{
		m_MouseState &= ~enumGISMouseLeftDown;//enumGISMouseNone;
		//set map init envelope
		pDisplayTransformation->SetDeviceFrame(GetClientRect());
		pGISScreenDisplay->SetDerty(true);
	}
	Refresh(false);

	event.Skip();
}
예제 #6
0
파일: MazeMap.c 프로젝트: maksverver/Amazes
static bool mark_dead_end(MazeMap *mm, bool dead_end[HEIGHT][WIDTH],
                          int r, int c)
{
    int num_walls = 0, num_dead_adjacent = 0, dir;
    bool changed = false;

    if (dead_end[r][c]) return false;

    for (dir = 0; dir < 4; ++dir)
    {
        int w = WALL(mm, r, c, dir);
        if (w == PRESENT)
            ++num_walls;
        else
        if (w == ABSENT && dead_end[RDR(r, dir)][CDC(c, dir)])
            ++num_dead_adjacent;
    }
    assert(num_walls + num_dead_adjacent < 4);

    if (num_walls + num_dead_adjacent == 3)
    {
        dead_end[r][c] = true;
        if (SQUARE(mm, r, c) == UNKNOWN)
        {
            SET_SQUARE(mm, r, c, PRESENT);
            changed = true;
        }
        for (dir = 0; dir < 4; ++dir)
        {
            if (WALL(mm, r, c, dir) == UNKNOWN)
            {
                SET_WALL(mm, r, c, dir, ABSENT);
                changed = true;
            }
        }
        for (dir = 0; dir < 4; ++dir)
        {
            if (WALL(mm, r, c, dir) == ABSENT)
            {
                if (mark_dead_end(mm, dead_end, RDR(r, dir), CDC(c, dir)))
                    changed = true;
            }
        }
    }

    return changed;
}
예제 #7
0
LRESULT CSolutionDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    LRESULT res = Base::OnInitDialog(uMsg, wParam, lParam, bHandled);
    GetDlgItem(IDC_QUESTION).SetWindowText(m_question);

    m_Quest.m_TextColor = CDC(GetDlgItem(IDC_QUESTION).GetDC()).GetTextColor();
    m_Quest.SubclassWindow(GetDlgItem(IDC_QUESTION));

    return res;
}
예제 #8
0
파일: mapview.cpp 프로젝트: Mileslee/wxgis
void wxGISMapView::PanMoveTo(wxPoint MouseLocation)
{
	if(m_nDrawingState == enumGISMapPanning)
	{
		wxCoord x =  m_StartMouseLocation.x - MouseLocation.x;
		wxCoord y =  m_StartMouseLocation.y - MouseLocation.y;
		wxClientDC CDC(this);
		if(m_pGISDisplay)
			m_pGISDisplay->PanningDraw(x, y, &CDC);
	}
}
예제 #9
0
파일: mapview.cpp 프로젝트: jacklibj/r5
void wxGISMapView::PanMoveTo(wxPoint MouseLocation)
{

	if(m_MapToolState & enumGISMapPanning)
	{
		wxCoord x =  m_StartMouseLocation.x - MouseLocation.x;
		wxCoord y =  m_StartMouseLocation.y - MouseLocation.y;
		wxClientDC CDC(this);
		pGISScreenDisplay->OnPanDraw(CDC, x, y);
	}
}
예제 #10
0
파일: rubberband.cpp 프로젝트: jacklibj/r5
void wxGISRubberBand::OnKeyDown(wxKeyEvent & event)
{
	switch(event.GetKeyCode())
	{
	case WXK_ESCAPE:
		{
			wxClientDC CDC(m_pWnd);
			m_pCachedDisplay->OnDraw(CDC);
		}
		OnUnlock();
		break;
	default:
		break;
	}
	event.Skip();
}
예제 #11
0
파일: MazeMap.c 프로젝트: maksverver/Amazes
void mm_move(MazeMap *mm, char move)
{
    RelDir rel_dir;
    switch (move)
    {
    case 'F': rel_dir = FRONT; break;
    case 'T': rel_dir = BACK;  break;
    case 'L': rel_dir = LEFT;  break;
    case 'R': rel_dir = RIGHT; break;
    default: assert(0);   /* invalid char */
    }
    mm->dir = TURN(mm->dir, rel_dir);
    push_border(mm, mm->loc.r, mm->loc.c, mm->dir);
    mm->loc.r = RDR(mm->loc.r, mm->dir);
    mm->loc.c = CDC(mm->loc.c, mm->dir);
    SET_SQUARE(mm, mm->loc.r, mm->loc.c, PRESENT);
}
예제 #12
0
파일: mapview.cpp 프로젝트: Mileslee/wxgis
void wxGISMapView::OnSize(wxSizeEvent & event)
{
    if(m_PrevSize == event.GetSize())
        return;

    //event.Skip(false);
    DestroyDrawThread();

    wxRect rc = GetClientRect();

    if(IsShownOnScreen())
    {
	    if(m_nDrawingState == enumGISMapZooming)
	    {
		    wxClientDC CDC(this);
		    if(m_pGISDisplay)
			    m_pGISDisplay->ZoomingDraw(GetClientRect(), &CDC);
	    }
	    else
	    {
		    //start zooming action
		    m_nDrawingState = enumGISMapZooming;
            if(m_pGISDisplay)
                m_pGISDisplay->SetDeviceFrame(rc);
			m_timer.Start(TM_ZOOMING);
        }
    }
    else
    {
        if(m_pGISDisplay)
            m_pGISDisplay->SetDeviceFrame(rc);
    }

	UpdateFrameCenter();
	//wxWakeUpIdle();
    m_PrevSize = event.GetSize();

}
예제 #13
0
파일: mapview.cpp 프로젝트: jacklibj/r5
wxGISMapView::wxGISMapView(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxScrolledWindow(parent, id, pos, size, style | wxHSCROLL | wxVSCROLL )/*| wxSTATIC_BORDER | wxBORDER_NONEwxBORDER_SUNKEN*/, wxGISMap(), m_pTrackCancel(NULL), m_pThread(NULL), m_pAni(NULL), m_timer(this, TIMER_ID)
{
	//set map init envelope

#if wxUSE_GRAPHICS_CONTEXT	
	pGISScreenDisplay = new wxGISScreenDisplayPlus();
#else
    pGISScreenDisplay = new wxGISScreenDisplay();
#endif
	m_pExtenStack = new ExtenStack(this);
	
	m_pTrackCancel = new ITrackCancel();
	m_pTrackCancel->Reset();

	IDisplayTransformation* pDisplayTransformation = pGISScreenDisplay->GetDisplayTransformation();
	pDisplayTransformation->SetDeviceFrame(GetClientRect());
	wxClientDC CDC(this);
	pDisplayTransformation->SetPPI(CDC.GetPPI());

	m_MouseState = enumGISMouseNone;
	m_MapToolState = enumGISMapNone;

}
예제 #14
0
파일: mapview.cpp 프로젝트: Mileslee/wxgis
void wxGISMapView::OnMouseWheel(wxMouseEvent& event)
{
	//event.Skip(false);
    DestroyDrawThread();

	int nDirection = event.GetWheelRotation();
	int nDelta = event.GetWheelDelta();
	int nFactor = nDirection / nDelta;
	m_nDrawingState = enumGISMapWheeling;

	m_nFactor += ZOOM_FACTOR * (double)nFactor;


	if(m_pGISDisplay)
	{
		double dZoom = 1;
		if(m_nFactor < 0)
			dZoom = fabs(1.0 / (m_nFactor - 1));
		else if(m_nFactor > 0)
			dZoom = 1 + m_nFactor;
        wxClientDC CDC(this);
		m_pGISDisplay->WheelingDraw(dZoom, &CDC);

		//draw scale text
		OGREnvelope Env = CreateEnvelopeFromZoomFactor(dZoom);
		if(Env.IsInit())
		{
			double sScale = GetScaleRatio( Env, CDC );
			wxString sFormatScale = NumberScale(sScale);
			sFormatScale.Prepend(wxT("1 : "));
			DrawToolTip(CDC, sFormatScale);
		}
	}

	//if(!m_timer.IsRunning())
		m_timer.Start(TM_WHEELING);
}
예제 #15
0
파일: rubberband.cpp 프로젝트: jacklibj/r5
void wxGISRubberEnvelope::OnMouseMove(wxMouseEvent& event)
{
	wxClientDC CDC(m_pWnd);
	m_pCachedDisplay->OnDraw(CDC);

	int EvX = event.GetX(), EvY = event.GetY();
	int width, height, X, Y;
	width = abs(EvX - m_StartX);
	height = abs(EvY - m_StartY);
	X = MIN(m_StartX, EvX);
	Y = MIN(m_StartY, EvY);

//#if wxUSE_GRAPHICS_CONTEXT	
//	wxGCDC GDC(CDC);
//	GDC.SetPen(m_pSymbol->GetPen());
//	GDC.SetBrush(m_pSymbol->GetBrush());
//	GDC.DrawRectangle(X, Y, width, height);
//#else
	CDC.SetPen(m_pSymbol->GetPen());
	CDC.SetBrush(wxBrush(m_pSymbol->GetBrush().GetColour(), wxTRANSPARENT));
	CDC.SetLogicalFunction(wxOR_REVERSE);
	CDC.DrawRectangle(X, Y, width, height);
//#endif
}
예제 #16
0
파일: mapview.cpp 프로젝트: jacklibj/r5
void wxGISMapView::OnMouseWheel(wxMouseEvent& event)
{
	event.Skip();

	m_pTrackCancel->Cancel();
	if(m_pThread)
		m_pThread->Delete();

	wxClientDC CDC(this);

	IDisplayTransformation* pDisplayTransformation = pGISScreenDisplay->GetDisplayTransformation();
	if(pDisplayTransformation)
	{
		if(!(m_MouseState & enumGISMouseWheel))
		{
			m_virtualrc = GetClientRect();
			m_virtualbounds = pDisplayTransformation->GetBounds();

			m_MouseState |= enumGISMouseWheel;
		}
		int direction = event.GetWheelRotation();
		int delta = event.GetWheelDelta();
		int factor = direction / delta;
		
		double world_zoom = ZOOM_FACTOR * (double)factor;


		//calc zoom dc
		int dx(0), dy(0);
		if(factor < 0)
		{
			dx = ((double)m_virtualrc.width * (world_zoom / (world_zoom - 1))) / -2;
			dy = ((double)m_virtualrc.height * (world_zoom / (world_zoom - 1))) / -2;
		}
		else
		{
			//dx = (double)m_virtualrc.width * (world_zoom) / (-2 * (1 + world_zoom));
			//dy = (double)m_virtualrc.height * (world_zoom) / (-2 * (1 + world_zoom));
			dx = ((double)m_virtualrc.width * (world_zoom)) / 2;
			dy = ((double)m_virtualrc.height * (world_zoom)) / 2;
		}

		m_virtualrc.Inflate(dx, dy);
		if(m_virtualrc.width <= 10 || m_virtualrc.height <= 10)
			return;

		m_virtualrc.CenterIn(GetClientRect());
		wxCoord x = m_virtualrc.x;
		wxCoord y = m_virtualrc.y;

		//calc zoom world
		double dwx(0), dwy(0);

		if(factor < 0)
		{
			dwx = (m_virtualbounds.MaxX - m_virtualbounds.MinX) * (world_zoom) / 2;
			dwy = (m_virtualbounds.MaxY - m_virtualbounds.MinY) * (world_zoom) / 2;
		}
		else
		{
			dwx = (m_virtualbounds.MaxX - m_virtualbounds.MinX) * (world_zoom) / (2 * (1 + world_zoom));
			dwy = (m_virtualbounds.MaxY - m_virtualbounds.MinY) * (world_zoom) / (2 * (1 + world_zoom));
		}

		m_virtualbounds.MaxX -= dwx;
		m_virtualbounds.MinX += dwx;
		m_virtualbounds.MaxY -= dwy;
		m_virtualbounds.MinY += dwy;


		wxClientDC CDC(this);

		if(!m_virtualrc.Contains(GetClientRect()))//(factor < 0)
			pGISScreenDisplay->OnStretchDraw(CDC, m_virtualrc.width, m_virtualrc.height, x, y, true, enumGISQualityBicubic/*enumGISQualityBilinear*/);
		else
		{
			wxRect client_rc = GetClientRect();
			wxRect rc = client_rc;
			rc.width = rc.width * rc.width / m_virtualrc.width;
			rc.height = rc.height * rc.height / m_virtualrc.height;
			rc.x = client_rc.x + (client_rc.width - rc.width) / 2;
			rc.y = client_rc.y + (client_rc.height - rc.height) / 2;
			pGISScreenDisplay->OnStretchDraw2(CDC, rc, false, enumGISQualityFourQuadBilinear);//enumGISQualityHalfBilinear//enumGISQualityHalfQuadBilinear//enumGISQualityNearest//
		}

		pDisplayTransformation->SetBounds(m_virtualbounds);
		//draw scale text
		double sc = pDisplayTransformation->GetScaleRatio();
		wxString format_s = NumberScale(sc);
		format_s.Prepend(wxT("1 : "));
		//wxString s = wxString::Format(_("1 : %.2f"), sc);
		//1 / (m_virtualbounds.MaxX - m_virtualbounds.MinX)/*pDisplayTransformation->GetScaleRatio()*/ * 243.84);
		wxSize size = GetClientSize();
		int width, height;

		CDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
		CDC.GetTextExtent(format_s, &width, &height);

		wxBrush br(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
		CDC.SetBrush(br);
		CDC.SetPen(*wxBLACK_PEN);
		int x1 = (size.x - width) / 2, y1 = (size.y - height) - 50/*/ 2*/;
		CDC.DrawRectangle( x1 - 5, y1 - 2, width + 10, height + 4);

		CDC.DrawText(format_s, x1, y1);

		////SetToolTip( //96 * 2.54
			//wxTipWindow* m_pTipWnd;
		//if(m_pTipWnd)
		//	wxDELETE(m_pTipWnd);

		//wxRect client_rc = GetScreenRect();
		//m_pTipWnd = new wxTipWindow(this, wxString::Format(_("1 : %.2f"), 1 / (m_virtualbounds.MaxX - m_virtualbounds.MinX)/*pDisplayTransformation->GetScaleRatio()*/ * 243.84), 200, &m_pTipWnd, &client_rc);
		//m_pTipWnd->Hide();		
		//wxPoint pt = client_rc.GetPosition();
		//pt.x += client_rc.width / 2 - m_pTipWnd->GetSize().GetWidth() * 1.5 ;
		//pt.y += client_rc.height / 2 - m_pTipWnd->GetSize().GetHeight() * 1.5;
		//m_pTipWnd->Position(pt,m_pTipWnd->GetSize());
		//m_pTipWnd->Show();
		//if(m_pTipWnd)
		//{
		//	wxDELETE(m_pTipWnd);
		//	m_pTipWnd = NULL;
		//}
		//, m_pTipWnd(NULL)

		m_timer.Start(WAITTIME);
	}
}