void Textbox::draw() { if (_fillBackground) { tft.fillRect(_pos.x, _pos.y, _size.w, _size.h, bgColor); _fillBackground = false; } if (fontSize == 1) { tft.setFont(&Inconsolata_g5pt7b); } else { tft.setFont(&Inconsolata_g8pt7b); } const char *valStr = _value; size_t valLength = strlen(valStr); if (_lastValLength > 0) { if (strcmp(_lastVal, valStr) == 0) { return; } tft.setCursor(_pos.x, _pos.y +_size.h-2); tft.setTextColor(bgColor); tft.print(_lastVal); } tft.setCursor(_pos.x, _pos.y +_size.h-2); tft.setTextColor(fontColor); tft.print(valStr); tft.setFont(&Inconsolata_g5pt7b); strcpy(_lastVal, valStr); _lastValLength = valLength; }
void Label::draw() { int ox = _pos.x; int oy = _pos.y; if (_touching) { ox++; oy++; } tft.setTextColor(fontColor); int offset = CURSOR_Y_SMALL; if (fontSize == 1) { tft.setFont(&Inconsolata_g5pt7b); } else { tft.setFont(&Inconsolata_g8pt7b); offset = CURSOR_Y_LARGE; } if (centerLabel) { uint16_t w, h; int16_t x1, y1; tft.getTextBounds(_label, 10, 10, &x1, &y1, &w, &h); int x = ox + (_size.w / 2) - ((int) w / 2) - 1; int y = oy + (_size.h / 2) - ((int) h / 2); tft.setCursor(x, y + offset); tft.print(_label); } else { tft.setCursor(ox, oy+_size.h-2); tft.print(_label); } }
void Stat::drawLabel() { if (!_hideLabel) { tft.setFont(&Inconsolata_g8pt7b); tft.setCursor(_pos.x, _pos.y+1+CURSOR_Y_LARGE); tft.setTextColor(ILI9341_WHITE); tft.print(_labelText); } tft.fillRect(_value.x, _value.y, _controlWidth, 17, tft.color565(10, 10, 10)); }
void Stat::drawChart() { if (_redrawChart) { _cur = 0; tft.fillRect(_chart.x, _chart.y - 1 /* catch the top of the unit of the axis */, _chartWidth, 32 /* to catch the bottom of the unit on the axis */, ILI9341_BLACK); tft.setCursor(_chart.x + 27 - ((int16_t) strlen(_labelText) * 6), _chart.y + 12+CURSOR_Y_SMALL); tft.setTextColor(ILI9341_WHITE); tft.setFont(&Inconsolata_g5pt7b); tft.print(_labelText); tft.setCursor(_chart.x + _chartWidth - 45, _chart.y+CURSOR_Y_SMALL); tft.print(_max == INT_MIN ? 0 : _max); if (_unitText) { tft.setTextColor(_chartColor); tft.setCursor(_chart.x + _chartWidth - 45, _chart.y + 12+CURSOR_Y_SMALL); tft.print(_unitText); tft.setTextColor(ILI9341_WHITE); } tft.setCursor(_chart.x + _chartWidth - 45, _chart.y + 24+CURSOR_Y_SMALL); tft.print(_min == INT_MAX ? 0 : _min); tft.setFont(&Inconsolata_g8pt7b); _redrawChart = false; tft.fillRect(_chart.x + 30, _chart.y, _chartWidth - 80, 30, tft.color565(10, 10, 10)); } for ( ; _cur < _end; _cur++) { if (invalidReadingi(_historical[_cur])) { tft.drawFastVLine(_chart.x+30+_cur, _chart.y, 30, ILI9341_MAROON); continue; } int norm = (int) map(_historical[_cur], _min, _max, 0, 29); int x = _chart.x+30+_cur; int y = _chart.y+29-norm; tft.fillRect(x, y, 1, 1, _chartColor); } }
void Stat::drawValue() { char valStr[8]; size_t valLength; if (validReadingi(_stat)) { valLength = (size_t) sprintf(valStr, "%d", _stat); } else { valLength = (size_t) sprintf(valStr, "-- "); } if (_lastValLength > 0) { if (_lastValDrawn == _stat) { return; } tft.setCursor(_value.x, _value.y + 1 + CURSOR_Y_LARGE); tft.setFont(&Inconsolata_g8pt7b); tft.setTextColor(tft.color565(10, 10, 10)); tft.print(_lastVal); if (valLength != _lastValLength) { tft.setFont(&Inconsolata_g5pt7b); tft.print(_unitText); } } tft.setCursor(_value.x, _value.y+1+CURSOR_Y_LARGE); tft.setFont(&Inconsolata_g8pt7b); tft.setTextColor(ILI9341_WHITE, tft.color565(10, 10, 10)); tft.print(valStr); tft.setFont(&Inconsolata_g5pt7b); if (valLength != _lastValLength) { tft.setFont(&Inconsolata_g5pt7b); tft.print(_unitText); } memcpy(_lastVal, valStr, valLength+1); _lastValDrawn = _stat; _lastValLength = valLength; }