Changeset 257
- Timestamp:
- 06/14/14 22:40:25 (11 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gui/gui_element.hh
r132 r257 25 25 class element : public object 26 26 { 27 protected: 28 29 /** 30 * Creates a new GUI element with the give root node and postioning data. 31 * 32 * @param r The rectangle representing the position and size of this element. 33 */ 34 explicit element( const rectangle& r ); 35 27 36 public: 28 29 /**30 * Creates a new GUI element.31 */32 element() : object() {}33 34 /**35 * Creates a new GUI element with the give root node and postioning data.36 *37 * @param aroot The root object that will be this object's parent.38 * @param r The rectangle representing the position and size of this element.39 */40 element( root* aroot, const rectangle& r );41 37 42 38 /** … … 49 45 50 46 /** 51 * Event handler for update events. Calls on_update for all affected children.47 * Event handler for update events. 52 48 * 53 49 * @param elapsed Time since last update. 54 50 */ 55 virtual void on_update( uint32 elapsed );56 57 /** 58 * Event handler for draw events. Calls on_draw for all affected children.59 */ 60 virtual void on_draw() ;51 virtual void on_update( uint32 /*elapsed*/ ) {} 52 53 /** 54 * Event handler for draw events. 55 */ 56 virtual void on_draw() {} 61 57 62 58 /** … … 191 187 virtual void recalculate_absolute_children(); 192 188 189 protected: 193 190 /** 194 191 * Destroys the element. -
trunk/nv/gui/gui_environment.hh
r234 r257 28 28 { 29 29 public: 30 screen( root* aroot, const rectangle& r ) : element( aroot,r ) {}30 screen( const rectangle& r ) : element( r ) {} 31 31 virtual bool on_event( const io_event& ) { return false; } 32 32 virtual void recalculate_absolute() { recalculate_absolute_children(); } … … 39 39 // temporary 40 40 void load_style( const std::string& filename ); 41 element* create_element( element* parent, const rectangle& r ); 41 42 void update( element* e, uint32 elapsed ); 42 43 void draw( element* e ); -
trunk/nv/object.hh
r256 r257 30 30 31 31 /** 32 * Object default constructor, needed for RTTI33 */34 object();35 36 /**37 32 * Object constructor 38 33 */ 39 object( root* aroot,const string& aid );34 explicit object( const string& aid ); 40 35 41 36 /** … … 94 89 95 90 /** 96 * Destroys all children.97 */98 void destroy_children();99 100 /**101 91 * Searches for child by pointer. 102 92 * … … 133 123 */ 134 124 virtual object* get_parent() const { return m_parent; } 135 136 /**137 * Returns the root object of this object.138 *139 * @returns root object of current object140 */141 virtual root* get_root() const { return (root*)m_root; }142 125 143 126 /** … … 178 161 * Destroys all children, unregisters the object from the uid_store. 179 162 */ 163 protected: 180 164 virtual ~object(); 181 165 182 166 protected: 183 void register_with_lua( const char* lua_name, const char* storage );184 185 protected:186 root* m_root; ///< pointer to root187 167 string m_id; ///< id type of the object 188 168 string m_name; ///< name of the object -
trunk/nv/root.hh
r256 r257 19 19 { 20 20 public: 21 root() : object( nullptr, "" ), m_lua_state( nullptr ), m_uid_store( nullptr ) { m_root = this; } 22 virtual void child_added( object* ) {} 23 virtual void child_removed( object* ) {} 24 virtual void object_created( object* o ); 25 virtual void object_destroyed( object* o ); 21 root() : object( "" ), m_lua_state( nullptr ), m_uid_store( nullptr ) {} 26 22 lua::state* get_lua_state() const { return m_lua_state; } 27 23 uid_store* get_uid_store() const { return m_uid_store; } 28 virtual ~root() 29 { 30 object_destroyed( this ); 31 destroy_children(); 32 m_root = nullptr; 24 template < typename T > 25 object* create_object( const std::string& id ) 26 { 27 object* o = new T(id); 28 object_created(o); 29 return o; 33 30 } 31 void register_with_lua( object* o, const char* lua_name, const char* storage ); 32 void destroy_children( object* o ); 33 virtual void destroy_object( object* o ); 34 virtual ~root() { destroy_object( this ); } 34 35 protected: 36 virtual void object_created( object* o ); 37 35 38 lua::state* m_lua_state; 36 39 uid_store* m_uid_store; -
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.