all menu items now use _drawMenuText, fully functioning with border when required

This commit is contained in:
rljonesau 2018-12-01 00:33:49 +11:00
parent a784943349
commit 891fa9f5c3
6 changed files with 52 additions and 135 deletions

View file

@ -240,7 +240,7 @@ CScreen1::showThermometer(float desired, float actual)
#ifdef MINI_TARGETLABEL
CAutoFont AF(_display, &MINIFONT); // temporarily use a mini font
#endif
_drawMenuTextCentreJustified(X_TARGET_ICON + (W_TARGET_ICON/2), Y_BASELINE, msg);
_drawMenuText(X_TARGET_ICON + (W_TARGET_ICON/2), Y_BASELINE, msg, false, eCentreJustify);
}
}
@ -264,7 +264,7 @@ CScreen1::showBodyThermometer(int actual)
#else
sprintf(label, "%d", actual);
#endif
_drawMenuTextRightJustified(_display.width(), Y_BASELINE, label);
_drawMenuText(_display.width(), Y_BASELINE, label, false, eRightJustify);
}
@ -278,9 +278,9 @@ CScreen1::showGlowPlug(float power)
#ifdef MINI_GLOWLABEL
CAutoFont AF(_display, &MINIFONT); // temporarily use a mini font
#endif
_drawMenuTextCentreJustified(X_GLOW_ICON + (W_GLOW_ICON/2),
Y_GLOW_ICON + H_GLOW_ICON + 3,
msg);
_drawMenuText(X_GLOW_ICON + (W_GLOW_ICON/2),
Y_GLOW_ICON + H_GLOW_ICON + 3,
msg, false, eCentreJustify);
}
void
@ -295,7 +295,7 @@ CScreen1::showFan(int RPM)
#ifdef MINI_FANLABEL
CAutoFont AF(_display, &MINIFONT); // temporarily use a mini font
#endif
_drawMenuTextCentreJustified(X_FAN_ICON + (W_FAN_ICON/2), Y_BASELINE, msg);
_drawMenuText(X_FAN_ICON + (W_FAN_ICON/2), Y_BASELINE, msg, false, eCentreJustify);
}
void
@ -309,7 +309,7 @@ CScreen1::showFuel(float rate)
#ifdef MINI_FUELLABEL
CAutoFont AF(_display, &MINIFONT); // temporarily use a mini font
#endif
_drawMenuTextCentreJustified(X_FUEL_ICON + (W_FUEL_ICON/2), Y_BASELINE, msg);
_drawMenuText(X_FUEL_ICON + (W_FUEL_ICON/2), Y_BASELINE, msg, false, eCentreJustify);
}
}
@ -345,7 +345,7 @@ CScreen1::showRunState(int runstate, int errstate)
}
}
if(toPrint) {
_drawMenuTextCentreJustified(_display.xCentre(), yPos, toPrint);
_drawMenuText(_display.xCentre(), yPos, toPrint, false, eCentreJustify);
}
}

View file

@ -54,7 +54,7 @@ CScreen2::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
sprintf(msg, "%.1f`", getActualTemperature());
{
CAutoFont AF(_display, &MAXIFONT); // temporarily use a large font
_drawMenuTextCentreJustified(_display.xCentre(), 25, false, msg);
_drawMenuText(_display.xCentre(), 25, msg, false, eCentreJustify);
}
@ -72,15 +72,15 @@ CScreen2::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
yPos = _display.height() - 8 - border; // bottom of screen, with room for box
// display "Fixed Hz" at lower left, allowing space for a selection surrounding box
// display "Fixed Hz" at lower right, allowing space for a selection surrounding box
strcpy(msg, "Fixed Hz");
xPos = _display.width() - border; // set X position to finish short of RHS
_drawMenuTextRightJustified(xPos, yPos, _nModeSel == 1, msg);
_drawMenuText(xPos, yPos, msg, _nModeSel == 1, eRightJustify);
// display "Thermostat" at lower right, allowing space for a selection surrounding box
// display "Thermostat" at lower left, allowing space for a selection surrounding box
strcpy(msg, "Thermostat");
xPos = border;
_drawMenuText(xPos, yPos, _nModeSel == 0, msg);
_drawMenuText(xPos, yPos, msg, _nModeSel == 0);
setThermostatMode(_nModeSel == 0 ? 1 : 0); // set the new mode
}
@ -101,7 +101,7 @@ CScreen2::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
sprintf(msg, "Setpoint = %.1fHz", getFixedHz());
}
// centre message at bottom of screen
_drawMenuTextCentreJustified(_display.xCentre(), _display.height() - 8, msg);
_drawMenuText(_display.xCentre(), _display.height() - 8, msg, false, eCentreJustify);
}
else {
_showSetMode = 0;

View file

@ -54,22 +54,22 @@ CScreen3::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
CRect extents;
// show next/prev screen navigation line
_drawMenuTextCentreJustified(_display.xCentre(), Row[0], _rowSel == 0, Label0);
_drawMenuText(_display.xCentre(), Row[0], Label0, _rowSel == 0, eCentreJustify);
int col = getThermostatMode() ? 0 : 1; // follow actual heater settings
if(_rowSel == 1) {
_drawMenuText(border, Row[1], col == 0, Label1[0]);
_drawMenuTextRightJustified(_display.width()-border, Row[1], col == 1, Label1[1]);
_drawMenuText(border, Row[1], Label1[0], col == 0);
_drawMenuText(_display.width()-border, Row[1], Label1[1], col == 1, eRightJustify);
}
else {
_printInverted(border, Row[1], col == 0, Label1[0]);
_printInverted(_display.width()-border, Row[1], col == 1, Label1[1], eRightJustify);
_printInverted(border, Row[1], Label1[0], col == 0);
_printInverted(_display.width()-border, Row[1], Label1[1], col == 1, eRightJustify);
}
// fuel pump priming menu
_drawMenuText(Col[0], Row[2], "Prime pump");
if(_rowSel == 2) {
_drawMenuText(Col[1], Row[2], _colSel == 1, "OFF");
_drawMenuText(Col[1], Row[2], "OFF", _colSel == 1);
if(_colSel != 2) {
if(!getRunState()) { // prevent option if heater is running
_drawMenuText(Col[2], Row[2], "ON"); // becomes Hz when actually priming
@ -91,7 +91,7 @@ CScreen3::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
if(_PrimeStop) {
char msg[16];
sprintf(msg, "%.1fHz", pumpHz);
_drawMenuTextRightJustified(_display.width()-border, Row[2], true, msg);
_drawMenuText(_display.width()-border, Row[2], msg, true, eRightJustify);
}
}
}

View file

@ -61,25 +61,25 @@ CScreen5::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
_display.setCursor(0, yPos);
_display.print("Pump (Hz)");
sprintf(str, "%.1f", getPumpMin());
_drawMenuTextRightJustified(col2, yPos, str);
_drawMenuText(col2, yPos, str, false, eRightJustify);
sprintf(str, "%.1f", getPumpMax());
_drawMenuTextRightJustified(col3, yPos, str);
_drawMenuText(col3, yPos, str, false, eRightJustify);
// fan max/min
yPos = 40;
_display.setCursor(0, yPos);
_display.print("Fan (RPM)");
sprintf(str, "%d", getFanMin());
_drawMenuTextRightJustified(col2, yPos, str);
_drawMenuText(col2, yPos, str, false, eRightJustify);
sprintf(str, "%d", getFanMax());
_drawMenuTextRightJustified(col3, yPos, str);
_drawMenuText(col3, yPos, str, false, eRightJustify);
// navigation line
yPos = 53;
xPos = _display.xCentre();
_drawMenuTextCentreJustified(xPos, yPos, true, baseLabel);
_drawMenuText(xPos, yPos, baseLabel, true, eCentreJustify);
break;
case 1:
_drawMenuTextCentreJustified(_display.xCentre(), 34, "Enter password...");
_drawMenuText(_display.xCentre(), 34, "Enter password...", false, eCentreJustify);
_showPassword();
break;
@ -93,34 +93,33 @@ CScreen5::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
_display.setCursor(0, yPos);
_display.print("Pump Min");
sprintf(str, "%.1f", adjPump[0]);
_drawMenuTextRightJustified(col3, yPos, _rowSel == 2, str);
_drawMenuText(col3, yPos, str, _rowSel == 2, eRightJustify);
// Pump Maximum adjustment
yPos = border + 24;
_display.setCursor(0, yPos);
_display.print("Pump Hz Max");
sprintf(str, "%.1f", adjPump[1]);
_drawMenuTextRightJustified(col3, yPos, _rowSel == 3, str);
_drawMenuText(col3, yPos, str, _rowSel == 3, eRightJustify);
// Fan Minimum adjustment
yPos = border + 12;
_display.setCursor(0, yPos);
_display.print("Fan Min");
sprintf(str, "%d", adjFan[0]);
_drawMenuTextRightJustified(col3, yPos, _rowSel == 4, str);
_drawMenuText(col3, yPos, str, _rowSel == 4, eRightJustify);
// Fan Maximum adjustment
yPos = border;
_display.setCursor(0, yPos);
_display.print("Fan RPM Max");
sprintf(str, "%d", adjFan[1]);
_drawMenuTextRightJustified(col3, yPos, _rowSel == 5, str);
_drawMenuText(col3, yPos, str, _rowSel == 5, eRightJustify);
// navigation line
yPos = 53;
_display.setCursor(_display.xCentre(), yPos);
_display.printCentreJustified(baseLabel);
_drawMenuText(_display.xCentre(), yPos, baseLabel, false, eCentreJustify);
break;
case 6:
_drawMenuTextCentreJustified(_display.xCentre(), 35, "Press UP to");
_drawMenuTextCentreJustified(_display.xCentre(), 43, "confirm save");
_drawMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
_drawMenuText(_display.xCentre(), 43, "confirm save", false, eCentreJustify);
break;
}
@ -295,25 +294,20 @@ CScreen5::_showPassword()
_display.getTextExtents(" ", extents);
int spaceWidth = extents.width;
for(int i =0 ; i < 4; i++) {
for(int idx =0 ; idx < 4; idx++) {
extents.xPos = _display.xCentre() - (2 - i) * (charWidth * 1.5);
extents.xPos = _display.xCentre() - (2 - idx) * (charWidth * 1.5);
extents.yPos = 50;
char str[8];
if(_PWdig[i] < 0) {
if(_PWdig[idx] < 0) {
strcpy(str, "-");
}
else {
sprintf(str, "%d", _PWdig[i]);
sprintf(str, "%d", _PWdig[idx]);
}
if(_rowSel == 1 && _colSel == i) {
// draw selection box
_drawSelectionBox(extents.xPos, extents.yPos, str);
}
_display.setCursor(extents.xPos, extents.yPos);
_display.print(str);
_drawMenuText(extents.xPos, extents.yPos, str, _colSel == idx);
}
}

View file

@ -333,96 +333,28 @@ CScreen::showBatteryIcon(float voltage)
_display.fillRect(X_BATT_ICON+2 + Capacity, Y_BATT_ICON+2, W_BATT_ICON-4-Capacity, 6, BLACK);
}
void
CScreen::_drawSelectionBox(int x, int y, const char* str, int border, int radius)
void
CScreen::_drawMenuText(int x, int y, const char* str, bool selected, eJUSTIFY justify, int border, int radius)
{
// position output, according to justification
CRect extents;
_display.getTextExtents(str, extents);
extents.xPos = x;
extents.yPos = y;
extents.Expand(border);
_display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE);
}
void
CScreen::_drawSelectionBoxCentreJustified(int x, int y, const char* str, int border, int radius)
{
CRect extents;
_display.getTextExtents(str, extents);
x -= extents.width / 2;
_drawSelectionBox(x, y, str, border, radius);
}
_adjustExtents(extents, justify, str);
void
CScreen::_drawSelectionBoxRightJustified(int x, int y, const char* str, int border, int radius)
{
CRect extents;
_display.getTextExtents(str, extents);
x -= extents.width;
_drawSelectionBox(x, y, str, border, radius);
}
void
CScreen::_drawMenuText(int x, int y, const char* str)
{
_display.setCursor(x, y);
_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);
}
}
void
CScreen::_drawMenuText(int x, int y, bool selected, const char* str, int border, int radius)
{
_drawMenuText(x, y, str);
if(selected)
_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)
{
_display.setCursor(x, y);
_display.printCentreJustified(str);
}
void
CScreen::_drawMenuTextCentreJustified(int x, int y, bool selected, const char* str, int border, int radius)
{
_drawMenuTextCentreJustified(x, y, str);
if(selected)
_drawSelectionBoxCentreJustified(x, y, str, border, radius);
}
void
CScreen::_drawMenuTextRightJustified(int x, int y, const char* str)
{
_display.setCursor(x, y);
_display.printRightJustified(str);
}
void
CScreen::_drawMenuTextRightJustified(int x, int y, bool selected, const char* str, int border, int radius)
{
_drawMenuTextRightJustified(x, y, str);
if(selected)
_drawSelectionBoxRightJustified(x, y, str, border, radius);
}
void
CScreen::_printInverted(int x, int y, const char* str, eJUSTIFY justify)
{
_printInverted( x, y, true, str, justify);
}
void
CScreen::_printInverted(int x, int y, bool selected, const char* str, eJUSTIFY justify)
CScreen::_printInverted(int x, int y, const char* str, bool selected, eJUSTIFY justify)
{
// position output, according to justification
CRect extents;

View file

@ -63,17 +63,8 @@ protected:
void showBTicon();
void showWifiIcon();
void showBatteryIcon(float voltage);
void _drawSelectionBox(int x, int y, const char* str, int border = 3, int radius = 4);
void _drawSelectionBoxRightJustified(int x, int y, const char* str, int border = 3, int radius = 4);
void _drawSelectionBoxCentreJustified(int x, int y, const char* str, int border = 3, int radius = 4);
void _drawMenuText(int x, int y, const char* str);
void _drawMenuText(int x, int y, bool selected, const char* str, int border = 3, int radius = 4);
void _drawMenuTextCentreJustified(int x, int y, const char* str);
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, eJUSTIFY justify = eLeftJustify);
void _printInverted(int x, int y, bool selected, const char* str, eJUSTIFY justify = eLeftJustify);
void _drawMenuText(int x, int y, const char* str, bool selected = false, eJUSTIFY justify = eLeftJustify, int border = 3, int radius = 4);
void _printInverted(int x, int y, const char* str, bool selected, eJUSTIFY justify = eLeftJustify);
void _adjustExtents(CRect& rect, eJUSTIFY justify, const char* str);
public:
CScreen(C128x64_OLED& disp, CScreenManager& mgr);