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>
38 #include <gtk/gtkstock.h>
42 #include "eclasslib.h"
44 #include "generic/callback.h"
46 #include "stream/stringstream.h"
47 #include "moduleobserver.h"
51 #include "gtkutil/accelerator.h"
52 #include "gtkutil/dialog.h"
53 #include "gtkutil/filechooser.h"
54 #include "gtkutil/messagebox.h"
55 #include "gtkutil/nonmodal.h"
56 #include "gtkutil/button.h"
57 #include "gtkutil/entry.h"
58 #include "gtkutil/container.h"
64 #include "mainframe.h"
65 #include "textureentry.h"
66 #include "groupdialog.h"
70 ui::Entry numeric_entry_new(){
71 auto entry = ui::Entry(ui::New);
73 entry.dimensions(64, -1);
79 typedef std::map<CopiedString, CopiedString> KeyValues;
80 KeyValues g_selectedKeyValues;
81 KeyValues g_selectedDefaultKeyValues;
84 const char* SelectedEntity_getValueForKey( const char* key ){
86 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
87 if ( i != g_selectedKeyValues.end() ) {
88 return ( *i ).second.c_str();
92 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
93 if ( i != g_selectedDefaultKeyValues.end() ) {
94 return ( *i ).second.c_str();
100 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
101 StringOutputStream command( 256 );
102 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
103 UndoableCommand undo( command.c_str() );
104 Scene_EntitySetKeyValue_Selected( key, value );
107 class EntityAttribute
110 virtual ~EntityAttribute() = default;
111 virtual ui::Widget getWidget() const = 0;
112 virtual void update() = 0;
113 virtual void release() = 0;
116 class BooleanAttribute : public EntityAttribute
119 ui::CheckButton m_check;
121 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
126 BooleanAttribute( const char* key ) :
129 auto check = ui::CheckButton(ui::New);
134 guint handler = check.connect( "toggled", G_CALLBACK( toggled ), this );
135 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
139 ui::Widget getWidget() const {
146 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_check.active() ? "1" : "" );
148 typedef MemberCaller<BooleanAttribute, void(), &BooleanAttribute::apply> ApplyCaller;
151 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
152 if ( !string_empty( value ) ) {
153 toggle_button_set_active_no_signal( m_check, atoi( value ) != 0 );
157 toggle_button_set_active_no_signal( m_check, false );
160 typedef MemberCaller<BooleanAttribute, void(), &BooleanAttribute::update> UpdateCaller;
164 class StringAttribute : public EntityAttribute
168 NonModalEntry m_nonModal;
170 StringAttribute( const char* key ) :
173 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
174 auto entry = ui::Entry(ui::New);
176 entry.dimensions(50, -1);
179 m_nonModal.connect( m_entry );
181 ui::Widget getWidget() const {
184 ui::Entry getEntry() const {
192 StringOutputStream value( 64 );
193 value << m_entry.text();
194 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
196 typedef MemberCaller<StringAttribute, void(), &StringAttribute::apply> ApplyCaller;
199 StringOutputStream value( 64 );
200 value << SelectedEntity_getValueForKey( m_key.c_str() );
201 m_entry.text(value.c_str());
203 typedef MemberCaller<StringAttribute, void(), &StringAttribute::update> UpdateCaller;
206 class ShaderAttribute : public StringAttribute
209 ShaderAttribute( const char* key ) : StringAttribute( key ){
210 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
215 class ColorAttribute : public EntityAttribute
218 BrowsedPathEntry m_entry;
219 NonModalEntry m_nonModal;
221 ColorAttribute( const char* key ) :
223 m_entry( BrowseCaller( *this ) ),
224 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
225 m_nonModal.connect( m_entry.m_entry.m_entry );
230 ui::Widget getWidget() const {
231 return ui::Widget( m_entry.m_entry.m_frame );
234 StringOutputStream value( 64 );
235 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
236 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
238 typedef MemberCaller<ColorAttribute, void(), &ColorAttribute::apply> ApplyCaller;
240 StringOutputStream value( 64 );
241 value << SelectedEntity_getValueForKey( m_key.c_str() );
242 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
244 typedef MemberCaller<ColorAttribute, void(), &ColorAttribute::update> UpdateCaller;
245 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
246 //const char *filename = misc_model_dialog( gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) );
248 /* hijack BrowsedPathEntry to call colour chooser */
251 // if ( filename != 0 ) {
252 // setPath( filename );
257 typedef MemberCaller<ColorAttribute, void(const BrowsedPathEntry::SetPathCallback&), &ColorAttribute::browse> BrowseCaller;
261 class ModelAttribute : public EntityAttribute
264 BrowsedPathEntry m_entry;
265 NonModalEntry m_nonModal;
267 ModelAttribute( const char* key ) :
269 m_entry( BrowseCaller( *this ) ),
270 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
271 m_nonModal.connect( m_entry.m_entry.m_entry );
276 ui::Widget getWidget() const {
277 return m_entry.m_entry.m_frame;
280 StringOutputStream value( 64 );
281 value << m_entry.m_entry.m_entry.text();
282 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
284 typedef MemberCaller<ModelAttribute, void(), &ModelAttribute::apply> ApplyCaller;
286 StringOutputStream value( 64 );
287 value << SelectedEntity_getValueForKey( m_key.c_str() );
288 m_entry.m_entry.m_entry.text(value.c_str());
290 typedef MemberCaller<ModelAttribute, void(), &ModelAttribute::update> UpdateCaller;
291 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
292 const char *filename = misc_model_dialog( m_entry.m_entry.m_frame.window() );
294 if ( filename != 0 ) {
299 typedef MemberCaller<ModelAttribute, void(const BrowsedPathEntry::SetPathCallback&), &ModelAttribute::browse> BrowseCaller;
302 const char* browse_sound( ui::Widget parent ){
303 StringOutputStream buffer( 1024 );
305 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
307 if ( !file_readable( buffer.c_str() ) ) {
310 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
313 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
314 if ( filename != 0 ) {
315 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
316 if ( relative == filename ) {
317 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
324 class SoundAttribute : public EntityAttribute
327 BrowsedPathEntry m_entry;
328 NonModalEntry m_nonModal;
330 SoundAttribute( const char* key ) :
332 m_entry( BrowseCaller( *this ) ),
333 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
334 m_nonModal.connect( m_entry.m_entry.m_entry );
339 ui::Widget getWidget() const {
340 return ui::Widget(m_entry.m_entry.m_frame );
343 StringOutputStream value( 64 );
344 value << m_entry.m_entry.m_entry.text();
345 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
347 typedef MemberCaller<SoundAttribute, void(), &SoundAttribute::apply> ApplyCaller;
349 StringOutputStream value( 64 );
350 value << SelectedEntity_getValueForKey( m_key.c_str() );
351 m_entry.m_entry.m_entry.text(value.c_str());
353 typedef MemberCaller<SoundAttribute, void(), &SoundAttribute::update> UpdateCaller;
354 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
355 const char *filename = browse_sound( m_entry.m_entry.m_frame.window() );
357 if ( filename != 0 ) {
362 typedef MemberCaller<SoundAttribute, void(const BrowsedPathEntry::SetPathCallback&), &SoundAttribute::browse> BrowseCaller;
365 inline double angle_normalised( double angle ){
366 return float_mod( angle, 360.0 );
369 class AngleAttribute : public EntityAttribute
373 NonModalEntry m_nonModal;
375 AngleAttribute( const char* key ) :
378 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
379 auto entry = numeric_entry_new();
381 m_nonModal.connect( m_entry );
386 ui::Widget getWidget() const {
387 return ui::Widget(m_entry );
390 StringOutputStream angle( 32 );
391 angle << angle_normalised( entry_get_float( m_entry ) );
392 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
394 typedef MemberCaller<AngleAttribute, void(), &AngleAttribute::apply> ApplyCaller;
397 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
398 if ( !string_empty( value ) ) {
399 StringOutputStream angle( 32 );
400 angle << angle_normalised( atof( value ) );
401 m_entry.text(angle.c_str());
408 typedef MemberCaller<AngleAttribute, void(), &AngleAttribute::update> UpdateCaller;
413 typedef const char* String;
414 const String buttons[] = { "up", "down", "z-axis" };
417 class DirectionAttribute : public EntityAttribute
421 NonModalEntry m_nonModal;
423 NonModalRadio m_nonModalRadio;
424 ui::HBox m_hbox{ui::null};
426 DirectionAttribute( const char* key ) :
429 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
430 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
431 m_nonModalRadio( ApplyRadioCaller( *this ) ){
432 auto entry = numeric_entry_new();
434 m_nonModal.connect( m_entry );
436 m_nonModalRadio.connect( m_radio.m_radio );
438 m_hbox = ui::HBox( FALSE, 4 );
441 m_hbox.pack_start( m_radio.m_hbox, TRUE, TRUE, 0 );
442 m_hbox.pack_start( m_entry, TRUE, TRUE, 0 );
447 ui::Widget getWidget() const {
448 return ui::Widget(m_hbox );
451 StringOutputStream angle( 32 );
452 angle << angle_normalised( entry_get_float( m_entry ) );
453 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
455 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::apply> ApplyCaller;
458 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
459 if ( !string_empty( value ) ) {
460 float f = float(atof( value ) );
462 gtk_widget_set_sensitive( m_entry , FALSE );
463 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
466 else if ( f == -2 ) {
467 gtk_widget_set_sensitive( m_entry , FALSE );
468 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
473 gtk_widget_set_sensitive( m_entry , TRUE );
474 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
475 StringOutputStream angle( 32 );
476 angle << angle_normalised( f );
477 m_entry.text(angle.c_str());
485 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::update> UpdateCaller;
488 int index = radio_button_get_active( m_radio.m_radio );
490 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
492 else if ( index == 1 ) {
493 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
495 else if ( index == 2 ) {
499 typedef MemberCaller<DirectionAttribute, void(), &DirectionAttribute::applyRadio> ApplyRadioCaller;
509 AnglesEntry() : m_roll( ui::null ), m_pitch( ui::null ), m_yaw( ui::null ){
513 typedef BasicVector3<double> DoubleVector3;
515 class AnglesAttribute : public EntityAttribute
518 AnglesEntry m_angles;
519 NonModalEntry m_nonModal;
522 AnglesAttribute( const char* key ) :
524 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
525 m_hbox(ui::HBox( TRUE, 4 ))
529 auto entry = numeric_entry_new();
530 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
531 m_angles.m_pitch = entry;
532 m_nonModal.connect( m_angles.m_pitch );
535 auto entry = numeric_entry_new();
536 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
537 m_angles.m_yaw = entry;
538 m_nonModal.connect( m_angles.m_yaw );
541 auto entry = numeric_entry_new();
542 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
543 m_angles.m_roll = entry;
544 m_nonModal.connect( m_angles.m_roll );
550 ui::Widget getWidget() const {
551 return ui::Widget(m_hbox );
554 StringOutputStream angles( 64 );
555 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
556 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
557 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
558 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
560 typedef MemberCaller<AnglesAttribute, void(), &AnglesAttribute::apply> ApplyCaller;
563 StringOutputStream angle( 32 );
564 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
565 if ( !string_empty( value ) ) {
566 DoubleVector3 pitch_yaw_roll;
567 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
568 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
571 angle << angle_normalised( pitch_yaw_roll.x() );
572 m_angles.m_pitch.text(angle.c_str());
575 angle << angle_normalised( pitch_yaw_roll.y() );
576 m_angles.m_yaw.text(angle.c_str());
579 angle << angle_normalised( pitch_yaw_roll.z() );
580 m_angles.m_roll.text(angle.c_str());
585 m_angles.m_pitch.text("0");
586 m_angles.m_yaw.text("0");
587 m_angles.m_roll.text("0");
590 typedef MemberCaller<AnglesAttribute, void(), &AnglesAttribute::update> UpdateCaller;
599 Vector3Entry() : m_x( ui::null ), m_y( ui::null ), m_z( ui::null ){
603 class Vector3Attribute : public EntityAttribute
606 Vector3Entry m_vector3;
607 NonModalEntry m_nonModal;
608 ui::Box m_hbox{ui::null};
610 Vector3Attribute( const char* key ) :
612 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
613 m_hbox = ui::HBox( TRUE, 4 );
616 auto entry = numeric_entry_new();
617 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
618 m_vector3.m_x = entry;
619 m_nonModal.connect( m_vector3.m_x );
622 auto entry = numeric_entry_new();
623 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
624 m_vector3.m_y = entry;
625 m_nonModal.connect( m_vector3.m_y );
628 auto entry = numeric_entry_new();
629 m_hbox.pack_start( entry, TRUE, TRUE, 0 );
630 m_vector3.m_z = entry;
631 m_nonModal.connect( m_vector3.m_z );
637 ui::Widget getWidget() const {
638 return ui::Widget(m_hbox );
641 StringOutputStream vector3( 64 );
642 vector3 << entry_get_float( m_vector3.m_x )
643 << " " << entry_get_float( m_vector3.m_y )
644 << " " << entry_get_float( m_vector3.m_z );
645 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
647 typedef MemberCaller<Vector3Attribute, void(), &Vector3Attribute::apply> ApplyCaller;
650 StringOutputStream buffer( 32 );
651 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
652 if ( !string_empty( value ) ) {
654 if ( !string_parse_vector3( value, x_y_z ) ) {
655 x_y_z = DoubleVector3( 0, 0, 0 );
659 m_vector3.m_x.text(buffer.c_str());
663 m_vector3.m_y.text(buffer.c_str());
667 m_vector3.m_z.text(buffer.c_str());
672 m_vector3.m_x.text("0");
673 m_vector3.m_y.text("0");
674 m_vector3.m_z.text("0");
677 typedef MemberCaller<Vector3Attribute, void(), &Vector3Attribute::update> UpdateCaller;
680 class NonModalComboBox
682 Callback<void()> m_changed;
683 guint m_changedHandler;
685 static gboolean changed( ui::ComboBox widget, NonModalComboBox* self ){
691 NonModalComboBox( const Callback<void()>& changed ) : m_changed( changed ), m_changedHandler( 0 ){
693 void connect( ui::ComboBox combo ){
694 m_changedHandler = combo.connect( "changed", G_CALLBACK( changed ), this );
696 void setActive( ui::ComboBox combo, int value ){
697 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
698 gtk_combo_box_set_active( combo, value );
703 class ListAttribute : public EntityAttribute
706 ui::ComboBox m_combo;
707 NonModalComboBox m_nonModal;
708 const ListAttributeType& m_type;
710 ListAttribute( const char* key, const ListAttributeType& type ) :
713 m_nonModal( ApplyCaller( *this ) ),
715 auto combo = ui::ComboBoxText(ui::New);
717 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
719 gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), ( *i ).first.c_str() );
723 m_nonModal.connect( combo );
730 ui::Widget getWidget() const {
731 return ui::Widget(m_combo );
734 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
736 typedef MemberCaller<ListAttribute, void(), &ListAttribute::apply> ApplyCaller;
739 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
740 ListAttributeType::const_iterator i = m_type.findValue( value );
741 if ( i != m_type.end() ) {
742 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
746 m_nonModal.setActive( m_combo, 0 );
749 typedef MemberCaller<ListAttribute, void(), &ListAttribute::update> UpdateCaller;
755 GtkWidget* g_entity_split0 = 0;
756 ui::Widget g_entity_split1{ui::null};
757 ui::Widget g_entity_split2{ui::null};
758 int g_entitysplit0_position;
759 int g_entitysplit1_position;
760 int g_entitysplit2_position;
762 bool g_entityInspector_windowConstructed = false;
764 ui::TreeView g_entityClassList{ui::null};
765 ui::TextView g_entityClassComment{ui::null};
767 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
769 ui::Entry g_entityKeyEntry{ui::null};
770 ui::Entry g_entityValueEntry{ui::null};
772 GtkToggleButton* g_focusToggleButton;
774 ui::ListStore g_entlist_store{ui::null};
775 ui::ListStore g_entprops_store{ui::null};
776 const EntityClass* g_current_flags = 0;
777 const EntityClass* g_current_comment = 0;
778 const EntityClass* g_current_attributes = 0;
780 // the number of active spawnflags
781 int g_spawnflag_count;
782 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
783 int spawn_table[MAX_FLAGS];
784 // we change the layout depending on how many spawn flags we need to display
785 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
786 ui::Table g_spawnflagsTable{ui::null};
788 ui::VBox g_attributeBox{ui::null};
789 typedef std::vector<EntityAttribute*> EntityAttributes;
790 EntityAttributes g_entityAttributes;
793 void GlobalEntityAttributes_clear(){
794 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
798 g_entityAttributes.clear();
801 class GetKeyValueVisitor : public Entity::Visitor
803 KeyValues& m_keyvalues;
805 GetKeyValueVisitor( KeyValues& keyvalues )
806 : m_keyvalues( keyvalues ){
809 void visit( const char* key, const char* value ){
810 m_keyvalues.insert( KeyValues::value_type( CopiedString( key ), CopiedString( value ) ) );
815 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
816 GetKeyValueVisitor visitor( keyvalues );
818 entity.forEachKeyValue( visitor );
820 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
822 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
824 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
828 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
829 class EntityGetKeyValues : public SelectionSystem::Visitor
831 KeyValues& m_keyvalues;
832 KeyValues& m_defaultValues;
833 mutable std::set<Entity*> m_visited;
835 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
836 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
838 void visit( scene::Instance& instance ) const {
839 Entity* entity = Node_getEntity( instance.path().top() );
840 if ( entity == 0 && instance.path().size() != 1 ) {
841 entity = Node_getEntity( instance.path().parent() );
843 if ( entity != 0 && m_visited.insert( entity ).second ) {
844 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
847 } visitor( keyvalues, defaultValues );
848 GlobalSelectionSystem().foreachSelected( visitor );
851 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
852 KeyValues::iterator i = keyvalues.find( CopiedString( key ) );
853 if ( i != keyvalues.end() ) {
854 return ( *i ).second.c_str();
859 class EntityClassListStoreAppend : public EntityClassVisitor
863 EntityClassListStoreAppend( ui::ListStore store_ ) : store( store_ ){
865 void visit( EntityClass* e ){
866 store.append(0, e->name(), 1, e);
870 void EntityClassList_fill(){
871 EntityClassListStoreAppend append( g_entlist_store );
872 GlobalEntityClassManager().forEach( append );
875 void EntityClassList_clear(){
876 g_entlist_store.clear();
879 void SetComment( EntityClass* eclass ){
880 if ( eclass == g_current_comment ) {
884 g_current_comment = eclass;
886 g_entityClassComment.text(eclass->comments());
888 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
889 //gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
890 const char* comment = eclass->comments(), *c;
891 int offset = 0, pattern_start = -1, spaces = 0;
893 gtk_text_buffer_set_text( buffer, comment, -1 );
895 // Catch patterns like "\nstuff :" used to describe keys and spawnflags, and make them bold for readability.
897 for( c = comment; *c; ++c, ++offset ) {
899 pattern_start = offset;
902 else if( pattern_start >= 0 && ( *c < 'a' || *c > 'z' ) && ( *c < 'A' || *c > 'Z' ) && ( *c < '0' || *c > '9' ) && ( *c != '_' ) ) {
903 if( *c == ':' && spaces <= 1 ) {
904 GtkTextIter iter_start, iter_end;
906 gtk_text_buffer_get_iter_at_offset( buffer, &iter_start, pattern_start );
907 gtk_text_buffer_get_iter_at_offset( buffer, &iter_end, offset );
908 gtk_text_buffer_apply_tag_by_name( buffer, "bold", &iter_start, &iter_end );
919 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
920 if ( eclass == g_current_flags ) {
924 g_current_flags = eclass;
926 unsigned int spawnflag_count = 0;
929 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
930 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
932 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
933 spawn_table[spawnflag_count] = i;
939 // disable all remaining boxes
940 // NOTE: these boxes might not even be on display
942 for ( int i = 0; i < g_spawnflag_count; ++i )
944 auto widget = ui::CheckButton::from(g_entitySpawnflagsCheck[i]);
945 auto label = ui::Label::from(gtk_bin_get_child(GTK_BIN(widget)));
949 g_spawnflagsTable.remove(widget);
953 g_spawnflag_count = spawnflag_count;
956 for (unsigned int i = 0; (int) i < g_spawnflag_count; ++i)
958 auto widget = ui::CheckButton::from(g_entitySpawnflagsCheck[i] );
961 StringOutputStream str( 16 );
962 str << LowerCase( eclass->flagnames[spawn_table[i]] );
964 g_spawnflagsTable.attach(widget, {i % 4, i % 4 + 1, i / 4, i / 4 + 1}, {GTK_FILL, GTK_FILL});
967 auto label = ui::Label::from(gtk_bin_get_child(GTK_BIN(widget)) );
968 label.text(str.c_str());
973 void EntityClassList_selectEntityClass( EntityClass* eclass ){
974 auto model = g_entlist_store;
976 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
979 gtk_tree_model_get( model, &iter, 0, &text, -1 );
980 if ( strcmp( text, eclass->name() ) == 0 ) {
981 auto view = ui::TreeView(g_entityClassList);
982 auto path = gtk_tree_model_get_path( model, &iter );
983 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
984 if ( gtk_widget_get_realized( view ) ) {
985 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
987 gtk_tree_path_free( path );
994 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
995 auto row = DialogRow_new( name, attribute.getWidget() );
996 DialogVBox_packRow( ui::VBox(g_attributeBox), row );
1000 template<typename Attribute>
1001 class StatelessAttributeCreator
1004 static EntityAttribute* create( const char* name ){
1005 return new Attribute( name );
1009 class EntityAttributeFactory
1011 typedef EntityAttribute* ( *CreateFunc )( const char* name );
1012 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
1013 Creators m_creators;
1015 EntityAttributeFactory(){
1016 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
1017 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<ColorAttribute>::create ) );
1018 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
1019 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
1020 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
1021 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
1022 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
1023 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
1024 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
1025 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
1026 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
1027 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
1028 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
1030 EntityAttribute* create( const char* type, const char* name ){
1031 Creators::iterator i = m_creators.find( type );
1032 if ( i != m_creators.end() ) {
1033 return ( *i ).second( name );
1035 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
1036 if ( listType != 0 ) {
1037 return new ListAttribute( name, *listType );
1043 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
1045 void EntityInspector_setEntityClass( EntityClass *eclass ){
1046 EntityClassList_selectEntityClass( eclass );
1047 SurfaceFlags_setEntityClass( eclass );
1049 if ( eclass != g_current_attributes ) {
1050 g_current_attributes = eclass;
1052 container_remove_all( g_attributeBox );
1053 GlobalEntityAttributes_clear();
1055 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
1057 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
1058 if ( attribute != 0 ) {
1059 g_entityAttributes.push_back( attribute );
1060 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
1066 void EntityInspector_updateSpawnflags(){
1068 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
1069 for ( int i = 0; i < g_spawnflag_count; ++i )
1071 int v = !!( f & ( 1 << spawn_table[i] ) );
1073 toggle_button_set_active_no_signal( ui::ToggleButton::from( g_entitySpawnflagsCheck[i] ), v );
1077 // take care of the remaining ones
1078 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1080 toggle_button_set_active_no_signal( ui::ToggleButton::from( g_entitySpawnflagsCheck[i] ), FALSE );
1085 void EntityInspector_applySpawnflags(){
1090 for ( i = 0; i < g_spawnflag_count; ++i )
1092 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1093 f |= v << spawn_table[i];
1096 sprintf( sz, "%i", f );
1097 const char* value = ( f == 0 ) ? "" : sz;
1100 StringOutputStream command;
1101 command << "entitySetFlags -flags " << f;
1102 UndoableCommand undo( "entitySetSpawnflags" );
1104 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1109 void EntityInspector_updateKeyValues(){
1110 g_selectedKeyValues.clear();
1111 g_selectedDefaultKeyValues.clear();
1112 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1114 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1116 EntityInspector_updateSpawnflags();
1118 ui::ListStore store = g_entprops_store;
1120 // save current key/val pair around filling epair box
1121 // row_select wipes it and sets to first in list
1122 CopiedString strKey( g_entityKeyEntry.text() );
1123 CopiedString strVal( g_entityValueEntry.text() );
1126 // Walk through list and add pairs
1127 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1129 StringOutputStream key( 64 );
1130 key << ( *i ).first.c_str();
1131 StringOutputStream value( 64 );
1132 value << ( *i ).second.c_str();
1133 store.append(0, key.c_str(), 1, value.c_str());
1136 g_entityKeyEntry.text( strKey.c_str() );
1137 g_entityValueEntry.text( strVal.c_str() );
1139 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1145 class EntityInspectorDraw
1147 IdleDraw m_idleDraw;
1149 EntityInspectorDraw() : m_idleDraw( makeCallbackF(EntityInspector_updateKeyValues) ){
1152 m_idleDraw.queueDraw();
1156 EntityInspectorDraw g_EntityInspectorDraw;
1159 void EntityInspector_keyValueChanged(){
1160 g_EntityInspectorDraw.queueDraw();
1162 void EntityInspector_selectionChanged( const Selectable& ){
1163 EntityInspector_keyValueChanged();
1166 // Creates a new entity based on the currently selected brush and entity type.
1168 void EntityClassList_createEntity(){
1169 auto view = g_entityClassList;
1171 // find out what type of entity we are trying to create
1172 GtkTreeModel* model;
1174 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( g_entityClassList ), &model, &iter ) == FALSE ) {
1175 ui::alert( view.window(), "You must have a selected class to create an entity", "info" );
1180 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1183 StringOutputStream command;
1184 command << "entityCreate -class " << text;
1186 UndoableCommand undo( command.c_str() );
1188 Entity_createFromSelection( text, g_vector3_identity );
1193 void EntityInspector_applyKeyValue(){
1194 // Get current selection text
1195 StringOutputStream key( 64 );
1196 key << gtk_entry_get_text( g_entityKeyEntry );
1197 StringOutputStream value( 64 );
1198 value << gtk_entry_get_text( g_entityValueEntry );
1201 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1202 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1203 ui::alert( g_entityKeyEntry.window(), "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1208 // RR2DO2: we don't want spaces in entity keys
1209 if ( strstr( key.c_str(), " " ) ) {
1210 ui::alert( g_entityKeyEntry.window(), "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1214 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1215 StringOutputStream command;
1216 command << "entitySetClass -class " << value.c_str();
1217 UndoableCommand undo( command.c_str() );
1218 Scene_EntitySetClassname_Selected( value.c_str() );
1222 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1226 void EntityInspector_clearKeyValue(){
1227 // Get current selection text
1228 StringOutputStream key( 64 );
1229 key << gtk_entry_get_text( g_entityKeyEntry );
1231 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1232 StringOutputStream command;
1233 command << "entityDeleteKey -key " << key.c_str();
1234 UndoableCommand undo( command.c_str() );
1235 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1239 static gint EntityInspector_clearKeyValueKB( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1240 if ( event->keyval == GDK_Delete ) {
1241 EntityInspector_clearKeyValue();
1247 void EntityInspector_clearAllKeyValues(){
1248 UndoableCommand undo( "entityClear" );
1250 // remove all keys except classname
1251 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1253 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1254 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1259 // =============================================================================
1262 static void EntityClassList_selection_changed( ui::TreeSelection selection, gpointer data ){
1263 GtkTreeModel* model;
1264 GtkTreeIter selected;
1265 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1266 EntityClass* eclass;
1267 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1268 if ( eclass != 0 ) {
1269 SetComment( eclass );
1274 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1275 if ( event->type == GDK_2BUTTON_PRESS ) {
1276 EntityClassList_createEntity();
1282 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1283 if ( event->keyval == GDK_KEY_Return ) {
1284 EntityClassList_createEntity();
1288 // select the entity that starts with the key pressed
1290 unsigned int code = gdk_keyval_to_upper( event->keyval );
1291 if ( code <= 'Z' && code >= 'A' && event->state == 0 ) {
1292 auto view = ui::TreeView(g_entityClassList);
1293 GtkTreeModel* model;
1295 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1296 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1297 gtk_tree_model_get_iter_first( model, &iter );
1300 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1303 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1305 if ( toupper( text[0] ) == (int)code ) {
1306 auto path = gtk_tree_model_get_path( model, &iter );
1307 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1308 if ( gtk_widget_get_realized( view ) ) {
1309 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1311 gtk_tree_path_free( path );
1317 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1318 gtk_tree_model_get_iter_first( model, &iter );
1328 static void EntityProperties_selection_changed( ui::TreeSelection selection, gpointer data ){
1329 // find out what type of entity we are trying to create
1330 GtkTreeModel* model;
1332 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1338 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1340 g_entityKeyEntry.text( key );
1341 g_entityValueEntry.text( val );
1347 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1348 EntityInspector_applySpawnflags();
1351 static gint EntityEntry_keypress( ui::Entry widget, GdkEventKey* event, gpointer data ){
1352 if ( event->keyval == GDK_KEY_Return ) {
1353 if ( widget._handle == g_entityKeyEntry._handle ) {
1354 // g_entityValueEntry.text( "" );
1355 gtk_window_set_focus( widget.window(), g_entityValueEntry );
1359 EntityInspector_applyKeyValue();
1363 if ( event->keyval == GDK_Tab ) {
1364 if ( widget._handle == g_entityKeyEntry._handle ) {
1365 gtk_window_set_focus( widget.window(), g_entityValueEntry );
1369 gtk_window_set_focus( widget.window(), g_entityKeyEntry );
1373 if ( event->keyval == GDK_Escape ) {
1374 // gtk_window_set_focus( widget.window(), NULL );
1381 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1382 g_entitysplit0_position = gtk_paned_get_position( GTK_PANED( g_entity_split0 ) );
1383 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1384 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1385 g_entityInspector_windowConstructed = false;
1386 GlobalEntityAttributes_clear();
1389 static gint EntityInspector_hideWindowKB( GtkWidget* widget, GdkEventKey* event, gpointer data ){
1390 //if ( event->keyval == GDK_Escape && GTK_WIDGET_VISIBLE( GTK_WIDGET( widget ) ) ) {
1391 if ( event->keyval == GDK_Escape ) {
1392 //GroupDialog_showPage( g_page_entity );
1393 gtk_widget_hide( GTK_WIDGET( GroupDialog_getWindow() ) );
1396 /* this doesn't work, if tab is bound (func is not called then) */
1397 if ( event->keyval == GDK_Tab ) {
1398 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityKeyEntry ) );
1404 void EntityInspector_selectTargeting( GtkButton *button, gpointer user_data ){
1405 bool focus = gtk_toggle_button_get_active( g_focusToggleButton );
1406 Select_ConnectedEntities( true, false, focus );
1409 void EntityInspector_selectTargets( GtkButton *button, gpointer user_data ){
1410 bool focus = gtk_toggle_button_get_active( g_focusToggleButton );
1411 Select_ConnectedEntities( false, true, focus );
1414 void EntityInspector_selectConnected( GtkButton *button, gpointer user_data ){
1415 bool focus = gtk_toggle_button_get_active( g_focusToggleButton );
1416 Select_ConnectedEntities( true, true, focus );
1419 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1420 auto vbox = ui::VBox( FALSE, 2 );
1422 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1424 g_signal_connect( G_OBJECT( toplevel ), "key_press_event", G_CALLBACK( EntityInspector_hideWindowKB ), 0 );
1425 vbox.connect( "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1428 auto split1 = ui::VPaned(ui::New);
1429 vbox.pack_start( split1, TRUE, TRUE, 0 );
1432 g_entity_split1 = split1;
1435 ui::Widget split2 = ui::VPaned(ui::New);
1436 //gtk_paned_add1( GTK_PANED( split1 ), split2 );
1437 gtk_paned_pack1( GTK_PANED( split1 ), split2, FALSE, FALSE );
1440 g_entity_split2 = split2;
1444 auto scr = ui::ScrolledWindow(ui::New);
1446 //gtk_paned_add1( GTK_PANED( split2 ), scr );
1447 gtk_paned_pack1( GTK_PANED( split2 ), scr, FALSE, FALSE );
1448 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1449 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1452 ui::ListStore store = ui::ListStore::from(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
1454 auto view = ui::TreeView( ui::TreeModel::from( store._handle ));
1455 // gtk_tree_view_set_enable_search(view, FALSE );
1456 gtk_tree_view_set_headers_visible( view, FALSE );
1457 view.connect( "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1458 view.connect( "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1461 auto renderer = ui::CellRendererText(ui::New);
1462 auto column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1463 gtk_tree_view_append_column( view, column );
1467 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection( view ));
1468 selection.connect( "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1476 g_entityClassList = view;
1477 g_entlist_store = store;
1482 auto scr = ui::ScrolledWindow(ui::New);
1484 //gtk_paned_add2( GTK_PANED( split2 ), scr );
1485 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1486 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1487 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1490 auto text = ui::TextView(ui::New);
1491 text.dimensions(0, -1); // allow shrinking
1492 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1493 gtk_text_view_set_editable( text, FALSE );
1496 g_entityClassComment = text;
1498 GtkTextBuffer *buffer = gtk_text_view_get_buffer( text );
1499 gtk_text_buffer_create_tag( buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL );
1506 ui::Widget split0 = ui::VPaned(ui::New);
1507 //gtk_paned_add2( GTK_PANED( split1 ), split0 );
1508 gtk_paned_pack2( GTK_PANED( split1 ), split0, FALSE, FALSE );
1510 g_entity_split0 = split0;
1513 auto vbox2 = ui::VBox( FALSE, 2 );
1515 gtk_paned_pack1( GTK_PANED( split0 ), vbox2, FALSE, FALSE );
1518 // Spawnflags (4 colums wide max, or window gets too wide.)
1519 auto table = ui::Table( 4, 4, FALSE );
1520 vbox2.pack_start( table, FALSE, TRUE, 0 );
1523 g_spawnflagsTable = table;
1525 for ( int i = 0; i < MAX_FLAGS; i++ )
1527 auto check = ui::CheckButton( "" );
1529 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( check.connect( "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1530 g_entitySpawnflagsCheck[i] = check;
1536 auto scr = ui::ScrolledWindow(ui::New);
1538 vbox2.pack_start( scr, TRUE, TRUE, 0 );
1539 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1540 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1543 ui::ListStore store = ui::ListStore::from(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ));
1545 auto view = ui::TreeView(ui::TreeModel::from(store._handle));
1546 gtk_tree_view_set_enable_search(view, FALSE );
1547 gtk_tree_view_set_headers_visible(view, FALSE );
1548 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityInspector_clearKeyValueKB ), 0 );
1551 auto renderer = ui::CellRendererText(ui::New);
1552 auto column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1553 gtk_tree_view_append_column(view, column );
1557 auto renderer = ui::CellRendererText(ui::New);
1558 auto column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1559 gtk_tree_view_append_column(view, column );
1563 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(view));
1564 selection.connect( "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1573 g_entprops_store = store;
1579 auto table = ui::Table( 2, 2, FALSE );
1581 vbox2.pack_start( table, FALSE, TRUE, 0 );
1582 gtk_table_set_row_spacings( table, 3 );
1583 gtk_table_set_col_spacings( table, 5 );
1586 auto entry = ui::Entry(ui::New);
1588 table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
1589 gtk_widget_set_events( entry , GDK_KEY_PRESS_MASK );
1590 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1591 g_entityKeyEntry = entry;
1595 auto entry = ui::Entry(ui::New);
1597 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
1598 gtk_widget_set_events( entry , GDK_KEY_PRESS_MASK );
1599 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1600 g_entityValueEntry = entry;
1604 auto label = ui::Label( "Value" );
1606 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
1607 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1611 auto label = ui::Label( "Key" );
1613 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
1614 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1619 auto hbox = ui::HBox( FALSE, 4 );
1621 vbox2.pack_start( hbox, FALSE, TRUE, 0 );
1624 auto button = ui::Button( "Clear All" );
1625 #define GARUX_DISABLE_BUTTON_NOFOCUS
1626 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1627 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1628 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1630 button.connect( "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1631 hbox.pack_start( button, TRUE, TRUE, 0 );
1634 auto button = ui::Button( "Delete Key" );
1635 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1636 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1637 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1639 button.connect( "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1640 hbox.pack_start( button, TRUE, TRUE, 0 );
1643 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "<" ) );
1644 gtk_widget_set_tooltip_text( GTK_WIDGET( button ), "Select targeting entities" );
1645 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1646 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1647 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1648 gtk_widget_show( GTK_WIDGET( button ) );
1649 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_selectTargeting ), 0 );
1650 gtk_box_pack_start( hbox, GTK_WIDGET( button ), FALSE, FALSE, 0 );
1653 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( ">" ) );
1654 gtk_widget_set_tooltip_text( GTK_WIDGET( button ), "Select targets" );
1655 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1656 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1657 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1658 gtk_widget_show( GTK_WIDGET( button ) );
1659 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_selectTargets ), 0 );
1660 gtk_box_pack_start( hbox, GTK_WIDGET( button ), FALSE, FALSE, 0 );
1663 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "<->" ) );
1664 gtk_widget_set_tooltip_text( GTK_WIDGET( button ), "Select connected entities" );
1665 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1666 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS );
1667 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1668 gtk_widget_show( GTK_WIDGET( button ) );
1669 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_selectConnected ), 0 );
1670 gtk_box_pack_start( hbox, GTK_WIDGET( button ), FALSE, FALSE, 0 );
1673 GtkWidget* button = gtk_toggle_button_new();
1674 GtkImage* image = GTK_IMAGE( gtk_image_new_from_stock( GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_SMALL_TOOLBAR ) );
1675 gtk_widget_show( GTK_WIDGET( image ) );
1676 gtk_container_add( GTK_CONTAINER( button ), GTK_WIDGET( image ) );
1677 gtk_button_set_relief( GTK_BUTTON( button ), GTK_RELIEF_NONE );
1678 #ifndef GARUX_DISABLE_BUTTON_NOFOCUS
1679 GTK_WIDGET_UNSET_FLAGS( button, GTK_CAN_FOCUS );
1680 #endif // GARUX_DISABLE_BUTTON_NOFOCUS
1681 gtk_box_pack_start( hbox, button, FALSE, FALSE, 0 );
1682 gtk_widget_set_tooltip_text( button, "Focus on Selected" );
1683 gtk_widget_show( button );
1684 g_focusToggleButton = GTK_TOGGLE_BUTTON( button );
1690 auto scr = ui::ScrolledWindow(ui::New);
1692 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1694 auto viewport = ui::Container::from(gtk_viewport_new( 0, 0 ));
1696 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1698 g_attributeBox = ui::VBox( FALSE, 2 );
1699 g_attributeBox.show();
1701 viewport.add(g_attributeBox);
1703 gtk_paned_pack2( GTK_PANED( split0 ), scr, FALSE, FALSE );
1710 // show the sliders in any case //no need, gtk can care
1711 /*if ( g_entitysplit2_position < 22 ) {
1712 g_entitysplit2_position = 22;
1714 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1715 /*if ( ( g_entitysplit1_position - g_entitysplit2_position ) < 27 ) {
1716 g_entitysplit1_position = g_entitysplit2_position + 27;
1718 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1719 gtk_paned_set_position( GTK_PANED( g_entity_split0 ), g_entitysplit0_position );
1722 g_entityInspector_windowConstructed = true;
1723 EntityClassList_fill();
1725 typedef FreeCaller<void(const Selectable&), EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1726 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1727 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1730 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1735 class EntityInspector : public ModuleObserver
1737 std::size_t m_unrealised;
1739 EntityInspector() : m_unrealised( 1 ){
1742 if ( --m_unrealised == 0 ) {
1743 if ( g_entityInspector_windowConstructed ) {
1744 //globalOutputStream() << "Entity Inspector: realise\n";
1745 EntityClassList_fill();
1750 if ( ++m_unrealised == 1 ) {
1751 if ( g_entityInspector_windowConstructed ) {
1752 //globalOutputStream() << "Entity Inspector: unrealise\n";
1753 EntityClassList_clear();
1759 EntityInspector g_EntityInspector;
1761 #include "preferencesystem.h"
1762 #include "stringio.h"
1764 void EntityInspector_construct(){
1765 GlobalEntityClassManager().attach( g_EntityInspector );
1767 GlobalPreferenceSystem().registerPreference( "EntitySplit0", make_property_string( g_entitysplit0_position ) );
1768 GlobalPreferenceSystem().registerPreference( "EntitySplit1", make_property_string( g_entitysplit1_position ) );
1769 GlobalPreferenceSystem().registerPreference( "EntitySplit2", make_property_string( g_entitysplit2_position ) );
1773 void EntityInspector_destroy(){
1774 GlobalEntityClassManager().detach( g_EntityInspector );
1777 const char *EntityInspector_getCurrentKey(){
1778 if ( !GroupDialog_isShown() ) {
1781 if ( GroupDialog_getPage() != g_page_entity ) {
1784 return gtk_entry_get_text( g_entityKeyEntry );