2019-04-06 10:45:25 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-12-01 00:36:25 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include "Screen.h"
|
2019-07-27 14:28:39 +00:00
|
|
|
#include "fonts/Arial.h"
|
2018-12-01 00:36:25 +00:00
|
|
|
|
|
|
|
// base class functionality for screens
|
|
|
|
|
|
|
|
CScreen::CScreen(C128x64_OLED& disp, CScreenManager& mgr) :
|
|
|
|
_display(disp),
|
|
|
|
_ScreenManager(mgr)
|
|
|
|
{
|
2018-12-20 06:29:00 +00:00
|
|
|
_showOEMerror = 0;
|
2018-12-01 00:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CScreen::~CScreen()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-01 18:25:10 +00:00
|
|
|
bool
|
2018-12-01 00:36:25 +00:00
|
|
|
CScreen::animate()
|
|
|
|
{
|
2018-12-20 06:29:00 +00:00
|
|
|
if(_showOEMerror) {
|
2019-01-19 11:05:14 +00:00
|
|
|
_display.clearDisplay();
|
2018-12-20 06:29:00 +00:00
|
|
|
_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 18:25:10 +00:00
|
|
|
return false;
|
2018-12-01 00:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2018-12-01 00:36:25 +00:00
|
|
|
CScreen::show()
|
|
|
|
{
|
2019-01-18 23:06:12 +00:00
|
|
|
return false;
|
2018-12-01 00:36:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 04:18:37 +00:00
|
|
|
void
|
|
|
|
CScreen::onSelect()
|
|
|
|
{
|
2019-07-21 11:17:54 +00:00
|
|
|
_display.clearDisplay();
|
2018-12-08 04:18:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 08:56:13 +00:00
|
|
|
void
|
|
|
|
CScreen::onExit()
|
|
|
|
{
|
|
|
|
}
|
2018-12-01 00:36:25 +00:00
|
|
|
|
|
|
|
void
|
2018-12-07 04:18:24 +00:00
|
|
|
CScreen::_printMenuText(int x, int y, const char* str, bool selected, eJUSTIFY justify, int border, int radius)
|
2018-12-01 00:36:25 +00:00
|
|
|
{
|
|
|
|
// 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 01:39:41 +00:00
|
|
|
void
|
|
|
|
CScreen::_drawMenuSelection(CRect extents, const char* str, int border, int radius)
|
|
|
|
{
|
2019-07-20 06:08:43 +00:00
|
|
|
CRect resize(extents);
|
|
|
|
_display.getTextExtents(str, resize);
|
|
|
|
// resize.Expand(border);
|
|
|
|
// _display.drawRoundRect(resize.xPos, resize.yPos, resize.width, resize.height, radius, WHITE);
|
|
|
|
_drawMenuSelection(resize, border, radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CScreen::_drawMenuSelection(const CRect& extents, int border, int radius)
|
|
|
|
{
|
|
|
|
CRect resize(extents);
|
|
|
|
resize.Expand(border);
|
|
|
|
_display.drawRoundRect(resize.xPos, resize.yPos, resize.width, resize.height, radius, WHITE);
|
2018-12-08 01:39:41 +00:00
|
|
|
}
|
2018-12-01 00:36:25 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-03-17 07:10:01 +00:00
|
|
|
void
|
|
|
|
CScreen::_scrollMessage(int y, const char* str, int& charOffset)
|
|
|
|
{
|
|
|
|
char msg[20];
|
|
|
|
int maxIndex = strlen(str) - 20;
|
|
|
|
strncpy(msg, &str[charOffset], 19);
|
|
|
|
msg[19] = 0;
|
|
|
|
_printMenuText(_display.xCentre(), y, msg, false, eCentreJustify);
|
|
|
|
|
|
|
|
charOffset++;
|
|
|
|
if(charOffset >= maxIndex) {
|
|
|
|
charOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-12-01 00:36:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CScreen::_adjustExtents(CRect& extents, eJUSTIFY justify, const char* str)
|
|
|
|
{
|
|
|
|
_display.getTextExtents(str, extents);
|
|
|
|
switch(justify) {
|
2019-06-26 20:04:24 +00:00
|
|
|
case eLeftJustify:
|
|
|
|
break;
|
2018-12-01 00:36:25 +00:00
|
|
|
case eCentreJustify:
|
|
|
|
extents.xPos -= extents.width/2;
|
|
|
|
break;
|
|
|
|
case eRightJustify:
|
|
|
|
extents.xPos -= extents.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 06:29:00 +00:00
|
|
|
void
|
|
|
|
CScreen::_reqOEMWarning()
|
|
|
|
{
|
|
|
|
_showOEMerror = 10;
|
|
|
|
}
|
2018-12-01 00:36:25 +00:00
|
|
|
|
2019-06-01 00:18:31 +00:00
|
|
|
void
|
2019-06-02 09:19:08 +00:00
|
|
|
CScreen::_drawBitmap(int x, int y, const BITMAP_INFO& info, uint16_t colour, uint16_t bg)
|
2019-06-01 00:18:31 +00:00
|
|
|
{
|
2019-06-02 09:19:08 +00:00
|
|
|
if(bg == 0xffff) {
|
|
|
|
// normal mode - does not erase background
|
|
|
|
_display.drawBitmap(x, y, info.pBitmap, info.width, info.height, colour);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// overwrite mode - erases background
|
|
|
|
_display.drawBitmap(x, y, info.pBitmap, info.width, info.height, colour, bg);
|
|
|
|
}
|
2019-06-01 00:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-27 14:28:39 +00:00
|
|
|
void
|
|
|
|
CScreen::_showTitle(const char* title)
|
|
|
|
{
|
|
|
|
CTransientFont AF(_display, &arial_8ptBoldFontInfo);
|
2019-07-27 23:07:29 +00:00
|
|
|
_printMenuText(_display.xCentre(), -1, title, false, eCentreJustify);
|
2019-07-27 14:28:39 +00:00
|
|
|
_display.drawFastHLine(0, 10, 128, WHITE);
|
|
|
|
}
|
|
|
|
|
2019-07-27 23:07:29 +00:00
|
|
|
void
|
|
|
|
CScreen::_showConfirmMessage()
|
|
|
|
{
|
|
|
|
_showTitle("Saving Settings");
|
|
|
|
_printMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 43, "confirm save", false, eCentreJustify);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CScreen::_showStoringMessage()
|
|
|
|
{
|
|
|
|
_display.writeFillRect(34, 19, 60, 26, WHITE);
|
|
|
|
CTransientFont AF(_display, &arial_8ptBoldFontInfo);
|
2019-07-28 01:37:39 +00:00
|
|
|
_printInverted(_display.xCentre(), 27, " STORING ", true, eCentreJustify);
|
2019-07-27 23:07:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 14:28:39 +00:00
|
|
|
|
2018-12-01 00:36:25 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|