diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2DlgItemGageBase.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2DlgItemGageBase.cpp | 97 |
1 files changed, 91 insertions, 6 deletions
diff --git a/src/T2DLL/T2DlgItemGageBase.cpp b/src/T2DLL/T2DlgItemGageBase.cpp index 4ef48e2..faa140a 100644 --- a/src/T2DLL/T2DlgItemGageBase.cpp +++ b/src/T2DLL/T2DlgItemGageBase.cpp @@ -1,19 +1,104 @@ #include "T2DlgItemGageBase.h" -T2DlgItemGageBase::T2DlgItemGageBase(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemGageBase::T2DlgItemGageBase(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItem(towerDoc, imageObj, palette) +{ } -/*virtual*/ int T2DlgItemGageBase::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemGageBase::OnT2DlgItemEraseBkgnd(CDC* dc) { + CRect clientRect; + GetClientRect(clientRect); + + int save = dc->SaveDC(); + dc->SelectPalette(mPalette, false); + dc->RealizePalette(); + + CRect interior = clientRect; + if (IsDrawInterior()) + DrawInterior(dc, interior); + + dc->RestoreDC(save); + return true; } -/*virtual*/ void T2DlgItemGageBase::DrawInterior(CDC*, const CRect&) { +/*virtual*/ void T2DlgItemGageBase::DrawInterior(CDC* dc, const CRect& rect) { + dc->FillSolidRect(rect, RGB(255, 255, 255)); + + int pos = CalcPos(rect, GetMinValue(), GetMaxValue(), GetValue()); + CRect rect2(rect.left, rect.top, rect.left + pos, rect.bottom); + dc->FillSolidRect(rect2, GetGageColor(GetValue())); + + DrawBorderLines(dc, rect); } -void T2DlgItemGageBase::DrawBorderLines(CDC*, const CRect&) { +void T2DlgItemGageBase::DrawBorderLines(CDC* dc, const CRect& rect) { + CPen pen; + pen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + HPEN prevPen = *dc->SelectObject(&pen); + + int bluePos = CalcPos(rect, GetMinValue(), GetMaxValue(), GetBlueValue()); + dc->MoveTo(bluePos, rect.top); + dc->LineTo(bluePos, rect.bottom - 1); + + int yellowPos = CalcPos(rect, GetMinValue(), GetMaxValue(), GetYellowValue()); + dc->MoveTo(yellowPos, rect.top); + dc->LineTo(yellowPos, rect.bottom - 1); + + dc->MoveTo(rect.left, rect.top); + dc->LineTo(rect.left, rect.bottom - 1); + dc->LineTo(rect.right - 1, rect.bottom - 1); + dc->LineTo(rect.right - 1, rect.top); + dc->LineTo(rect.left, rect.top); + + dc->SelectObject(prevPen); } -void T2DlgItemGageBase::DrawValueByText(CDC*, const CRect&) { +void T2DlgItemGageBase::DrawValueByText(CDC* dc, const CRect& rect) { + CRect smallerRect = rect; + smallerRect.DeflateRect(2, 0); + + CString text; + text.Format("%d", GetValue()); + + CFont font; + font.CreateFont( + -(rect.Height() - 4), + 0, + 0, + 0, + FW_BOLD, + false, + false, + false, + DEFAULT_CHARSET, + OUT_TT_PRECIS, + CLIP_TT_ALWAYS, + PROOF_QUALITY, + DEFAULT_PITCH, + "Arial" + ); + + HFONT prevFont = *dc->SelectObject(&font); + dc->SetBkMode(TRANSPARENT); + dc->SetTextColor(PALETTERGB(255, 255, 255)); + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + CRect shadowRect = smallerRect; + shadowRect.OffsetRect(x, y); + dc->DrawText(text, shadowRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE); + } + } + + CRect textRect = smallerRect; + dc->SetTextColor(PALETTEINDEX(255)); + dc->DrawText(text, textRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE); + + dc->SelectObject(prevFont); } -int T2DlgItemGageBase::CalcPos(const CRect&, int, int, int) { +int T2DlgItemGageBase::CalcPos(const CRect& rect, int minValue, int maxValue, int value) { + return (minValue < maxValue) + ? (rect.left + ((rect.Width() * (value - minValue)) / (maxValue - minValue))) + : 0; } |