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

Last change on this file since 257 was 257, checked in by epyon, 11 years ago
  • object can now only created from root
  • all registration is done root side
  • gui::element draw and update logic fully in environment
  • root removed from object - a lot less coupling
File size: 2.3 KB
RevLine 
[69]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
[126]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
[152]24#include "nv/gfx/sliced_buffer.hh"
[126]25#include "nv/gfx/texture_atlas.hh"
26
27#include <vector>
28
[69]29using namespace nv;
30using namespace nv::gui;
31
[234]32environment::environment( window* w, const std::string& shader_path )
[126]33        : m_renderer( nullptr ), m_window( w ), m_screen( nullptr )
34{
35        m_area.dim( dimension( w->get_width(), w->get_height() ) );
[257]36        m_screen = new screen( m_area );
[234]37        m_renderer = new renderer( w, shader_path );
[126]38        root::add_child( m_screen );
39}
40
41void nv::gui::environment::load_style( const std::string& filename )
42{
43        m_renderer->load_style( filename );
44}
45
[257]46element* nv::gui::environment::create_element( element* parent, const rectangle& r )
47{
48        element* result = new element( r );
49        object_created( result );
50        if ( parent == nullptr ) parent = m_screen;
51        parent->add_child( result );
52        return result;
53}
54
[126]55void environment::update( element* e, uint32 elapsed )
56{
[257]57        e->on_update( elapsed );
58        if ( e->is_visible() )
59        {
60                for ( object* i : *e )
61                {
62                        update( ((element*)i), elapsed );
63                }
64        }
[126]65        if ( e->is_dirty() || e->m_render_data == nullptr )
66        {
67                m_renderer->redraw( e, elapsed );
68                e->set_dirty( false );
69        }
70}
71
[69]72void environment::draw( element* e )
73{
[257]74        if ( e->is_visible() )
75        {
76                e->on_draw();
77                m_renderer->draw( e );
78                for ( object* i : *e )
79                {
80                        draw((element*)i);
81                }
82        }
[69]83}
[126]84
85void environment::update()
86{
[257]87        update( m_screen, 0 );
[126]88}
89
90void environment::draw()
91{
[257]92        draw( m_screen );
[126]93        m_renderer->draw();
94}
95
96void environment::add_child( object* child )
97{
98        // TODO: check if element
99        m_screen->add_child( child );
100}
101
102environment::~environment()
103{
[257]104        destroy_children( this );
[126]105        delete m_renderer;
106}
107
Note: See TracBrowser for help on using the repository browser.