std::wstring Meter::ToString() { std::wstringstream ss; ss << L"Geometry: (" << _rect.X << L", " << _rect.Y << "); "; ss << _rect.Width << L"x" << _rect.Height << std::endl; ss << L"Units: " << Units() << std::endl; ss << L"Current Value: " << Value() << L" (" << CalcUnits() << L" units)"; return ss.str(); }
void VerticalTile::Draw(Gdiplus::Bitmap *buffer, Gdiplus::Graphics *graphics) { int currentUnits = CalcUnits(); int height = _rect.Height * currentUnits; graphics->FillRectangle(_texture, _rect.X, _rect.Y, _rect.Width, height); UpdateDrawnValues(); }
bool Meter::Dirty() { /* Not dirty if the meter's value is unchanged */ if (Value() == _drawnValue) { return false; } /* Not dirty if the change in value won't affect the meter graphically */ if (CalcUnits() == _drawnUnits) { return false; } return true; }
void HorizontalBar::Draw(Gdiplus::Bitmap *buffer, Gdiplus::Graphics *graphics) { int width = _pixelsPerUnit * CalcUnits(); if (_reversed) { width = _rect.Width - width; } Gdiplus::Rect drawRect(_rect.X, _rect.Y, width, _rect.Height); graphics->DrawImage(_bitmap, drawRect, 0, 0, width, _rect.Height, Gdiplus::UnitPixel, &_imageAttributes, NULL, NULL); UpdateDrawnValues(); }
void Text::Draw(Gdiplus::Bitmap *buffer, Gdiplus::Graphics *graphics) { int units = CalcUnits(); Gdiplus::RectF layoutRect((float) _rect.X, (float) _rect.Y, (float) _rect.Width, (float) _rect.Height); graphics->SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); wchar_t perc[4]; _itow_s(units * (100 / _units), perc, 10); std::wstring tempstr(_formatString); const wchar_t *str = tempstr.replace(_replaceIndex, 8, perc).c_str(); graphics->DrawString(str, -1, _font, layoutRect, &_strFormat, _fontColor); UpdateDrawnValues(); }
void NumberStrip::Draw(Gdiplus::Bitmap *buffer, Gdiplus::Graphics *graphics) { int units = CalcUnits(); int perc = units * (100 / _units); int digits[] = { perc % 10, (perc / 10) % 10, perc / 100, }; int chars = 1; if (digits[1] > 0) { chars = 2; } else if (digits[2] > 0) { chars = 3; } int drawX = _charWidth * 2; if (_align == Gdiplus::StringAlignmentNear) { drawX = (chars - 1) * _charWidth; } else if (_align == Gdiplus::StringAlignmentFar) { drawX = (_charWidth * 2) - ((3 - chars) * (_charWidth / 2)); } for (int i = 0, x = drawX; i < chars; ++i, x -= _charWidth) { int digit = digits[i]; QCLOG(L"Drawing digit [%d]; x-offset: %d", digit, _rect.X + x); Gdiplus::Rect destRect(_rect.X + x, _rect.Y, _charWidth, _rect.Height); graphics->DrawImage(_bitmap, destRect, 0, digit * _rect.Height, _charWidth, _rect.Height, Gdiplus::UnitPixel, NULL, NULL, NULL); } UpdateDrawnValues(); }
void Meter::UpdateDrawnValues() { _drawnUnits = CalcUnits(); _drawnValue = _value; }
void CallbackMeter::Draw(Gdiplus::Bitmap *buffer, Gdiplus::Graphics *graphics) { int units = CalcUnits(); _receiver.MeterChangeCallback(units); UpdateDrawnValues(); }