- Timestamp:
- 06/14/14 22:40:25 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/gui_element.cc
r126 r257 7 7 #include "nv/gui/gui_element.hh" 8 8 9 #include "nv/gui/gui_environment.hh"10 11 9 using namespace nv; 12 10 using namespace nv::gui; 13 11 14 element::element( root* aroot,const rectangle& r )15 : object( aroot,"" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr )12 element::element( const rectangle& r ) 13 : object( "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr ) 16 14 { 17 15 18 }19 20 void element::on_update( uint32 elapsed )21 {22 if ( is_visible() )23 {24 for ( object* i : *this )25 {26 ((element*)i)->on_update( elapsed );27 }28 }29 ((environment*)m_root)->update( this, elapsed );30 }31 32 void element::on_draw()33 {34 if ( is_visible() )35 {36 ((environment*)m_root)->draw( this );37 for ( object* i : *this )38 {39 ((element*)i)->on_draw();40 }41 }42 16 } 43 17 -
trunk/src/gui/gui_environment.cc
r239 r257 34 34 { 35 35 m_area.dim( dimension( w->get_width(), w->get_height() ) ); 36 m_screen = new screen( this,m_area );36 m_screen = new screen( m_area ); 37 37 m_renderer = new renderer( w, shader_path ); 38 38 root::add_child( m_screen ); … … 44 44 } 45 45 46 element* 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 46 55 void environment::update( element* e, uint32 elapsed ) 47 56 { 57 e->on_update( elapsed ); 58 if ( e->is_visible() ) 59 { 60 for ( object* i : *e ) 61 { 62 update( ((element*)i), elapsed ); 63 } 64 } 48 65 if ( e->is_dirty() || e->m_render_data == nullptr ) 49 66 { … … 55 72 void environment::draw( element* e ) 56 73 { 57 m_renderer->draw( e ); 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 } 58 83 } 59 84 60 85 void environment::update() 61 86 { 62 m_screen->on_update(0 );87 update( m_screen, 0 ); 63 88 } 64 89 65 90 void environment::draw() 66 91 { 67 m_screen->on_draw();92 draw( m_screen ); 68 93 m_renderer->draw(); 69 94 } … … 77 102 environment::~environment() 78 103 { 79 destroy_children( );104 destroy_children( this ); 80 105 delete m_renderer; 81 106 } -
trunk/src/object.cc
r256 r257 8 8 9 9 #include <algorithm> 10 #include "nv/root.hh"11 10 #include "nv/types.hh" 12 11 #include "nv/lua/lua_state.hh" … … 15 14 using namespace nv; 16 15 17 object::object() 18 : m_root( nullptr ) 19 , m_id() 16 object::object( const string& aid ) 17 : m_id( aid ) 20 18 , m_name() 21 19 , m_uid(0) … … 26 24 , m_child_count(0) 27 25 { 28 }29 30 object::object( root* aroot, const string& aid )31 : m_root( aroot )32 , m_id( aid )33 , m_name()34 , m_uid(0)35 , m_lua_index(lua::ref_none)36 , m_lua_proto_index(lua::ref_none)37 , m_parent( nullptr )38 , m_children()39 , m_child_count(0)40 {41 if ( m_root )42 {43 m_root->object_created( this );44 }45 26 } 46 27 … … 56 37 m_children.push_back( child ); 57 38 m_child_count++; 58 m_root->child_added( child );59 39 } 60 40 } … … 71 51 (*it)->m_parent = nullptr; 72 52 m_children.erase(it); 73 m_root->child_removed( child );74 53 } 75 54 } … … 89 68 } 90 69 91 void object::destroy_children()92 {93 while ( !m_children.empty() )94 {95 delete m_children.front();96 }97 }98 99 70 object::~object() 100 71 { 101 if ( m_root )102 {103 m_root->object_destroyed( this );104 }105 detach();106 destroy_children();107 72 } 108 73 … … 195 160 // db->create_type<object>("object").fields(fields); 196 161 // } 197 198 void nv::object::register_with_lua( const char* lua_name, const char* storage )199 {200 lua::state* state = get_root()->get_lua_state();201 if (state)202 {203 if ( lua_name != nullptr )204 {205 m_lua_index = state->register_object( this, lua_name );206 }207 if ( storage != nullptr )208 {209 m_lua_proto_index = state->register_proto( this, storage );210 }211 }212 } -
trunk/src/root.cc
r256 r257 18 18 } 19 19 20 void nv::root:: object_destroyed( object* o )20 void nv::root::destroy_object( object* o ) 21 21 { 22 destroy_children( o ); 23 o->detach(); 22 24 if ( m_lua_state && o->m_lua_index != lua::ref_none ) 23 25 { … … 28 30 m_uid_store->remove( o->m_uid ); 29 31 } 32 if ( o != this) delete o; 30 33 } 34 35 void nv::root::destroy_children( object* o ) 36 { 37 while ( !o->m_children.empty() ) 38 { 39 destroy_object( o->m_children.front() ); 40 } 41 } 42 43 void nv::root::register_with_lua( object* o, const char* lua_name, const char* storage ) 44 { 45 if ( m_lua_state ) 46 { 47 if ( lua_name != nullptr ) 48 { 49 o->m_lua_index = m_lua_state->register_object( o, lua_name ); 50 } 51 if ( storage != nullptr ) 52 { 53 o->m_lua_proto_index = m_lua_state->register_proto( o, storage ); 54 } 55 } 56 57 } 58
Note: See TracChangeset
for help on using the changeset viewer.