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>
40 #include "eclasslib.h"
42 #include "generic/callback.h"
44 #include "stream/stringstream.h"
45 #include "moduleobserver.h"
49 #include "gtkutil/accelerator.h"
50 #include "gtkutil/dialog.h"
51 #include "gtkutil/filechooser.h"
52 #include "gtkutil/messagebox.h"
53 #include "gtkutil/nonmodal.h"
54 #include "gtkutil/button.h"
55 #include "gtkutil/entry.h"
56 #include "gtkutil/container.h"
62 #include "mainframe.h"
63 #include "textureentry.h"
64 #include "groupdialog.h"
68 ui::Entry numeric_entry_new(){
69 auto entry = ui::Entry(ui::New);
71 entry.dimensions(64, -1);
77 typedef std::map<CopiedString, CopiedString> KeyValues;
78 KeyValues g_selectedKeyValues;
79 KeyValues g_selectedDefaultKeyValues;
82 const char* SelectedEntity_getValueForKey( const char* key ){
84 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
85 if ( i != g_selectedKeyValues.end() ) {
86 return ( *i ).second.c_str();
90 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
91 if ( i != g_selectedDefaultKeyValues.end() ) {
92 return ( *i ).second.c_str();
98 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
99 StringOutputStream command( 256 );
100 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
101 UndoableCommand undo( command.c_str() );
102 Scene_EntitySetKeyValue_Selected( key, value );
105 class EntityAttribute
108 virtual ~EntityAttribute() = default;
109 virtual ui::Widget getWidget() const = 0;
110 virtual void update() = 0;
111 virtual void release() = 0;
114 class BooleanAttribute : public EntityAttribute
117 ui::CheckButton m_check;
119 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
124 BooleanAttribute( const char* key ) :
127 auto check = ui::CheckButton(ui::New);
132 guint handler = check.connect( "toggled", G_CALLBACK( toggled ), this );
133 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
137 ui::Widget getWidget() const {
144 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_check.active() ? "1" : "" );
146 typedef MemberCaller<BooleanAttribute, void(), &BooleanAttribute::apply> ApplyCaller;
149 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
150 if ( !string_empty( value ) ) {
151 toggle_button_set_active_no_signal( m_check, atoi( value ) != 0 );
155 toggle_button_set_active_no_signal( m_check, false );
158 typedef MemberCaller<BooleanAttribute, void(), &BooleanAttribute::update> UpdateCaller;
162 class StringAttribute : public EntityAttribute
166 NonModalEntry m_nonModal;
168 StringAttribute( const char* key ) :
171 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
172 auto entry = ui::Entry(ui::New);
174 entry.dimensions(50, -1);
177 m_nonModal.connect( m_entry );
179 ui::Widget getWidget() const {
182 ui::Entry getEntry() const {
190 StringOutputStream value( 64 );
191 value << m_entry.text();
192 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
194 typedef MemberCaller<StringAttribute, void(), &StringAttribute::apply> ApplyCaller;
197 StringOutputStream value( 64 );
198 value << SelectedEntity_getValueForKey( m_key.c_str() );
199 m_entry.text(value.c_str());
201 typedef MemberCaller<StringAttribute, void(), &StringAttribute::update> UpdateCaller;
204 class ShaderAttribute : public StringAttribute
207 ShaderAttribute( const char* key ) : StringAttribute( key ){
208 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
213 class ColorAttribute : public EntityAttribute
216 BrowsedPathEntry m_entry;
217 NonModalEntry m_nonModal;
219 ColorAttribute( const char* key ) :
221 m_entry( BrowseCaller( *this ) ),
222 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
223 m_nonModal.connect( m_entry.m_entry.m_entry );
228 ui::Widget getWidget() const {
229 return ui::Widget( m_entry.m_entry.m_frame );
232 StringOutputStream value( 64 );
233 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
234 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
236 typedef MemberCaller<ColorAttribute, void(), &ColorAttribute::apply> ApplyCaller;
238 StringOutputStream value( 64 );
239 value << SelectedEntity_getValueForKey( m_key.c_str() );
240 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
242 typedef MemberCaller<ColorAttribute, void(), &ColorAttribute::update> UpdateCaller;
243 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
244 //const char *filename = misc_model_dialog( gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) );
246 /* hijack BrowsedPathEntry to call colour chooser */
249 // if ( filename != 0 ) {
250 // setPath( filename );
255 typedef MemberCaller<ColorAttribute, void(const BrowsedPathEntry::SetPathCallback&), &ColorAttribute::browse> BrowseCaller;
259 class ModelAttribute : public EntityAttribute
262 BrowsedPathEntry m_entry;
263 NonModalEntry m_nonModal;
265 ModelAttribute( const char* key ) :
267 m_entry( BrowseCaller( *this ) ),
268 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
269 m_nonModal.connect( m_entry.m_entry.m_entry );
274 ui::Widget getWidget() const {
275 return m_entry.m_entry.m_frame;
278 StringOutputStream value( 64 );
279 value << m_entry.m_entry.m_entry.text();
280 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
282 typedef MemberCaller<ModelAttribute, void(), &ModelAttribute::apply> ApplyCaller;
284 StringOutputStream value( 64 );
285 value << SelectedEntity_getValueForKey( m_key.c_str() );
286 m_entry.m_entry.m_entry.text(value.c_str());
288 typedef MemberCaller<ModelAttribute, void(), &ModelAttribute::update> UpdateCaller;
289 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
290 const char *filename = misc_model_dialog( m_entry.m_entry.m_frame.window() );
292 if ( filename != 0 ) {
297 typedef MemberCaller<ModelAttribute, void(const BrowsedPathEntry::SetPathCallback&), &ModelAttribute::browse> BrowseCaller;
300 const char* browse_sound( ui::Widget parent ){
301 StringOutputStream buffer( 1024 );
303 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
305 if ( !file_readable( buffer.c_str() ) ) {
308 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
311 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
312 if ( filename != 0 ) {
313 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
314 if ( relative == filename ) {
315 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
322 class SoundAttribute : public EntityAttribute
325 BrowsedPathEntry m_entry;
326 NonModalEntry m_nonModal;
328 SoundAttribute( const char* key ) :
330 m_entry( BrowseCaller( *this ) ),
331 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
332 m_nonModal.connect( m_entry.m_entry.m_entry );
337 ui::Widget getWidget() const {
338 return ui::Widget(m_entry.m_entry.m_frame );
341 StringOutputStream value( 64 );
342 value << m_entry.m_entry.m_entry.text();
343 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
345 typedef MemberCaller<SoundAttribute, void(), &SoundAttribute::apply> ApplyCaller;
347 StringOutputStream value( 64 );
348 value << SelectedEntity_getValueForKey( m_key.c_str() );
349 m_entry.m_entry.m_entry.text(value.c_str());
351 typedef MemberCaller<SoundAttribute, void(), &SoundAttribute::update> UpdateCaller;
352 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
353 const char *filename = browse_sound( m_entry.m_entry.m_frame.window() );
355 if ( filename != 0 ) {
360 typedef MemberCaller<SoundAttribute, void(const BrowsedPathEntry::SetPathCallback&), &SoundAttribute::browse> BrowseCaller;
363 inline double angle_normalised( double angle ){
364 return float_mod( angle, 360.0 );
367 class AngleAttribute : public EntityAttribute
371 NonModalEntry m_nonModal;
373 AngleAttribute( const char* key ) :
376 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
377 auto entry = numeric_entry_new();
379 m_nonModal.connect( m_entry );
384 ui::Widget getWidget() const {
385 return ui::Widget(m_entry );
388 StringOutputStream angle( 32 );
389 angle << angle_normalised( entry_get_float( m_entry ) );
390 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
392 typedef MemberCaller<AngleAttribute, void(), &AngleAttribute::apply> ApplyCaller;
395 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
396 if ( !string_empty( value ) ) {
397 StringOutputStream angle( 32 );
398 angle << angle_normalised( atof( value ) );
399 m_entry.text(angle.c_str());
406 typedef MemberCaller<AngleAttribute, void(), &AngleAttribute::update> UpdateCaller;
411 typedef const char* String;
412 const String buttons[] = { "up", "down", "z-axis" };
415 class DirectionAttribute : public EntityAttribute
419 NonModalEntry m_nonModal;
421 NonModalRadio m_nonModalRadio;
422 ui::HBox m_hbox{ui::null};
424 DirectionAttribute( const char* key ) :
427 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
428 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
429 m_nonModalRadio( ApplyRadioCaller( *this ) ){
430 auto entry = numeric_entry_new();
432 m_nonModal.connect( m_entry );
434 m_nonModalRadio.connect( m_radio.m_radio );
436 m_hbox = ui::HBox( FALSE, 4 );
439 m_hbox.pack_start( m_radio.m_hbox, TRUE, TRUE, 0 );
440 m_hbox.pack_start( m_entry, TRUE, TRUE, 0 );
445 ui::Widget getWidget() const {
446 return ui::Widget(m_hbox );
449 StringOutputStream angle( 32 );
450 angle << angle_normalised( entry_get_float( m_entry ) );
451 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
453 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::apply> ApplyCaller;
456 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
457 if ( !string_empty( value ) ) {
458 float f = float(atof( value ) );
460 gtk_widget_set_sensitive( m_entry , FALSE );
461 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
464 else if ( f == -2 ) {
465 gtk_widget_set_sensitive( m_entry , FALSE );
466 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
471 gtk_widget_set_sensitive( m_entry , TRUE );
472 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
473 StringOutputStream angle( 32 );
474 angle << angle_normalised( f );
475 m_entry.text(angle.c_str());
483 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::update> UpdateCaller;
486 int index = radio_button_get_active( m_radio.m_radio );
488 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
490 else if ( index == 1 ) {
491 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
493 else if ( index == 2 ) {
497 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::applyRadio> ApplyRadioCaller;
507 AnglesEntry() : m_roll( ui::null ), m_pitch( ui::null ), m_yaw( ui::null ){
511 typedef BasicVector3<double> DoubleVector3;
513 class AnglesAttribute : public EntityAttribute
516 AnglesEntry m_angles;
517 NonModalEntry m_nonModal;
520 AnglesAttribute( const char* key ) :
522 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
523 m_hbox(ui::HBox( TRUE, 4 ))
527 auto entry = numeric_entry_new();
528 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
529 m_angles.m_pitch = entry;
530 m_nonModal.connect( m_angles.m_pitch );
533 auto entry = numeric_entry_new();
534 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
535 m_angles.m_yaw = entry;
536 m_nonModal.connect( m_angles.m_yaw );
539 auto entry = numeric_entry_new();
540 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
541 m_angles.m_roll = entry;
542 m_nonModal.connect( m_angles.m_roll );
548 ui::Widget getWidget() const {
549 return ui::Widget(m_hbox );
552 StringOutputStream angles( 64 );
553 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
554 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
555 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
556 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
558 typedef MemberCaller<AnglesAttribute, void(), &AnglesAttribute::apply> ApplyCaller;
561 StringOutputStream angle( 32 );
562 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
563 if ( !string_empty( value ) ) {
564 DoubleVector3 pitch_yaw_roll;
565 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
566 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
569 angle << angle_normalised( pitch_yaw_roll.x() );
570 m_angles.m_pitch.text(angle.c_str());
573 angle << angle_normalised( pitch_yaw_roll.y() );
574 m_angles.m_yaw.text(angle.c_str());
577 angle << angle_normalised( pitch_yaw_roll.z() );
578 m_angles.m_roll.text(angle.c_str());
583 m_angles.m_pitch.text("0");
584 m_angles.m_yaw.text("0");
585 m_angles.m_roll.text("0");
588 typedef MemberCaller<AnglesAttribute, void(), &AnglesAttribute::update> UpdateCaller;
597 Vector3Entry() : m_x( ui::null ), m_y( ui::null ), m_z( ui::null ){
601 class Vector3Attribute : public EntityAttribute
604 Vector3Entry m_vector3;
605 NonModalEntry m_nonModal;
606 ui::Box m_hbox{ui::null};
608 Vector3Attribute( const char* key ) :
610 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
611 m_hbox = ui::HBox( TRUE, 4 );
614 auto entry = numeric_entry_new();
615 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
616 m_vector3.m_x = entry;
617 m_nonModal.connect( m_vector3.m_x );
620 auto entry = numeric_entry_new();
621 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
622 m_vector3.m_y = entry;
623 m_nonModal.connect( m_vector3.m_y );
626 auto entry = numeric_entry_new();
627 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
628 m_vector3.m_z = entry;
629 m_nonModal.connect( m_vector3.m_z );
635 ui::Widget getWidget() const {
636 return ui::Widget(m_hbox );
639 StringOutputStream vector3( 64 );
640 vector3 << entry_get_float( m_vector3.m_x )
641 << " " << entry_get_float( m_vector3.m_y )
642 << " " << entry_get_float( m_vector3.m_z );
643 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
645 typedef MemberCaller<Vector3Attribute, void(), &Vector3Attribute::apply> ApplyCaller;
648 StringOutputStream buffer( 32 );
649 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
650 if ( !string_empty( value ) ) {
652 if ( !string_parse_vector3( value, x_y_z ) ) {
653 x_y_z = DoubleVector3( 0, 0, 0 );
657 m_vector3.m_x.text(buffer.c_str());
661 m_vector3.m_y.text(buffer.c_str());
665 m_vector3.m_z.text(buffer.c_str());
670 m_vector3.m_x.text("0");
671 m_vector3.m_y.text("0");
672 m_vector3.m_z.text("0");
675 typedef MemberCaller<Vector3Attribute, void(), &Vector3Attribute::update> UpdateCaller;
678 class NonModalComboBox
680 Callback<void()> m_changed;
681 guint m_changedHandler;
683 static gboolean changed( ui::ComboBox widget, NonModalComboBox* self ){
689 NonModalComboBox( const Callback<void()>& changed ) : m_changed( changed ), m_changedHandler( 0 ){
691 void connect( ui::ComboBox combo ){
692 m_changedHandler = combo.connect( "changed", G_CALLBACK( changed ), this );
694 void setActive( ui::ComboBox combo, int value ){
695 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
696 gtk_combo_box_set_active( combo, value );
701 class ListAttribute : public EntityAttribute
704 ui::ComboBox m_combo;
705 NonModalComboBox m_nonModal;
706 const ListAttributeType& m_type;
708 ListAttribute( const char* key, const ListAttributeType& type ) :
711 m_nonModal( ApplyCaller( *this ) ),
713 auto combo = ui::ComboBoxText(ui::New);
715 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
717 gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), ( *i ).first.c_str() );
721 m_nonModal.connect( combo );
728 ui::Widget getWidget() const {
729 return ui::Widget(m_combo );
732 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
734 typedef MemberCaller<ListAttribute, void(), &ListAttribute::apply> ApplyCaller;
737 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
738 ListAttributeType::const_iterator i = m_type.findValue( value );
739 if ( i != m_type.end() ) {
740 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
744 m_nonModal.setActive( m_combo, 0 );
747 typedef MemberCaller<ListAttribute, void(), &ListAttribute::update> UpdateCaller;
753 GtkWidget* g_entity_split0 = 0;
754 ui::Widget g_entity_split1{ui::null};
755 ui::Widget g_entity_split2{ui::null};
756 int g_entitysplit0_position;
757 int g_entitysplit1_position;
758 int g_entitysplit2_position;
760 bool g_entityInspector_windowConstructed = false;
762 ui::TreeView g_entityClassList{ui::null};
763 ui::TextView g_entityClassComment{ui::null};
765 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
767 ui::Entry g_entityKeyEntry{ui::null};
768 ui::Entry g_entityValueEntry{ui::null};
770 GtkToggleButton* g_focusToggleButton;
772 ui::ListStore g_entlist_store{ui::null};
773 ui::ListStore g_entprops_store{ui::null};
774 const EntityClass* g_current_flags = 0;
775 const EntityClass* g_current_comment = 0;
776 const EntityClass* g_current_attributes = 0;
778 // the number of active spawnflags
779 int g_spawnflag_count;
780 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
781 int spawn_table[MAX_FLAGS];
782 // we change the layout depending on how many spawn flags we need to display
783 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
784 ui::Table g_spawnflagsTable{ui::null};
786 ui::VBox g_attributeBox{ui::null};
787 typedef std::vector<EntityAttribute*> EntityAttributes;
788 EntityAttributes g_entityAttributes;
791 void GlobalEntityAttributes_clear(){
792 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
796 g_entityAttributes.clear();
799 class GetKeyValueVisitor : public Entity::Visitor
801 KeyValues& m_keyvalues;
803 GetKeyValueVisitor( KeyValues& keyvalues )
804 : m_keyvalues( keyvalues ){
807 void visit( const char* key, const char* value ){
808 m_keyvalues.insert( KeyValues::value_type( CopiedString( key ), CopiedString( value ) ) );
813 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
814 GetKeyValueVisitor visitor( keyvalues );
816 entity.forEachKeyValue( visitor );
818 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
820 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
822 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
826 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
827 class EntityGetKeyValues : public SelectionSystem::Visitor
829 KeyValues& m_keyvalues;
830 KeyValues& m_defaultValues;
831 mutable std::set<Entity*> m_visited;
833 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
834 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
836 void visit( scene::Instance& instance ) const {
837 Entity* entity = Node_getEntity( instance.path().top() );
838 if ( entity == 0 && instance.path().size() != 1 ) {
839 entity = Node_getEntity( instance.path().parent() );
841 if ( entity != 0 && m_visited.insert( entity ).second ) {
842 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
845 } visitor( keyvalues, defaultValues );
846 GlobalSelectionSystem().foreachSelected( visitor );
849 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
850 KeyValues::iterator i = keyvalues.find( CopiedString( key ) );
851 if ( i != keyvalues.end() ) {
852 return ( *i ).second.c_str();
857 class EntityClassListStoreAppend : public EntityClassVisitor
861 EntityClassListStoreAppend( ui::ListStore store_ ) : store( store_ ){
863 void visit( EntityClass* e ){
864 store.append(0, e->name(), 1, e);
868 void EntityClassList_fill(){
869 EntityClassListStoreAppend append( g_entlist_store );
870 GlobalEntityClassManager().forEach( append );
873 void EntityClassList_clear(){
874 g_entlist_store.clear();
877 void SetComment( EntityClass* eclass ){
878 if ( eclass == g_current_comment ) {
882 g_current_comment = eclass;
884 g_entityClassComment.text(eclass->comments());
886 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
887 //gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
888 const char* comment = eclass->comments(), *c;
889 int offset = 0, pattern_start = -1, spaces = 0;
891 gtk_text_buffer_set_text( buffer, comment, -1 );
893 // Catch patterns like "\nstuff :" used to describe keys and spawnflags, and make them bold for readability.
895 for( c = comment; *c; ++c, ++offset ) {
897 pattern_start = offset;
900 else if( pattern_start >= 0 && ( *c < 'a' || *c > 'z' ) && ( *c < 'A' || *c > 'Z' ) && ( *c < '0' || *c > '9' ) && ( *c != '_' ) ) {
901 if( *c == ':' && spaces <= 1 ) {
902 GtkTextIter iter_start, iter_end;
904 gtk_text_buffer_get_iter_at_offset( buffer, &iter_start, pattern_start );
905 gtk_text_buffer_get_iter_at_offset( buffer, &iter_end, offset );
906 gtk_text_buffer_apply_tag_by_name( buffer, "bold", &iter_start, &iter_end );
917 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
918 if ( eclass == g_current_flags ) {
922 g_current_flags = eclass;
924 unsigned int spawnflag_count = 0;
927 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
928 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
930 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
931 spawn_table[spawnflag_count] = i;
937 // disable all remaining boxes
938 // NOTE: these boxes might not even be on display
940 for ( int i = 0; i < g_spawnflag_count; ++i )
942 auto widget = ui::CheckButton::from(g_entitySpawnflagsCheck[i]);
943 auto label = ui::Label::from(gtk_bin_get_child(GTK_BIN(widget)));
947 g_spawnflagsTable.remove(widget);
951 g_spawnflag_count = spawnflag_count;
954 for (unsigned int i = 0; (int) i < g_spawnflag_count; ++i)
956 auto widget = ui::CheckButton::from(g_entitySpawnflagsCheck[i] );
959 StringOutputStream str( 16 );
960 str << LowerCase( eclass->flagnames[spawn_table[i]] );
962 g_spawnflagsTable.attach(widget, {i % 4, i % 4 + 1, i / 4, i / 4 + 1}, {GTK_FILL, GTK_FILL});
965 auto label = ui::Label::from(gtk_bin_get_child(GTK_BIN(widget)) );
966 label.text(str.c_str());
971 void EntityClassList_selectEntityClass( EntityClass* eclass ){
972 auto model = g_entlist_store;
974 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
977 gtk_tree_model_get( model, &iter, 0, &text, -1 );
978 if ( strcmp( text, eclass->name() ) == 0 ) {
979 auto view = ui::TreeView(g_entityClassList);
980 auto path = gtk_tree_model_get_path( model, &iter );
981 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
982 if ( gtk_widget_get_realized( view ) ) {
983 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
985 gtk_tree_path_free( path );
992 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
993 auto row = DialogRow_new( name, attribute.getWidget() );
994 DialogVBox_packRow( ui::VBox(g_attributeBox), row );
998 template<typename Attribute>
999 class StatelessAttributeCreator
1002 static EntityAttribute* create( const char* name ){
1003 return new Attribute( name );
1007 class EntityAttributeFactory
1009 typedef EntityAttribute* ( *CreateFunc )( const char* name );
1010 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
1011 Creators m_creators;
1013 EntityAttributeFactory(){
1014 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
1015 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<ColorAttribute>::create ) );
1016 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
1017 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
1018 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
1019 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
1020 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
1021 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
1022 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
1023 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
1024 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
1025 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
1026 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
1028 EntityAttribute* create( const char* type, const char* name ){
1029 Creators::iterator i = m_creators.find( type );
1030 if ( i != m_creators.end() ) {
1031 return ( *i ).second( name );
1033 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
1034 if ( listType != 0 ) {
1035 return new ListAttribute( name, *listType );
1041 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
1043 void EntityInspector_setEntityClass( EntityClass *eclass ){
1044 EntityClassList_selectEntityClass( eclass );
1045 SurfaceFlags_setEntityClass( eclass );
1047 if ( eclass != g_current_attributes ) {
1048 g_current_attributes = eclass;
1050 container_remove_all( g_attributeBox );
1051 GlobalEntityAttributes_clear();
1053 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
1055 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
1056 if ( attribute != 0 ) {
1057 g_entityAttributes.push_back( attribute );
1058 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
1064 void EntityInspector_updateSpawnflags(){
1066 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
1067 for ( int i = 0; i < g_spawnflag_count; ++i )
1069 int v = !!( f & ( 1 << spawn_table[i] ) );
1071 toggle_button_set_active_no_signal( ui::ToggleButton::from( g_entitySpawnflagsCheck[i] ), v );
1075 // take care of the remaining ones
1076 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1078 toggle_button_set_active_no_signal( ui::ToggleButton::from( g_entitySpawnflagsCheck[i] ), FALSE );
1083 void EntityInspector_applySpawnflags(){
1088 for ( i = 0; i < g_spawnflag_count; ++i )
1090 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1091 f |= v << spawn_table[i];
1094 sprintf( sz, "%i", f );
1095 const char* value = ( f == 0 ) ? "" : sz;
1098 StringOutputStream command;
1099 command << "entitySetFlags -flags " << f;
1100 UndoableCommand undo( "entitySetSpawnflags" );
1102 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1107 void EntityInspector_updateKeyValues(){
1108 g_selectedKeyValues.clear();
1109 g_selectedDefaultKeyValues.clear();
1110 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1112 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1114 EntityInspector_updateSpawnflags();
1116 ui::ListStore store = g_entprops_store;
1118 // save current key/val pair around filling epair box
1119 // row_select wipes it and sets to first in list
1120 CopiedString strKey( g_entityKeyEntry.text() );
1121 CopiedString strVal( g_entityValueEntry.text() );
1124 // Walk through list and add pairs
1125 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1127 StringOutputStream key( 64 );
1128 key << ( *i ).first.c_str();
1129 StringOutputStream value( 64 );
1130 value << ( *i ).second.c_str();
1131 store.append(0, key.c_str(), 1, value.c_str());
1134 g_entityKeyEntry.text( strKey.c_str() );
1135 g_entityValueEntry.text( strVal.c_str() );
1137 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1143 class EntityInspectorDraw
1145 IdleDraw m_idleDraw;
1147 EntityInspectorDraw() : m_idleDraw( makeCallbackF(EntityInspector_updateKeyValues) ){
1150 m_idleDraw.queueDraw();
1154 EntityInspectorDraw g_EntityInspectorDraw;
1157 void EntityInspector_keyValueChanged(){
1158 g_EntityInspectorDraw.queueDraw();
1160 void EntityInspector_selectionChanged( const Selectable& ){
1161 EntityInspector_keyValueChanged();
1164 // Creates a new entity based on the currently selected brush and entity type.
1166 void EntityClassList_createEntity(){
1167 auto view = g_entityClassList;
1169 // find out what type of entity we are trying to create
1170 GtkTreeModel* model;
1172 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( g_entityClassList ), &model, &iter ) == FALSE ) {
1173 ui::alert( view.window(), "You must have a selected class to create an entity", "info" );
1178 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1181 StringOutputStream command;
1182 command << "entityCreate -class " << text;
1184 UndoableCommand undo( command.c_str() );
1186 Entity_createFromSelection( text, g_vector3_identity );
1191 void EntityInspector_applyKeyValue(){
1192 // Get current selection text
1193 StringOutputStream key( 64 );
1194 key << gtk_entry_get_text( g_entityKeyEntry );
1195 StringOutputStream value( 64 );
1196 value << gtk_entry_get_text( g_entityValueEntry );
1199 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1200 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1201 ui::alert( g_entityKeyEntry.window(), "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1206 // RR2DO2: we don't want spaces in entity keys
1207 if ( strstr( key.c_str(), " " ) ) {
1208 ui::alert( g_entityKeyEntry.window(), "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1212 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1213 StringOutputStream command;
1214 command << "entitySetClass -class " << value.c_str();
1215 UndoableCommand undo( command.c_str() );
1216 Scene_EntitySetClassname_Selected( value.c_str() );
1220 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1224 void EntityInspector_clearKeyValue(){
1225 // Get current selection text
1226 StringOutputStream key( 64 );
1227 key << gtk_entry_get_text( g_entityKeyEntry );
1229 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1230 StringOutputStream command;
1231 command << "entityDeleteKey -key " << key.c_str();
1232 UndoableCommand undo( command.c_str() );
1233 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1237 static gint EntityInspector_clearKeyValueKB( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1238 if ( event->keyval == GDK_KEY_Delete ) {
1239 EntityInspector_clearKeyValue();
1245 void EntityInspector_clearAllKeyValues(){
1246 UndoableCommand undo( "entityClear" );
1248 // remove all keys except classname
1249 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1251 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1252 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1257 // =============================================================================
1260 static void EntityClassList_selection_changed( ui::TreeSelection selection, gpointer data ){
1261 GtkTreeModel* model;
1262 GtkTreeIter selected;
1263 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1264 EntityClass* eclass;
1265 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1266 if ( eclass != 0 ) {
1267 SetComment( eclass );
1272 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1273 if ( event->type == GDK_2BUTTON_PRESS ) {
1274 EntityClassList_createEntity();
1280 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1281 if ( event->keyval == GDK_KEY_Return ) {
1282 EntityClassList_createEntity();
1286 // select the entity that starts with the key pressed
1288 unsigned int code = gdk_keyval_to_upper( event->keyval );
1289 if ( code <= 'Z' && code >= 'A' && event->state == 0 ) {
1290 auto view = ui::TreeView(g_entityClassList);
1291 GtkTreeModel* model;
1293 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1294 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1295 gtk_tree_model_get_iter_first( model, &iter );
1298 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1301 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1303 if ( toupper( text[0] ) == (int)code ) {
1304 auto path = gtk_tree_model_get_path( model, &iter );
1305 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1306 if ( gtk_widget_get_realized( view ) ) {
1307 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1309 gtk_tree_path_free( path );
1315 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1316 gtk_tree_model_get_iter_first( model, &iter );
1326 static void EntityProperties_selection_changed( ui::TreeSelection selection, gpointer data ){
1327 // find out what type of entity we are trying to create
1328 GtkTreeModel* model;
1330 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1336 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1338 g_entityKeyEntry.text( key );
1339 g_entityValueEntry.text( val );
1345 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1346 EntityInspector_applySpawnflags();
1349 static gint EntityEntry_keypress( ui::Entry widget, GdkEventKey* event, gpointer data ){
1350 if ( event->keyval == GDK_KEY_Return ) {
1351 if ( widget._handle == g_entityKeyEntry._handle ) {
1352 // g_entityValueEntry.text( "" );
1353 gtk_window_set_focus( widget.window(), g_entityValueEntry );
1357 EntityInspector_applyKeyValue();
1361 if ( event->keyval == GDK_KEY_Tab ) {
1362 if ( widget._handle == g_entityKeyEntry._handle ) {
1363 gtk_window_set_focus( widget.window(), g_entityValueEntry );
1367 gtk_window_set_focus( widget.window(), g_entityKeyEntry );
1371 if ( event->keyval == GDK_KEY_Escape ) {
1372 // gtk_window_set_focus( widget.window(), NULL );
1379 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1380 g_entitysplit0_position = gtk_paned_get_position( GTK_PANED( g_entity_split0 ) );
1381 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1382 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1383 g_entityInspector_windowConstructed = false;
1384 GlobalEntityAttributes_clear();
1387 static gint EntityInspector_hideWindowKB( GtkWidget* widget, GdkEventKey* event, gpointer data ){
1388 //if ( event->keyval == GDK_KEY_Escape && GTK_WIDGET_VISIBLE( GTK_WIDGET( widget ) ) ) {
1389 if ( event->keyval == GDK_KEY_Escape ) {
1390 //GroupDialog_showPage( g_page_entity );
1391 gtk_widget_hide( GTK_WIDGET( GroupDialog_getWindow() ) );
1394 /* this doesn't work, if tab is bound (func is not called then) */
1395 if ( event->keyval == GDK_KEY_Tab ) {
1396 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityKeyEntry ) );
1402 void EntityInspector_selectTargeting( GtkButton *button, gpointer user_data ){
1403 bool focus = gtk_toggle_button_get_active( g_focusToggleButton );
1404 Select_ConnectedEntities( true, false, focus );
1407 void EntityInspector_selectTargets( GtkButton *button, gpointer user_data ){
1408 bool focus = gtk_toggle_button_get_active( g_focusToggleButton );
1409 Select_ConnectedEntities( false, true, focus );
1412 void EntityInspector_selectConnected( GtkButton *button, gpointer user_data ){
1413 bool focus = gtk_toggle_button_get_active( g_focusToggleButton );
1414 Select_ConnectedEntities( true, true, focus );
1417 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1418 auto vbox = ui::VBox( FALSE, 2 );
1420 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1422 g_signal_connect( G_OBJECT( toplevel ), "key_press_event", G_CALLBACK( EntityInspector_hideWindowKB ), 0 );
1423 vbox.connect( "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1426 auto split1 = ui::VPaned(ui::New);
1427 vbox.pack_start( split1, TRUE, TRUE, 0 );
1430 g_entity_split1 = split1;
1433 ui::Widget split2 = ui::VPaned(ui::New);
1434 //gtk_paned_add1( GTK_PANED( split1 ), split2 );
1435 gtk_paned_pack1( GTK_PANED( split1 ), split2, FALSE, FALSE );
1438 g_entity_split2 = split2;
1442 auto scr = ui::ScrolledWindow(ui::New);
1444 //gtk_paned_add1( GTK_PANED( split2 ), scr );
1445 gtk_paned_pack1( GTK_PANED( split2 ), scr, FALSE, FALSE );
1446 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1447 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1450 ui::ListStore store = ui::ListStore::from(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
1452 auto view = ui::TreeView( ui::TreeModel::from( store._handle ));
1453 // gtk_tree_view_set_enable_search(view, FALSE );
1454 gtk_tree_view_set_headers_visible( view, FALSE );
1455 view.connect( "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1456 view.connect( "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1459 auto renderer = ui::CellRendererText(ui::New);
1460 auto column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1461 gtk_tree_view_append_column( view, column );
1465 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection( view ));
1466 selection.connect( "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1474 g_entityClassList = view;
1475 g_entlist_store = store;
1480 auto scr = ui::ScrolledWindow(ui::New);
1482 //gtk_paned_add2( GTK_PANED( split2 ), scr );
1483 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1484 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1485 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1488 auto text = ui::TextView(ui::New);
1489 text.dimensions(0, -1); // allow shrinking
1490 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1491 gtk_text_view_set_editable( text, FALSE );
1494 g_entityClassComment = text;
1496 GtkTextBuffer *buffer = gtk_text_view_get_buffer( text );
1497 gtk_text_buffer_create_tag( buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL );
1504 ui::Widget split0 = ui::VPaned(ui::New);
1505 //gtk_paned_add2( GTK_PANED( split1 ), split0 );
1506 gtk_paned_pack2( GTK_PANED( split1 ), split0, FALSE, FALSE );
1508 g_entity_split0 = split0;
1511 auto vbox2 = ui::VBox( FALSE, 2 );
1513 gtk_paned_pack1( GTK_PANED( split0 ), vbox2, FALSE, FALSE );
1516 // Spawnflags (4 colums wide max, or window gets too wide.)
1517 auto table = ui::Table( 4, 4, FALSE );
1518 vbox2.pack_start( table, FALSE, TRUE, 0 );
1521 g_spawnflagsTable = table;
1523 for ( int i = 0; i < MAX_FLAGS; i++ )
1525 auto check = ui::CheckButton( "" );
1527 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( check.connect( "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1528 g_entitySpawnflagsCheck[i] = check;
1534 auto scr = ui::ScrolledWindow(ui::New);
1536 vbox2.pack_start( scr, TRUE, TRUE, 0 );
1537 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1538 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1541 ui::ListStore store = ui::ListStore::from(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ));
1543 auto view = ui::TreeView(ui::TreeModel::from(store._handle));
1544 gtk_tree_view_set_enable_search(view, FALSE );
1545 gtk_tree_view_set_headers_visible(view, FALSE );
1546 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityInspector_clearKeyValueKB ), 0 );
1549 auto renderer = ui::CellRendererText(ui::New);
1550 auto column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1551 gtk_tree_view_append_column(view, column );
1555 auto renderer = ui::CellRendererText(ui::New);
1556 auto column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1557 gtk_tree_view_append_column(view, column );
1561 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(view));
1562 selection.connect( "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1571 g_entprops_store = store;
1577 auto table = ui::Table( 2, 2, FALSE );
1579 vbox2.pack_start( table, FALSE, TRUE, 0 );
1580 gtk_table_set_row_spacings( table, 3 );
1581 gtk_table_set_col_spacings( table, 5 );
1584 auto entry = ui::Entry(ui::New);
1586 table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
1587 gtk_widget_set_events( entry , GDK_KEY_PRESS_MASK );
1588 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1589 g_entityKeyEntry = entry;
1593 auto entry = ui::Entry(ui::New);
1595 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
1596 gtk_widget_set_events( entry , GDK_KEY_PRESS_MASK );
1597 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1598 g_entityValueEntry = entry;
1602 auto label = ui::Label( "Value" );
1604 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
1605 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1609 auto label = ui::Label( "Key" );
1611 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
1612 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1617 auto hbox = ui::HBox( FALSE, 4 );
1619 vbox2.pack_start( hbox, FALSE, TRUE, 0 );
1622 auto button = ui::Button( "Clear All" );
1623 #define GARUX_DISABLE_BUTTON_NOFOCUS
1624 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1625 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1626 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1628 button.connect( "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1629 hbox.pack_start( button, TRUE, TRUE, 0 );
1632 auto button = ui::Button( "Delete Key" );
1633 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1634 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1635 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1637 button.connect( "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1638 hbox.pack_start( button, TRUE, TRUE, 0 );
1641 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "<" ) );
1642 gtk_widget_set_tooltip_text( GTK_WIDGET( button ), "Select targeting entities" );
1643 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1644 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1645 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1646 gtk_widget_show( GTK_WIDGET( button ) );
1647 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_selectTargeting ), 0 );
1648 gtk_box_pack_start( hbox, GTK_WIDGET( button ), FALSE, FALSE, 0 );
1651 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( ">" ) );
1652 gtk_widget_set_tooltip_text( GTK_WIDGET( button ), "Select targets" );
1653 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1654 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1655 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1656 gtk_widget_show( GTK_WIDGET( button ) );
1657 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_selectTargets ), 0 );
1658 gtk_box_pack_start( hbox, GTK_WIDGET( button ), FALSE, FALSE, 0 );
1661 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "<->" ) );
1662 gtk_widget_set_tooltip_text( GTK_WIDGET( button ), "Select connected entities" );
1663 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1664 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1665 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1666 gtk_widget_show( GTK_WIDGET( button ) );
1667 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_selectConnected ), 0 );
1668 gtk_box_pack_start( hbox, GTK_WIDGET( button ), FALSE, FALSE, 0 );
1671 GtkWidget* button = gtk_toggle_button_new();
1672 GtkImage* image = GTK_IMAGE( gtk_image_new_from_stock( GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_SMALL_TOOLBAR ) );
1673 gtk_widget_show( GTK_WIDGET( image ) );
1674 gtk_container_add( GTK_CONTAINER( button ), GTK_WIDGET( image ) );
1675 gtk_button_set_relief( GTK_BUTTON( button ), GTK_RELIEF_NONE );
1676 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1677 GTK_WIDGET_UNSET_FLAGS( button, GTK_CAN_FOCUS );
1678 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1679 gtk_box_pack_start( hbox, button, FALSE, FALSE, 0 );
1680 gtk_widget_set_tooltip_text( button, "Focus on Selected" );
1681 gtk_widget_show( button );
1682 g_focusToggleButton = GTK_TOGGLE_BUTTON( button );
1688 auto scr = ui::ScrolledWindow(ui::New);
1690 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1692 auto viewport = ui::Container::from(gtk_viewport_new( 0, 0 ));
1694 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1696 g_attributeBox = ui::VBox( FALSE, 2 );
1697 g_attributeBox.show();
1699 viewport.add(g_attributeBox);
1701 gtk_paned_pack2( GTK_PANED( split0 ), scr, FALSE, FALSE );
1708 // show the sliders in any case //no need, gtk can care
1709 /*if ( g_entitysplit2_position < 22 ) {
1710 g_entitysplit2_position = 22;
1712 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1713 /*if ( ( g_entitysplit1_position - g_entitysplit2_position ) < 27 ) {
1714 g_entitysplit1_position = g_entitysplit2_position + 27;
1716 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1717 gtk_paned_set_position( GTK_PANED( g_entity_split0 ), g_entitysplit0_position );
1720 g_entityInspector_windowConstructed = true;
1721 EntityClassList_fill();
1723 typedef FreeCaller<void(const Selectable&), EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1724 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1725 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1728 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1733 class EntityInspector : public ModuleObserver
1735 std::size_t m_unrealised;
1737 EntityInspector() : m_unrealised( 1 ){
1740 if ( --m_unrealised == 0 ) {
1741 if ( g_entityInspector_windowConstructed ) {
1742 //globalOutputStream() << "Entity Inspector: realise\n";
1743 EntityClassList_fill();
1748 if ( ++m_unrealised == 1 ) {
1749 if ( g_entityInspector_windowConstructed ) {
1750 //globalOutputStream() << "Entity Inspector: unrealise\n";
1751 EntityClassList_clear();
1757 EntityInspector g_EntityInspector;
1759 #include "preferencesystem.h"
1760 #include "stringio.h"
1762 void EntityInspector_construct(){
1763 GlobalEntityClassManager().attach( g_EntityInspector );
1765 GlobalPreferenceSystem().registerPreference( "EntitySplit0", make_property_string( g_entitysplit0_position ) );
1766 GlobalPreferenceSystem().registerPreference( "EntitySplit1", make_property_string( g_entitysplit1_position ) );
1767 GlobalPreferenceSystem().registerPreference( "EntitySplit2", make_property_string( g_entitysplit2_position ) );
1771 void EntityInspector_destroy(){
1772 GlobalEntityClassManager().detach( g_EntityInspector );
1775 const char *EntityInspector_getCurrentKey(){
1776 if ( !GroupDialog_isShown() ) {
1779 if ( GroupDialog_getPage() != g_page_entity ) {
1782 return gtk_entry_get_text( g_entityKeyEntry );