📄 2dscale.cpp
字号:
/************************************************************************************************
// $Header: /home/cvsroot/SoccerDoctor/Chart/2DScale.cpp,v 1.4 2002/09/10 06:44:35 peter Exp $
//***********************************************************************************************
/************************************************************************************************/
/* */
/* File : 2DScale.cpp */
/* */
/* Purpose : interface for the Axis in the CChartCtrl */
/* */
/* Author : Scott Pelger Date Created: 10JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 10JUN02 initial version */
/* */
/************************************************************************************************/
#include "stdafx.h"
#include "2DScale.h"
#include "math.h"
C2DScale::C2DScale(BOOL bXAxis/*=TRUE*/, BOOL bYAxis/*=TRUE*/) :
m_bXAxis(bXAxis),m_bYAxis(bYAxis),m_dXMin(0),m_dXMax(10),m_dYMin(0),m_dYMax(10),
m_dPrevYMin(0),m_dPrevYMax(10),m_dMinorStepX(1),m_dMajorStepX(5),m_dMajorStepXDraw(5),
m_dMinorStepY(1),m_dMajorStepY(5),m_dMajorStepYDraw(5),m_dwXStyle(TICK_MAJOR|TICK_OUTSIDE|TICK_TEXT|GRAT_MAJOR|AXIS_BOTTOM),
m_dwYStyle(TICK_MAJOR|TICK_OUTSIDE|TICK_TEXT|GRAT_MAJOR|AXIS_LEFT),m_dwGenericStyle(NONE),
m_pRect(NULL),m_yDepth(30),m_dHorzRotation(30),m_dVertRotation(30),m_sXAxisText(), m_sYAxisText(),
m_FullRect(0, 0, 0, 0),m_sXAxisFormat("%f"),m_sYAxisFormat("%f"),m_bRemoved(FALSE),
m_LineColor(RGB(255, 255, 255)),m_ChartFillColor(RGB(255, 255, 255)+1) {
m_Pen.CreatePen(PS_SOLID, 1, m_LineColor);
}
C2DScale::~C2DScale() {
m_Pen.DeleteObject();
m_pRect = NULL;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::SetLineColor() */
/* */
/* Purpose : resets the color of the line */
/* */
/* Inputs : COLORREF LineColor -> new line color */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 11JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 11JUN02 initial version */
/* */
/************************************************************************************************/
void C2DScale::SetLineColor(COLORREF LineColor) {
m_Pen.DeleteObject();
m_Pen.CreatePen(PS_SOLID, 1, m_LineColor = LineColor);
}
/************************************************************************************************/
/* */
/* Function: C2DScale::DrawAxis() */
/* */
/* Purpose : draws all aspects of the axes */
/* */
/* Inputs : CDC* pDC -> the CDC to draw with */
/* CRect* pRect -> the confining rect to draw in, while this function executes the */
/* rect will be reduced in size to further limit data to the space defined by the axes */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* Scott Pelger 11JUN02 setting the text color */
/* */
/************************************************************************************************/
void C2DScale::DrawAxis(CDC* pDC, CRect* pRect) {
CPen* pOldPen = pDC->SelectObject(&m_Pen);
pDC->SelectObject(m_pFont);
if (*pRect==CRect(0, 0, 0, 0)) {
ASSERT(FALSE);
return;
}else {
m_pRect = pRect;
m_FullRect = *pRect;
m_pDC = pDC;
m_pDC->SetTextColor(m_LineColor);
}
if (DRAW&m_dwGenericStyle) {
WORD wMaxWidthXAxis(0);
WORD wMaxWidthYAxis(0);
int nXAxisOffset(0);
int nYAxisOffset(0);
CRect TickRectX(0, 0, 0, 0);
CRect TickRectY(0, 0, 0, 0);
_SetDrawingArea(wMaxWidthXAxis, wMaxWidthYAxis, nXAxisOffset, nYAxisOffset, &TickRectX, &TickRectY);
//fill the plot area
if (RGB(255, 255, 255)+1!=m_ChartFillColor) {
COLORREF BkColor = m_pDC->GetBkColor();
m_pDC->FillSolidRect(m_pRect, m_ChartFillColor);
m_pDC->SetBkColor(BkColor);
}
//draw all parts of the grid now
_DrawTickText(wMaxWidthXAxis, wMaxWidthYAxis, nXAxisOffset, nYAxisOffset, &TickRectX, &TickRectY);
_DrawAxis();
_DrawGraticules();
_DrawTickMarks();
}
pDC->SelectObject(pOldPen);
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_SetDrawingArea() */
/* */
/* Purpose : sets up the plot area rect based on the range of axis labels and axis text */
/* */
/* Inputs : WORD& wMaxWidthXAxis -> max width of the X axis text */
/* WORD& wMaxWidthYAxis -> max width of the X axis text */
/* int& nXAxisOffset -> offset due to axis text */
/* int& nYAxisOffset -> offset due to axis text */
/* CRect* pTickRectX -> bounding rect to draw in */
/* CRect* pTickRectY -> bounding rect to draw in */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 4JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 4JUN02 initial version */
/* */
/************************************************************************************************/
void C2DScale::_SetDrawingArea(WORD& wMaxWidthXAxis, WORD& wMaxWidthYAxis, int& nXAxisOffset, int& nYAxisOffset, CRect* pTickRectX, CRect* pTickRectY) {
double dStepX(m_dXMin);
double dStepY(m_dYMin);
CString TickText;
/****first, determine how tall the text will be as well as the widest label****/
while (dStepX<=m_dXMax) {
if (TYPE_STRIP_CHART&m_dwGenericStyle||
TYPE_STRIP_CHART_FILLED&m_dwGenericStyle) {
CTime TTime = (long)dStepX;
TickText = TTime.Format(m_sXAxisFormat);
}
else
TickText.Format(m_sXAxisFormat, dStepX);
pTickRectX->SetRectEmpty();
m_pDC->DrawText(TickText, pTickRectX, DT_CALCRECT);
wMaxWidthXAxis = wMaxWidthXAxis>pTickRectX->Width()?wMaxWidthXAxis:pTickRectX->Width();
if (TYPE_STRIP_CHART&m_dwGenericStyle||
TYPE_STRIP_CHART_FILLED&m_dwGenericStyle)
dStepX += 1;
else
dStepX += m_dMajorStepX;
}
while (dStepY<=m_dYMax) {
pTickRectY->SetRectEmpty();
TickText.Format(m_sYAxisFormat, dStepY);
m_pDC->DrawText(TickText, pTickRectY, DT_CALCRECT);
wMaxWidthYAxis = wMaxWidthYAxis>pTickRectY->Width()?wMaxWidthYAxis:pTickRectY->Width();
dStepY += m_dMajorStepY;
}
/****first, determine how tall the text will be as well as the widest label****/
/****now, readjust the rect to compensate for the needed space that the labels will occupy****/
if (m_dwYStyle&TICK_TEXT) {
if (m_dwYStyle&AXIS_LEFT) {
m_pRect->left += wMaxWidthYAxis + pTickRectY->Height();
m_pRect->right -= wMaxWidthXAxis/2;
}
else {
m_pRect->right -= wMaxWidthYAxis + pTickRectY->Height();
m_pRect->left += wMaxWidthXAxis/2;
}
}
else if (m_dwXStyle&TICK_TEXT) {
m_pRect->left += wMaxWidthXAxis/2;
m_pRect->right -= wMaxWidthXAxis/2;
}
/****now, readjust the rect to compensate for the needed space that the labels will occupy****/
_PrintAxisText(nXAxisOffset, nYAxisOffset);
/****now, adjust the top/bottom to compensate for x axis location****/
if (m_dwXStyle&AXIS_BOTTOM) {
m_pRect->bottom -= pTickRectX->Height()*2;
m_pRect->top += m_dwYStyle&TICK_TEXT?pTickRectY->Height():0;
}
else {
m_pRect->bottom -= m_dwYStyle&TICK_TEXT?pTickRectY->Height():0;
m_pRect->top += pTickRectX->Height()*2;
}
/****now, adjust the top/bottom to compensate for x axis location****/
int nLabels((int)((m_dXMax-m_dXMin)/m_dMajorStepX));
if (TYPE_STRIP_CHART&m_dwGenericStyle||
TYPE_STRIP_CHART_FILLED&m_dwGenericStyle) {
m_dMajorStepXDraw = 1;
nLabels = (int)((m_dXMax-m_dXMin)/m_dMajorStepXDraw);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -