?? roundmap.cpp
字號:
#include "roundmap.h"
RoundMap::RoundMap()
{
// do initialization stuff here
vector<POINT> point60(60);
int iallpoint[120]=
{
305,-21,324,-23,344 , -23 ,365 ,-19,384, -13, 402, -6,421, 4,437, 16 ,454 ,28,468 ,41,
482, 57, 493, 74,503, 93,509, 113, 515, 132, 518, 152,520,173,518, 193,514, 214,510,233,
501, 254,493, 271,481, 287,468,304, 456, 318, 439,329,422, 342,284, -16,263 ,-12,246, -4,
225, 3, 210, 17,194, 28,178, 42, 166, 56, 156, 74,145, 93,137, 112,133,131,129, 153,
127, 173,128,195,132, 213,137, 233,146 ,255, 155 ,272,165, 290,180, 307,194,318,208, 331,
227 ,343,244,352,265, 360,282 ,365,303 ,366, 326, 369,343, 368,368, 365,385, 360,404, 353
};
for(int n=0;n<60;n++)
{
point60[n].x=iallpoint[2*n];
point60[n].y=iallpoint[2*n+1];
}
for(int n=0;n<60;n++)
{
point60[n].x=point60[n].x+51;
point60[n].y=point60[n].y+51;
}
mappoint=point60;
}
////////////////////// 畫地圖 /////////////////////////
void RoundMap::DrawMap(HWND hwnd,HDC hdc ) ////n表示線的條數(shù)
{
RECT rect;
rect.bottom=450;///// 無效區(qū)域 (背景區(qū)域)
rect.left=100;
rect.right=740;
rect.top=0;
HBRUSH hbrush; //擦除背景區(qū)域
hbrush=CreateSolidBrush( RGB(255,255,255) );
FillRect(hdc,& rect, hbrush );
SelectObject (hdc, GetStockObject (BLACK_PEN)) ;
for(int n=0;n<60;n++)
{ Ellipse (hdc, mappoint[n].x-5, mappoint[n].y-5, mappoint[n].x+5, mappoint[n].y+5) ; }
}
////////////////////// 保存刪除POINT(在地圖位置)到向量/////////////////////////////
void RoundMap::SaveClickPoint()
{
fstream outFile( "copy.text", ios_base::out );
if ( !outFile )
{
cerr << "unable to open input file: "<< " -- bailing out!\n";
return ;
}
if(vecpoint.size()<=0)
{ return; }
outFile<<"#"<<"Round_Map_NAME"<<'\n'; ///以后有用
outFile<<"#"<<vecpoint.size()<<'\n';
for(int n=0;n<vecpoint.size();n++)
{
outFile<<vecpoint[n].x;
outFile<<" ";
outFile<<vecpoint[n].y;
outFile<<'\n';
}
return;
}
void RoundMap::DelAllPoint() //刪除所有的點(diǎn)
{
if(vecpoint.size()<=0)
{ return; }
vecpoint.clear();
return;
}
//////////////// 找到該點(diǎn) 是否有所在區(qū)域的值 /////////////////////////
POINT RoundMap::FindAroundPoint( const POINT& point)
{
vector< POINT> vecroundpoint;
POINT temppoint;
vector <POINT>::iterator Iter;
for(int n=-3;n<4;n++)
for(int m=3;m>-4;m--)
{
temppoint.x=point.x+m;
temppoint.y=point.y+n;
vecroundpoint.push_back(temppoint); //獲得該點(diǎn)附近的點(diǎn)
temppoint.x=point.x+n;
temppoint.y=point.y+m;
vecroundpoint.push_back(temppoint); //獲得該點(diǎn)附近的點(diǎn)
}
Iter=find_first_of(mappoint.begin(),mappoint.end(),vecroundpoint.begin(),vecroundpoint.end(),equal_point());
if(Iter==mappoint.end())
{
temppoint.x=-1;
temppoint.y=-1;
return temppoint;
}
return (*Iter);
}
///////////////// 在地圖上畫點(diǎn)或?qū)⒌攸c(diǎn)上以存在的點(diǎn)從地圖上刪除 //////////////////////
void RoundMap::DrawPonit( HWND hwnd ,const POINT& point) //在地圖上畫點(diǎn)(參數(shù)為實(shí)際位置)
{
HDC hdc;
POINT temppoint,Drawpoint;
temppoint.x=-1;
temppoint.y=-1;
Drawpoint=FindAroundPoint(point);
if(Drawpoint.x==temppoint.x&&Drawpoint.y==temppoint.y)
{ return;}
AddPoint( point );
hdc=GetDC( hwnd );
HBRUSH hbrush=CreateSolidBrush( RGB(255,0,0) );
SelectObject( hdc,hbrush );
Ellipse (hdc, (Drawpoint).x-5, (Drawpoint).y-5, (Drawpoint).x+5, (Drawpoint).y+5) ;
DeleteObject( hbrush );
ReleaseDC (hwnd, hdc);
}
void RoundMap::SmearPonit( HWND hwnd ,const POINT& point)//將地圖上已存在的點(diǎn)(參數(shù)為實(shí)際位置)重畫
{
int n=vecpoint.size();
SubPoint(point);
if(n==vecpoint.size()) //在其他地區(qū)(60個(gè)之外 )點(diǎn)擊右鍵則向量大小不變
{ return;}
for(int n=0;n<vecpoint.size();n++) ///重畫所有的點(diǎn)和地圖
{ DrawPonit(hwnd,vecpoint[n] ); } // 1
return;
////// 以下為另一種擦除點(diǎn)的方法(可代替前面一對1之間的內(nèi)容)/////
///////,可以減少修改的數(shù)目為一個(gè),但在連線后無法刪除線 ///
/*
hdc=GetDC(hwnd);
HBRUSH hbrush=CreateSolidBrush( RGB(255,255,255) );
SelectObject( hdc,hbrush ); //// 將該點(diǎn)刷為白色
Ellipse (hdc, (Drawpoint).x-5, (Drawpoint).y-5, (Drawpoint).x+5, (Drawpoint).y+5) ;
DeleteObject( hbrush );
SelectObject (hdc, GetStockObject (BLACK_PEN)) ; //在該點(diǎn)畫橢圓
Ellipse (hdc, (Drawpoint).x-5, (Drawpoint).y-5, (Drawpoint).x+5, (Drawpoint).y+5) ; ;
ReleaseDC (hwnd, hdc);*/
}
/////////////////// 添加和減少點(diǎn)( 在地圖位置)到向量 ///////////////////////
void RoundMap::AddPoint(const POINT& point) // 保存POINT(參數(shù)為實(shí)際位置)到向量
{
POINT temppoint,Drawpoint;
temppoint.x=-1;
temppoint.y=-1;
Drawpoint=FindAroundPoint(point);
if(Drawpoint.x==temppoint.x)//表示未找到點(diǎn)
{ return;}
if(find_if(vecpoint.begin(),vecpoint.end(),equal_point(Drawpoint))!=vecpoint.end())
{ return;} //保證點(diǎn)不重復(fù)
vecpoint.push_back(Drawpoint);
}
void RoundMap::SubPoint(const POINT& point)
{
POINT temppoint,Drawpoint;
vector <POINT>::iterator Iter;
temppoint.x=-1;
temppoint.y=-1;
Drawpoint=FindAroundPoint(point);
if(Drawpoint.x==temppoint.x)
{ return;}
Iter=remove_if(vecpoint.begin(),vecpoint.end(),equal_point( Drawpoint));
if( Iter==vecpoint.end( ))
{ return;}
vecpoint.erase(Iter);
}
//////////////////// 獲得所有已點(diǎn)擊的點(diǎn)的位置 ////////////////////
vector<POINT> RoundMap::GetAllClickPoint( )
{
return vecpoint;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -