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 = GTK_ENTRY( gtk_entry_new() );
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 = GTK_ENTRY( gtk_entry_new() );
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 = GTK_HBOX( gtk_hbox_new( 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 ), UpdateCaller( *this ) ){
491 m_hbox = GTK_BOX( gtk_hbox_new( TRUE, 4 ) );
492 gtk_widget_show( GTK_WIDGET( m_hbox ) );
494 GtkEntry* entry = numeric_entry_new();
495 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
496 m_angles.m_pitch = entry;
497 m_nonModal.connect( m_angles.m_pitch );
500 GtkEntry* entry = numeric_entry_new();
501 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
502 m_angles.m_yaw = entry;
503 m_nonModal.connect( m_angles.m_yaw );
506 GtkEntry* entry = numeric_entry_new();
507 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
508 m_angles.m_roll = entry;
509 m_nonModal.connect( m_angles.m_roll );
515 ui::Widget getWidget() const {
516 return ui::Widget(GTK_WIDGET( m_hbox ));
519 StringOutputStream angles( 64 );
520 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
521 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
522 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
523 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
525 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
528 StringOutputStream angle( 32 );
529 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
530 if ( !string_empty( value ) ) {
531 DoubleVector3 pitch_yaw_roll;
532 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
533 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
536 angle << angle_normalised( pitch_yaw_roll.x() );
537 gtk_entry_set_text( m_angles.m_pitch, angle.c_str() );
540 angle << angle_normalised( pitch_yaw_roll.y() );
541 gtk_entry_set_text( m_angles.m_yaw, angle.c_str() );
544 angle << angle_normalised( pitch_yaw_roll.z() );
545 gtk_entry_set_text( m_angles.m_roll, angle.c_str() );
550 gtk_entry_set_text( m_angles.m_pitch, "0" );
551 gtk_entry_set_text( m_angles.m_yaw, "0" );
552 gtk_entry_set_text( m_angles.m_roll, "0" );
555 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
564 Vector3Entry() : m_x( 0 ), m_y( 0 ), m_z( 0 ){
568 class Vector3Attribute : public EntityAttribute
571 Vector3Entry m_vector3;
572 NonModalEntry m_nonModal;
575 Vector3Attribute( const char* key ) :
577 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
578 m_hbox = GTK_BOX( gtk_hbox_new( TRUE, 4 ) );
579 gtk_widget_show( GTK_WIDGET( m_hbox ) );
581 GtkEntry* entry = numeric_entry_new();
582 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
583 m_vector3.m_x = entry;
584 m_nonModal.connect( m_vector3.m_x );
587 GtkEntry* entry = numeric_entry_new();
588 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
589 m_vector3.m_y = entry;
590 m_nonModal.connect( m_vector3.m_y );
593 GtkEntry* entry = numeric_entry_new();
594 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
595 m_vector3.m_z = entry;
596 m_nonModal.connect( m_vector3.m_z );
602 ui::Widget getWidget() const {
603 return ui::Widget(GTK_WIDGET( m_hbox ));
606 StringOutputStream vector3( 64 );
607 vector3 << entry_get_float( m_vector3.m_x )
608 << " " << entry_get_float( m_vector3.m_y )
609 << " " << entry_get_float( m_vector3.m_z );
610 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
612 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
615 StringOutputStream buffer( 32 );
616 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
617 if ( !string_empty( value ) ) {
619 if ( !string_parse_vector3( value, x_y_z ) ) {
620 x_y_z = DoubleVector3( 0, 0, 0 );
624 gtk_entry_set_text( m_vector3.m_x, buffer.c_str() );
628 gtk_entry_set_text( m_vector3.m_y, buffer.c_str() );
632 gtk_entry_set_text( m_vector3.m_z, buffer.c_str() );
637 gtk_entry_set_text( m_vector3.m_x, "0" );
638 gtk_entry_set_text( m_vector3.m_y, "0" );
639 gtk_entry_set_text( m_vector3.m_z, "0" );
642 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
645 class NonModalComboBox
648 guint m_changedHandler;
650 static gboolean changed( GtkComboBox *widget, NonModalComboBox* self ){
656 NonModalComboBox( const Callback& changed ) : m_changed( changed ), m_changedHandler( 0 ){
658 void connect( GtkComboBox* combo ){
659 m_changedHandler = g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( changed ), this );
661 void setActive( GtkComboBox* combo, int value ){
662 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
663 gtk_combo_box_set_active( combo, value );
668 class ListAttribute : public EntityAttribute
671 GtkComboBox* m_combo;
672 NonModalComboBox m_nonModal;
673 const ListAttributeType& m_type;
675 ListAttribute( const char* key, const ListAttributeType& type ) :
678 m_nonModal( ApplyCaller( *this ) ),
680 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
682 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
684 gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), ( *i ).first.c_str() );
687 gtk_widget_show( GTK_WIDGET( combo ) );
688 m_nonModal.connect( combo );
695 ui::Widget getWidget() const {
696 return ui::Widget(GTK_WIDGET( m_combo ));
699 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
701 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
704 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
705 ListAttributeType::const_iterator i = m_type.findValue( value );
706 if ( i != m_type.end() ) {
707 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
711 m_nonModal.setActive( m_combo, 0 );
714 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
720 ui::Widget g_entity_split1;
721 ui::Widget g_entity_split2;
722 int g_entitysplit1_position;
723 int g_entitysplit2_position;
725 bool g_entityInspector_windowConstructed = false;
727 GtkTreeView* g_entityClassList;
728 GtkTextView* g_entityClassComment;
730 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
732 GtkEntry* g_entityKeyEntry;
733 GtkEntry* g_entityValueEntry;
735 GtkListStore* g_entlist_store;
736 GtkListStore* g_entprops_store;
737 const EntityClass* g_current_flags = 0;
738 const EntityClass* g_current_comment = 0;
739 const EntityClass* g_current_attributes = 0;
741 // the number of active spawnflags
742 int g_spawnflag_count;
743 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
744 int spawn_table[MAX_FLAGS];
745 // we change the layout depending on how many spawn flags we need to display
746 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
747 GtkTable* g_spawnflagsTable;
749 GtkVBox* g_attributeBox = 0;
750 typedef std::vector<EntityAttribute*> EntityAttributes;
751 EntityAttributes g_entityAttributes;
754 void GlobalEntityAttributes_clear(){
755 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
759 g_entityAttributes.clear();
762 class GetKeyValueVisitor : public Entity::Visitor
764 KeyValues& m_keyvalues;
766 GetKeyValueVisitor( KeyValues& keyvalues )
767 : m_keyvalues( keyvalues ){
770 void visit( const char* key, const char* value ){
771 m_keyvalues.insert( KeyValues::value_type( std::string( key ), std::string( value ) ) );
776 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
777 GetKeyValueVisitor visitor( keyvalues );
779 entity.forEachKeyValue( visitor );
781 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
783 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
785 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
789 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
790 class EntityGetKeyValues : public SelectionSystem::Visitor
792 KeyValues& m_keyvalues;
793 KeyValues& m_defaultValues;
794 mutable std::set<Entity*> m_visited;
796 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
797 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
799 void visit( scene::Instance& instance ) const {
800 Entity* entity = Node_getEntity( instance.path().top() );
801 if ( entity == 0 && instance.path().size() != 1 ) {
802 entity = Node_getEntity( instance.path().parent() );
804 if ( entity != 0 && m_visited.insert( entity ).second ) {
805 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
808 } visitor( keyvalues, defaultValues );
809 GlobalSelectionSystem().foreachSelected( visitor );
812 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
813 KeyValues::iterator i = keyvalues.find( std::string( key ) );
814 if ( i != keyvalues.end() ) {
815 return ( *i ).second.c_str();
820 class EntityClassListStoreAppend : public EntityClassVisitor
824 EntityClassListStoreAppend( GtkListStore* store_ ) : store( store_ ){
826 void visit( EntityClass* e ){
828 gtk_list_store_append( store, &iter );
829 gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
833 void EntityClassList_fill(){
834 EntityClassListStoreAppend append( g_entlist_store );
835 GlobalEntityClassManager().forEach( append );
838 void EntityClassList_clear(){
839 gtk_list_store_clear( g_entlist_store );
842 void SetComment( EntityClass* eclass ){
843 if ( eclass == g_current_comment ) {
847 g_current_comment = eclass;
849 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
850 gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
853 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
854 if ( eclass == g_current_flags ) {
858 g_current_flags = eclass;
860 int spawnflag_count = 0;
863 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
864 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
866 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
867 spawn_table[spawnflag_count] = i;
873 // disable all remaining boxes
874 // NOTE: these boxes might not even be on display
876 for ( int i = 0; i < g_spawnflag_count; ++i )
878 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
879 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), " " );
880 gtk_widget_hide( widget );
881 gtk_widget_ref( widget );
882 gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget );
886 g_spawnflag_count = spawnflag_count;
889 for ( int i = 0; i < g_spawnflag_count; ++i )
891 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
892 gtk_widget_show( widget );
894 StringOutputStream str( 16 );
895 str << LowerCase( eclass->flagnames[spawn_table[i]] );
897 gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1,
898 (GtkAttachOptions)( GTK_FILL ),
899 (GtkAttachOptions)( GTK_FILL ), 0, 0 );
900 gtk_widget_unref( widget );
902 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), str.c_str() );
907 void EntityClassList_selectEntityClass( EntityClass* eclass ){
908 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
910 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
913 gtk_tree_model_get( model, &iter, 0, &text, -1 );
914 if ( strcmp( text, eclass->name() ) == 0 ) {
915 GtkTreeView* view = g_entityClassList;
916 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
917 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
918 if ( GTK_WIDGET_REALIZED( view ) ) {
919 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
921 gtk_tree_path_free( path );
928 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
929 GtkTable* row = DialogRow_new( name, attribute.getWidget() );
930 DialogVBox_packRow( g_attributeBox, GTK_WIDGET( row ) );
934 template<typename Attribute>
935 class StatelessAttributeCreator
938 static EntityAttribute* create( const char* name ){
939 return new Attribute( name );
943 class EntityAttributeFactory
945 typedef EntityAttribute* ( *CreateFunc )( const char* name );
946 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
949 EntityAttributeFactory(){
950 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
951 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
952 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
953 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
954 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
955 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
956 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
957 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
958 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
959 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
960 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
961 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
962 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
964 EntityAttribute* create( const char* type, const char* name ){
965 Creators::iterator i = m_creators.find( type );
966 if ( i != m_creators.end() ) {
967 return ( *i ).second( name );
969 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
970 if ( listType != 0 ) {
971 return new ListAttribute( name, *listType );
977 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
979 void EntityInspector_setEntityClass( EntityClass *eclass ){
980 EntityClassList_selectEntityClass( eclass );
981 SurfaceFlags_setEntityClass( eclass );
983 if ( eclass != g_current_attributes ) {
984 g_current_attributes = eclass;
986 container_remove_all( GTK_CONTAINER( g_attributeBox ) );
987 GlobalEntityAttributes_clear();
989 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
991 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
992 if ( attribute != 0 ) {
993 g_entityAttributes.push_back( attribute );
994 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
1000 void EntityInspector_updateSpawnflags(){
1002 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
1003 for ( int i = 0; i < g_spawnflag_count; ++i )
1005 int v = !!( f & ( 1 << spawn_table[i] ) );
1007 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), v );
1011 // take care of the remaining ones
1012 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1014 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), FALSE );
1019 void EntityInspector_applySpawnflags(){
1024 for ( i = 0; i < g_spawnflag_count; ++i )
1026 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1027 f |= v << spawn_table[i];
1030 sprintf( sz, "%i", f );
1031 const char* value = ( f == 0 ) ? "" : sz;
1034 StringOutputStream command;
1035 command << "entitySetFlags -flags " << f;
1036 UndoableCommand undo( "entitySetSpawnflags" );
1038 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1043 void EntityInspector_updateKeyValues(){
1044 g_selectedKeyValues.clear();
1045 g_selectedDefaultKeyValues.clear();
1046 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1048 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1050 EntityInspector_updateSpawnflags();
1052 GtkListStore* store = g_entprops_store;
1054 // save current key/val pair around filling epair box
1055 // row_select wipes it and sets to first in list
1056 std::string strKey( gtk_entry_get_text( g_entityKeyEntry ) );
1057 std::string strVal( gtk_entry_get_text( g_entityValueEntry ) );
1059 gtk_list_store_clear( store );
1060 // Walk through list and add pairs
1061 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1064 gtk_list_store_append( store, &iter );
1065 StringOutputStream key( 64 );
1066 key << ( *i ).first.c_str();
1067 StringOutputStream value( 64 );
1068 value << ( *i ).second.c_str();
1069 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1072 gtk_entry_set_text( g_entityKeyEntry, strKey.c_str() );
1073 gtk_entry_set_text( g_entityValueEntry, strVal.c_str() );
1075 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1081 class EntityInspectorDraw
1083 IdleDraw m_idleDraw;
1085 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1088 m_idleDraw.queueDraw();
1092 EntityInspectorDraw g_EntityInspectorDraw;
1095 void EntityInspector_keyValueChanged(){
1096 g_EntityInspectorDraw.queueDraw();
1098 void EntityInspector_selectionChanged( const Selectable& ){
1099 EntityInspector_keyValueChanged();
1102 // Creates a new entity based on the currently selected brush and entity type.
1104 void EntityClassList_createEntity(){
1105 GtkTreeView* view = g_entityClassList;
1107 // find out what type of entity we are trying to create
1108 GtkTreeModel* model;
1110 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1111 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) )).alert( "You must have a selected class to create an entity", "info" );
1116 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1119 StringOutputStream command;
1120 command << "entityCreate -class " << text;
1122 UndoableCommand undo( command.c_str() );
1124 Entity_createFromSelection( text, g_vector3_identity );
1129 void EntityInspector_applyKeyValue(){
1130 // Get current selection text
1131 StringOutputStream key( 64 );
1132 key << gtk_entry_get_text( g_entityKeyEntry );
1133 StringOutputStream value( 64 );
1134 value << gtk_entry_get_text( g_entityValueEntry );
1137 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1138 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1139 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1144 // RR2DO2: we don't want spaces in entity keys
1145 if ( strstr( key.c_str(), " " ) ) {
1146 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1150 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1151 StringOutputStream command;
1152 command << "entitySetClass -class " << value.c_str();
1153 UndoableCommand undo( command.c_str() );
1154 Scene_EntitySetClassname_Selected( value.c_str() );
1158 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1162 void EntityInspector_clearKeyValue(){
1163 // Get current selection text
1164 StringOutputStream key( 64 );
1165 key << gtk_entry_get_text( g_entityKeyEntry );
1167 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1168 StringOutputStream command;
1169 command << "entityDeleteKey -key " << key.c_str();
1170 UndoableCommand undo( command.c_str() );
1171 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1175 void EntityInspector_clearAllKeyValues(){
1176 UndoableCommand undo( "entityClear" );
1178 // remove all keys except classname
1179 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1181 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1182 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1187 // =============================================================================
1190 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1191 GtkTreeModel* model;
1192 GtkTreeIter selected;
1193 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1194 EntityClass* eclass;
1195 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1196 if ( eclass != 0 ) {
1197 SetComment( eclass );
1202 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1203 if ( event->type == GDK_2BUTTON_PRESS ) {
1204 EntityClassList_createEntity();
1210 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1211 unsigned int code = gdk_keyval_to_upper( event->keyval );
1213 if ( event->keyval == GDK_Return ) {
1214 EntityClassList_createEntity();
1218 // select the entity that starts with the key pressed
1219 if ( code <= 'Z' && code >= 'A' ) {
1220 GtkTreeView* view = g_entityClassList;
1221 GtkTreeModel* model;
1223 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1224 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1225 gtk_tree_model_get_iter_first( model, &iter );
1228 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1231 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1233 if ( toupper( text[0] ) == (int)code ) {
1234 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1235 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1236 if ( GTK_WIDGET_REALIZED( view ) ) {
1237 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1239 gtk_tree_path_free( path );
1245 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1246 gtk_tree_model_get_iter_first( model, &iter );
1255 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1256 // find out what type of entity we are trying to create
1257 GtkTreeModel* model;
1259 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1265 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1267 gtk_entry_set_text( g_entityKeyEntry, key );
1268 gtk_entry_set_text( g_entityValueEntry, val );
1274 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1275 EntityInspector_applySpawnflags();
1278 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1279 if ( event->keyval == GDK_Return ) {
1280 if ( widget == g_entityKeyEntry ) {
1281 gtk_entry_set_text( g_entityValueEntry, "" );
1282 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1286 EntityInspector_applyKeyValue();
1290 if ( event->keyval == GDK_Escape ) {
1291 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1298 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1299 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1300 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1302 g_entityInspector_windowConstructed = false;
1303 GlobalEntityAttributes_clear();
1306 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1307 ui::Widget vbox = ui::VBox( FALSE, 2 );
1308 gtk_widget_show( vbox );
1309 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1311 g_signal_connect( G_OBJECT( vbox ), "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1314 ui::Widget split1 = ui::Widget(gtk_vpaned_new());
1315 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1316 gtk_widget_show( split1 );
1318 g_entity_split1 = split1;
1321 ui::Widget split2 = ui::Widget(gtk_vpaned_new());
1322 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1323 gtk_widget_show( split2 );
1325 g_entity_split2 = split2;
1329 ui::Widget scr = ui::ScrolledWindow();
1330 gtk_widget_show( scr );
1331 gtk_paned_add1( GTK_PANED( split2 ), scr );
1332 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1333 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1336 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER );
1338 GtkTreeView* view = GTK_TREE_VIEW( gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) ) );
1339 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1340 gtk_tree_view_set_headers_visible( view, FALSE );
1341 g_signal_connect( G_OBJECT( view ), "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1342 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1345 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1346 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Key", renderer, "text", 0, 0 );
1347 gtk_tree_view_append_column( view, column );
1351 GtkTreeSelection* selection = gtk_tree_view_get_selection( view );
1352 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1355 gtk_widget_show( GTK_WIDGET( view ) );
1357 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( view ) );
1359 g_object_unref( G_OBJECT( store ) );
1360 g_entityClassList = view;
1361 g_entlist_store = store;
1366 ui::Widget scr = ui::ScrolledWindow();
1367 gtk_widget_show( scr );
1368 gtk_paned_add2( GTK_PANED( split2 ), scr );
1369 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1370 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1373 GtkTextView* text = GTK_TEXT_VIEW( gtk_text_view_new() );
1374 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1375 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1376 gtk_text_view_set_editable( text, FALSE );
1377 gtk_widget_show( GTK_WIDGET( text ) );
1378 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( text ) );
1379 g_entityClassComment = text;
1385 ui::Widget split2 = ui::Widget(gtk_vpaned_new());
1386 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1387 gtk_widget_show( split2 );
1390 ui::Widget vbox2 = ui::VBox( FALSE, 2 );
1391 gtk_widget_show( vbox2 );
1392 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1395 // Spawnflags (4 colums wide max, or window gets too wide.)
1396 GtkTable* table = GTK_TABLE( gtk_table_new( 4, 4, FALSE ) );
1397 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1398 gtk_widget_show( GTK_WIDGET( table ) );
1400 g_spawnflagsTable = table;
1402 for ( int i = 0; i < MAX_FLAGS; i++ )
1404 GtkCheckButton* check = ui::CheckButton( "" );
1405 gtk_widget_ref( GTK_WIDGET( check ) );
1406 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1407 g_entitySpawnflagsCheck[i] = check;
1413 ui::Widget scr = ui::ScrolledWindow();
1414 gtk_widget_show( scr );
1415 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1416 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1417 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1420 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING );
1422 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
1423 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1424 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1427 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1428 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, 0 );
1429 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1433 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1434 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 1, 0 );
1435 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1439 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
1440 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1443 gtk_widget_show( view );
1445 gtk_container_add( GTK_CONTAINER( scr ), view );
1447 g_object_unref( G_OBJECT( store ) );
1449 g_entprops_store = store;
1455 GtkTable* table = GTK_TABLE( gtk_table_new( 2, 2, FALSE ) );
1456 gtk_widget_show( GTK_WIDGET( table ) );
1457 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1458 gtk_table_set_row_spacings( table, 3 );
1459 gtk_table_set_col_spacings( table, 5 );
1462 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
1463 gtk_widget_show( GTK_WIDGET( entry ) );
1464 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1465 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1466 (GtkAttachOptions)( 0 ), 0, 0 );
1467 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1468 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1469 g_entityKeyEntry = entry;
1473 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
1474 gtk_widget_show( GTK_WIDGET( entry ) );
1475 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1476 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1477 (GtkAttachOptions)( 0 ), 0, 0 );
1478 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1479 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1480 g_entityValueEntry = entry;
1484 GtkLabel* label = GTK_LABEL( ui::Label( "Value" ) );
1485 gtk_widget_show( GTK_WIDGET( label ) );
1486 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1487 (GtkAttachOptions)( GTK_FILL ),
1488 (GtkAttachOptions)( 0 ), 0, 0 );
1489 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1493 GtkLabel* label = GTK_LABEL( ui::Label( "Key" ) );
1494 gtk_widget_show( GTK_WIDGET( label ) );
1495 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1496 (GtkAttachOptions)( GTK_FILL ),
1497 (GtkAttachOptions)( 0 ), 0, 0 );
1498 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1503 GtkBox* hbox = GTK_BOX( gtk_hbox_new( TRUE, 4 ) );
1504 gtk_widget_show( GTK_WIDGET( hbox ) );
1505 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1508 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Clear All" ) );
1509 gtk_widget_show( GTK_WIDGET( button ) );
1510 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1511 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1514 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Delete Key" ) );
1515 gtk_widget_show( GTK_WIDGET( button ) );
1516 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1517 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1523 ui::Widget scr = ui::ScrolledWindow();
1524 gtk_widget_show( scr );
1525 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1527 ui::Widget viewport = ui::Widget(gtk_viewport_new( 0, 0 ));
1528 gtk_widget_show( viewport );
1529 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1531 g_attributeBox = ui::VBox( FALSE, 2 );
1532 gtk_widget_show( GTK_WIDGET( g_attributeBox ) );
1534 gtk_container_add( GTK_CONTAINER( viewport ), GTK_WIDGET( g_attributeBox ) );
1535 gtk_container_add( GTK_CONTAINER( scr ), viewport );
1536 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1543 // show the sliders in any case
1544 if ( g_entitysplit2_position > 22 ) {
1545 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1548 g_entitysplit2_position = 22;
1549 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1551 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1552 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1555 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1559 g_entityInspector_windowConstructed = true;
1560 EntityClassList_fill();
1562 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1563 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1564 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1567 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1572 class EntityInspector : public ModuleObserver
1574 std::size_t m_unrealised;
1576 EntityInspector() : m_unrealised( 1 ){
1579 if ( --m_unrealised == 0 ) {
1580 if ( g_entityInspector_windowConstructed ) {
1581 //globalOutputStream() << "Entity Inspector: realise\n";
1582 EntityClassList_fill();
1587 if ( ++m_unrealised == 1 ) {
1588 if ( g_entityInspector_windowConstructed ) {
1589 //globalOutputStream() << "Entity Inspector: unrealise\n";
1590 EntityClassList_clear();
1596 EntityInspector g_EntityInspector;
1598 #include "preferencesystem.h"
1599 #include "stringio.h"
1601 void EntityInspector_construct(){
1602 GlobalEntityClassManager().attach( g_EntityInspector );
1604 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1605 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1609 void EntityInspector_destroy(){
1610 GlobalEntityClassManager().detach( g_EntityInspector );
1613 const char *EntityInspector_getCurrentKey(){
1614 if ( !GroupDialog_isShown() ) {
1617 if ( GroupDialog_getPage() != g_page_entity ) {
1620 return gtk_entry_get_text( g_entityKeyEntry );