📄 drawdemoview.cpp
字号:
curx+=tx;
if(d<0)
{
d+=inc1;
}
else
{
cury+=ty;
d+=inc2;
}
if(iTag)
{
//m_craGrids[curx][cury]=m_crCurColor;//Y first
SetGrid(cury, curx, m_crCurColor);
}
else
{
//m_craGrids[cury][curx]=m_crCurColor;//Y first, so swap cury and curx
SetGrid(curx, cury, m_crCurColor);
}
}
}
void CDrawDemoView::Swap(int& a, int& b)
{
int temp;
temp=a;
a=b;
b=temp;
}
int CDrawDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void CDrawDemoView::OnColorRed()
{
// TODO: Add your command handler code here
m_crCurColor=RGB(255,0,0);
m_bColorDark=0;
m_bColorRed=1;
m_bColorGreen=0;
m_bColorBlue=0;
m_bColorOther=0;
}
void CDrawDemoView::OnColorBlue()
{
// TODO: Add your command handler code here
m_crCurColor=RGB(0,0,255);
m_bColorDark=0;
m_bColorRed=0;
m_bColorGreen=0;
m_bColorBlue=1;
m_bColorOther=0;
}
void CDrawDemoView::OnColorGreen()
{
// TODO: Add your command handler code here
m_crCurColor=RGB(0,255,0);
m_bColorDark=0;
m_bColorRed=0;
m_bColorGreen=1;
m_bColorBlue=0;
m_bColorOther=0;
}
void CDrawDemoView::OnColorOther()
{
// TODO: Add your command handler code here
CColorDialog dlg;
if(dlg.DoModal()==1)
{
m_crCurColor=dlg.GetColor();
m_bColorDark=0;
m_bColorRed=0;
m_bColorGreen=0;
m_bColorBlue=0;
m_bColorOther=1;
}
}
void CDrawDemoView::OnUpdateColorGreen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bColorGreen);
}
void CDrawDemoView::OnUpdateColorOther(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bColorOther);
}
void CDrawDemoView::OnUpdateColorRed(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bColorRed);
}
void CDrawDemoView::OnUpdateColorBlue(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bColorBlue);
}
void CDrawDemoView::OnColorClear()
{
// TODO: Add your command handler code here
bmp.DeleteObject();
bmp.LoadBitmap(IDB_MAP);
dcMemory.SelectObject(&bmp);
DrawGrid(&dcMemory);
Invalidate();
}
void CDrawDemoView::OnOpLine()
{
// TODO: Add your command handler code here
m_bOpNull=0;
m_bOpLine=1;
m_bOpCurve=0;
m_bOpCircle=0;;
m_bOpRectangle=0;
m_bOpFill=0;
}
void CDrawDemoView::SetGrid(int x, int y, COLORREF color)
{
if(x>=0 && x<m_nMapWidth &&
y>=0 && y<m_nMapHeight)
{
tempPoint.x=x;
tempPoint.y=y;
pointList.AddTail(tempPoint);
}
}
void CDrawDemoView::BresCircle(int x0, int y0, int r)
{
int x, y, d;
x=0;
y=r;
d=3-2*r;
while(x<y)
{
CirPot(x0, y0, x, y);
if(d<0)
d+=4*x+6;
else
{
d+=4*(x-y)+10;
y--;
}
x++;
}
if(x==y)
CirPot(x0, y0, x, y);
}
void CDrawDemoView::CirPot(int x0, int y0, int x, int y)
{
SetGrid(x0+x, y0+y, m_crCurColor);
SetGrid(x0+y, y0+x, m_crCurColor);
SetGrid(x0+y, y0-x, m_crCurColor);
SetGrid(x0+x, y0-y, m_crCurColor);
SetGrid(x0-x, y0-y, m_crCurColor);
SetGrid(x0-y, y0-x, m_crCurColor);
SetGrid(x0-y, y0+x, m_crCurColor);
SetGrid(x0-x, y0+y, m_crCurColor);
}
void CDrawDemoView::OnColorDark()
{
// TODO: Add your command handler code here
m_crCurColor=RGB(0,0,0);
m_bColorDark=1;
m_bColorRed=0;
m_bColorGreen=0;
m_bColorBlue=0;
m_bColorOther=0;
}
void CDrawDemoView::OnUpdateColorDark(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bColorDark);
}
void CDrawDemoView::OnOpCircle()
{
// TODO: Add your command handler code here
m_bOpNull=0;
m_bOpLine=0;
m_bOpCurve=0;
m_bOpCircle=1;
m_bOpRectangle=0;
m_bOpFill=0;
}
void CDrawDemoView::OnUpdateOpCircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bOpCircle);
}
void CDrawDemoView::OnUpdateOpCurve(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bOpCurve);
}
void CDrawDemoView::OnOpFill()
{
// TODO: Add your command handler code here
//MessageBox("No function in this version!");
//return;
m_bOpNull=0;
m_bOpLine=0;
m_bOpCurve=0;
m_bOpCircle=0;;
m_bOpRectangle=0;
m_bOpFill=1;
}
void CDrawDemoView::OnUpdateOpFill(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bOpFill);
}
void CDrawDemoView::OnUpdateOpLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bOpLine);
}
void CDrawDemoView::OnOpNull()
{
// TODO: Add your command handler code here
m_bOpNull=1;
m_bOpLine=0;
m_bOpCurve=0;
m_bOpCircle=0;;
m_bOpRectangle=0;
m_bOpFill=0;
}
void CDrawDemoView::OnUpdateOpNull(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bOpNull);
}
void CDrawDemoView::OnOpRectangle()
{
// TODO: Add your command handler code here
m_bOpNull=0;
m_bOpLine=0;
m_bOpCurve=0;
m_bOpCircle=0;;
m_bOpRectangle=1;
m_bOpFill=0;
}
void CDrawDemoView::OnUpdateOpRectangle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bOpRectangle);
}
void CDrawDemoView::Rectangle(int x1, int y1, int x2, int y2)
{
int temp;
if(x1>x2)
Swap(x1, x2);
if(y1>y2)
Swap(y1, y2);
for(temp=x1;temp<=x2;temp++)
{
SetGrid(temp, y1, m_crCurColor);
SetGrid(temp, y2, m_crCurColor);
}
for(temp=y1;temp<=y2;temp++)
{
SetGrid(x1, temp, m_crCurColor);
SetGrid(x2, temp, m_crCurColor);
}
}
void CDrawDemoView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
MessageBox("Timer!"); //Just a test.
CView::OnTimer(nIDEvent);
}
COLORREF CDrawDemoView::GetColor(int x, int y)
{
COLORREF tmpColor;
int gridX, gridY;
gridX=m_rtMapRect.left+m_nGridWidth*x+m_nGridWidth/2;
gridY=m_rtMapRect.top +m_nGridWidth*y+m_nGridWidth/2;
tmpColor=dcMemory.GetPixel(CPoint(gridX, gridY));
return tmpColor;
}
void CDrawDemoView::FillArea(int x, int y, COLORREF oldColor, COLORREF newColor)
{
if(newColor==oldColor)
return;
int px[1000],py[1000],xsave,xleft,xright,np=0;
px[np]=x;
py[np]=y;
while(np>-1)
{
y=py[np];
x=xsave=px[np];
np--;
while(GetColor(x, y)==oldColor && x<MAPWIDTH)
{
FillGrid(&dcMemory, x, y, newColor);
x++;
}
xright=x;
x=xsave-1;
while(GetColor(x, y)==oldColor && x>=0)
{
FillGrid(&dcMemory, x, y, newColor);
x--;
}
xleft=x;
y++;
if(y<MAPHEIGHT)
while(x<xright)
{
while(++x<xright && GetColor(x, y)!=oldColor)
;
if(x==xright)
break;
while(++x<xright && GetColor(x, y)==oldColor)
;
np++;
px[np]=x;
py[np]=y;
}
x=xleft;
y-=2;
if(y>=0)
while(x<xright)
{
while(++x<xright && GetColor(x, y)!=oldColor)
;
if(x==xright)
break;
while(++x<xright && GetColor(x, y)==oldColor)
;
np++;
px[np]=x;
py[np]=y;
}
}
return;
}
void CDrawDemoView::OnUpdateTimeStep(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bIfStep);
}
void CDrawDemoView::OnUpdateTimeImme(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(!m_bIfStep);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -