DeskControl/src/lib/screen/home.cpp

145 lines
3.2 KiB
C++

#include "./home.h"
#include "./move.h"
#include "include/config.h"
#include "include/metrics.h"
#include "lib/settings.h"
#include "lib/control.h"
#include "./menu.h"
void HomeScreen::onShow()
{
this->showTime = State.CurrentTime;
auto display = this->getDisplay();
display->setFont(Metrics::LargeFont);
display->fillScreen(Config::ColorHomeBackground);
this->drawPreset1();
this->drawMenu();
this->drawPreset2();
this->drawNonPresetHeight();
}
void HomeScreen::onButton(Button button)
{
if (this->idle)
{
this->getScreenManager()->displayOn();
this->idle = false;
this->showTime = State.CurrentTime;
// Preset buttons activate immediately
if (button == Button::Menu)
return;
}
switch (button)
{
case Button::Up:
controlMoveTo(Settings.Height.Preset[0]);
this->getScreenManager()->show<MoveScreen>();
break;
case Button::Down:
controlMoveTo(Settings.Height.Preset[1]);
this->getScreenManager()->show<MoveScreen>();
break;
case Button::Menu:
this->getScreenManager()->show<MenuScreen>();
break;
}
}
void HomeScreen::onTick()
{
if (!this->idle && State.CurrentTime - this->showTime >= Config::DisplayIdleTime)
{
this->getScreenManager()->displayOff();
this->idle = true;
}
}
void HomeScreen::drawPreset1()
{
this->drawPreset(0, Settings.Height.Preset[0]);
}
void HomeScreen::drawPreset2()
{
this->drawPreset(Config::DisplayHeight - Metrics::LargeTextLineHeight, Settings.Height.Preset[1]);
}
void HomeScreen::drawNonPresetHeight()
{
auto display = this->getDisplay();
auto y = Metrics::LargeTextLineHeight;
if (State.CurrentHeight != Settings.Height.Preset[0] &&
State.CurrentHeight != Settings.Height.Preset[1])
{
display->setTextColor(Config::ColorNonPresetText);
this->drawHeight(y, State.CurrentHeight);
}
}
void HomeScreen::drawPreset(int16_t y, uint16_t value)
{
auto display = this->getDisplay();
uint16_t textColor;
uint16_t backgroundColor;
uint16_t arrowColor;
// An exact comparison is enough here, the movement code takes care of that if it's "close enough"
if (value == State.CurrentHeight)
{
textColor = Config::ColorPresetSelectedText;
backgroundColor = Config::ColorPresetSelectedBackground;
arrowColor = 0;
}
else
{
textColor = Config::ColorPresetText;
backgroundColor = Config::ColorPresetBackground;
arrowColor = Config::ColorPresetArrow;
}
display->fillRect(0, y, Config::DisplayWidth, Metrics::LargeTextLineHeight, backgroundColor);
if (arrowColor)
this->drawArrowLeft(Metrics::ArrowMargin, y + Metrics::LargeTextLineHArrowYOffset, arrowColor);
display->setTextColor(textColor);
this->drawHeight(y, value);
}
void HomeScreen::drawHeight(int16_t y, uint16_t value)
{
char textValue[6];
getDisplayHeight(&textValue[0], value);
this->printCentered(&textValue[0], y + Metrics::LargeTextLineYOffset);
}
void HomeScreen::drawMenu()
{
auto display = this->getDisplay();
this->drawArrowLeft(Metrics::ArrowMargin, Metrics::MiddleLargeTextLineY, Config::ColorHomeMenuArrow);
display->setTextColor(Config::ColorHomeMenuText);
this->printCentered("Menu", Metrics::MiddleLargeTextLineY + Metrics::LargeTextLineYOffset);
}