2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_NAMEDENTITY_H )
23 #define INCLUDED_NAMEDENTITY_H
25 #include "entitylib.h"
26 #include "eclasslib.h"
27 #include "generic/callback.h"
29 #include "entity.h" //g_showTargetNames
35 typedef std::set<NameCallback> NameCallbacks;
36 NameCallbacks m_callbacks;
38 void insert( const NameCallback& callback ){
39 m_callbacks.insert( callback );
41 void erase( const NameCallback& callback ){
42 m_callbacks.erase( callback );
44 void changed( const char* name ) const {
45 for ( NameCallbacks::const_iterator i = m_callbacks.begin(); i != m_callbacks.end(); ++i )
52 class NamedEntity : public Nameable
54 EntityKeyValues& m_entity;
55 NameCallbackSet m_changed;
58 NamedEntity( EntityKeyValues& entity ) : m_entity( entity ){
60 const char* name() const {
61 if ( string_empty( m_name.c_str() ) ) {
62 return m_entity.getEntityClass().name();
64 return m_name.c_str();
66 const char* classname() const {
67 return m_entity.getEntityClass().name();
69 void attach( const NameCallback& callback ){
70 m_changed.insert( callback );
72 void detach( const NameCallback& callback ){
73 m_changed.erase( callback );
76 void identifierChanged( const char* value ){
77 if ( string_empty( value ) ) {
78 m_changed.changed( m_entity.getEntityClass().name() );
82 m_changed.changed( value );
86 typedef MemberCaller<NamedEntity, void(const char*), &NamedEntity::identifierChanged> IdentifierChangedCaller;
89 class RenderableNamedEntity : public OpenGLRenderable
91 const NamedEntity& m_named;
92 const Vector3& m_position;
94 RenderableNamedEntity( const NamedEntity& named, const Vector3& position )
95 : m_named( named ), m_position( position ){
97 void render( RenderStateFlags state ) const {
98 glRasterPos3fv( vector3_to_array( m_position ) );
99 GlobalOpenGL().drawString( g_showTargetNames ? m_named.name() : m_named.classname() );