1 | // Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of NV Libraries.
|
---|
5 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
6 |
|
---|
7 | #include "nv/gui/gui_environment.hh"
|
---|
8 |
|
---|
9 | #include "nv/gui/gui_renderer.hh"
|
---|
10 |
|
---|
11 |
|
---|
12 | /*
|
---|
13 |
|
---|
14 | TODO: parse a lua stylesheet as per Trac wiki
|
---|
15 |
|
---|
16 | IDEA: Store everything in std::unordered_maps, with lua_value's?
|
---|
17 |
|
---|
18 | A lua_value is a variant stores strings as const char* that deletes them on destructor?
|
---|
19 | Question is that there might not be much gained on speed anyway, due to Lua's speed.
|
---|
20 | Special function field allows delayed per parse execution?
|
---|
21 |
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "nv/gfx/sliced_buffer.hh"
|
---|
25 | #include "nv/gfx/texture_atlas.hh"
|
---|
26 |
|
---|
27 | #include <vector>
|
---|
28 |
|
---|
29 | using namespace nv;
|
---|
30 | using namespace nv::gui;
|
---|
31 |
|
---|
32 | environment::environment( window* w, const std::string& shader_path )
|
---|
33 | : m_renderer( nullptr ), m_window( w ), m_screen( nullptr )
|
---|
34 | {
|
---|
35 | m_area.dim( dimension( w->get_width(), w->get_height() ) );
|
---|
36 | m_screen = new screen( this, m_area );
|
---|
37 | m_renderer = new renderer( w, shader_path );
|
---|
38 | root::add_child( m_screen );
|
---|
39 | }
|
---|
40 |
|
---|
41 | void nv::gui::environment::load_style( const std::string& filename )
|
---|
42 | {
|
---|
43 | m_renderer->load_style( filename );
|
---|
44 | }
|
---|
45 |
|
---|
46 | void environment::update( element* e, uint32 elapsed )
|
---|
47 | {
|
---|
48 | if ( e->is_dirty() || e->m_render_data == nullptr )
|
---|
49 | {
|
---|
50 | m_renderer->redraw( e, elapsed );
|
---|
51 | e->set_dirty( false );
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | void environment::draw( element* e )
|
---|
56 | {
|
---|
57 | m_renderer->draw( e );
|
---|
58 | }
|
---|
59 |
|
---|
60 | void environment::update()
|
---|
61 | {
|
---|
62 | m_screen->on_update( 0 );
|
---|
63 | }
|
---|
64 |
|
---|
65 | void environment::draw()
|
---|
66 | {
|
---|
67 | m_screen->on_draw();
|
---|
68 | m_renderer->draw();
|
---|
69 | }
|
---|
70 |
|
---|
71 | void environment::add_child( object* child )
|
---|
72 | {
|
---|
73 | // TODO: check if element
|
---|
74 | m_screen->add_child( child );
|
---|
75 | }
|
---|
76 |
|
---|
77 | environment::~environment()
|
---|
78 | {
|
---|
79 | destroy_children();
|
---|
80 | delete m_renderer;
|
---|
81 | }
|
---|
82 |
|
---|