From a78494334905ad35b58f44809b8739b41b5f5227 Mon Sep 17 00:00:00 2001 From: rljonesau Date: Fri, 30 Nov 2018 07:09:46 +1100 Subject: [PATCH] Immensely tidied Screen3's handling of fixed/thermo mode by adding _printInverted to CScreen --- Arduino/BTCDieselHeater/Screen3.cpp | 26 +++------------- Arduino/BTCDieselHeater/display.cpp | 48 +++++++++++++++++++++-------- Arduino/BTCDieselHeater/display.h | 11 +++++-- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/Arduino/BTCDieselHeater/Screen3.cpp b/Arduino/BTCDieselHeater/Screen3.cpp index e25b871..322aacb 100644 --- a/Arduino/BTCDieselHeater/Screen3.cpp +++ b/Arduino/BTCDieselHeater/Screen3.cpp @@ -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"); diff --git a/Arduino/BTCDieselHeater/display.cpp b/Arduino/BTCDieselHeater/display.cpp index d33ae2d..c45513e 100644 --- a/Arduino/BTCDieselHeater/display.cpp +++ b/Arduino/BTCDieselHeater/display.cpp @@ -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; + } +} diff --git a/Arduino/BTCDieselHeater/display.h b/Arduino/BTCDieselHeater/display.h index b6174ac..04fa9da 100644 --- a/Arduino/BTCDieselHeater/display.h +++ b/Arduino/BTCDieselHeater/display.h @@ -24,11 +24,17 @@ #include #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();