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

93 lines
2 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"
Theme::Theme (std::shared_ptr<PropertiesFile> file)
{
m_configFile = file;
2020-04-03 13:23:19 +02:00
}
Theme::~Theme ()
{
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
}
m_configFile->setValue (ThemeColourToString (index), colour->toString ());
m_configFile->save ();
2020-04-03 13:23:19 +02:00
}
void Theme::init ()
{
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)
{
std::string key = ThemeColourToString (index);
if (m_configFile->containsKey (key))
{
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 :)
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];
}
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:
setLEDTheme (this);
2020-06-13 10:56:20 +02:00
break;
case 2:
setOrangeDreamTheme (this);
2020-06-13 10:56:20 +02:00
break;
case 3:
setBloodTheme (this);
2020-06-13 10:56:20 +02:00
break;
case 4:
setOceanTheme (this);
2020-06-13 10:56:20 +02:00
default:
break;
2020-04-03 13:23:19 +02:00
}
}