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 <gtk/gtktreemodel.h>
37 #include <gtk/gtktreeview.h>
38 #include <gtk/gtkcellrenderertext.h>
39 #include <gtk/gtktreeselection.h>
40 #include <gtk/gtkliststore.h>
41 #include <gtk/gtktextview.h>
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtktable.h>
44 #include <gtk/gtktogglebutton.h>
45 #include <gtk/gtkcheckbutton.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkvpaned.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkentry.h>
51 #include <gtk/gtkcombobox.h>
52 #include <uilib/uilib.h>
56 #include "eclasslib.h"
58 #include "generic/callback.h"
60 #include "stream/stringstream.h"
61 #include "moduleobserver.h"
65 #include "gtkutil/accelerator.h"
66 #include "gtkutil/dialog.h"
67 #include "gtkutil/filechooser.h"
68 #include "gtkutil/messagebox.h"
69 #include "gtkutil/nonmodal.h"
70 #include "gtkutil/button.h"
71 #include "gtkutil/entry.h"
72 #include "gtkutil/container.h"
78 #include "mainframe.h"
79 #include "textureentry.h"
80 #include "groupdialog.h"
82 GtkEntry* numeric_entry_new(){
83 GtkEntry* entry = ui::Entry();
84 gtk_widget_show( GTK_WIDGET( entry ) );
85 gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 );
91 typedef std::map<std::string, std::string> KeyValues;
92 KeyValues g_selectedKeyValues;
93 KeyValues g_selectedDefaultKeyValues;
96 const char* SelectedEntity_getValueForKey( const char* key ){
98 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
99 if ( i != g_selectedKeyValues.end() ) {
100 return ( *i ).second.c_str();
104 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
105 if ( i != g_selectedDefaultKeyValues.end() ) {
106 return ( *i ).second.c_str();
112 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
113 StringOutputStream command( 256 );
114 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
115 UndoableCommand undo( command.c_str() );
116 Scene_EntitySetKeyValue_Selected( key, value );
119 class EntityAttribute
122 virtual ~EntityAttribute(){}
123 virtual ui::Widget getWidget() const = 0;
124 virtual void update() = 0;
125 virtual void release() = 0;
128 class BooleanAttribute : public EntityAttribute
131 GtkCheckButton* m_check;
133 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
138 BooleanAttribute( const char* key ) :
141 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
142 gtk_widget_show( GTK_WIDGET( check ) );
146 guint handler = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( toggled ), this );
147 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
151 ui::Widget getWidget() const {
152 return ui::Widget(GTK_WIDGET( m_check ));
158 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_check ) ) ? "1" : "0" );
160 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
163 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
164 if ( !string_empty( value ) ) {
165 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), atoi( value ) != 0 );
169 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), false );
172 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
176 class StringAttribute : public EntityAttribute
180 NonModalEntry m_nonModal;
182 StringAttribute( const char* key ) :
185 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
186 GtkEntry* entry = ui::Entry();
187 gtk_widget_show( GTK_WIDGET( entry ) );
188 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
191 m_nonModal.connect( m_entry );
193 ui::Widget getWidget() const {
194 return ui::Widget(GTK_WIDGET( m_entry ));
196 GtkEntry* getEntry() const {
204 StringOutputStream value( 64 );
205 value << gtk_entry_get_text( m_entry );
206 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
208 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
211 StringOutputStream value( 64 );
212 value << SelectedEntity_getValueForKey( m_key.c_str() );
213 gtk_entry_set_text( m_entry, value.c_str() );
215 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
218 class ShaderAttribute : public StringAttribute
221 ShaderAttribute( const char* key ) : StringAttribute( key ){
222 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
227 class ModelAttribute : public EntityAttribute
230 BrowsedPathEntry m_entry;
231 NonModalEntry m_nonModal;
233 ModelAttribute( const char* key ) :
235 m_entry( BrowseCaller( *this ) ),
236 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
237 m_nonModal.connect( m_entry.m_entry.m_entry );
242 ui::Widget getWidget() const {
243 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
246 StringOutputStream value( 64 );
247 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
248 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
250 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
252 StringOutputStream value( 64 );
253 value << SelectedEntity_getValueForKey( m_key.c_str() );
254 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
256 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
257 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
258 const char *filename = misc_model_dialog( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) ));
260 if ( filename != 0 ) {
265 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
268 const char* browse_sound( ui::Widget parent ){
269 StringOutputStream buffer( 1024 );
271 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
273 if ( !file_readable( buffer.c_str() ) ) {
276 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
279 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
280 if ( filename != 0 ) {
281 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
282 if ( relative == filename ) {
283 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
290 class SoundAttribute : public EntityAttribute
293 BrowsedPathEntry m_entry;
294 NonModalEntry m_nonModal;
296 SoundAttribute( const char* key ) :
298 m_entry( BrowseCaller( *this ) ),
299 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
300 m_nonModal.connect( m_entry.m_entry.m_entry );
305 ui::Widget getWidget() const {
306 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
309 StringOutputStream value( 64 );
310 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
311 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
313 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
315 StringOutputStream value( 64 );
316 value << SelectedEntity_getValueForKey( m_key.c_str() );
317 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
319 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
320 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
321 const char *filename = browse_sound( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) )) );
323 if ( filename != 0 ) {
328 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
331 inline double angle_normalised( double angle ){
332 return float_mod( angle, 360.0 );
335 class AngleAttribute : public EntityAttribute
339 NonModalEntry m_nonModal;
341 AngleAttribute( const char* key ) :
344 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
345 GtkEntry* entry = numeric_entry_new();
347 m_nonModal.connect( m_entry );
352 ui::Widget getWidget() const {
353 return ui::Widget(GTK_WIDGET( m_entry ));
356 StringOutputStream angle( 32 );
357 angle << angle_normalised( entry_get_float( m_entry ) );
358 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
360 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
363 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
364 if ( !string_empty( value ) ) {
365 StringOutputStream angle( 32 );
366 angle << angle_normalised( atof( value ) );
367 gtk_entry_set_text( m_entry, angle.c_str() );
371 gtk_entry_set_text( m_entry, "0" );
374 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
379 typedef const char* String;
380 const String buttons[] = { "up", "down", "z-axis" };
383 class DirectionAttribute : public EntityAttribute
387 NonModalEntry m_nonModal;
389 NonModalRadio m_nonModalRadio;
392 DirectionAttribute( const char* key ) :
395 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
396 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
397 m_nonModalRadio( ApplyRadioCaller( *this ) ){
398 GtkEntry* entry = numeric_entry_new();
400 m_nonModal.connect( m_entry );
402 m_nonModalRadio.connect( m_radio.m_radio );
404 m_hbox = ui::HBox( FALSE, 4 );
405 gtk_widget_show( GTK_WIDGET( m_hbox ) );
407 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_radio.m_hbox ), TRUE, TRUE, 0 );
408 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_entry ), TRUE, TRUE, 0 );
413 ui::Widget getWidget() const {
414 return ui::Widget(GTK_WIDGET( m_hbox ));
417 StringOutputStream angle( 32 );
418 angle << angle_normalised( entry_get_float( m_entry ) );
419 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
421 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
424 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
425 if ( !string_empty( value ) ) {
426 float f = float(atof( value ) );
428 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
429 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
430 gtk_entry_set_text( m_entry, "" );
432 else if ( f == -2 ) {
433 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
434 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
435 gtk_entry_set_text( m_entry, "" );
439 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), TRUE );
440 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
441 StringOutputStream angle( 32 );
442 angle << angle_normalised( f );
443 gtk_entry_set_text( m_entry, angle.c_str() );
448 gtk_entry_set_text( m_entry, "0" );
451 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
454 int index = radio_button_get_active( m_radio.m_radio );
456 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
458 else if ( index == 1 ) {
459 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
461 else if ( index == 2 ) {
465 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
475 AnglesEntry() : m_roll( 0 ), m_pitch( 0 ), m_yaw( 0 ){
479 typedef BasicVector3<double> DoubleVector3;
481 class AnglesAttribute : public EntityAttribute
484 AnglesEntry m_angles;
485 NonModalEntry m_nonModal;
488 AnglesAttribute( const char* key ) :
490 m_nonModal( ApplyCaller( *this ),
491 UpdateCaller( *this ) ),
492 m_hbox(ui::HBox( TRUE, 4 ))
494 gtk_widget_show( GTK_WIDGET( m_hbox ) );
496 GtkEntry* entry = numeric_entry_new();
497 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
498 m_angles.m_pitch = entry;
499 m_nonModal.connect( m_angles.m_pitch );
502 GtkEntry* entry = numeric_entry_new();
503 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
504 m_angles.m_yaw = entry;
505 m_nonModal.connect( m_angles.m_yaw );
508 GtkEntry* entry = numeric_entry_new();
509 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
510 m_angles.m_roll = entry;
511 m_nonModal.connect( m_angles.m_roll );
517 ui::Widget getWidget() const {
518 return ui::Widget(GTK_WIDGET( m_hbox ));
521 StringOutputStream angles( 64 );
522 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
523 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
524 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
525 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
527 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
530 StringOutputStream angle( 32 );
531 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
532 if ( !string_empty( value ) ) {
533 DoubleVector3 pitch_yaw_roll;
534 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
535 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
538 angle << angle_normalised( pitch_yaw_roll.x() );
539 gtk_entry_set_text( m_angles.m_pitch, angle.c_str() );
542 angle << angle_normalised( pitch_yaw_roll.y() );
543 gtk_entry_set_text( m_angles.m_yaw, angle.c_str() );
546 angle << angle_normalised( pitch_yaw_roll.z() );
547 gtk_entry_set_text( m_angles.m_roll, angle.c_str() );
552 gtk_entry_set_text( m_angles.m_pitch, "0" );
553 gtk_entry_set_text( m_angles.m_yaw, "0" );
554 gtk_entry_set_text( m_angles.m_roll, "0" );
557 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
566 Vector3Entry() : m_x( 0 ), m_y( 0 ), m_z( 0 ){
570 class Vector3Attribute : public EntityAttribute
573 Vector3Entry m_vector3;
574 NonModalEntry m_nonModal;
577 Vector3Attribute( const char* key ) :
579 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
580 m_hbox = ui::HBox( TRUE, 4 );
581 gtk_widget_show( GTK_WIDGET( m_hbox ) );
583 GtkEntry* entry = numeric_entry_new();
584 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
585 m_vector3.m_x = entry;
586 m_nonModal.connect( m_vector3.m_x );
589 GtkEntry* entry = numeric_entry_new();
590 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
591 m_vector3.m_y = entry;
592 m_nonModal.connect( m_vector3.m_y );
595 GtkEntry* entry = numeric_entry_new();
596 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
597 m_vector3.m_z = entry;
598 m_nonModal.connect( m_vector3.m_z );
604 ui::Widget getWidget() const {
605 return ui::Widget(GTK_WIDGET( m_hbox ));
608 StringOutputStream vector3( 64 );
609 vector3 << entry_get_float( m_vector3.m_x )
610 << " " << entry_get_float( m_vector3.m_y )
611 << " " << entry_get_float( m_vector3.m_z );
612 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
614 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
617 StringOutputStream buffer( 32 );
618 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
619 if ( !string_empty( value ) ) {
621 if ( !string_parse_vector3( value, x_y_z ) ) {
622 x_y_z = DoubleVector3( 0, 0, 0 );
626 gtk_entry_set_text( m_vector3.m_x, buffer.c_str() );
630 gtk_entry_set_text( m_vector3.m_y, buffer.c_str() );
634 gtk_entry_set_text( m_vector3.m_z, buffer.c_str() );
639 gtk_entry_set_text( m_vector3.m_x, "0" );
640 gtk_entry_set_text( m_vector3.m_y, "0" );
641 gtk_entry_set_text( m_vector3.m_z, "0" );
644 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
647 class NonModalComboBox
650 guint m_changedHandler;
652 static gboolean changed( GtkComboBox *widget, NonModalComboBox* self ){
658 NonModalComboBox( const Callback& changed ) : m_changed( changed ), m_changedHandler( 0 ){
660 void connect( GtkComboBox* combo ){
661 m_changedHandler = g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( changed ), this );
663 void setActive( GtkComboBox* combo, int value ){
664 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
665 gtk_combo_box_set_active( combo, value );
670 class ListAttribute : public EntityAttribute
673 GtkComboBox* m_combo;
674 NonModalComboBox m_nonModal;
675 const ListAttributeType& m_type;
677 ListAttribute( const char* key, const ListAttributeType& type ) :
680 m_nonModal( ApplyCaller( *this ) ),
682 auto combo = ui::ComboBoxText();
684 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
686 gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), ( *i ).first.c_str() );
689 gtk_widget_show( GTK_WIDGET( combo ) );
690 m_nonModal.connect( combo );
697 ui::Widget getWidget() const {
698 return ui::Widget(GTK_WIDGET( m_combo ));
701 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
703 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
706 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
707 ListAttributeType::const_iterator i = m_type.findValue( value );
708 if ( i != m_type.end() ) {
709 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
713 m_nonModal.setActive( m_combo, 0 );
716 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
722 ui::Widget g_entity_split1;
723 ui::Widget g_entity_split2;
724 int g_entitysplit1_position;
725 int g_entitysplit2_position;
727 bool g_entityInspector_windowConstructed = false;
729 GtkTreeView* g_entityClassList;
730 GtkTextView* g_entityClassComment;
732 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
734 GtkEntry* g_entityKeyEntry;
735 GtkEntry* g_entityValueEntry;
737 GtkListStore* g_entlist_store;
738 GtkListStore* g_entprops_store;
739 const EntityClass* g_current_flags = 0;
740 const EntityClass* g_current_comment = 0;
741 const EntityClass* g_current_attributes = 0;
743 // the number of active spawnflags
744 int g_spawnflag_count;
745 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
746 int spawn_table[MAX_FLAGS];
747 // we change the layout depending on how many spawn flags we need to display
748 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
749 GtkTable* g_spawnflagsTable;
751 GtkVBox* g_attributeBox = 0;
752 typedef std::vector<EntityAttribute*> EntityAttributes;
753 EntityAttributes g_entityAttributes;
756 void GlobalEntityAttributes_clear(){
757 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
761 g_entityAttributes.clear();
764 class GetKeyValueVisitor : public Entity::Visitor
766 KeyValues& m_keyvalues;
768 GetKeyValueVisitor( KeyValues& keyvalues )
769 : m_keyvalues( keyvalues ){
772 void visit( const char* key, const char* value ){
773 m_keyvalues.insert( KeyValues::value_type( std::string( key ), std::string( value ) ) );
778 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
779 GetKeyValueVisitor visitor( keyvalues );
781 entity.forEachKeyValue( visitor );
783 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
785 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
787 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
791 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
792 class EntityGetKeyValues : public SelectionSystem::Visitor
794 KeyValues& m_keyvalues;
795 KeyValues& m_defaultValues;
796 mutable std::set<Entity*> m_visited;
798 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
799 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
801 void visit( scene::Instance& instance ) const {
802 Entity* entity = Node_getEntity( instance.path().top() );
803 if ( entity == 0 && instance.path().size() != 1 ) {
804 entity = Node_getEntity( instance.path().parent() );
806 if ( entity != 0 && m_visited.insert( entity ).second ) {
807 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
810 } visitor( keyvalues, defaultValues );
811 GlobalSelectionSystem().foreachSelected( visitor );
814 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
815 KeyValues::iterator i = keyvalues.find( std::string( key ) );
816 if ( i != keyvalues.end() ) {
817 return ( *i ).second.c_str();
822 class EntityClassListStoreAppend : public EntityClassVisitor
826 EntityClassListStoreAppend( GtkListStore* store_ ) : store( store_ ){
828 void visit( EntityClass* e ){
830 gtk_list_store_append( store, &iter );
831 gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
835 void EntityClassList_fill(){
836 EntityClassListStoreAppend append( g_entlist_store );
837 GlobalEntityClassManager().forEach( append );
840 void EntityClassList_clear(){
841 gtk_list_store_clear( g_entlist_store );
844 void SetComment( EntityClass* eclass ){
845 if ( eclass == g_current_comment ) {
849 g_current_comment = eclass;
851 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
852 gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
855 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
856 if ( eclass == g_current_flags ) {
860 g_current_flags = eclass;
862 int spawnflag_count = 0;
865 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
866 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
868 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
869 spawn_table[spawnflag_count] = i;
875 // disable all remaining boxes
876 // NOTE: these boxes might not even be on display
878 for ( int i = 0; i < g_spawnflag_count; ++i )
880 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
881 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), " " );
882 gtk_widget_hide( widget );
883 gtk_widget_ref( widget );
884 gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget );
888 g_spawnflag_count = spawnflag_count;
891 for ( int i = 0; i < g_spawnflag_count; ++i )
893 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
894 gtk_widget_show( widget );
896 StringOutputStream str( 16 );
897 str << LowerCase( eclass->flagnames[spawn_table[i]] );
899 gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1,
900 (GtkAttachOptions)( GTK_FILL ),
901 (GtkAttachOptions)( GTK_FILL ), 0, 0 );
902 gtk_widget_unref( widget );
904 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), str.c_str() );
909 void EntityClassList_selectEntityClass( EntityClass* eclass ){
910 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
912 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
915 gtk_tree_model_get( model, &iter, 0, &text, -1 );
916 if ( strcmp( text, eclass->name() ) == 0 ) {
917 GtkTreeView* view = g_entityClassList;
918 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
919 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
920 if ( GTK_WIDGET_REALIZED( view ) ) {
921 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
923 gtk_tree_path_free( path );
930 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
931 GtkTable* row = DialogRow_new( name, attribute.getWidget() );
932 DialogVBox_packRow( g_attributeBox, GTK_WIDGET( row ) );
936 template<typename Attribute>
937 class StatelessAttributeCreator
940 static EntityAttribute* create( const char* name ){
941 return new Attribute( name );
945 class EntityAttributeFactory
947 typedef EntityAttribute* ( *CreateFunc )( const char* name );
948 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
951 EntityAttributeFactory(){
952 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
953 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
954 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
955 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
956 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
957 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
958 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
959 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
960 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
961 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
962 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
963 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
964 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
966 EntityAttribute* create( const char* type, const char* name ){
967 Creators::iterator i = m_creators.find( type );
968 if ( i != m_creators.end() ) {
969 return ( *i ).second( name );
971 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
972 if ( listType != 0 ) {
973 return new ListAttribute( name, *listType );
979 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
981 void EntityInspector_setEntityClass( EntityClass *eclass ){
982 EntityClassList_selectEntityClass( eclass );
983 SurfaceFlags_setEntityClass( eclass );
985 if ( eclass != g_current_attributes ) {
986 g_current_attributes = eclass;
988 container_remove_all( GTK_CONTAINER( g_attributeBox ) );
989 GlobalEntityAttributes_clear();
991 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
993 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
994 if ( attribute != 0 ) {
995 g_entityAttributes.push_back( attribute );
996 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
1002 void EntityInspector_updateSpawnflags(){
1004 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
1005 for ( int i = 0; i < g_spawnflag_count; ++i )
1007 int v = !!( f & ( 1 << spawn_table[i] ) );
1009 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), v );
1013 // take care of the remaining ones
1014 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1016 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), FALSE );
1021 void EntityInspector_applySpawnflags(){
1026 for ( i = 0; i < g_spawnflag_count; ++i )
1028 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1029 f |= v << spawn_table[i];
1032 sprintf( sz, "%i", f );
1033 const char* value = ( f == 0 ) ? "" : sz;
1036 StringOutputStream command;
1037 command << "entitySetFlags -flags " << f;
1038 UndoableCommand undo( "entitySetSpawnflags" );
1040 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1045 void EntityInspector_updateKeyValues(){
1046 g_selectedKeyValues.clear();
1047 g_selectedDefaultKeyValues.clear();
1048 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1050 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1052 EntityInspector_updateSpawnflags();
1054 GtkListStore* store = g_entprops_store;
1056 // save current key/val pair around filling epair box
1057 // row_select wipes it and sets to first in list
1058 std::string strKey( gtk_entry_get_text( g_entityKeyEntry ) );
1059 std::string strVal( gtk_entry_get_text( g_entityValueEntry ) );
1061 gtk_list_store_clear( store );
1062 // Walk through list and add pairs
1063 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1066 gtk_list_store_append( store, &iter );
1067 StringOutputStream key( 64 );
1068 key << ( *i ).first.c_str();
1069 StringOutputStream value( 64 );
1070 value << ( *i ).second.c_str();
1071 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1074 gtk_entry_set_text( g_entityKeyEntry, strKey.c_str() );
1075 gtk_entry_set_text( g_entityValueEntry, strVal.c_str() );
1077 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1083 class EntityInspectorDraw
1085 IdleDraw m_idleDraw;
1087 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1090 m_idleDraw.queueDraw();
1094 EntityInspectorDraw g_EntityInspectorDraw;
1097 void EntityInspector_keyValueChanged(){
1098 g_EntityInspectorDraw.queueDraw();
1100 void EntityInspector_selectionChanged( const Selectable& ){
1101 EntityInspector_keyValueChanged();
1104 // Creates a new entity based on the currently selected brush and entity type.
1106 void EntityClassList_createEntity(){
1107 GtkTreeView* view = g_entityClassList;
1109 // find out what type of entity we are trying to create
1110 GtkTreeModel* model;
1112 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1113 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) )).alert( "You must have a selected class to create an entity", "info" );
1118 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1121 StringOutputStream command;
1122 command << "entityCreate -class " << text;
1124 UndoableCommand undo( command.c_str() );
1126 Entity_createFromSelection( text, g_vector3_identity );
1131 void EntityInspector_applyKeyValue(){
1132 // Get current selection text
1133 StringOutputStream key( 64 );
1134 key << gtk_entry_get_text( g_entityKeyEntry );
1135 StringOutputStream value( 64 );
1136 value << gtk_entry_get_text( g_entityValueEntry );
1139 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1140 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1141 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1146 // RR2DO2: we don't want spaces in entity keys
1147 if ( strstr( key.c_str(), " " ) ) {
1148 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1152 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1153 StringOutputStream command;
1154 command << "entitySetClass -class " << value.c_str();
1155 UndoableCommand undo( command.c_str() );
1156 Scene_EntitySetClassname_Selected( value.c_str() );
1160 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1164 void EntityInspector_clearKeyValue(){
1165 // Get current selection text
1166 StringOutputStream key( 64 );
1167 key << gtk_entry_get_text( g_entityKeyEntry );
1169 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1170 StringOutputStream command;
1171 command << "entityDeleteKey -key " << key.c_str();
1172 UndoableCommand undo( command.c_str() );
1173 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1177 void EntityInspector_clearAllKeyValues(){
1178 UndoableCommand undo( "entityClear" );
1180 // remove all keys except classname
1181 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1183 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1184 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1189 // =============================================================================
1192 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1193 GtkTreeModel* model;
1194 GtkTreeIter selected;
1195 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1196 EntityClass* eclass;
1197 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1198 if ( eclass != 0 ) {
1199 SetComment( eclass );
1204 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1205 if ( event->type == GDK_2BUTTON_PRESS ) {
1206 EntityClassList_createEntity();
1212 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1213 unsigned int code = gdk_keyval_to_upper( event->keyval );
1215 if ( event->keyval == GDK_Return ) {
1216 EntityClassList_createEntity();
1220 // select the entity that starts with the key pressed
1221 if ( code <= 'Z' && code >= 'A' ) {
1222 GtkTreeView* view = g_entityClassList;
1223 GtkTreeModel* model;
1225 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1226 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1227 gtk_tree_model_get_iter_first( model, &iter );
1230 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1233 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1235 if ( toupper( text[0] ) == (int)code ) {
1236 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1237 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1238 if ( GTK_WIDGET_REALIZED( view ) ) {
1239 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1241 gtk_tree_path_free( path );
1247 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1248 gtk_tree_model_get_iter_first( model, &iter );
1257 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1258 // find out what type of entity we are trying to create
1259 GtkTreeModel* model;
1261 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1267 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1269 gtk_entry_set_text( g_entityKeyEntry, key );
1270 gtk_entry_set_text( g_entityValueEntry, val );
1276 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1277 EntityInspector_applySpawnflags();
1280 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1281 if ( event->keyval == GDK_Return ) {
1282 if ( widget == g_entityKeyEntry ) {
1283 gtk_entry_set_text( g_entityValueEntry, "" );
1284 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1288 EntityInspector_applyKeyValue();
1292 if ( event->keyval == GDK_Escape ) {
1293 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1300 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1301 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1302 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1304 g_entityInspector_windowConstructed = false;
1305 GlobalEntityAttributes_clear();
1308 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1309 ui::Widget vbox = ui::VBox( FALSE, 2 );
1310 gtk_widget_show( vbox );
1311 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1313 g_signal_connect( G_OBJECT( vbox ), "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1316 ui::Widget split1 = ui::VPaned();
1317 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1318 gtk_widget_show( split1 );
1320 g_entity_split1 = split1;
1323 ui::Widget split2 = ui::VPaned();
1324 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1325 gtk_widget_show( split2 );
1327 g_entity_split2 = split2;
1331 ui::Widget scr = ui::ScrolledWindow();
1332 gtk_widget_show( scr );
1333 gtk_paned_add1( GTK_PANED( split2 ), scr );
1334 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1335 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1338 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER );
1340 GtkTreeView* view = GTK_TREE_VIEW( gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) ) );
1341 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1342 gtk_tree_view_set_headers_visible( view, FALSE );
1343 g_signal_connect( G_OBJECT( view ), "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1344 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1347 auto renderer = ui::CellRendererText();
1348 GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1349 gtk_tree_view_append_column( view, column );
1353 GtkTreeSelection* selection = gtk_tree_view_get_selection( view );
1354 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1357 gtk_widget_show( GTK_WIDGET( view ) );
1359 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( view ) );
1361 g_object_unref( G_OBJECT( store ) );
1362 g_entityClassList = view;
1363 g_entlist_store = store;
1368 ui::Widget scr = ui::ScrolledWindow();
1369 gtk_widget_show( scr );
1370 gtk_paned_add2( GTK_PANED( split2 ), scr );
1371 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1372 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1375 GtkTextView* text = GTK_TEXT_VIEW( gtk_text_view_new() );
1376 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1377 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1378 gtk_text_view_set_editable( text, FALSE );
1379 gtk_widget_show( GTK_WIDGET( text ) );
1380 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( text ) );
1381 g_entityClassComment = text;
1387 ui::Widget split2 = ui::VPaned();
1388 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1389 gtk_widget_show( split2 );
1392 ui::Widget vbox2 = ui::VBox( FALSE, 2 );
1393 gtk_widget_show( vbox2 );
1394 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1397 // Spawnflags (4 colums wide max, or window gets too wide.)
1398 GtkTable* table = ui::Table( 4, 4, FALSE );
1399 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1400 gtk_widget_show( GTK_WIDGET( table ) );
1402 g_spawnflagsTable = table;
1404 for ( int i = 0; i < MAX_FLAGS; i++ )
1406 GtkCheckButton* check = ui::CheckButton( "" );
1407 gtk_widget_ref( GTK_WIDGET( check ) );
1408 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1409 g_entitySpawnflagsCheck[i] = check;
1415 ui::Widget scr = ui::ScrolledWindow();
1416 gtk_widget_show( scr );
1417 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1418 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1419 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1422 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING );
1424 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
1425 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1426 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1429 auto renderer = ui::CellRendererText();
1430 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1431 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1435 auto renderer = ui::CellRendererText();
1436 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1437 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1441 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
1442 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1445 gtk_widget_show( view );
1447 gtk_container_add( GTK_CONTAINER( scr ), view );
1449 g_object_unref( G_OBJECT( store ) );
1451 g_entprops_store = store;
1457 GtkTable* table = ui::Table( 2, 2, FALSE );
1458 gtk_widget_show( GTK_WIDGET( table ) );
1459 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1460 gtk_table_set_row_spacings( table, 3 );
1461 gtk_table_set_col_spacings( table, 5 );
1464 GtkEntry* entry = ui::Entry();
1465 gtk_widget_show( GTK_WIDGET( entry ) );
1466 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1467 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1468 (GtkAttachOptions)( 0 ), 0, 0 );
1469 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1470 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1471 g_entityKeyEntry = entry;
1475 GtkEntry* entry = ui::Entry();
1476 gtk_widget_show( GTK_WIDGET( entry ) );
1477 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1478 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1479 (GtkAttachOptions)( 0 ), 0, 0 );
1480 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1481 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1482 g_entityValueEntry = entry;
1486 GtkLabel* label = GTK_LABEL( ui::Label( "Value" ) );
1487 gtk_widget_show( GTK_WIDGET( label ) );
1488 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1489 (GtkAttachOptions)( GTK_FILL ),
1490 (GtkAttachOptions)( 0 ), 0, 0 );
1491 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1495 GtkLabel* label = GTK_LABEL( ui::Label( "Key" ) );
1496 gtk_widget_show( GTK_WIDGET( label ) );
1497 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1498 (GtkAttachOptions)( GTK_FILL ),
1499 (GtkAttachOptions)( 0 ), 0, 0 );
1500 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1505 GtkBox* hbox = ui::HBox( TRUE, 4 );
1506 gtk_widget_show( GTK_WIDGET( hbox ) );
1507 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1510 GtkButton* button = ui::Button( "Clear All" );
1511 gtk_widget_show( GTK_WIDGET( button ) );
1512 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1513 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1516 GtkButton* button = ui::Button( "Delete Key" );
1517 gtk_widget_show( GTK_WIDGET( button ) );
1518 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1519 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1525 ui::Widget scr = ui::ScrolledWindow();
1526 gtk_widget_show( scr );
1527 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1529 ui::Widget viewport = ui::Widget(gtk_viewport_new( 0, 0 ));
1530 gtk_widget_show( viewport );
1531 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1533 g_attributeBox = ui::VBox( FALSE, 2 );
1534 gtk_widget_show( GTK_WIDGET( g_attributeBox ) );
1536 gtk_container_add( GTK_CONTAINER( viewport ), GTK_WIDGET( g_attributeBox ) );
1537 gtk_container_add( GTK_CONTAINER( scr ), viewport );
1538 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1545 // show the sliders in any case
1546 if ( g_entitysplit2_position > 22 ) {
1547 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1550 g_entitysplit2_position = 22;
1551 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1553 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1554 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1557 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1561 g_entityInspector_windowConstructed = true;
1562 EntityClassList_fill();
1564 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1565 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1566 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1569 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1574 class EntityInspector : public ModuleObserver
1576 std::size_t m_unrealised;
1578 EntityInspector() : m_unrealised( 1 ){
1581 if ( --m_unrealised == 0 ) {
1582 if ( g_entityInspector_windowConstructed ) {
1583 //globalOutputStream() << "Entity Inspector: realise\n";
1584 EntityClassList_fill();
1589 if ( ++m_unrealised == 1 ) {
1590 if ( g_entityInspector_windowConstructed ) {
1591 //globalOutputStream() << "Entity Inspector: unrealise\n";
1592 EntityClassList_clear();
1598 EntityInspector g_EntityInspector;
1600 #include "preferencesystem.h"
1601 #include "stringio.h"
1603 void EntityInspector_construct(){
1604 GlobalEntityClassManager().attach( g_EntityInspector );
1606 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1607 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1611 void EntityInspector_destroy(){
1612 GlobalEntityClassManager().detach( g_EntityInspector );
1615 const char *EntityInspector_getCurrentKey(){
1616 if ( !GroupDialog_isShown() ) {
1619 if ( GroupDialog_getPage() != g_page_entity ) {
1622 return gtk_entry_get_text( g_entityKeyEntry );