代码拉取完成,页面将自动刷新
// MapView.cpp : ʵļ
//
#include "stdafx.h"
#include "TurboMir.h"
#include "MapView.h"
#include ".\mapview.h"
#include ".\wilfile.h"
// CMapView
IMPLEMENT_DYNAMIC(CMapView, CWnd)
CMapView::CMapView(CGameMir& game)
: m_Game(game)
, m_DrawOk(false)
{
}
CMapView::~CMapView()
{
}
BEGIN_MESSAGE_MAP(CMapView, CWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_SIZE()
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_LBUTTONDOWN()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// CMapView Ϣ
int CMapView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
lpCreateStruct->style|=WS_HSCROLL|WS_VSCROLL;
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
SetTimer(0x815,500,NULL);
return 0;
}
void CMapView::OnPaint()
{
if( IsWindowVisible() && (m_LastMap!=m_Game.m_Map.get_MapName()) )
{
m_DrawOk=false;
AfxBeginThread(DrawMapThread,(LPVOID)this);
return;
}
CPaintDC dc(this); // device context for painting
int top = GetScrollPos(SB_VERT);
int left = GetScrollPos(SB_HORZ);
CRect rect;
GetClientRect(rect);
if ( m_DrawOk )
{
if ( m_W<rect.Width() )
{
dc.FillSolidRect(m_W,0,rect.Width()-m_W,rect.Height(),crChatBg);
}
if ( m_H<rect.Height() )
{
dc.FillSolidRect(0,m_H,rect.Width(),rect.Height()-m_H,crChatBg);
}
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&m_DC,left,top,SRCCOPY);
}
else
{
dc.FillSolidRect(rect,crChatBg);
}
CPen pen(PS_SOLID,2,crYellow);
CPen*oldPen=dc.SelectObject(&pen);
if (!m_Path.empty())
{
std::vector<POINT>::iterator pos=m_Path.begin();
dc.MoveTo(pos->x*1.5-left,pos->y-top);
while ( (++pos)!=m_Path.end() )
{
dc.LineTo(pos->x*1.5-left,pos->y-top);
}
}
CPen pen2(PS_SOLID,1,crFuchsia);
dc.SelectObject(&pen2);
dc.MoveTo(m_Game.GetSelfInfo().xx*1.5-15-left,m_Game.GetSelfInfo().yy-10-top);
dc.LineTo(m_Game.GetSelfInfo().xx*1.5+15-left,m_Game.GetSelfInfo().yy-10-top);
dc.LineTo(m_Game.GetSelfInfo().xx*1.5+15-left,m_Game.GetSelfInfo().yy+10-top);
dc.LineTo(m_Game.GetSelfInfo().xx*1.5-15-left,m_Game.GetSelfInfo().yy+10-top);
dc.LineTo(m_Game.GetSelfInfo().xx*1.5-15-left,m_Game.GetSelfInfo().yy-10-top);
dc.SelectObject(oldPen);
}
UINT CMapView::DrawMapThread( LPVOID pParam )
{
CMapView*self=(CMapView*)pParam;
self->m_LastMap=self->m_Game.m_Map.get_MapName();
DWORD w,h;
self->m_Game.m_Map.GetSize(w,h);
self->m_W=w*1.5;
self->m_H=h;
self->ResetScroll();
CClientDC dc(self);
CBitmap Bitmap1;
Bitmap1.CreateCompatibleBitmap(&dc, self->m_W, self->m_H);
self->m_DC.CreateCompatibleDC(&dc);
self->m_DC.SelectObject(&Bitmap1);
QWORD t1=timestamp();
DWORD old_w=w;
HDC hdc=self->m_DC.GetSafeHdc();
if ( self->m_Game.m_SettingMgr.ShowMiniMap)
if ( UIExtended::LoadBitmapWil("mmap",self->m_Game.m_DataManager.GetMiniMap(self->m_LastMap)-1,self->m_DC) )
goto LABEL_DRAW_OK;
self->m_DC.FillSolidRect(0,0,self->m_W,self->m_H,crMapNotFree);
while ((h--)!=0)
{
w=old_w;
while ((w--)!=0)
{
if( self->m_Game.m_Map.TestMap(w,h) )
{
SetPixel(hdc,w*1.5,h,crMapFree);
if ( (w&1)==1 )
SetPixel(hdc,w*1.5+1,h,crMapFree);
}
}
}
LABEL_DRAW_OK:
CGameMir::sMap*pMap;
self->m_Game.m_DataManager.GetMap(self->m_LastMap,&pMap);
if(pMap!=NULL)
{
for(CGameMir::tDoorLinkList::iterator pos=pMap->DoorLinks.begin();pos!=pMap->DoorLinks.end();pos++)
{
self->m_DC.FillSolidRect(pos->source.pos.x*1.5,pos->source.pos.y-1,3,3,crRed);
}
}
QWORD t2=timestamp();
self->m_DrawOk=true;
self->Invalidate(FALSE);
return 0;
}
void CMapView::OnTimer(UINT nIDEvent)
{
//if((nIDEvent==0x815) && IsWindowVisible() && (m_LastMap!=m_Game.m_Map.get_MapName()))
//{
// m_DrawOk=false;
// AfxBeginThread(DrawMapThread,(LPVOID)this);
//}
CWnd::OnTimer(nIDEvent);
}
void CMapView::ResetScroll(void)
{
DWORD w,h;
m_Game.m_Map.GetSize(w,h);
m_W=w*1.5;
m_H=h;
CRect rect;
GetClientRect(rect);
if(!((rect.Width()>0)&&(rect.Height()>0)))return;
SCROLLINFO si;
ZeroMemory(&si,sizeof(SCROLLINFO));
si.cbSize=sizeof(SCROLLINFO);
si.fMask=SIF_ALL;
si.nMax=w*1.5-1;
si.nPage=rect.Width();
SetScrollInfo(SB_HORZ,&si);
ZeroMemory(&si,sizeof(SCROLLINFO));
si.cbSize=sizeof(SCROLLINFO);
si.fMask=SIF_ALL;
si.nMax=h-1;
si.nPage=rect.Height();
SetScrollInfo(SB_VERT,&si);
}
void CMapView::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
ResetScroll();
}
void CMapView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// Get the minimum and maximum scroll-bar positions.
int minpos;
int maxpos;
GetScrollRange(SB_HORZ,&minpos, &maxpos);
// Get the current position of scroll box.
int curpos = GetScrollPos(SB_HORZ);
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_LEFT: // Scroll to far left.
curpos = minpos;
break;
case SB_RIGHT: // Scroll to far right.
curpos = maxpos;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINELEFT: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINERIGHT: // Scroll right.
if (curpos < maxpos)
curpos++;
break;
case SB_PAGELEFT: // Scroll one page left.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_HORZ,&info, SIF_ALL);
if (curpos > minpos)
curpos = max(minpos, curpos - (int) info.nPage);
}
break;
case SB_PAGERIGHT: // Scroll one page right.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_HORZ,&info, SIF_ALL);
if (curpos < maxpos)
curpos = min(maxpos, curpos + (int) info.nPage);
}
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = nPos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
SetScrollPos(SB_HORZ,curpos);
CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
Invalidate();
}
void CMapView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// Get the minimum and maximum scroll-bar positions.
int minpos;
int maxpos;
GetScrollRange(SB_VERT,&minpos, &maxpos);
// Get the current position of scroll box.
int curpos = GetScrollPos(SB_VERT);
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_TOP: // Scroll to far left.
curpos = minpos;
break;
case SB_BOTTOM: // Scroll to far right.
curpos = maxpos;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINEUP: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINEDOWN: // Scroll right.
if (curpos < maxpos)
curpos++;
break;
case SB_PAGEUP: // Scroll one page left.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_VERT,&info, SIF_ALL);
if (curpos > minpos)
curpos = max(minpos, curpos - (int) info.nPage);
}
break;
case SB_PAGEDOWN: // Scroll one page right.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_VERT,&info, SIF_ALL);
if (curpos < maxpos)
curpos = min(maxpos, curpos + (int) info.nPage);
}
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = nPos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
SetScrollPos(SB_VERT,curpos);
CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
Invalidate();
}
void CMapView::OnLButtonDown(UINT nFlags, CPoint point)
{
CString str;
str.Format("%d,%d",(point.x*2)/3,point.y);
MessageBox(str);
SetFocus();
CWnd::OnLButtonDown(nFlags, point);
}
BOOL CMapView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CMapView::SetPath(std::vector<POINT> path)
{
m_Path=path;
Invalidate();
}
void CMapView::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd::OnMouseMove(nFlags, point);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。