2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "entityinspector.h"
24 #include "debugging/debugging.h"
28 #include "ifilesystem.h"
30 #include "iscenegraph.h"
31 #include "iselection.h"
36 #include <gdk/gdkkeysyms.h>
37 #include <uilib/uilib.h>
41 #include "eclasslib.h"
43 #include "generic/callback.h"
45 #include "stream/stringstream.h"
46 #include "moduleobserver.h"
50 #include "gtkutil/accelerator.h"
51 #include "gtkutil/dialog.h"
52 #include "gtkutil/filechooser.h"
53 #include "gtkutil/messagebox.h"
54 #include "gtkutil/nonmodal.h"
55 #include "gtkutil/button.h"
56 #include "gtkutil/entry.h"
57 #include "gtkutil/container.h"
63 #include "mainframe.h"
64 #include "textureentry.h"
65 #include "groupdialog.h"
67 ui::Entry numeric_entry_new(){
68 auto entry = ui::Entry(ui::New);
70 entry.dimensions(64, -1);
76 typedef std::map<CopiedString, CopiedString> KeyValues;
77 KeyValues g_selectedKeyValues;
78 KeyValues g_selectedDefaultKeyValues;
81 const char* SelectedEntity_getValueForKey( const char* key ){
83 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
84 if ( i != g_selectedKeyValues.end() ) {
85 return ( *i ).second.c_str();
89 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
90 if ( i != g_selectedDefaultKeyValues.end() ) {
91 return ( *i ).second.c_str();
97 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
98 StringOutputStream command( 256 );
99 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
100 UndoableCommand undo( command.c_str() );
101 Scene_EntitySetKeyValue_Selected( key, value );
104 class EntityAttribute
107 virtual ~EntityAttribute() = default;
108 virtual ui::Widget getWidget() const = 0;
109 virtual void update() = 0;
110 virtual void release() = 0;
113 class BooleanAttribute : public EntityAttribute
116 ui::CheckButton m_check;
118 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
123 BooleanAttribute( const char* key ) :
126 auto check = ui::CheckButton(ui::New);
131 guint handler = check.connect( "toggled", G_CALLBACK( toggled ), this );
132 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
136 ui::Widget getWidget() const {
143 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_check.active() ? "1" : "" );
145 typedef MemberCaller<BooleanAttribute, void(), &BooleanAttribute::apply> ApplyCaller;
148 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
149 if ( !string_empty( value ) ) {
150 toggle_button_set_active_no_signal( m_check, atoi( value ) != 0 );
154 toggle_button_set_active_no_signal( m_check, false );
157 typedef MemberCaller<BooleanAttribute, void(), &BooleanAttribute::update> UpdateCaller;
161 class StringAttribute : public EntityAttribute
165 NonModalEntry m_nonModal;
167 StringAttribute( const char* key ) :
170 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
171 auto entry = ui::Entry(ui::New);
173 entry.dimensions(50, -1);
176 m_nonModal.connect( m_entry );
178 ui::Widget getWidget() const {
181 ui::Entry getEntry() const {
189 StringOutputStream value( 64 );
190 value << m_entry.text();
191 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
193 typedef MemberCaller<StringAttribute, void(), &StringAttribute::apply> ApplyCaller;
196 StringOutputStream value( 64 );
197 value << SelectedEntity_getValueForKey( m_key.c_str() );
198 m_entry.text(value.c_str());
200 typedef MemberCaller<StringAttribute, void(), &StringAttribute::update> UpdateCaller;
203 class ShaderAttribute : public StringAttribute
206 ShaderAttribute( const char* key ) : StringAttribute( key ){
207 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
212 class ColorAttribute : public EntityAttribute
215 BrowsedPathEntry m_entry;
216 NonModalEntry m_nonModal;
218 ColorAttribute( const char* key ) :
220 m_entry( BrowseCaller( *this ) ),
221 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
222 m_nonModal.connect( m_entry.m_entry.m_entry );
227 ui::Widget getWidget() const {
228 return ui::Widget( m_entry.m_entry.m_frame );
231 StringOutputStream value( 64 );
232 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
233 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
235 typedef MemberCaller<ColorAttribute, void(), &ColorAttribute::apply> ApplyCaller;
237 StringOutputStream value( 64 );
238 value << SelectedEntity_getValueForKey( m_key.c_str() );
239 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
241 typedef MemberCaller<ColorAttribute, void(), &ColorAttribute::update> UpdateCaller;
242 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
243 //const char *filename = misc_model_dialog( gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) );
245 /* hijack BrowsedPathEntry to call colour chooser */
248 // if ( filename != 0 ) {
249 // setPath( filename );
254 typedef MemberCaller<ColorAttribute, void(const BrowsedPathEntry::SetPathCallback&), &ColorAttribute::browse> BrowseCaller;
258 class ModelAttribute : public EntityAttribute
261 BrowsedPathEntry m_entry;
262 NonModalEntry m_nonModal;
264 ModelAttribute( const char* key ) :
266 m_entry( BrowseCaller( *this ) ),
267 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
268 m_nonModal.connect( m_entry.m_entry.m_entry );
273 ui::Widget getWidget() const {
274 return m_entry.m_entry.m_frame;
277 StringOutputStream value( 64 );
278 value << m_entry.m_entry.m_entry.text();
279 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
281 typedef MemberCaller<ModelAttribute, void(), &ModelAttribute::apply> ApplyCaller;
283 StringOutputStream value( 64 );
284 value << SelectedEntity_getValueForKey( m_key.c_str() );
285 m_entry.m_entry.m_entry.text(value.c_str());
287 typedef MemberCaller<ModelAttribute, void(), &ModelAttribute::update> UpdateCaller;
288 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
289 const char *filename = misc_model_dialog( m_entry.m_entry.m_frame.window() );
291 if ( filename != 0 ) {
296 typedef MemberCaller<ModelAttribute, void(const BrowsedPathEntry::SetPathCallback&), &ModelAttribute::browse> BrowseCaller;
299 const char* browse_sound( ui::Widget parent ){
300 StringOutputStream buffer( 1024 );
302 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
304 if ( !file_readable( buffer.c_str() ) ) {
307 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
310 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
311 if ( filename != 0 ) {
312 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
313 if ( relative == filename ) {
314 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
321 class SoundAttribute : public EntityAttribute
324 BrowsedPathEntry m_entry;
325 NonModalEntry m_nonModal;
327 SoundAttribute( const char* key ) :
329 m_entry( BrowseCaller( *this ) ),
330 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
331 m_nonModal.connect( m_entry.m_entry.m_entry );
336 ui::Widget getWidget() const {
337 return ui::Widget(m_entry.m_entry.m_frame );
340 StringOutputStream value( 64 );
341 value << m_entry.m_entry.m_entry.text();
342 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
344 typedef MemberCaller<SoundAttribute, void(), &SoundAttribute::apply> ApplyCaller;
346 StringOutputStream value( 64 );
347 value << SelectedEntity_getValueForKey( m_key.c_str() );
348 m_entry.m_entry.m_entry.text(value.c_str());
350 typedef MemberCaller<SoundAttribute, void(), &SoundAttribute::update> UpdateCaller;
351 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
352 const char *filename = browse_sound( m_entry.m_entry.m_frame.window() );
354 if ( filename != 0 ) {
359 typedef MemberCaller<SoundAttribute, void(const BrowsedPathEntry::SetPathCallback&), &SoundAttribute::browse> BrowseCaller;
362 inline double angle_normalised( double angle ){
363 return float_mod( angle, 360.0 );
366 class AngleAttribute : public EntityAttribute
370 NonModalEntry m_nonModal;
372 AngleAttribute( const char* key ) :
375 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
376 auto entry = numeric_entry_new();
378 m_nonModal.connect( m_entry );
383 ui::Widget getWidget() const {
384 return ui::Widget(m_entry );
387 StringOutputStream angle( 32 );
388 angle << angle_normalised( entry_get_float( m_entry ) );
389 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
391 typedef MemberCaller<AngleAttribute, void(), &AngleAttribute::apply> ApplyCaller;
394 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
395 if ( !string_empty( value ) ) {
396 StringOutputStream angle( 32 );
397 angle << angle_normalised( atof( value ) );
398 m_entry.text(angle.c_str());
405 typedef MemberCaller<AngleAttribute, void(), &AngleAttribute::update> UpdateCaller;
410 typedef const char* String;
411 const String buttons[] = { "up", "down", "z-axis" };
414 class DirectionAttribute : public EntityAttribute
418 NonModalEntry m_nonModal;
420 NonModalRadio m_nonModalRadio;
421 ui::HBox m_hbox{ui::null};
423 DirectionAttribute( const char* key ) :
426 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
427 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
428 m_nonModalRadio( ApplyRadioCaller( *this ) ){
429 auto entry = numeric_entry_new();
431 m_nonModal.connect( m_entry );
433 m_nonModalRadio.connect( m_radio.m_radio );
435 m_hbox = ui::HBox( FALSE, 4 );
438 m_hbox.pack_start( m_radio.m_hbox, TRUE, TRUE, 0 );
439 m_hbox.pack_start( m_entry, TRUE, TRUE, 0 );
444 ui::Widget getWidget() const {
445 return ui::Widget(m_hbox );
448 StringOutputStream angle( 32 );
449 angle << angle_normalised( entry_get_float( m_entry ) );
450 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
452 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::apply> ApplyCaller;
455 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
456 if ( !string_empty( value ) ) {
457 float f = float(atof( value ) );
459 gtk_widget_set_sensitive( m_entry , FALSE );
460 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
463 else if ( f == -2 ) {
464 gtk_widget_set_sensitive( m_entry , FALSE );
465 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
470 gtk_widget_set_sensitive( m_entry , TRUE );
471 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
472 StringOutputStream angle( 32 );
473 angle << angle_normalised( f );
474 m_entry.text(angle.c_str());
482 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::update> UpdateCaller;
485 int index = radio_button_get_active( m_radio.m_radio );
487 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
489 else if ( index == 1 ) {
490 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
492 else if ( index == 2 ) {
496 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::applyRadio> ApplyRadioCaller;
506 AnglesEntry() : m_roll( ui::null ), m_pitch( ui::null ), m_yaw( ui::null ){
510 typedef BasicVector3<double> DoubleVector3;
512 class AnglesAttribute : public EntityAttribute
515 AnglesEntry m_angles;
516 NonModalEntry m_nonModal;
519 AnglesAttribute( const char* key ) :
521 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
522 m_hbox(ui::HBox( TRUE, 4 ))
526 auto entry = numeric_entry_new();
527 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
528 m_angles.m_pitch = entry;
529 m_nonModal.connect( m_angles.m_pitch );
532 auto entry = numeric_entry_new();
533 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
534 m_angles.m_yaw = entry;
535 m_nonModal.connect( m_angles.m_yaw );
538 auto entry = numeric_entry_new();
539 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
540 m_angles.m_roll = entry;
541 m_nonModal.connect( m_angles.m_roll );
547 ui::Widget getWidget() const {
548 return ui::Widget(m_hbox );
551 StringOutputStream angles( 64 );
552 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
553 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
554 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
555 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
557 typedef MemberCaller<AnglesAttribute, void(), &AnglesAttribute::apply> ApplyCaller;
560 StringOutputStream angle( 32 );
561 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
562 if ( !string_empty( value ) ) {
563 DoubleVector3 pitch_yaw_roll;
564 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
565 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
568 angle << angle_normalised( pitch_yaw_roll.x() );
569 m_angles.m_pitch.text(angle.c_str());
572 angle << angle_normalised( pitch_yaw_roll.y() );
573 m_angles.m_yaw.text(angle.c_str());
576 angle << angle_normalised( pitch_yaw_roll.z() );
577 m_angles.m_roll.text(angle.c_str());
582 m_angles.m_pitch.text("0");
583 m_angles.m_yaw.text("0");
584 m_angles.m_roll.text("0");
587 typedef MemberCaller<AnglesAttribute, void(), &AnglesAttribute::update> UpdateCaller;
596 Vector3Entry() : m_x( ui::null ), m_y( ui::null ), m_z( ui::null ){
600 class Vector3Attribute : public EntityAttribute
603 Vector3Entry m_vector3;
604 NonModalEntry m_nonModal;
605 ui::Box m_hbox{ui::null};
607 Vector3Attribute( const char* key ) :
609 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
610 m_hbox = ui::HBox( TRUE, 4 );
613 auto entry = numeric_entry_new();
614 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
615 m_vector3.m_x = entry;
616 m_nonModal.connect( m_vector3.m_x );
619 auto entry = numeric_entry_new();
620 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
621 m_vector3.m_y = entry;
622 m_nonModal.connect( m_vector3.m_y );
625 auto entry = numeric_entry_new();
626 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
627 m_vector3.m_z = entry;
628 m_nonModal.connect( m_vector3.m_z );
634 ui::Widget getWidget() const {
635 return ui::Widget(m_hbox );
638 StringOutputStream vector3( 64 );
639 vector3 << entry_get_float( m_vector3.m_x )
640 << " " << entry_get_float( m_vector3.m_y )
641 << " " << entry_get_float( m_vector3.m_z );
642 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
644 typedef MemberCaller<Vector3Attribute, void(), &Vector3Attribute::apply> ApplyCaller;
647 StringOutputStream buffer( 32 );
648 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
649 if ( !string_empty( value ) ) {
651 if ( !string_parse_vector3( value, x_y_z ) ) {
652 x_y_z = DoubleVector3( 0, 0, 0 );
656 m_vector3.m_x.text(buffer.c_str());
660 m_vector3.m_y.text(buffer.c_str());
664 m_vector3.m_z.text(buffer.c_str());
669 m_vector3.m_x.text("0");
670 m_vector3.m_y.text("0");
671 m_vector3.m_z.text("0");
674 typedef MemberCaller<Vector3Attribute, void(), &Vector3Attribute::update> UpdateCaller;
677 class NonModalComboBox
679 Callback<void()> m_changed;
680 guint m_changedHandler;
682 static gboolean changed( ui::ComboBox widget, NonModalComboBox* self ){
688 NonModalComboBox( const Callback<void()>& changed ) : m_changed( changed ), m_changedHandler( 0 ){
690 void connect( ui::ComboBox combo ){
691 m_changedHandler = combo.connect( "changed", G_CALLBACK( changed ), this );
693 void setActive( ui::ComboBox combo, int value ){
694 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
695 gtk_combo_box_set_active( combo, value );
700 class ListAttribute : public EntityAttribute
703 ui::ComboBox m_combo;
704 NonModalComboBox m_nonModal;
705 const ListAttributeType& m_type;
707 ListAttribute( const char* key, const ListAttributeType& type ) :
710 m_nonModal( ApplyCaller( *this ) ),
712 auto combo = ui::ComboBoxText(ui::New);
714 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
716 gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), ( *i ).first.c_str() );
720 m_nonModal.connect( combo );
727 ui::Widget getWidget() const {
728 return ui::Widget(m_combo );
731 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
733 typedef MemberCaller<ListAttribute, void(), &ListAttribute::apply> ApplyCaller;
736 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
737 ListAttributeType::const_iterator i = m_type.findValue( value );
738 if ( i != m_type.end() ) {
739 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
743 m_nonModal.setActive( m_combo, 0 );
746 typedef MemberCaller<ListAttribute, void(), &ListAttribute::update> UpdateCaller;
752 GtkWidget* g_entity_split0 = 0;
753 ui::Widget g_entity_split1{ui::null};
754 ui::Widget g_entity_split2{ui::null};
755 int g_entitysplit0_position;
756 int g_entitysplit1_position;
757 int g_entitysplit2_position;
759 bool g_entityInspector_windowConstructed = false;
761 ui::TreeView g_entityClassList{ui::null};
762 ui::TextView g_entityClassComment{ui::null};
764 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
766 ui::Entry g_entityKeyEntry{ui::null};
767 ui::Entry g_entityValueEntry{ui::null};
769 ui::ListStore g_entlist_store{ui::null};
770 ui::ListStore g_entprops_store{ui::null};
771 const EntityClass* g_current_flags = 0;
772 const EntityClass* g_current_comment = 0;
773 const EntityClass* g_current_attributes = 0;
775 // the number of active spawnflags
776 int g_spawnflag_count;
777 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
778 int spawn_table[MAX_FLAGS];
779 // we change the layout depending on how many spawn flags we need to display
780 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
781 ui::Table g_spawnflagsTable{ui::null};
783 ui::VBox g_attributeBox{ui::null};
784 typedef std::vector<EntityAttribute*> EntityAttributes;
785 EntityAttributes g_entityAttributes;
788 void GlobalEntityAttributes_clear(){
789 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
793 g_entityAttributes.clear();
796 class GetKeyValueVisitor : public Entity::Visitor
798 KeyValues& m_keyvalues;
800 GetKeyValueVisitor( KeyValues& keyvalues )
801 : m_keyvalues( keyvalues ){
804 void visit( const char* key, const char* value ){
805 m_keyvalues.insert( KeyValues::value_type( CopiedString( key ), CopiedString( value ) ) );
810 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
811 GetKeyValueVisitor visitor( keyvalues );
813 entity.forEachKeyValue( visitor );
815 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
817 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
819 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
823 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
824 class EntityGetKeyValues : public SelectionSystem::Visitor
826 KeyValues& m_keyvalues;
827 KeyValues& m_defaultValues;
828 mutable std::set<Entity*> m_visited;
830 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
831 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
833 void visit( scene::Instance& instance ) const {
834 Entity* entity = Node_getEntity( instance.path().top() );
835 if ( entity == 0 && instance.path().size() != 1 ) {
836 entity = Node_getEntity( instance.path().parent() );
838 if ( entity != 0 && m_visited.insert( entity ).second ) {
839 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
842 } visitor( keyvalues, defaultValues );
843 GlobalSelectionSystem().foreachSelected( visitor );
846 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
847 KeyValues::iterator i = keyvalues.find( CopiedString( key ) );
848 if ( i != keyvalues.end() ) {
849 return ( *i ).second.c_str();
854 class EntityClassListStoreAppend : public EntityClassVisitor
858 EntityClassListStoreAppend( ui::ListStore store_ ) : store( store_ ){
860 void visit( EntityClass* e ){
861 store.append(0, e->name(), 1, e);
865 void EntityClassList_fill(){
866 EntityClassListStoreAppend append( g_entlist_store );
867 GlobalEntityClassManager().forEach( append );
870 void EntityClassList_clear(){
871 g_entlist_store.clear();
874 void SetComment( EntityClass* eclass ){
875 if ( eclass == g_current_comment ) {
879 g_current_comment = eclass;
881 g_entityClassComment.text(eclass->comments());
883 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
884 //gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
885 const char* comment = eclass->comments(), *c;
886 int offset = 0, pattern_start = -1, spaces = 0;
888 gtk_text_buffer_set_text( buffer, comment, -1 );
890 // Catch patterns like "\nstuff :" used to describe keys and spawnflags, and make them bold for readability.
892 for( c = comment; *c; ++c, ++offset ) {
894 pattern_start = offset;
897 else if( pattern_start >= 0 && ( *c < 'a' || *c > 'z' ) && ( *c < 'A' || *c > 'Z' ) && ( *c < '0' || *c > '9' ) && ( *c != '_' ) ) {
898 if( *c == ':' && spaces <= 1 ) {
899 GtkTextIter iter_start, iter_end;
901 gtk_text_buffer_get_iter_at_offset( buffer, &iter_start, pattern_start );
902 gtk_text_buffer_get_iter_at_offset( buffer, &iter_end, offset );
903 gtk_text_buffer_apply_tag_by_name( buffer, "bold", &iter_start, &iter_end );
914 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
915 if ( eclass == g_current_flags ) {
919 g_current_flags = eclass;
921 unsigned int spawnflag_count = 0;
924 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
925 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
927 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
928 spawn_table[spawnflag_count] = i;
934 // disable all remaining boxes
935 // NOTE: these boxes might not even be on display
937 for ( int i = 0; i < g_spawnflag_count; ++i )
939 auto widget = ui::CheckButton::from(g_entitySpawnflagsCheck[i]);
940 auto label = ui::Label::from(gtk_bin_get_child(GTK_BIN(widget)));
944 g_spawnflagsTable.remove(widget);
948 g_spawnflag_count = spawnflag_count;
951 for (unsigned int i = 0; (int) i < g_spawnflag_count; ++i)
953 auto widget = ui::CheckButton::from(g_entitySpawnflagsCheck[i] );
956 StringOutputStream str( 16 );
957 str << LowerCase( eclass->flagnames[spawn_table[i]] );
959 g_spawnflagsTable.attach(widget, {i % 4, i % 4 + 1, i / 4, i / 4 + 1}, {GTK_FILL, GTK_FILL});
962 auto label = ui::Label::from(gtk_bin_get_child(GTK_BIN(widget)) );
963 label.text(str.c_str());
968 void EntityClassList_selectEntityClass( EntityClass* eclass ){
969 auto model = g_entlist_store;
971 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
974 gtk_tree_model_get( model, &iter, 0, &text, -1 );
975 if ( strcmp( text, eclass->name() ) == 0 ) {
976 auto view = ui::TreeView(g_entityClassList);
977 auto path = gtk_tree_model_get_path( model, &iter );
978 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
979 if ( gtk_widget_get_realized( view ) ) {
980 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
982 gtk_tree_path_free( path );
989 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
990 auto row = DialogRow_new( name, attribute.getWidget() );
991 DialogVBox_packRow( ui::VBox(g_attributeBox), row );
995 template<typename Attribute>
996 class StatelessAttributeCreator
999 static EntityAttribute* create( const char* name ){
1000 return new Attribute( name );
1004 class EntityAttributeFactory
1006 typedef EntityAttribute* ( *CreateFunc )( const char* name );
1007 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
1008 Creators m_creators;
1010 EntityAttributeFactory(){
1011 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
1012 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<ColorAttribute>::create ) );
1013 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
1014 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
1015 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
1016 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
1017 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
1018 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
1019 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
1020 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
1021 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
1022 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
1023 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
1025 EntityAttribute* create( const char* type, const char* name ){
1026 Creators::iterator i = m_creators.find( type );
1027 if ( i != m_creators.end() ) {
1028 return ( *i ).second( name );
1030 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
1031 if ( listType != 0 ) {
1032 return new ListAttribute( name, *listType );
1038 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
1040 void EntityInspector_setEntityClass( EntityClass *eclass ){
1041 EntityClassList_selectEntityClass( eclass );
1042 SurfaceFlags_setEntityClass( eclass );
1044 if ( eclass != g_current_attributes ) {
1045 g_current_attributes = eclass;
1047 container_remove_all( g_attributeBox );
1048 GlobalEntityAttributes_clear();
1050 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
1052 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
1053 if ( attribute != 0 ) {
1054 g_entityAttributes.push_back( attribute );
1055 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
1061 void EntityInspector_updateSpawnflags(){
1063 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
1064 for ( int i = 0; i < g_spawnflag_count; ++i )
1066 int v = !!( f & ( 1 << spawn_table[i] ) );
1068 toggle_button_set_active_no_signal( ui::ToggleButton::from( g_entitySpawnflagsCheck[i] ), v );
1072 // take care of the remaining ones
1073 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1075 toggle_button_set_active_no_signal( ui::ToggleButton::from( g_entitySpawnflagsCheck[i] ), FALSE );
1080 void EntityInspector_applySpawnflags(){
1085 for ( i = 0; i < g_spawnflag_count; ++i )
1087 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1088 f |= v << spawn_table[i];
1091 sprintf( sz, "%i", f );
1092 const char* value = ( f == 0 ) ? "" : sz;
1095 StringOutputStream command;
1096 command << "entitySetFlags -flags " << f;
1097 UndoableCommand undo( "entitySetSpawnflags" );
1099 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1104 void EntityInspector_updateKeyValues(){
1105 g_selectedKeyValues.clear();
1106 g_selectedDefaultKeyValues.clear();
1107 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1109 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1111 EntityInspector_updateSpawnflags();
1113 ui::ListStore store = g_entprops_store;
1115 // save current key/val pair around filling epair box
1116 // row_select wipes it and sets to first in list
1117 CopiedString strKey( g_entityKeyEntry.text() );
1118 CopiedString strVal( g_entityValueEntry.text() );
1121 // Walk through list and add pairs
1122 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1124 StringOutputStream key( 64 );
1125 key << ( *i ).first.c_str();
1126 StringOutputStream value( 64 );
1127 value << ( *i ).second.c_str();
1128 store.append(0, key.c_str(), 1, value.c_str());
1131 g_entityKeyEntry.text( strKey.c_str() );
1132 g_entityValueEntry.text( strVal.c_str() );
1134 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1140 class EntityInspectorDraw
1142 IdleDraw m_idleDraw;
1144 EntityInspectorDraw() : m_idleDraw( makeCallbackF(EntityInspector_updateKeyValues) ){
1147 m_idleDraw.queueDraw();
1151 EntityInspectorDraw g_EntityInspectorDraw;
1154 void EntityInspector_keyValueChanged(){
1155 g_EntityInspectorDraw.queueDraw();
1157 void EntityInspector_selectionChanged( const Selectable& ){
1158 EntityInspector_keyValueChanged();
1161 // Creates a new entity based on the currently selected brush and entity type.
1163 void EntityClassList_createEntity(){
1164 auto view = g_entityClassList;
1166 // find out what type of entity we are trying to create
1167 GtkTreeModel* model;
1169 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( g_entityClassList ), &model, &iter ) == FALSE ) {
1170 ui::alert( view.window(), "You must have a selected class to create an entity", "info" );
1175 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1178 StringOutputStream command;
1179 command << "entityCreate -class " << text;
1181 UndoableCommand undo( command.c_str() );
1183 Entity_createFromSelection( text, g_vector3_identity );
1188 void EntityInspector_applyKeyValue(){
1189 // Get current selection text
1190 StringOutputStream key( 64 );
1191 key << gtk_entry_get_text( g_entityKeyEntry );
1192 StringOutputStream value( 64 );
1193 value << gtk_entry_get_text( g_entityValueEntry );
1196 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1197 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1198 ui::alert( g_entityKeyEntry.window(), "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1203 // RR2DO2: we don't want spaces in entity keys
1204 if ( strstr( key.c_str(), " " ) ) {
1205 ui::alert( g_entityKeyEntry.window(), "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1209 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1210 StringOutputStream command;
1211 command << "entitySetClass -class " << value.c_str();
1212 UndoableCommand undo( command.c_str() );
1213 Scene_EntitySetClassname_Selected( value.c_str() );
1217 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1221 void EntityInspector_clearKeyValue(){
1222 // Get current selection text
1223 StringOutputStream key( 64 );
1224 key << gtk_entry_get_text( g_entityKeyEntry );
1226 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1227 StringOutputStream command;
1228 command << "entityDeleteKey -key " << key.c_str();
1229 UndoableCommand undo( command.c_str() );
1230 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1234 static gint EntityInspector_clearKeyValueKB( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1235 if ( event->keyval == GDK_Delete ) {
1236 EntityInspector_clearKeyValue();
1242 void EntityInspector_clearAllKeyValues(){
1243 UndoableCommand undo( "entityClear" );
1245 // remove all keys except classname
1246 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1248 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1249 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1254 // =============================================================================
1257 static void EntityClassList_selection_changed( ui::TreeSelection selection, gpointer data ){
1258 GtkTreeModel* model;
1259 GtkTreeIter selected;
1260 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1261 EntityClass* eclass;
1262 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1263 if ( eclass != 0 ) {
1264 SetComment( eclass );
1269 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1270 if ( event->type == GDK_2BUTTON_PRESS ) {
1271 EntityClassList_createEntity();
1277 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1278 if ( event->keyval == GDK_KEY_Return ) {
1279 EntityClassList_createEntity();
1283 // select the entity that starts with the key pressed
1285 unsigned int code = gdk_keyval_to_upper( event->keyval );
1286 if ( code <= 'Z' && code >= 'A' && event->state == 0 ) {
1287 auto view = ui::TreeView(g_entityClassList);
1288 GtkTreeModel* model;
1290 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1291 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1292 gtk_tree_model_get_iter_first( model, &iter );
1295 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1298 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1300 if ( toupper( text[0] ) == (int)code ) {
1301 auto path = gtk_tree_model_get_path( model, &iter );
1302 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1303 if ( gtk_widget_get_realized( view ) ) {
1304 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1306 gtk_tree_path_free( path );
1312 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1313 gtk_tree_model_get_iter_first( model, &iter );
1323 static void EntityProperties_selection_changed( ui::TreeSelection selection, gpointer data ){
1324 // find out what type of entity we are trying to create
1325 GtkTreeModel* model;
1327 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1333 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1335 g_entityKeyEntry.text( key );
1336 g_entityValueEntry.text( val );
1342 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1343 EntityInspector_applySpawnflags();
1346 static gint EntityEntry_keypress( ui::Entry widget, GdkEventKey* event, gpointer data ){
1347 if ( event->keyval == GDK_KEY_Return ) {
1348 if ( widget._handle == g_entityKeyEntry._handle ) {
1349 // g_entityValueEntry.text( "" );
1350 gtk_window_set_focus( widget.window(), g_entityValueEntry );
1354 EntityInspector_applyKeyValue();
1358 if ( event->keyval == GDK_Tab ) {
1359 if ( widget._handle == g_entityKeyEntry._handle ) {
1360 gtk_window_set_focus( widget.window(), g_entityValueEntry );
1364 gtk_window_set_focus( widget.window(), g_entityKeyEntry );
1368 if ( event->keyval == GDK_Escape ) {
1369 // gtk_window_set_focus( widget.window(), NULL );
1376 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1377 g_entitysplit0_position = gtk_paned_get_position( GTK_PANED( g_entity_split0 ) );
1378 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1379 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1380 g_entityInspector_windowConstructed = false;
1381 GlobalEntityAttributes_clear();
1384 static gint EntityInspector_hideWindowKB( GtkWidget* widget, GdkEventKey* event, gpointer data ){
1385 //if ( event->keyval == GDK_Escape && GTK_WIDGET_VISIBLE( GTK_WIDGET( widget ) ) ) {
1386 if ( event->keyval == GDK_Escape ) {
1387 //GroupDialog_showPage( g_page_entity );
1388 gtk_widget_hide( GTK_WIDGET( GroupDialog_getWindow() ) );
1391 /* this doesn't work, if tab is bound (func is not called then) */
1392 if ( event->keyval == GDK_Tab ) {
1393 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityKeyEntry ) );
1399 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1400 auto vbox = ui::VBox( FALSE, 2 );
1402 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1404 g_signal_connect( G_OBJECT( toplevel ), "key_press_event", G_CALLBACK( EntityInspector_hideWindowKB ), 0 );
1405 vbox.connect( "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1408 auto split1 = ui::VPaned(ui::New);
1409 vbox.pack_start( split1, TRUE, TRUE, 0 );
1412 g_entity_split1 = split1;
1415 ui::Widget split2 = ui::VPaned(ui::New);
1416 //gtk_paned_add1( GTK_PANED( split1 ), split2 );
1417 gtk_paned_pack1( GTK_PANED( split1 ), split2, FALSE, FALSE );
1420 g_entity_split2 = split2;
1424 auto scr = ui::ScrolledWindow(ui::New);
1426 //gtk_paned_add1( GTK_PANED( split2 ), scr );
1427 gtk_paned_pack1( GTK_PANED( split2 ), scr, FALSE, FALSE );
1428 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1429 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1432 ui::ListStore store = ui::ListStore::from(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
1434 auto view = ui::TreeView( ui::TreeModel::from( store._handle ));
1435 // gtk_tree_view_set_enable_search(view, FALSE );
1436 gtk_tree_view_set_headers_visible( view, FALSE );
1437 view.connect( "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1438 view.connect( "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1441 auto renderer = ui::CellRendererText(ui::New);
1442 auto column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1443 gtk_tree_view_append_column( view, column );
1447 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection( view ));
1448 selection.connect( "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1456 g_entityClassList = view;
1457 g_entlist_store = store;
1462 auto scr = ui::ScrolledWindow(ui::New);
1464 //gtk_paned_add2( GTK_PANED( split2 ), scr );
1465 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1466 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1467 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1470 auto text = ui::TextView(ui::New);
1471 text.dimensions(0, -1); // allow shrinking
1472 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1473 gtk_text_view_set_editable( text, FALSE );
1476 g_entityClassComment = text;
1478 GtkTextBuffer *buffer = gtk_text_view_get_buffer( text );
1479 gtk_text_buffer_create_tag( buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL );
1486 ui::Widget split0 = ui::VPaned(ui::New);
1487 //gtk_paned_add2( GTK_PANED( split1 ), split0 );
1488 gtk_paned_pack2( GTK_PANED( split1 ), split0, FALSE, FALSE );
1490 g_entity_split0 = split0;
1493 auto vbox2 = ui::VBox( FALSE, 2 );
1495 gtk_paned_pack1( GTK_PANED( split0 ), vbox2, FALSE, FALSE );
1498 // Spawnflags (4 colums wide max, or window gets too wide.)
1499 auto table = ui::Table( 4, 4, FALSE );
1500 vbox2.pack_start( table, FALSE, TRUE, 0 );
1503 g_spawnflagsTable = table;
1505 for ( int i = 0; i < MAX_FLAGS; i++ )
1507 auto check = ui::CheckButton( "" );
1509 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( check.connect( "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1510 g_entitySpawnflagsCheck[i] = check;
1516 auto scr = ui::ScrolledWindow(ui::New);
1518 vbox2.pack_start( scr, TRUE, TRUE, 0 );
1519 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1520 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1523 ui::ListStore store = ui::ListStore::from(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ));
1525 auto view = ui::TreeView(ui::TreeModel::from(store._handle));
1526 gtk_tree_view_set_enable_search(view, FALSE );
1527 gtk_tree_view_set_headers_visible(view, FALSE );
1528 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityInspector_clearKeyValueKB ), 0 );
1531 auto renderer = ui::CellRendererText(ui::New);
1532 auto column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1533 gtk_tree_view_append_column(view, column );
1537 auto renderer = ui::CellRendererText(ui::New);
1538 auto column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1539 gtk_tree_view_append_column(view, column );
1543 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(view));
1544 selection.connect( "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1553 g_entprops_store = store;
1559 auto table = ui::Table( 2, 2, FALSE );
1561 vbox2.pack_start( table, FALSE, TRUE, 0 );
1562 gtk_table_set_row_spacings( table, 3 );
1563 gtk_table_set_col_spacings( table, 5 );
1566 auto entry = ui::Entry(ui::New);
1568 table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
1569 gtk_widget_set_events( entry , GDK_KEY_PRESS_MASK );
1570 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1571 g_entityKeyEntry = entry;
1575 auto entry = ui::Entry(ui::New);
1577 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
1578 gtk_widget_set_events( entry , GDK_KEY_PRESS_MASK );
1579 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1580 g_entityValueEntry = entry;
1584 auto label = ui::Label( "Value" );
1586 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
1587 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1591 auto label = ui::Label( "Key" );
1593 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
1594 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1599 auto hbox = ui::HBox( TRUE, 4 );
1601 vbox2.pack_start( hbox, FALSE, TRUE, 0 );
1604 auto button = ui::Button( "Clear All" );
1606 button.connect( "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1607 hbox.pack_start( button, TRUE, TRUE, 0 );
1610 auto button = ui::Button( "Delete Key" );
1612 button.connect( "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1613 hbox.pack_start( button, TRUE, TRUE, 0 );
1619 auto scr = ui::ScrolledWindow(ui::New);
1621 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1623 auto viewport = ui::Container::from(gtk_viewport_new( 0, 0 ));
1625 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1627 g_attributeBox = ui::VBox( FALSE, 2 );
1628 g_attributeBox.show();
1630 viewport.add(g_attributeBox);
1632 gtk_paned_pack2( GTK_PANED( split0 ), scr, FALSE, FALSE );
1639 // show the sliders in any case //no need, gtk can care
1640 /*if ( g_entitysplit2_position < 22 ) {
1641 g_entitysplit2_position = 22;
1643 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1644 /*if ( ( g_entitysplit1_position - g_entitysplit2_position ) < 27 ) {
1645 g_entitysplit1_position = g_entitysplit2_position + 27;
1647 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1648 gtk_paned_set_position( GTK_PANED( g_entity_split0 ), g_entitysplit0_position );
1651 g_entityInspector_windowConstructed = true;
1652 EntityClassList_fill();
1654 typedef FreeCaller<void(const Selectable&), EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1655 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1656 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1659 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1664 class EntityInspector : public ModuleObserver
1666 std::size_t m_unrealised;
1668 EntityInspector() : m_unrealised( 1 ){
1671 if ( --m_unrealised == 0 ) {
1672 if ( g_entityInspector_windowConstructed ) {
1673 //globalOutputStream() << "Entity Inspector: realise\n";
1674 EntityClassList_fill();
1679 if ( ++m_unrealised == 1 ) {
1680 if ( g_entityInspector_windowConstructed ) {
1681 //globalOutputStream() << "Entity Inspector: unrealise\n";
1682 EntityClassList_clear();
1688 EntityInspector g_EntityInspector;
1690 #include "preferencesystem.h"
1691 #include "stringio.h"
1693 void EntityInspector_construct(){
1694 GlobalEntityClassManager().attach( g_EntityInspector );
1696 GlobalPreferenceSystem().registerPreference( "EntitySplit0", make_property_string( g_entitysplit0_position ) );
1697 GlobalPreferenceSystem().registerPreference( "EntitySplit1", make_property_string( g_entitysplit1_position ) );
1698 GlobalPreferenceSystem().registerPreference( "EntitySplit2", make_property_string( g_entitysplit2_position ) );
1702 void EntityInspector_destroy(){
1703 GlobalEntityClassManager().detach( g_EntityInspector );
1706 const char *EntityInspector_getCurrentKey(){
1707 if ( !GroupDialog_isShown() ) {
1710 if ( GroupDialog_getPage() != g_page_entity ) {
1713 return gtk_entry_get_text( g_entityKeyEntry );