Skip to content
Draft
33 changes: 15 additions & 18 deletions Firmware/UI/Screens/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@
#include "../MenuSystem.h"

// TODO: Add assignment of menu system to IMenu
MainPage::MainPage(IUSBDevice* cdcDevice) : IMenu(cdcDevice), _backgroundColor(Color565::MenuBackground)
MainPage::MainPage(IUSBDevice* cdcDevice) :
IMenu(cdcDevice), _backgroundColor(Color565::MenuBackground), _fpsButton(10, 0, 90, "FPS", false),
_analogGainButton(115, 0, 90, "A. Gain", false), _digitalGainButton(220, 0, 90, "D. Gain", false),
_menuButton(10, 210, 90, "MENU", true, ButtonType::BUTTON), _shutterButton(115, 179, 90, "Shutter", true),
_whiteBalanceButton(220, 179, 90, "WB", true)
{
SetupButtons();
}

void MainPage::SetupButtons()
{
// Top row
_fpsButton = MainPageButton(10, 0, 90, "FPS", false);

_analogGainButton = MainPageButton(115, 0, 90, "A. Gain", false);
_analogGainButton.SetHandler(&AnalogGainButtonHandler);

_digitalGainButton = MainPageButton(220, 0, 90, "D. Gain", false),
_digitalGainButton.SetHandler(&DigitalGainButtonHandler);

// Bottom row
_menuButton = MainPageButton(10, 210, 90, "MENU", true, ButtonType::BUTTON);
_menuButton.SetLabelHeight(30);
_menuButton.SetLabelFont(Font::FreeSans12pt7b);
_menuButton.SetHandler(&MenuButtonHandler);

_shutterButton = MainPageButton(115, 179, 90, "Shutter", true);
_whiteBalanceButton = MainPageButton(220, 179, 90, "WB", true);
}

Color565 MainPage::GetBackgroundColor()
Expand Down Expand Up @@ -81,45 +78,45 @@ void MainPage::Update(Button button, int8_t knob, IMenuSystem* menuSystem)
{
case Button::BUTTON_1_UP:
_fpsButton.SetValue((char*)"1U");
_fpsButton.SetHighlighted(false);
_fpsButton.SetState(ButtonState::Default);
break;
case Button::BUTTON_1_DOWN:
_fpsButton.SetValue((char*)"1D");
_fpsButton.SetHighlighted(true);
_fpsButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_2_UP:
//_fpsButton.SetValue((char*)"2");
_analogGainButton.SetHighlighted(false);
_analogGainButton.SetState(ButtonState::Default);
_analogGainButton.Activate(this);
// _usbDevice->Send((uint8_t*)"Button 2\r\n", 10);
break;
case Button::BUTTON_2_DOWN:
_analogGainButton.SetHighlighted(true);
_analogGainButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_3_UP:
//_fpsButton.SetValue((char*)"3");
_digitalGainButton.SetHighlighted(false);
_digitalGainButton.SetState(ButtonState::Default);
_digitalGainButton.Activate(this);
break;
case Button::BUTTON_3_DOWN:
_fpsButton.SetValue((char*)"3");
_digitalGainButton.SetHighlighted(true);
_digitalGainButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_4_UP:
//_menuButton.Activate(this);
_menuButton.SetHighlighted(false);
_menuButton.SetState(ButtonState::Default);
menuSystem->SetCurrentScreen(AvailableScreens::MainMenu);
break;
case Button::BUTTON_4_DOWN:
_menuButton.SetHighlighted(true);
_menuButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_6_UP:
//_menuButton.Activate(this);
_whiteBalanceButton.SetHighlighted(false);
_whiteBalanceButton.SetState(ButtonState::Default);
menuSystem->SetCurrentScreen(AvailableScreens::WhiteBalance);
break;
case Button::BUTTON_6_DOWN:
_whiteBalanceButton.SetHighlighted(true);
_whiteBalanceButton.SetState(ButtonState::Highlighted);
break;
default:
break;
Expand Down
7 changes: 4 additions & 3 deletions Firmware/UI/Screens/NumericValueScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class NumericValueScreen : public IScreen

// This is the primary button in this menu
//_setButton.SetHandler(&SetButtonHandler);
_setButton.SetBackgroundColor((uint16_t)Color565::AXIOM_Orange);
_setButton.SetColor(ButtonState::Default, PushButton::Colors::Background,
static_cast<uint16_t>(Color565::AXIOM_Orange));
_bottomButtonBar.SetButton(ButtonPosition::Right, &_setButton);

_bottomButtonBar.SetButton(ButtonPosition::Center, &_liveButton);
Expand Down Expand Up @@ -119,12 +120,12 @@ class NumericValueScreen : public IScreen

void SetSetButtonPressed(bool pressed)
{
_setButton.SetHighlighted(pressed);
_setButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default);
}

void SetCancelButtonPressed(bool pressed)
{
_cancelButton.SetHighlighted(pressed);
_cancelButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default);
}

void Draw(IPainter* painter) override
Expand Down
7 changes: 4 additions & 3 deletions Firmware/UI/Screens/ParameterListScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class ParameterListScreen : public IScreen

// This is the primary button in this menu
//_setButton.SetHandler(&SetButtonHandler);
_setButton.SetBackgroundColor((uint16_t)Color565::AXIOM_Orange);
_setButton.SetColor(ButtonState::Default, PushButton::Colors::Background,
static_cast<uint16_t>(Color565::AXIOM_Orange));
_bottomButtonBar.SetButton(ButtonPosition::Right, &_setButton);
}

Expand All @@ -63,12 +64,12 @@ class ParameterListScreen : public IScreen

void SetSetButtonPressed(bool pressed)
{
_setButton.SetHighlighted(pressed);
_setButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default);
}

void SetCancelButtonPressed(bool pressed)
{
_cancelButton.SetHighlighted(pressed);
_cancelButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default);
}

void SetHighlighted(uint8_t highlightindex)
Expand Down
19 changes: 10 additions & 9 deletions Firmware/UI/Screens/WhiteBalanceScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ WhiteBalanceScreen::WhiteBalanceScreen(IUSBDevice* usbDevice) :

// This is the primary button in this menu
_setButton.SetHandler(&SetButtonHandler);
_setButton.SetBackgroundColor((uint16_t)Color565::AXIOM_Orange);
_setButton.SetColor(ButtonState::Default, PushButton::Colors::Background,
static_cast<uint16_t>(Color565::AXIOM_Orange));
_bottomButtonBar.SetButton(ButtonPosition::Right, &_setButton);

//_leftButtonBar.SetButton(ButtonPosition::Left, &_homeButton); //already done in IScreen
Expand Down Expand Up @@ -74,30 +75,30 @@ void WhiteBalanceScreen::Update(Button button, int8_t knob, IMenuSystem* menuSys
switch (button)
{
case Button::BUTTON_4_DOWN:
_cancelButton.SetHighlighted(true);
_cancelButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_4_UP:
_cancelButton.SetHighlighted(false);
_cancelButton.SetState(ButtonState::Default);
menuSystem->SetCurrentScreen(AvailableScreens::MainPage);
break;
case Button::BUTTON_5_DOWN:
_addPresetButton.SetHighlighted(true);
_addPresetButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_5_UP:
_addPresetButton.SetHighlighted(false);
_addPresetButton.SetState(ButtonState::Default);
break;
case Button::BUTTON_6_DOWN:
_setButton.SetHighlighted(true);
_setButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_6_UP:
_setButton.SetHighlighted(false);
_setButton.SetState(ButtonState::Default);
menuSystem->SetCurrentScreen(AvailableScreens::MainPage);
break;
case Button::BUTTON_7_DOWN:
_homeButton.SetHighlighted(true);
_homeButton.SetState(ButtonState::Highlighted);
break;
case Button::BUTTON_7_UP:
_homeButton.SetHighlighted(false);
_homeButton.SetState(ButtonState::Default);
menuSystem->SetCurrentScreen(AvailableScreens::MainPage);
break;
default:
Expand Down
49 changes: 47 additions & 2 deletions Firmware/UI/Widgets/IButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,39 @@

#include "IWidget.h"

enum class ButtonState : uint8_t
{
Default = 0,
Highlighted = 1,
Disabled = 2,
};

class IButton : public IWidget
{
// void* -> sender, e.g. MainPage
void (*_handlerPtr)(void*);

// Might want to move these three into implementers instead,
// to allow for correct sizes

uint16_t* _colorPtr;
const uint8_t _colorsPerState;
const uint8_t _stateCount;
ButtonState _currentState;

// index: every derived class is supposed to define its own enum for colorMeanings
uint8_t Index(ButtonState state, uint8_t index)
{
return static_cast<uint8_t>(state) * _colorsPerState + index;
}

public:
IButton(uint16_t x = 0, uint16_t y = 0, uint16_t width = 0, uint16_t height = 0) :
IWidget(x, y, width, height), _handlerPtr(nullptr)
// TODO: add startState to constructor?
IButton(uint8_t stateCount, uint8_t colorsPerState, uint16_t* colorPointer, uint16_t x = 0, uint16_t y = 0,
uint16_t width = 0, uint16_t height = 0) :
IWidget(x, y, width, height),
_handlerPtr(nullptr), _currentState(ButtonState::Default), _colorPtr(colorPointer),
_colorsPerState(colorsPerState), _stateCount(colorsPerState)
{
}

Expand All @@ -30,6 +55,26 @@ class IButton : public IWidget
{
_handlerPtr(sender);
}

void SetColor(ButtonState state, uint8_t index, uint16_t color)
{
_colorPtr[Index(state, index)] = color;
}

uint16_t GetColor(ButtonState state, uint8_t index)
{
return _colorPtr[Index(state, index)];
}

uint16_t GetCurrentColor(uint8_t index)
{
return GetColor(_currentState, index);
}

void SetState(ButtonState state)
{
_currentState = state;
}
};

#endif /* IBUTTON_H */
94 changes: 20 additions & 74 deletions Firmware/UI/Widgets/ImageButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@ class ImageButton : public IButton
const char* _label;

uint8_t _cornerRadius;
bool _highlighted;

// Color Defintions
uint16_t _textColor;
uint16_t _imageColor;
uint16_t _backgroundColor;

uint16_t _textHighlightColor;
uint16_t _imageHighlightColor;
uint16_t _backgroundHighlightColor;

uint16_t _currentTextColor;
uint16_t _currentImageColor;
uint16_t _currentBackgroundColor;
// Color Definitions
static constexpr uint8_t _stateCount = 3;
static constexpr uint8_t _colorsPerState = 3;
uint16_t _colors[_stateCount * _colorsPerState];

uint8_t _imagePositionX;
uint8_t _textPositionX;
Expand All @@ -42,13 +33,20 @@ class ImageButton : public IButton
ButtonStyle _buttonStyle;

public:
enum Colors : uint8_t
{
Text = 0,
Background = 1,
Image = 2,
};

explicit ImageButton(const Icon* icon, uint16_t x = 0, uint16_t y = 0, uint16_t width = 0, uint16_t height = 0) :
IButton(x, y, width, height), _image(icon), _cornerRadius(3), _highlighted(false),
_imageColor((uint16_t)Color565::Black), _currentImageColor(_imageColor),
_backgroundHighlightColor((uint16_t)Color565::AXIOM_Blue),
_currentBackgroundColor(utils::RGB565(220, 220, 220)), _backgroundColor(utils::RGB565(220, 220, 220)),
IButton(_stateCount, _colorsPerState, _colors, x, y, width, height), _image(icon), _cornerRadius(3),
_buttonStyle(ButtonStyle::Icon)
{
SetColor(ButtonState::Default, Colors::Image, static_cast<uint16_t>(Color565::Black));
SetColor(ButtonState::Default, Colors::Background, utils::RGB565(220, 220, 220));
SetColor(ButtonState::Highlighted, Colors::Background, static_cast<uint16_t>(Color565::AXIOM_Blue));
_totalWidth = _image->Width;
_textPositionY = _height / 2;
_imagePositionX = _width / 2 - _totalWidth / 2;
Expand Down Expand Up @@ -88,7 +86,7 @@ class ImageButton : public IButton

virtual void Draw(IPainter* painter) override
{
painter->DrawFillRoundRectangle(_x, _y, _width, _height, _cornerRadius, _currentBackgroundColor);
painter->DrawFillRoundRectangle(_x, _y, _width, _height, _cornerRadius, GetCurrentColor(Colors::Background));

if (_buttonStyle == ButtonStyle::IconAndText)
{
Expand All @@ -99,66 +97,14 @@ class ImageButton : public IButton
_textPositionY +=
painter->GetCurrentFontHeight() / 2; // TODO: This should not be recalculated with every redraw

painter->DrawIcon(_image, _x + _imagePositionX, _y + _height / 2 - _image->Height / 2, _currentImageColor);
painter->DrawText(_x + _textPositionX, _y + _textPositionY, _label, _currentTextColor,
painter->DrawIcon(_image, _x + _imagePositionX, _y + _height / 2 - _image->Height / 2,
GetCurrentColor(Colors::Image));
painter->DrawText(_x + _textPositionX, _y + _textPositionY, _label, GetCurrentColor(Colors::Text),
TextAlign::TEXT_ALIGN_LEFT, strlen(_label));
} else if (_buttonStyle == ButtonStyle::Icon)
{
painter->DrawIcon(_image, _x + _width / 2 - _image->Width / 2, _y + _height / 2 - _image->Height / 2,
_currentImageColor);
}
}

void SetBackgroundColor(uint16_t color)
{
_backgroundColor = color;
SetHighlighted(_highlighted);
}

void SetImageColor(uint16_t color)
{
_imageColor = color;
SetHighlighted(_highlighted);
}

void SetTextColor(uint16_t color)
{
_textColor = color;
SetHighlighted(_highlighted);
}

void SetHighlightBackgroundColor(uint16_t color)
{
_backgroundHighlightColor = color;
SetHighlighted(_highlighted);
}

void SetHighlightImageColor(uint16_t color)
{
_imageHighlightColor = color;
SetHighlighted(_highlighted);
}

void SetHighlightTextColor(uint16_t color)
{
_textHighlightColor = color;
SetHighlighted(_highlighted);
}

void SetHighlighted(bool highlighted)
{
_highlighted = highlighted;
if (highlighted)
{
_currentImageColor = _imageHighlightColor;
_currentBackgroundColor = _backgroundHighlightColor;
_currentTextColor = _textHighlightColor;

} else
{
_currentImageColor = _imageColor;
_currentBackgroundColor = _backgroundColor;
_currentTextColor = _textColor;
GetCurrentColor(Colors::Image));
}
}
};
Expand Down
Loading