#include "StdAfx.h" #include "T2DlgItemGageBase.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif T2DlgItemGageBase::T2DlgItemGageBase(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) : T2DlgItem(towerDoc, imageObj, palette) { } /*virtual*/ BOOL T2DlgItemGageBase::OnT2DlgItemEraseBkgnd(CDC* dc) { CRect rect; GetClientRect(rect); int saved = dc->SaveDC(); dc->SelectPalette(mPalette, false); dc->RealizePalette(); CRect theInterior = rect; if (IsDrawInterior()) DrawInterior(dc, theInterior); dc->RestoreDC(saved); return true; } /*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* dc, const CRect& rect) { CPen pen; pen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); HPEN oldPenH = *dc->SelectObject(&pen); int theBlue = CalcPos(rect, GetMinValue(), GetMaxValue(), GetBlueValue()); dc->MoveTo(theBlue, rect.top); dc->LineTo(theBlue, rect.bottom - 1); int theYellow = CalcPos(rect, GetMinValue(), GetMaxValue(), GetYellowValue()); dc->MoveTo(theYellow, rect.top); dc->LineTo(theYellow, 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(oldPenH); } void T2DlgItemGageBase::DrawValueByText(CDC* dc, const CRect& inRect) { CRect theFrameRect = inRect; theFrameRect.DeflateRect(2, 0); CString theString; theString.Format("%d", GetValue()); CFont theFont; theFont.CreateFont( -(inRect.Height() - 4), 0, 0, 0, FW_BOLD, false, false, false, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "Arial" ); HFONT theOldFont = *dc->SelectObject(&theFont); 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 = theFrameRect; shadowRect.OffsetRect(x, y); dc->DrawText(theString, shadowRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE); } } CRect textRect = theFrameRect; dc->SetTextColor(PALETTEINDEX(255)); dc->DrawText(theString, textRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE); dc->SelectObject(theOldFont); } int T2DlgItemGageBase::CalcPos(const CRect& rect, int minValue, int maxValue, int value) { return (minValue < maxValue) ? (rect.left + ((rect.Width() * (value - minValue)) / (maxValue - minValue))) : 0; }