#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); } }