Gorgon Game Engine
Registry.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../UI/Template.h"
4 
5 namespace Gorgon { namespace Widgets {
6 
7 
12  class Registry {
13  public:
14 
18  enum TemplateType {
21 
24 
27 
29 
31 
38 
40 
43 
46 
48 
50 
52  Max
53  };
54 
56  explicit Registry(bool activate = false) : templates({}) {
57  if(activate)
58  Activate();
59  }
60 
62  virtual ~Registry() {
63  for(auto t : templates) {
64  delete t;
65  }
66  }
67 
69  void Activate() {
70  active = this;
71  }
72 
73  static Registry &Active() {
74  ASSERT(active, "UI is not initialized.");
75 
76  return *active;
77  }
78 
81  if(templates[type] == nullptr) {
82  templates[type] = &generate(type);
83  }
84 
85  return *templates[type];
86  }
87 
88  virtual int GetSpacing()const = 0;
89 
90  virtual int GetEmSize()const = 0;
91 
92  protected:
93 
94 
101  virtual UI::Template &generate(TemplateType type) = 0;
102 
104  mutable std::array<UI::Template*, Max> templates;
105 
106 
107  private:
108  static Registry *active; //initialized in UI.cpp
109  };
110 
111 
116  class PresetRegistry : public Registry {
117  public:
118 
121  void Add(TemplateType type, UI::Template &temp) {
122  delete templates[type];
123 
124  templates[type] = &temp;
125  }
126 
127  void SetSpacing(const int tspacing) {
128  spacing = tspacing;
129  }
130 
131  void SetEmSize(const int size) {
132  emsize = size;
133 
134  }
135 
136  virtual int GetSpacing()const override {
137  return spacing;
138  }
139 
140  virtual int GetEmSize()const override {
141  return emsize;
142  }
143 
144  protected:
146  return *new UI::Template();
147  }
148 
149  int spacing = 5;
150 
151  int emsize = 14;
152 
153  };
154 
155 
156 } }
Gorgon::Widgets::Registry::Max
@ Max
Do not use this value.
Definition: Registry.h:52
Gorgon::Widgets::PresetRegistry::SetSpacing
void SetSpacing(const int tspacing)
Definition: Registry.h:127
Gorgon::Widgets::PresetRegistry::GetEmSize
virtual int GetEmSize() const override
Definition: Registry.h:140
Gorgon::Widgets::Registry::Listbox_Regular
@ Listbox_Regular
Definition: Registry.h:47
Gorgon::Widgets::Registry::Button_Regular
@ Button_Regular
Definition: Registry.h:19
Gorgon::UI::Template
This class stores visual information about a widget template.
Definition: Template.h:392
Gorgon::Widgets::Registry::Label_Error
@ Label_Error
Definition: Registry.h:23
Gorgon::Widgets::Registry::Checkbox_Regular
@ Checkbox_Regular
Definition: Registry.h:25
Gorgon::Widgets::Registry::GetSpacing
virtual int GetSpacing() const =0
Gorgon::Widgets::Registry::generate
virtual UI::Template & generate(TemplateType type)=0
This function should return a template for the given type.
Gorgon::Widgets::Registry::Button_Icon
@ Button_Icon
Definition: Registry.h:20
Gorgon::Widgets::Registry::GetEmSize
virtual int GetEmSize() const =0
Gorgon::Widgets::PresetRegistry::SetEmSize
void SetEmSize(const int size)
Definition: Registry.h:131
Gorgon::Widgets::Registry::Inputbox_Regular
@ Inputbox_Regular
Definition: Registry.h:30
Gorgon::Widgets::Registry::Dropdown_Regular
@ Dropdown_Regular
Definition: Registry.h:49
Gorgon::Widgets::PresetRegistry::generate
virtual UI::Template & generate(Gorgon::Widgets::Registry::TemplateType) override
This function should return a template for the given type.
Definition: Registry.h:145
Gorgon::Widgets::Registry::Active
static Registry & Active()
Definition: Registry.h:73
Gorgon::Widgets::Registry::Activate
void Activate()
Activates this registry to be used to provide templates.
Definition: Registry.h:69
Gorgon::Widgets::Registry::Panel_Top
@ Panel_Top
Definition: Registry.h:34
Gorgon::Widgets::Registry::TemplateType
TemplateType
This enum lists all possible template types.
Definition: Registry.h:18
Gorgon::Widgets::Registry::Radio_Regular
@ Radio_Regular
Definition: Registry.h:28
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Widgets::Registry::Panel_Bottom
@ Panel_Bottom
Definition: Registry.h:36
ASSERT
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Gorgon::Widgets::PresetRegistry::GetSpacing
virtual int GetSpacing() const override
Definition: Registry.h:136
Gorgon::Widgets::Registry::Panel_Regular
@ Panel_Regular
Definition: Registry.h:32
Gorgon::Widgets::Registry::Label_Regular
@ Label_Regular
Definition: Registry.h:22
Gorgon::Widgets::Registry::Scrollbar_Horizontal
@ Scrollbar_Horizontal
Definition: Registry.h:44
Gorgon::Widgets::Registry::templates
std::array< UI::Template *, Max > templates
Stores the templates. Mutable to allow late loading.
Definition: Registry.h:104
Gorgon::Widgets::Registry::Progress_Regular
@ Progress_Regular
Definition: Registry.h:39
Gorgon::Widgets::Registry::Registry
Registry(bool activate=false)
Default constructor.
Definition: Registry.h:56
Gorgon::Widgets::PresetRegistry::Add
void Add(TemplateType type, UI::Template &temp)
Add the given template to the registry, transferring ownership.
Definition: Registry.h:121
Gorgon::Widgets::Registry::Panel_Left
@ Panel_Left
Definition: Registry.h:35
Gorgon::Widgets::Registry::Layerbox_Blank
@ Layerbox_Blank
Definition: Registry.h:42
Gorgon::Widgets::PresetRegistry::emsize
int emsize
Definition: Registry.h:151
Gorgon::Widgets::Registry::~Registry
virtual ~Registry()
Destroys all stored templates.
Definition: Registry.h:62
Gorgon::Widgets::Registry::Scrollbar_Vertical
@ Scrollbar_Vertical
Definition: Registry.h:45
Gorgon::Widgets::Registry::Layerbox_Regular
@ Layerbox_Regular
Definition: Registry.h:41
Gorgon::Widgets::Registry::operator[]
const UI::Template & operator[](TemplateType type)
Returns the template for the requested type.
Definition: Registry.h:80
Gorgon::Widgets::Registry::Panel_Blank
@ Panel_Blank
Definition: Registry.h:33
Gorgon::Widgets::PresetRegistry::spacing
int spacing
Definition: Registry.h:149
Gorgon::Widgets::PresetRegistry
This registry contains preset templates.
Definition: Registry.h:116
Gorgon::Widgets::Registry::Checkbox_Button
@ Checkbox_Button
Definition: Registry.h:26
Gorgon::Widgets::Registry
This class stores templates for elements.
Definition: Registry.h:12
Gorgon::Widgets::Registry::Panel_Right
@ Panel_Right
Definition: Registry.h:37