reVeno/Source/Veno/GUI/Theme/Theme.cpp

115 lines
2.4 KiB
C++
Raw Normal View History

2020-04-03 13:23:19 +02:00
//
// Created by versustune on 01.03.20.
//
#include "Theme.h"
#include "ThemePresets.cpp"
2020-06-14 21:14:28 +02:00
#include "../../Core/Config.h"
2020-04-03 13:23:19 +02:00
Theme::Theme (std::shared_ptr<PropertiesFile> file)
{
m_configFile = file;
2020-04-03 13:23:19 +02:00
}
Theme::~Theme ()
{
2020-06-14 21:14:28 +02:00
m_colours.clear();
m_configFile.reset();
2020-04-03 13:23:19 +02:00
}
void Theme::setColour (ThemeColour index, Colour* colour)
{
auto c = m_colours[index];
if (c)
{
2020-04-03 13:23:19 +02:00
delete c;
m_colours[index] = colour;
}
else
{
m_colours[index] = colour;
2020-04-03 13:23:19 +02:00
}
2020-06-14 21:14:28 +02:00
m_configFile->setValue(ThemeColourToString(index), colour->toString());
m_configFile->setNeedsToBeSaved(true);
2020-04-03 13:23:19 +02:00
}
void Theme::init ()
{
2020-06-14 21:14:28 +02:00
getColourFromConfig(ThemeColour::bg);
getColourFromConfig(ThemeColour::bg_two);
getColourFromConfig(ThemeColour::accent);
getColourFromConfig(ThemeColour::accent_two);
getColourFromConfig(ThemeColour::warning);
getColourFromConfig(ThemeColour::clip);
getColourFromConfig(ThemeColour::lcd_bg);
getColourFromConfig(ThemeColour::lcd);
2020-04-03 13:23:19 +02:00
}
void Theme::getColourFromConfig (ThemeColour index)
{
2020-06-14 21:14:28 +02:00
std::string key = ThemeColourToString(index);
if (m_configFile->containsKey(key))
{
2020-06-14 21:14:28 +02:00
auto baseColour = Colour::fromString(m_configFile->getValue(key));
auto* colour = new Colour(baseColour.getRed(), baseColour.getGreen(), baseColour.getBlue());
2020-06-13 10:56:20 +02:00
delete m_colours[index];
m_colours[index] = colour;
}
else
{
2020-06-13 10:56:20 +02:00
// should only trigger if config is broken or empty :)
2020-06-14 21:14:28 +02:00
setLEDTheme(this);
2020-06-13 10:56:20 +02:00
}
}
Colour Theme::getColour (ThemeColour index)
{
if (m_colours[index] != nullptr)
{
2020-06-13 10:56:20 +02:00
return *m_colours[index];
}
2020-06-14 21:14:28 +02:00
return Colour(255, 255, 255);
2020-06-13 10:56:20 +02:00
}
void Theme::setColourThemeById (int id)
{
switch (id)
{
2020-06-13 10:56:20 +02:00
case 1:
2020-06-14 21:14:28 +02:00
setLEDTheme(this);
2020-06-13 10:56:20 +02:00
break;
case 2:
2020-06-14 21:14:28 +02:00
setOrangeDreamTheme(this);
2020-06-13 10:56:20 +02:00
break;
case 3:
2020-06-14 21:14:28 +02:00
setBloodTheme(this);
2020-06-13 10:56:20 +02:00
break;
case 4:
2020-06-14 21:14:28 +02:00
setOceanTheme(this);
2020-06-13 10:56:20 +02:00
default:
break;
2020-04-03 13:23:19 +02:00
}
}
2020-06-14 21:14:28 +02:00
void Theme::setDefault (const std::string& value)
{
if (value == "LED")
{
setLEDTheme(this);
}
if (value == "Blood")
{
setBloodTheme(this);
}
if (value == "Orange Dream")
{
setOrangeDreamTheme(this);
}
if (value == "Ocean")
{
setOceanTheme(this);
}
Config::getInstance()->repaintAll();
}