aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper/BrushMapper.cpp
blob: bfaef5079571956469bedb3f44f194fb37dcff09 (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.hpp"
#include "../Helper.hpp"
#include "cru/platform/Color.hpp"
#include "cru/platform/graphics/Brush.hpp"
#include "cru/platform/graphics/Factory.hpp"
#include "cru/ui/mapper/ColorMapper.hpp"
#include "cru/ui/mapper/MapperRegistry.hpp"
#include "cru/xml/XmlNode.hpp"

#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