📄 ippsdemoview.cpp
字号:
int CippsDemoView::GetZero() { return getSpaceHeight() + GetMaxPixel();}
int CippsDemoView::GetZeroIm() {
return getSpaceHeight() + getSpaceCplxHeight() +
GetMaxPixel()*2 - GetMinPixel();
}
int CippsDemoView::GetY0(int zero) { return zero - GetMinPixel();}
int CippsDemoView::GetY1(int zero) { return zero - GetMaxPixel();}
void CippsDemoView::SelectPenSignal(CDC* pDC)
{
m_Pen.DeleteObject();
m_Pen.CreatePen(PS_SOLID, 1, m_colorSignal);
pDC->SelectObject(&m_Pen);
}
void CippsDemoView::SelectPenAxis(CDC* pDC)
{
m_Pen.DeleteObject();
m_Pen.CreatePen(PS_SOLID, 1, m_colorAxis);
pDC->SelectObject(&m_Pen);
pDC->SetTextColor(m_colorAxis);
pDC->SetBkColor(m_colorAxisBack);
}
void CippsDemoView::DrawReal(CDC* pDC)
{
DrawBackReal(pDC);
int zero = GetZero();
DrawFrame(pDC, zero);
int i;
for (i=0; i < m_numPoints; i++)
m_points[i].y += zero;
SelectPenSignal(pDC);
pDC->Polyline(m_points,m_numPoints);
SelectPenAxis(pDC);
DrawAxisX(pDC,zero);
DrawAxisY(pDC,zero);
for (i=0; i < m_numPoints; i++)
m_points[i].y -= zero;
}
void CippsDemoView::DrawComplex(CDC* pDC)
{
DrawBackComplex(pDC);
CippsDemoDoc *pDoc = GetDoc();
int zero = GetZero();
int zeroIm = GetZeroIm();
DrawFrame(pDC, zero);
DrawFrame(pDC, zeroIm);
int i;
for (i=0; i < m_numPoints; i++) {
m_points [i].y += zero;
m_pointsIm[i].y += zeroIm;
}
SelectPenSignal(pDC);
pDC->Polyline(m_points,m_numPoints);
pDC->Polyline(m_pointsIm,m_numPoints);
SelectPenAxis(pDC);
DrawAxisX(pDC,zero);
DrawAxisX(pDC,zeroIm, FALSE);
DrawAxisY(pDC,zero);
DrawAxisY(pDC,zeroIm);
for (i=0; i < m_numPoints; i++) {
m_points [i].y -= zero;
m_pointsIm[i].y -= zeroIm;
}
}
void CippsDemoView::DrawFrame(CDC* pDC, int zero)
{
int x0 = GetX0();
int x1 = GetX1();
int y0 = GetY0(zero);
int y1 = GetY1(zero);
if (DEMO_APP->GetXAxis()) {
DrawLine(pDC, x0, y0, x1, y0);
DrawLine(pDC, x0, y1, x1, y1);
}
if (DEMO_APP->GetYAxis()) {
DrawLine(pDC, x0, y0, x0, y1);
DrawLine(pDC, x1, y0, x1, y1);
}
}
void CippsDemoView::DrawAxisX(CDC* pDC, int zero, BOOL bTopNumbers)
{
CippsDemoDoc *pDoc = GetDoc();
int len = pDoc->Length();
int w = (int)(len * pDoc->FactorW());
int x0 = GetX0();
int y0 = GetY0(zero);
int y1 = GetY1(zero);
double factor = pDoc->FactorW();
double step = GetStepAxis(getMinStepX()/pDoc->FactorW(), len);
double gap = step*pDoc->FactorW();
if (!DEMO_APP->GetXAxis()) return;
for (int i=1 ;; i++) {
int x = (int)(gap*i);
if (x > w) break;
DrawLabelX(pDC, x0 + x, y0, (int)(step*i + .5), SIDE_BOTTOM);
DrawLabelX(pDC, x0 + x, y1, (int)(step*i + .5), bTopNumbers ? SIDE_TOP : 0);
DrawGridLine(pDC, x0 + x, y0, x0 + x, y1);
}
}
static double minLabel(double min, double step)
{
double val = min >= 0 ? min : -min;
double lab = ((int)(val / step))*step;
if (min < 0) return -lab;
if (ABS(val - lab)/step < 1.e-2) return lab;
return lab + step;
}
void CippsDemoView::DrawAxisY(CDC* pDC, int zero)
{
CippsDemoDoc *pDoc = GetDoc();
double factorW = pDoc->FactorW();
double factorH = pDoc->FactorH();
double min, max;
GetMinMax(min,max);
double minStep = getMinStepY()/factorH;
if (!pDoc->Float()) minStep = MAX(minStep, 1);
double step = GetStepAxis(minStep, pDoc->Magnitude(min,max));
int h = (int)((max - min) * factorH);
int w = (int)(pDoc->Length() * factorW + .5);
int x0 = GetX0();
int x1 = GetX1();
double gap = step*factorH;
// pDC->FillSolidRect(0, 0, getSpaceWidth(), GetScaleHeight(), m_colorAxisBack);
// pDC->FillSolidRect(x1, 0, getSpaceWidth(), GetScaleHeight(), m_colorAxisBack);
if (!DEMO_APP->GetYAxis()) return;
ASSERT(h > 0);
double val = minLabel(min,step);
double yStart = val*factorH;
double yEnd = max*factorH + 1;
for (double y=yStart; y < yEnd; y += gap, val += step) {
if (ABS(val)/step < 1.e-3) val = 0;
int iy = (int)(y + .5);
DrawLabelY(pDC, x0, zero - iy, val, SIDE_LEFT);
DrawLabelY(pDC, x1, zero - iy, val, SIDE_RIGHT);
DrawGridLine(pDC, x0, zero - iy, x1, zero - iy);
}
}
void CippsDemoView::DrawGridLine(CDC* pDC, int x0, int y0, int x1, int y1)
{
if (DEMO_APP->GetGrid())
DrawLine(pDC, x0, y0, x1, y1);
}
void CippsDemoView::DrawLine(CDC* pDC, int x0, int y0, int x1, int y1, COLORREF clr)
{
if ((int)clr < 0)
clr = GetColorAxis();
CPen pen(PS_SOLID, 1, clr);
CPen* pOldPen = pDC->SelectObject(&pen);
CPoint p1(x0, y0);
CPoint p2(x1, y1);
pDC->MoveTo(p1);
pDC->LineTo(p2);
pDC->SelectObject(pOldPen);
}
void CippsDemoView::DrawLabelX(CDC* pDC, int x, int y, int val, int textSide,
COLORREF clr)
{
if ((int)clr < 0)
clr = GetColorAxis();
int halfLabel = 3;
DrawLine(pDC, x, y - halfLabel, x, y + halfLabel, clr);
if (!textSide) return;
pDC->SelectObject(&m_Font);
pDC->SetTextColor(clr);
CString text;
text.Format("%d",val);
CSize offset = pDC->GetTextExtent(text);
offset.cx = -offset.cx/2;
if (textSide == SIDE_TOP)
offset.cy = -offset.cy - halfLabel*2;
else
offset.cy = halfLabel*2;
pDC->TextOut(x + offset.cx, y + offset.cy, text);
}
void CippsDemoView::DrawLabelY(CDC* pDC, int x, int y, double val, int textSide,
COLORREF clr, BOOL bIntVal)
{
int halfLabel = 3;
DrawLine(pDC, x - halfLabel, y, x + halfLabel, y, clr);
if (!textSide) return;
pDC->SelectObject(&m_Font);
pDC->SetTextColor(clr);
CString text;
if (bIntVal)
text.Format("%d",(int)val);
else
text.Format("%.6g",val);
CSize offset = pDC->GetTextExtent(text);
if (textSide == SIDE_LEFT)
offset.cx = - offset.cx - halfLabel*2;
else
offset.cx = halfLabel*2;
offset.cy = -offset.cy/2;
pDC->TextOut(x + offset.cx, y + offset.cy, text);
}
void CippsDemoView::DrawLabelY(CDC* pDC, int x, int y, double val, int textSide)
{
BOOL bIntVal = TRUE;
if (GetDoc()->Float()) bIntVal = FALSE;
else if (GetDoc()->Depth() >= 32) {
if (ABS(val) > 999999) bIntVal = FALSE;
}
DrawLabelY(pDC, x, y, val, textSide, GetColorAxis(), bIntVal);
}
static int cDelta = 40;
static void dark(int& c)
{
c -= cDelta;
if (c < 0) c = 0;
}
static void light(int& c)
{
c += cDelta;
if (c > 255) c = 255;
}
static COLORREF darkColor(COLORREF clr)
{
int cRed = clr & 0x000000FF;
int cGreen = (clr & 0x0000FF00) >> 8;
int cBlue = (clr & 0x00FF0000) >> 16;
dark(cRed );
dark(cGreen);
dark(cBlue );
return RGB(cRed,cBlue,cGreen);
}
static COLORREF lightColor(COLORREF clr)
{
int cRed = clr & 0x000000FF;
int cGreen = (clr & 0x0000FF00) >> 8;
int cBlue = (clr & 0x00FF0000) >> 16;
light(cRed);
light(cGreen);
light(cBlue);
return RGB(cRed,cBlue,cGreen);
}
void CippsDemoView::DrawBackReal(CDC* pDC)
{
DrawBackAxis(pDC);
DrawBackSignal(pDC, GetZero());
}
void CippsDemoView::DrawBackComplex(CDC* pDC)
{
DrawBackAxis(pDC);
DrawBackSignal(pDC, GetZero());
DrawBackSignal(pDC, GetZeroIm());
}
void CippsDemoView::DrawBackAxis(CDC* pDC)
{
CBrush brush(m_colorAxisBack);
CRect rect(0, 0, GetScaleWidth(), GetScaleHeight());
pDC->FillRect(&rect,&brush);
}
void CippsDemoView::DrawBackSignal(CDC* pDC, int zero)
{
CBrush brush(m_colorSignalBack);
int left = GetX0();
int right = GetX1();
int top = GetY1(zero);
int bottom = GetY0(zero);
CRect rect(left,top,right,bottom);
pDC->FillRect(&rect,&brush);
/*
left--;
top--;
DrawLine(pDC, left, top, right, top, darkColor(m_colorAxisBack));
DrawLine(pDC, left, top, left, bottom, darkColor(m_colorAxisBack));
DrawLine(pDC, right, bottom, left, bottom, lightColor(m_colorAxisBack));
DrawLine(pDC, right, bottom, right, top, lightColor(m_colorAxisBack));
*/
}
void CippsDemoView::DrawBackground(CDC* pDC)
{
int gW = GetScaleWidth();
int gH = GetScaleHeight();
int cW = GetClientWidth();
int cH = GetClientHeight();
POINT points[6];
points[0].x = gW; points[0].y = gH;
points[1].x = gW; points[1].y = 0;
points[2].x = cW; points[2].y = 0;
points[3].x = cW; points[3].y = cH;
points[4].x = 0; points[4].y = cH;
points[5].x = 0; points[5].y = gH;
CPen pen(PS_NULL, 0, RGB(0,0,0));
CBrush brush(m_colorAxisBack);
pDC->SelectObject(&pen);
pDC->SelectObject(&brush);
pDC->Polygon(points,6);
}
/////////////////////////////////////////////////////////////////////////////
// CippsDemoView diagnostics
#ifdef _DEBUG
void CippsDemoView::AssertValid() const
{
CScrollView::AssertValid();
}
void CippsDemoView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CippsDemoView message handlers
void CippsDemoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
m_IsUpdated = TRUE;
Zoom();
}
void CippsDemoView::OnLButtonUp(UINT nFlags, CPoint point)
{
CippsDemoDoc *pDoc = GetDoc();
if (DEMO_APP->GetPickMode() && pDoc->MayBePicked()) {
DEMO_APP->GetDirector()->GrabDoc(pDoc);
}
CScrollView::OnLButtonUp(nFlags, point);
}
BOOL CippsDemoView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CippsDemoDoc *pDoc = GetDoc();
if (DEMO_APP->IsCursorWait()) return TRUE;
if (DEMO_APP->GetPickMode()) {
if (pDoc->MayBePicked()) {
DEMO_APP->SetCursorGrab();
MAIN_FRAME->SetMessageGrab();
return TRUE;
} else {
DEMO_APP->SetCursorPick();
MAIN_FRAME->SetMessagePick();
return TRUE;
}
} else {
return CScrollView::OnSetCursor(pWnd, nHitTest, message);
}
}
void CippsDemoView::OnRButtonDown(UINT nFlags, CPoint point)
{
UINT ident = (DEMO_APP->GetPickMode()) ? IDR_SIGNAL_P : IDR_SIGNAL;
ClientToScreen(&point);
CContextMenu cMenu;
cMenu.TrackPopup(ident, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -