2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
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 #include "entityinspector.h"
24 #include "debugging/debugging.h"
27 #include "ifilesystem.h"
29 #include "iscenegraph.h"
30 #include "iselection.h"
35 #include <gdk/gdkkeysyms.h>
37 #include <uilib/uilib.h>
41 #include "eclasslib.h"
43 #include "generic/callback.h"
45 #include "stream/stringstream.h"
46 #include "moduleobserver.h"
50 #include "gtkutil/accelerator.h"
51 #include "gtkutil/dialog.h"
52 #include "gtkutil/filechooser.h"
53 #include "gtkutil/messagebox.h"
54 #include "gtkutil/nonmodal.h"
55 #include "gtkutil/button.h"
56 #include "gtkutil/entry.h"
57 #include "gtkutil/container.h"
63 #include "mainframe.h"
64 #include "textureentry.h"
65 #include "groupdialog.h"
67 GtkEntry* numeric_entry_new(){
68 GtkEntry* entry = ui::Entry();
69 gtk_widget_show( GTK_WIDGET( entry ) );
70 gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 );
76 typedef std::map<std::string, std::string> KeyValues;
77 KeyValues g_selectedKeyValues;
78 KeyValues g_selectedDefaultKeyValues;
81 const char* SelectedEntity_getValueForKey( const char* key ){
83 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
84 if ( i != g_selectedKeyValues.end() ) {
85 return ( *i ).second.c_str();
89 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
90 if ( i != g_selectedDefaultKeyValues.end() ) {
91 return ( *i ).second.c_str();
97 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
98 StringOutputStream command( 256 );
99 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
100 UndoableCommand undo( command.c_str() );
101 Scene_EntitySetKeyValue_Selected( key, value );
104 class EntityAttribute
107 virtual ~EntityAttribute(){}
108 virtual ui::Widget getWidget() const = 0;
109 virtual void update() = 0;
110 virtual void release() = 0;
113 class BooleanAttribute : public EntityAttribute
116 GtkCheckButton* m_check;
118 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
123 BooleanAttribute( const char* key ) :
126 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
127 gtk_widget_show( GTK_WIDGET( check ) );
131 guint handler = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( toggled ), this );
132 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
136 ui::Widget getWidget() const {
137 return ui::Widget(GTK_WIDGET( m_check ));
143 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_check ) ) ? "1" : "0" );
145 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
148 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
149 if ( !string_empty( value ) ) {
150 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), atoi( value ) != 0 );
154 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), false );
157 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
161 class StringAttribute : public EntityAttribute
165 NonModalEntry m_nonModal;
167 StringAttribute( const char* key ) :
170 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
171 GtkEntry* entry = ui::Entry();
172 gtk_widget_show( GTK_WIDGET( entry ) );
173 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
176 m_nonModal.connect( m_entry );
178 ui::Widget getWidget() const {
179 return ui::Widget(GTK_WIDGET( m_entry ));
181 GtkEntry* getEntry() const {
189 StringOutputStream value( 64 );
190 value << gtk_entry_get_text( m_entry );
191 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
193 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
196 StringOutputStream value( 64 );
197 value << SelectedEntity_getValueForKey( m_key.c_str() );
198 gtk_entry_set_text( m_entry, value.c_str() );
200 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
203 class ShaderAttribute : public StringAttribute
206 ShaderAttribute( const char* key ) : StringAttribute( key ){
207 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
212 class ModelAttribute : public EntityAttribute
215 BrowsedPathEntry m_entry;
216 NonModalEntry m_nonModal;
218 ModelAttribute( const char* key ) :
220 m_entry( BrowseCaller( *this ) ),
221 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
222 m_nonModal.connect( m_entry.m_entry.m_entry );
227 ui::Widget getWidget() const {
228 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
231 StringOutputStream value( 64 );
232 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
233 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
235 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
237 StringOutputStream value( 64 );
238 value << SelectedEntity_getValueForKey( m_key.c_str() );
239 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
241 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
242 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
243 const char *filename = misc_model_dialog( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) ));
245 if ( filename != 0 ) {
250 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
253 const char* browse_sound( ui::Widget parent ){
254 StringOutputStream buffer( 1024 );
256 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
258 if ( !file_readable( buffer.c_str() ) ) {
261 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
264 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
265 if ( filename != 0 ) {
266 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
267 if ( relative == filename ) {
268 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
275 class SoundAttribute : public EntityAttribute
278 BrowsedPathEntry m_entry;
279 NonModalEntry m_nonModal;
281 SoundAttribute( const char* key ) :
283 m_entry( BrowseCaller( *this ) ),
284 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
285 m_nonModal.connect( m_entry.m_entry.m_entry );
290 ui::Widget getWidget() const {
291 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
294 StringOutputStream value( 64 );
295 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
296 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
298 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
300 StringOutputStream value( 64 );
301 value << SelectedEntity_getValueForKey( m_key.c_str() );
302 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
304 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
305 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
306 const char *filename = browse_sound( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) )) );
308 if ( filename != 0 ) {
313 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
316 inline double angle_normalised( double angle ){
317 return float_mod( angle, 360.0 );
320 class AngleAttribute : public EntityAttribute
324 NonModalEntry m_nonModal;
326 AngleAttribute( const char* key ) :
329 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
330 GtkEntry* entry = numeric_entry_new();
332 m_nonModal.connect( m_entry );
337 ui::Widget getWidget() const {
338 return ui::Widget(GTK_WIDGET( m_entry ));
341 StringOutputStream angle( 32 );
342 angle << angle_normalised( entry_get_float( m_entry ) );
343 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
345 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
348 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
349 if ( !string_empty( value ) ) {
350 StringOutputStream angle( 32 );
351 angle << angle_normalised( atof( value ) );
352 gtk_entry_set_text( m_entry, angle.c_str() );
356 gtk_entry_set_text( m_entry, "0" );
359 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
364 typedef const char* String;
365 const String buttons[] = { "up", "down", "z-axis" };
368 class DirectionAttribute : public EntityAttribute
372 NonModalEntry m_nonModal;
374 NonModalRadio m_nonModalRadio;
377 DirectionAttribute( const char* key ) :
380 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
381 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
382 m_nonModalRadio( ApplyRadioCaller( *this ) ){
383 GtkEntry* entry = numeric_entry_new();
385 m_nonModal.connect( m_entry );
387 m_nonModalRadio.connect( m_radio.m_radio );
389 m_hbox = ui::HBox( FALSE, 4 );
390 gtk_widget_show( GTK_WIDGET( m_hbox ) );
392 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_radio.m_hbox ), TRUE, TRUE, 0 );
393 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_entry ), TRUE, TRUE, 0 );
398 ui::Widget getWidget() const {
399 return ui::Widget(GTK_WIDGET( m_hbox ));
402 StringOutputStream angle( 32 );
403 angle << angle_normalised( entry_get_float( m_entry ) );
404 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
406 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
409 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
410 if ( !string_empty( value ) ) {
411 float f = float(atof( value ) );
413 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
414 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
415 gtk_entry_set_text( m_entry, "" );
417 else if ( f == -2 ) {
418 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
419 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
420 gtk_entry_set_text( m_entry, "" );
424 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), TRUE );
425 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
426 StringOutputStream angle( 32 );
427 angle << angle_normalised( f );
428 gtk_entry_set_text( m_entry, angle.c_str() );
433 gtk_entry_set_text( m_entry, "0" );
436 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
439 int index = radio_button_get_active( m_radio.m_radio );
441 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
443 else if ( index == 1 ) {
444 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
446 else if ( index == 2 ) {
450 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
460 AnglesEntry() : m_roll( 0 ), m_pitch( 0 ), m_yaw( 0 ){
464 typedef BasicVector3<double> DoubleVector3;
466 class AnglesAttribute : public EntityAttribute
469 AnglesEntry m_angles;
470 NonModalEntry m_nonModal;
473 AnglesAttribute( const char* key ) :
475 m_nonModal( ApplyCaller( *this ),
476 UpdateCaller( *this ) ),
477 m_hbox(ui::HBox( TRUE, 4 ))
479 gtk_widget_show( GTK_WIDGET( m_hbox ) );
481 GtkEntry* entry = numeric_entry_new();
482 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
483 m_angles.m_pitch = entry;
484 m_nonModal.connect( m_angles.m_pitch );
487 GtkEntry* entry = numeric_entry_new();
488 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
489 m_angles.m_yaw = entry;
490 m_nonModal.connect( m_angles.m_yaw );
493 GtkEntry* entry = numeric_entry_new();
494 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
495 m_angles.m_roll = entry;
496 m_nonModal.connect( m_angles.m_roll );
502 ui::Widget getWidget() const {
503 return ui::Widget(GTK_WIDGET( m_hbox ));
506 StringOutputStream angles( 64 );
507 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
508 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
509 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
510 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
512 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
515 StringOutputStream angle( 32 );
516 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
517 if ( !string_empty( value ) ) {
518 DoubleVector3 pitch_yaw_roll;
519 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
520 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
523 angle << angle_normalised( pitch_yaw_roll.x() );
524 gtk_entry_set_text( m_angles.m_pitch, angle.c_str() );
527 angle << angle_normalised( pitch_yaw_roll.y() );
528 gtk_entry_set_text( m_angles.m_yaw, angle.c_str() );
531 angle << angle_normalised( pitch_yaw_roll.z() );
532 gtk_entry_set_text( m_angles.m_roll, angle.c_str() );
537 gtk_entry_set_text( m_angles.m_pitch, "0" );
538 gtk_entry_set_text( m_angles.m_yaw, "0" );
539 gtk_entry_set_text( m_angles.m_roll, "0" );
542 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
551 Vector3Entry() : m_x( 0 ), m_y( 0 ), m_z( 0 ){
555 class Vector3Attribute : public EntityAttribute
558 Vector3Entry m_vector3;
559 NonModalEntry m_nonModal;
562 Vector3Attribute( const char* key ) :
564 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
565 m_hbox = ui::HBox( TRUE, 4 );
566 gtk_widget_show( GTK_WIDGET( m_hbox ) );
568 GtkEntry* entry = numeric_entry_new();
569 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
570 m_vector3.m_x = entry;
571 m_nonModal.connect( m_vector3.m_x );
574 GtkEntry* entry = numeric_entry_new();
575 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
576 m_vector3.m_y = entry;
577 m_nonModal.connect( m_vector3.m_y );
580 GtkEntry* entry = numeric_entry_new();
581 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
582 m_vector3.m_z = entry;
583 m_nonModal.connect( m_vector3.m_z );
589 ui::Widget getWidget() const {
590 return ui::Widget(GTK_WIDGET( m_hbox ));
593 StringOutputStream vector3( 64 );
594 vector3 << entry_get_float( m_vector3.m_x )
595 << " " << entry_get_float( m_vector3.m_y )
596 << " " << entry_get_float( m_vector3.m_z );
597 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
599 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
602 StringOutputStream buffer( 32 );
603 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
604 if ( !string_empty( value ) ) {
606 if ( !string_parse_vector3( value, x_y_z ) ) {
607 x_y_z = DoubleVector3( 0, 0, 0 );
611 gtk_entry_set_text( m_vector3.m_x, buffer.c_str() );
615 gtk_entry_set_text( m_vector3.m_y, buffer.c_str() );
619 gtk_entry_set_text( m_vector3.m_z, buffer.c_str() );
624 gtk_entry_set_text( m_vector3.m_x, "0" );
625 gtk_entry_set_text( m_vector3.m_y, "0" );
626 gtk_entry_set_text( m_vector3.m_z, "0" );
629 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
632 class NonModalComboBox
635 guint m_changedHandler;
637 static gboolean changed( GtkComboBox *widget, NonModalComboBox* self ){
643 NonModalComboBox( const Callback& changed ) : m_changed( changed ), m_changedHandler( 0 ){
645 void connect( GtkComboBox* combo ){
646 m_changedHandler = g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( changed ), this );
648 void setActive( GtkComboBox* combo, int value ){
649 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
650 gtk_combo_box_set_active( combo, value );
655 class ListAttribute : public EntityAttribute
658 GtkComboBox* m_combo;
659 NonModalComboBox m_nonModal;
660 const ListAttributeType& m_type;
662 ListAttribute( const char* key, const ListAttributeType& type ) :
665 m_nonModal( ApplyCaller( *this ) ),
667 auto combo = ui::ComboBoxText();
669 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
671 gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), ( *i ).first.c_str() );
674 gtk_widget_show( GTK_WIDGET( combo ) );
675 m_nonModal.connect( combo );
682 ui::Widget getWidget() const {
683 return ui::Widget(GTK_WIDGET( m_combo ));
686 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
688 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
691 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
692 ListAttributeType::const_iterator i = m_type.findValue( value );
693 if ( i != m_type.end() ) {
694 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
698 m_nonModal.setActive( m_combo, 0 );
701 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
707 ui::Widget g_entity_split1;
708 ui::Widget g_entity_split2;
709 int g_entitysplit1_position;
710 int g_entitysplit2_position;
712 bool g_entityInspector_windowConstructed = false;
714 GtkTreeView* g_entityClassList;
715 GtkTextView* g_entityClassComment;
717 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
719 GtkEntry* g_entityKeyEntry;
720 GtkEntry* g_entityValueEntry;
722 GtkListStore* g_entlist_store;
723 GtkListStore* g_entprops_store;
724 const EntityClass* g_current_flags = 0;
725 const EntityClass* g_current_comment = 0;
726 const EntityClass* g_current_attributes = 0;
728 // the number of active spawnflags
729 int g_spawnflag_count;
730 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
731 int spawn_table[MAX_FLAGS];
732 // we change the layout depending on how many spawn flags we need to display
733 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
734 GtkTable* g_spawnflagsTable;
736 GtkVBox* g_attributeBox = 0;
737 typedef std::vector<EntityAttribute*> EntityAttributes;
738 EntityAttributes g_entityAttributes;
741 void GlobalEntityAttributes_clear(){
742 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
746 g_entityAttributes.clear();
749 class GetKeyValueVisitor : public Entity::Visitor
751 KeyValues& m_keyvalues;
753 GetKeyValueVisitor( KeyValues& keyvalues )
754 : m_keyvalues( keyvalues ){
757 void visit( const char* key, const char* value ){
758 m_keyvalues.insert( KeyValues::value_type( std::string( key ), std::string( value ) ) );
763 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
764 GetKeyValueVisitor visitor( keyvalues );
766 entity.forEachKeyValue( visitor );
768 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
770 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
772 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
776 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
777 class EntityGetKeyValues : public SelectionSystem::Visitor
779 KeyValues& m_keyvalues;
780 KeyValues& m_defaultValues;
781 mutable std::set<Entity*> m_visited;
783 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
784 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
786 void visit( scene::Instance& instance ) const {
787 Entity* entity = Node_getEntity( instance.path().top() );
788 if ( entity == 0 && instance.path().size() != 1 ) {
789 entity = Node_getEntity( instance.path().parent() );
791 if ( entity != 0 && m_visited.insert( entity ).second ) {
792 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
795 } visitor( keyvalues, defaultValues );
796 GlobalSelectionSystem().foreachSelected( visitor );
799 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
800 KeyValues::iterator i = keyvalues.find( std::string( key ) );
801 if ( i != keyvalues.end() ) {
802 return ( *i ).second.c_str();
807 class EntityClassListStoreAppend : public EntityClassVisitor
811 EntityClassListStoreAppend( GtkListStore* store_ ) : store( store_ ){
813 void visit( EntityClass* e ){
815 gtk_list_store_append( store, &iter );
816 gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
820 void EntityClassList_fill(){
821 EntityClassListStoreAppend append( g_entlist_store );
822 GlobalEntityClassManager().forEach( append );
825 void EntityClassList_clear(){
826 gtk_list_store_clear( g_entlist_store );
829 void SetComment( EntityClass* eclass ){
830 if ( eclass == g_current_comment ) {
834 g_current_comment = eclass;
836 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
837 gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
840 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
841 if ( eclass == g_current_flags ) {
845 g_current_flags = eclass;
847 int spawnflag_count = 0;
850 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
851 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
853 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
854 spawn_table[spawnflag_count] = i;
860 // disable all remaining boxes
861 // NOTE: these boxes might not even be on display
863 for ( int i = 0; i < g_spawnflag_count; ++i )
865 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
866 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), " " );
867 gtk_widget_hide( widget );
868 gtk_widget_ref( widget );
869 gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget );
873 g_spawnflag_count = spawnflag_count;
876 for ( int i = 0; i < g_spawnflag_count; ++i )
878 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
879 gtk_widget_show( widget );
881 StringOutputStream str( 16 );
882 str << LowerCase( eclass->flagnames[spawn_table[i]] );
884 gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1,
885 (GtkAttachOptions)( GTK_FILL ),
886 (GtkAttachOptions)( GTK_FILL ), 0, 0 );
887 gtk_widget_unref( widget );
889 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), str.c_str() );
894 void EntityClassList_selectEntityClass( EntityClass* eclass ){
895 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
897 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
900 gtk_tree_model_get( model, &iter, 0, &text, -1 );
901 if ( strcmp( text, eclass->name() ) == 0 ) {
902 GtkTreeView* view = g_entityClassList;
903 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
904 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
905 if ( GTK_WIDGET_REALIZED( view ) ) {
906 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
908 gtk_tree_path_free( path );
915 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
916 GtkTable* row = DialogRow_new( name, attribute.getWidget() );
917 DialogVBox_packRow( g_attributeBox, GTK_WIDGET( row ) );
921 template<typename Attribute>
922 class StatelessAttributeCreator
925 static EntityAttribute* create( const char* name ){
926 return new Attribute( name );
930 class EntityAttributeFactory
932 typedef EntityAttribute* ( *CreateFunc )( const char* name );
933 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
936 EntityAttributeFactory(){
937 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
938 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
939 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
940 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
941 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
942 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
943 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
944 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
945 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
946 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
947 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
948 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
949 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
951 EntityAttribute* create( const char* type, const char* name ){
952 Creators::iterator i = m_creators.find( type );
953 if ( i != m_creators.end() ) {
954 return ( *i ).second( name );
956 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
957 if ( listType != 0 ) {
958 return new ListAttribute( name, *listType );
964 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
966 void EntityInspector_setEntityClass( EntityClass *eclass ){
967 EntityClassList_selectEntityClass( eclass );
968 SurfaceFlags_setEntityClass( eclass );
970 if ( eclass != g_current_attributes ) {
971 g_current_attributes = eclass;
973 container_remove_all( GTK_CONTAINER( g_attributeBox ) );
974 GlobalEntityAttributes_clear();
976 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
978 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
979 if ( attribute != 0 ) {
980 g_entityAttributes.push_back( attribute );
981 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
987 void EntityInspector_updateSpawnflags(){
989 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
990 for ( int i = 0; i < g_spawnflag_count; ++i )
992 int v = !!( f & ( 1 << spawn_table[i] ) );
994 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), v );
998 // take care of the remaining ones
999 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1001 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), FALSE );
1006 void EntityInspector_applySpawnflags(){
1011 for ( i = 0; i < g_spawnflag_count; ++i )
1013 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1014 f |= v << spawn_table[i];
1017 sprintf( sz, "%i", f );
1018 const char* value = ( f == 0 ) ? "" : sz;
1021 StringOutputStream command;
1022 command << "entitySetFlags -flags " << f;
1023 UndoableCommand undo( "entitySetSpawnflags" );
1025 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1030 void EntityInspector_updateKeyValues(){
1031 g_selectedKeyValues.clear();
1032 g_selectedDefaultKeyValues.clear();
1033 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1035 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1037 EntityInspector_updateSpawnflags();
1039 GtkListStore* store = g_entprops_store;
1041 // save current key/val pair around filling epair box
1042 // row_select wipes it and sets to first in list
1043 std::string strKey( gtk_entry_get_text( g_entityKeyEntry ) );
1044 std::string strVal( gtk_entry_get_text( g_entityValueEntry ) );
1046 gtk_list_store_clear( store );
1047 // Walk through list and add pairs
1048 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1051 gtk_list_store_append( store, &iter );
1052 StringOutputStream key( 64 );
1053 key << ( *i ).first.c_str();
1054 StringOutputStream value( 64 );
1055 value << ( *i ).second.c_str();
1056 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1059 gtk_entry_set_text( g_entityKeyEntry, strKey.c_str() );
1060 gtk_entry_set_text( g_entityValueEntry, strVal.c_str() );
1062 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1068 class EntityInspectorDraw
1070 IdleDraw m_idleDraw;
1072 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1075 m_idleDraw.queueDraw();
1079 EntityInspectorDraw g_EntityInspectorDraw;
1082 void EntityInspector_keyValueChanged(){
1083 g_EntityInspectorDraw.queueDraw();
1085 void EntityInspector_selectionChanged( const Selectable& ){
1086 EntityInspector_keyValueChanged();
1089 // Creates a new entity based on the currently selected brush and entity type.
1091 void EntityClassList_createEntity(){
1092 GtkTreeView* view = g_entityClassList;
1094 // find out what type of entity we are trying to create
1095 GtkTreeModel* model;
1097 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1098 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) )).alert( "You must have a selected class to create an entity", "info" );
1103 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1106 StringOutputStream command;
1107 command << "entityCreate -class " << text;
1109 UndoableCommand undo( command.c_str() );
1111 Entity_createFromSelection( text, g_vector3_identity );
1116 void EntityInspector_applyKeyValue(){
1117 // Get current selection text
1118 StringOutputStream key( 64 );
1119 key << gtk_entry_get_text( g_entityKeyEntry );
1120 StringOutputStream value( 64 );
1121 value << gtk_entry_get_text( g_entityValueEntry );
1124 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1125 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1126 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1131 // RR2DO2: we don't want spaces in entity keys
1132 if ( strstr( key.c_str(), " " ) ) {
1133 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1137 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1138 StringOutputStream command;
1139 command << "entitySetClass -class " << value.c_str();
1140 UndoableCommand undo( command.c_str() );
1141 Scene_EntitySetClassname_Selected( value.c_str() );
1145 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1149 void EntityInspector_clearKeyValue(){
1150 // Get current selection text
1151 StringOutputStream key( 64 );
1152 key << gtk_entry_get_text( g_entityKeyEntry );
1154 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1155 StringOutputStream command;
1156 command << "entityDeleteKey -key " << key.c_str();
1157 UndoableCommand undo( command.c_str() );
1158 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1162 void EntityInspector_clearAllKeyValues(){
1163 UndoableCommand undo( "entityClear" );
1165 // remove all keys except classname
1166 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1168 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1169 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1174 // =============================================================================
1177 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1178 GtkTreeModel* model;
1179 GtkTreeIter selected;
1180 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1181 EntityClass* eclass;
1182 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1183 if ( eclass != 0 ) {
1184 SetComment( eclass );
1189 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1190 if ( event->type == GDK_2BUTTON_PRESS ) {
1191 EntityClassList_createEntity();
1197 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1198 unsigned int code = gdk_keyval_to_upper( event->keyval );
1200 if ( event->keyval == GDK_Return ) {
1201 EntityClassList_createEntity();
1205 // select the entity that starts with the key pressed
1206 if ( code <= 'Z' && code >= 'A' ) {
1207 GtkTreeView* view = g_entityClassList;
1208 GtkTreeModel* model;
1210 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1211 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1212 gtk_tree_model_get_iter_first( model, &iter );
1215 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1218 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1220 if ( toupper( text[0] ) == (int)code ) {
1221 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1222 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1223 if ( GTK_WIDGET_REALIZED( view ) ) {
1224 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1226 gtk_tree_path_free( path );
1232 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1233 gtk_tree_model_get_iter_first( model, &iter );
1242 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1243 // find out what type of entity we are trying to create
1244 GtkTreeModel* model;
1246 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1252 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1254 gtk_entry_set_text( g_entityKeyEntry, key );
1255 gtk_entry_set_text( g_entityValueEntry, val );
1261 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1262 EntityInspector_applySpawnflags();
1265 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1266 if ( event->keyval == GDK_Return ) {
1267 if ( widget == g_entityKeyEntry ) {
1268 gtk_entry_set_text( g_entityValueEntry, "" );
1269 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1273 EntityInspector_applyKeyValue();
1277 if ( event->keyval == GDK_Escape ) {
1278 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1285 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1286 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1287 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1289 g_entityInspector_windowConstructed = false;
1290 GlobalEntityAttributes_clear();
1293 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1294 ui::Widget vbox = ui::VBox( FALSE, 2 );
1295 gtk_widget_show( vbox );
1296 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1298 g_signal_connect( G_OBJECT( vbox ), "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1301 ui::Widget split1 = ui::VPaned();
1302 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1303 gtk_widget_show( split1 );
1305 g_entity_split1 = split1;
1308 ui::Widget split2 = ui::VPaned();
1309 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1310 gtk_widget_show( split2 );
1312 g_entity_split2 = split2;
1316 ui::Widget scr = ui::ScrolledWindow();
1317 gtk_widget_show( scr );
1318 gtk_paned_add1( GTK_PANED( split2 ), scr );
1319 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1320 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1323 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER );
1325 GtkTreeView* view = ui::TreeView( ui::TreeModel( GTK_TREE_MODEL( store ) ));
1326 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1327 gtk_tree_view_set_headers_visible( view, FALSE );
1328 g_signal_connect( G_OBJECT( view ), "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1329 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1332 auto renderer = ui::CellRendererText();
1333 GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1334 gtk_tree_view_append_column( view, column );
1338 GtkTreeSelection* selection = gtk_tree_view_get_selection( view );
1339 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1342 gtk_widget_show( GTK_WIDGET( view ) );
1344 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( view ) );
1346 g_object_unref( G_OBJECT( store ) );
1347 g_entityClassList = view;
1348 g_entlist_store = store;
1353 ui::Widget scr = ui::ScrolledWindow();
1354 gtk_widget_show( scr );
1355 gtk_paned_add2( GTK_PANED( split2 ), scr );
1356 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1357 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1360 GtkTextView* text = ui::TextView();
1361 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1362 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1363 gtk_text_view_set_editable( text, FALSE );
1364 gtk_widget_show( GTK_WIDGET( text ) );
1365 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( text ) );
1366 g_entityClassComment = text;
1372 ui::Widget split2 = ui::VPaned();
1373 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1374 gtk_widget_show( split2 );
1377 ui::Widget vbox2 = ui::VBox( FALSE, 2 );
1378 gtk_widget_show( vbox2 );
1379 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1382 // Spawnflags (4 colums wide max, or window gets too wide.)
1383 GtkTable* table = ui::Table( 4, 4, FALSE );
1384 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1385 gtk_widget_show( GTK_WIDGET( table ) );
1387 g_spawnflagsTable = table;
1389 for ( int i = 0; i < MAX_FLAGS; i++ )
1391 GtkCheckButton* check = ui::CheckButton( "" );
1392 gtk_widget_ref( GTK_WIDGET( check ) );
1393 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1394 g_entitySpawnflagsCheck[i] = check;
1400 ui::Widget scr = ui::ScrolledWindow();
1401 gtk_widget_show( scr );
1402 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1403 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1404 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1407 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING );
1409 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
1410 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1411 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1414 auto renderer = ui::CellRendererText();
1415 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1416 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1420 auto renderer = ui::CellRendererText();
1421 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1422 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1426 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
1427 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1430 gtk_widget_show( view );
1432 gtk_container_add( GTK_CONTAINER( scr ), view );
1434 g_object_unref( G_OBJECT( store ) );
1436 g_entprops_store = store;
1442 GtkTable* table = ui::Table( 2, 2, FALSE );
1443 gtk_widget_show( GTK_WIDGET( table ) );
1444 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1445 gtk_table_set_row_spacings( table, 3 );
1446 gtk_table_set_col_spacings( table, 5 );
1449 GtkEntry* entry = ui::Entry();
1450 gtk_widget_show( GTK_WIDGET( entry ) );
1451 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1452 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1453 (GtkAttachOptions)( 0 ), 0, 0 );
1454 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1455 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1456 g_entityKeyEntry = entry;
1460 GtkEntry* entry = ui::Entry();
1461 gtk_widget_show( GTK_WIDGET( entry ) );
1462 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1463 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1464 (GtkAttachOptions)( 0 ), 0, 0 );
1465 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1466 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1467 g_entityValueEntry = entry;
1471 GtkLabel* label = GTK_LABEL( ui::Label( "Value" ) );
1472 gtk_widget_show( GTK_WIDGET( label ) );
1473 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1474 (GtkAttachOptions)( GTK_FILL ),
1475 (GtkAttachOptions)( 0 ), 0, 0 );
1476 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1480 GtkLabel* label = GTK_LABEL( ui::Label( "Key" ) );
1481 gtk_widget_show( GTK_WIDGET( label ) );
1482 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1483 (GtkAttachOptions)( GTK_FILL ),
1484 (GtkAttachOptions)( 0 ), 0, 0 );
1485 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1490 GtkBox* hbox = ui::HBox( TRUE, 4 );
1491 gtk_widget_show( GTK_WIDGET( hbox ) );
1492 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1495 GtkButton* button = ui::Button( "Clear All" );
1496 gtk_widget_show( GTK_WIDGET( button ) );
1497 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1498 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1501 GtkButton* button = ui::Button( "Delete Key" );
1502 gtk_widget_show( GTK_WIDGET( button ) );
1503 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1504 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1510 ui::Widget scr = ui::ScrolledWindow();
1511 gtk_widget_show( scr );
1512 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1514 ui::Widget viewport = ui::Widget(gtk_viewport_new( 0, 0 ));
1515 gtk_widget_show( viewport );
1516 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1518 g_attributeBox = ui::VBox( FALSE, 2 );
1519 gtk_widget_show( GTK_WIDGET( g_attributeBox ) );
1521 gtk_container_add( GTK_CONTAINER( viewport ), GTK_WIDGET( g_attributeBox ) );
1522 gtk_container_add( GTK_CONTAINER( scr ), viewport );
1523 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1530 // show the sliders in any case
1531 if ( g_entitysplit2_position > 22 ) {
1532 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1535 g_entitysplit2_position = 22;
1536 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1538 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1539 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1542 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1546 g_entityInspector_windowConstructed = true;
1547 EntityClassList_fill();
1549 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1550 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1551 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1554 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1559 class EntityInspector : public ModuleObserver
1561 std::size_t m_unrealised;
1563 EntityInspector() : m_unrealised( 1 ){
1566 if ( --m_unrealised == 0 ) {
1567 if ( g_entityInspector_windowConstructed ) {
1568 //globalOutputStream() << "Entity Inspector: realise\n";
1569 EntityClassList_fill();
1574 if ( ++m_unrealised == 1 ) {
1575 if ( g_entityInspector_windowConstructed ) {
1576 //globalOutputStream() << "Entity Inspector: unrealise\n";
1577 EntityClassList_clear();
1583 EntityInspector g_EntityInspector;
1585 #include "preferencesystem.h"
1586 #include "stringio.h"
1588 void EntityInspector_construct(){
1589 GlobalEntityClassManager().attach( g_EntityInspector );
1591 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1592 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1596 void EntityInspector_destroy(){
1597 GlobalEntityClassManager().detach( g_EntityInspector );
1600 const char *EntityInspector_getCurrentKey(){
1601 if ( !GroupDialog_isShown() ) {
1604 if ( GroupDialog_getPage() != g_page_entity ) {
1607 return gtk_entry_get_text( g_entityKeyEntry );