+ Added parsing for shader constants that have extra information

+ Added support for slider properties

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2021-11-29 13:56:50 +01:00
parent 9d2e9b43ee
commit 7db3618350
5 changed files with 110 additions and 10 deletions

View File

@ -121,6 +121,8 @@ add_executable(
src/WallpaperEngine/Core/Projects/CPropertyColor.cpp src/WallpaperEngine/Core/Projects/CPropertyColor.cpp
src/WallpaperEngine/Core/Projects/CPropertyBoolean.h src/WallpaperEngine/Core/Projects/CPropertyBoolean.h
src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp
src/WallpaperEngine/Core/Projects/CPropertySlider.h
src/WallpaperEngine/Core/Projects/CPropertySlider.cpp
src/WallpaperEngine/Core/Scenes/CCamera.cpp src/WallpaperEngine/Core/Scenes/CCamera.cpp
src/WallpaperEngine/Core/Scenes/CCamera.h src/WallpaperEngine/Core/Scenes/CCamera.h

View File

@ -1,6 +1,7 @@
#include "CEffect.h" #include "CEffect.h"
#include <utility> #include <utility>
#include <iostream>
#include "WallpaperEngine/Core/Objects/CImage.h" #include "WallpaperEngine/Core/Objects/CImage.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
@ -149,20 +150,36 @@ void CEffect::constantsFromJSON (json::const_iterator constants_it, Core::Object
for (; cur != end; cur ++) for (; cur != end; cur ++)
{ {
json::const_iterator val = cur;
Effects::Constants::CShaderConstant* constant = nullptr; Effects::Constants::CShaderConstant* constant = nullptr;
if ((*cur).is_number_float () == true) // if the constant is an object, that means the constant has some extra information
// for the UI, take the value, which is what we need
if ((*cur).is_object () == true)
{ {
constant = new Effects::Constants::CShaderConstantFloat ((*cur).get <float> ()); val = (*cur).find ("value");
if (val == (*cur).end ())
{
std::cerr << "Found object for shader constant without \"value\" member" << std::endl;
continue;
}
} }
else if ((*cur).is_number_integer () == true)
if ((*val).is_number_float () == true)
{ {
constant = new Effects::Constants::CShaderConstantInteger ((*cur).get <int> ()); constant = new Effects::Constants::CShaderConstantFloat ((*val).get <float> ());
} }
else if ((*cur).is_string () == true) else if ((*val).is_number_integer () == true)
{
constant = new Effects::Constants::CShaderConstantInteger ((*val).get <int> ());
}
else if ((*val).is_string () == true)
{ {
// try a vector 4 first, then a vector3 and then a vector 2 // try a vector 4 first, then a vector3 and then a vector 2
constant = new Effects::Constants::CShaderConstantVector4 (WallpaperEngine::Core::aToVector4 (*cur)); constant = new Effects::Constants::CShaderConstantVector4 (WallpaperEngine::Core::aToVector4 (*val));
} }
else else
{ {

View File

@ -1,5 +1,6 @@
#include "CProperty.h" #include "CProperty.h"
#include "CPropertyColor.h" #include "CPropertyColor.h"
#include "CPropertySlider.h"
#include "CPropertyBoolean.h" #include "CPropertyBoolean.h"
using namespace WallpaperEngine::Core::Projects; using namespace WallpaperEngine::Core::Projects;
@ -11,14 +12,13 @@ CProperty* CProperty::fromJSON (json data, const std::string& name)
auto text = data.find ("text"); auto text = data.find ("text");
if (*type == CPropertyColor::Type) if (*type == CPropertyColor::Type)
{
return CPropertyColor::fromJSON (data, name); return CPropertyColor::fromJSON (data, name);
}
if (*type == CPropertyBoolean::Type) if (*type == CPropertyBoolean::Type)
{
return CPropertyBoolean::fromJSON (data, name); return CPropertyBoolean::fromJSON (data, name);
}
if (*type == CPropertySlider::Type)
return CPropertySlider::fromJSON (data, name);
throw std::runtime_error ("Unexpected type for property"); throw std::runtime_error ("Unexpected type for property");
} }

View File

@ -0,0 +1,49 @@
#include "CPropertySlider.h"
using namespace WallpaperEngine::Core::Projects;
CPropertySlider* CPropertySlider::fromJSON (json data, const std::string& name)
{
auto value = data.find ("value");
auto text = data.find ("type");
auto min = jsonFindDefault(data, "min", 0.0);
auto max = jsonFindDefault (data, "max", 0.0);
auto step = jsonFindDefault (data, "step", 0.0);
return new CPropertySlider (
*value,
name,
*text,
min,
max,
step
);
}
const double& CPropertySlider::getValue () const
{
return this->m_value;
}
const double& CPropertySlider::getMinValue () const
{
return this->m_min;
}
const double& CPropertySlider::getMaxValue () const
{
return this->m_max;
}
const double& CPropertySlider::getStep () const
{
return this->m_step;
}
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)
{
}
const std::string CPropertySlider::Type = "slider";

View File

@ -0,0 +1,32 @@
#pragma once
#include "CProperty.h"
#include "WallpaperEngine/Core/Core.h"
namespace WallpaperEngine::Core::Projects
{
using json = nlohmann::json;
using namespace WallpaperEngine::Core::Types;
class CPropertySlider : public CProperty
{
public:
static CPropertySlider* fromJSON (json data, const std::string& name);
const double& getValue () const;
const double& getMinValue () const;
const double& getMaxValue () const;
const double& getStep () const;
static const std::string Type;
private:
CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step);
double m_value;
double m_min;
double m_max;
double m_step;
};
};