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 ui::Entry numeric_entry_new(){
68 auto entry = ui::Entry();
70 gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 );
76 typedef std::map<CopiedString, CopiedString> 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 ui::Widget getWidget() const = 0;
108 virtual void update() = 0;
109 virtual void release() = 0;
112 class BooleanAttribute : public EntityAttribute
115 GtkCheckButton* m_check;
117 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
122 BooleanAttribute( const char* key ) :
125 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
126 gtk_widget_show( GTK_WIDGET( check ) );
130 guint handler = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( toggled ), this );
131 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
135 ui::Widget getWidget() const {
136 return ui::Widget(GTK_WIDGET( m_check ));
142 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_check ) ) ? "1" : "0" );
144 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
147 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
148 if ( !string_empty( value ) ) {
149 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), atoi( value ) != 0 );
153 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), false );
156 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
160 class StringAttribute : public EntityAttribute
164 NonModalEntry m_nonModal;
166 StringAttribute( const char* key ) :
169 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
170 auto entry = ui::Entry();
171 gtk_widget_show( GTK_WIDGET( entry ) );
172 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
175 m_nonModal.connect( m_entry );
177 ui::Widget getWidget() const {
178 return ui::Widget(GTK_WIDGET( m_entry ));
180 GtkEntry* getEntry() const {
188 StringOutputStream value( 64 );
189 value << gtk_entry_get_text( m_entry );
190 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
192 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
195 StringOutputStream value( 64 );
196 value << SelectedEntity_getValueForKey( m_key.c_str() );
197 gtk_entry_set_text( m_entry, value.c_str() );
199 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
202 class ShaderAttribute : public StringAttribute
205 ShaderAttribute( const char* key ) : StringAttribute( key ){
206 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
211 class ModelAttribute : public EntityAttribute
214 BrowsedPathEntry m_entry;
215 NonModalEntry m_nonModal;
217 ModelAttribute( const char* key ) :
219 m_entry( BrowseCaller( *this ) ),
220 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
221 m_nonModal.connect( m_entry.m_entry.m_entry );
226 ui::Widget getWidget() const {
227 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
230 StringOutputStream value( 64 );
231 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
232 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
234 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
236 StringOutputStream value( 64 );
237 value << SelectedEntity_getValueForKey( m_key.c_str() );
238 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
240 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
241 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
242 const char *filename = misc_model_dialog( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) ));
244 if ( filename != 0 ) {
249 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
252 const char* browse_sound( ui::Widget parent ){
253 StringOutputStream buffer( 1024 );
255 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
257 if ( !file_readable( buffer.c_str() ) ) {
260 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
263 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
264 if ( filename != 0 ) {
265 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
266 if ( relative == filename ) {
267 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
274 class SoundAttribute : public EntityAttribute
277 BrowsedPathEntry m_entry;
278 NonModalEntry m_nonModal;
280 SoundAttribute( const char* key ) :
282 m_entry( BrowseCaller( *this ) ),
283 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
284 m_nonModal.connect( m_entry.m_entry.m_entry );
289 ui::Widget getWidget() const {
290 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
293 StringOutputStream value( 64 );
294 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
295 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
297 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
299 StringOutputStream value( 64 );
300 value << SelectedEntity_getValueForKey( m_key.c_str() );
301 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
303 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
304 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
305 const char *filename = browse_sound( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) )) );
307 if ( filename != 0 ) {
312 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
315 inline double angle_normalised( double angle ){
316 return float_mod( angle, 360.0 );
319 class AngleAttribute : public EntityAttribute
323 NonModalEntry m_nonModal;
325 AngleAttribute( const char* key ) :
328 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
329 auto entry = numeric_entry_new();
331 m_nonModal.connect( m_entry );
336 ui::Widget getWidget() const {
337 return ui::Widget(GTK_WIDGET( m_entry ));
340 StringOutputStream angle( 32 );
341 angle << angle_normalised( entry_get_float( m_entry ) );
342 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
344 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
347 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
348 if ( !string_empty( value ) ) {
349 StringOutputStream angle( 32 );
350 angle << angle_normalised( atof( value ) );
351 gtk_entry_set_text( m_entry, angle.c_str() );
355 gtk_entry_set_text( m_entry, "0" );
358 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
363 typedef const char* String;
364 const String buttons[] = { "up", "down", "z-axis" };
367 class DirectionAttribute : public EntityAttribute
371 NonModalEntry m_nonModal;
373 NonModalRadio m_nonModalRadio;
376 DirectionAttribute( const char* key ) :
379 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
380 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
381 m_nonModalRadio( ApplyRadioCaller( *this ) ){
382 auto entry = numeric_entry_new();
384 m_nonModal.connect( m_entry );
386 m_nonModalRadio.connect( m_radio.m_radio );
388 m_hbox = ui::HBox( FALSE, 4 );
389 gtk_widget_show( GTK_WIDGET( m_hbox ) );
391 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_radio.m_hbox ), TRUE, TRUE, 0 );
392 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_entry ), TRUE, TRUE, 0 );
397 ui::Widget getWidget() const {
398 return ui::Widget(GTK_WIDGET( m_hbox ));
401 StringOutputStream angle( 32 );
402 angle << angle_normalised( entry_get_float( m_entry ) );
403 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
405 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
408 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
409 if ( !string_empty( value ) ) {
410 float f = float(atof( value ) );
412 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
413 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
414 gtk_entry_set_text( m_entry, "" );
416 else if ( f == -2 ) {
417 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
418 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
419 gtk_entry_set_text( m_entry, "" );
423 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), TRUE );
424 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
425 StringOutputStream angle( 32 );
426 angle << angle_normalised( f );
427 gtk_entry_set_text( m_entry, angle.c_str() );
432 gtk_entry_set_text( m_entry, "0" );
435 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
438 int index = radio_button_get_active( m_radio.m_radio );
440 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
442 else if ( index == 1 ) {
443 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
445 else if ( index == 2 ) {
449 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
459 AnglesEntry() : m_roll( nullptr ), m_pitch( nullptr ), m_yaw( nullptr ){
463 typedef BasicVector3<double> DoubleVector3;
465 class AnglesAttribute : public EntityAttribute
468 AnglesEntry m_angles;
469 NonModalEntry m_nonModal;
472 AnglesAttribute( const char* key ) :
474 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
475 m_hbox(ui::HBox( TRUE, 4 ))
477 gtk_widget_show( GTK_WIDGET( m_hbox ) );
479 auto entry = numeric_entry_new();
480 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
481 m_angles.m_pitch = entry;
482 m_nonModal.connect( m_angles.m_pitch );
485 auto entry = numeric_entry_new();
486 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
487 m_angles.m_yaw = entry;
488 m_nonModal.connect( m_angles.m_yaw );
491 auto entry = numeric_entry_new();
492 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
493 m_angles.m_roll = entry;
494 m_nonModal.connect( m_angles.m_roll );
500 ui::Widget getWidget() const {
501 return ui::Widget(GTK_WIDGET( m_hbox ));
504 StringOutputStream angles( 64 );
505 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
506 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
507 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
508 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
510 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
513 StringOutputStream angle( 32 );
514 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
515 if ( !string_empty( value ) ) {
516 DoubleVector3 pitch_yaw_roll;
517 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
518 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
521 angle << angle_normalised( pitch_yaw_roll.x() );
522 gtk_entry_set_text( m_angles.m_pitch, angle.c_str() );
525 angle << angle_normalised( pitch_yaw_roll.y() );
526 gtk_entry_set_text( m_angles.m_yaw, angle.c_str() );
529 angle << angle_normalised( pitch_yaw_roll.z() );
530 gtk_entry_set_text( m_angles.m_roll, angle.c_str() );
535 gtk_entry_set_text( m_angles.m_pitch, "0" );
536 gtk_entry_set_text( m_angles.m_yaw, "0" );
537 gtk_entry_set_text( m_angles.m_roll, "0" );
540 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
549 Vector3Entry() : m_x( nullptr ), m_y( nullptr ), m_z( nullptr ){
553 class Vector3Attribute : public EntityAttribute
556 Vector3Entry m_vector3;
557 NonModalEntry m_nonModal;
560 Vector3Attribute( const char* key ) :
562 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
563 m_hbox = ui::HBox( TRUE, 4 );
564 gtk_widget_show( GTK_WIDGET( m_hbox ) );
566 auto entry = numeric_entry_new();
567 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
568 m_vector3.m_x = entry;
569 m_nonModal.connect( m_vector3.m_x );
572 auto entry = numeric_entry_new();
573 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
574 m_vector3.m_y = entry;
575 m_nonModal.connect( m_vector3.m_y );
578 auto entry = numeric_entry_new();
579 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
580 m_vector3.m_z = entry;
581 m_nonModal.connect( m_vector3.m_z );
587 ui::Widget getWidget() const {
588 return ui::Widget(GTK_WIDGET( m_hbox ));
591 StringOutputStream vector3( 64 );
592 vector3 << entry_get_float( m_vector3.m_x )
593 << " " << entry_get_float( m_vector3.m_y )
594 << " " << entry_get_float( m_vector3.m_z );
595 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
597 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
600 StringOutputStream buffer( 32 );
601 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
602 if ( !string_empty( value ) ) {
604 if ( !string_parse_vector3( value, x_y_z ) ) {
605 x_y_z = DoubleVector3( 0, 0, 0 );
609 gtk_entry_set_text( m_vector3.m_x, buffer.c_str() );
613 gtk_entry_set_text( m_vector3.m_y, buffer.c_str() );
617 gtk_entry_set_text( m_vector3.m_z, buffer.c_str() );
622 gtk_entry_set_text( m_vector3.m_x, "0" );
623 gtk_entry_set_text( m_vector3.m_y, "0" );
624 gtk_entry_set_text( m_vector3.m_z, "0" );
627 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
630 class NonModalComboBox
633 guint m_changedHandler;
635 static gboolean changed( GtkComboBox *widget, NonModalComboBox* self ){
641 NonModalComboBox( const Callback& changed ) : m_changed( changed ), m_changedHandler( 0 ){
643 void connect( GtkComboBox* combo ){
644 m_changedHandler = g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( changed ), this );
646 void setActive( GtkComboBox* combo, int value ){
647 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
648 gtk_combo_box_set_active( combo, value );
653 class ListAttribute : public EntityAttribute
656 GtkComboBox* m_combo;
657 NonModalComboBox m_nonModal;
658 const ListAttributeType& m_type;
660 ListAttribute( const char* key, const ListAttributeType& type ) :
663 m_nonModal( ApplyCaller( *this ) ),
665 auto combo = ui::ComboBoxText();
667 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
669 gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), ( *i ).first.c_str() );
672 gtk_widget_show( GTK_WIDGET( combo ) );
673 m_nonModal.connect( combo );
680 ui::Widget getWidget() const {
681 return ui::Widget(GTK_WIDGET( m_combo ));
684 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
686 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
689 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
690 ListAttributeType::const_iterator i = m_type.findValue( value );
691 if ( i != m_type.end() ) {
692 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
696 m_nonModal.setActive( m_combo, 0 );
699 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
705 ui::Widget g_entity_split1;
706 ui::Widget g_entity_split2;
707 int g_entitysplit1_position;
708 int g_entitysplit2_position;
710 bool g_entityInspector_windowConstructed = false;
712 GtkTreeView* g_entityClassList;
713 GtkTextView* g_entityClassComment;
715 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
717 GtkEntry* g_entityKeyEntry;
718 GtkEntry* g_entityValueEntry;
720 ui::ListStore g_entlist_store{nullptr};
721 ui::ListStore g_entprops_store{nullptr};
722 const EntityClass* g_current_flags = 0;
723 const EntityClass* g_current_comment = 0;
724 const EntityClass* g_current_attributes = 0;
726 // the number of active spawnflags
727 int g_spawnflag_count;
728 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
729 int spawn_table[MAX_FLAGS];
730 // we change the layout depending on how many spawn flags we need to display
731 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
732 GtkTable* g_spawnflagsTable;
734 GtkVBox* g_attributeBox = 0;
735 typedef std::vector<EntityAttribute*> EntityAttributes;
736 EntityAttributes g_entityAttributes;
739 void GlobalEntityAttributes_clear(){
740 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
744 g_entityAttributes.clear();
747 class GetKeyValueVisitor : public Entity::Visitor
749 KeyValues& m_keyvalues;
751 GetKeyValueVisitor( KeyValues& keyvalues )
752 : m_keyvalues( keyvalues ){
755 void visit( const char* key, const char* value ){
756 m_keyvalues.insert( KeyValues::value_type( CopiedString( key ), CopiedString( value ) ) );
761 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
762 GetKeyValueVisitor visitor( keyvalues );
764 entity.forEachKeyValue( visitor );
766 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
768 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
770 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
774 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
775 class EntityGetKeyValues : public SelectionSystem::Visitor
777 KeyValues& m_keyvalues;
778 KeyValues& m_defaultValues;
779 mutable std::set<Entity*> m_visited;
781 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
782 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
784 void visit( scene::Instance& instance ) const {
785 Entity* entity = Node_getEntity( instance.path().top() );
786 if ( entity == 0 && instance.path().size() != 1 ) {
787 entity = Node_getEntity( instance.path().parent() );
789 if ( entity != 0 && m_visited.insert( entity ).second ) {
790 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
793 } visitor( keyvalues, defaultValues );
794 GlobalSelectionSystem().foreachSelected( visitor );
797 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
798 KeyValues::iterator i = keyvalues.find( CopiedString( key ) );
799 if ( i != keyvalues.end() ) {
800 return ( *i ).second.c_str();
805 class EntityClassListStoreAppend : public EntityClassVisitor
809 EntityClassListStoreAppend( ui::ListStore store_ ) : store( store_ ){
811 void visit( EntityClass* e ){
813 gtk_list_store_append( store, &iter );
814 gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
818 void EntityClassList_fill(){
819 EntityClassListStoreAppend append( g_entlist_store );
820 GlobalEntityClassManager().forEach( append );
823 void EntityClassList_clear(){
824 gtk_list_store_clear( g_entlist_store );
827 void SetComment( EntityClass* eclass ){
828 if ( eclass == g_current_comment ) {
832 g_current_comment = eclass;
834 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
835 gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
838 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
839 if ( eclass == g_current_flags ) {
843 g_current_flags = eclass;
845 int spawnflag_count = 0;
848 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
849 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
851 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
852 spawn_table[spawnflag_count] = i;
858 // disable all remaining boxes
859 // NOTE: these boxes might not even be on display
861 for ( int i = 0; i < g_spawnflag_count; ++i )
863 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
864 gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN(widget)) ), " " );
865 gtk_widget_hide( widget );
866 g_object_ref( widget );
867 gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget );
871 g_spawnflag_count = spawnflag_count;
874 for ( int i = 0; i < g_spawnflag_count; ++i )
876 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
877 gtk_widget_show( widget );
879 StringOutputStream str( 16 );
880 str << LowerCase( eclass->flagnames[spawn_table[i]] );
882 gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1,
883 (GtkAttachOptions)( GTK_FILL ),
884 (GtkAttachOptions)( GTK_FILL ), 0, 0 );
885 g_object_unref( widget );
887 gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN(widget)) ), str.c_str() );
892 void EntityClassList_selectEntityClass( EntityClass* eclass ){
893 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
895 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
898 gtk_tree_model_get( model, &iter, 0, &text, -1 );
899 if ( strcmp( text, eclass->name() ) == 0 ) {
900 GtkTreeView* view = g_entityClassList;
901 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
902 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
903 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
904 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
906 gtk_tree_path_free( path );
913 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
914 auto row = DialogRow_new( name, attribute.getWidget() );
915 DialogVBox_packRow( ui::VBox(g_attributeBox), row );
919 template<typename Attribute>
920 class StatelessAttributeCreator
923 static EntityAttribute* create( const char* name ){
924 return new Attribute( name );
928 class EntityAttributeFactory
930 typedef EntityAttribute* ( *CreateFunc )( const char* name );
931 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
934 EntityAttributeFactory(){
935 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
936 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
937 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
938 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
939 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
940 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
941 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
942 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
943 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
944 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
945 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
946 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
947 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
949 EntityAttribute* create( const char* type, const char* name ){
950 Creators::iterator i = m_creators.find( type );
951 if ( i != m_creators.end() ) {
952 return ( *i ).second( name );
954 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
955 if ( listType != 0 ) {
956 return new ListAttribute( name, *listType );
962 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
964 void EntityInspector_setEntityClass( EntityClass *eclass ){
965 EntityClassList_selectEntityClass( eclass );
966 SurfaceFlags_setEntityClass( eclass );
968 if ( eclass != g_current_attributes ) {
969 g_current_attributes = eclass;
971 container_remove_all( GTK_CONTAINER( g_attributeBox ) );
972 GlobalEntityAttributes_clear();
974 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
976 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
977 if ( attribute != 0 ) {
978 g_entityAttributes.push_back( attribute );
979 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
985 void EntityInspector_updateSpawnflags(){
987 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
988 for ( int i = 0; i < g_spawnflag_count; ++i )
990 int v = !!( f & ( 1 << spawn_table[i] ) );
992 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), v );
996 // take care of the remaining ones
997 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
999 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), FALSE );
1004 void EntityInspector_applySpawnflags(){
1009 for ( i = 0; i < g_spawnflag_count; ++i )
1011 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1012 f |= v << spawn_table[i];
1015 sprintf( sz, "%i", f );
1016 const char* value = ( f == 0 ) ? "" : sz;
1019 StringOutputStream command;
1020 command << "entitySetFlags -flags " << f;
1021 UndoableCommand undo( "entitySetSpawnflags" );
1023 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1028 void EntityInspector_updateKeyValues(){
1029 g_selectedKeyValues.clear();
1030 g_selectedDefaultKeyValues.clear();
1031 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1033 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1035 EntityInspector_updateSpawnflags();
1037 ui::ListStore store = g_entprops_store;
1039 // save current key/val pair around filling epair box
1040 // row_select wipes it and sets to first in list
1041 CopiedString strKey( gtk_entry_get_text( g_entityKeyEntry ) );
1042 CopiedString strVal( gtk_entry_get_text( g_entityValueEntry ) );
1044 gtk_list_store_clear( store );
1045 // Walk through list and add pairs
1046 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1049 gtk_list_store_append( store, &iter );
1050 StringOutputStream key( 64 );
1051 key << ( *i ).first.c_str();
1052 StringOutputStream value( 64 );
1053 value << ( *i ).second.c_str();
1054 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1057 gtk_entry_set_text( g_entityKeyEntry, strKey.c_str() );
1058 gtk_entry_set_text( g_entityValueEntry, strVal.c_str() );
1060 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1066 class EntityInspectorDraw
1068 IdleDraw m_idleDraw;
1070 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1073 m_idleDraw.queueDraw();
1077 EntityInspectorDraw g_EntityInspectorDraw;
1080 void EntityInspector_keyValueChanged(){
1081 g_EntityInspectorDraw.queueDraw();
1083 void EntityInspector_selectionChanged( const Selectable& ){
1084 EntityInspector_keyValueChanged();
1087 // Creates a new entity based on the currently selected brush and entity type.
1089 void EntityClassList_createEntity(){
1090 GtkTreeView* view = g_entityClassList;
1092 // find out what type of entity we are trying to create
1093 GtkTreeModel* model;
1095 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1096 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) )).alert( "You must have a selected class to create an entity", "info" );
1101 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1104 StringOutputStream command;
1105 command << "entityCreate -class " << text;
1107 UndoableCommand undo( command.c_str() );
1109 Entity_createFromSelection( text, g_vector3_identity );
1114 void EntityInspector_applyKeyValue(){
1115 // Get current selection text
1116 StringOutputStream key( 64 );
1117 key << gtk_entry_get_text( g_entityKeyEntry );
1118 StringOutputStream value( 64 );
1119 value << gtk_entry_get_text( g_entityValueEntry );
1122 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1123 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1124 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1129 // RR2DO2: we don't want spaces in entity keys
1130 if ( strstr( key.c_str(), " " ) ) {
1131 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1135 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1136 StringOutputStream command;
1137 command << "entitySetClass -class " << value.c_str();
1138 UndoableCommand undo( command.c_str() );
1139 Scene_EntitySetClassname_Selected( value.c_str() );
1143 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1147 void EntityInspector_clearKeyValue(){
1148 // Get current selection text
1149 StringOutputStream key( 64 );
1150 key << gtk_entry_get_text( g_entityKeyEntry );
1152 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1153 StringOutputStream command;
1154 command << "entityDeleteKey -key " << key.c_str();
1155 UndoableCommand undo( command.c_str() );
1156 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1160 void EntityInspector_clearAllKeyValues(){
1161 UndoableCommand undo( "entityClear" );
1163 // remove all keys except classname
1164 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1166 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1167 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1172 // =============================================================================
1175 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1176 GtkTreeModel* model;
1177 GtkTreeIter selected;
1178 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1179 EntityClass* eclass;
1180 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1181 if ( eclass != 0 ) {
1182 SetComment( eclass );
1187 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1188 if ( event->type == GDK_2BUTTON_PRESS ) {
1189 EntityClassList_createEntity();
1195 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1196 unsigned int code = gdk_keyval_to_upper( event->keyval );
1198 if ( event->keyval == GDK_Return ) {
1199 EntityClassList_createEntity();
1203 // select the entity that starts with the key pressed
1204 if ( code <= 'Z' && code >= 'A' ) {
1205 GtkTreeView* view = g_entityClassList;
1206 GtkTreeModel* model;
1208 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1209 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1210 gtk_tree_model_get_iter_first( model, &iter );
1213 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1216 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1218 if ( toupper( text[0] ) == (int)code ) {
1219 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1220 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1221 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
1222 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1224 gtk_tree_path_free( path );
1230 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1231 gtk_tree_model_get_iter_first( model, &iter );
1240 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1241 // find out what type of entity we are trying to create
1242 GtkTreeModel* model;
1244 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1250 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1252 gtk_entry_set_text( g_entityKeyEntry, key );
1253 gtk_entry_set_text( g_entityValueEntry, val );
1259 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1260 EntityInspector_applySpawnflags();
1263 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1264 if ( event->keyval == GDK_Return ) {
1265 if ( widget == g_entityKeyEntry ) {
1266 gtk_entry_set_text( g_entityValueEntry, "" );
1267 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1271 EntityInspector_applyKeyValue();
1275 if ( event->keyval == GDK_Escape ) {
1276 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1283 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1284 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1285 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1287 g_entityInspector_windowConstructed = false;
1288 GlobalEntityAttributes_clear();
1291 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1292 ui::Widget vbox = ui::VBox( FALSE, 2 );
1293 gtk_widget_show( vbox );
1294 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1296 g_signal_connect( G_OBJECT( vbox ), "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1299 ui::Widget split1 = ui::VPaned();
1300 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1301 gtk_widget_show( split1 );
1303 g_entity_split1 = split1;
1306 ui::Widget split2 = ui::VPaned();
1307 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1308 gtk_widget_show( split2 );
1310 g_entity_split2 = split2;
1314 ui::Widget scr = ui::ScrolledWindow();
1315 gtk_widget_show( scr );
1316 gtk_paned_add1( GTK_PANED( split2 ), scr );
1317 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1318 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1321 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
1323 GtkTreeView* view = ui::TreeView( ui::TreeModel( GTK_TREE_MODEL( store ) ));
1324 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1325 gtk_tree_view_set_headers_visible( view, FALSE );
1326 g_signal_connect( G_OBJECT( view ), "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1327 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1330 auto renderer = ui::CellRendererText();
1331 GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1332 gtk_tree_view_append_column( view, column );
1336 GtkTreeSelection* selection = gtk_tree_view_get_selection( view );
1337 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1340 gtk_widget_show( GTK_WIDGET( view ) );
1342 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( view ) );
1344 g_object_unref( G_OBJECT( store ) );
1345 g_entityClassList = view;
1346 g_entlist_store = store;
1351 ui::Widget scr = ui::ScrolledWindow();
1352 gtk_widget_show( scr );
1353 gtk_paned_add2( GTK_PANED( split2 ), scr );
1354 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1355 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1358 GtkTextView* text = ui::TextView();
1359 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1360 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1361 gtk_text_view_set_editable( text, FALSE );
1362 gtk_widget_show( GTK_WIDGET( text ) );
1363 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( text ) );
1364 g_entityClassComment = text;
1370 ui::Widget split2 = ui::VPaned();
1371 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1372 gtk_widget_show( split2 );
1375 ui::Widget vbox2 = ui::VBox( FALSE, 2 );
1376 gtk_widget_show( vbox2 );
1377 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1380 // Spawnflags (4 colums wide max, or window gets too wide.)
1381 GtkTable* table = ui::Table( 4, 4, FALSE );
1382 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1383 gtk_widget_show( GTK_WIDGET( table ) );
1385 g_spawnflagsTable = table;
1387 for ( int i = 0; i < MAX_FLAGS; i++ )
1389 GtkCheckButton* check = ui::CheckButton( "" );
1390 g_object_ref( GTK_WIDGET( check ) );
1391 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1392 g_entitySpawnflagsCheck[i] = check;
1398 ui::Widget scr = ui::ScrolledWindow();
1399 gtk_widget_show( scr );
1400 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1401 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1402 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1405 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ));
1407 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
1408 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1409 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1412 auto renderer = ui::CellRendererText();
1413 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1414 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1418 auto renderer = ui::CellRendererText();
1419 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1420 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1424 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
1425 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1428 gtk_widget_show( view );
1430 gtk_container_add( GTK_CONTAINER( scr ), view );
1432 g_object_unref( G_OBJECT( store ) );
1434 g_entprops_store = store;
1440 GtkTable* table = ui::Table( 2, 2, FALSE );
1441 gtk_widget_show( GTK_WIDGET( table ) );
1442 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1443 gtk_table_set_row_spacings( table, 3 );
1444 gtk_table_set_col_spacings( table, 5 );
1447 auto entry = ui::Entry();
1448 gtk_widget_show( GTK_WIDGET( entry ) );
1449 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1450 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1451 (GtkAttachOptions)( 0 ), 0, 0 );
1452 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1453 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1454 g_entityKeyEntry = entry;
1458 auto entry = ui::Entry();
1459 gtk_widget_show( GTK_WIDGET( entry ) );
1460 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1461 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1462 (GtkAttachOptions)( 0 ), 0, 0 );
1463 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1464 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1465 g_entityValueEntry = entry;
1469 GtkLabel* label = GTK_LABEL( ui::Label( "Value" ) );
1470 gtk_widget_show( GTK_WIDGET( label ) );
1471 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1472 (GtkAttachOptions)( GTK_FILL ),
1473 (GtkAttachOptions)( 0 ), 0, 0 );
1474 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1478 GtkLabel* label = GTK_LABEL( ui::Label( "Key" ) );
1479 gtk_widget_show( GTK_WIDGET( label ) );
1480 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1481 (GtkAttachOptions)( GTK_FILL ),
1482 (GtkAttachOptions)( 0 ), 0, 0 );
1483 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1488 GtkBox* hbox = ui::HBox( TRUE, 4 );
1489 gtk_widget_show( GTK_WIDGET( hbox ) );
1490 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1493 GtkButton* button = ui::Button( "Clear All" );
1494 gtk_widget_show( GTK_WIDGET( button ) );
1495 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1496 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1499 GtkButton* button = ui::Button( "Delete Key" );
1500 gtk_widget_show( GTK_WIDGET( button ) );
1501 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1502 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1508 ui::Widget scr = ui::ScrolledWindow();
1509 gtk_widget_show( scr );
1510 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1512 ui::Widget viewport = ui::Widget(gtk_viewport_new( 0, 0 ));
1513 gtk_widget_show( viewport );
1514 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1516 g_attributeBox = ui::VBox( FALSE, 2 );
1517 gtk_widget_show( GTK_WIDGET( g_attributeBox ) );
1519 gtk_container_add( GTK_CONTAINER( viewport ), GTK_WIDGET( g_attributeBox ) );
1520 gtk_container_add( GTK_CONTAINER( scr ), viewport );
1521 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1528 // show the sliders in any case
1529 if ( g_entitysplit2_position > 22 ) {
1530 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1533 g_entitysplit2_position = 22;
1534 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1536 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1537 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1540 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1544 g_entityInspector_windowConstructed = true;
1545 EntityClassList_fill();
1547 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1548 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1549 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1552 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1557 class EntityInspector : public ModuleObserver
1559 std::size_t m_unrealised;
1561 EntityInspector() : m_unrealised( 1 ){
1564 if ( --m_unrealised == 0 ) {
1565 if ( g_entityInspector_windowConstructed ) {
1566 //globalOutputStream() << "Entity Inspector: realise\n";
1567 EntityClassList_fill();
1572 if ( ++m_unrealised == 1 ) {
1573 if ( g_entityInspector_windowConstructed ) {
1574 //globalOutputStream() << "Entity Inspector: unrealise\n";
1575 EntityClassList_clear();
1581 EntityInspector g_EntityInspector;
1583 #include "preferencesystem.h"
1584 #include "stringio.h"
1586 void EntityInspector_construct(){
1587 GlobalEntityClassManager().attach( g_EntityInspector );
1589 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1590 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1594 void EntityInspector_destroy(){
1595 GlobalEntityClassManager().detach( g_EntityInspector );
1598 const char *EntityInspector_getCurrentKey(){
1599 if ( !GroupDialog_isShown() ) {
1602 if ( GroupDialog_getPage() != g_page_entity ) {
1605 return gtk_entry_get_text( g_entityKeyEntry );