Gorgon Game Engine
Composer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../UI/Widget.h"
4 #include "../UI/WidgetContainer.h"
5 
6 namespace Gorgon { namespace Widgets {
7 
19  class Composer : public UI::Widget, protected UI::WidgetContainer {
20  public:
21  ~Composer() { }
22 
23  using Widget::Resize;
24 
25  using Widget::Move;
26 
27  using Widget::Remove;
28 
30 
31 
32  virtual bool Activate() override;
33 
34  virtual bool IsVisible() const override {
35  return base.IsVisible();
36  }
37 
38  virtual Geometry::Size GetInteriorSize() const override {
39  return base.GetSize();
40  }
41 
42  virtual Geometry::Size GetSize() const override {
43  return base.GetSize();
44  }
45 
46  virtual bool ResizeInterior(Geometry::Size size) override {
47  Resize(size);
48 
49  return true;
50  }
51 
52  virtual void Resize(const Geometry::Size &size) override;
53 
54  virtual Geometry::Point GetLocation() const override {
55  return base.GetLocation();
56  }
57 
58  virtual void Move(const Geometry::Point &location) override;
59 
60  using Widget::EnsureVisible;
61 
62  bool EnsureVisible(const UI::Widget &widget) override {
63  return true;
64  }
65 
66  using Widget::Enable;
67  using Widget::Disable;
68  using Widget::ToggleEnabled;
69 
70  virtual void SetEnabled(bool value) override {
71  if(value != IsEnabled()) {
72  enabled = value;
74  }
75  }
76 
77  virtual bool IsEnabled() const override {
78  return enabled;
79  }
80 
82  virtual bool KeyEvent(Input::Key key, float state) override { return distributekeyevent(key, state, true); }
83 
86  virtual bool CharacterEvent(Char c) override { return distributecharevent(c); }
87 
88 
89  virtual UI::ExtenderRequestResponse RequestExtender(const Gorgon::Layer &self) override;
90 
91  protected:
92  //ensure this object is derived
94  }
95 
96  virtual bool allowfocus() const override;
97 
98  virtual void focused() override;
99 
100  virtual void focuslost() override;
101 
102  virtual Layer &getlayer() override {
103  return base;
104  }
105 
106  void focuschanged() override;
107 
108  virtual void addto(Layer &layer) override {
109  layer.Add(base);
110  }
111 
112  virtual void removefrom(Layer &layer) override {
113  layer.Remove(base);
114  }
115 
116  virtual void setlayerorder(Layer &, int order) override {
117  base.PlaceBefore(order);
118  }
119 
120  private:
121  bool enabled = true;
122 
123  virtual void hide() override;
124 
125  virtual void show() override;
126 
127  Layer base;
128  };
129 
130 } }
Gorgon::UI::Widget::HasParent
bool HasParent() const
Returns if this widget has a parent.
Definition: Widget.h:140
Gorgon::Layer::Resize
virtual void Resize(const Geometry::Size &size)
Resizes the layer to the given size.
Definition: Layer.h:337
Gorgon::Widgets::Composer::addto
virtual void addto(Layer &layer) override
When called, widget should locate itself on to this layer.
Definition: Composer.h:108
Gorgon::Containers::Remove
void Remove(const I_ &first, const I_ &end)
This function works with collection iterators.
Definition: Iterator.h:386
Gorgon::UI::Widget::Focus
bool Focus()
Transfers the focus to this widget.
Definition: Widget.cpp:13
Gorgon::Widgets::Composer::GetInteriorSize
virtual Geometry::Size GetInteriorSize() const override
Should return the interior (usable) size of the container.
Definition: Composer.h:38
Gorgon::UI::WidgetContainer::distributekeyevent
bool distributekeyevent(Input::Key key, float state, bool handlestandard)
Distributes the pressed key to the focused widget.
Definition: WidgetContainer.cpp:400
Gorgon::Layer::Add
void Add(Layer &layer)
Adds the given layer as a child.
Definition: Layer.cpp:23
Gorgon::Layer::GetLocation
Geometry::Point GetLocation() const
Returns the current location of the layer.
Definition: Layer.h:403
Gorgon::Widgets::Composer::focuslost
virtual void focuslost() override
This is called after the focus is lost.
Definition: Composer.cpp:34
Gorgon::Widgets::Composer::GetLocation
virtual Geometry::Point GetLocation() const override
Returns the location of the widget.
Definition: Composer.h:54
Gorgon::UI::WidgetContainer::CurrentFocusStrategy
FocusStrategy CurrentFocusStrategy() const
Returns the active focus strategy. This function will not return Inherit.
Definition: WidgetContainer.h:340
Gorgon::Widgets::Composer::SetEnabled
virtual void SetEnabled(bool value) override
Sets the enabled state of the widget.
Definition: Composer.h:70
Gorgon::Widgets::Composer::removefrom
virtual void removefrom(Layer &layer) override
When called, widget should remove itself from the given layer.
Definition: Composer.h:112
Gorgon::Widgets::Composer::allowfocus
virtual bool allowfocus() const override
Should return true if the widget can be focused.
Definition: Composer.cpp:15
Gorgon::Widgets::Composer::Composer
Composer()
Definition: Composer.h:93
Gorgon::UI::WidgetContainer::FocusFirst
bool FocusFirst()
Focuses the first widget that accepts focus.
Definition: WidgetContainer.cpp:137
Composer.h
Gorgon::Input::Mouse::Move
@ Move
Definition: Mouse.h:17
Gorgon::Widgets::Composer::Resize
virtual void Resize(const Geometry::Size &size) override
Changes the size of the widget.
Definition: Composer.cpp:58
Gorgon::Layer::IsVisible
virtual bool IsVisible() const
Returns whether this layer is effectively visible.
Definition: Layer.h:459
Gorgon::Input::Key
int Key
A type to represent an input key.
Definition: Input.h:14
Gorgon::Widgets::Composer::CharacterEvent
virtual bool CharacterEvent(Char c) override
This function should be called whenever a character is received from operating system.
Definition: Composer.h:86
Gorgon::Widgets::Composer::KeyEvent
virtual bool KeyEvent(Input::Key key, float state) override
This function should be called whenever a key is pressed or released.
Definition: Composer.h:82
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::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::Char
uint32_t Char
Definition: Types.h:46
Gorgon::Widgets::Composer::focuschanged
void focuschanged() override
This function is called when the focus is changed.
Definition: Composer.cpp:39
Gorgon::Layer::PlaceBefore
void PlaceBefore(int before)
Places this layer before the given index.
Definition: Layer.h:290
Gorgon::Widgets::Composer::GetSize
virtual Geometry::Size GetSize() const override
Returns the size of the widget.
Definition: Composer.h:42
Gorgon::Widgets::Composer::focused
virtual void focused() override
This is called after the focus is transferred to this widget.
Definition: Composer.cpp:28
Gorgon::Widgets::Composer::Move
virtual void Move(const Geometry::Point &location) override
Moves this widget to the given position.
Definition: Composer.cpp:64
Gorgon::UI::WidgetContainer::RemoveFocus
bool RemoveFocus()
Removes the focus from the focused widget.
Definition: WidgetContainer.cpp:335
Gorgon::Widgets::Composer::IsVisible
virtual bool IsVisible() const override
Should return whether the container is visible.
Definition: Composer.h:34
Gorgon::Layer::Move
virtual void Move(const Geometry::Point &location)
Moves this layer to the given location.
Definition: Layer.h:327
Gorgon::UI::ExtenderRequestResponse
This structure is used to transfer extender request response.
Definition: WidgetContainer.h:15
Gorgon::Widgets::Composer
This object allows its users to compose widgets using other widgets.
Definition: Composer.h:19
Gorgon::UI::WidgetContainer::widgets
Containers::Collection< Widget > widgets
This container is sorted by the focus order.
Definition: WidgetContainer.h:395
Gorgon::Layer::Remove
void Remove(Layer &layer)
Removes the given layer.
Definition: Layer.h:203
Gorgon::Layer
This class is the base class for all layer types.
Definition: Layer.h:79
Gorgon::UI::ExtenderRequestResponse::CoordinatesInExtender
Geometry::Point CoordinatesInExtender
Coordinates of the given point in the extender container.
Definition: WidgetContainer.h:24
Gorgon::Geometry::basic_Point
This class represents a 2D point.
Definition: Point.h:32
Gorgon::UI::WidgetContainer::HasFocusedWidget
bool HasFocusedWidget() const
Returns if this container has a focused widget.
Definition: WidgetContainer.h:171
Gorgon::Widgets::Composer::~Composer
~Composer()
Definition: Composer.h:21
Gorgon::Widgets::Composer::setlayerorder
virtual void setlayerorder(Layer &, int order) override
When called, widget should reorder itself in layer hierarchy.
Definition: Composer.h:116
Gorgon::UI::WidgetContainer::RequestExtender
virtual ExtenderRequestResponse RequestExtender(const Gorgon::Layer &self)=0
This function will return a container that will act as an extender.
Gorgon::UI::Widget::IsFocused
bool IsFocused() const
Returns if this widget is focused.
Definition: Widget.h:98
Gorgon::Layer::Hide
virtual void Hide()
Hides this layer.
Definition: Layer.h:456
Gorgon::Layer::Show
virtual void Show()
Displays this layer.
Definition: Layer.h:453
Gorgon::Widgets::Composer::EnsureVisible
bool EnsureVisible(const UI::Widget &widget) override
Ensures the widget is visible.
Definition: Composer.h:62
Gorgon::Widgets::Composer::getlayer
virtual Layer & getlayer() override
Returns the layer that will be used to place the contained widgets.
Definition: Composer.h:102
Gorgon::Widgets::Composer::ResizeInterior
virtual bool ResizeInterior(Geometry::Size size) override
Should resize the interior (usable) size of the container.
Definition: Composer.h:46
Gorgon::Widgets::Composer::Activate
virtual bool Activate() override
Activates the widget.
Definition: Composer.cpp:6
Gorgon::UI::WidgetContainer::Deny
@ Deny
No widget is allowed focus and this container will not handle any keys.
Definition: WidgetContainer.h:63
Gorgon::UI::WidgetContainer
This class is the base class for all widget containers.
Definition: WidgetContainer.h:37
Gorgon::UI::Widget::boundschanged
virtual void boundschanged()
Call this function when the widget bounds is changed.
Definition: Widget.cpp:62
Gorgon::UI::WidgetContainer::distributecharevent
bool distributecharevent(Char c)
Distributes a pressed character to the focused widget.
Definition: WidgetContainer.cpp:416
Gorgon::GL::Resize
void Resize(const Geometry::Size &size)
Resizes the active context.
Definition: OpenGL.cpp:273
Gorgon::Widgets::Composer::IsEnabled
virtual bool IsEnabled() const override
Returns whether the widget is enabled.
Definition: Composer.h:77
Gorgon::UI::WidgetContainer::distributeparentenabled
void distributeparentenabled(bool state)
Distributes a enabled state to children.
Definition: WidgetContainer.cpp:426
Gorgon::Layer::GetSize
Geometry::Size GetSize() const
Returns the size of the layer.
Definition: Layer.h:362
Gorgon::UI::Widget
This class is the base for all widgets.
Definition: Widget.h:16
Gorgon::Widgets::Composer::RequestExtender
virtual UI::ExtenderRequestResponse RequestExtender(const Gorgon::Layer &self) override
This function will return a container that will act as an extender.
Definition: Composer.cpp:71