summaryrefslogtreecommitdiff
path: root/src/T2DLL/CPiledMultiBarChartView.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
commitc0c336500955a23e344651e5412c9d9d441ef4ee (patch)
tree790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/CPiledMultiBarChartView.cpp
parent37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff)
downloadt2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz
t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip
first pass of T2DLL
Diffstat (limited to 'src/T2DLL/CPiledMultiBarChartView.cpp')
-rw-r--r--src/T2DLL/CPiledMultiBarChartView.cpp107
1 files changed, 102 insertions, 5 deletions
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);
+ }
}