mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
+ 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:
parent
9d2e9b43ee
commit
7db3618350
@ -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
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
|
49
src/WallpaperEngine/Core/Projects/CPropertySlider.cpp
Normal file
49
src/WallpaperEngine/Core/Projects/CPropertySlider.cpp
Normal 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";
|
32
src/WallpaperEngine/Core/Projects/CPropertySlider.h
Normal file
32
src/WallpaperEngine/Core/Projects/CPropertySlider.h
Normal 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;
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user