📄 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表示线的条数
{
RECT rect;
rect.bottom=450;///// 无效区域 (背景区域)
rect.left=100;
rect.right=740;
rect.top=0;
HBRUSH hbrush; //擦除背景区域
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() //删除所有的点
{
if(vecpoint.size()<=0)
{ return; }
vecpoint.clear();
return;
}
//////////////// 找到该点 是否有所在区域的值 /////////////////////////
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); //获得该点附近的点
temppoint.x=point.x+n;
temppoint.y=point.y+m;
vecroundpoint.push_back(temppoint); //获得该点附近的点
}
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);
}
///////////////// 在地图上画点或将地点上以存在的点从地图上删除 //////////////////////
void RoundMap::DrawPonit( HWND hwnd ,const POINT& point) //在地图上画点(参数为实际位置)
{
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)//将地图上已存在的点(参数为实际位置)重画
{
int n=vecpoint.size();
SubPoint(point);
if(n==vecpoint.size()) //在其他地区(60个之外 )点击右键则向量大小不变
{ return;}
for(int n=0;n<vecpoint.size();n++) ///重画所有的点和地图
{ DrawPonit(hwnd,vecpoint[n] ); } // 1
return;
////// 以下为另一种擦除点的方法(可代替前面一对1之间的内容)/////
///////,可以减少修改的数目为一个,但在连线后无法删除线 ///
/*
hdc=GetDC(hwnd);
HBRUSH hbrush=CreateSolidBrush( RGB(255,255,255) );
SelectObject( hdc,hbrush ); //// 将该点刷为白色
Ellipse (hdc, (Drawpoint).x-5, (Drawpoint).y-5, (Drawpoint).x+5, (Drawpoint).y+5) ;
DeleteObject( hbrush );
SelectObject (hdc, GetStockObject (BLACK_PEN)) ; //在该点画椭圆
Ellipse (hdc, (Drawpoint).x-5, (Drawpoint).y-5, (Drawpoint).x+5, (Drawpoint).y+5) ; ;
ReleaseDC (hwnd, hdc);*/
}
/////////////////// 添加和减少点( 在地图位置)到向量 ///////////////////////
void RoundMap::AddPoint(const POINT& point) // 保存POINT(参数为实际位置)到向量
{
POINT temppoint,Drawpoint;
temppoint.x=-1;
temppoint.y=-1;
Drawpoint=FindAroundPoint(point);
if(Drawpoint.x==temppoint.x)//表示未找到点
{ return;}
if(find_if(vecpoint.begin(),vecpoint.end(),equal_point(Drawpoint))!=vecpoint.end())
{ return;} //保证点不重复
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);
}
//////////////////// 获得所有已点击的点的位置 ////////////////////
vector<POINT> RoundMap::GetAllClickPoint( )
{
return vecpoint;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -