1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include "StdAfx.h"
#include "CPiledMultiBarChartView.h"
#include "T2Archive.h"
/*static*/ CPiledMultiBarChartView* CPiledMultiBarChartView::CreateCPiledMultiBarChartViewStream(T2Archive* inStream) {
return new CPiledMultiBarChartView(inStream);
}
CPiledMultiBarChartView::CPiledMultiBarChartView(T2Archive* inStream)
: mPixelPerValue(1)
, mColorOfPiles(NULL)
, mGraphData(NULL)
{
inStream->Read(&mSkipDrawing, sizeof(mSkipDrawing));
inStream->Read(&mPiles, sizeof(mPiles));
inStream->Read(&mBars, sizeof(mBars));
inStream->Read(&mBarWidth, sizeof(mBarWidth));
inStream->Read(&mXOffset, sizeof(mXOffset));
inStream->Read(&mBarInterval, sizeof(mBarInterval));
#line 40
_ASSERT(mPiles > 0 && mBars > 0 && mBarWidth > 0 && mBarInterval >= 0);
inStream->Read(&mLines, sizeof(mLines));
inStream->Read(&mLineInterval, sizeof(mLineInterval));
inStream->Read(&mLineLength, sizeof(mLineLength));
}
/*virtual*/ CPiledMultiBarChartView::~CPiledMultiBarChartView() {
if (mColorOfPiles)
delete[] mColorOfPiles;
}
void CPiledMultiBarChartView::SetGraphData(const GraphData* inData) {
mGraphData = inData;
Refresh();
}
void CPiledMultiBarChartView::SetPixelPerValue(int inPixelPerValue, BOOL inRefresh) {
mPixelPerValue = inPixelPerValue;
if (inRefresh)
Refresh();
}
void CPiledMultiBarChartView::SetColorOfPiles(int inCount, const COLORREF* inColors, BOOL inRefresh) {
if (inColors) {
if (!mColorOfPiles)
mColorOfPiles = new COLORREF[mPiles];
memset(mColorOfPiles, 0, mPiles * sizeof(COLORREF));
memmove(mColorOfPiles, inColors, min(inCount, mPiles) * sizeof(COLORREF));
if (inRefresh)
Refresh();
}
}
void CPiledMultiBarChartView::Refresh() {
CRect rect;
GetClientRect(rect);
InvalidateRect(rect);
}
void CPiledMultiBarChartView::DrawSelf() {
CRect theFrameRect;
GetClientRect(theFrameRect);
if (!theFrameRect.IsRectEmpty()) {
CDC *pDC = GetDC();
int unknownValue = 0;
CPen *theOldPen = (CPen *) pDC->SelectStockObject(BLACK_PEN);
CBrush *oldBrush = (CBrush *) pDC->SelectStockObject(NULL_BRUSH);
pDC->MoveTo(theFrameRect.left, theFrameRect.top);
pDC->LineTo(theFrameRect.left, theFrameRect.bottom - 1);
pDC->LineTo(theFrameRect.right - 1, theFrameRect.bottom - 1);
BOOL drawBars = (mGraphData != NULL) && (mColorOfPiles != NULL) && (mPixelPerValue != 0);
BOOL drawLines = (mLines > 0) && (mLineInterval > 0) && (mLineLength > 0);
if (mSkipDrawing)
goto skip;
if (drawLines) {
int y = theFrameRect.bottom - 1;
for (int i = 0; i < mLines; i++) {
y -= mLineInterval;
pDC->MoveTo(theFrameRect.left, y);
pDC->LineTo(theFrameRect.left + mLineLength, y);
}
}
if (drawBars) {
int numOfBars = min(mBars, mGraphData->bars);
int x = mXOffset;
for (int currentBar = 0; currentBar < numOfBars; currentBar++) {
int y = 0;
int numOfPiles = min(mPiles, mGraphData->piles);
for (int currentPile = 0; currentPile < numOfPiles; currentPile++) {
int rawValue = mGraphData->data[mGraphData->piles * currentBar + currentPile];
int value = rawValue / mPixelPerValue;
if (value > 0) {
CRect pileRect(x, -(y + value), x + mBarWidth, -y);
pileRect.OffsetRect(theFrameRect.left, theFrameRect.bottom);
y += value;
CBrush pileBrush(mColorOfPiles[currentPile]);
pDC->SelectObject(pileBrush);
pDC->Rectangle(pileRect);
}
}
x += mBarInterval;
}
}
skip:
pDC->SelectObject(oldBrush);
pDC->SelectObject(theOldPen);
ReleaseDC(pDC);
}
}
|