mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 05:46:48 +08:00
Compare commits
3 Commits
fae2b5e01e
...
fc865499fc
Author | SHA1 | Date | |
---|---|---|---|
![]() |
fc865499fc | ||
![]() |
af02d82ea9 | ||
![]() |
f400b2abd9 |
@ -400,19 +400,6 @@ add_executable(
|
|||||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
|
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
|
||||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h
|
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Projects/CProperty.h
|
|
||||||
src/WallpaperEngine/Core/Projects/CProperty.cpp
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyColor.h
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyColor.cpp
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyBoolean.h
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertySlider.h
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertySlider.cpp
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyCombo.h
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyText.h
|
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyText.cpp
|
|
||||||
|
|
||||||
src/WallpaperEngine/Data/Model/Types.h
|
src/WallpaperEngine/Data/Model/Types.h
|
||||||
src/WallpaperEngine/Data/Model/Project.h
|
src/WallpaperEngine/Data/Model/Project.h
|
||||||
src/WallpaperEngine/Data/Model/Wallpaper.h
|
src/WallpaperEngine/Data/Model/Wallpaper.h
|
||||||
@ -423,6 +410,7 @@ add_executable(
|
|||||||
src/WallpaperEngine/Data/Model/UserSetting.h
|
src/WallpaperEngine/Data/Model/UserSetting.h
|
||||||
src/WallpaperEngine/Data/Model/DynamicValue.h
|
src/WallpaperEngine/Data/Model/DynamicValue.h
|
||||||
src/WallpaperEngine/Data/Model/DynamicValue.cpp
|
src/WallpaperEngine/Data/Model/DynamicValue.cpp
|
||||||
|
src/WallpaperEngine/Data/Model/Property.h
|
||||||
src/WallpaperEngine/Data/Utils/TypeCaster.cpp
|
src/WallpaperEngine/Data/Utils/TypeCaster.cpp
|
||||||
src/WallpaperEngine/Data/Utils/TypeCaster.h
|
src/WallpaperEngine/Data/Utils/TypeCaster.h
|
||||||
src/WallpaperEngine/Data/Utils/SFINAE.h
|
src/WallpaperEngine/Data/Utils/SFINAE.h
|
||||||
@ -440,6 +428,8 @@ add_executable(
|
|||||||
src/WallpaperEngine/Data/Parsers/ModelParser.h
|
src/WallpaperEngine/Data/Parsers/ModelParser.h
|
||||||
src/WallpaperEngine/Data/Parsers/ShaderConstantParser.cpp
|
src/WallpaperEngine/Data/Parsers/ShaderConstantParser.cpp
|
||||||
src/WallpaperEngine/Data/Parsers/ShaderConstantParser.h
|
src/WallpaperEngine/Data/Parsers/ShaderConstantParser.h
|
||||||
|
src/WallpaperEngine/Data/Parsers/PropertyParser.cpp
|
||||||
|
src/WallpaperEngine/Data/Parsers/PropertyParser.h
|
||||||
src/WallpaperEngine/Data/Builders/UserSettingBuilder.h
|
src/WallpaperEngine/Data/Builders/UserSettingBuilder.h
|
||||||
src/WallpaperEngine/Data/Builders/VectorBuilder.cpp
|
src/WallpaperEngine/Data/Builders/VectorBuilder.cpp
|
||||||
src/WallpaperEngine/Data/Builders/VectorBuilder.h
|
src/WallpaperEngine/Data/Builders/VectorBuilder.h
|
||||||
|
@ -10,12 +10,11 @@
|
|||||||
#include "WallpaperEngine/Render/CRenderContext.h"
|
#include "WallpaperEngine/Render/CRenderContext.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Parsers/ProjectParser.h"
|
#include "WallpaperEngine/Data/Parsers/ProjectParser.h"
|
||||||
#include "WallpaperEngine/Data/Dumpers/StringPrinter.h"
|
#include "WallpaperEngine/Data/Dumpers/StringPrinter.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
||||||
|
#include "WallpaperEngine/Data/Model/Property.h"
|
||||||
|
|
||||||
#if DEMOMODE
|
#if DEMOMODE
|
||||||
#include "recording.h"
|
#include "recording.h"
|
||||||
@ -227,11 +226,11 @@ void CWallpaperApplication::setupPropertiesForProject (const Project& project) {
|
|||||||
if (override != this->m_context.settings.general.properties.end ()) {
|
if (override != this->m_context.settings.general.properties.end ()) {
|
||||||
sLog.out ("Applying override value for ", key);
|
sLog.out ("Applying override value for ", key);
|
||||||
|
|
||||||
cur->set (override->second);
|
cur->update (override->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->m_context.settings.general.onlyListProperties)
|
if (this->m_context.settings.general.onlyListProperties)
|
||||||
sLog.out (cur->dump ());
|
sLog.out (cur->toString ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ void pa_stream_notify_cb (pa_stream* stream, void* /*userdata*/) {
|
|||||||
switch (pa_stream_get_state (stream)) {
|
switch (pa_stream_get_state (stream)) {
|
||||||
case PA_STREAM_FAILED: sLog.error ("Cannot open stream for capture. Audio processing is disabled"); break;
|
case PA_STREAM_FAILED: sLog.error ("Cannot open stream for capture. Audio processing is disabled"); break;
|
||||||
case PA_STREAM_READY: sLog.debug ("Capture stream ready"); break;
|
case PA_STREAM_READY: sLog.debug ("Capture stream ready"); break;
|
||||||
default: sLog.debug("pa_stream_get_state unknown result"); break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,6 @@ void pa_context_notify_cb (pa_context* ctx, void* userdata) {
|
|||||||
sLog.error ("PulseAudio context initialization failed. Audio processing is disabled");
|
sLog.error ("PulseAudio context initialization failed. Audio processing is disabled");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sLog.debug ("pa_context_get_state unknown result");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
#include "CProperty.h"
|
|
||||||
#include "CPropertyBoolean.h"
|
|
||||||
#include "CPropertyColor.h"
|
|
||||||
#include "CPropertyCombo.h"
|
|
||||||
#include "CPropertySlider.h"
|
|
||||||
#include "CPropertyText.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CProperty> CProperty::fromJSON (const JSON& data, const std::string& name) {
|
|
||||||
const auto type = data.require <std::string> ("type", "Project properties must have the type field");
|
|
||||||
|
|
||||||
if (type == "color")
|
|
||||||
return CPropertyColor::fromJSON (data, name);
|
|
||||||
if (type == "bool")
|
|
||||||
return CPropertyBoolean::fromJSON (data, name);
|
|
||||||
if (type == "slider")
|
|
||||||
return CPropertySlider::fromJSON (data, name);
|
|
||||||
if (type == "combo")
|
|
||||||
return CPropertyCombo::fromJSON (data, name);
|
|
||||||
if (type == "text")
|
|
||||||
return CPropertyText::fromJSON (data, name);
|
|
||||||
|
|
||||||
if (type != "group") {
|
|
||||||
// show the error and ignore this property
|
|
||||||
sLog.error ("Unexpected type for property: ", type);
|
|
||||||
sLog.error (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CProperty::CProperty (std::string name, std::string text) :
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_text (std::move(text)) {}
|
|
||||||
|
|
||||||
const std::string& CProperty::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CProperty::getText () const {
|
|
||||||
return this->m_text;
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Utils/TypeCaster.h"
|
|
||||||
#include "WallpaperEngine/Data/Model/DynamicValue.h"
|
|
||||||
#include "WallpaperEngine/Data/JSON.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
|
||||||
using namespace WallpaperEngine::Data::Model;
|
|
||||||
using namespace WallpaperEngine::Data::Utils;
|
|
||||||
/**
|
|
||||||
* Represents a property in a background
|
|
||||||
*
|
|
||||||
* Properties are settings that alter how the background looks or works
|
|
||||||
* and are configurable by the user so they can customize it to their likings
|
|
||||||
*/
|
|
||||||
class CProperty : public DynamicValue, public TypeCaster {
|
|
||||||
public:
|
|
||||||
using UniquePtr = std::unique_ptr<CProperty>;
|
|
||||||
using SharedPtr = std::shared_ptr<CProperty>;
|
|
||||||
using WeakPtr = std::weak_ptr<CProperty>;
|
|
||||||
|
|
||||||
static std::shared_ptr<CProperty> fromJSON (const JSON& data, const std::string& name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Representation of what the property does and the default values
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual std::string dump () const = 0;
|
|
||||||
/**
|
|
||||||
* Updates the value of the property with the one in the string
|
|
||||||
*
|
|
||||||
* @param value New value for the property
|
|
||||||
*/
|
|
||||||
virtual void set (const std::string& value) = 0;
|
|
||||||
/**
|
|
||||||
* @return Name of the property
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
/**
|
|
||||||
* @return Textual type representation of this property
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual const char* getPropertyType () const = 0;
|
|
||||||
/**
|
|
||||||
* @return Text of the property
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getText () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CProperty (std::string name, std::string text);
|
|
||||||
/** Name of the property */
|
|
||||||
const std::string m_name;
|
|
||||||
/** Description of the property for the user */
|
|
||||||
mutable std::string m_text;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,38 +0,0 @@
|
|||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CPropertyBoolean.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyBoolean> CPropertyBoolean::fromJSON (const JSON& data, std::string name) {
|
|
||||||
return std::make_shared <CPropertyBoolean> (
|
|
||||||
data.require ("value", "Boolean property must have a value"),
|
|
||||||
std::move(name),
|
|
||||||
data.optional <std::string> ("text", "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CPropertyBoolean::set (const std::string& value) {
|
|
||||||
this->update (value == "1" || value == "true" || value == "on");
|
|
||||||
}
|
|
||||||
|
|
||||||
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->getBool ();
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyBoolean::getPropertyType () const {
|
|
||||||
return "bool";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyBoolean::CPropertyBoolean (bool value, std::string name, std::string text) :
|
|
||||||
CProperty (std::move(name), std::move(text)) {}
|
|
@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a boolean property
|
|
||||||
*/
|
|
||||||
class CPropertyBoolean final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertyBoolean (bool value, std::string name, std::string text);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertyBoolean> fromJSON (const JSON& data, std::string name);
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getPropertyType () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,81 +0,0 @@
|
|||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CPropertyColor.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Data::Builders;
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
glm::vec3 ParseColor (std::string value) {
|
|
||||||
// TODO: ENSURE THIS PARSING IS ACTUALLY ACCURATE
|
|
||||||
if (value.find (',') != std::string::npos) {
|
|
||||||
// replace commas with dots so it can be parsed
|
|
||||||
std::replace (value.begin (), value.end (), ',', ' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.find ('.') == std::string::npos && value != "0 0 0" && value != "1 1 1") {
|
|
||||||
if (value.find ('#') == 0) {
|
|
||||||
// hex color, parse it to int color and then convert it to float
|
|
||||||
auto number = value.substr (1);
|
|
||||||
|
|
||||||
if (number.size () == 3) {
|
|
||||||
// CSS short-number, expand to the proper size
|
|
||||||
number = number[0] + number[0] + number[1] + number[1] + number[2] + number[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove alpha if it's present, should look into it more closely
|
|
||||||
if (number.size () > 6) {
|
|
||||||
sLog.error ("Color value has alpha channel, which is not supported");
|
|
||||||
number = number.substr (0, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto color = std::stoi (number, nullptr, 16);
|
|
||||||
|
|
||||||
return {
|
|
||||||
(((color >> 16) & 0xFF) / 255.0),
|
|
||||||
(((color >> 8) & 0xFF) / 255.0),
|
|
||||||
(((color >> 0) & 0xFF) / 255.0)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto intcolor = VectorBuilder::parse <glm::ivec3> (value);
|
|
||||||
|
|
||||||
return {intcolor.r / 255.0, intcolor.g / 255.0, intcolor.b / 255.0};
|
|
||||||
}
|
|
||||||
|
|
||||||
return VectorBuilder::parse <glm::vec3> (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyColor> CPropertyColor::fromJSON (const JSON& data, std::string name) {
|
|
||||||
return std::make_shared <CPropertyColor> (
|
|
||||||
data.require ("value", "Color property must have a value"),
|
|
||||||
std::move(name),
|
|
||||||
data.optional <std::string> ("text", "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertyColor::set (const std::string& value) {
|
|
||||||
this->update (ParseColor (std::string (value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CPropertyColor::dump () const {
|
|
||||||
const auto color = this->getVec3 ();
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << this->m_name << " - color" << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Description: " << this->m_text << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "R: " << color.r << " G: " << color.g << " B: " << color.b;
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyColor::getPropertyType () const {
|
|
||||||
return "color";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyColor::CPropertyColor (const std::string& color, std::string name, std::string text) :
|
|
||||||
CProperty (std::move(name), std::move(text)) {
|
|
||||||
this->set (color);
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/JSON.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a color property
|
|
||||||
*/
|
|
||||||
class CPropertyColor final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertyColor (const std::string& color, std::string name, std::string text);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertyColor> fromJSON (const JSON& data, std::string name);
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getPropertyType () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,112 +0,0 @@
|
|||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CPropertyCombo.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyCombo> CPropertyCombo::fromJSON (const JSON& data, std::string name) {
|
|
||||||
std::vector<CPropertyComboValue> values;
|
|
||||||
const auto options = data.require ("options", "Options for a property combo is required");
|
|
||||||
|
|
||||||
if (!options.is_array ())
|
|
||||||
sLog.exception ("Property combo options should be an array");
|
|
||||||
|
|
||||||
for (auto& cur : options) {
|
|
||||||
// TODO: PROPERLY REPORT THESE ISSUES
|
|
||||||
if (!cur.is_object ())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const auto valueIt = cur.require ("value", "Value is required for a property combo option");
|
|
||||||
auto value = valueIt.is_number () ? std::to_string (valueIt.get <int> ()) : valueIt.get <std::string> ();
|
|
||||||
|
|
||||||
// check for label and value to ensure they're there
|
|
||||||
values.push_back ({
|
|
||||||
.label = cur.require ("label", "Label is required for a property combo option"),
|
|
||||||
.value = value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto valueIt = data.require ("value", "Value is required for a property combo");
|
|
||||||
auto value = valueIt.is_number () ? std::to_string (valueIt.get <int> ()) : valueIt.get <std::string> ();
|
|
||||||
|
|
||||||
return std::make_shared <CPropertyCombo> (
|
|
||||||
std::move(name),
|
|
||||||
data.optional <std::string> ("text", ""),
|
|
||||||
value,
|
|
||||||
values
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyCombo::CPropertyCombo (
|
|
||||||
std::string name, std::string text, const std::string& defaultValue,
|
|
||||||
std::vector<CPropertyComboValue> values
|
|
||||||
) :
|
|
||||||
CProperty (std::move(name), std::move(text)),
|
|
||||||
m_values (std::move(values)) {
|
|
||||||
this->set (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->getInt () << std::endl
|
|
||||||
<< "\t\t"
|
|
||||||
<< "Posible values:" << std::endl;
|
|
||||||
|
|
||||||
for (const auto& cur : this->m_values)
|
|
||||||
ss << "\t\t" << cur.label << " -> " << cur.value << std::endl;
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertyCombo::set (const std::string& value) {
|
|
||||||
bool found = false;
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
// ensure the value is present somewhere in the value list
|
|
||||||
for (const auto& cur : this->m_values) {
|
|
||||||
if (cur.value == value) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
index ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
sLog.exception ("Assigning invalid value to property ", this->m_name);
|
|
||||||
|
|
||||||
this->update (index);
|
|
||||||
}
|
|
||||||
|
|
||||||
int CPropertyCombo::translateValueToIndex (const std::string& value) const {
|
|
||||||
bool found = false;
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
// ensure the value is present somewhere in the value list
|
|
||||||
for (const auto& cur : this->m_values) {
|
|
||||||
if (cur.value == value) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
index ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyCombo::getPropertyType () const {
|
|
||||||
return "combo";
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using JSON = WallpaperEngine::Data::JSON::JSON;;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents different combo values
|
|
||||||
*/
|
|
||||||
struct CPropertyComboValue {
|
|
||||||
public:
|
|
||||||
const std::string label;
|
|
||||||
const std::string value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a combo property
|
|
||||||
*
|
|
||||||
* Combos are properties that have different values available and only one can be selected at once
|
|
||||||
* this limits the user's possibilities, used for things like the amount of samples to use in audioprocessing
|
|
||||||
* backgrounds
|
|
||||||
*/
|
|
||||||
class CPropertyCombo final : public CProperty {
|
|
||||||
public:
|
|
||||||
static std::shared_ptr<CPropertyCombo> fromJSON (const JSON& data, std::string name);
|
|
||||||
|
|
||||||
CPropertyCombo (
|
|
||||||
std::string name, std::string text, const std::string& defaultValue,
|
|
||||||
std::vector<CPropertyComboValue> values);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
int translateValueToIndex (const std::string& value) const;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getPropertyType () const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** List of values available to select */
|
|
||||||
const std::vector<CPropertyComboValue> m_values;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,67 +0,0 @@
|
|||||||
#include "CPropertySlider.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertySlider> CPropertySlider::fromJSON (const JSON& data, const std::string& name) {
|
|
||||||
const auto value = data.find ("value");
|
|
||||||
const auto text = data.optional <std::string> ("text", "");
|
|
||||||
const auto min = data.optional ("min", 0.0f);
|
|
||||||
const auto max = data.optional ("max", 0.0f);
|
|
||||||
const auto step = data.optional ("step", 0.0f);
|
|
||||||
|
|
||||||
return std::make_shared <CPropertySlider> (*value, name, text, min, max, step);
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& CPropertySlider::getMinValue () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& CPropertySlider::getMaxValue () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& 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->getFloat () << 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 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertySlider::set (const std::string& value) {
|
|
||||||
const auto newValue = strtof (value.c_str (), nullptr);
|
|
||||||
|
|
||||||
if (newValue < this->m_min || newValue > this->m_max)
|
|
||||||
sLog.exception ("Slider value (", newValue, ") is out of range (", this->m_min, ",", this->m_max, ")");
|
|
||||||
|
|
||||||
this->update (newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertySlider::getPropertyType () const {
|
|
||||||
return "slider";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertySlider::CPropertySlider (float value, const std::string& name, const std::string& text, float min,
|
|
||||||
float max, float step) :
|
|
||||||
CProperty (name, text),
|
|
||||||
m_min (min),
|
|
||||||
m_max (max),
|
|
||||||
m_step (step) {
|
|
||||||
this->update (value);
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a slider value with a minimum and maximum value
|
|
||||||
*/
|
|
||||||
class CPropertySlider final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertySlider (float value, const std::string& name, const std::string& text, float min, float max, float step);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertySlider> fromJSON (const JSON& data, const std::string& name);
|
|
||||||
/**
|
|
||||||
* @return The slider's minimum value
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const float& getMinValue () const;
|
|
||||||
/**
|
|
||||||
* @return The slider's maximum value
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const float& getMaxValue () const;
|
|
||||||
/**
|
|
||||||
* @return The slider's value increment steps, only really used in the UI
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const float& getStep () const;
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getPropertyType () const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Minimum value */
|
|
||||||
const float m_min;
|
|
||||||
/** Maximum value */
|
|
||||||
const float m_max;
|
|
||||||
/** Increment steps for the slider in the UI */
|
|
||||||
const float m_step;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,34 +0,0 @@
|
|||||||
#include "CPropertyText.h"
|
|
||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyText> CPropertyText::fromJSON (const JSON& data, std::string name) {
|
|
||||||
//TODO: VALIDATE THIS IS RIGHT
|
|
||||||
return std::make_shared <CPropertyText> (
|
|
||||||
std::move(name),
|
|
||||||
data.optional <std::string> ("text", "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CPropertyText::dump () const {
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << this->m_name << " - text" << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Value: " << this->m_text;
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertyText::set (const std::string& value) {
|
|
||||||
this->m_text = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyText::getPropertyType () const {
|
|
||||||
return "text";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyText::CPropertyText (std::string name, std::string text) :
|
|
||||||
CProperty (std::move(name), std::move(text)) {}
|
|
@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a text property
|
|
||||||
*/
|
|
||||||
class CPropertyText final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertyText (std::string name, std::string text);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertyText> fromJSON (const JSON& data, std::string name);
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getPropertyType () const override;
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -13,7 +13,7 @@ class UserSettingBuilder {
|
|||||||
|
|
||||||
return std::make_unique <UserSetting> (UserSetting {
|
return std::make_unique <UserSetting> (UserSetting {
|
||||||
.value = std::move (value),
|
.value = std::move (value),
|
||||||
.property = PropertyWeakPtr (),
|
.property = PropertySharedPtr (),
|
||||||
.condition = std::nullopt,
|
.condition = std::nullopt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -271,6 +271,9 @@ void DynamicValue::connect (DynamicValue* other) {
|
|||||||
this->update (other);
|
this->update (other);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// update our value on connection
|
||||||
|
this->update (*other);
|
||||||
|
|
||||||
this->m_connections.push_back (deregisterFunction);
|
this->m_connections.push_back (deregisterFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class DynamicValue {
|
|||||||
[[nodiscard]] const int& getInt () const;
|
[[nodiscard]] const int& getInt () const;
|
||||||
[[nodiscard]] const bool& getBool () const;
|
[[nodiscard]] const bool& getBool () const;
|
||||||
[[nodiscard]] UnderlyingType getType () const;
|
[[nodiscard]] UnderlyingType getType () const;
|
||||||
[[nodiscard]] std::string toString () const;
|
[[nodiscard]] virtual std::string toString () const;
|
||||||
|
|
||||||
void update (float newValue);
|
void update (float newValue);
|
||||||
void update (int newValue);
|
void update (int newValue);
|
||||||
|
@ -65,7 +65,7 @@ struct ImageEffect {
|
|||||||
/** Effect's name for the editor */
|
/** Effect's name for the editor */
|
||||||
std::string name;
|
std::string name;
|
||||||
/** If this effect is visible or not */
|
/** If this effect is visible or not */
|
||||||
UserSettingSharedPtr visible;
|
UserSettingUniquePtr visible;
|
||||||
/** Pass overrides to apply to the effect's passes */
|
/** Pass overrides to apply to the effect's passes */
|
||||||
std::vector <ImageEffectPassOverrideUniquePtr> passOverrides;
|
std::vector <ImageEffectPassOverrideUniquePtr> passOverrides;
|
||||||
/** The effect definition */
|
/** The effect definition */
|
||||||
@ -74,17 +74,17 @@ struct ImageEffect {
|
|||||||
|
|
||||||
struct ImageData {
|
struct ImageData {
|
||||||
/** The point of origin of the image */
|
/** The point of origin of the image */
|
||||||
UserSettingSharedPtr origin;
|
UserSettingUniquePtr origin;
|
||||||
/** The scale of the image */
|
/** The scale of the image */
|
||||||
UserSettingSharedPtr scale;
|
UserSettingUniquePtr scale;
|
||||||
/** The rotation of the image */
|
/** The rotation of the image */
|
||||||
UserSettingSharedPtr angles;
|
UserSettingUniquePtr angles;
|
||||||
/** If the image is visible or not */
|
/** If the image is visible or not */
|
||||||
UserSettingSharedPtr visible;
|
UserSettingUniquePtr visible;
|
||||||
/** The alpha of the image */
|
/** The alpha of the image */
|
||||||
UserSettingSharedPtr alpha;
|
UserSettingUniquePtr alpha;
|
||||||
/** The color of the image */
|
/** The color of the image */
|
||||||
UserSettingSharedPtr color;
|
UserSettingUniquePtr color;
|
||||||
// TODO: WRITE A COUPLE OF ENUMS FOR THIS
|
// TODO: WRITE A COUPLE OF ENUMS FOR THIS
|
||||||
/** The alignment of the image */
|
/** The alignment of the image */
|
||||||
std::string alignment;
|
std::string alignment;
|
||||||
|
138
src/WallpaperEngine/Data/Model/Property.h
Normal file
138
src/WallpaperEngine/Data/Model/Property.h
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include "DynamicValue.h"
|
||||||
|
#include "../Utils/TypeCaster.h"
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Data::Model {
|
||||||
|
using namespace WallpaperEngine::Data::Utils;
|
||||||
|
using namespace WallpaperEngine::Data::Builders;
|
||||||
|
|
||||||
|
struct PropertyData {
|
||||||
|
std::string name;
|
||||||
|
std::string text;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SliderData {
|
||||||
|
float min;
|
||||||
|
float max;
|
||||||
|
float step;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ComboData {
|
||||||
|
std::map<std::string, std::string> values;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Property : public DynamicValue, public TypeCaster, public PropertyData {
|
||||||
|
public:
|
||||||
|
explicit Property (PropertyData data) : PropertyData (std::move(data)), TypeCaster (), DynamicValue () {}
|
||||||
|
|
||||||
|
using DynamicValue::update;
|
||||||
|
virtual void update(const std::string& value) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PropertySlider : public Property, SliderData {
|
||||||
|
public:
|
||||||
|
PropertySlider (PropertyData data, SliderData sliderData, float value) : Property (std::move(data)), SliderData (sliderData) {
|
||||||
|
this->update (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
using Property::update;
|
||||||
|
void update(const std::string& value) override {
|
||||||
|
this->update (std::stof (value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PropertyBoolean : public Property {
|
||||||
|
public:
|
||||||
|
explicit PropertyBoolean (PropertyData data, bool value) : Property (std::move(data)) {
|
||||||
|
this->update (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
using Property::update;
|
||||||
|
void update(const std::string& value) override {
|
||||||
|
this->update (value == "true" || value == "1");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PropertyColor : public Property {
|
||||||
|
public:
|
||||||
|
explicit PropertyColor (PropertyData data, std::string value) : Property (std::move(data)) {
|
||||||
|
this->update (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
using Property::update;
|
||||||
|
void update(const std::string& value) override {
|
||||||
|
auto copy = value;
|
||||||
|
|
||||||
|
// TODO: ENSURE ALL THIS PARSING IS CORRECT
|
||||||
|
if (copy.find (',') != std::string::npos) {
|
||||||
|
// replace comma separator with spaces so it's
|
||||||
|
std::replace (copy.begin (), copy.end (), ',', ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// hex colors should be converted to int colors
|
||||||
|
if (copy.find ('#') == 0) {
|
||||||
|
auto number = copy.substr (1);
|
||||||
|
|
||||||
|
// support for css notation
|
||||||
|
if (number.size () == 3) {
|
||||||
|
number = number[0] + number[0] + number[1] + number[1] + number[2] + number[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove alpha if it's present, should look into it more closely
|
||||||
|
if (number.size () > 6) {
|
||||||
|
sLog.error ("Color value has alpha channel, which is not supported");
|
||||||
|
number = number.substr (0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto color = std::stoi (number, nullptr, 16);
|
||||||
|
|
||||||
|
// format the number as float vector
|
||||||
|
copy =
|
||||||
|
std::to_string (((color >> 16) & 0xFF) / 255.0) + " " +
|
||||||
|
std::to_string (((color >> 8) & 0xFF) / 255.0) + " " +
|
||||||
|
std::to_string ((color & 0xFF) / 255.0);
|
||||||
|
} else if (copy.find ('.') == std::string::npos) {
|
||||||
|
// integer vector, convert it to float vector
|
||||||
|
const auto intcolor = VectorBuilder::parse <glm::ivec3> (copy);
|
||||||
|
|
||||||
|
copy =
|
||||||
|
std::to_string (intcolor.r / 255.0) + " " +
|
||||||
|
std::to_string (intcolor.g / 255.0) + " " +
|
||||||
|
std::to_string (intcolor.b / 255.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally parse the string as a float vector
|
||||||
|
this->update (VectorBuilder::parse <glm::vec3> (copy));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PropertyCombo : public Property, ComboData {
|
||||||
|
public:
|
||||||
|
PropertyCombo (PropertyData data, ComboData comboData, std::string value) : Property (std::move(data)), ComboData (std::move(comboData)) {
|
||||||
|
this->update (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
using Property::update;
|
||||||
|
void update(const std::string& value) override {
|
||||||
|
this->update (std::stoi (value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PropertyText : public Property {
|
||||||
|
public:
|
||||||
|
explicit PropertyText (PropertyData data) : Property (std::move(data)) {}
|
||||||
|
|
||||||
|
using Property::update;
|
||||||
|
void update(const std::string& value) override {
|
||||||
|
throw std::runtime_error ("PropertyText::update() is not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::string toString () const override {
|
||||||
|
return this->text;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -8,10 +8,6 @@
|
|||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
#include "WallpaperEngine/Assets/CContainer.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
class CProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Data::Model {
|
namespace WallpaperEngine::Data::Model {
|
||||||
struct Project;
|
struct Project;
|
||||||
class Wallpaper;
|
class Wallpaper;
|
||||||
@ -26,6 +22,12 @@ struct ImageEffect;
|
|||||||
struct ImageEffectPassOverride;
|
struct ImageEffectPassOverride;
|
||||||
class Particle;
|
class Particle;
|
||||||
class DynamicValue;
|
class DynamicValue;
|
||||||
|
class Property;
|
||||||
|
class PropertySlider;
|
||||||
|
class PropertyBoolean;
|
||||||
|
class PropertyCombo;
|
||||||
|
class PropertyText;
|
||||||
|
class PropertyColor;
|
||||||
struct Material;
|
struct Material;
|
||||||
struct MaterialPass;
|
struct MaterialPass;
|
||||||
struct FBO;
|
struct FBO;
|
||||||
@ -36,16 +38,10 @@ struct ModelStruct;
|
|||||||
// TODO: REMOVE ONCE THESE ARE RENAMED AND MOVED
|
// TODO: REMOVE ONCE THESE ARE RENAMED AND MOVED
|
||||||
using Container = WallpaperEngine::Assets::CContainer;
|
using Container = WallpaperEngine::Assets::CContainer;
|
||||||
|
|
||||||
using Property = WallpaperEngine::Core::Projects::CProperty;
|
|
||||||
using PropertySharedPtr = std::shared_ptr <Property>;
|
using PropertySharedPtr = std::shared_ptr <Property>;
|
||||||
using PropertyWeakPtr = std::weak_ptr <Property>;
|
|
||||||
using Properties = std::map <std::string, PropertySharedPtr>;
|
using Properties = std::map <std::string, PropertySharedPtr>;
|
||||||
using DynamicValueUniquePtr = std::unique_ptr <DynamicValue>;
|
using DynamicValueUniquePtr = std::unique_ptr <DynamicValue>;
|
||||||
using DynamicValueSharedPtr = std::shared_ptr <DynamicValue>;
|
|
||||||
using DynamicValueWeakPtr = std::weak_ptr <DynamicValue>;
|
|
||||||
using UserSettingSharedPtr = std::shared_ptr <UserSetting>;
|
|
||||||
using UserSettingUniquePtr = std::unique_ptr <UserSetting>;
|
using UserSettingUniquePtr = std::unique_ptr <UserSetting>;
|
||||||
using UserSettingWeakPtr = std::weak_ptr <UserSetting>;
|
|
||||||
// TODO: UP TO THIS POINT
|
// TODO: UP TO THIS POINT
|
||||||
|
|
||||||
using ShaderConstantMap = std::map <std::string, UserSettingUniquePtr>;
|
using ShaderConstantMap = std::map <std::string, UserSettingUniquePtr>;
|
||||||
|
@ -22,7 +22,7 @@ struct UserSetting {
|
|||||||
*/
|
*/
|
||||||
DynamicValueUniquePtr value;
|
DynamicValueUniquePtr value;
|
||||||
/** The property this setting takes the value from (if specified) */
|
/** The property this setting takes the value from (if specified) */
|
||||||
PropertyWeakPtr property;
|
PropertySharedPtr property;
|
||||||
/** Condition required for this setting, this should be possible to run in JS' V8 */
|
/** Condition required for this setting, this should be possible to run in JS' V8 */
|
||||||
std::optional <ConditionInfo> condition;
|
std::optional <ConditionInfo> condition;
|
||||||
/** TODO: Value might come from a script and not have conditions, implement this later */
|
/** TODO: Value might come from a script and not have conditions, implement this later */
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include "WallpaperParser.h"
|
#include "WallpaperParser.h"
|
||||||
|
|
||||||
|
#include "PropertyParser.h"
|
||||||
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
||||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Data::Parsers;
|
using namespace WallpaperEngine::Data::Parsers;
|
||||||
|
|
||||||
@ -70,18 +70,15 @@ Properties ProjectParser::parseProperties (const std::optional <JSON>& data) {
|
|||||||
|
|
||||||
Properties result = {};
|
Properties result = {};
|
||||||
|
|
||||||
// TODO: CHANGE THIS ONCE THE PROPERTIES PARSING IS HANDLED IN THE NEW TYPES
|
|
||||||
// THESE ARE COMPLEX TYPES THAT INCLUDE SOME RUNTIME INFO THAT ISN'T EXPLICITLY DATA
|
|
||||||
// SO THIS WILL NEED A RETHINK IN THE FUTURE
|
|
||||||
for (const auto& cur : properties.value ().items ()) {
|
for (const auto& cur : properties.value ().items ()) {
|
||||||
const auto& property = Property::fromJSON (cur.value (), cur.key ());
|
const auto& property = PropertyParser::parse (cur.value (), cur.key ());
|
||||||
|
|
||||||
// ignore properties that failed, these are generally groups
|
// ignore properties that failed, these are generally groups
|
||||||
if (property == nullptr) {
|
if (property == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.emplace (property->getName (), property);
|
result.emplace (cur.key (), property);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
98
src/WallpaperEngine/Data/Parsers/PropertyParser.cpp
Normal file
98
src/WallpaperEngine/Data/Parsers/PropertyParser.cpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include "PropertyParser.h"
|
||||||
|
#include "../Model/Property.h"
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Data::Parsers;
|
||||||
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
|
||||||
|
PropertySharedPtr PropertyParser::parse (const JSON& it, std::string name) {
|
||||||
|
const auto type = it.require <std::string> ("type", "Property type is required");
|
||||||
|
|
||||||
|
if (type == "color") {
|
||||||
|
return parseColor (it, name);
|
||||||
|
}
|
||||||
|
if (type == "bool") {
|
||||||
|
return parseBoolean (it, name);
|
||||||
|
}
|
||||||
|
if (type == "slider") {
|
||||||
|
return parseSlider (it, name);
|
||||||
|
}
|
||||||
|
if (type == "combo") {
|
||||||
|
return parseCombo (it, name);
|
||||||
|
}
|
||||||
|
if (type == "text") {
|
||||||
|
return parseText (it, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type != "group") {
|
||||||
|
// show the error and ignore this property
|
||||||
|
sLog.error ("Unexpected type for property: ", type);
|
||||||
|
sLog.error (it.dump ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PropertySharedPtr PropertyParser::parseCombo (const JSON& it, std::string name) {
|
||||||
|
std::map <std::string, std::string> optionsMap = {};
|
||||||
|
|
||||||
|
const auto options = it.require ("options", "Combo property must have options");
|
||||||
|
|
||||||
|
if (!options.is_array ()) {
|
||||||
|
sLog.exception ("Property combo options should be an array");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& cur : options) {
|
||||||
|
if (!cur.is_object ()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto value = cur.require ("value", "Combo option must have a value");
|
||||||
|
|
||||||
|
optionsMap.emplace (
|
||||||
|
cur.require ("label", "Combo option must have a label"),
|
||||||
|
value.is_number () ? std::to_string (value.get <int> ()) : value.get <std::string> ()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto value = it.require ("value", "Combo property must have a value");
|
||||||
|
|
||||||
|
return std::make_shared <PropertyCombo> (PropertyData {
|
||||||
|
.name = name,
|
||||||
|
.text = it.optional <std::string> ("text", ""),
|
||||||
|
}, ComboData {
|
||||||
|
.values = optionsMap
|
||||||
|
}, value.is_number () ? std::to_string (value.get <int> ()) : value.get <std::string> ());
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertySharedPtr PropertyParser::parseColor (const JSON& it, std::string name) {
|
||||||
|
return std::make_shared <PropertyColor> (PropertyData {
|
||||||
|
.name = name,
|
||||||
|
.text = it.optional <std::string> ("text", ""),
|
||||||
|
}, it.require ("value", "Property must have a value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertySharedPtr PropertyParser::parseBoolean (const JSON& it, std::string name) {
|
||||||
|
return std::make_shared <PropertyBoolean> (PropertyData {
|
||||||
|
.name = name,
|
||||||
|
.text = it.optional <std::string> ("text", ""),
|
||||||
|
}, it.require ("value", "Property must have a value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertySharedPtr PropertyParser::parseSlider (const JSON& it, std::string name) {
|
||||||
|
return std::make_shared <PropertySlider> (PropertyData {
|
||||||
|
.name = name,
|
||||||
|
.text = it.optional <std::string> ("text", ""),
|
||||||
|
}, SliderData {
|
||||||
|
.min = it.optional ("min", 0.0f),
|
||||||
|
.max = it.optional ("max", 0.0f),
|
||||||
|
.step = it.optional ("step", 0.0f),
|
||||||
|
}, it.require ("value", "Property must have a value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertySharedPtr PropertyParser::parseText (const JSON& it, std::string name) {
|
||||||
|
return std::make_shared <PropertyText> (PropertyData {
|
||||||
|
.name = name,
|
||||||
|
.text = it.optional <std::string> ("text", ""),
|
||||||
|
});
|
||||||
|
}
|
20
src/WallpaperEngine/Data/Parsers/PropertyParser.h
Normal file
20
src/WallpaperEngine/Data/Parsers/PropertyParser.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Data/JSON.h"
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Data::Parsers {
|
||||||
|
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||||
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
|
||||||
|
class PropertyParser {
|
||||||
|
public:
|
||||||
|
static PropertySharedPtr parse (const JSON& it, std::string name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static PropertySharedPtr parseCombo (const JSON& it, std::string name);
|
||||||
|
static PropertySharedPtr parseColor (const JSON& it, std::string name);
|
||||||
|
static PropertySharedPtr parseBoolean (const JSON& it, std::string name);
|
||||||
|
static PropertySharedPtr parseSlider (const JSON& it, std::string name);
|
||||||
|
static PropertySharedPtr parseText (const JSON& it, std::string name);
|
||||||
|
};
|
||||||
|
}
|
@ -1,13 +1,14 @@
|
|||||||
#include "UserSettingParser.h"
|
#include "UserSettingParser.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Model/UserSetting.h"
|
#include "WallpaperEngine/Data/Model/UserSetting.h"
|
||||||
|
#include "WallpaperEngine/Data/Model/Property.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine::Data::Parsers;
|
using namespace WallpaperEngine::Data::Parsers;
|
||||||
using namespace WallpaperEngine::Data::Builders;
|
using namespace WallpaperEngine::Data::Builders;
|
||||||
|
|
||||||
UserSettingUniquePtr UserSettingParser::parse (const json& data, const Properties& properties) {
|
UserSettingUniquePtr UserSettingParser::parse (const json& data, const Properties& properties) {
|
||||||
DynamicValueUniquePtr value = std::make_unique <DynamicValue> ();
|
DynamicValueUniquePtr value = std::make_unique <DynamicValue> ();
|
||||||
PropertyWeakPtr property;
|
PropertySharedPtr property;
|
||||||
std::optional<ConditionInfo> condition;
|
std::optional<ConditionInfo> condition;
|
||||||
auto valueIt = data;
|
auto valueIt = data;
|
||||||
std::string content = data.dump ();
|
std::string content = data.dump ();
|
||||||
@ -64,6 +65,9 @@ UserSettingUniquePtr UserSettingParser::parse (const json& data, const Propertie
|
|||||||
value->update (valueIt.get <float> ());
|
value->update (valueIt.get <float> ());
|
||||||
} else if (valueIt.is_boolean ()) {
|
} else if (valueIt.is_boolean ()) {
|
||||||
value->update (valueIt.get <bool> ());
|
value->update (valueIt.get <bool> ());
|
||||||
|
} else if (valueIt.is_null () && property != nullptr) {
|
||||||
|
// null values are directly connected to the property
|
||||||
|
value->connect (property.get());
|
||||||
} else {
|
} else {
|
||||||
sLog.exception ("Unsupported user setting type ", valueIt.type_name ());
|
sLog.exception ("Unsupported user setting type ", valueIt.type_name ());
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,6 @@
|
|||||||
#include "WallpaperEngine/Render/Objects/CImage.h"
|
#include "WallpaperEngine/Render/Objects/CImage.h"
|
||||||
#include "WallpaperEngine/Render/CFBO.h"
|
#include "WallpaperEngine/Render/CFBO.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
|
||||||
#include "WallpaperEngine/Core/Projects/CPropertyColor.h"
|
|
||||||
#include "WallpaperEngine/Core/Projects/CPropertyCombo.h"
|
|
||||||
#include "WallpaperEngine/Core/Projects/CPropertySlider.h"
|
|
||||||
#include "WallpaperEngine/Core/Projects/CPropertyBoolean.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h"
|
||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h"
|
||||||
|
@ -17,7 +17,6 @@ class CImage;
|
|||||||
namespace WallpaperEngine::Render::Objects::Effects {
|
namespace WallpaperEngine::Render::Objects::Effects {
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
using namespace WallpaperEngine::Data::Model;
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
|
||||||
class CPass final : public Helpers::CContextAware {
|
class CPass final : public Helpers::CContextAware {
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include "CGLSLContext.h"
|
#include "CGLSLContext.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Shaders {
|
namespace WallpaperEngine::Render::Shaders {
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
"#define varying out\n"
|
"#define varying out\n"
|
||||||
#define DEFINE_COMBO(name, value) "#define " + name + " " + std::to_string (value) + "\n";
|
#define DEFINE_COMBO(name, value) "#define " + name + " " + std::to_string (value) + "\n";
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
using namespace WallpaperEngine::Data::Builders;
|
using namespace WallpaperEngine::Data::Builders;
|
||||||
using namespace WallpaperEngine::Render::Shaders;
|
using namespace WallpaperEngine::Render::Shaders;
|
||||||
@ -411,10 +410,6 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
// TODO: BETTER CONVERSION HERE
|
// TODO: BETTER CONVERSION HERE
|
||||||
size_t index = value - '0';
|
size_t index = value - '0';
|
||||||
|
|
||||||
if (combo != data.end () && paintDefaultColor != data.end () && combo->get <std::string> () == "MASK" && this->m_file.find ("water")) {
|
|
||||||
sLog.debug("mask defaultcolor!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (combo != data.end ()) {
|
if (combo != data.end ()) {
|
||||||
// TODO: CLEANUP HOW THIS IS DETERMINED FIRST
|
// TODO: CLEANUP HOW THIS IS DETERMINED FIRST
|
||||||
// if the texture exists (and is not null), add to the combo
|
// if the texture exists (and is not null), add to the combo
|
||||||
|
Loading…
Reference in New Issue
Block a user