mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-16 14:22:24 +08:00
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#include "CImage.h"
|
|
#include "Images/CMaterial.h"
|
|
|
|
#include "WallpaperEngine/Core/Core.h"
|
|
#include "../../FileSystem/utils.h"
|
|
|
|
using namespace WallpaperEngine::Core::Objects;
|
|
|
|
CImage::CImage (
|
|
Images::CMaterial* material,
|
|
bool visible,
|
|
irr::u32 id,
|
|
std::string name,
|
|
const irr::core::vector3df& origin,
|
|
const irr::core::vector3df& scale,
|
|
const irr::core::vector3df& angles,
|
|
const irr::core::vector2df& size) :
|
|
CObject (visible, id, std::move(name), origin, scale, angles),
|
|
m_size (size)
|
|
{
|
|
|
|
}
|
|
|
|
WallpaperEngine::Core::CObject* CImage::fromJSON (
|
|
json data,
|
|
bool visible,
|
|
irr::u32 id,
|
|
std::string name,
|
|
const irr::core::vector3df& origin,
|
|
const irr::core::vector3df& scale,
|
|
const irr::core::vector3df& angles)
|
|
{
|
|
json::const_iterator image_it = data.find ("image");
|
|
json::const_iterator size_it = data.find ("size");
|
|
|
|
if (size_it == data.end ())
|
|
{
|
|
throw std::runtime_error ("Images must have size");
|
|
}
|
|
|
|
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*image_it).get <std::string> ().c_str ()));
|
|
|
|
json::const_iterator material_it = content.find ("material");
|
|
|
|
if (material_it == content.end ())
|
|
{
|
|
throw std::runtime_error ("Image must have a material");
|
|
}
|
|
|
|
return new CImage (
|
|
Images::CMaterial::fromFile ((*material_it).get <std::string> ().c_str ()),
|
|
visible,
|
|
id,
|
|
name,
|
|
origin,
|
|
scale,
|
|
angles,
|
|
WallpaperEngine::Core::ato2vf (*size_it)
|
|
);
|
|
} |