Gorgon Game Engine
Label.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  Label(const Label &) = delete;
14 
15  explicit Label(std::string text = "", Registry::TemplateType type = Registry::Label_Regular) :
16  Label(Registry::Active()[type], text)
17  {
18  }
19 
21  Label(Registry::Active()[type], "")
22  {
23  }
24 
25 
26  explicit Label(const UI::Template &temp, std::string text = "");
27 
28  Label(const UI::Template &temp, const char *text) : Label(temp, std::string(text)) { }
29 
30  virtual ~Label();
31 
32  void SetText(const std::string &value);
33 
34  std::string GetText() const { return text; }
35 
39  void SetIcon(const Graphics::Bitmap &value);
40 
44  void SetIcon(const Graphics::Animation &value);
45 
49 
53 
55  void RemoveIcon();
56 
58  bool HasIcon() const { return icon != nullptr; }
59 
62  const Graphics::Animation &GetIcon() const {
63  if(!HasIcon())
64  throw std::runtime_error("This widget has no icon.");
65 
66  return *icon;
67  }
68 
70  void OwnIcon();
71 
73  void OwnIcon(const Graphics::Animation &value);
74 
76  void OwnIcon(Graphics::Bitmap &&value);
77 
78  virtual bool Activate() override;
79 
81 
83 
84  private:
85  std::string text;
86  const Graphics::Animation *icon = nullptr;
87  const Graphics::AnimationProvider *iconprov = nullptr;
88 
89  bool ownicon = false;
90 
91  protected:
92  virtual bool allowfocus() const override;
93 
94  };
95 
96 } }
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::Widgets::Label::HasIcon
bool HasIcon() const
Returns if the label has an icon.
Definition: Label.h:58
Gorgon::Widgets::Label::GetIcon
const Graphics::Animation & GetIcon() const
Returns the icon on the label.
Definition: Label.h:62
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::Label::SetIconProvider
void SetIconProvider(const Graphics::AnimationProvider &value)
Changes the icon on the label.
Definition: Label.cpp:53
Gorgon::Widgets::Label::RemoveIcon
void RemoveIcon()
Removes the icon on the label.
Definition: Label.cpp:66
Label.h
Gorgon::Graphics::AnimationProvider
A regular drawable animation provider.
Definition: Animations.h:28
Gorgon::Widgets::Label::OwnIcon
void OwnIcon()
Transfers the ownership of the current icon.
Definition: Label.cpp:78
Gorgon::UI::Template
This class stores visual information about a widget template.
Definition: Template.h:392
Gorgon::TextualProperty
Supports everything that string class supports including +, +=, length()
Definition: Property.h:562
Gorgon::Resource::GID::Text
constexpr Type Text
Stores text data, no longer a resource.
Definition: GID.h:134
Gorgon::Widgets::Label::allowfocus
virtual bool allowfocus() const override
Should return true if the widget can be focused.
Definition: Label.cpp:100
Gorgon::Widgets::Label::~Label
virtual ~Label()
Definition: Label.cpp:23
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::Widgets::Label::SetText
void SetText(const std::string &value)
Definition: Label.cpp:28
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::Label::Label
Label(const Label &)=delete
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::Registry::Label_Regular
@ Label_Regular
Definition: Registry.h:22
Gorgon::Graphics::Bitmap
This object contains an bitmap image.
Definition: Bitmap.h:25
Gorgon::Widgets::Label::Label
Label(Registry::TemplateType type)
Definition: Label.h:20
Gorgon::Animation::Base::DeleteAnimation
virtual void DeleteAnimation() const
Deletes this animation.
Definition: Animation.h:379
Registry.h
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::Label::Activate
virtual bool Activate() override
Activates the widget.
Definition: Label.cpp:93
Gorgon::Widgets::Label::GetText
std::string GetText() const
Definition: Label.h:34
Gorgon::Widgets::Label::Label
Label(std::string text="", Registry::TemplateType type=Registry::Label_Regular)
Definition: Label.h:15
Gorgon::Widgets::Label::SetIcon
void SetIcon(const Graphics::Bitmap &value)
Changes the icon on the label.
Definition: Label.cpp:48
Gorgon::Widgets::Label::Icon
ObjectProperty< Label, const Graphics::Animation, &Label::GetIcon, &Label::SetIcon > Icon
Definition: Label.h:82
Gorgon::UI::WidgetContainer::FocusNext
bool FocusNext()
Focuses the next widget that accepts focus.
Definition: WidgetContainer.cpp:141
Gorgon::Widgets::Label
Definition: Label.h:11
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
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::Label::Label
Label(const UI::Template &temp, const char *text)
Definition: Label.h:28
Gorgon::Input::Keyboard::Keycodes::Left
constexpr Key Left
Definition: Keyboard.h:62
Gorgon::Widgets::Label::Text
TextualProperty< Label, std::string, &Label::GetText, &Label::SetText > Text
Definition: Label.h:80
Gorgon::Widgets::Registry
This class stores templates for elements.
Definition: Registry.h:12