Immensely tidied Screen3's handling of fixed/thermo mode by adding _printInverted to CScreen

This commit is contained in:
rljonesau 2018-11-30 07:09:46 +11:00
parent abc8f63590
commit a784943349
3 changed files with 48 additions and 37 deletions

View file

@ -56,33 +56,15 @@ CScreen3::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
// show next/prev screen navigation line
_drawMenuTextCentreJustified(_display.xCentre(), Row[0], _rowSel == 0, Label0);
// thermostat / fixed mode selection menu
// highlight active state - depends if line is active whetehr this is an open box, or inverse text
int col = getThermostatMode() ? 0 : 1; // follow actual heater settings
_display.getTextExtents(Label1[col], extents);
extents.xPos = (col == 0) ? border : _display.width() - extents.width - border;
extents.yPos = Row[1];
if(_rowSel == 1) {
// draw selection box
_drawSelectionBox(extents.xPos, extents.yPos, Label1[col]);
_drawMenuText(border, Row[1], col == 0, Label1[0]);
_drawMenuTextRightJustified(_display.width()-border, Row[1], col == 1, Label1[1]);
}
else {
// draw white background, expanded about usual text size
extents.Expand(1);
_display.fillRect(extents.xPos, extents.yPos, extents.width, extents.height, WHITE);
_printInverted(border, Row[1], col == 0, Label1[0]);
_printInverted(_display.width()-border, Row[1], col == 1, Label1[1], eRightJustify);
}
if(col == 0 && _rowSel != 1)
_display.setTextColor(BLACK);
_display.setCursor(border, Row[1]);
_display.print(Label1[0]);
_display.setTextColor(WHITE);
if(col == 1 && _rowSel != 1)
_display.setTextColor(BLACK);
_display.setCursor(_display.width() - border, Row[1]);
_display.printRightJustified(Label1[1]);
_display.setTextColor(WHITE);
// fuel pump priming menu
_drawMenuText(Col[0], Row[2], "Prime pump");

View file

@ -377,6 +377,14 @@ CScreen::_drawMenuText(int x, int y, bool selected, const char* str, int border,
_drawSelectionBox(x, y, str, border, radius);
}
/*void
CScreen::_drawMenuText(int x, int y, bool selected, const char* str, eJUSTIFY justify, int border, int radius)
{
_drawMenuText(x, y, str);
if(selected)
_drawSelectionBox(x, y, str, border, radius);
}*/
void
CScreen::_drawMenuTextCentreJustified(int x, int y, const char* str)
{
@ -408,29 +416,29 @@ CScreen::_drawMenuTextRightJustified(int x, int y, bool selected, const char* st
}
void
CScreen::_printInverted(int x, int y, const char* str)
CScreen::_printInverted(int x, int y, const char* str, eJUSTIFY justify)
{
_display.setCursor(x, y);
_display.setTextColor(BLACK);
_display.print(str);
_display.setTextColor(WHITE);
_printInverted( x, y, true, str, justify);
}
void
CScreen::_printInvertedConditional(int x, int y, bool selected, const char* str)
CScreen::_printInverted(int x, int y, bool selected, const char* str, eJUSTIFY justify)
{
// position output, according to justification
CRect extents;
extents.xPos = x;
extents.yPos = y;
_adjustExtents(extents, justify, str);
if(selected) {
_display.setTextColor(BLACK);
CRect extents;
_display.getTextExtents(str, extents);
extents.xPos = x;
extents.yPos = y;
_display.setTextColor(BLACK, WHITE);
extents.Expand(1);
_display.fillRect(extents.xPos, extents.yPos, extents.width, extents.height, WHITE);
extents.Expand(-1);
}
_display.setCursor(x, y);
_display.setCursor(extents.xPos, extents.yPos);
_display.print(str);
_display.setTextColor(WHITE);
_display.setTextColor(WHITE, BLACK);
}
CAutoFont::CAutoFont(C128x64_OLED& disp, const FONT_INFO* pFont) :
@ -444,3 +452,17 @@ CAutoFont::~CAutoFont()
{
_display.setFontInfo(NULL);
}
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;
}
}

View file

@ -24,11 +24,17 @@
#include <Arduino.h>
#include "FontTypes.h"
#include "UtilClasses.h"
class CProtocol;
class C128x64_OLED;
class CScreen;
struct CRect;
enum eJUSTIFY {
eLeftJustify, eCentreJustify, eRightJustify
};
class CScreenManager {
static const int _maxScreens = 5;
@ -66,8 +72,9 @@ protected:
void _drawMenuTextCentreJustified(int x, int y, bool selected, const char* str, int border = 3, int radius = 4);
void _drawMenuTextRightJustified(int x, int y, const char* str);
void _drawMenuTextRightJustified(int x, int y, bool selected, const char* str, int border = 3, int radius = 4);
void _printInverted(int x, int y, const char* str);
void _printInvertedConditional(int x, int y, bool selected, const char* str);
void _printInverted(int x, int y, const char* str, eJUSTIFY justify = eLeftJustify);
void _printInverted(int x, int y, bool selected, const char* str, eJUSTIFY justify = eLeftJustify);
void _adjustExtents(CRect& rect, eJUSTIFY justify, const char* str);
public:
CScreen(C128x64_OLED& disp, CScreenManager& mgr);
virtual ~CScreen();