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 "nomlib/config.hpp"
35#include "nomlib/math/Point2.hpp"
36#include "nomlib/math/Size2.hpp"
37#include "nomlib/gui/RocketUtilities.hpp"
38
39namespace nom {
40
41// Forward declarations
42class UIEventListener;
43class UIContext;
44
46{
47 public:
48 typedef UIWidget self_type;
49 typedef self_type* raw_ptr;
50
51 enum FocusPolicy
52 {
53 NONE = rocket::ElementDocument::FocusFlags::NONE,
54 FOCUS = rocket::ElementDocument::FocusFlags::FOCUS,
55 MODAL = rocket::ElementDocument::FocusFlags::MODAL
56 };
57
63
65 virtual ~UIWidget();
66
75 virtual Point2i position() const;
76
85 virtual Size2i size() const;
86
94 virtual void set_position( const Point2i& pos );
95
107 virtual void set_size( const Size2i& dims );
108
111
113 rocket::ElementDocument* document() const;
114
115 bool valid() const;
116 bool valid( rocket::Element* target ) const;
117 bool visible() const;
118
119 const std::string& title_id() const;
120 std::string title() const;
121
125 uint32 text_alignment( rocket::Element* target ) const;
126
127 bool set_context(UIContext* ctx);
128
129 bool load_document_file( const std::string& filename );
130
131 void show();
132 void hide();
133 void close();
134
138 void set_focus( uint32 focus = FocusPolicy::FOCUS );
139
141 bool hit_test( rocket::Element* target, const Point2i& pt );
142
143 void set_title( const std::string& text );
144
145 void set_title_id( const std::string& id );
146
147 void set_font( rocket::Element* target, const std::string& font );
148 void set_font_size( rocket::Element* target, int point_size );
149
150 bool set_alignment(uint32 alignment);
151
156 void set_text_alignment( rocket::Element* element, uint32 alignment );
157
165 void register_event_listener( rocket::Element* element,
166 const std::string& ev,
167 UIEventListener* observer,
168 bool interruptible = false );
169
170 private:
173
175 rocket::ElementDocument* document_;
176
177 std::string title_id_;
178};
179
180} // namespace nom
181
182#endif // include guard defined
libRocket context abstraction
Definition UIContext.hpp:60
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:175
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:172
virtual ~UIWidget()
Destructor.