mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-13 21:02:34 +08:00
Added support for usersettings in the bloom
Added casting for integer to double in json loading Added support for dumping all available properties Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
fc150576eb
commit
cf37fe388c
67
main.cpp
67
main.cpp
@ -55,7 +55,8 @@ void print_help (const char* route)
|
||||
<< " --screen-root <screen name>\tDisplay as screen's background" << std::endl
|
||||
<< " --fps <maximum-fps>\tLimits the FPS to the given number, useful to keep battery consumption low" << std::endl
|
||||
<< " --assets-dir <path>\tFolder where the assets are stored" << std::endl
|
||||
<< " --screenshot\t\tTakes a screenshot of the background" << std::endl;
|
||||
<< " --screenshot\t\tTakes a screenshot of the background" << std::endl
|
||||
<< " --list-properties\tList all the available properties and their possible values" << std::endl;
|
||||
}
|
||||
|
||||
std::string stringPathFixes(const std::string& s)
|
||||
@ -318,23 +319,24 @@ int main (int argc, char* argv[])
|
||||
int maximumFPS = 30;
|
||||
bool shouldEnableAudio = true;
|
||||
bool shouldTakeScreenshot = false;
|
||||
bool shouldListPropertiesAndStop = false;
|
||||
FREE_IMAGE_FORMAT screenshotFormat = FIF_UNKNOWN;
|
||||
std::string path;
|
||||
std::string assetsDir;
|
||||
std::string screenshotPath;
|
||||
|
||||
|
||||
static struct option long_options [] = {
|
||||
{"screen-root", required_argument, 0, 'r'},
|
||||
{"pkg", required_argument, 0, 'p'},
|
||||
{"dir", required_argument, 0, 'd'},
|
||||
{"silent", no_argument, 0, 's'},
|
||||
{"volume", required_argument, 0, 'v'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"fps", required_argument, 0, 'f'},
|
||||
{"assets-dir", required_argument, 0, 'a'},
|
||||
{"screenshot", required_argument, 0, 'c'},
|
||||
{nullptr, 0, 0, 0}
|
||||
{"screen-root", required_argument, 0, 'r'},
|
||||
{"pkg", required_argument, 0, 'p'},
|
||||
{"dir", required_argument, 0, 'd'},
|
||||
{"silent", no_argument, 0, 's'},
|
||||
{"volume", required_argument, 0, 'v'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"fps", required_argument, 0, 'f'},
|
||||
{"assets-dir", required_argument, 0, 'a'},
|
||||
{"screenshot", required_argument, 0, 'c'},
|
||||
{"list-properties", no_argument, 0, 'l'},
|
||||
{nullptr, 0, 0, 0}
|
||||
};
|
||||
|
||||
while (true)
|
||||
@ -346,6 +348,10 @@ int main (int argc, char* argv[])
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 'l':
|
||||
shouldListPropertiesAndStop = true;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
screens.emplace_back (optarg);
|
||||
break;
|
||||
@ -412,13 +418,6 @@ int main (int argc, char* argv[])
|
||||
throw std::runtime_error ("Unsupported screenshot format...");
|
||||
}
|
||||
|
||||
// attach signals so if a stop is requested the X11 resources are freed and the program shutsdown gracefully
|
||||
std::signal(SIGINT, signalhandler);
|
||||
std::signal(SIGTERM, signalhandler);
|
||||
|
||||
// initialize glfw
|
||||
initGLFW ();
|
||||
|
||||
std::string homepath = getHomePath ();
|
||||
auto containers = new WallpaperEngine::Assets::CCombinedContainer ();
|
||||
|
||||
@ -516,6 +515,30 @@ int main (int argc, char* argv[])
|
||||
// add containers to the list
|
||||
containers->add (new WallpaperEngine::Assets::CDirectory (assetsDir + "/"));
|
||||
|
||||
// parse the project.json file
|
||||
auto project = WallpaperEngine::Core::CProject::fromFile ("project.json", containers);
|
||||
// go to the right folder so the videos will play
|
||||
if (project->getWallpaper ()->is <WallpaperEngine::Core::CVideo> () == true)
|
||||
chdir (path.c_str ());
|
||||
|
||||
// show properties if required
|
||||
if (shouldListPropertiesAndStop)
|
||||
{
|
||||
for (auto cur : project->getProperties ())
|
||||
{
|
||||
std::cout << cur->dump () << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// attach signals so if a stop is requested the X11 resources are freed and the program shutsdown gracefully
|
||||
std::signal(SIGINT, signalhandler);
|
||||
std::signal(SIGTERM, signalhandler);
|
||||
|
||||
// initialize glfw
|
||||
initGLFW ();
|
||||
|
||||
// auto projection = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> ()->getOrthogonalProjection ();
|
||||
// create the window!
|
||||
// TODO: DO WE NEED TO PASS MONITOR HERE OR ANYTHING?
|
||||
@ -553,12 +576,6 @@ int main (int argc, char* argv[])
|
||||
std::cerr << "Continuing without audio support" << std::endl;
|
||||
}
|
||||
|
||||
// parse the project.json file
|
||||
auto project = WallpaperEngine::Core::CProject::fromFile ("project.json", containers);
|
||||
// go to the right folder so the videos will play
|
||||
if (project->getWallpaper ()->is <WallpaperEngine::Core::CVideo> () == true)
|
||||
chdir (path.c_str ());
|
||||
|
||||
// initialize custom context class
|
||||
WallpaperEngine::Render::CContext* context = new WallpaperEngine::Render::CContext (screens, window, containers);
|
||||
// initialize mouse support
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
||||
#include "WallpaperEngine/Core/Types/FloatColor.h"
|
||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
||||
|
||||
using namespace WallpaperEngine::Core;
|
||||
using namespace WallpaperEngine::Core::Types;
|
||||
@ -11,7 +12,7 @@ CScene::CScene (
|
||||
CContainer* container,
|
||||
Scenes::CCamera* camera,
|
||||
FloatColor ambientColor,
|
||||
bool bloom,
|
||||
CUserSettingBoolean* bloom,
|
||||
double bloomStrength,
|
||||
double bloomThreshold,
|
||||
bool cameraFade,
|
||||
@ -61,7 +62,14 @@ CScene* CScene::fromFile (const std::string& filename, CContainer* container)
|
||||
|
||||
// TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA PARALLAX ARE PRESENT
|
||||
auto ambientcolor = jsonFindDefault <std::string> (*general_it, "ambientcolor", "0 0 0");
|
||||
auto bloom = jsonFindDefault <bool> (*general_it, "bloom", false);
|
||||
auto bloom_it = (*general_it).find ("bloom");
|
||||
CUserSettingBoolean* bloom;
|
||||
|
||||
if (bloom_it == (*general_it).end ())
|
||||
bloom = CUserSettingBoolean::fromScalar (false);
|
||||
else
|
||||
bloom = CUserSettingBoolean::fromJSON (*bloom_it);
|
||||
|
||||
auto bloomstrength = jsonFindUserConfig <float> (*general_it, "bloomstrength", 0.0);
|
||||
auto bloomthreshold = jsonFindUserConfig <float> (*general_it, "bloomthreshold", 0.0);
|
||||
auto camerafade = jsonFindDefault <bool> (*general_it, "camerafade", false);
|
||||
@ -149,7 +157,7 @@ const FloatColor &CScene::getAmbientColor() const
|
||||
|
||||
const bool CScene::isBloom () const
|
||||
{
|
||||
return this->m_bloom;
|
||||
return this->m_bloom->processValue (this->getProject ()->getProperties ());
|
||||
}
|
||||
|
||||
const double CScene::getBloomStrength () const
|
||||
|
@ -50,7 +50,7 @@ namespace WallpaperEngine::Core
|
||||
CContainer* container,
|
||||
Scenes::CCamera* camera,
|
||||
FloatColor ambientColor,
|
||||
bool bloom,
|
||||
CUserSettingBoolean* bloom,
|
||||
double bloomStrength,
|
||||
double bloomThreshold,
|
||||
bool cameraFade,
|
||||
@ -79,7 +79,7 @@ namespace WallpaperEngine::Core
|
||||
|
||||
// data from general section on the json
|
||||
FloatColor m_ambientColor;
|
||||
bool m_bloom;
|
||||
CUserSettingBoolean* m_bloom;
|
||||
double m_bloomStrength;
|
||||
double m_bloomThreshold;
|
||||
bool m_cameraFade;
|
||||
|
@ -7,7 +7,7 @@ CWallpaper::CWallpaper (std::string type) :
|
||||
{
|
||||
}
|
||||
|
||||
CProject* CWallpaper::getProject ()
|
||||
CProject* CWallpaper::getProject () const
|
||||
{
|
||||
return this->m_project;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace WallpaperEngine::Core
|
||||
|
||||
CWallpaper (std::string type);
|
||||
|
||||
CProject* getProject ();
|
||||
CProject* getProject () const;
|
||||
|
||||
protected:
|
||||
friend class CProject;
|
||||
|
@ -105,10 +105,15 @@ template <typename T> T Core::jsonFindDefault (nlohmann::json& data, const char
|
||||
return defaultValue;
|
||||
|
||||
// type checks
|
||||
if ((std::is_same <T, float>::value || std::is_same <T, double>::value) && value->type () != nlohmann::detail::value_t::number_float)
|
||||
if ((std::is_same <T, float>::value || std::is_same <T, double>::value))
|
||||
{
|
||||
fprintf(stderr, "%s is not of type double, returning default value\n", key);
|
||||
return defaultValue;
|
||||
if (value->type () != nlohmann::detail::value_t::number_float &&
|
||||
value->type () != nlohmann::detail::value_t::number_integer &&
|
||||
value->type () != nlohmann::detail::value_t::number_unsigned)
|
||||
{
|
||||
fprintf(stderr, "%s is not of type double or integer, returning default value\n", key);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
else if (std::is_same <T, std::string>::value && value->type () != nlohmann::detail::value_t::string)
|
||||
{
|
||||
|
@ -18,6 +18,8 @@ namespace WallpaperEngine::Core::Projects
|
||||
|
||||
template<class T> bool is () { return this->m_type == T::Type; }
|
||||
|
||||
virtual std::string dump () const = 0;
|
||||
|
||||
const std::string& getName () const;
|
||||
const std::string& getType () const;
|
||||
const std::string& getText () const;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "CPropertyBoolean.h"
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
|
||||
@ -6,18 +8,30 @@ using namespace WallpaperEngine::Core::Projects;
|
||||
CPropertyBoolean* CPropertyBoolean::fromJSON (json data, const std::string& name)
|
||||
{
|
||||
json::const_iterator value = data.find ("value");
|
||||
json::const_iterator text = data.find ("type");
|
||||
std::string text = jsonFindDefault <std::string> (data, "text", "");
|
||||
|
||||
return new CPropertyBoolean (
|
||||
*value,
|
||||
name,
|
||||
*text
|
||||
text
|
||||
);
|
||||
}
|
||||
|
||||
bool CPropertyBoolean::getValue ()
|
||||
{
|
||||
return &this->m_value;
|
||||
return this->m_value;
|
||||
}
|
||||
|
||||
std::string CPropertyBoolean::dump () const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss
|
||||
<< this->m_name << " - boolean" << std::endl
|
||||
<< "\t" << "Description: " << this->m_text << std::endl
|
||||
<< "\t" << "Value: " << this->m_value;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
CPropertyBoolean::CPropertyBoolean (bool value, const std::string& name, const std::string& text) :
|
||||
|
@ -12,6 +12,7 @@ namespace WallpaperEngine::Core::Projects
|
||||
static CPropertyBoolean* fromJSON (json data, const std::string& name);
|
||||
|
||||
bool getValue ();
|
||||
std::string dump () const override;
|
||||
|
||||
static const std::string Type;
|
||||
|
||||
|
@ -1,25 +1,58 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "CPropertyColor.h"
|
||||
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
|
||||
CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name)
|
||||
{
|
||||
auto value = data.find ("value");
|
||||
auto text = data.find ("type");
|
||||
std::string value = *jsonFindRequired (data, "value", "Color property must have a value");
|
||||
std::string text = jsonFindDefault <std::string> (data, "text", "");
|
||||
FloatColor color (0, 0, 0, 0);
|
||||
|
||||
if (value.find ('.') == std::string::npos && value != "0 0 0" && value != "1 1 1")
|
||||
{
|
||||
IntegerColor intcolor = WallpaperEngine::Core::aToColori (value);
|
||||
|
||||
color.r = intcolor.r / 255.0;
|
||||
color.g = intcolor.g / 255.0;
|
||||
color.b = intcolor.b / 255.0;
|
||||
color.a = intcolor.a / 255.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = WallpaperEngine::Core::aToColorf (value);
|
||||
}
|
||||
|
||||
return new CPropertyColor (
|
||||
WallpaperEngine::Core::aToColori (*value),
|
||||
color,
|
||||
name,
|
||||
*text
|
||||
text
|
||||
);
|
||||
}
|
||||
|
||||
const IntegerColor& CPropertyColor::getValue () const
|
||||
const FloatColor& CPropertyColor::getValue () const
|
||||
{
|
||||
return this->m_color;
|
||||
}
|
||||
|
||||
CPropertyColor::CPropertyColor (IntegerColor color, const std::string& name, const std::string& text) :
|
||||
std::string CPropertyColor::dump () const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss
|
||||
<< this->m_name << " - color" << std::endl
|
||||
<< "\t" << "Description: " << this->m_text << std::endl
|
||||
<< "\t"
|
||||
<< "R: " << this->m_color.r
|
||||
<< " G: " << this->m_color.g
|
||||
<< " B: " << this->m_color.b
|
||||
<< " A: " << this->m_color.a;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
CPropertyColor::CPropertyColor (FloatColor color, const std::string& name, const std::string& text) :
|
||||
CProperty (name, Type, text),
|
||||
m_color (color)
|
||||
{
|
||||
|
@ -14,13 +14,14 @@ namespace WallpaperEngine::Core::Projects
|
||||
public:
|
||||
static CPropertyColor* fromJSON (json data, const std::string& name);
|
||||
|
||||
const IntegerColor& getValue () const;
|
||||
const FloatColor& getValue () const;
|
||||
std::string dump () const override;
|
||||
|
||||
static const std::string Type;
|
||||
|
||||
private:
|
||||
CPropertyColor (IntegerColor color, const std::string& name, const std::string& text);
|
||||
CPropertyColor (FloatColor color, const std::string& name, const std::string& text);
|
||||
|
||||
IntegerColor m_color;
|
||||
FloatColor m_color;
|
||||
};
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "CPropertyCombo.h"
|
||||
|
||||
#include <utility>
|
||||
@ -8,12 +10,12 @@ using namespace WallpaperEngine::Core::Projects;
|
||||
CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name)
|
||||
{
|
||||
auto value = data.find ("value");
|
||||
auto text = data.find ("type");
|
||||
std::string text = jsonFindDefault <std::string> (data, "text", "");
|
||||
auto options = jsonFindRequired (data, "options", "Options for a property combo is required");
|
||||
|
||||
CPropertyCombo* combo = new CPropertyCombo (
|
||||
name,
|
||||
*text,
|
||||
text,
|
||||
*value
|
||||
);
|
||||
|
||||
@ -52,6 +54,24 @@ const std::string& CPropertyCombo::getValue () const
|
||||
return this->m_defaultValue;
|
||||
}
|
||||
|
||||
std::string CPropertyCombo::dump () const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss
|
||||
<< this->m_name << " - combolist" << std::endl
|
||||
<< "\t" << "Description: " << this->m_text << std::endl
|
||||
<< "\t" << "Value: " << this->m_defaultValue << std::endl
|
||||
<< "\t\t" << "Posible values:" << std::endl;
|
||||
|
||||
for (auto cur : this->m_values)
|
||||
{
|
||||
ss << "\t\t" << cur->label << " -> " << cur->value << std::endl;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void CPropertyCombo::addValue (std::string label, std::string value)
|
||||
{
|
||||
CPropertyComboValue* prop = new CPropertyComboValue;
|
||||
|
@ -19,6 +19,7 @@ namespace WallpaperEngine::Core::Projects
|
||||
static CPropertyCombo* fromJSON (json data, const std::string& name);
|
||||
|
||||
const std::string& getValue () const;
|
||||
std::string dump () const override;
|
||||
|
||||
static const std::string Type;
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <sstream>
|
||||
#include "CPropertySlider.h"
|
||||
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
@ -5,7 +6,7 @@ using namespace WallpaperEngine::Core::Projects;
|
||||
CPropertySlider* CPropertySlider::fromJSON (json data, const std::string& name)
|
||||
{
|
||||
auto value = data.find ("value");
|
||||
auto text = data.find ("type");
|
||||
std::string text = jsonFindDefault <std::string> (data, "text", "");
|
||||
auto min = jsonFindDefault(data, "min", 0.0);
|
||||
auto max = jsonFindDefault (data, "max", 0.0);
|
||||
auto step = jsonFindDefault (data, "step", 0.0);
|
||||
@ -13,7 +14,7 @@ CPropertySlider* CPropertySlider::fromJSON (json data, const std::string& name)
|
||||
return new CPropertySlider (
|
||||
*value,
|
||||
name,
|
||||
*text,
|
||||
text,
|
||||
min,
|
||||
max,
|
||||
step
|
||||
@ -40,6 +41,21 @@ const double& CPropertySlider::getStep () const
|
||||
return this->m_step;
|
||||
}
|
||||
|
||||
std::string CPropertySlider::dump () const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss
|
||||
<< this->m_name << " - slider" << std::endl
|
||||
<< "\t" << "Description: " << this->m_text << std::endl
|
||||
<< "\t" << "Value: " << this->m_value << std::endl
|
||||
<< "\t" << "Minimum value: " << this->m_min << std::endl
|
||||
<< "\t" << "Maximum value: " << this->m_max << std::endl
|
||||
<< "\t" << "Step: " << this->m_step << std::endl;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
CPropertySlider::CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step) :
|
||||
CProperty (name, Type, text),
|
||||
m_value (value), m_min (min), m_max (max), m_step (step)
|
||||
|
@ -18,6 +18,7 @@ namespace WallpaperEngine::Core::Projects
|
||||
const double& getMinValue () const;
|
||||
const double& getMaxValue () const;
|
||||
const double& getStep () const;
|
||||
std::string dump () const override;
|
||||
|
||||
static const std::string Type;
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <sstream>
|
||||
#include "CPropertyText.h"
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
|
||||
@ -13,6 +14,17 @@ CPropertyText* CPropertyText::fromJSON (json data, const std::string& name)
|
||||
);
|
||||
}
|
||||
|
||||
std::string CPropertyText::dump () const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss
|
||||
<< this->m_name << " - text" << std::endl
|
||||
<< "\t" << "Value: " << this->m_text;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
CPropertyText::CPropertyText (const std::string& name, const std::string& text) :
|
||||
CProperty (name, Type, text)
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ namespace WallpaperEngine::Core::Projects
|
||||
{
|
||||
public:
|
||||
static CPropertyText* fromJSON (json data, const std::string& name);
|
||||
std::string dump () const override;
|
||||
|
||||
static const std::string Type;
|
||||
|
||||
|
@ -5,24 +5,24 @@ namespace WallpaperEngine::Core::Types
|
||||
class FloatColor
|
||||
{
|
||||
public:
|
||||
FloatColor (float r, float g, float b, float a) :
|
||||
FloatColor (double r, double g, double b, double a) :
|
||||
r(r), g(g), b(b), a(a) { }
|
||||
|
||||
/**
|
||||
* The red color
|
||||
*/
|
||||
float r;
|
||||
double r;
|
||||
/**
|
||||
* The green color
|
||||
*/
|
||||
float g;
|
||||
double g;
|
||||
/**
|
||||
* The blue color
|
||||
*/
|
||||
float b;
|
||||
double b;
|
||||
/**
|
||||
* The alpha
|
||||
*/
|
||||
float a;
|
||||
double a;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user