📄 rsimagestarview.cpp
字号:
m_pDoc->UpdateAllViews(NULL);
m_pDoc->SetModifiedFlag();
EndWaitCursor();
}
m_PreView=false;
}
void CRSImageStarView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDC *pDC;
pDC=new CDC;
pDC=GetDC();
OnPrepareDC(pDC);
int drawmode;
if(flagtime==0)
{
drawmode=pDC->GetROP2();
pDC->SetROP2(R2_NOTCOPYPEN);
}
CPen pen;
pen.CreatePen(PS_DOT,1,RGB(0,0,0));
CPen *oldpen=pDC->SelectObject(&pen);
pDC->SelectStockObject(NULL_BRUSH );
if(m_pDoc->pHead!=NULL)
{
m_pDoc->pTempPt=m_pDoc->pHead;
CPoint point,point1;
while(m_pDoc->pTempPt->next!=NULL)
{
point=m_pDoc->pTempPt->point;
DibToClient(point);
pDC->MoveTo(point);
point=m_pDoc->pTempPt->next->point;
DibToClient(point);
pDC->LineTo(point);
m_pDoc->pTempPt=m_pDoc->pTempPt->next;
}
point=m_pDoc->pTempPt->point;
DibToClient(point);
pDC->MoveTo(point);
point=m_pDoc->pHead->point;
DibToClient(point);
pDC->LineTo(point);
}
else if(m_DrawRect.Width()>=2)
{
CRect rect;
rect=m_DibRect;
DibToClient(rect);
CPoint pos;
switch(m_DrawType)
{
case SELECT:
pDC->Rectangle(rect);
break;
case OVAL:
pDC->Ellipse(rect);
break;
case ROUND:
pos.x=int(rect.Width()/5.0);
pos.y=int(rect.Height()/5.0);
pDC->RoundRect(rect,pos);
break;
case RECT:
pDC->Rectangle(rect);
break;
default:
return;
}
}
pDC->SelectObject(oldpen);
if(flagtime==0)
{
pDC->SetROP2(drawmode);
flagtime=1;
}
else
flagtime=0;
ReleaseDC(pDC);
CScrollView::OnTimer(nIDEvent);
}
void CRSImageStarView::OnFillcolor()
{
if(m_pDoc->curptr->pre==NULL)
{
CColorDialog dlgColor(m_crFillColor);
if (dlgColor.DoModal() == IDOK)
{
m_crFillColor = dlgColor.GetColor();
ShowFillColor();
}
}
}
void CRSImageStarView::OnPencolor()
{
if(m_pDoc->curptr->pre==NULL)
{
CColorDialog dlgColor(m_crPenColor);
if (dlgColor.DoModal() == IDOK)
{
m_crPenColor = dlgColor.GetColor();
ShowPenColor();
}
}
}
void CRSImageStarView::ShowPenColor()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
pAppFrame->m_wndPaintParamBar.ShowPenColor(m_crPenColor);
pAppFrame->m_wndMyDialogBar.SetButtonColor(m_crPenColor);
}
void CRSImageStarView::ShowFillColor()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
pAppFrame->m_wndPaintParamBar.ShowFillColor(m_crFillColor);
}
void CRSImageStarView::ClientToDib(CPoint& point)
{
point.x=int(point.x/m_fScale+0.5);
point.y=int(point.y/m_fScale+0.5);
}
void CRSImageStarView::ClientToDib(CRect& rect)
{
rect.left=int(rect.left/m_fScale+0.5);
rect.top=int(rect.top/m_fScale+0.5);
rect.right=int(rect.right/m_fScale+0.5);
rect.bottom=int(rect.bottom/m_fScale+0.5);
}
//从逻辑坐标点到图象坐标点的转换
void CRSImageStarView::DibToClient(CPoint& point)
{
point.x=int(point.x*m_fScale+0.5);
point.y=int(point.y*m_fScale+0.5);
}
//从逻辑坐标矩形到图象坐标矩形的转换
void CRSImageStarView::DibToClient(CRect& rect)
{
rect.left=int(rect.left*m_fScale+0.5);
rect.top=int(rect.top*m_fScale+0.5);
rect.right=int(rect.right*m_fScale+0.5);
rect.bottom=int(rect.bottom*m_fScale+0.5);
}
BOOL CRSImageStarView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
switch(m_ToolOption)
{
case PEN:
::SetCursor(m_Pen);
return true;
case ERASE:
::SetCursor(m_Erase);
return true;
case PICKER:
::SetCursor(m_Picker);
return true;
default:
break;
}
return CScrollView::OnSetCursor(pWnd, nHitTest, message);
}
int CRSImageStarView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CScrollView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_Pen = AfxGetApp()->LoadCursor(IDC_CURSORPEN);
m_Erase = AfxGetApp()->LoadCursor(IDC_CURSORERASE);
m_Picker= AfxGetApp()->LoadCursor(IDC_CURSORPIKER);
m_Cross = AfxGetApp()->LoadCursor(IDC_CURSORCROSS);
m_Text = AfxGetApp()->LoadCursor(IDC_CURSORTEXT);
m_Paint = AfxGetApp()->LoadCursor(IDC_CURSORPAINT);
return 0;
}
void CRSImageStarView::OnFillcolor1()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_FILL_COLOR)
OnFillcolor();
else
pAppFrame->m_wndPaintParamBar.SetSelectColorMode(PP_FILL_COLOR);
}
void CRSImageStarView::OnPencolor1()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_PEN_COLOR)
OnPencolor();
else
pAppFrame->m_wndPaintParamBar.SetSelectColorMode(PP_PEN_COLOR);
}
void CRSImageStarView::OnZoomIn(CPoint pos,BOOL flag)
{
// TODO: Add your command handler code here
if(m_fScale<0.002)
return;
if(!flag)
{
pos.x=m_ClientRect.Width()/2;
pos.y=m_ClientRect.Height()/2;
}
int width=m_ClientRect.Width();
int height=m_ClientRect.Height();
if(m_fScale>1.0)
{
m_fScale-=float(1.0);
}
else
m_fScale/=float(2.0);
CSize sizeTotal;
sizeTotal.cx=int(m_fSize.cx*m_fScale);
sizeTotal.cy=int(m_fSize.cy*m_fScale);
m_DrawRect = m_DibRect;
DibToClient(m_DrawRect);
pos.x=int(pos.x*m_fScale)-width/2;
if((pos.x+width)>sizeTotal.cx)
pos.x=0;
pos.y=int(pos.y*m_fScale)-height/2;
if((pos.y+height)>sizeTotal.cy)
pos.y=0;
if(pos.x<0)
pos.x=0;
if(pos.y<0)
pos.y=0;
SetScrollSizes(MM_TEXT, sizeTotal);
ScrollToPosition(pos);
CreateRgn();
Invalidate();
}
void CRSImageStarView::OnZoomOut(CPoint pos,BOOL flag)
{
if(!flag)
{
pos.x=m_ClientRect.Width()/2;
pos.y=m_ClientRect.Height()/2;
}
int width = m_ClientRect.Width();
int height= m_ClientRect.Height();
if(m_fScale>=1.0)
m_fScale+=float(1.0);
else
m_fScale*=float(2.0);
CSize sizeTotal;
sizeTotal.cx=int(m_fSize.cx*m_fScale);
sizeTotal.cy=int(m_fSize.cy*m_fScale);
if((sizeTotal.cx>32766)||(sizeTotal.cy>32766))
{
m_fScale-=float(1.0);
return;
}
m_DrawRect = m_DibRect;
DibToClient(m_DrawRect);
pos.x=int(pos.x*m_fScale)-width/2;
if((pos.x+width)>sizeTotal.cx)
pos.x=0;
pos.y=int(pos.y*m_fScale)-height/2;
if((pos.y+height)>sizeTotal.cy)
pos.y=0;
if(pos.x<0)
pos.x=0;
if(pos.y<0)
pos.y=0;
SetScrollSizes(MM_TEXT, sizeTotal);
ScrollToPosition(pos);
CreateRgn();
Invalidate(false);
}
void CRSImageStarView::AddPoint(CPoint pt)
{
m_pDoc->pTempPt=(struct Vertex *)malloc(sizeof(struct Vertex));
if(m_pDoc->pHead==NULL)
{
m_pDoc->pTempPt->next=NULL;
m_pDoc->pTempPt->pre=NULL;
m_pDoc->pTempPt->point=pt;
m_pDoc->pTempPt->num=0;
m_pDoc->pHead=m_pDoc->pCurPt=m_pDoc->pTempPt;
}
else
{
m_pDoc->pTempPt->next=NULL;
m_pDoc->pTempPt->pre=m_pDoc->pCurPt;
m_pDoc->pTempPt->point=pt;
m_pDoc->pTempPt->num=0;
m_pDoc->pCurPt->next=m_pDoc->pTempPt;
m_pDoc->pCurPt=m_pDoc->pTempPt;
}
}
void CRSImageStarView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//符号操作
if(m_symbol==2)
{
m_TextCurve=false;
CClientDC dc(this);
OnPrepareDC(&dc);
m_pDoc->curptr->dib->m_ReDraw=true;
CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
CPoint pos[200];
int xmin,ymin,xmax,ymax;
xmin=ymin= 100000;
xmax=ymax=-100000;
int i=0;
m_pDoc->pTempPt=m_pDoc->pHead;
while(m_pDoc->pTempPt!=NULL)
{
pos[i]=m_pDoc->pTempPt->point;
if(m_pDoc->pTempPt->point.x<xmin)
xmin=m_pDoc->pTempPt->point.x;
if(m_pDoc->pTempPt->point.x>xmax)
xmax=m_pDoc->pTempPt->point.x;
if(m_pDoc->pTempPt->point.y<ymin)
ymin=m_pDoc->pTempPt->point.y;
if(m_pDoc->pTempPt->point.y>ymax)
ymax=m_pDoc->pTempPt->point.y;
i++;
m_pDoc->pTempPt=m_pDoc->pTempPt->next;
}
m_DibRect.left=xmin;
m_DibRect.right=xmax;
m_DibRect.top=ymin;
m_DibRect.bottom=ymax;
m_DrawRect=m_DibRect;
DibToClient(m_DrawRect);
symbol.DrawPline(pDibDC,FileNameLine,pos,i);
m_pDoc->curptr->dib->EndPaint();
Invalidate(false);
return;
}
else if(m_symbol==3)
{
m_TextCurve=false;
CClientDC dc(this);
OnPrepareDC(&dc);
m_pDoc->curptr->dib->m_ReDraw=true;
CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
CPoint pos[200];
int xmin,ymin,xmax,ymax;
xmin=ymin= 100000;
xmax=ymax=-100000;
int i=0;
m_pDoc->pTempPt=m_pDoc->pHead;
while(m_pDoc->pTempPt!=NULL)
{
pos[i]=m_pDoc->pTempPt->point;
if(m_pDoc->pTempPt->point.x<xmin)
xmin=m_pDoc->pTempPt->point.x;
if(m_pDoc->pTempPt->point.x>xmax)
xmax=m_pDoc->pTempPt->point.x;
if(m_pDoc->pTempPt->point.y<ymin)
ymin=m_pDoc->pTempPt->point.y;
if(m_pDoc->pTempPt->point.y>ymax)
ymax=m_pDoc->pTempPt->point.y;
i++;
m_pDoc->pTempPt=m_pDoc->pTempPt->next;
}
m_DibRect.left=xmin;
m_DibRect.right=xmax;
m_DibRect.top=ymin;
m_DibRect.bottom=ymax;
m_DrawRect=m_DibRect;
DibToClient(m_DrawRect);
symbol.DrawArea(pDibDC,FileNameArea,pos,i);
m_pDoc->curptr->dib->EndPaint();
Invalidate(false);
return;
}
pos.x=-100;
if(m_ToolOption==POLYLINE)
{
m_PolyLine=false;
m_ToolOption=0;
CClientDC dc(this);
OnPrepareDC(&dc);
CPoint pt = point;
dc.DPtoLP(&pt);
CPen pen(m_nPenStyle, int(m_nPenWidth*m_fScale+0.5), RGB(0,0,0));
CPen* pOldPen = dc.SelectObject(&pen);
int nOldRop = dc.SetROP2(R2_NOTXORPEN);
dc.MoveTo(temppoint);
dc.LineTo(pt);
dc.SetROP2(nOldRop);
dc.SelectObject(&nOldRop);
CPen pen1(m_nPenStyle, m_nPenWidth, m_crPenColor);
ClientToDib(pt);
if(m_Poly)
{
CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
pOldPen = pDibDC->SelectObject(&pen1);
pDibDC->MoveTo(m_TempPoint);
pDibDC->LineTo(m_FirstPoint);
pDibDC->SelectObject(pOldPen);
m_pDoc->curptr->dib->EndPaint();
m_Poly=false;
}
int width=int(m_nPenWidth*m_fScale+3.5);
CRect rect;
if(m_TempPoint.x<m_FirstPoint.x)
{
rect.left=m_TempPoint.x-width;
rect.right=m_FirstPoint.x+width;
}
else
{
rect.left=m_FirstPoint.x-width;
rect.right=m_FirstPoint.x+width;
}
if(m_TempPoint.y<m_FirstPoint.y)
{
rect.top=m_TempPoint.y-width;
rect.bottom=m_FirstPoint.y+width;
}
else
{
rect.top=m_FirstPoint.y-width;
rect.bottom=m_TempPoint.y+width;
}
m_InValidateRect=true;
m_InVRect=rect;
DibToClient(m_InVRect);
dc.LPtoDP(m_InVRect);
InvalidateRect(m_InVRect,false);
}
if(m_ToolOption==CURVE)
{
int nOldRop;
m_DrawType=m_ToolOption;
m_TextCurve=false;
CPoint pt = point;
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&pt);
ClientToDib(pt);
pos=pt;
DibToClient(pos);
if(m_pDoc->pHead!=NULL)
{
nOldRop = dc.SetROP2(R2_NOTXORPEN);
temppoint=startpoint;
DibToClient(temppoint);
dc.MoveTo(temppoint);
dc.LineTo(pos);
dc.MoveTo(temppoint);
CPoint postemp=m_pDoc->pHead->point;
DibToClient(postemp);
dc.LineTo(postemp);
dc.SetROP2(nOldRop);
}
CPoint pos[200];
int i=0;
int xmin,ymin,xmax,ymax;
xmin=ymin= 100000;
xmax=ymax=-100000;
m_pDoc->pTempPt=m_pDoc->pHead;
while(m_pDoc->pTempPt!=NULL)
{
pos[i]=m_pDoc->pTempPt->point;
if(m_pDoc->pTempPt->point.x<xmin)
xmin=m_pDoc->pTempPt->point.x;
if(m_pDoc->pTempPt->point.x>xmax)
xmax=m_pDoc->pTempPt->point.x;
if(m_pDoc->pTempPt->point.y<ymin)
ymin=m_pDoc->pTempPt->point.y;
if(m_pDoc->pTempPt->point.y>ymax)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -