2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "entityinspector.h"
24 #include "debugging/debugging.h"
27 #include "ifilesystem.h"
29 #include "iscenegraph.h"
30 #include "iselection.h"
35 #include <gdk/gdkkeysyms.h>
36 #include <gtk/gtktreemodel.h>
37 #include <gtk/gtktreeview.h>
38 #include <gtk/gtkcellrenderertext.h>
39 #include <gtk/gtktreeselection.h>
40 #include <gtk/gtkliststore.h>
41 #include <gtk/gtktextview.h>
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtktable.h>
44 #include <gtk/gtktogglebutton.h>
45 #include <gtk/gtkcheckbutton.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkvpaned.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkentry.h>
51 #include <gtk/gtkcombobox.h>
55 #include "eclasslib.h"
57 #include "generic/callback.h"
59 #include "stream/stringstream.h"
60 #include "moduleobserver.h"
64 #include "gtkutil/accelerator.h"
65 #include "gtkutil/dialog.h"
66 #include "gtkutil/filechooser.h"
67 #include "gtkutil/messagebox.h"
68 #include "gtkutil/nonmodal.h"
69 #include "gtkutil/button.h"
70 #include "gtkutil/entry.h"
71 #include "gtkutil/container.h"
77 #include "mainframe.h"
78 #include "textureentry.h"
79 #include "groupdialog.h"
81 GtkEntry* numeric_entry_new()
83 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
84 gtk_widget_show(GTK_WIDGET(entry));
85 gtk_widget_set_size_request(GTK_WIDGET(entry), 64, -1);
91 typedef std::map<CopiedString, CopiedString> KeyValues;
92 KeyValues g_selectedKeyValues;
93 KeyValues g_selectedDefaultKeyValues;
96 const char* SelectedEntity_getValueForKey(const char* key)
99 KeyValues::const_iterator i = g_selectedKeyValues.find(key);
100 if(i != g_selectedKeyValues.end())
102 return (*i).second.c_str();
106 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find(key);
107 if(i != g_selectedDefaultKeyValues.end())
109 return (*i).second.c_str();
115 void Scene_EntitySetKeyValue_Selected_Undoable(const char* key, const char* value)
117 StringOutputStream command(256);
118 command << "entitySetKeyValue -key " << makeQuoted(key) << " -value " << makeQuoted(value);
119 UndoableCommand undo(command.c_str());
120 Scene_EntitySetKeyValue_Selected(key, value);
123 class EntityAttribute
126 virtual GtkWidget* getWidget() const = 0;
127 virtual void update() = 0;
128 virtual void release() = 0;
131 class BooleanAttribute : public EntityAttribute
134 GtkCheckButton* m_check;
136 static gboolean toggled(GtkWidget *widget, BooleanAttribute* self)
142 BooleanAttribute(const char* key) :
146 GtkCheckButton* check = GTK_CHECK_BUTTON(gtk_check_button_new());
147 gtk_widget_show(GTK_WIDGET(check));
151 guint handler = g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(toggled), this);
152 g_object_set_data(G_OBJECT(check), "handler", gint_to_pointer(handler));
156 GtkWidget* getWidget() const
158 return GTK_WIDGET(m_check);
166 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_check)) ? "1" : "0");
168 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
172 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
173 if(!string_empty(value))
175 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(m_check), atoi(value) != 0);
179 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(m_check), false);
182 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
186 class StringAttribute : public EntityAttribute
190 NonModalEntry m_nonModal;
192 StringAttribute(const char* key) :
195 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
197 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
198 gtk_widget_show(GTK_WIDGET(entry));
199 gtk_widget_set_size_request(GTK_WIDGET(entry), 50, -1);
202 m_nonModal.connect(m_entry);
204 GtkWidget* getWidget() const
206 return GTK_WIDGET(m_entry);
208 GtkEntry* getEntry() const
219 StringOutputStream value(64);
220 value << gtk_entry_get_text(m_entry);
221 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), value.c_str());
223 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
227 StringOutputStream value(64);
228 value << SelectedEntity_getValueForKey(m_key.c_str());
229 gtk_entry_set_text(m_entry, value.c_str());
231 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
234 class ShaderAttribute : public StringAttribute
237 ShaderAttribute(const char* key) : StringAttribute(key)
239 GlobalShaderEntryCompletion::instance().connect(StringAttribute::getEntry());
244 class ModelAttribute : public EntityAttribute
247 BrowsedPathEntry m_entry;
248 NonModalEntry m_nonModal;
250 ModelAttribute(const char* key) :
252 m_entry(BrowseCaller(*this)),
253 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
255 m_nonModal.connect(m_entry.m_entry.m_entry);
261 GtkWidget* getWidget() const
263 return GTK_WIDGET(m_entry.m_entry.m_frame);
267 StringOutputStream value(64);
268 value << gtk_entry_get_text(GTK_ENTRY(m_entry.m_entry.m_entry));
269 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), value.c_str());
271 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
274 StringOutputStream value(64);
275 value << SelectedEntity_getValueForKey(m_key.c_str());
276 gtk_entry_set_text(GTK_ENTRY(m_entry.m_entry.m_entry), value.c_str());
278 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
279 void browse(const BrowsedPathEntry::SetPathCallback& setPath)
281 const char *filename = misc_model_dialog(gtk_widget_get_toplevel(GTK_WIDGET(m_entry.m_entry.m_frame)));
289 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
292 const char* browse_sound(GtkWidget* parent)
294 StringOutputStream buffer(1024);
296 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
298 if(!file_readable(buffer.c_str()))
302 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
305 const char* filename = file_dialog(parent, TRUE, "Open Wav File", buffer.c_str(), "sound");
308 const char* relative = path_make_relative(filename, GlobalFileSystem().findRoot(filename));
309 if(relative == filename)
311 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
318 class SoundAttribute : public EntityAttribute
321 BrowsedPathEntry m_entry;
322 NonModalEntry m_nonModal;
324 SoundAttribute(const char* key) :
326 m_entry(BrowseCaller(*this)),
327 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
329 m_nonModal.connect(m_entry.m_entry.m_entry);
335 GtkWidget* getWidget() const
337 return GTK_WIDGET(m_entry.m_entry.m_frame);
341 StringOutputStream value(64);
342 value << gtk_entry_get_text(GTK_ENTRY(m_entry.m_entry.m_entry));
343 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), value.c_str());
345 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
348 StringOutputStream value(64);
349 value << SelectedEntity_getValueForKey(m_key.c_str());
350 gtk_entry_set_text(GTK_ENTRY(m_entry.m_entry.m_entry), value.c_str());
352 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
353 void browse(const BrowsedPathEntry::SetPathCallback& setPath)
355 const char *filename = browse_sound(gtk_widget_get_toplevel(GTK_WIDGET(m_entry.m_entry.m_frame)));
363 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
366 inline double angle_normalised(double angle)
368 return float_mod(angle, 360.0);
371 class AngleAttribute : public EntityAttribute
375 NonModalEntry m_nonModal;
377 AngleAttribute(const char* key) :
380 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
382 GtkEntry* entry = numeric_entry_new();
384 m_nonModal.connect(m_entry);
390 GtkWidget* getWidget() const
392 return GTK_WIDGET(m_entry);
396 StringOutputStream angle(32);
397 angle << angle_normalised(entry_get_float(m_entry));
398 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), angle.c_str());
400 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
404 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
405 if(!string_empty(value))
407 StringOutputStream angle(32);
408 angle << angle_normalised(atof(value));
409 gtk_entry_set_text(m_entry, angle.c_str());
413 gtk_entry_set_text(m_entry, "0");
416 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
421 typedef const char* String;
422 const String buttons[] = { "up", "down", "z-axis" };
425 class DirectionAttribute : public EntityAttribute
429 NonModalEntry m_nonModal;
431 NonModalRadio m_nonModalRadio;
434 DirectionAttribute(const char* key) :
437 m_nonModal(ApplyCaller(*this), UpdateCaller(*this)),
438 m_radio(RadioHBox_new(STRING_ARRAY_RANGE(buttons))),
439 m_nonModalRadio(ApplyRadioCaller(*this))
441 GtkEntry* entry = numeric_entry_new();
443 m_nonModal.connect(m_entry);
445 m_nonModalRadio.connect(m_radio.m_radio);
447 m_hbox = GTK_HBOX(gtk_hbox_new(FALSE, 4));
448 gtk_widget_show(GTK_WIDGET(m_hbox));
450 gtk_box_pack_start(GTK_BOX(m_hbox), GTK_WIDGET(m_radio.m_hbox), TRUE, TRUE, 0);
451 gtk_box_pack_start(GTK_BOX(m_hbox), GTK_WIDGET(m_entry), TRUE, TRUE, 0);
457 GtkWidget* getWidget() const
459 return GTK_WIDGET(m_hbox);
463 StringOutputStream angle(32);
464 angle << angle_normalised(entry_get_float(m_entry));
465 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), angle.c_str());
467 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
471 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
472 if(!string_empty(value))
474 float f = float(atof(value));
477 gtk_widget_set_sensitive(GTK_WIDGET(m_entry), FALSE);
478 radio_button_set_active_no_signal(m_radio.m_radio, 0);
479 gtk_entry_set_text(m_entry, "");
483 gtk_widget_set_sensitive(GTK_WIDGET(m_entry), FALSE);
484 radio_button_set_active_no_signal(m_radio.m_radio, 1);
485 gtk_entry_set_text(m_entry, "");
489 gtk_widget_set_sensitive(GTK_WIDGET(m_entry), TRUE);
490 radio_button_set_active_no_signal(m_radio.m_radio, 2);
491 StringOutputStream angle(32);
492 angle << angle_normalised(f);
493 gtk_entry_set_text(m_entry, angle.c_str());
498 gtk_entry_set_text(m_entry, "0");
501 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
505 int index = radio_button_get_active(m_radio.m_radio);
508 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), "-1");
512 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), "-2");
519 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
529 AnglesEntry() : m_roll(0), m_pitch(0), m_yaw(0)
534 typedef BasicVector3<double> DoubleVector3;
536 class AnglesAttribute : public EntityAttribute
539 AnglesEntry m_angles;
540 NonModalEntry m_nonModal;
543 AnglesAttribute(const char* key) :
545 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
547 m_hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
548 gtk_widget_show(GTK_WIDGET(m_hbox));
550 GtkEntry* entry = numeric_entry_new();
551 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
552 m_angles.m_pitch = entry;
553 m_nonModal.connect(m_angles.m_pitch);
556 GtkEntry* entry = numeric_entry_new();
557 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
558 m_angles.m_yaw = entry;
559 m_nonModal.connect(m_angles.m_yaw);
562 GtkEntry* entry = numeric_entry_new();
563 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
564 m_angles.m_roll = entry;
565 m_nonModal.connect(m_angles.m_roll);
572 GtkWidget* getWidget() const
574 return GTK_WIDGET(m_hbox);
578 StringOutputStream angles(64);
579 angles << angle_normalised(entry_get_float(m_angles.m_pitch))
580 << " " << angle_normalised(entry_get_float(m_angles.m_yaw))
581 << " " << angle_normalised(entry_get_float(m_angles.m_roll));
582 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), angles.c_str());
584 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
588 StringOutputStream angle(32);
589 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
590 if(!string_empty(value))
592 DoubleVector3 pitch_yaw_roll;
593 if(!string_parse_vector3(value, pitch_yaw_roll))
595 pitch_yaw_roll = DoubleVector3(0, 0, 0);
598 angle << angle_normalised(pitch_yaw_roll.x());
599 gtk_entry_set_text(m_angles.m_pitch, angle.c_str());
602 angle << angle_normalised(pitch_yaw_roll.y());
603 gtk_entry_set_text(m_angles.m_yaw, angle.c_str());
606 angle << angle_normalised(pitch_yaw_roll.z());
607 gtk_entry_set_text(m_angles.m_roll, angle.c_str());
612 gtk_entry_set_text(m_angles.m_pitch, "0");
613 gtk_entry_set_text(m_angles.m_yaw, "0");
614 gtk_entry_set_text(m_angles.m_roll, "0");
617 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
626 Vector3Entry() : m_x(0), m_y(0), m_z(0)
631 class Vector3Attribute : public EntityAttribute
634 Vector3Entry m_vector3;
635 NonModalEntry m_nonModal;
638 Vector3Attribute(const char* key) :
640 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
642 m_hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
643 gtk_widget_show(GTK_WIDGET(m_hbox));
645 GtkEntry* entry = numeric_entry_new();
646 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
647 m_vector3.m_x = entry;
648 m_nonModal.connect(m_vector3.m_x);
651 GtkEntry* entry = numeric_entry_new();
652 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
653 m_vector3.m_y = entry;
654 m_nonModal.connect(m_vector3.m_y);
657 GtkEntry* entry = numeric_entry_new();
658 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
659 m_vector3.m_z = entry;
660 m_nonModal.connect(m_vector3.m_z);
667 GtkWidget* getWidget() const
669 return GTK_WIDGET(m_hbox);
673 StringOutputStream vector3(64);
674 vector3 << entry_get_float(m_vector3.m_x)
675 << " " << entry_get_float(m_vector3.m_y)
676 << " " << entry_get_float(m_vector3.m_z);
677 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), vector3.c_str());
679 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
683 StringOutputStream buffer(32);
684 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
685 if(!string_empty(value))
688 if(!string_parse_vector3(value, x_y_z))
690 x_y_z = DoubleVector3(0, 0, 0);
694 gtk_entry_set_text(m_vector3.m_x, buffer.c_str());
698 gtk_entry_set_text(m_vector3.m_y, buffer.c_str());
702 gtk_entry_set_text(m_vector3.m_z, buffer.c_str());
707 gtk_entry_set_text(m_vector3.m_x, "0");
708 gtk_entry_set_text(m_vector3.m_y, "0");
709 gtk_entry_set_text(m_vector3.m_z, "0");
712 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
715 class NonModalComboBox
718 guint m_changedHandler;
720 static gboolean changed(GtkComboBox *widget, NonModalComboBox* self)
727 NonModalComboBox(const Callback& changed) : m_changed(changed), m_changedHandler(0)
730 void connect(GtkComboBox* combo)
732 m_changedHandler = g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(changed), this);
734 void setActive(GtkComboBox* combo, int value)
736 g_signal_handler_disconnect(G_OBJECT(combo), m_changedHandler);
737 gtk_combo_box_set_active(combo, value);
742 class ListAttribute : public EntityAttribute
745 GtkComboBox* m_combo;
746 NonModalComboBox m_nonModal;
747 const ListAttributeType& m_type;
749 ListAttribute(const char* key, const ListAttributeType& type) :
752 m_nonModal(ApplyCaller(*this)),
755 GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
757 for(ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i)
759 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (*i).first.c_str());
762 gtk_widget_show(GTK_WIDGET(combo));
763 m_nonModal.connect(combo);
771 GtkWidget* getWidget() const
773 return GTK_WIDGET(m_combo);
777 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), m_type[gtk_combo_box_get_active(m_combo)].second.c_str());
779 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
783 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
784 ListAttributeType::const_iterator i = m_type.findValue(value);
785 if(i != m_type.end())
787 m_nonModal.setActive(m_combo, static_cast<int>(std::distance(m_type.begin(), i)));
791 m_nonModal.setActive(m_combo, 0);
794 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
800 GtkWidget* g_entity_split1 = 0;
801 GtkWidget* g_entity_split2 = 0;
802 int g_entitysplit1_position;
803 int g_entitysplit2_position;
805 bool g_entityInspector_windowConstructed = false;
807 GtkTreeView* g_entityClassList;
808 GtkTextView* g_entityClassComment;
810 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
812 GtkEntry* g_entityKeyEntry;
813 GtkEntry* g_entityValueEntry;
815 GtkListStore* g_entlist_store;
816 GtkListStore* g_entprops_store;
817 const EntityClass* g_current_flags = 0;
818 const EntityClass* g_current_comment = 0;
819 const EntityClass* g_current_attributes = 0;
821 // the number of active spawnflags
822 int g_spawnflag_count;
823 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
824 int spawn_table[MAX_FLAGS];
825 // we change the layout depending on how many spawn flags we need to display
826 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
827 GtkTable* g_spawnflagsTable;
829 GtkVBox* g_attributeBox = 0;
830 typedef std::vector<EntityAttribute*> EntityAttributes;
831 EntityAttributes g_entityAttributes;
834 void GlobalEntityAttributes_clear()
836 for(EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i)
840 g_entityAttributes.clear();
843 class GetKeyValueVisitor : public Entity::Visitor
845 KeyValues& m_keyvalues;
847 GetKeyValueVisitor(KeyValues& keyvalues)
848 : m_keyvalues(keyvalues)
852 void visit(const char* key, const char* value)
854 m_keyvalues.insert(KeyValues::value_type(CopiedString(key), CopiedString(value)));
859 void Entity_GetKeyValues(const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues)
861 GetKeyValueVisitor visitor(keyvalues);
863 entity.forEachKeyValue(visitor);
865 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
867 for(EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i)
869 defaultValues.insert(KeyValues::value_type((*i).first, (*i).second.m_value));
873 void Entity_GetKeyValues_Selected(KeyValues& keyvalues, KeyValues& defaultValues)
875 class EntityGetKeyValues : public SelectionSystem::Visitor
877 KeyValues& m_keyvalues;
878 KeyValues& m_defaultValues;
879 mutable std::set<Entity*> m_visited;
881 EntityGetKeyValues(KeyValues& keyvalues, KeyValues& defaultValues)
882 : m_keyvalues(keyvalues), m_defaultValues(defaultValues)
885 void visit(scene::Instance& instance) const
887 Entity* entity = Node_getEntity(instance.path().top());
888 if(entity == 0 && instance.path().size() != 1)
890 entity = Node_getEntity(instance.path().parent());
892 if(entity != 0 && m_visited.insert(entity).second)
894 Entity_GetKeyValues(*entity, m_keyvalues, m_defaultValues);
897 } visitor(keyvalues, defaultValues);
898 GlobalSelectionSystem().foreachSelected(visitor);
901 const char* keyvalues_valueforkey(KeyValues& keyvalues, const char* key)
903 KeyValues::iterator i = keyvalues.find(CopiedString(key));
904 if(i != keyvalues.end())
905 return (*i).second.c_str();
909 class EntityClassListStoreAppend : public EntityClassVisitor
913 EntityClassListStoreAppend(GtkListStore* store_) : store(store_)
916 void visit(EntityClass* e)
919 gtk_list_store_append(store, &iter);
920 gtk_list_store_set(store, &iter, 0, e->name(), 1, e, -1);
924 void EntityClassList_fill()
926 EntityClassListStoreAppend append(g_entlist_store);
927 GlobalEntityClassManager().forEach(append);
930 void EntityClassList_clear()
932 gtk_list_store_clear(g_entlist_store);
935 void SetComment(EntityClass* eclass)
937 if(eclass == g_current_comment)
940 g_current_comment = eclass;
942 GtkTextBuffer* buffer = gtk_text_view_get_buffer(g_entityClassComment);
943 gtk_text_buffer_set_text(buffer, eclass->comments(), -1);
946 void SurfaceFlags_setEntityClass(EntityClass* eclass)
948 if(eclass == g_current_flags)
951 g_current_flags = eclass;
953 int spawnflag_count = 0;
956 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
957 for (int i=0 ; i<MAX_FLAGS ; i++)
959 if (eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp(eclass->flagnames[i],"-"))
961 spawn_table[spawnflag_count] = i;
967 // disable all remaining boxes
968 // NOTE: these boxes might not even be on display
970 for (int i = 0; i < g_spawnflag_count; ++i)
972 GtkWidget* widget = GTK_WIDGET(g_entitySpawnflagsCheck[i]);
973 gtk_label_set_text(GTK_LABEL(GTK_BIN(widget)->child), " ");
974 gtk_widget_hide(widget);
975 gtk_widget_ref(widget);
976 gtk_container_remove(GTK_CONTAINER(g_spawnflagsTable), widget);
980 g_spawnflag_count = spawnflag_count;
983 for (int i = 0; i < g_spawnflag_count; ++i)
985 GtkWidget* widget = GTK_WIDGET(g_entitySpawnflagsCheck[i]);
986 gtk_widget_show (widget);
988 StringOutputStream str(16);
989 str << LowerCase(eclass->flagnames[spawn_table[i]]);
991 gtk_table_attach(g_spawnflagsTable, widget, i%4, i%4+1, i/4, i/4+1,
992 (GtkAttachOptions)(GTK_FILL),
993 (GtkAttachOptions)(GTK_FILL), 0, 0);
994 gtk_widget_unref(widget);
996 gtk_label_set_text(GTK_LABEL(GTK_BIN(widget)->child), str.c_str());
1001 void EntityClassList_selectEntityClass(EntityClass* eclass)
1003 GtkTreeModel* model = GTK_TREE_MODEL(g_entlist_store);
1005 for(gboolean good = gtk_tree_model_get_iter_first(model, &iter); good != FALSE; good = gtk_tree_model_iter_next(model, &iter))
1008 gtk_tree_model_get(model, &iter, 0, &text, -1);
1009 if (strcmp (text, eclass->name()) == 0)
1011 GtkTreeView* view = g_entityClassList;
1012 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
1013 gtk_tree_selection_select_path(gtk_tree_view_get_selection(view), path);
1014 if(GTK_WIDGET_REALIZED(view))
1016 gtk_tree_view_scroll_to_cell(view, path, 0, FALSE, 0, 0);
1018 gtk_tree_path_free(path);
1025 void EntityInspector_appendAttribute(const char* name, EntityAttribute& attribute)
1027 GtkTable* row = DialogRow_new(name, attribute.getWidget());
1028 DialogVBox_packRow(g_attributeBox, GTK_WIDGET(row));
1032 template<typename Attribute>
1033 class StatelessAttributeCreator
1036 static EntityAttribute* create(const char* name)
1038 return new Attribute(name);
1042 class EntityAttributeFactory
1044 typedef EntityAttribute* (*CreateFunc)(const char* name);
1045 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
1046 Creators m_creators;
1048 EntityAttributeFactory()
1050 m_creators.insert(Creators::value_type("string", &StatelessAttributeCreator<StringAttribute>::create));
1051 m_creators.insert(Creators::value_type("color", &StatelessAttributeCreator<StringAttribute>::create));
1052 m_creators.insert(Creators::value_type("integer", &StatelessAttributeCreator<StringAttribute>::create));
1053 m_creators.insert(Creators::value_type("real", &StatelessAttributeCreator<StringAttribute>::create));
1054 m_creators.insert(Creators::value_type("shader", &StatelessAttributeCreator<ShaderAttribute>::create));
1055 m_creators.insert(Creators::value_type("boolean", &StatelessAttributeCreator<BooleanAttribute>::create));
1056 m_creators.insert(Creators::value_type("angle", &StatelessAttributeCreator<AngleAttribute>::create));
1057 m_creators.insert(Creators::value_type("direction", &StatelessAttributeCreator<DirectionAttribute>::create));
1058 m_creators.insert(Creators::value_type("angles", &StatelessAttributeCreator<AnglesAttribute>::create));
1059 m_creators.insert(Creators::value_type("model", &StatelessAttributeCreator<ModelAttribute>::create));
1060 m_creators.insert(Creators::value_type("sound", &StatelessAttributeCreator<SoundAttribute>::create));
1061 m_creators.insert(Creators::value_type("vector3", &StatelessAttributeCreator<Vector3Attribute>::create));
1062 m_creators.insert(Creators::value_type("real3", &StatelessAttributeCreator<Vector3Attribute>::create));
1064 EntityAttribute* create(const char* type, const char* name)
1066 Creators::iterator i = m_creators.find(type);
1067 if(i != m_creators.end())
1069 return (*i).second(name);
1071 const ListAttributeType* listType = GlobalEntityClassManager().findListType(type);
1074 return new ListAttribute(name, *listType);
1080 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
1082 void EntityInspector_setEntityClass(EntityClass *eclass)
1084 EntityClassList_selectEntityClass(eclass);
1085 SurfaceFlags_setEntityClass(eclass);
1087 if(eclass != g_current_attributes)
1089 g_current_attributes = eclass;
1091 container_remove_all(GTK_CONTAINER(g_attributeBox));
1092 GlobalEntityAttributes_clear();
1094 for(EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i)
1096 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create((*i).second.m_type.c_str(), (*i).first.c_str());
1099 g_entityAttributes.push_back(attribute);
1100 EntityInspector_appendAttribute(EntityClassAttributePair_getName(*i), *g_entityAttributes.back());
1106 void EntityInspector_updateSpawnflags()
1109 int f = atoi(SelectedEntity_getValueForKey("spawnflags"));
1110 for (int i = 0; i < g_spawnflag_count; ++i)
1112 int v = !!(f&(1<<spawn_table[i]));
1114 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(g_entitySpawnflagsCheck[i]), v);
1118 // take care of the remaining ones
1119 for (int i = g_spawnflag_count; i < MAX_FLAGS; ++i)
1121 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(g_entitySpawnflagsCheck[i]), FALSE);
1126 void EntityInspector_applySpawnflags()
1132 for (i = 0; i < g_spawnflag_count; ++i)
1134 v = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_entitySpawnflagsCheck[i]));
1135 f |= v<<spawn_table[i];
1138 sprintf (sz, "%i", f);
1139 const char* value = (f == 0) ? "" : sz;
1142 StringOutputStream command;
1143 command << "entitySetFlags -flags " << f;
1144 UndoableCommand undo("entitySetSpawnflags");
1146 Scene_EntitySetKeyValue_Selected("spawnflags", value);
1151 void EntityInspector_updateKeyValues()
1153 g_selectedKeyValues.clear();
1154 g_selectedDefaultKeyValues.clear();
1155 Entity_GetKeyValues_Selected(g_selectedKeyValues, g_selectedDefaultKeyValues);
1157 EntityInspector_setEntityClass(GlobalEntityClassManager().findOrInsert(keyvalues_valueforkey(g_selectedKeyValues, "classname"), false));
1159 EntityInspector_updateSpawnflags();
1161 GtkListStore* store = g_entprops_store;
1163 // save current key/val pair around filling epair box
1164 // row_select wipes it and sets to first in list
1165 CopiedString strKey(gtk_entry_get_text(g_entityKeyEntry));
1166 CopiedString strVal(gtk_entry_get_text(g_entityValueEntry));
1168 gtk_list_store_clear(store);
1169 // Walk through list and add pairs
1170 for(KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i)
1173 gtk_list_store_append(store, &iter);
1174 StringOutputStream key(64);
1175 key << (*i).first.c_str();
1176 StringOutputStream value(64);
1177 value << (*i).second.c_str();
1178 gtk_list_store_set(store, &iter, 0, key.c_str(), 1, value.c_str(), -1);
1181 gtk_entry_set_text(g_entityKeyEntry, strKey.c_str());
1182 gtk_entry_set_text(g_entityValueEntry, strVal.c_str());
1184 for(EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i)
1190 class EntityInspectorDraw
1192 IdleDraw m_idleDraw;
1194 EntityInspectorDraw() : m_idleDraw(FreeCaller<EntityInspector_updateKeyValues>())
1199 m_idleDraw.queueDraw();
1203 EntityInspectorDraw g_EntityInspectorDraw;
1206 void EntityInspector_keyValueChanged()
1208 g_EntityInspectorDraw.queueDraw();
1210 void EntityInspector_selectionChanged(const Selectable&)
1212 EntityInspector_keyValueChanged();
1215 // Creates a new entity based on the currently selected brush and entity type.
1217 void EntityClassList_createEntity()
1219 GtkTreeView* view = g_entityClassList;
1221 // find out what type of entity we are trying to create
1222 GtkTreeModel* model;
1224 if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(view), &model, &iter) == FALSE)
1226 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityClassList)), "You must have a selected class to create an entity", "info");
1231 gtk_tree_model_get(model, &iter, 0, &text, -1);
1234 StringOutputStream command;
1235 command << "entityCreate -class " << text;
1237 UndoableCommand undo(command.c_str());
1239 Entity_createFromSelection(text, g_vector3_identity);
1244 void EntityInspector_applyKeyValue()
1246 // Get current selection text
1247 StringOutputStream key(64);
1248 key << gtk_entry_get_text(g_entityKeyEntry);
1249 StringOutputStream value(64);
1250 value << gtk_entry_get_text(g_entityValueEntry);
1253 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1254 if (!strcmp(key.c_str(), "classname") && !strcmp(value.c_str(), "worldspawn"))
1256 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityKeyEntry)), "Cannot change \"classname\" key back to worldspawn.", 0, eMB_OK );
1261 // RR2DO2: we don't want spaces in entity keys
1262 if (strstr( key.c_str(), " " ))
1264 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityKeyEntry)), "No spaces are allowed in entity keys.", 0, eMB_OK );
1268 if(strcmp(key.c_str(), "classname") == 0)
1270 StringOutputStream command;
1271 command << "entitySetClass -class " << value.c_str();
1272 UndoableCommand undo(command.c_str());
1273 Scene_EntitySetClassname_Selected(value.c_str());
1277 Scene_EntitySetKeyValue_Selected_Undoable(key.c_str(), value.c_str());
1281 void EntityInspector_clearKeyValue()
1283 // Get current selection text
1284 StringOutputStream key(64);
1285 key << gtk_entry_get_text(g_entityKeyEntry);
1287 if(strcmp(key.c_str(), "classname") != 0)
1289 StringOutputStream command;
1290 command << "entityDeleteKey -key " << key.c_str();
1291 UndoableCommand undo(command.c_str());
1292 Scene_EntitySetKeyValue_Selected(key.c_str(), "");
1296 void EntityInspector_clearAllKeyValues()
1298 UndoableCommand undo("entityClear");
1300 // remove all keys except classname
1301 for(KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i)
1303 if(strcmp((*i).first.c_str(), "classname") != 0)
1305 Scene_EntitySetKeyValue_Selected((*i).first.c_str(), "");
1310 // =============================================================================
1313 static void EntityClassList_selection_changed(GtkTreeSelection* selection, gpointer data)
1315 GtkTreeModel* model;
1316 GtkTreeIter selected;
1317 if(gtk_tree_selection_get_selected(selection, &model, &selected))
1319 EntityClass* eclass;
1320 gtk_tree_model_get(model, &selected, 1, &eclass, -1);
1328 static gint EntityClassList_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
1330 if (event->type == GDK_2BUTTON_PRESS)
1332 EntityClassList_createEntity();
1338 static gint EntityClassList_keypress(GtkWidget* widget, GdkEventKey* event, gpointer data)
1340 unsigned int code = gdk_keyval_to_upper (event->keyval);
1342 if (event->keyval == GDK_Return)
1344 EntityClassList_createEntity();
1348 // select the entity that starts with the key pressed
1349 if (code <= 'Z' && code >= 'A')
1351 GtkTreeView* view = g_entityClassList;
1352 GtkTreeModel* model;
1354 if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(view), &model, &iter) == FALSE
1355 || gtk_tree_model_iter_next(model, &iter) == FALSE)
1357 gtk_tree_model_get_iter_first(model, &iter);
1360 for(std::size_t count = gtk_tree_model_iter_n_children(model, 0); count > 0; --count)
1363 gtk_tree_model_get(model, &iter, 0, &text, -1);
1365 if (toupper (text[0]) == (int)code)
1367 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
1368 gtk_tree_selection_select_path(gtk_tree_view_get_selection(view), path);
1369 if(GTK_WIDGET_REALIZED(view))
1371 gtk_tree_view_scroll_to_cell(view, path, 0, FALSE, 0, 0);
1373 gtk_tree_path_free(path);
1379 if(gtk_tree_model_iter_next(model, &iter) == FALSE)
1380 gtk_tree_model_get_iter_first(model, &iter);
1388 static void EntityProperties_selection_changed(GtkTreeSelection* selection, gpointer data)
1390 // find out what type of entity we are trying to create
1391 GtkTreeModel* model;
1393 if(gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE)
1400 gtk_tree_model_get(model, &iter, 0, &key, 1, &val, -1);
1402 gtk_entry_set_text(g_entityKeyEntry, key);
1403 gtk_entry_set_text(g_entityValueEntry, val);
1409 static void SpawnflagCheck_toggled(GtkWidget *widget, gpointer data)
1411 EntityInspector_applySpawnflags();
1414 static gint EntityEntry_keypress(GtkEntry* widget, GdkEventKey* event, gpointer data)
1416 if (event->keyval == GDK_Return)
1418 if(widget == g_entityKeyEntry)
1420 gtk_entry_set_text(g_entityValueEntry, "");
1421 gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), GTK_WIDGET(g_entityValueEntry));
1425 EntityInspector_applyKeyValue();
1429 if (event->keyval == GDK_Escape)
1431 gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), NULL);
1438 void EntityInspector_destroyWindow(GtkWidget* widget, gpointer data)
1440 g_entitysplit1_position = gtk_paned_get_position(GTK_PANED(g_entity_split1));
1441 g_entitysplit2_position = gtk_paned_get_position(GTK_PANED(g_entity_split2));
1443 g_entityInspector_windowConstructed = false;
1444 GlobalEntityAttributes_clear();
1447 GtkWidget* EntityInspector_constructWindow(GtkWindow* toplevel)
1449 GtkWidget* vbox = gtk_vbox_new(FALSE, 2);
1450 gtk_widget_show (vbox);
1451 gtk_container_set_border_width(GTK_CONTAINER (vbox), 2);
1453 g_signal_connect(G_OBJECT(vbox), "destroy", G_CALLBACK(EntityInspector_destroyWindow), 0);
1456 GtkWidget* split1 = gtk_vpaned_new();
1457 gtk_box_pack_start(GTK_BOX(vbox), split1, TRUE, TRUE, 0);
1458 gtk_widget_show (split1);
1460 g_entity_split1 = split1;
1463 GtkWidget* split2 = gtk_vpaned_new();
1464 gtk_paned_add1 (GTK_PANED (split1), split2);
1465 gtk_widget_show (split2);
1467 g_entity_split2 = split2;
1471 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1472 gtk_widget_show (scr);
1473 gtk_paned_add1 (GTK_PANED (split2), scr);
1474 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1475 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1478 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
1480 GtkTreeView* view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1481 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), FALSE);
1482 gtk_tree_view_set_headers_visible(view, FALSE);
1483 g_signal_connect(G_OBJECT(view), "button_press_event", G_CALLBACK(EntityClassList_button_press), 0);
1484 g_signal_connect(G_OBJECT(view), "key_press_event", G_CALLBACK(EntityClassList_keypress), 0);
1487 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1488 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("Key", renderer, "text", 0, 0);
1489 gtk_tree_view_append_column(view, column);
1493 GtkTreeSelection* selection = gtk_tree_view_get_selection(view);
1494 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(EntityClassList_selection_changed), 0);
1497 gtk_widget_show(GTK_WIDGET(view));
1499 gtk_container_add(GTK_CONTAINER(scr), GTK_WIDGET(view));
1501 g_object_unref(G_OBJECT(store));
1502 g_entityClassList = view;
1503 g_entlist_store = store;
1508 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1509 gtk_widget_show (scr);
1510 gtk_paned_add2 (GTK_PANED (split2), scr);
1511 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1512 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1515 GtkTextView* text = GTK_TEXT_VIEW(gtk_text_view_new());
1516 gtk_widget_set_size_request(GTK_WIDGET(text), 0, -1); // allow shrinking
1517 gtk_text_view_set_wrap_mode(text, GTK_WRAP_WORD);
1518 gtk_text_view_set_editable(text, FALSE);
1519 gtk_widget_show(GTK_WIDGET(text));
1520 gtk_container_add(GTK_CONTAINER(scr), GTK_WIDGET(text));
1521 g_entityClassComment = text;
1527 GtkWidget* split2 = gtk_vpaned_new();
1528 gtk_paned_add2 (GTK_PANED (split1), split2);
1529 gtk_widget_show(split2);
1532 GtkWidget* vbox2 = gtk_vbox_new (FALSE, 2);
1533 gtk_widget_show (vbox2);
1534 gtk_paned_pack1(GTK_PANED(split2), vbox2, FALSE, FALSE);
1537 // Spawnflags (4 colums wide max, or window gets too wide.)
1538 GtkTable* table = GTK_TABLE(gtk_table_new(4, 4, FALSE));
1539 gtk_box_pack_start (GTK_BOX (vbox2), GTK_WIDGET(table), FALSE, TRUE, 0);
1540 gtk_widget_show(GTK_WIDGET(table));
1542 g_spawnflagsTable = table;
1544 for (int i = 0; i < MAX_FLAGS; i++)
1546 GtkCheckButton* check = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(""));
1547 gtk_widget_ref(GTK_WIDGET(check));
1548 g_object_set_data(G_OBJECT(check), "handler", gint_to_pointer(g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(SpawnflagCheck_toggled), 0)));
1549 g_entitySpawnflagsCheck[i] = check;
1555 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1556 gtk_widget_show (scr);
1557 gtk_box_pack_start (GTK_BOX (vbox2), scr, TRUE, TRUE, 0);
1558 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1559 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1562 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
1564 GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1565 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), FALSE);
1566 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
1569 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1570 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, 0);
1571 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1575 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1576 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 1, 0);
1577 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1581 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1582 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(EntityProperties_selection_changed), 0);
1585 gtk_widget_show(view);
1587 gtk_container_add(GTK_CONTAINER (scr), view);
1589 g_object_unref(G_OBJECT(store));
1591 g_entprops_store = store;
1597 GtkTable* table = GTK_TABLE(gtk_table_new(2, 2, FALSE));
1598 gtk_widget_show(GTK_WIDGET(table));
1599 gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(table), FALSE, TRUE, 0);
1600 gtk_table_set_row_spacings(table, 3);
1601 gtk_table_set_col_spacings(table, 5);
1604 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
1605 gtk_widget_show(GTK_WIDGET(entry));
1606 gtk_table_attach(table, GTK_WIDGET(entry), 1, 2, 0, 1,
1607 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
1608 (GtkAttachOptions)(0), 0, 0);
1609 gtk_widget_set_events(GTK_WIDGET(entry), GDK_KEY_PRESS_MASK);
1610 g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(EntityEntry_keypress), 0);
1611 g_entityKeyEntry = entry;
1615 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
1616 gtk_widget_show(GTK_WIDGET(entry));
1617 gtk_table_attach(table, GTK_WIDGET(entry), 1, 2, 1, 2,
1618 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
1619 (GtkAttachOptions)(0), 0, 0);
1620 gtk_widget_set_events(GTK_WIDGET(entry), GDK_KEY_PRESS_MASK);
1621 g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(EntityEntry_keypress), 0);
1622 g_entityValueEntry = entry;
1626 GtkLabel* label = GTK_LABEL(gtk_label_new("Value"));
1627 gtk_widget_show(GTK_WIDGET(label));
1628 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 1, 2,
1629 (GtkAttachOptions)(GTK_FILL),
1630 (GtkAttachOptions)(0), 0, 0);
1631 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1635 GtkLabel* label = GTK_LABEL(gtk_label_new("Key"));
1636 gtk_widget_show(GTK_WIDGET(label));
1637 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 0, 1,
1638 (GtkAttachOptions)(GTK_FILL),
1639 (GtkAttachOptions)(0), 0, 0);
1640 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1645 GtkBox* hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
1646 gtk_widget_show(GTK_WIDGET(hbox));
1647 gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(hbox), FALSE, TRUE, 0);
1650 GtkButton* button = GTK_BUTTON(gtk_button_new_with_label("Clear All"));
1651 gtk_widget_show(GTK_WIDGET(button));
1652 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(EntityInspector_clearAllKeyValues), 0);
1653 gtk_box_pack_start(hbox, GTK_WIDGET(button), TRUE, TRUE, 0);
1656 GtkButton* button = GTK_BUTTON(gtk_button_new_with_label("Delete Key"));
1657 gtk_widget_show(GTK_WIDGET(button));
1658 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(EntityInspector_clearKeyValue), 0);
1659 gtk_box_pack_start(hbox, GTK_WIDGET(button), TRUE, TRUE, 0);
1665 GtkWidget* scr = gtk_scrolled_window_new(0, 0);
1666 gtk_widget_show(scr);
1667 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scr), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1669 GtkWidget* viewport = gtk_viewport_new(0, 0);
1670 gtk_widget_show(viewport);
1671 gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
1673 g_attributeBox = GTK_VBOX(gtk_vbox_new(FALSE, 2));
1674 gtk_widget_show(GTK_WIDGET(g_attributeBox));
1676 gtk_container_add(GTK_CONTAINER(viewport), GTK_WIDGET(g_attributeBox));
1677 gtk_container_add(GTK_CONTAINER(scr), viewport);
1678 gtk_paned_pack2(GTK_PANED(split2), scr, FALSE, FALSE);
1685 // show the sliders in any case
1686 if(g_entitysplit2_position > 22)
1688 gtk_paned_set_position (GTK_PANED(g_entity_split2), g_entitysplit2_position);
1690 g_entitysplit2_position = 22;
1691 gtk_paned_set_position (GTK_PANED(g_entity_split2), 22);
1693 if((g_entitysplit1_position - g_entitysplit2_position) > 27)
1695 gtk_paned_set_position (GTK_PANED(g_entity_split1), g_entitysplit1_position);
1697 gtk_paned_set_position (GTK_PANED(g_entity_split1), g_entitysplit2_position + 27);
1701 g_entityInspector_windowConstructed = true;
1702 EntityClassList_fill();
1704 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1705 GlobalSelectionSystem().addSelectionChangeCallback(EntityInspectorSelectionChangedCaller());
1706 GlobalEntityCreator().setKeyValueChangedFunc(EntityInspector_keyValueChanged);
1709 gtk_container_set_focus_chain(GTK_CONTAINER(vbox), NULL);
1714 class EntityInspector : public ModuleObserver
1716 std::size_t m_unrealised;
1718 EntityInspector() : m_unrealised(1)
1723 if(--m_unrealised == 0)
1725 if(g_entityInspector_windowConstructed)
1727 //globalOutputStream() << "Entity Inspector: realise\n";
1728 EntityClassList_fill();
1734 if(++m_unrealised == 1)
1736 if(g_entityInspector_windowConstructed)
1738 //globalOutputStream() << "Entity Inspector: unrealise\n";
1739 EntityClassList_clear();
1745 EntityInspector g_EntityInspector;
1747 #include "preferencesystem.h"
1748 #include "stringio.h"
1750 void EntityInspector_construct()
1752 GlobalEntityClassManager().attach(g_EntityInspector);
1754 GlobalPreferenceSystem().registerPreference("EntitySplit1", IntImportStringCaller(g_entitysplit1_position), IntExportStringCaller(g_entitysplit1_position));
1755 GlobalPreferenceSystem().registerPreference("EntitySplit2", IntImportStringCaller(g_entitysplit2_position), IntExportStringCaller(g_entitysplit2_position));
1759 void EntityInspector_destroy()
1761 GlobalEntityClassManager().detach(g_EntityInspector);
1764 const char *EntityInspector_getCurrentKey()
1766 if(!GroupDialog_isShown())
1768 if(GroupDialog_getPage() != g_page_entity)
1770 return gtk_entry_get_text(g_entityKeyEntry);