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 "nomlib/config.hpp"
35#include "nomlib/math/Point2.hpp"
36#include "nomlib/math/Size2.hpp"
37
38// Forward declarations (third-party)
39namespace Rocket {
40namespace Core {
41
42class Context;
43class RenderInterface;
44class ElementDocument;
45
46} // namespace Core
47} // namespace Rocket
48
49namespace nom {
50
51// Forward declarations
52struct Event;
53class EventHandler;
54class IUIEventHandler;
55
60{
61 public:
62 typedef UIContext self_type;
63
67
69 virtual ~UIContext();
70
76 void shutdown();
77
79 bool debugger_enabled() const;
80
83
86
95 Size2i debugger_size() const;
96
108 void set_debugger_position(const Point2i& pos);
109
121 Size2i beacon_size() const;
122
130 void set_beacon_position(const Point2i& pos);
131
140 void set_debugger_size(const Size2i& dims);
141
148 Rocket::Core::Context* context() const;
149
155 Size2i size() const;
156
158 bool valid() const;
159
173 bool create_context( const std::string& name, const Size2i& res,
174 Rocket::Core::RenderInterface* interface = nullptr );
175
176 Rocket::Core::ElementDocument*
177 load_document_file( const std::string& filename );
178
179 Rocket::Core::ElementDocument* load_mouse_cursor_file( const std::string& filename );
180
181 void show_mouse_cursor( bool state );
182
183 bool load_font( const std::string& filename );
184
190 void set_size(const Size2i& dims);
191
200
203 void update();
204
207 void draw();
208
209 private:
218
220 void process_event(const nom::Event& evt);
221
224
228 Rocket::Core::Context* context_;
229
233 Rocket::Core::RenderInterface* renderer_;
234
236 std::unique_ptr<IUIEventHandler> evt_;
237
238 // Non-owned pointer
239 EventHandler* event_handler_ = nullptr;
240
242 Size2i res_;
243};
244
245} // namespace nom
246
247#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:457