source: trunk/src/gui/gui_environment.cc @ 266

Last change on this file since 266 was 264, checked in by epyon, 11 years ago
  • decoupling - root doesn't have to be an object
  • decoupling - gui::environment doesn't need a root object at all
File size: 2.5 KB
Line 
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
29using namespace nv;
30using namespace nv::gui;
31
32environment::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( m_area );
37        m_renderer = new renderer( w, shader_path );
38}
39
40void nv::gui::environment::load_style( const std::string& filename )
41{
42        m_renderer->load_style( filename );
43}
44
45element* nv::gui::environment::create_element( element* parent, const rectangle& r )
46{
47        element* result = new element( r );
48        if ( parent == nullptr ) parent = m_screen;
49        parent->add_child( result );
50        return result;
51}
52
53void nv::gui::environment::destroy_element( element* e )
54{
55        destroy_children( e );
56        e->detach();
57        delete e;
58}
59
60void environment::update( element* e, uint32 elapsed )
61{
62        e->on_update( elapsed );
63        if ( e->is_visible() )
64        {
65                for ( object* i : *e )
66                {
67                        update( ((element*)i), elapsed );
68                }
69        }
70        if ( e->is_dirty() || e->m_render_data == nullptr )
71        {
72                m_renderer->redraw( e, elapsed );
73                e->set_dirty( false );
74        }
75}
76
77void environment::draw( element* e )
78{
79        if ( e->is_visible() )
80        {
81                e->on_draw();
82                m_renderer->draw( e );
83                for ( object* i : *e )
84                {
85                        draw((element*)i);
86                }
87        }
88}
89
90void environment::update()
91{
92        update( m_screen, 0 );
93}
94
95void environment::draw()
96{
97        draw( m_screen );
98        m_renderer->draw();
99}
100
101void environment::add_child( element* child )
102{
103        m_screen->add_child( child );
104}
105
106void environment::destroy_children( element* e )
107{
108        while ( !e->m_children.empty() )
109        {
110                destroy_element( (element*)e->m_children.front() );
111        }
112}
113
114
115environment::~environment()
116{
117        destroy_element( m_screen );
118        delete m_renderer;
119}
120
Note: See TracBrowser for help on using the repository browser.