📄 legendwnd.cpp
字号:
/************************************************************************************************
// $Header: /home/cvsroot/SoccerDoctor/Chart/LegendWnd.cpp,v 1.4 2002/09/10 06:44:35 peter Exp $
//***********************************************************************************************
/************************************************************************************************/
/* */
/* File : LegendWnd.cpp */
/* */
/* Purpose : interface for the legend window */
/* */
/* Author : Scott Pelger Date Created: 10JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 10JUN02 initial version */
/* */
/************************************************************************************************/
// LegendWnd.cpp : implementation file
//
#include "stdafx.h"
#include "LegendWnd.h"
/////////////////////////////////////////////////////////////////////////////
// CLegendWnd
CLegendWnd::CLegendWnd() : m_bShowPointLegend(TRUE), m_yAutoHideWidth(100), m_yAutoHideHeight(100) {}
CLegendWnd::~CLegendWnd() {Purge();}
BEGIN_MESSAGE_MAP(CLegendWnd, CChartWndBase)
//{{AFX_MSG_MAP(CLegendWnd)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLegendWnd message handlers
void CLegendWnd::OnPaint() {
CPaintDC dc(this);
GetClientRect(&m_rcClientRect);
dc.FillSolidRect(&m_rcClientRect, m_crWindowColor);
switch (m_eLegendPosition) {
case eLEFT :
case eRIGHT :
_ArrangeVertical();
break;
default :
_ArrangeHorizontal();
}
}
void CLegendWnd::SetAutoHide(BYTE yWidth, BYTE yHeight) {
m_yAutoHideWidth = yWidth>100?100:yWidth;
m_yAutoHideHeight = yHeight>100?100:yHeight;
}
/************************************************************************************************/
/* */
/* Function: CLegendWnd::_ArrangeVertical() */
/* */
/* Purpose : arranges the legend when this window is taller than it is wider */
/* */
/* Inputs : NONE */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 17MAY02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 17MAY02 initial version */
/* */
/************************************************************************************************/
void CLegendWnd::_ArrangeVertical() {
int nWidth(_GetWindowMaxWidth());
int nXDelta(nWidth/2);
int nHeight(_GetWindowMaxHeight());
int nYDelta(nHeight/2);
CPtrArray* pLegendList = _GetLegendList();
int nCnt(pLegendList->GetSize());
if (!nCnt||m_rcClientRect.IsRectEmpty())
return;
int nTotalHeight(0);
int nNumInCol(0);
for (int nCols(1);;nCols++) {
nNumInCol = nCnt/nCols + nCnt%nCols;
nTotalHeight = nHeight*nNumInCol + nYDelta*(nNumInCol-1);
if (nTotalHeight<m_rcClientRect.Height())
break;
}
CLegendText* pLegendText;
CRect Rect;
int nNumInRow(nCnt/nNumInCol + (nCnt%nNumInCol>0));
int nOffsetX((m_rcClientRect.Width()-nWidth*nNumInRow-nXDelta*(nNumInRow-1))/2);
int nX(nOffsetX);
int nOffsetY((m_rcClientRect.Height()-(nHeight*nNumInCol+nYDelta*(nNumInCol-1)))/2);
int nY(nOffsetY);
for (int l(0),i(0);i<nNumInRow;i++) {
for (int j(0);j<nNumInCol&&l<nCnt;j++,l++) {
pLegendText = (CLegendText*)pLegendList->GetAt(l);
if (!pLegendText)
continue;
pLegendText->GetClientRect(&Rect);
pLegendText->MoveWindow(nX, nY, Rect.Width(), Rect.Height());
nY += nHeight + nYDelta;
}
nX += nWidth + nXDelta;
nY = nOffsetY;
}
}
/************************************************************************************************/
/* */
/* Function: CLegendWnd::_ArrangeHorizontal() */
/* */
/* Purpose : arranges the legend when this window is wider than it is taller */
/* */
/* Inputs : NONE */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 17MAY02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 17MAY02 initial version */
/* */
/************************************************************************************************/
void CLegendWnd::_ArrangeHorizontal() {
int nWidth(_GetWindowMaxWidth());
int nXDelta(nWidth/2);
int nHeight(_GetWindowMaxHeight());
int nYDelta(nHeight/2);
CPtrArray* pLegendList = _GetLegendList();
int nCnt(pLegendList->GetSize());
if (!nCnt||m_rcClientRect.IsRectEmpty())
return;
int nTotalWidth(0);
int nNumInRow(0);
for (int nRows(1);;nRows++) {
nNumInRow = nCnt/nRows + nCnt%nRows;
nTotalWidth = nWidth*nNumInRow + nXDelta*(nNumInRow-1);
if (nTotalWidth<m_rcClientRect.Width())
break;
}
CLegendText* pLegendText;
CRect Rect;
int nNumInCol(nCnt/nNumInRow + (nCnt%nNumInRow>0));
int nOffsetX((m_rcClientRect.Width()-nWidth*nNumInRow-nXDelta*(nNumInRow-1))/2);
int nX(nOffsetX);
int nOffsetY((m_rcClientRect.Height()-(nHeight*nNumInCol+nYDelta*(nNumInCol-1)))/2);
int nY(nOffsetY);
for (int l(0),i(0);i<nNumInCol;i++) {
for (int j(0);j<nNumInRow&&l<nCnt;j++,l++) {
pLegendText = (CLegendText*)pLegendList->GetAt(l);
if (!pLegendText)
continue;
pLegendText->GetClientRect(&Rect);
pLegendText->MoveWindow(nX, nY, Rect.Width(), Rect.Height());
nX += nWidth + nXDelta;
}
nY += nHeight + nYDelta;
nX = nOffsetX;
}
}
/************************************************************************************************/
/* */
/* Function: CLegendWnd::_GetWindowMaxWidth() */
/* */
/* Purpose : Returns the maximum window width */
/* */
/* Inputs : NONE */
/* */
/* Outputs : int <- width of the window */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -