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"
80 GtkEntry* numeric_entry_new()
82 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
83 gtk_widget_show(GTK_WIDGET(entry));
84 gtk_widget_set_size_request(GTK_WIDGET(entry), 64, -1);
90 typedef std::map<CopiedString, CopiedString> KeyValues;
91 KeyValues g_selectedKeyValues;
92 KeyValues g_selectedDefaultKeyValues;
95 const char* SelectedEntity_getValueForKey(const char* key)
98 KeyValues::const_iterator i = g_selectedKeyValues.find(key);
99 if(i != g_selectedKeyValues.end())
101 return (*i).second.c_str();
105 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find(key);
106 if(i != g_selectedDefaultKeyValues.end())
108 return (*i).second.c_str();
114 void Scene_EntitySetKeyValue_Selected_Undoable(const char* key, const char* value)
116 StringOutputStream command(256);
117 command << "entitySetKeyValue -key " << makeQuoted(key) << " -value " << makeQuoted(value);
118 UndoableCommand undo(command.c_str());
119 Scene_EntitySetKeyValue_Selected(key, value);
122 class EntityAttribute
125 virtual GtkWidget* getWidget() const = 0;
126 virtual void update() = 0;
127 virtual void release() = 0;
130 class BooleanAttribute : public EntityAttribute
133 GtkCheckButton* m_check;
135 static gboolean toggled(GtkWidget *widget, BooleanAttribute* self)
141 BooleanAttribute(const char* key) :
145 GtkCheckButton* check = GTK_CHECK_BUTTON(gtk_check_button_new());
146 gtk_widget_show(GTK_WIDGET(check));
150 guint handler = g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(toggled), this);
151 g_object_set_data(G_OBJECT(check), "handler", gint_to_pointer(handler));
155 GtkWidget* getWidget() const
157 return GTK_WIDGET(m_check);
165 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_check)) ? "1" : "0");
167 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
171 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
172 if(!string_empty(value))
174 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(m_check), atoi(value) != 0);
178 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(m_check), false);
181 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
185 class StringAttribute : public EntityAttribute
189 NonModalEntry m_nonModal;
191 StringAttribute(const char* key) :
194 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
196 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
197 gtk_widget_show(GTK_WIDGET(entry));
198 gtk_widget_set_size_request(GTK_WIDGET(entry), 50, -1);
201 m_nonModal.connect(m_entry);
203 GtkWidget* getWidget() const
205 return GTK_WIDGET(m_entry);
207 GtkEntry* getEntry() const
218 StringOutputStream value(64);
219 value << ConvertUTF8ToLocale(gtk_entry_get_text(m_entry));
220 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), value.c_str());
222 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
226 StringOutputStream value(64);
227 value << ConvertLocaleToUTF8(SelectedEntity_getValueForKey(m_key.c_str()));
228 gtk_entry_set_text(m_entry, value.c_str());
230 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
233 class ShaderAttribute : public StringAttribute
236 ShaderAttribute(const char* key) : StringAttribute(key)
238 GlobalShaderEntryCompletion::instance().connect(StringAttribute::getEntry());
243 class ModelAttribute : public EntityAttribute
246 BrowsedPathEntry m_entry;
247 NonModalEntry m_nonModal;
249 ModelAttribute(const char* key) :
251 m_entry(BrowseCaller(*this)),
252 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
254 m_nonModal.connect(m_entry.m_entry.m_entry);
260 GtkWidget* getWidget() const
262 return GTK_WIDGET(m_entry.m_entry.m_frame);
266 StringOutputStream value(64);
267 value << ConvertUTF8ToLocale(gtk_entry_get_text(GTK_ENTRY(m_entry.m_entry.m_entry)));
268 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), value.c_str());
270 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
273 StringOutputStream value(64);
274 value << ConvertLocaleToUTF8(SelectedEntity_getValueForKey(m_key.c_str()));
275 gtk_entry_set_text(GTK_ENTRY(m_entry.m_entry.m_entry), value.c_str());
277 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
278 void browse(const BrowsedPathEntry::SetPathCallback& setPath)
280 const char *filename = misc_model_dialog(GTK_WIDGET(m_entry.m_entry.m_frame));
288 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
291 const char* browse_sound(GtkWidget* parent)
293 StringOutputStream buffer(1024);
295 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
297 if(!file_readable(buffer.c_str()))
301 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
304 const char* filename = file_dialog(parent, TRUE, "Open Wav File", buffer.c_str(), "sound");
307 const char* relative = path_make_relative(filename, GlobalFileSystem().findRoot(filename));
308 if(relative == filename)
310 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
317 class SoundAttribute : public EntityAttribute
320 BrowsedPathEntry m_entry;
321 NonModalEntry m_nonModal;
323 SoundAttribute(const char* key) :
325 m_entry(BrowseCaller(*this)),
326 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
328 m_nonModal.connect(m_entry.m_entry.m_entry);
334 GtkWidget* getWidget() const
336 return GTK_WIDGET(m_entry.m_entry.m_frame);
340 StringOutputStream value(64);
341 value << ConvertUTF8ToLocale(gtk_entry_get_text(GTK_ENTRY(m_entry.m_entry.m_entry)));
342 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), value.c_str());
344 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
347 StringOutputStream value(64);
348 value << ConvertLocaleToUTF8(SelectedEntity_getValueForKey(m_key.c_str()));
349 gtk_entry_set_text(GTK_ENTRY(m_entry.m_entry.m_entry), value.c_str());
351 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
352 void browse(const BrowsedPathEntry::SetPathCallback& setPath)
354 const char *filename = browse_sound(gtk_widget_get_toplevel(GTK_WIDGET(m_entry.m_entry.m_frame)));
362 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
365 inline double angle_normalised(double angle)
367 return float_mod(angle, 360.0);
370 class AngleAttribute : public EntityAttribute
374 NonModalEntry m_nonModal;
376 AngleAttribute(const char* key) :
379 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
381 GtkEntry* entry = numeric_entry_new();
383 m_nonModal.connect(m_entry);
389 GtkWidget* getWidget() const
391 return GTK_WIDGET(m_entry);
395 StringOutputStream angle(32);
396 angle << angle_normalised(entry_get_float(m_entry));
397 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), angle.c_str());
399 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
403 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
404 if(!string_empty(value))
406 StringOutputStream angle(32);
407 angle << angle_normalised(atof(value));
408 gtk_entry_set_text(m_entry, angle.c_str());
412 gtk_entry_set_text(m_entry, "0");
415 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
420 typedef const char* String;
421 const String buttons[] = { "up", "down", "z-axis" };
424 class DirectionAttribute : public EntityAttribute
428 NonModalEntry m_nonModal;
430 NonModalRadio m_nonModalRadio;
433 DirectionAttribute(const char* key) :
436 m_nonModal(ApplyCaller(*this), UpdateCaller(*this)),
437 m_radio(RadioHBox_new(STRING_ARRAY_RANGE(buttons))),
438 m_nonModalRadio(ApplyRadioCaller(*this))
440 GtkEntry* entry = numeric_entry_new();
442 m_nonModal.connect(m_entry);
444 m_nonModalRadio.connect(m_radio.m_radio);
446 m_hbox = GTK_HBOX(gtk_hbox_new(FALSE, 4));
447 gtk_widget_show(GTK_WIDGET(m_hbox));
449 gtk_box_pack_start(GTK_BOX(m_hbox), GTK_WIDGET(m_radio.m_hbox), TRUE, TRUE, 0);
450 gtk_box_pack_start(GTK_BOX(m_hbox), GTK_WIDGET(m_entry), TRUE, TRUE, 0);
456 GtkWidget* getWidget() const
458 return GTK_WIDGET(m_hbox);
462 StringOutputStream angle(32);
463 angle << angle_normalised(entry_get_float(m_entry));
464 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), angle.c_str());
466 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
470 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
471 if(!string_empty(value))
473 float f = float(atof(value));
476 gtk_widget_set_sensitive(GTK_WIDGET(m_entry), FALSE);
477 radio_button_set_active_no_signal(m_radio.m_radio, 0);
478 gtk_entry_set_text(m_entry, "");
482 gtk_widget_set_sensitive(GTK_WIDGET(m_entry), FALSE);
483 radio_button_set_active_no_signal(m_radio.m_radio, 1);
484 gtk_entry_set_text(m_entry, "");
488 gtk_widget_set_sensitive(GTK_WIDGET(m_entry), TRUE);
489 radio_button_set_active_no_signal(m_radio.m_radio, 2);
490 StringOutputStream angle(32);
491 angle << angle_normalised(f);
492 gtk_entry_set_text(m_entry, angle.c_str());
497 gtk_entry_set_text(m_entry, "0");
500 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
504 int index = radio_button_get_active(m_radio.m_radio);
507 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), "-1");
511 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), "-2");
518 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
528 AnglesEntry() : m_roll(0), m_pitch(0), m_yaw(0)
533 typedef BasicVector3<double> DoubleVector3;
535 class AnglesAttribute : public EntityAttribute
538 AnglesEntry m_angles;
539 NonModalEntry m_nonModal;
542 AnglesAttribute(const char* key) :
544 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
546 m_hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
547 gtk_widget_show(GTK_WIDGET(m_hbox));
549 GtkEntry* entry = numeric_entry_new();
550 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
551 m_angles.m_pitch = entry;
552 m_nonModal.connect(m_angles.m_pitch);
555 GtkEntry* entry = numeric_entry_new();
556 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
557 m_angles.m_yaw = entry;
558 m_nonModal.connect(m_angles.m_yaw);
561 GtkEntry* entry = numeric_entry_new();
562 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
563 m_angles.m_roll = entry;
564 m_nonModal.connect(m_angles.m_roll);
571 GtkWidget* getWidget() const
573 return GTK_WIDGET(m_hbox);
577 StringOutputStream angles(64);
578 angles << angle_normalised(entry_get_float(m_angles.m_pitch))
579 << " " << angle_normalised(entry_get_float(m_angles.m_yaw))
580 << " " << angle_normalised(entry_get_float(m_angles.m_roll));
581 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), angles.c_str());
583 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
587 StringOutputStream angle(32);
588 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
589 if(!string_empty(value))
591 DoubleVector3 pitch_yaw_roll;
592 if(!string_parse_vector3(value, pitch_yaw_roll))
594 pitch_yaw_roll = DoubleVector3(0, 0, 0);
597 angle << angle_normalised(pitch_yaw_roll.x());
598 gtk_entry_set_text(m_angles.m_pitch, angle.c_str());
601 angle << angle_normalised(pitch_yaw_roll.y());
602 gtk_entry_set_text(m_angles.m_yaw, angle.c_str());
605 angle << angle_normalised(pitch_yaw_roll.z());
606 gtk_entry_set_text(m_angles.m_roll, angle.c_str());
611 gtk_entry_set_text(m_angles.m_pitch, "0");
612 gtk_entry_set_text(m_angles.m_yaw, "0");
613 gtk_entry_set_text(m_angles.m_roll, "0");
616 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
625 Vector3Entry() : m_x(0), m_y(0), m_z(0)
630 class Vector3Attribute : public EntityAttribute
633 Vector3Entry m_vector3;
634 NonModalEntry m_nonModal;
637 Vector3Attribute(const char* key) :
639 m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
641 m_hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
642 gtk_widget_show(GTK_WIDGET(m_hbox));
644 GtkEntry* entry = numeric_entry_new();
645 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
646 m_vector3.m_x = entry;
647 m_nonModal.connect(m_vector3.m_x);
650 GtkEntry* entry = numeric_entry_new();
651 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
652 m_vector3.m_y = entry;
653 m_nonModal.connect(m_vector3.m_y);
656 GtkEntry* entry = numeric_entry_new();
657 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
658 m_vector3.m_z = entry;
659 m_nonModal.connect(m_vector3.m_z);
666 GtkWidget* getWidget() const
668 return GTK_WIDGET(m_hbox);
672 StringOutputStream vector3(64);
673 vector3 << entry_get_float(m_vector3.m_x)
674 << " " << entry_get_float(m_vector3.m_y)
675 << " " << entry_get_float(m_vector3.m_z);
676 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), vector3.c_str());
678 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
682 StringOutputStream buffer(32);
683 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
684 if(!string_empty(value))
687 if(!string_parse_vector3(value, x_y_z))
689 x_y_z = DoubleVector3(0, 0, 0);
693 gtk_entry_set_text(m_vector3.m_x, buffer.c_str());
697 gtk_entry_set_text(m_vector3.m_y, buffer.c_str());
701 gtk_entry_set_text(m_vector3.m_z, buffer.c_str());
706 gtk_entry_set_text(m_vector3.m_x, "0");
707 gtk_entry_set_text(m_vector3.m_y, "0");
708 gtk_entry_set_text(m_vector3.m_z, "0");
711 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
714 class NonModalComboBox
717 guint m_changedHandler;
719 static gboolean changed(GtkComboBox *widget, NonModalComboBox* self)
726 NonModalComboBox(const Callback& changed) : m_changed(changed), m_changedHandler(0)
729 void connect(GtkComboBox* combo)
731 m_changedHandler = g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(changed), this);
733 void setActive(GtkComboBox* combo, int value)
735 g_signal_handler_disconnect(G_OBJECT(combo), m_changedHandler);
736 gtk_combo_box_set_active(combo, value);
741 class ListAttribute : public EntityAttribute
744 GtkComboBox* m_combo;
745 NonModalComboBox m_nonModal;
746 const ListAttributeType& m_type;
748 ListAttribute(const char* key, const ListAttributeType& type) :
751 m_nonModal(ApplyCaller(*this)),
754 GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
756 for(ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i)
758 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (*i).first.c_str());
761 gtk_widget_show(GTK_WIDGET(combo));
762 m_nonModal.connect(combo);
770 GtkWidget* getWidget() const
772 return GTK_WIDGET(m_combo);
776 Scene_EntitySetKeyValue_Selected_Undoable(m_key.c_str(), m_type[gtk_combo_box_get_active(m_combo)].second.c_str());
778 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
782 const char* value = SelectedEntity_getValueForKey(m_key.c_str());
783 ListAttributeType::const_iterator i = m_type.findValue(value);
784 if(i != m_type.end())
786 m_nonModal.setActive(m_combo, static_cast<int>(std::distance(m_type.begin(), i)));
790 m_nonModal.setActive(m_combo, 0);
793 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
799 GtkWidget* g_entity_split1 = 0;
800 GtkWidget* g_entity_split2 = 0;
801 int g_entitysplit1_position;
802 int g_entitysplit2_position;
804 bool g_entityInspector_windowConstructed = false;
806 GtkTreeView* g_entityClassList;
807 GtkTextView* g_entityClassComment;
809 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
811 GtkEntry* g_entityKeyEntry;
812 GtkEntry* g_entityValueEntry;
814 GtkListStore* g_entlist_store;
815 GtkListStore* g_entprops_store;
816 const EntityClass* g_current_flags = 0;
817 const EntityClass* g_current_comment = 0;
818 const EntityClass* g_current_attributes = 0;
820 // the number of active spawnflags
821 int g_spawnflag_count;
822 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
823 int spawn_table[MAX_FLAGS];
824 // we change the layout depending on how many spawn flags we need to display
825 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
826 GtkTable* g_spawnflagsTable;
828 GtkVBox* g_attributeBox = 0;
829 typedef std::vector<EntityAttribute*> EntityAttributes;
830 EntityAttributes g_entityAttributes;
833 void GlobalEntityAttributes_clear()
835 for(EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i)
839 g_entityAttributes.clear();
842 class GetKeyValueVisitor : public Entity::Visitor
844 KeyValues& m_keyvalues;
846 GetKeyValueVisitor(KeyValues& keyvalues)
847 : m_keyvalues(keyvalues)
851 void visit(const char* key, const char* value)
853 m_keyvalues.insert(KeyValues::value_type(CopiedString(key), CopiedString(value)));
858 void Entity_GetKeyValues(const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues)
860 GetKeyValueVisitor visitor(keyvalues);
862 entity.forEachKeyValue(visitor);
864 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
866 for(EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i)
868 defaultValues.insert(KeyValues::value_type((*i).first, (*i).second.m_value));
872 void Entity_GetKeyValues_Selected(KeyValues& keyvalues, KeyValues& defaultValues)
874 class EntityGetKeyValues : public SelectionSystem::Visitor
876 KeyValues& m_keyvalues;
877 KeyValues& m_defaultValues;
878 mutable std::set<Entity*> m_visited;
880 EntityGetKeyValues(KeyValues& keyvalues, KeyValues& defaultValues)
881 : m_keyvalues(keyvalues), m_defaultValues(defaultValues)
884 void visit(scene::Instance& instance) const
886 Entity* entity = Node_getEntity(instance.path().top());
887 if(entity == 0 && instance.path().size() != 1)
889 entity = Node_getEntity(instance.path().parent());
891 if(entity != 0 && m_visited.insert(entity).second)
893 Entity_GetKeyValues(*entity, m_keyvalues, m_defaultValues);
896 } visitor(keyvalues, defaultValues);
897 GlobalSelectionSystem().foreachSelected(visitor);
900 const char* keyvalues_valueforkey(KeyValues& keyvalues, const char* key)
902 KeyValues::iterator i = keyvalues.find(CopiedString(key));
903 if(i != keyvalues.end())
904 return (*i).second.c_str();
908 class EntityClassListStoreAppend : public EntityClassVisitor
912 EntityClassListStoreAppend(GtkListStore* store_) : store(store_)
915 void visit(EntityClass* e)
918 gtk_list_store_append(store, &iter);
919 gtk_list_store_set(store, &iter, 0, e->name(), 1, e, -1);
923 void EntityClassList_fill()
925 EntityClassListStoreAppend append(g_entlist_store);
926 GlobalEntityClassManager().forEach(append);
929 void EntityClassList_clear()
931 gtk_list_store_clear(g_entlist_store);
934 void SetComment(EntityClass* eclass)
936 if(eclass == g_current_comment)
939 g_current_comment = eclass;
941 GtkTextBuffer* buffer = gtk_text_view_get_buffer(g_entityClassComment);
942 gtk_text_buffer_set_text(buffer, eclass->comments(), -1);
945 void SurfaceFlags_setEntityClass(EntityClass* eclass)
947 if(eclass == g_current_flags)
950 g_current_flags = eclass;
952 int spawnflag_count = 0;
955 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
956 for (int i=0 ; i<MAX_FLAGS ; i++)
958 if (eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp(eclass->flagnames[i],"-"))
960 spawn_table[spawnflag_count] = i;
966 // disable all remaining boxes
967 // NOTE: these boxes might not even be on display
969 for (int i = 0; i < g_spawnflag_count; ++i)
971 GtkWidget* widget = GTK_WIDGET(g_entitySpawnflagsCheck[i]);
972 gtk_label_set_text(GTK_LABEL(GTK_BIN(widget)->child), " ");
973 gtk_widget_hide(widget);
974 gtk_widget_ref(widget);
975 gtk_container_remove(GTK_CONTAINER(g_spawnflagsTable), widget);
979 g_spawnflag_count = spawnflag_count;
982 for (int i = 0; i < g_spawnflag_count; ++i)
984 GtkWidget* widget = GTK_WIDGET(g_entitySpawnflagsCheck[i]);
985 gtk_widget_show (widget);
987 StringOutputStream str(16);
988 str << LowerCase(eclass->flagnames[spawn_table[i]]);
990 gtk_table_attach(g_spawnflagsTable, widget, i%4, i%4+1, i/4, i/4+1,
991 (GtkAttachOptions)(GTK_FILL),
992 (GtkAttachOptions)(GTK_FILL), 0, 0);
993 gtk_widget_unref(widget);
995 gtk_label_set_text(GTK_LABEL(GTK_BIN(widget)->child), str.c_str());
1000 void EntityClassList_selectEntityClass(EntityClass* eclass)
1002 GtkTreeModel* model = GTK_TREE_MODEL(g_entlist_store);
1004 for(gboolean good = gtk_tree_model_get_iter_first(model, &iter); good != FALSE; good = gtk_tree_model_iter_next(model, &iter))
1007 gtk_tree_model_get(model, &iter, 0, &text, -1);
1008 if (strcmp (text, eclass->name()) == 0)
1010 GtkTreeView* view = g_entityClassList;
1011 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
1012 gtk_tree_selection_select_path(gtk_tree_view_get_selection(view), path);
1013 gtk_tree_view_scroll_to_cell(view, path, 0, FALSE, 0, 0);
1014 gtk_tree_path_free(path);
1021 void EntityInspector_appendAttribute(const char* name, EntityAttribute& attribute)
1023 GtkTable* row = DialogRow_new(name, attribute.getWidget());
1024 DialogVBox_packRow(g_attributeBox, GTK_WIDGET(row));
1028 template<typename Attribute>
1029 class StatelessAttributeCreator
1032 static EntityAttribute* create(const char* name)
1034 return new Attribute(name);
1038 class EntityAttributeFactory
1040 typedef EntityAttribute* (*CreateFunc)(const char* name);
1041 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
1042 Creators m_creators;
1044 EntityAttributeFactory()
1046 m_creators.insert(Creators::value_type("string", &StatelessAttributeCreator<StringAttribute>::create));
1047 m_creators.insert(Creators::value_type("color", &StatelessAttributeCreator<StringAttribute>::create));
1048 m_creators.insert(Creators::value_type("integer", &StatelessAttributeCreator<StringAttribute>::create));
1049 m_creators.insert(Creators::value_type("real", &StatelessAttributeCreator<StringAttribute>::create));
1050 m_creators.insert(Creators::value_type("shader", &StatelessAttributeCreator<ShaderAttribute>::create));
1051 m_creators.insert(Creators::value_type("boolean", &StatelessAttributeCreator<BooleanAttribute>::create));
1052 m_creators.insert(Creators::value_type("angle", &StatelessAttributeCreator<AngleAttribute>::create));
1053 m_creators.insert(Creators::value_type("direction", &StatelessAttributeCreator<DirectionAttribute>::create));
1054 m_creators.insert(Creators::value_type("angles", &StatelessAttributeCreator<AnglesAttribute>::create));
1055 m_creators.insert(Creators::value_type("model", &StatelessAttributeCreator<ModelAttribute>::create));
1056 m_creators.insert(Creators::value_type("sound", &StatelessAttributeCreator<SoundAttribute>::create));
1057 m_creators.insert(Creators::value_type("vector3", &StatelessAttributeCreator<Vector3Attribute>::create));
1059 EntityAttribute* create(const char* type, const char* name)
1061 Creators::iterator i = m_creators.find(type);
1062 if(i != m_creators.end())
1064 return (*i).second(name);
1066 const ListAttributeType* listType = GlobalEntityClassManager().findListType(type);
1069 return new ListAttribute(name, *listType);
1075 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
1077 void EntityInspector_setEntityClass(EntityClass *eclass)
1079 EntityClassList_selectEntityClass(eclass);
1080 SurfaceFlags_setEntityClass(eclass);
1082 if(eclass != g_current_attributes)
1084 g_current_attributes = eclass;
1086 container_remove_all(GTK_CONTAINER(g_attributeBox));
1087 GlobalEntityAttributes_clear();
1089 for(EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i)
1091 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create((*i).second.m_type.c_str(), (*i).first.c_str());
1094 g_entityAttributes.push_back(attribute);
1095 EntityInspector_appendAttribute(EntityClassAttributePair_getName(*i), *g_entityAttributes.back());
1101 void EntityInspector_updateSpawnflags()
1104 int f = atoi(SelectedEntity_getValueForKey("spawnflags"));
1105 for (int i = 0; i < g_spawnflag_count; ++i)
1107 int v = !!(f&(1<<spawn_table[i]));
1109 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(g_entitySpawnflagsCheck[i]), v);
1113 // take care of the remaining ones
1114 for (int i = g_spawnflag_count; i < MAX_FLAGS; ++i)
1116 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(g_entitySpawnflagsCheck[i]), FALSE);
1121 void EntityInspector_applySpawnflags()
1127 for (i = 0; i < g_spawnflag_count; ++i)
1129 v = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_entitySpawnflagsCheck[i]));
1130 f |= v<<spawn_table[i];
1133 sprintf (sz, "%i", f);
1134 const char* value = (f == 0) ? "" : sz;
1137 StringOutputStream command;
1138 command << "entitySetFlags -flags " << f;
1139 UndoableCommand undo("entitySetSpawnflags");
1141 Scene_EntitySetKeyValue_Selected("spawnflags", value);
1146 void EntityInspector_updateKeyValues()
1148 g_selectedKeyValues.clear();
1149 g_selectedDefaultKeyValues.clear();
1150 Entity_GetKeyValues_Selected(g_selectedKeyValues, g_selectedDefaultKeyValues);
1152 EntityInspector_setEntityClass(GlobalEntityClassManager().findOrInsert(keyvalues_valueforkey(g_selectedKeyValues, "classname"), false));
1154 EntityInspector_updateSpawnflags();
1156 GtkListStore* store = g_entprops_store;
1158 // save current key/val pair around filling epair box
1159 // row_select wipes it and sets to first in list
1160 CopiedString strKey(gtk_entry_get_text(g_entityKeyEntry));
1161 CopiedString strVal(gtk_entry_get_text(g_entityValueEntry));
1163 gtk_list_store_clear(store);
1164 // Walk through list and add pairs
1165 for(KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i)
1168 gtk_list_store_append(store, &iter);
1169 StringOutputStream key(64);
1170 key << ConvertLocaleToUTF8((*i).first.c_str());
1171 StringOutputStream value(64);
1172 value << ConvertLocaleToUTF8((*i).second.c_str());
1173 gtk_list_store_set(store, &iter, 0, key.c_str(), 1, value.c_str(), -1);
1176 gtk_entry_set_text(g_entityKeyEntry, strKey.c_str());
1177 gtk_entry_set_text(g_entityValueEntry, strVal.c_str());
1179 for(EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i)
1185 class EntityInspectorDraw
1187 IdleDraw m_idleDraw;
1189 EntityInspectorDraw() : m_idleDraw(FreeCaller<EntityInspector_updateKeyValues>())
1194 m_idleDraw.queueDraw();
1198 EntityInspectorDraw g_EntityInspectorDraw;
1201 void EntityInspector_keyValueChanged()
1203 g_EntityInspectorDraw.queueDraw();
1205 void EntityInspector_selectionChanged(const Selectable&)
1207 EntityInspector_keyValueChanged();
1210 // Creates a new entity based on the currently selected brush and entity type.
1212 void EntityClassList_createEntity()
1214 GtkTreeView* view = g_entityClassList;
1216 // find out what type of entity we are trying to create
1217 GtkTreeModel* model;
1219 if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(view), &model, &iter) == FALSE)
1221 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityClassList)), "You must have a selected class to create an entity", "info");
1226 gtk_tree_model_get(model, &iter, 0, &text, -1);
1229 StringOutputStream command;
1230 command << "entityCreate -class " << text;
1232 UndoableCommand undo(command.c_str());
1234 Entity_createFromSelection(text, g_vector3_identity);
1239 void EntityInspector_applyKeyValue()
1241 // Get current selection text
1242 StringOutputStream key(64);
1243 key << ConvertUTF8ToLocale(gtk_entry_get_text(g_entityKeyEntry));
1244 StringOutputStream value(64);
1245 value << ConvertUTF8ToLocale(gtk_entry_get_text(g_entityValueEntry));
1248 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1249 if (!strcmp(key.c_str(), "classname") && !strcmp(value.c_str(), "worldspawn"))
1251 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityKeyEntry)), "Cannot change \"classname\" key back to worldspawn.", 0, eMB_OK );
1256 // RR2DO2: we don't want spaces in entity keys
1257 if (strstr( key.c_str(), " " ))
1259 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityKeyEntry)), "No spaces are allowed in entity keys.", 0, eMB_OK );
1263 if(strcmp(key.c_str(), "classname") == 0)
1265 StringOutputStream command;
1266 command << "entitySetClass -class " << value.c_str();
1267 UndoableCommand undo(command.c_str());
1268 Scene_EntitySetClassname_Selected(value.c_str());
1272 Scene_EntitySetKeyValue_Selected_Undoable(key.c_str(), value.c_str());
1276 void EntityInspector_clearKeyValue()
1278 // Get current selection text
1279 StringOutputStream key(64);
1280 key << ConvertUTF8ToLocale(gtk_entry_get_text(g_entityKeyEntry));
1282 if(strcmp(key.c_str(), "classname") != 0)
1284 StringOutputStream command;
1285 command << "entityDeleteKey -key " << key.c_str();
1286 UndoableCommand undo(command.c_str());
1287 Scene_EntitySetKeyValue_Selected(key.c_str(), "");
1291 void EntityInspector_clearAllKeyValues()
1293 UndoableCommand undo("entityClear");
1295 // remove all keys except classname
1296 for(KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i)
1298 if(strcmp((*i).first.c_str(), "classname") != 0)
1300 Scene_EntitySetKeyValue_Selected((*i).first.c_str(), "");
1305 // =============================================================================
1308 static void EntityClassList_selection_changed(GtkTreeSelection* selection, gpointer data)
1310 GtkTreeModel* model;
1311 GtkTreeIter selected;
1312 if(gtk_tree_selection_get_selected(selection, &model, &selected))
1314 EntityClass* eclass;
1315 gtk_tree_model_get(model, &selected, 1, &eclass, -1);
1323 static gint EntityClassList_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
1325 if (event->type == GDK_2BUTTON_PRESS)
1327 EntityClassList_createEntity();
1333 static gint EntityClassList_keypress(GtkWidget* widget, GdkEventKey* event, gpointer data)
1335 unsigned int code = gdk_keyval_to_upper (event->keyval);
1337 if (event->keyval == GDK_Return)
1339 EntityClassList_createEntity();
1343 // select the entity that starts with the key pressed
1344 if (code <= 'Z' && code >= 'A')
1346 GtkTreeView* view = g_entityClassList;
1347 GtkTreeModel* model;
1349 if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(view), &model, &iter) == FALSE
1350 || gtk_tree_model_iter_next(model, &iter) == FALSE)
1352 gtk_tree_model_get_iter_first(model, &iter);
1355 for(std::size_t count = gtk_tree_model_iter_n_children(model, 0); count > 0; --count)
1358 gtk_tree_model_get(model, &iter, 0, &text, -1);
1360 if (toupper (text[0]) == (int)code)
1362 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
1363 gtk_tree_selection_select_path(gtk_tree_view_get_selection(view), path);
1364 gtk_tree_view_scroll_to_cell(view, path, 0, FALSE, 0, 0);
1365 gtk_tree_path_free(path);
1371 if(gtk_tree_model_iter_next(model, &iter) == FALSE)
1372 gtk_tree_model_get_iter_first(model, &iter);
1380 static void EntityProperties_selection_changed(GtkTreeSelection* selection, gpointer data)
1382 // find out what type of entity we are trying to create
1383 GtkTreeModel* model;
1385 if(gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE)
1392 gtk_tree_model_get(model, &iter, 0, &key, 1, &val, -1);
1394 gtk_entry_set_text(g_entityKeyEntry, key);
1395 gtk_entry_set_text(g_entityValueEntry, val);
1401 static void SpawnflagCheck_toggled(GtkWidget *widget, gpointer data)
1403 EntityInspector_applySpawnflags();
1406 static gint EntityEntry_keypress(GtkEntry* widget, GdkEventKey* event, gpointer data)
1408 if (event->keyval == GDK_Return)
1410 if(widget == g_entityKeyEntry)
1412 gtk_entry_set_text(g_entityValueEntry, "");
1413 gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), GTK_WIDGET(g_entityValueEntry));
1417 EntityInspector_applyKeyValue();
1421 if (event->keyval == GDK_Escape)
1423 gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), NULL);
1430 void EntityInspector_destroyWindow(GtkWidget* widget, gpointer data)
1432 g_entitysplit1_position = gtk_paned_get_position(GTK_PANED(g_entity_split1));
1433 g_entitysplit2_position = gtk_paned_get_position(GTK_PANED(g_entity_split2));
1435 g_entityInspector_windowConstructed = false;
1436 GlobalEntityAttributes_clear();
1439 GtkWidget* EntityInspector_constructWindow(GtkWindow* toplevel)
1441 GtkWidget* vbox = gtk_vbox_new(FALSE, 2);
1442 gtk_widget_show (vbox);
1443 gtk_container_set_border_width(GTK_CONTAINER (vbox), 2);
1445 g_signal_connect(G_OBJECT(vbox), "destroy", G_CALLBACK(EntityInspector_destroyWindow), 0);
1448 GtkWidget* split1 = gtk_vpaned_new();
1449 gtk_box_pack_start(GTK_BOX(vbox), split1, TRUE, TRUE, 0);
1450 gtk_widget_show (split1);
1452 g_entity_split1 = split1;
1455 GtkWidget* split2 = gtk_vpaned_new();
1456 gtk_paned_add1 (GTK_PANED (split1), split2);
1457 gtk_widget_show (split2);
1459 g_entity_split2 = split2;
1463 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1464 gtk_widget_show (scr);
1465 gtk_paned_add1 (GTK_PANED (split2), scr);
1466 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1467 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1470 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
1472 GtkTreeView* view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1473 gtk_tree_view_set_headers_visible(view, FALSE);
1474 g_signal_connect(G_OBJECT(view), "button_press_event", G_CALLBACK(EntityClassList_button_press), 0);
1475 g_signal_connect(G_OBJECT(view), "key_press_event", G_CALLBACK(EntityClassList_keypress), 0);
1478 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1479 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("Key", renderer, "text", 0, 0);
1480 gtk_tree_view_append_column(view, column);
1484 GtkTreeSelection* selection = gtk_tree_view_get_selection(view);
1485 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(EntityClassList_selection_changed), 0);
1488 gtk_widget_show(GTK_WIDGET(view));
1490 gtk_container_add(GTK_CONTAINER(scr), GTK_WIDGET(view));
1492 g_object_unref(G_OBJECT(store));
1493 g_entityClassList = view;
1494 g_entlist_store = store;
1499 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1500 gtk_widget_show (scr);
1501 gtk_paned_add2 (GTK_PANED (split2), scr);
1502 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1503 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1506 GtkTextView* text = GTK_TEXT_VIEW(gtk_text_view_new());
1507 gtk_widget_set_size_request(GTK_WIDGET(text), 0, -1); // allow shrinking
1508 gtk_text_view_set_wrap_mode(text, GTK_WRAP_WORD);
1509 gtk_text_view_set_editable(text, FALSE);
1510 gtk_widget_show(GTK_WIDGET(text));
1511 gtk_container_add(GTK_CONTAINER(scr), GTK_WIDGET(text));
1512 g_entityClassComment = text;
1518 GtkWidget* split2 = gtk_vpaned_new();
1519 gtk_paned_add2 (GTK_PANED (split1), split2);
1520 gtk_widget_show(split2);
1523 GtkWidget* vbox2 = gtk_vbox_new (FALSE, 2);
1524 gtk_widget_show (vbox2);
1525 gtk_paned_pack1(GTK_PANED(split2), vbox2, FALSE, FALSE);
1528 // Spawnflags (4 colums wide max, or window gets too wide.)
1529 GtkTable* table = GTK_TABLE(gtk_table_new(4, 4, FALSE));
1530 gtk_box_pack_start (GTK_BOX (vbox2), GTK_WIDGET(table), FALSE, TRUE, 0);
1531 gtk_widget_show(GTK_WIDGET(table));
1533 g_spawnflagsTable = table;
1535 for (int i = 0; i < MAX_FLAGS; i++)
1537 GtkCheckButton* check = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(""));
1538 gtk_widget_ref(GTK_WIDGET(check));
1539 g_object_set_data(G_OBJECT(check), "handler", gint_to_pointer(g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(SpawnflagCheck_toggled), 0)));
1540 g_entitySpawnflagsCheck[i] = check;
1546 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1547 gtk_widget_show (scr);
1548 gtk_box_pack_start (GTK_BOX (vbox2), scr, TRUE, TRUE, 0);
1549 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1550 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1553 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
1555 GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1556 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
1559 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1560 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, 0);
1561 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1565 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1566 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 1, 0);
1567 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1571 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1572 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(EntityProperties_selection_changed), 0);
1575 gtk_widget_show(view);
1577 gtk_container_add(GTK_CONTAINER (scr), view);
1579 g_object_unref(G_OBJECT(store));
1581 g_entprops_store = store;
1587 GtkTable* table = GTK_TABLE(gtk_table_new(2, 2, FALSE));
1588 gtk_widget_show(GTK_WIDGET(table));
1589 gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(table), FALSE, TRUE, 0);
1590 gtk_table_set_row_spacings(table, 3);
1591 gtk_table_set_col_spacings(table, 5);
1594 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
1595 gtk_widget_show(GTK_WIDGET(entry));
1596 gtk_table_attach(table, GTK_WIDGET(entry), 1, 2, 0, 1,
1597 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
1598 (GtkAttachOptions)(0), 0, 0);
1599 gtk_widget_set_events(GTK_WIDGET(entry), GDK_KEY_PRESS_MASK);
1600 g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(EntityEntry_keypress), 0);
1601 g_entityKeyEntry = entry;
1605 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
1606 gtk_widget_show(GTK_WIDGET(entry));
1607 gtk_table_attach(table, GTK_WIDGET(entry), 1, 2, 1, 2,
1608 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
1609 (GtkAttachOptions)(0), 0, 0);
1610 gtk_widget_set_events(GTK_WIDGET(entry), GDK_KEY_PRESS_MASK);
1611 g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(EntityEntry_keypress), 0);
1612 g_entityValueEntry = entry;
1616 GtkLabel* label = GTK_LABEL(gtk_label_new("Value"));
1617 gtk_widget_show(GTK_WIDGET(label));
1618 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 1, 2,
1619 (GtkAttachOptions)(GTK_FILL),
1620 (GtkAttachOptions)(0), 0, 0);
1621 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1625 GtkLabel* label = GTK_LABEL(gtk_label_new("Key"));
1626 gtk_widget_show(GTK_WIDGET(label));
1627 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 0, 1,
1628 (GtkAttachOptions)(GTK_FILL),
1629 (GtkAttachOptions)(0), 0, 0);
1630 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1635 GtkBox* hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
1636 gtk_widget_show(GTK_WIDGET(hbox));
1637 gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(hbox), FALSE, TRUE, 0);
1640 GtkButton* button = GTK_BUTTON(gtk_button_new_with_label("Clear All"));
1641 gtk_widget_show(GTK_WIDGET(button));
1642 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(EntityInspector_clearAllKeyValues), 0);
1643 gtk_box_pack_start(hbox, GTK_WIDGET(button), TRUE, TRUE, 0);
1646 GtkButton* button = GTK_BUTTON(gtk_button_new_with_label("Delete Key"));
1647 gtk_widget_show(GTK_WIDGET(button));
1648 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(EntityInspector_clearKeyValue), 0);
1649 gtk_box_pack_start(hbox, GTK_WIDGET(button), TRUE, TRUE, 0);
1655 GtkWidget* scr = gtk_scrolled_window_new(0, 0);
1656 gtk_widget_show(scr);
1657 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scr), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1659 GtkWidget* viewport = gtk_viewport_new(0, 0);
1660 gtk_widget_show(viewport);
1661 gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
1663 g_attributeBox = GTK_VBOX(gtk_vbox_new(FALSE, 2));
1664 gtk_widget_show(GTK_WIDGET(g_attributeBox));
1666 gtk_container_add(GTK_CONTAINER(viewport), GTK_WIDGET(g_attributeBox));
1667 gtk_container_add(GTK_CONTAINER(scr), viewport);
1668 gtk_paned_pack2(GTK_PANED(split2), scr, FALSE, FALSE);
1675 int x = g_entitysplit1_position;
1678 gtk_paned_set_position(GTK_PANED(g_entity_split1), x);
1680 x = g_entitysplit2_position;
1683 gtk_paned_set_position (GTK_PANED(g_entity_split2), x);
1687 g_entityInspector_windowConstructed = true;
1688 EntityClassList_fill();
1690 GlobalSelectionSystem().addSelectionChangeCallback(FreeCaller1<const Selectable&, EntityInspector_selectionChanged>());
1691 GlobalEntityCreator().setKeyValueChangedFunc(EntityInspector_keyValueChanged);
1694 gtk_container_set_focus_chain(GTK_CONTAINER(vbox), NULL);
1699 class EntityInspector : public ModuleObserver
1701 std::size_t m_unrealised;
1703 EntityInspector() : m_unrealised(1)
1708 if(--m_unrealised == 0)
1710 if(g_entityInspector_windowConstructed)
1712 //globalOutputStream() << "Entity Inspector: realise\n";
1713 EntityClassList_fill();
1719 if(++m_unrealised == 1)
1721 if(g_entityInspector_windowConstructed)
1723 //globalOutputStream() << "Entity Inspector: unrealise\n";
1724 EntityClassList_clear();
1730 EntityInspector g_EntityInspector;
1732 #include "preferencesystem.h"
1733 #include "stringio.h"
1735 void EntityInspector_construct()
1737 GlobalEntityClassManager().attach(g_EntityInspector);
1739 GlobalPreferenceSystem().registerPreference("EntitySplit1", IntImportStringCaller(g_entitysplit1_position), IntExportStringCaller(g_entitysplit1_position));
1740 GlobalPreferenceSystem().registerPreference("EntitySplit2", IntImportStringCaller(g_entitysplit2_position), IntExportStringCaller(g_entitysplit2_position));
1744 void EntityInspector_destroy()
1746 GlobalEntityClassManager().detach(g_EntityInspector);