ESP32_ChinaDieselHeater_Con.../Arduino/BTCDieselHeater/src/OLED/Screen.cpp

129 lines
2.7 KiB
C++
Raw Normal View History

#include <Arduino.h>
#include "Screen.h"
// base class functionality for screens
CScreen::CScreen(C128x64_OLED& disp, CScreenManager& mgr) :
_display(disp),
_ScreenManager(mgr)
{
_showOEMerror = 0;
}
CScreen::~CScreen()
{
}
2018-12-01 19:25:10 +01:00
bool
CScreen::animate()
{
if(_showOEMerror) {
DebugPort.println("CScreen::animate()");
_display.fillRect(8, 20, 112, 24, WHITE);
if(_showOEMerror & 0x01) {
_printInverted(_display.xCentre(), 23, "Other controller ", true, eCentreJustify);
_printInverted(_display.xCentre(), 32, "Operation blocked", true, eCentreJustify);
}
_showOEMerror--;
return true;
}
2018-12-01 19:25:10 +01:00
return false;
}
void
CScreen::show()
{
}
void
CScreen::onSelect()
{
}
void
2018-12-07 05:18:24 +01:00
CScreen::_printMenuText(int x, int y, const char* str, bool selected, eJUSTIFY justify, int border, int radius)
{
// position output, according to justification
CRect extents;
extents.xPos = x;
extents.yPos = y;
_display.getTextExtents(str, extents);
_adjustExtents(extents, justify, str);
_display.setCursor(extents.xPos, extents.yPos);
_display.print(str);
if(selected) {
extents.Expand(border);
_display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE);
}
}
2018-12-08 02:39:41 +01:00
void
CScreen::_drawMenuSelection(CRect extents, const char* str, int border, int radius)
{
_display.getTextExtents(str, extents);
extents.Expand(border);
_display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE);
}
void
CScreen::_printInverted(int x, int y, const char* str, bool selected, eJUSTIFY justify)
{
// position output, according to justification
CRect extents;
extents.xPos = x;
extents.yPos = y;
_adjustExtents(extents, justify, str);
if(selected) {
_display.setTextColor(BLACK, WHITE);
extents.Expand(1);
_display.fillRect(extents.xPos, extents.yPos, extents.width, extents.height, WHITE);
extents.Expand(-1);
}
_display.setCursor(extents.xPos, extents.yPos);
_display.print(str);
_display.setTextColor(WHITE, BLACK);
}
void
CScreen::_adjustExtents(CRect& extents, eJUSTIFY justify, const char* str)
{
_display.getTextExtents(str, extents);
switch(justify) {
case eCentreJustify:
extents.xPos -= extents.width/2;
break;
case eRightJustify:
extents.xPos -= extents.width;
break;
}
}
void
CScreen::_reqOEMWarning()
{
_showOEMerror = 10;
}
// a class used for temporary alternate fonts usage
// Reverts to standard inbuilt font when the instance falls out of scope
CTransientFont::CTransientFont(C128x64_OLED& disp, const FONT_INFO* pFont) :
_display(disp)
{
_display.setFontInfo(pFont);
_display.setTextColor(WHITE, BLACK);
}
CTransientFont::~CTransientFont()
{
_display.setFontInfo(NULL);
}