nomlib
Loading...
Searching...
No Matches
UIContext.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_UICONTEXT_HPP
30#define NOMLIB_GUI_UICONTEXT_HPP
31
32#include <memory>
33
34#include "export.hpp"
35#include "nomlib/config.hpp"
36#include "nomlib/math/Point2.hpp"
37#include "nomlib/math/Size2.hpp"
38
39// Forward declarations (third-party)
40namespace Rocket {
41namespace Core {
42
43class Context;
44class RenderInterface;
45class ElementDocument;
46
47} // namespace Core
48} // namespace Rocket
49
50namespace nom {
51
52// Forward declarations
53struct Event;
54class EventHandler;
55class IUIEventHandler;
56
60class NOM_EXPORT UIContext
61{
62 public:
63 typedef UIContext self_type;
64
68
70 virtual ~UIContext();
71
77 void shutdown();
78
80 bool debugger_enabled() const;
81
84
87
96 Size2i debugger_size() const;
97
109 void set_debugger_position(const Point2i& pos);
110
122 Size2i beacon_size() const;
123
131 void set_beacon_position(const Point2i& pos);
132
141 void set_debugger_size(const Size2i& dims);
142
149 Rocket::Core::Context* context() const;
150
156 Size2i size() const;
157
159 bool valid() const;
160
174 bool create_context( const std::string& name, const Size2i& res,
175 Rocket::Core::RenderInterface* interface = nullptr );
176
177 Rocket::Core::ElementDocument*
178 load_document_file( const std::string& filename );
179
180 Rocket::Core::ElementDocument* load_mouse_cursor_file( const std::string& filename );
181
182 void show_mouse_cursor( bool state );
183
184 bool load_font( const std::string& filename );
185
191 void set_size(const Size2i& dims);
192
201
204 void update();
205
208 void draw();
209
210 private:
219
221 void process_event(const nom::Event& evt);
222
225
229 Rocket::Core::Context* context_;
230
234 Rocket::Core::RenderInterface* renderer_;
235
237 std::unique_ptr<IUIEventHandler> evt_;
238
239 // Non-owned pointer
240 EventHandler* event_handler_ = nullptr;
241
243 Size2i res_;
244};
245
246} // namespace nom
247
248#endif // include guard defined
Event handling abstraction.
Interface for a nom::UIContext event processing loop.
void set_size(const Size2i &dims)
Resize the dimensions (width and height) of this context instance.
virtual ~UIContext()
Destructor.
void initialize_debugger()
Initialize libRocket's visual debugger tool.
bool create_context(const std::string &name, const Size2i &res, Rocket::Core::RenderInterface *interface=nullptr)
Create a new element context used by libRocket.
bool debugger_enabled() const
Get the state of the visual debugger for the context.
bool debugger_
Active state of libRocket's visual debugger.
Size2i beacon_size() const
Get the visual error beacon dimensions.
void process_event(const nom::Event &evt)
Internal event processing loop for the context.
void set_debugger_position(const Point2i &pos)
Set the visual debugger's position.
void disable_debugger()
Disable libRocket's visual debugger tool.
void enable_debugger()
Enable libRocket's visual debugger tool.
Size2i res_
The dimensions of the context.
std::unique_ptr< IUIEventHandler > evt_
The internal event handler for the context.
UIContext()
Default constructor; initialize the visual debugger state to boolean FALSE.
Size2i size() const
Get the dimensions (width and height) of this context instance.
void shutdown()
Free the resources (documents) used by the context followed by the context itself.
Rocket::Core::Context * context() const
Get libRocket's context.
void set_debugger_size(const Size2i &dims)
Set the visual debugger's dimensions.
void set_beacon_position(const Point2i &pos)
Set the visual error beacon position.
Size2i debugger_size() const
Get the visual debugger's dimensions.
Rocket::Core::RenderInterface * renderer_
Rendering bridge between libRocket and nomlib.
bool valid() const
Get the validity status of this context instance.
Rocket::Core::Context * context_
The implementation's element context (used by libRocket).
void set_event_handler(nom::EventHandler &evt_handler)
Install the event handler used by the context.
Event handling types.
Definition Event.hpp:458