blob: fa585ac15405a7da6f9260d6ce4afb187753e1d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "style.h"
#include "assetFactory.h"
void
Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const Shape::CreatedFaces & faces) const
{
if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) {
for (const auto & face : faces) {
mesh.set_color(face.second, effectiveColour->get());
}
}
}
void
Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const ModelFactoryMesh::FaceHandle & face) const
{
if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) {
mesh.set_color(face, effectiveColour->get());
}
}
std::optional<std::reference_wrapper<const Style::ColourAlpha>>
Style::getColour(const StyleStack & parents)
{
return getProperty(parents, &Style::colour, [](auto && style) {
return style->colour.a > 0;
});
}
bool
Style::persist(Persistence::PersistenceStore & store)
{
struct ColourParser : public Persistence::SelectionV<ColourAlpha> {
using Persistence::SelectionV<ColourAlpha>::SelectionV;
using Persistence::SelectionV<ColourAlpha>::setValue;
void
setValue(std::string && str) override
{
if (auto mf = Persistence::ParseBase::getShared<const AssetFactory>("assetFactory")) {
v = mf->parseColour(str);
}
}
};
return STORE_HELPER(colour, ColourParser) && STORE_MEMBER(texture) && STORE_MEMBER(textureRotation);
}
|