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"
28 #include "ifilesystem.h"
30 #include "iscenegraph.h"
31 #include "iselection.h"
36 #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 entry.dimensions(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 ui::CheckButton m_check;
117 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
122 BooleanAttribute( const char* key ) :
125 auto check = ui::CheckButton();
130 guint handler = check.connect( "toggled", G_CALLBACK( toggled ), this );
131 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
135 ui::Widget getWidget() const {
142 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_check.active() ? "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( m_check, atoi( value ) != 0 );
153 toggle_button_set_active_no_signal( 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();
172 entry.dimensions(50, -1);
175 m_nonModal.connect( m_entry );
177 ui::Widget getWidget() const {
180 ui::Entry getEntry() const {
188 StringOutputStream value( 64 );
189 value << m_entry.text();
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 m_entry.text(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 m_entry.m_entry.m_frame;
230 StringOutputStream value( 64 );
231 value << m_entry.m_entry.m_entry.text();
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 m_entry.m_entry.m_entry.text(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 << m_entry.m_entry.m_entry.text();
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 m_entry.m_entry.m_entry.text(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 m_entry.text(angle.c_str());
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;
374 ui::HBox m_hbox{ui::null};
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 );
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 );
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 );
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 m_entry.text(angle.c_str());
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( ui::null ), m_pitch( ui::null ), m_yaw( ui::null ){
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 ))
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 m_angles.m_pitch.text(angle.c_str());
525 angle << angle_normalised( pitch_yaw_roll.y() );
526 m_angles.m_yaw.text(angle.c_str());
529 angle << angle_normalised( pitch_yaw_roll.z() );
530 m_angles.m_roll.text(angle.c_str());
535 m_angles.m_pitch.text("0");
536 m_angles.m_yaw.text("0");
537 m_angles.m_roll.text("0");
540 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
549 Vector3Entry() : m_x( ui::null ), m_y( ui::null ), m_z( ui::null ){
553 class Vector3Attribute : public EntityAttribute
556 Vector3Entry m_vector3;
557 NonModalEntry m_nonModal;
558 ui::Box m_hbox{ui::null};
560 Vector3Attribute( const char* key ) :
562 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
563 m_hbox = ui::HBox( TRUE, 4 );
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 m_vector3.m_x.text(buffer.c_str());
613 m_vector3.m_y.text(buffer.c_str());
617 m_vector3.m_z.text(buffer.c_str());
622 m_vector3.m_x.text("0");
623 m_vector3.m_y.text("0");
624 m_vector3.m_z.text("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( ui::ComboBox combo ){
644 m_changedHandler = combo.connect( "changed", G_CALLBACK( changed ), this );
646 void setActive( ui::ComboBox 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 ui::ComboBox 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() );
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 ui::TextView g_entityClassComment;
715 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
717 ui::Entry g_entityKeyEntry;
718 ui::Entry g_entityValueEntry;
720 ui::ListStore g_entlist_store{ui::null};
721 ui::ListStore g_entprops_store{ui::null};
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 ui::VBox g_attributeBox{ui::null};
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 g_entityClassComment.text(eclass->comments());
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 auto widget = ui::Widget(GTK_WIDGET(g_entitySpawnflagsCheck[i]));
863 auto label = ui::Label(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] ));
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 );
887 auto label = ui::Label(GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget)) ));
888 label.text(str.c_str());
893 void EntityClassList_selectEntityClass( EntityClass* eclass ){
894 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
896 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
899 gtk_tree_model_get( model, &iter, 0, &text, -1 );
900 if ( strcmp( text, eclass->name() ) == 0 ) {
901 GtkTreeView* view = g_entityClassList;
902 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
903 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
904 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
905 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
907 gtk_tree_path_free( path );
914 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
915 auto row = DialogRow_new( name, attribute.getWidget() );
916 DialogVBox_packRow( ui::VBox(g_attributeBox), row );
920 template<typename Attribute>
921 class StatelessAttributeCreator
924 static EntityAttribute* create( const char* name ){
925 return new Attribute( name );
929 class EntityAttributeFactory
931 typedef EntityAttribute* ( *CreateFunc )( const char* name );
932 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
935 EntityAttributeFactory(){
936 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
937 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
938 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
939 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
940 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
941 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
942 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
943 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
944 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
945 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
946 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
947 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
948 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
950 EntityAttribute* create( const char* type, const char* name ){
951 Creators::iterator i = m_creators.find( type );
952 if ( i != m_creators.end() ) {
953 return ( *i ).second( name );
955 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
956 if ( listType != 0 ) {
957 return new ListAttribute( name, *listType );
963 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
965 void EntityInspector_setEntityClass( EntityClass *eclass ){
966 EntityClassList_selectEntityClass( eclass );
967 SurfaceFlags_setEntityClass( eclass );
969 if ( eclass != g_current_attributes ) {
970 g_current_attributes = eclass;
972 container_remove_all( g_attributeBox );
973 GlobalEntityAttributes_clear();
975 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
977 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
978 if ( attribute != 0 ) {
979 g_entityAttributes.push_back( attribute );
980 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
986 void EntityInspector_updateSpawnflags(){
988 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
989 for ( int i = 0; i < g_spawnflag_count; ++i )
991 int v = !!( f & ( 1 << spawn_table[i] ) );
993 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), v );
997 // take care of the remaining ones
998 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1000 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), FALSE );
1005 void EntityInspector_applySpawnflags(){
1010 for ( i = 0; i < g_spawnflag_count; ++i )
1012 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1013 f |= v << spawn_table[i];
1016 sprintf( sz, "%i", f );
1017 const char* value = ( f == 0 ) ? "" : sz;
1020 StringOutputStream command;
1021 command << "entitySetFlags -flags " << f;
1022 UndoableCommand undo( "entitySetSpawnflags" );
1024 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1029 void EntityInspector_updateKeyValues(){
1030 g_selectedKeyValues.clear();
1031 g_selectedDefaultKeyValues.clear();
1032 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1034 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1036 EntityInspector_updateSpawnflags();
1038 ui::ListStore store = g_entprops_store;
1040 // save current key/val pair around filling epair box
1041 // row_select wipes it and sets to first in list
1042 CopiedString strKey( g_entityKeyEntry.text() );
1043 CopiedString strVal( g_entityValueEntry.text() );
1045 gtk_list_store_clear( store );
1046 // Walk through list and add pairs
1047 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1050 gtk_list_store_append( store, &iter );
1051 StringOutputStream key( 64 );
1052 key << ( *i ).first.c_str();
1053 StringOutputStream value( 64 );
1054 value << ( *i ).second.c_str();
1055 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1058 g_entityKeyEntry.text( strKey.c_str() );
1059 g_entityValueEntry.text( strVal.c_str() );
1061 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1067 class EntityInspectorDraw
1069 IdleDraw m_idleDraw;
1071 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1074 m_idleDraw.queueDraw();
1078 EntityInspectorDraw g_EntityInspectorDraw;
1081 void EntityInspector_keyValueChanged(){
1082 g_EntityInspectorDraw.queueDraw();
1084 void EntityInspector_selectionChanged( const Selectable& ){
1085 EntityInspector_keyValueChanged();
1088 // Creates a new entity based on the currently selected brush and entity type.
1090 void EntityClassList_createEntity(){
1091 GtkTreeView* view = g_entityClassList;
1093 // find out what type of entity we are trying to create
1094 GtkTreeModel* model;
1096 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1097 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) )).alert( "You must have a selected class to create an entity", "info" );
1102 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1105 StringOutputStream command;
1106 command << "entityCreate -class " << text;
1108 UndoableCommand undo( command.c_str() );
1110 Entity_createFromSelection( text, g_vector3_identity );
1115 void EntityInspector_applyKeyValue(){
1116 // Get current selection text
1117 StringOutputStream key( 64 );
1118 key << gtk_entry_get_text( g_entityKeyEntry );
1119 StringOutputStream value( 64 );
1120 value << gtk_entry_get_text( g_entityValueEntry );
1123 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1124 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1125 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1130 // RR2DO2: we don't want spaces in entity keys
1131 if ( strstr( key.c_str(), " " ) ) {
1132 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1136 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1137 StringOutputStream command;
1138 command << "entitySetClass -class " << value.c_str();
1139 UndoableCommand undo( command.c_str() );
1140 Scene_EntitySetClassname_Selected( value.c_str() );
1144 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1148 void EntityInspector_clearKeyValue(){
1149 // Get current selection text
1150 StringOutputStream key( 64 );
1151 key << gtk_entry_get_text( g_entityKeyEntry );
1153 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1154 StringOutputStream command;
1155 command << "entityDeleteKey -key " << key.c_str();
1156 UndoableCommand undo( command.c_str() );
1157 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1161 void EntityInspector_clearAllKeyValues(){
1162 UndoableCommand undo( "entityClear" );
1164 // remove all keys except classname
1165 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1167 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1168 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1173 // =============================================================================
1176 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1177 GtkTreeModel* model;
1178 GtkTreeIter selected;
1179 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1180 EntityClass* eclass;
1181 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1182 if ( eclass != 0 ) {
1183 SetComment( eclass );
1188 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1189 if ( event->type == GDK_2BUTTON_PRESS ) {
1190 EntityClassList_createEntity();
1196 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1197 unsigned int code = gdk_keyval_to_upper( event->keyval );
1199 if ( event->keyval == GDK_KEY_Return ) {
1200 EntityClassList_createEntity();
1204 // select the entity that starts with the key pressed
1205 if ( code <= 'Z' && code >= 'A' ) {
1206 GtkTreeView* view = g_entityClassList;
1207 GtkTreeModel* model;
1209 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1210 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1211 gtk_tree_model_get_iter_first( model, &iter );
1214 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1217 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1219 if ( toupper( text[0] ) == (int)code ) {
1220 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1221 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1222 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
1223 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1225 gtk_tree_path_free( path );
1231 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1232 gtk_tree_model_get_iter_first( model, &iter );
1241 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1242 // find out what type of entity we are trying to create
1243 GtkTreeModel* model;
1245 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1251 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1253 g_entityKeyEntry.text( key );
1254 g_entityValueEntry.text( val );
1260 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1261 EntityInspector_applySpawnflags();
1264 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1265 if ( event->keyval == GDK_KEY_Return ) {
1266 if ( widget == g_entityKeyEntry ) {
1267 g_entityValueEntry.text( "" );
1268 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1272 EntityInspector_applyKeyValue();
1276 if ( event->keyval == GDK_KEY_Escape ) {
1277 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1284 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1285 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1286 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1288 g_entityInspector_windowConstructed = false;
1289 GlobalEntityAttributes_clear();
1292 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1293 ui::Widget vbox = ui::VBox( FALSE, 2 );
1295 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1297 vbox.connect( "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1300 ui::Widget split1 = ui::VPaned();
1301 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1304 g_entity_split1 = split1;
1307 ui::Widget split2 = ui::VPaned();
1308 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1311 g_entity_split2 = split2;
1315 auto scr = ui::ScrolledWindow();
1317 gtk_paned_add1( GTK_PANED( split2 ), scr );
1318 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1319 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1322 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
1324 auto view = ui::TreeView( ui::TreeModel( GTK_TREE_MODEL( store ) ));
1325 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1326 gtk_tree_view_set_headers_visible( view, FALSE );
1327 view.connect( "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1328 view.connect( "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1331 auto renderer = ui::CellRendererText();
1332 GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1333 gtk_tree_view_append_column( view, column );
1337 auto selection = ui::TreeSelection(gtk_tree_view_get_selection( view ));
1338 selection.connect( "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1346 g_entityClassList = view;
1347 g_entlist_store = store;
1352 auto scr = ui::ScrolledWindow();
1354 gtk_paned_add2( GTK_PANED( split2 ), scr );
1355 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1356 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1359 auto text = ui::TextView();
1360 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1361 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1362 gtk_text_view_set_editable( text, FALSE );
1365 g_entityClassComment = text;
1371 ui::Widget split2 = ui::VPaned();
1372 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1376 ui::Widget vbox2 = ui::VBox( FALSE, 2 );
1378 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1381 // Spawnflags (4 colums wide max, or window gets too wide.)
1382 auto table = ui::Table( 4, 4, FALSE );
1383 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1386 g_spawnflagsTable = table;
1388 for ( int i = 0; i < MAX_FLAGS; i++ )
1390 auto check = ui::CheckButton( "" );
1391 g_object_ref( GTK_WIDGET( check ) );
1392 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( check.connect( "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1393 g_entitySpawnflagsCheck[i] = check;
1399 auto scr = ui::ScrolledWindow();
1401 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1402 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1403 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1406 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ));
1408 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
1409 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1410 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1413 auto renderer = ui::CellRendererText();
1414 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1415 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1419 auto renderer = ui::CellRendererText();
1420 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1421 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1425 auto selection = ui::TreeSelection(gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ));
1426 selection.connect( "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1435 g_entprops_store = store;
1441 auto table = ui::Table( 2, 2, FALSE );
1443 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1444 gtk_table_set_row_spacings( table, 3 );
1445 gtk_table_set_col_spacings( table, 5 );
1448 auto entry = ui::Entry();
1450 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1451 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1452 (GtkAttachOptions)( 0 ), 0, 0 );
1453 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1454 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1455 g_entityKeyEntry = entry;
1459 auto entry = ui::Entry();
1461 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1462 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1463 (GtkAttachOptions)( 0 ), 0, 0 );
1464 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1465 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1466 g_entityValueEntry = entry;
1470 auto label = ui::Label( "Value" );
1472 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1473 (GtkAttachOptions)( GTK_FILL ),
1474 (GtkAttachOptions)( 0 ), 0, 0 );
1475 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1479 auto label = ui::Label( "Key" );
1481 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1482 (GtkAttachOptions)( GTK_FILL ),
1483 (GtkAttachOptions)( 0 ), 0, 0 );
1484 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1489 auto hbox = ui::HBox( TRUE, 4 );
1491 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1494 auto button = ui::Button( "Clear All" );
1496 button.connect( "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1497 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1500 auto button = ui::Button( "Delete Key" );
1502 button.connect( "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1503 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1509 auto scr = ui::ScrolledWindow();
1511 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1513 auto viewport = ui::Container(GTK_CONTAINER(gtk_viewport_new( 0, 0 )));
1515 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1517 g_attributeBox = ui::VBox( FALSE, 2 );
1518 g_attributeBox.show();
1520 viewport.add(g_attributeBox);
1522 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1529 // show the sliders in any case
1530 if ( g_entitysplit2_position > 22 ) {
1531 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1534 g_entitysplit2_position = 22;
1535 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1537 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1538 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1541 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1545 g_entityInspector_windowConstructed = true;
1546 EntityClassList_fill();
1548 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1549 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1550 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1553 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1558 class EntityInspector : public ModuleObserver
1560 std::size_t m_unrealised;
1562 EntityInspector() : m_unrealised( 1 ){
1565 if ( --m_unrealised == 0 ) {
1566 if ( g_entityInspector_windowConstructed ) {
1567 //globalOutputStream() << "Entity Inspector: realise\n";
1568 EntityClassList_fill();
1573 if ( ++m_unrealised == 1 ) {
1574 if ( g_entityInspector_windowConstructed ) {
1575 //globalOutputStream() << "Entity Inspector: unrealise\n";
1576 EntityClassList_clear();
1582 EntityInspector g_EntityInspector;
1584 #include "preferencesystem.h"
1585 #include "stringio.h"
1587 void EntityInspector_construct(){
1588 GlobalEntityClassManager().attach( g_EntityInspector );
1590 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1591 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1595 void EntityInspector_destroy(){
1596 GlobalEntityClassManager().detach( g_EntityInspector );
1599 const char *EntityInspector_getCurrentKey(){
1600 if ( !GroupDialog_isShown() ) {
1603 if ( GroupDialog_getPage() != g_page_entity ) {
1606 return gtk_entry_get_text( g_entityKeyEntry );