From c0c336500955a23e344651e5412c9d9d441ef4ee Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 28 Jun 2023 22:22:32 +0100 Subject: first pass of T2DLL --- src/T2DLL/CPiledMultiBarChartView.cpp | 107 ++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 5 deletions(-) (limited to 'src/T2DLL/CPiledMultiBarChartView.cpp') diff --git a/src/T2DLL/CPiledMultiBarChartView.cpp b/src/T2DLL/CPiledMultiBarChartView.cpp index 16b602e..b39450a 100644 --- a/src/T2DLL/CPiledMultiBarChartView.cpp +++ b/src/T2DLL/CPiledMultiBarChartView.cpp @@ -1,25 +1,122 @@ #include "CPiledMultiBarChartView.h" +#include "T2Archive.h" -/*static*/ CPiledMultiBarChartView* CPiledMultiBarChartView::CreateCPiledMultiBarChartViewStream(T2Archive*) { +/*static*/ CPiledMultiBarChartView* CPiledMultiBarChartView::CreateCPiledMultiBarChartViewStream(T2Archive* inStream) { + return new CPiledMultiBarChartView(inStream); } -CPiledMultiBarChartView::CPiledMultiBarChartView(T2Archive*) { +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 CPiledMultiBarChartView::GraphData*) { +void CPiledMultiBarChartView::SetGraphData(const GraphData* inData) { + mGraphData = inData; + Refresh(); } -void CPiledMultiBarChartView::SetPixelPerValue(int, int) { +void CPiledMultiBarChartView::SetPixelPerValue(int inPixelPerValue, BOOL inRefresh) { + mPixelPerValue = inPixelPerValue; + if (inRefresh) + Refresh(); } -void CPiledMultiBarChartView::SetColorOfPiles(int, const unsigned long*, int) { +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); + } } -- cgit v1.2.3