blob: 737508cea10fb6786020048056f0eaf7acbdda8a (
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
|
#include "cru/ui/mapper/BrushMapper.h"
#include "../Helper.h"
#include "cru/platform/Color.h"
#include "cru/platform/graphics/Brush.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/ui/mapper/ColorMapper.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/xml/XmlNode.h"
#include <memory>
namespace cru::ui::mapper {
bool BrushMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
return color_mapper->XmlElementIsOfThisType(node) ||
node->GetTag().CaseInsensitiveEqual(u"Brush");
}
std::shared_ptr<platform::graphics::IBrush> BrushMapper::DoMapFromXml(
xml::XmlElementNode* node) {
auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
Color color = colors::transparent;
if (color_mapper->XmlElementIsOfThisType(node)) {
color = color_mapper->MapFromXml(node);
} else {
for (auto child : node->GetChildren()) {
if (child->IsElementNode()) {
auto c = child->AsElement();
if (color_mapper->XmlElementIsOfThisType(node)) {
color = color_mapper->MapFromXml(node);
}
}
}
}
return GetGraphicsFactory()->CreateSolidColorBrush(color);
}
} // namespace cru::ui::mapper
|