📄 grdemoview.cpp
字号:
m_pGraph = &m_XLogYLog;
if (!m_pGraph->SetRange(1, 1, 100, 100))
{
m_bCanDraw = FALSE;
MessageBox("Setting Range failed");
return;
}
Redraw();
}
void CGrDemoView::OnUpdateTypeXlogylog(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_pGraph == &m_XLogYLog);
}
void CGrDemoView::OnTypeGrid()
{
m_bGrid = !m_bGrid;
Redraw();
}
void CGrDemoView::OnUpdateTypeGrid(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bGrid);
}
void CGrDemoView::OnTypeBoundary()
{
m_bBoundary = !m_bBoundary;
Redraw();
}
void CGrDemoView::OnUpdateTypeBoundary(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bBoundary);
}
void CGrDemoView::OnTypeLegend()
{
m_bLegend = !m_bLegend;
m_pGraph->EnableLegend(m_bLegend);
Redraw();
}
void CGrDemoView::OnUpdateTypeLegend(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bLegend);
}
void CGrDemoView::OnTypeBackcolor()
{
// CColorDialog bug under the debug version
CColorDialog cDlg(m_nBkColor);
if (cDlg.DoModal() == IDOK)
{
m_nBkColor = cDlg.GetColor();
m_pGraph->SetBackColor(m_nBkColor);
Redraw();
}
}
void CGrDemoView::OnUpdateTypeBackcolor(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CGrDemoView::OnTypeTitle()
{
m_bTitle = !m_bTitle;
Redraw();
}
void CGrDemoView::OnUpdateTypeTitle(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bTitle);
}
void CGrDemoView::OnTypeMemorydraw()
{
m_bMemDraw = !m_bMemDraw;
m_pGraph->EnableMemoryDraw(m_bMemDraw);
Redraw();
}
void CGrDemoView::OnUpdateTypeMemorydraw(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bMemDraw);
}
void CGrDemoView::OnMaps1map()
{
m_nMaps = MAP1;
Redraw();
}
void CGrDemoView::OnUpdateMaps1map(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_nMaps != MAP1);
}
void CGrDemoView::OnMaps2maps()
{
m_nMaps = MAPS2;
Redraw();
}
void CGrDemoView::OnUpdateMaps2maps(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_nMaps != MAPS2);
}
void CGrDemoView::OnMaps4maps()
{
m_nMaps = MAPS4;
Redraw();
}
void CGrDemoView::OnUpdateMaps4maps(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_nMaps != MAPS4);
}
void CGrDemoView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CRect rect;
GetClientRect(&rect);
CSize sizeTotal = CSize(rect.right-rect.left, rect.bottom-rect.top);
SetScaleToFitSize(sizeTotal);
// this demo only support MM_TEXT mode
ASSERT(m_nMapMode == MM_TEXT);
}
void CGrDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
if (m_ZoomDrag == RECTZOOMIN)
{
c_down = point;
c_last = point;
Zoom_in_First = point; //保存矩形区域的左上角坐标
SetCapture(); //设置输入焦点
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENWSE));
}
else if (m_ZoomDrag == DRAG)
{
sPT = point;
SetCapture();
SetCursor(::LoadCursor(NULL, IDC_SIZEALL));
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CGrDemoView::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
CTPoint<float> pt = m_pGraph->GetTValue(point);
m_nCoord.Format("(%8.3f, %8.3f)", pt.x, pt.y );
//Now, show (x, y) coordinates in the statu bar
((CMainFrame*)(AfxGetApp()->m_pMainWnd))->m_wndStatusBar.SetPaneText(1, (LPCTSTR)m_nCoord);
if (GetCapture() != this)
return;
if (m_ZoomDrag == RECTZOOMIN)
{
CRect rect(c_down.x, c_down.y, c_last.x, c_last.y);
rect.NormalizeRect();
dc.DrawFocusRect(rect);
rect.SetRect(c_down.x, c_down.y, point.x, point.y);
rect.NormalizeRect();
dc.DrawFocusRect(rect);
c_last = point;
}
else if (m_ZoomDrag == DRAG)
{
}
CScrollView::OnMouseMove(nFlags, point);
}
void CGrDemoView::OnLButtonUp(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
ReleaseCapture(); //释放鼠标输入焦点
//如果矩形区域的面积等于零, 矩形缩放无效, 立即返回
if (m_ZoomDrag == RECTZOOMIN)
{
Zoom_in_Last = point; //保存矩形区域的右下角坐标
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); //改变鼠标光标状态
if ((Zoom_in_Last.x != Zoom_in_First.x) &&
(Zoom_in_Last.y != Zoom_in_First.y))
{
CRect rect;
GetWindowRect(&rect);
float tX_ini = (int)(1.0f * (rect.right - rect.left) /
(abs(Zoom_in_Last.x - Zoom_in_First.x)));
float tY_ini = (int)(1.0f * (rect.bottom - rect.top) /
(abs(Zoom_in_Last.y - Zoom_in_First.y)));
if (tX_ini > 30 || tY_ini > 30 || tX_ini < 0.3 || tY_ini < 0.3)
{
CScrollView::OnLButtonUp(nFlags, point);
return;
}
m_fXScale *= tX_ini;
m_fYScale *= tY_ini;
if (m_fXScale > 30)
m_fXScale = 30;
if (m_fYScale > 30)
m_fYScale = 30;
CSize size = GetTotalSize();
if((size.cx * m_fXScale) > 32767)
size.cx = 32767;
else
size.cx = (int)(size.cx * m_fXScale);
if((size.cy * m_fYScale) > 32767)
size.cy = 32767;
else
size.cy = (int)(size.cy * m_fYScale);
SetScrollSizes(m_nMapMode, size);
MidPoint.x = (int)(Zoom_in_First.x * m_fXScale);
MidPoint.y = (int)(Zoom_in_First.y * m_fYScale);
ScrollToPosition(MidPoint);
Redraw();
}
}
else if (m_ZoomDrag == DRAG)
{
SetCursor(::LoadCursor(NULL, IDC_ARROW));
CPoint pt = point - sPT;
CPoint pt1 = GetScrollPosition();
CPoint pt2 = pt1 - pt;
ScrollToPosition(pt2);
Redraw();
}
CScrollView::OnLButtonUp(nFlags, point);
}
void CGrDemoView::OnZoomRandom()
{
CZoomDlg zoomdlg;
zoomdlg.m_nXzoom = m_fXScale;
zoomdlg.m_nYzoom = m_fYScale;
if (zoomdlg.DoModal() == IDOK)
{
CRect rect;
GetClientRect(rect);
CSize size = rect.Size();
float xZoom = zoomdlg.m_nXzoom;
float yZoom = zoomdlg.m_nYzoom;
if ((size.cx * xZoom) > 32767)
size.cx = 32767;
else
size.cx = (int)(size.cx * xZoom);
if ((size.cy * yZoom) > 32767)
size.cy = 32767;
else
size.cy = (int)(size.cy * yZoom);
m_fXScale = zoomdlg.m_nXzoom;
m_fYScale = zoomdlg.m_nYzoom;
SetScrollSizes(m_nMapMode, size);
Redraw();
}
}
void CGrDemoView::OnUpdateZoomRandom(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CGrDemoView::OnZoomRectangle()
{
m_ZoomDrag = RECTZOOMIN;
}
void CGrDemoView::OnUpdateZoomRectangle(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_ZoomDrag == RECTZOOMIN);
}
void CGrDemoView::OnZoomDrag()
{
m_ZoomDrag = DRAG;
}
void CGrDemoView::OnUpdateZoomDrag(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_ZoomDrag == DRAG);
if (fabs(m_fXScale - 1) < 0.000001 && fabs(m_fYScale - 1) < 0.000001)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}
void CGrDemoView::OnZoomIn()
{
if (m_fXScale >= 30 && m_fYScale >= 30)
return;
m_ZoomDrag = ZOOMIN;
CSize size = GetTotalSize();
size.cx = (int)(size.cx * m_fDelta);
size.cy = (int)(size.cy * m_fDelta);
m_fXScale *= m_fDelta;
m_fYScale *= m_fDelta;
SetScrollSizes(m_nMapMode, size);
Redraw();
}
void CGrDemoView::OnUpdateZoomIn(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_ZoomDrag == ZOOMIN);
if (m_fXScale >= 30 && m_fYScale >= 30)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}
void CGrDemoView::OnZoomOut()
{
CSize size = GetTotalSize();
CRect rect;
GetClientRect(rect);
int width = rect.Width();
int height = rect.Height();
if (size.cx <= rect.Width() && size.cy <= rect.Height())
return;
m_ZoomDrag = ZOOMOUT;
if (width < size.cx)
{
size.cx = (int)(size.cx / m_fDelta);
m_fXScale /= m_fDelta;
}
if (height < size.cy)
{
size.cy = (int)(size.cy / m_fDelta);
m_fYScale /= m_fDelta;
}
if (size.cx <= rect.Width())
{
size.cx = rect.Width();
m_fXScale = 1.0f;
}
if (size.cy <= rect.Height())
{
size.cy = rect.Height();
m_fYScale = 1.0f;
}
SetScrollSizes(m_nMapMode, size);
Redraw();
}
void CGrDemoView::OnUpdateZoomOut(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_ZoomDrag == ZOOMOUT);
CRect rect;
GetClientRect(rect);
CSize size = GetTotalSize();
int width = rect.Width();
int height = rect.Height();
if (size.cx <= rect.Width() && size.cy <= rect.Height())
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}
void CGrDemoView::OnZoomNone()
{
m_ZoomDrag = NONE;
}
void CGrDemoView::OnUpdateZoomNone(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_ZoomDrag == NONE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -