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>
36 #include <uilib/uilib.h>
40 #include "eclasslib.h"
42 #include "generic/callback.h"
44 #include "stream/stringstream.h"
45 #include "moduleobserver.h"
49 #include "gtkutil/accelerator.h"
50 #include "gtkutil/dialog.h"
51 #include "gtkutil/filechooser.h"
52 #include "gtkutil/messagebox.h"
53 #include "gtkutil/nonmodal.h"
54 #include "gtkutil/button.h"
55 #include "gtkutil/entry.h"
56 #include "gtkutil/container.h"
62 #include "mainframe.h"
63 #include "textureentry.h"
64 #include "groupdialog.h"
66 ui::Entry numeric_entry_new(){
67 auto entry = ui::Entry();
69 gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 );
75 typedef std::map<CopiedString, CopiedString> KeyValues;
76 KeyValues g_selectedKeyValues;
77 KeyValues g_selectedDefaultKeyValues;
80 const char* SelectedEntity_getValueForKey( const char* key ){
82 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
83 if ( i != g_selectedKeyValues.end() ) {
84 return ( *i ).second.c_str();
88 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
89 if ( i != g_selectedDefaultKeyValues.end() ) {
90 return ( *i ).second.c_str();
96 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
97 StringOutputStream command( 256 );
98 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
99 UndoableCommand undo( command.c_str() );
100 Scene_EntitySetKeyValue_Selected( key, value );
103 class EntityAttribute
106 virtual ui::Widget getWidget() const = 0;
107 virtual void update() = 0;
108 virtual void release() = 0;
111 class BooleanAttribute : public EntityAttribute
114 GtkCheckButton* m_check;
116 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
121 BooleanAttribute( const char* key ) :
124 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
125 gtk_widget_show( GTK_WIDGET( check ) );
129 guint handler = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( toggled ), this );
130 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
134 ui::Widget getWidget() const {
135 return ui::Widget(GTK_WIDGET( m_check ));
141 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_check ) ) ? "1" : "0" );
143 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
146 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
147 if ( !string_empty( value ) ) {
148 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), atoi( value ) != 0 );
152 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), false );
155 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
159 class StringAttribute : public EntityAttribute
163 NonModalEntry m_nonModal;
165 StringAttribute( const char* key ) :
168 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
169 auto entry = ui::Entry();
170 gtk_widget_show( GTK_WIDGET( entry ) );
171 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
174 m_nonModal.connect( m_entry );
176 ui::Widget getWidget() const {
177 return ui::Widget(GTK_WIDGET( m_entry ));
179 GtkEntry* getEntry() const {
187 StringOutputStream value( 64 );
188 value << gtk_entry_get_text( m_entry );
189 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
191 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
194 StringOutputStream value( 64 );
195 value << SelectedEntity_getValueForKey( m_key.c_str() );
196 gtk_entry_set_text( m_entry, value.c_str() );
198 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
201 class ShaderAttribute : public StringAttribute
204 ShaderAttribute( const char* key ) : StringAttribute( key ){
205 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
210 class ModelAttribute : public EntityAttribute
213 BrowsedPathEntry m_entry;
214 NonModalEntry m_nonModal;
216 ModelAttribute( const char* key ) :
218 m_entry( BrowseCaller( *this ) ),
219 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
220 m_nonModal.connect( m_entry.m_entry.m_entry );
225 ui::Widget getWidget() const {
226 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
229 StringOutputStream value( 64 );
230 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
231 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
233 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
235 StringOutputStream value( 64 );
236 value << SelectedEntity_getValueForKey( m_key.c_str() );
237 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
239 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
240 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
241 const char *filename = misc_model_dialog( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) ));
243 if ( filename != 0 ) {
248 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
251 const char* browse_sound( ui::Widget parent ){
252 StringOutputStream buffer( 1024 );
254 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
256 if ( !file_readable( buffer.c_str() ) ) {
259 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
262 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
263 if ( filename != 0 ) {
264 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
265 if ( relative == filename ) {
266 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
273 class SoundAttribute : public EntityAttribute
276 BrowsedPathEntry m_entry;
277 NonModalEntry m_nonModal;
279 SoundAttribute( const char* key ) :
281 m_entry( BrowseCaller( *this ) ),
282 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
283 m_nonModal.connect( m_entry.m_entry.m_entry );
288 ui::Widget getWidget() const {
289 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
292 StringOutputStream value( 64 );
293 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
294 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
296 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
298 StringOutputStream value( 64 );
299 value << SelectedEntity_getValueForKey( m_key.c_str() );
300 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
302 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
303 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
304 const char *filename = browse_sound( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) )) );
306 if ( filename != 0 ) {
311 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
314 inline double angle_normalised( double angle ){
315 return float_mod( angle, 360.0 );
318 class AngleAttribute : public EntityAttribute
322 NonModalEntry m_nonModal;
324 AngleAttribute( const char* key ) :
327 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
328 auto entry = numeric_entry_new();
330 m_nonModal.connect( m_entry );
335 ui::Widget getWidget() const {
336 return ui::Widget(GTK_WIDGET( m_entry ));
339 StringOutputStream angle( 32 );
340 angle << angle_normalised( entry_get_float( m_entry ) );
341 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
343 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
346 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
347 if ( !string_empty( value ) ) {
348 StringOutputStream angle( 32 );
349 angle << angle_normalised( atof( value ) );
350 gtk_entry_set_text( m_entry, angle.c_str() );
354 gtk_entry_set_text( m_entry, "0" );
357 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
362 typedef const char* String;
363 const String buttons[] = { "up", "down", "z-axis" };
366 class DirectionAttribute : public EntityAttribute
370 NonModalEntry m_nonModal;
372 NonModalRadio m_nonModalRadio;
375 DirectionAttribute( const char* key ) :
378 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
379 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
380 m_nonModalRadio( ApplyRadioCaller( *this ) ){
381 auto entry = numeric_entry_new();
383 m_nonModal.connect( m_entry );
385 m_nonModalRadio.connect( m_radio.m_radio );
387 m_hbox = ui::HBox( FALSE, 4 );
388 gtk_widget_show( GTK_WIDGET( m_hbox ) );
390 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_radio.m_hbox ), TRUE, TRUE, 0 );
391 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_entry ), TRUE, TRUE, 0 );
396 ui::Widget getWidget() const {
397 return ui::Widget(GTK_WIDGET( m_hbox ));
400 StringOutputStream angle( 32 );
401 angle << angle_normalised( entry_get_float( m_entry ) );
402 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
404 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
407 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
408 if ( !string_empty( value ) ) {
409 float f = float(atof( value ) );
411 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
412 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
413 gtk_entry_set_text( m_entry, "" );
415 else if ( f == -2 ) {
416 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
417 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
418 gtk_entry_set_text( m_entry, "" );
422 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), TRUE );
423 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
424 StringOutputStream angle( 32 );
425 angle << angle_normalised( f );
426 gtk_entry_set_text( m_entry, angle.c_str() );
431 gtk_entry_set_text( m_entry, "0" );
434 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
437 int index = radio_button_get_active( m_radio.m_radio );
439 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
441 else if ( index == 1 ) {
442 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
444 else if ( index == 2 ) {
448 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
458 AnglesEntry() : m_roll( nullptr ), m_pitch( nullptr ), m_yaw( nullptr ){
462 typedef BasicVector3<double> DoubleVector3;
464 class AnglesAttribute : public EntityAttribute
467 AnglesEntry m_angles;
468 NonModalEntry m_nonModal;
471 AnglesAttribute( const char* key ) :
473 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
474 m_hbox(ui::HBox( TRUE, 4 ))
476 gtk_widget_show( GTK_WIDGET( m_hbox ) );
478 auto entry = numeric_entry_new();
479 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
480 m_angles.m_pitch = entry;
481 m_nonModal.connect( m_angles.m_pitch );
484 auto entry = numeric_entry_new();
485 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
486 m_angles.m_yaw = entry;
487 m_nonModal.connect( m_angles.m_yaw );
490 auto entry = numeric_entry_new();
491 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
492 m_angles.m_roll = entry;
493 m_nonModal.connect( m_angles.m_roll );
499 ui::Widget getWidget() const {
500 return ui::Widget(GTK_WIDGET( m_hbox ));
503 StringOutputStream angles( 64 );
504 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
505 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
506 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
507 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
509 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
512 StringOutputStream angle( 32 );
513 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
514 if ( !string_empty( value ) ) {
515 DoubleVector3 pitch_yaw_roll;
516 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
517 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
520 angle << angle_normalised( pitch_yaw_roll.x() );
521 gtk_entry_set_text( m_angles.m_pitch, angle.c_str() );
524 angle << angle_normalised( pitch_yaw_roll.y() );
525 gtk_entry_set_text( m_angles.m_yaw, angle.c_str() );
528 angle << angle_normalised( pitch_yaw_roll.z() );
529 gtk_entry_set_text( m_angles.m_roll, angle.c_str() );
534 gtk_entry_set_text( m_angles.m_pitch, "0" );
535 gtk_entry_set_text( m_angles.m_yaw, "0" );
536 gtk_entry_set_text( m_angles.m_roll, "0" );
539 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
548 Vector3Entry() : m_x( nullptr ), m_y( nullptr ), m_z( nullptr ){
552 class Vector3Attribute : public EntityAttribute
555 Vector3Entry m_vector3;
556 NonModalEntry m_nonModal;
559 Vector3Attribute( const char* key ) :
561 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
562 m_hbox = ui::HBox( TRUE, 4 );
563 gtk_widget_show( GTK_WIDGET( m_hbox ) );
565 auto entry = numeric_entry_new();
566 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
567 m_vector3.m_x = entry;
568 m_nonModal.connect( m_vector3.m_x );
571 auto entry = numeric_entry_new();
572 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
573 m_vector3.m_y = entry;
574 m_nonModal.connect( m_vector3.m_y );
577 auto entry = numeric_entry_new();
578 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
579 m_vector3.m_z = entry;
580 m_nonModal.connect( m_vector3.m_z );
586 ui::Widget getWidget() const {
587 return ui::Widget(GTK_WIDGET( m_hbox ));
590 StringOutputStream vector3( 64 );
591 vector3 << entry_get_float( m_vector3.m_x )
592 << " " << entry_get_float( m_vector3.m_y )
593 << " " << entry_get_float( m_vector3.m_z );
594 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
596 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
599 StringOutputStream buffer( 32 );
600 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
601 if ( !string_empty( value ) ) {
603 if ( !string_parse_vector3( value, x_y_z ) ) {
604 x_y_z = DoubleVector3( 0, 0, 0 );
608 gtk_entry_set_text( m_vector3.m_x, buffer.c_str() );
612 gtk_entry_set_text( m_vector3.m_y, buffer.c_str() );
616 gtk_entry_set_text( m_vector3.m_z, buffer.c_str() );
621 gtk_entry_set_text( m_vector3.m_x, "0" );
622 gtk_entry_set_text( m_vector3.m_y, "0" );
623 gtk_entry_set_text( m_vector3.m_z, "0" );
626 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
629 class NonModalComboBox
632 guint m_changedHandler;
634 static gboolean changed( GtkComboBox *widget, NonModalComboBox* self ){
640 NonModalComboBox( const Callback& changed ) : m_changed( changed ), m_changedHandler( 0 ){
642 void connect( GtkComboBox* combo ){
643 m_changedHandler = g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( changed ), this );
645 void setActive( GtkComboBox* combo, int value ){
646 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
647 gtk_combo_box_set_active( combo, value );
652 class ListAttribute : public EntityAttribute
655 GtkComboBox* m_combo;
656 NonModalComboBox m_nonModal;
657 const ListAttributeType& m_type;
659 ListAttribute( const char* key, const ListAttributeType& type ) :
662 m_nonModal( ApplyCaller( *this ) ),
664 auto combo = ui::ComboBoxText();
666 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
668 gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), ( *i ).first.c_str() );
671 gtk_widget_show( GTK_WIDGET( combo ) );
672 m_nonModal.connect( combo );
679 ui::Widget getWidget() const {
680 return ui::Widget(GTK_WIDGET( m_combo ));
683 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
685 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
688 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
689 ListAttributeType::const_iterator i = m_type.findValue( value );
690 if ( i != m_type.end() ) {
691 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
695 m_nonModal.setActive( m_combo, 0 );
698 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
704 ui::Widget g_entity_split1;
705 ui::Widget g_entity_split2;
706 int g_entitysplit1_position;
707 int g_entitysplit2_position;
709 bool g_entityInspector_windowConstructed = false;
711 GtkTreeView* g_entityClassList;
712 GtkTextView* g_entityClassComment;
714 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
716 GtkEntry* g_entityKeyEntry;
717 GtkEntry* g_entityValueEntry;
719 ui::ListStore g_entlist_store{nullptr};
720 ui::ListStore g_entprops_store{nullptr};
721 const EntityClass* g_current_flags = 0;
722 const EntityClass* g_current_comment = 0;
723 const EntityClass* g_current_attributes = 0;
725 // the number of active spawnflags
726 int g_spawnflag_count;
727 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
728 int spawn_table[MAX_FLAGS];
729 // we change the layout depending on how many spawn flags we need to display
730 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
731 GtkTable* g_spawnflagsTable;
733 GtkVBox* g_attributeBox = 0;
734 typedef std::vector<EntityAttribute*> EntityAttributes;
735 EntityAttributes g_entityAttributes;
738 void GlobalEntityAttributes_clear(){
739 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
743 g_entityAttributes.clear();
746 class GetKeyValueVisitor : public Entity::Visitor
748 KeyValues& m_keyvalues;
750 GetKeyValueVisitor( KeyValues& keyvalues )
751 : m_keyvalues( keyvalues ){
754 void visit( const char* key, const char* value ){
755 m_keyvalues.insert( KeyValues::value_type( CopiedString( key ), CopiedString( value ) ) );
760 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
761 GetKeyValueVisitor visitor( keyvalues );
763 entity.forEachKeyValue( visitor );
765 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
767 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
769 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
773 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
774 class EntityGetKeyValues : public SelectionSystem::Visitor
776 KeyValues& m_keyvalues;
777 KeyValues& m_defaultValues;
778 mutable std::set<Entity*> m_visited;
780 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
781 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
783 void visit( scene::Instance& instance ) const {
784 Entity* entity = Node_getEntity( instance.path().top() );
785 if ( entity == 0 && instance.path().size() != 1 ) {
786 entity = Node_getEntity( instance.path().parent() );
788 if ( entity != 0 && m_visited.insert( entity ).second ) {
789 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
792 } visitor( keyvalues, defaultValues );
793 GlobalSelectionSystem().foreachSelected( visitor );
796 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
797 KeyValues::iterator i = keyvalues.find( CopiedString( key ) );
798 if ( i != keyvalues.end() ) {
799 return ( *i ).second.c_str();
804 class EntityClassListStoreAppend : public EntityClassVisitor
808 EntityClassListStoreAppend( ui::ListStore store_ ) : store( store_ ){
810 void visit( EntityClass* e ){
812 gtk_list_store_append( store, &iter );
813 gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
817 void EntityClassList_fill(){
818 EntityClassListStoreAppend append( g_entlist_store );
819 GlobalEntityClassManager().forEach( append );
822 void EntityClassList_clear(){
823 gtk_list_store_clear( g_entlist_store );
826 void SetComment( EntityClass* eclass ){
827 if ( eclass == g_current_comment ) {
831 g_current_comment = eclass;
833 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
834 gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
837 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
838 if ( eclass == g_current_flags ) {
842 g_current_flags = eclass;
844 int spawnflag_count = 0;
847 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
848 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
850 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
851 spawn_table[spawnflag_count] = i;
857 // disable all remaining boxes
858 // NOTE: these boxes might not even be on display
860 for ( int i = 0; i < g_spawnflag_count; ++i )
862 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
863 gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN(widget)) ), " " );
864 gtk_widget_hide( widget );
865 g_object_ref( widget );
866 gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget );
870 g_spawnflag_count = spawnflag_count;
873 for ( int i = 0; i < g_spawnflag_count; ++i )
875 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
876 gtk_widget_show( widget );
878 StringOutputStream str( 16 );
879 str << LowerCase( eclass->flagnames[spawn_table[i]] );
881 gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1,
882 (GtkAttachOptions)( GTK_FILL ),
883 (GtkAttachOptions)( GTK_FILL ), 0, 0 );
884 g_object_unref( widget );
886 gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN(widget)) ), str.c_str() );
891 void EntityClassList_selectEntityClass( EntityClass* eclass ){
892 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
894 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
897 gtk_tree_model_get( model, &iter, 0, &text, -1 );
898 if ( strcmp( text, eclass->name() ) == 0 ) {
899 GtkTreeView* view = g_entityClassList;
900 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
901 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
902 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
903 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
905 gtk_tree_path_free( path );
912 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
913 auto row = DialogRow_new( name, attribute.getWidget() );
914 DialogVBox_packRow( ui::VBox(g_attributeBox), row );
918 template<typename Attribute>
919 class StatelessAttributeCreator
922 static EntityAttribute* create( const char* name ){
923 return new Attribute( name );
927 class EntityAttributeFactory
929 typedef EntityAttribute* ( *CreateFunc )( const char* name );
930 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
933 EntityAttributeFactory(){
934 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
935 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
936 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
937 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
938 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
939 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
940 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
941 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
942 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
943 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
944 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
945 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
946 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
948 EntityAttribute* create( const char* type, const char* name ){
949 Creators::iterator i = m_creators.find( type );
950 if ( i != m_creators.end() ) {
951 return ( *i ).second( name );
953 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
954 if ( listType != 0 ) {
955 return new ListAttribute( name, *listType );
961 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
963 void EntityInspector_setEntityClass( EntityClass *eclass ){
964 EntityClassList_selectEntityClass( eclass );
965 SurfaceFlags_setEntityClass( eclass );
967 if ( eclass != g_current_attributes ) {
968 g_current_attributes = eclass;
970 container_remove_all( GTK_CONTAINER( g_attributeBox ) );
971 GlobalEntityAttributes_clear();
973 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
975 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
976 if ( attribute != 0 ) {
977 g_entityAttributes.push_back( attribute );
978 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
984 void EntityInspector_updateSpawnflags(){
986 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
987 for ( int i = 0; i < g_spawnflag_count; ++i )
989 int v = !!( f & ( 1 << spawn_table[i] ) );
991 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), v );
995 // take care of the remaining ones
996 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
998 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), FALSE );
1003 void EntityInspector_applySpawnflags(){
1008 for ( i = 0; i < g_spawnflag_count; ++i )
1010 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1011 f |= v << spawn_table[i];
1014 sprintf( sz, "%i", f );
1015 const char* value = ( f == 0 ) ? "" : sz;
1018 StringOutputStream command;
1019 command << "entitySetFlags -flags " << f;
1020 UndoableCommand undo( "entitySetSpawnflags" );
1022 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1027 void EntityInspector_updateKeyValues(){
1028 g_selectedKeyValues.clear();
1029 g_selectedDefaultKeyValues.clear();
1030 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1032 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1034 EntityInspector_updateSpawnflags();
1036 ui::ListStore store = g_entprops_store;
1038 // save current key/val pair around filling epair box
1039 // row_select wipes it and sets to first in list
1040 CopiedString strKey( gtk_entry_get_text( g_entityKeyEntry ) );
1041 CopiedString strVal( gtk_entry_get_text( g_entityValueEntry ) );
1043 gtk_list_store_clear( store );
1044 // Walk through list and add pairs
1045 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1048 gtk_list_store_append( store, &iter );
1049 StringOutputStream key( 64 );
1050 key << ( *i ).first.c_str();
1051 StringOutputStream value( 64 );
1052 value << ( *i ).second.c_str();
1053 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1056 gtk_entry_set_text( g_entityKeyEntry, strKey.c_str() );
1057 gtk_entry_set_text( g_entityValueEntry, strVal.c_str() );
1059 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1065 class EntityInspectorDraw
1067 IdleDraw m_idleDraw;
1069 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1072 m_idleDraw.queueDraw();
1076 EntityInspectorDraw g_EntityInspectorDraw;
1079 void EntityInspector_keyValueChanged(){
1080 g_EntityInspectorDraw.queueDraw();
1082 void EntityInspector_selectionChanged( const Selectable& ){
1083 EntityInspector_keyValueChanged();
1086 // Creates a new entity based on the currently selected brush and entity type.
1088 void EntityClassList_createEntity(){
1089 GtkTreeView* view = g_entityClassList;
1091 // find out what type of entity we are trying to create
1092 GtkTreeModel* model;
1094 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1095 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) )).alert( "You must have a selected class to create an entity", "info" );
1100 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1103 StringOutputStream command;
1104 command << "entityCreate -class " << text;
1106 UndoableCommand undo( command.c_str() );
1108 Entity_createFromSelection( text, g_vector3_identity );
1113 void EntityInspector_applyKeyValue(){
1114 // Get current selection text
1115 StringOutputStream key( 64 );
1116 key << gtk_entry_get_text( g_entityKeyEntry );
1117 StringOutputStream value( 64 );
1118 value << gtk_entry_get_text( g_entityValueEntry );
1121 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1122 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1123 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1128 // RR2DO2: we don't want spaces in entity keys
1129 if ( strstr( key.c_str(), " " ) ) {
1130 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1134 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1135 StringOutputStream command;
1136 command << "entitySetClass -class " << value.c_str();
1137 UndoableCommand undo( command.c_str() );
1138 Scene_EntitySetClassname_Selected( value.c_str() );
1142 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1146 void EntityInspector_clearKeyValue(){
1147 // Get current selection text
1148 StringOutputStream key( 64 );
1149 key << gtk_entry_get_text( g_entityKeyEntry );
1151 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1152 StringOutputStream command;
1153 command << "entityDeleteKey -key " << key.c_str();
1154 UndoableCommand undo( command.c_str() );
1155 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1159 void EntityInspector_clearAllKeyValues(){
1160 UndoableCommand undo( "entityClear" );
1162 // remove all keys except classname
1163 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1165 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1166 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1171 // =============================================================================
1174 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1175 GtkTreeModel* model;
1176 GtkTreeIter selected;
1177 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1178 EntityClass* eclass;
1179 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1180 if ( eclass != 0 ) {
1181 SetComment( eclass );
1186 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1187 if ( event->type == GDK_2BUTTON_PRESS ) {
1188 EntityClassList_createEntity();
1194 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1195 unsigned int code = gdk_keyval_to_upper( event->keyval );
1197 if ( event->keyval == GDK_Return ) {
1198 EntityClassList_createEntity();
1202 // select the entity that starts with the key pressed
1203 if ( code <= 'Z' && code >= 'A' ) {
1204 GtkTreeView* view = g_entityClassList;
1205 GtkTreeModel* model;
1207 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1208 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1209 gtk_tree_model_get_iter_first( model, &iter );
1212 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1215 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1217 if ( toupper( text[0] ) == (int)code ) {
1218 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1219 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1220 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
1221 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1223 gtk_tree_path_free( path );
1229 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1230 gtk_tree_model_get_iter_first( model, &iter );
1239 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1240 // find out what type of entity we are trying to create
1241 GtkTreeModel* model;
1243 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1249 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1251 gtk_entry_set_text( g_entityKeyEntry, key );
1252 gtk_entry_set_text( g_entityValueEntry, val );
1258 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1259 EntityInspector_applySpawnflags();
1262 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1263 if ( event->keyval == GDK_Return ) {
1264 if ( widget == g_entityKeyEntry ) {
1265 gtk_entry_set_text( g_entityValueEntry, "" );
1266 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1270 EntityInspector_applyKeyValue();
1274 if ( event->keyval == GDK_Escape ) {
1275 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1282 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1283 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1284 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1286 g_entityInspector_windowConstructed = false;
1287 GlobalEntityAttributes_clear();
1290 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1291 ui::Widget vbox = ui::VBox( FALSE, 2 );
1292 gtk_widget_show( vbox );
1293 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1295 g_signal_connect( G_OBJECT( vbox ), "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1298 ui::Widget split1 = ui::VPaned();
1299 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1300 gtk_widget_show( split1 );
1302 g_entity_split1 = split1;
1305 ui::Widget split2 = ui::VPaned();
1306 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1307 gtk_widget_show( split2 );
1309 g_entity_split2 = split2;
1313 ui::Widget scr = ui::ScrolledWindow();
1314 gtk_widget_show( scr );
1315 gtk_paned_add1( GTK_PANED( split2 ), scr );
1316 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1317 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1320 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
1322 GtkTreeView* view = ui::TreeView( ui::TreeModel( GTK_TREE_MODEL( store ) ));
1323 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1324 gtk_tree_view_set_headers_visible( view, FALSE );
1325 g_signal_connect( G_OBJECT( view ), "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1326 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1329 auto renderer = ui::CellRendererText();
1330 GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1331 gtk_tree_view_append_column( view, column );
1335 GtkTreeSelection* selection = gtk_tree_view_get_selection( view );
1336 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1339 gtk_widget_show( GTK_WIDGET( view ) );
1341 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( view ) );
1343 g_object_unref( G_OBJECT( store ) );
1344 g_entityClassList = view;
1345 g_entlist_store = store;
1350 ui::Widget scr = ui::ScrolledWindow();
1351 gtk_widget_show( scr );
1352 gtk_paned_add2( GTK_PANED( split2 ), scr );
1353 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1354 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1357 GtkTextView* text = ui::TextView();
1358 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1359 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1360 gtk_text_view_set_editable( text, FALSE );
1361 gtk_widget_show( GTK_WIDGET( text ) );
1362 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( text ) );
1363 g_entityClassComment = text;
1369 ui::Widget split2 = ui::VPaned();
1370 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1371 gtk_widget_show( split2 );
1374 ui::Widget vbox2 = ui::VBox( FALSE, 2 );
1375 gtk_widget_show( vbox2 );
1376 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1379 // Spawnflags (4 colums wide max, or window gets too wide.)
1380 GtkTable* table = ui::Table( 4, 4, FALSE );
1381 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1382 gtk_widget_show( GTK_WIDGET( table ) );
1384 g_spawnflagsTable = table;
1386 for ( int i = 0; i < MAX_FLAGS; i++ )
1388 GtkCheckButton* check = ui::CheckButton( "" );
1389 g_object_ref( GTK_WIDGET( check ) );
1390 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1391 g_entitySpawnflagsCheck[i] = check;
1397 ui::Widget scr = ui::ScrolledWindow();
1398 gtk_widget_show( scr );
1399 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1400 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1401 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1404 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ));
1406 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
1407 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1408 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1411 auto renderer = ui::CellRendererText();
1412 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1413 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1417 auto renderer = ui::CellRendererText();
1418 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1419 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1423 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
1424 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1427 gtk_widget_show( view );
1429 gtk_container_add( GTK_CONTAINER( scr ), view );
1431 g_object_unref( G_OBJECT( store ) );
1433 g_entprops_store = store;
1439 GtkTable* table = ui::Table( 2, 2, FALSE );
1440 gtk_widget_show( GTK_WIDGET( table ) );
1441 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1442 gtk_table_set_row_spacings( table, 3 );
1443 gtk_table_set_col_spacings( table, 5 );
1446 auto entry = ui::Entry();
1447 gtk_widget_show( GTK_WIDGET( entry ) );
1448 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1449 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1450 (GtkAttachOptions)( 0 ), 0, 0 );
1451 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1452 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1453 g_entityKeyEntry = entry;
1457 auto entry = ui::Entry();
1458 gtk_widget_show( GTK_WIDGET( entry ) );
1459 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1460 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1461 (GtkAttachOptions)( 0 ), 0, 0 );
1462 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1463 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1464 g_entityValueEntry = entry;
1468 GtkLabel* label = GTK_LABEL( ui::Label( "Value" ) );
1469 gtk_widget_show( GTK_WIDGET( label ) );
1470 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1471 (GtkAttachOptions)( GTK_FILL ),
1472 (GtkAttachOptions)( 0 ), 0, 0 );
1473 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1477 GtkLabel* label = GTK_LABEL( ui::Label( "Key" ) );
1478 gtk_widget_show( GTK_WIDGET( label ) );
1479 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1480 (GtkAttachOptions)( GTK_FILL ),
1481 (GtkAttachOptions)( 0 ), 0, 0 );
1482 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1487 GtkBox* hbox = ui::HBox( TRUE, 4 );
1488 gtk_widget_show( GTK_WIDGET( hbox ) );
1489 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1492 GtkButton* button = ui::Button( "Clear All" );
1493 gtk_widget_show( GTK_WIDGET( button ) );
1494 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1495 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1498 GtkButton* button = ui::Button( "Delete Key" );
1499 gtk_widget_show( GTK_WIDGET( button ) );
1500 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1501 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1507 ui::Widget scr = ui::ScrolledWindow();
1508 gtk_widget_show( scr );
1509 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1511 ui::Widget viewport = ui::Widget(gtk_viewport_new( 0, 0 ));
1512 gtk_widget_show( viewport );
1513 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1515 g_attributeBox = ui::VBox( FALSE, 2 );
1516 gtk_widget_show( GTK_WIDGET( g_attributeBox ) );
1518 gtk_container_add( GTK_CONTAINER( viewport ), GTK_WIDGET( g_attributeBox ) );
1519 gtk_container_add( GTK_CONTAINER( scr ), viewport );
1520 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1527 // show the sliders in any case
1528 if ( g_entitysplit2_position > 22 ) {
1529 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1532 g_entitysplit2_position = 22;
1533 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1535 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1536 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1539 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1543 g_entityInspector_windowConstructed = true;
1544 EntityClassList_fill();
1546 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1547 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1548 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1551 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1556 class EntityInspector : public ModuleObserver
1558 std::size_t m_unrealised;
1560 EntityInspector() : m_unrealised( 1 ){
1563 if ( --m_unrealised == 0 ) {
1564 if ( g_entityInspector_windowConstructed ) {
1565 //globalOutputStream() << "Entity Inspector: realise\n";
1566 EntityClassList_fill();
1571 if ( ++m_unrealised == 1 ) {
1572 if ( g_entityInspector_windowConstructed ) {
1573 //globalOutputStream() << "Entity Inspector: unrealise\n";
1574 EntityClassList_clear();
1580 EntityInspector g_EntityInspector;
1582 #include "preferencesystem.h"
1583 #include "stringio.h"
1585 void EntityInspector_construct(){
1586 GlobalEntityClassManager().attach( g_EntityInspector );
1588 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1589 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1593 void EntityInspector_destroy(){
1594 GlobalEntityClassManager().detach( g_EntityInspector );
1597 const char *EntityInspector_getCurrentKey(){
1598 if ( !GroupDialog_isShown() ) {
1601 if ( GroupDialog_getPage() != g_page_entity ) {
1604 return gtk_entry_get_text( g_entityKeyEntry );