Gorgon Game Engine
Layerbox.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../UI/ComponentStackWidget.h"
4 #include "../Property.h"
5 #include "Registry.h"
6 
7 namespace Gorgon { namespace Graphics { class Bitmap; } }
8 
9 namespace Gorgon { namespace Widgets {
10 
12  public:
13  Layerbox(const Layerbox &) = delete;
14 
15  explicit Layerbox(std::string text = "", Registry::TemplateType type = Registry::Layerbox_Regular) :
16  Layerbox(Registry::Active()[type], text)
17  {
18  }
19 
20  explicit Layerbox(Registry::TemplateType type) :
21  Layerbox(Registry::Active()[type])
22  {
23  }
24 
25 
26  explicit Layerbox(const UI::Template &temp, std::string text = "");
27 
28  Layerbox(const UI::Template &temp, const char *text) : Layerbox(temp, std::string(text)) { }
29 
30  virtual ~Layerbox();
31 
33  void SetText(const std::string &value);
34 
36  std::string GetText() const { return text; }
37 
41  void SetIcon(const Graphics::Bitmap &value);
42 
46  void SetIcon(const Graphics::Animation &value);
47 
51 
55 
57  void RemoveIcon();
58 
60  bool HasIcon() const { return icon != nullptr; }
61 
64  const Graphics::Animation &GetIcon() const {
65  if(!HasIcon())
66  throw std::runtime_error("This widget has no icon.");
67 
68  return *icon;
69  }
70 
72  void OwnIcon();
73 
75  void OwnIcon(const Graphics::Animation &value);
76 
78  void OwnIcon(Graphics::Bitmap &&value);
79 
81  Layer &GetLayer();
82 
83  virtual bool Activate() override { return false; }
84 
86 
88 
89  private:
90  std::string text;
91  const Graphics::Animation *icon = nullptr;
92  const Graphics::AnimationProvider *iconprov = nullptr;
93 
94  bool ownicon = false;
95 
96  protected:
97  virtual bool allowfocus() const override;
98 
99  };
100 
101 } }
Gorgon::UI::Widget::HasParent
bool HasParent() const
Returns if this widget has a parent.
Definition: Widget.h:140
Gorgon::UI::ComponentStackWidget::stack
ComponentStack & stack
Definition: ComponentStackWidget.h:76
Gorgon::ObjectProperty
Object property allows the consumers of the property to be able to access object's member functions a...
Definition: Property.h:323
Gorgon::UI::ComponentTemplate::ContentsTag
@ ContentsTag
Definition: Template.h:872
Gorgon::UI::ComponentTemplate::Icon
@ Icon
Data will effect the displayed graphics.
Definition: Template.h:678
Gorgon::UI::ComponentStack::SetData
void SetData(ComponentTemplate::DataEffect effect, const std::string &text)
Sets the data for a specific data effect.
Definition: ComponentStack.cpp:725
Gorgon::Widgets::Layerbox::RemoveIcon
void RemoveIcon()
Removes the icon of the layer.
Definition: Layerbox.cpp:63
Gorgon::Graphics::AnimationProvider
A regular drawable animation provider.
Definition: Animations.h:28
Gorgon::UI::Template
This class stores visual information about a widget template.
Definition: Template.h:392
Gorgon::UI::ComponentStack::GetLayerOf
Layer & GetLayerOf(int ind)
Returns the layer of the given component index.
Definition: ComponentStack.cpp:1356
Gorgon::TextualProperty
Supports everything that string class supports including +, +=, length()
Definition: Property.h:562
Gorgon::Widgets::Layerbox::SetText
void SetText(const std::string &value)
Changes the displayed text which is generally shown on top.
Definition: Layerbox.cpp:28
Gorgon::Resource::GID::Text
constexpr Type Text
Stores text data, no longer a resource.
Definition: GID.h:134
Gorgon::Widgets::Layerbox::GetText
std::string GetText() const
Returns the displayed text which is generally shown on top.
Definition: Layerbox.h:36
Gorgon::Widgets::Layerbox::OwnIcon
void OwnIcon()
Transfers the ownership of the current icon.
Definition: Layerbox.cpp:74
Gorgon::Widgets::Layerbox::GetIcon
const Graphics::Animation & GetIcon() const
Returns the icon of the layer.
Definition: Layerbox.h:64
Gorgon::UI::ComponentStack::RemoveData
void RemoveData(ComponentTemplate::DataEffect effect)
Removes the data associated with data effect.
Definition: ComponentStack.cpp:759
Gorgon::Widgets::Registry::TemplateType
TemplateType
This enum lists all possible template types.
Definition: Registry.h:18
Gorgon::UI::ComponentTemplate::Text
@ Text
Works only for TextholderTemplate, data will affect the text that is displayed.
Definition: Template.h:651
Gorgon::UI::Widget::GetParent
WidgetContainer & GetParent() const
Returns the parent of this widget, throws if it does not have a parent.
Definition: Widget.cpp:30
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Widgets::Layerbox::GetLayer
Layer & GetLayer()
Returns the layer of this layerbox.
Definition: Layerbox.cpp:92
Gorgon::Graphics::AnimationProvider::CreateAnimation
virtual Animation & CreateAnimation(Gorgon::Animation::ControllerBase &timer) const override=0
This function should create a new animation with the given controller and if owner parameter is set t...
Gorgon::Widgets::Layerbox::HasIcon
bool HasIcon() const
Returns if the layerbox has an icon.
Definition: Layerbox.h:60
Gorgon::Graphics::Bitmap
This object contains an bitmap image.
Definition: Bitmap.h:25
Gorgon::UI::ComponentStack::IndexOfTag
int IndexOfTag(ComponentTemplate::Tag tag)
Returns the index of the component with the specified tag.
Definition: ComponentStack.cpp:1437
Gorgon::Widgets::Layerbox::allowfocus
virtual bool allowfocus() const override
Should return true if the widget can be focused.
Definition: Layerbox.cpp:88
Gorgon::Layer
This class is the base class for all layer types.
Definition: Layer.h:79
Gorgon::Animation::Base::DeleteAnimation
virtual void DeleteAnimation() const
Deletes this animation.
Definition: Animation.h:379
Gorgon::Widgets::Layerbox::Layerbox
Layerbox(Registry::TemplateType type)
Definition: Layerbox.h:20
Registry.h
Gorgon::Widgets::Layerbox::SetIconProvider
void SetIconProvider(const Graphics::AnimationProvider &value)
Changes the icon of the layer.
Definition: Layerbox.cpp:50
Gorgon::UI::ComponentStack::SetClickEvent
void SetClickEvent(std::function< void(ComponentTemplate::Tag, Geometry::Point, Input::Mouse::Button)> handler)
Sets the mouse down event.
Definition: ComponentStack.h:490
Gorgon::UI::Active
@ Active
This is for widgets that can be activated, like a count down timer.
Definition: Template.h:245
Gorgon::Graphics::Animation
A regular drawable animation.
Definition: Animations.h:14
Gorgon::UI::Graphics
@ Graphics
Definition: Template.h:164
Gorgon::Widgets::Layerbox::SetIcon
void SetIcon(const Graphics::Bitmap &value)
Changes the icon of the layer.
Definition: Layerbox.cpp:46
Gorgon::Widgets::Layerbox::Text
TextualProperty< Layerbox, std::string, &Layerbox::GetText, &Layerbox::SetText > Text
Definition: Layerbox.h:85
Gorgon::Widgets::Layerbox::~Layerbox
virtual ~Layerbox()
Definition: Layerbox.cpp:23
Gorgon::Widgets::Layerbox::Layerbox
Layerbox(std::string text="", Registry::TemplateType type=Registry::Layerbox_Regular)
Definition: Layerbox.h:15
Gorgon::Widgets::Registry::Layerbox_Regular
@ Layerbox_Regular
Definition: Registry.h:41
Gorgon::UI::WidgetContainer::FocusNext
bool FocusNext()
Focuses the next widget that accepts focus.
Definition: WidgetContainer.cpp:141
Gorgon::UI::ComponentStack::HandleMouse
void HandleMouse(Input::Mouse::Button accepted=Input::Mouse::Button::All)
This function instructs stack to handle mouse to automatically change hover/down states,...
Definition: ComponentStack.cpp:1023
Layerbox.h
Gorgon::Widgets::Layerbox::Icon
ObjectProperty< Layerbox, const Graphics::Animation, &Layerbox::GetIcon, &Layerbox::SetIcon > Icon
Definition: Layerbox.h:87
Gorgon::UI::ComponentStackWidget
This class acts as a widget base that uses component stack to handle rendering, resizing and other op...
Definition: ComponentStackWidget.h:14
Gorgon::Widgets::Layerbox
Definition: Layerbox.h:11
Gorgon::Input::Keyboard::Keycodes::Left
constexpr Key Left
Definition: Keyboard.h:62
Gorgon::Widgets::Layerbox::Layerbox
Layerbox(const UI::Template &temp, const char *text)
Definition: Layerbox.h:28
Gorgon::Widgets::Registry
This class stores templates for elements.
Definition: Registry.h:12
Gorgon::Widgets::Layerbox::Activate
virtual bool Activate() override
Activates the widget.
Definition: Layerbox.h:83
Gorgon::Widgets::Layerbox::Layerbox
Layerbox(const Layerbox &)=delete