aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/graph/graph_factory.hpp
blob: 0b1034cc8351a8c1042738bc6f51f10e0ba07c77 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include "../graphic_base.hpp"
#include "../native_resource.hpp"

#include "brush.hpp"
#include "font.hpp"
#include "geometry.hpp"
#include "text_layout.hpp"

#include <memory>
#include <string>
#include <string_view>

namespace cru::platform::graph {
// Entry point of the graph module.
// If you create a IUiApplication instance, then you should not create
// IGraphFactory manually. IUiApplication will call
// IGraphFactory::CreateInstance and set auto-delete to true.
// The manual creation method of IGraphFactory provides a you a way to use graph
// related tools without interact with actual ui like window system.
class GraphFactory : public NativeResource {
 public:
  // Create a platform-specific instance and save it as the global instance.
  // Do not create the instance twice. Implements should assert for that.
  // After creating, get the instance by GetInstance.
  static GraphFactory* CreateInstance();

  // Get the global instance. If it is not created, then return nullptr.
  static GraphFactory* GetInstance();

 protected:
  GraphFactory() = default;

 public:
  GraphFactory(const GraphFactory& other) = delete;
  GraphFactory& operator=(const GraphFactory& other) = delete;

  GraphFactory(GraphFactory&& other) = delete;
  GraphFactory& operator=(GraphFactory&& other) = delete;

  ~GraphFactory() override = default;

 public:
  virtual SolidColorBrush* CreateSolidColorBrush() = 0;
  SolidColorBrush* CreateSolidColorBrush(const Color& color) {
    const auto brush = CreateSolidColorBrush();
    brush->SetColor(color);
    return brush;
  }

  virtual GeometryBuilder* CreateGeometryBuilder() = 0;

  virtual Font* CreateFont(const std::wstring_view& font_family,
                           float font_size) = 0;

  virtual TextLayout* CreateTextLayout(std::shared_ptr<Font> font,
                                       std::wstring text) = 0;

  virtual bool IsAutoDelete() const = 0;
  virtual void SetAutoDelete(bool value) = 0;
};
}  // namespace cru::platform::graph