nomlib
Loading...
Searching...
No Matches
UIWidget.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_GUI_UIWIDGET_HPP
30#define NOMLIB_GUI_UIWIDGET_HPP
31
32#include <string>
33
34#include "export.hpp"
35#include "nomlib/config.hpp"
36#include "nomlib/math/Point2.hpp"
37#include "nomlib/math/Size2.hpp"
38#include "nomlib/gui/RocketUtilities.hpp"
39
40namespace nom {
41
42// Forward declarations
43class UIEventListener;
44class UIContext;
45
46class NOM_EXPORT UIWidget
47{
48 public:
49 typedef UIWidget self_type;
50 typedef self_type* raw_ptr;
51
52 enum FocusPolicy
53 {
54 NONE = rocket::ElementDocument::FocusFlags::NONE,
55 FOCUS = rocket::ElementDocument::FocusFlags::FOCUS,
56 MODAL = rocket::ElementDocument::FocusFlags::MODAL
57 };
58
64
66 virtual ~UIWidget();
67
76 virtual Point2i position() const;
77
86 virtual Size2i size() const;
87
95 virtual void set_position( const Point2i& pos );
96
108 virtual void set_size( const Size2i& dims );
109
112
114 rocket::ElementDocument* document() const;
115
116 bool valid() const;
117 bool valid( rocket::Element* target ) const;
118 bool visible() const;
119
120 const std::string& title_id() const;
121 std::string title() const;
122
126 uint32 text_alignment( rocket::Element* target ) const;
127
128 bool set_context(UIContext* ctx);
129
130 bool load_document_file( const std::string& filename );
131
132 void show();
133 void hide();
134 void close();
135
139 void set_focus( uint32 focus = FocusPolicy::FOCUS );
140
142 bool hit_test( rocket::Element* target, const Point2i& pt );
143
144 void set_title( const std::string& text );
145
146 void set_title_id( const std::string& id );
147
148 void set_font( rocket::Element* target, const std::string& font );
149 void set_font_size( rocket::Element* target, int point_size );
150
151 bool set_alignment(uint32 alignment);
152
157 void set_text_alignment( rocket::Element* element, uint32 alignment );
158
166 void register_event_listener( rocket::Element* element,
167 const std::string& ev,
168 UIEventListener* observer,
169 bool interruptible = false );
170
171 private:
174
176 rocket::ElementDocument* document_;
177
178 std::string title_id_;
179};
180
181} // namespace nom
182
183#endif // include guard defined
libRocket context abstraction
Definition UIContext.hpp:61
Interface for an event listener for libRocket's platform.
virtual Size2i size() const
Get the size of the widget.
bool hit_test(rocket::Element *target, const Point2i &pt)
Perform a bounds coordinates collision test.
void register_event_listener(rocket::Element *element, const std::string &ev, UIEventListener *observer, bool interruptible=false)
Register an event listener for an element.
UIContext * context() const
virtual Point2i position() const
Get the position of the widget.
void set_focus(uint32 focus=FocusPolicy::FOCUS)
Set the focus policy.
UIWidget()
Default constructor; initialize default title element ID.
uint32 text_alignment(rocket::Element *target) const
Get an element's text alignment.
rocket::ElementDocument * document() const
virtual void set_position(const Point2i &pos)
Set the position of the widget.
rocket::ElementDocument * document_
Definition UIWidget.hpp:176
virtual void set_size(const Size2i &dims)
Set the size of the widget.
void set_text_alignment(rocket::Element *element, uint32 alignment)
UIContext * ctx_
Definition UIWidget.hpp:173
virtual ~UIWidget()
Destructor.