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_get_toplevel(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 if(GTK_WIDGET_REALIZED(view))
1015 gtk_tree_view_scroll_to_cell(view, path, 0, FALSE, 0, 0);
1017 gtk_tree_path_free(path);
1024 void EntityInspector_appendAttribute(const char* name, EntityAttribute& attribute)
1026 GtkTable* row = DialogRow_new(name, attribute.getWidget());
1027 DialogVBox_packRow(g_attributeBox, GTK_WIDGET(row));
1031 template<typename Attribute>
1032 class StatelessAttributeCreator
1035 static EntityAttribute* create(const char* name)
1037 return new Attribute(name);
1041 class EntityAttributeFactory
1043 typedef EntityAttribute* (*CreateFunc)(const char* name);
1044 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
1045 Creators m_creators;
1047 EntityAttributeFactory()
1049 m_creators.insert(Creators::value_type("string", &StatelessAttributeCreator<StringAttribute>::create));
1050 m_creators.insert(Creators::value_type("color", &StatelessAttributeCreator<StringAttribute>::create));
1051 m_creators.insert(Creators::value_type("integer", &StatelessAttributeCreator<StringAttribute>::create));
1052 m_creators.insert(Creators::value_type("real", &StatelessAttributeCreator<StringAttribute>::create));
1053 m_creators.insert(Creators::value_type("shader", &StatelessAttributeCreator<ShaderAttribute>::create));
1054 m_creators.insert(Creators::value_type("boolean", &StatelessAttributeCreator<BooleanAttribute>::create));
1055 m_creators.insert(Creators::value_type("angle", &StatelessAttributeCreator<AngleAttribute>::create));
1056 m_creators.insert(Creators::value_type("direction", &StatelessAttributeCreator<DirectionAttribute>::create));
1057 m_creators.insert(Creators::value_type("angles", &StatelessAttributeCreator<AnglesAttribute>::create));
1058 m_creators.insert(Creators::value_type("model", &StatelessAttributeCreator<ModelAttribute>::create));
1059 m_creators.insert(Creators::value_type("sound", &StatelessAttributeCreator<SoundAttribute>::create));
1060 m_creators.insert(Creators::value_type("vector3", &StatelessAttributeCreator<Vector3Attribute>::create));
1062 EntityAttribute* create(const char* type, const char* name)
1064 Creators::iterator i = m_creators.find(type);
1065 if(i != m_creators.end())
1067 return (*i).second(name);
1069 const ListAttributeType* listType = GlobalEntityClassManager().findListType(type);
1072 return new ListAttribute(name, *listType);
1078 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
1080 void EntityInspector_setEntityClass(EntityClass *eclass)
1082 EntityClassList_selectEntityClass(eclass);
1083 SurfaceFlags_setEntityClass(eclass);
1085 if(eclass != g_current_attributes)
1087 g_current_attributes = eclass;
1089 container_remove_all(GTK_CONTAINER(g_attributeBox));
1090 GlobalEntityAttributes_clear();
1092 for(EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i)
1094 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create((*i).second.m_type.c_str(), (*i).first.c_str());
1097 g_entityAttributes.push_back(attribute);
1098 EntityInspector_appendAttribute(EntityClassAttributePair_getName(*i), *g_entityAttributes.back());
1104 void EntityInspector_updateSpawnflags()
1107 int f = atoi(SelectedEntity_getValueForKey("spawnflags"));
1108 for (int i = 0; i < g_spawnflag_count; ++i)
1110 int v = !!(f&(1<<spawn_table[i]));
1112 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(g_entitySpawnflagsCheck[i]), v);
1116 // take care of the remaining ones
1117 for (int i = g_spawnflag_count; i < MAX_FLAGS; ++i)
1119 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(g_entitySpawnflagsCheck[i]), FALSE);
1124 void EntityInspector_applySpawnflags()
1130 for (i = 0; i < g_spawnflag_count; ++i)
1132 v = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_entitySpawnflagsCheck[i]));
1133 f |= v<<spawn_table[i];
1136 sprintf (sz, "%i", f);
1137 const char* value = (f == 0) ? "" : sz;
1140 StringOutputStream command;
1141 command << "entitySetFlags -flags " << f;
1142 UndoableCommand undo("entitySetSpawnflags");
1144 Scene_EntitySetKeyValue_Selected("spawnflags", value);
1149 void EntityInspector_updateKeyValues()
1151 g_selectedKeyValues.clear();
1152 g_selectedDefaultKeyValues.clear();
1153 Entity_GetKeyValues_Selected(g_selectedKeyValues, g_selectedDefaultKeyValues);
1155 EntityInspector_setEntityClass(GlobalEntityClassManager().findOrInsert(keyvalues_valueforkey(g_selectedKeyValues, "classname"), false));
1157 EntityInspector_updateSpawnflags();
1159 GtkListStore* store = g_entprops_store;
1161 // save current key/val pair around filling epair box
1162 // row_select wipes it and sets to first in list
1163 CopiedString strKey(gtk_entry_get_text(g_entityKeyEntry));
1164 CopiedString strVal(gtk_entry_get_text(g_entityValueEntry));
1166 gtk_list_store_clear(store);
1167 // Walk through list and add pairs
1168 for(KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i)
1171 gtk_list_store_append(store, &iter);
1172 StringOutputStream key(64);
1173 key << ConvertLocaleToUTF8((*i).first.c_str());
1174 StringOutputStream value(64);
1175 value << ConvertLocaleToUTF8((*i).second.c_str());
1176 gtk_list_store_set(store, &iter, 0, key.c_str(), 1, value.c_str(), -1);
1179 gtk_entry_set_text(g_entityKeyEntry, strKey.c_str());
1180 gtk_entry_set_text(g_entityValueEntry, strVal.c_str());
1182 for(EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i)
1188 class EntityInspectorDraw
1190 IdleDraw m_idleDraw;
1192 EntityInspectorDraw() : m_idleDraw(FreeCaller<EntityInspector_updateKeyValues>())
1197 m_idleDraw.queueDraw();
1201 EntityInspectorDraw g_EntityInspectorDraw;
1204 void EntityInspector_keyValueChanged()
1206 g_EntityInspectorDraw.queueDraw();
1208 void EntityInspector_selectionChanged(const Selectable&)
1210 EntityInspector_keyValueChanged();
1213 // Creates a new entity based on the currently selected brush and entity type.
1215 void EntityClassList_createEntity()
1217 GtkTreeView* view = g_entityClassList;
1219 // find out what type of entity we are trying to create
1220 GtkTreeModel* model;
1222 if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(view), &model, &iter) == FALSE)
1224 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityClassList)), "You must have a selected class to create an entity", "info");
1229 gtk_tree_model_get(model, &iter, 0, &text, -1);
1232 StringOutputStream command;
1233 command << "entityCreate -class " << text;
1235 UndoableCommand undo(command.c_str());
1237 Entity_createFromSelection(text, g_vector3_identity);
1242 void EntityInspector_applyKeyValue()
1244 // Get current selection text
1245 StringOutputStream key(64);
1246 key << ConvertUTF8ToLocale(gtk_entry_get_text(g_entityKeyEntry));
1247 StringOutputStream value(64);
1248 value << ConvertUTF8ToLocale(gtk_entry_get_text(g_entityValueEntry));
1251 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1252 if (!strcmp(key.c_str(), "classname") && !strcmp(value.c_str(), "worldspawn"))
1254 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityKeyEntry)), "Cannot change \"classname\" key back to worldspawn.", 0, eMB_OK );
1259 // RR2DO2: we don't want spaces in entity keys
1260 if (strstr( key.c_str(), " " ))
1262 gtk_MessageBox(gtk_widget_get_toplevel(GTK_WIDGET(g_entityKeyEntry)), "No spaces are allowed in entity keys.", 0, eMB_OK );
1266 if(strcmp(key.c_str(), "classname") == 0)
1268 StringOutputStream command;
1269 command << "entitySetClass -class " << value.c_str();
1270 UndoableCommand undo(command.c_str());
1271 Scene_EntitySetClassname_Selected(value.c_str());
1275 Scene_EntitySetKeyValue_Selected_Undoable(key.c_str(), value.c_str());
1279 void EntityInspector_clearKeyValue()
1281 // Get current selection text
1282 StringOutputStream key(64);
1283 key << ConvertUTF8ToLocale(gtk_entry_get_text(g_entityKeyEntry));
1285 if(strcmp(key.c_str(), "classname") != 0)
1287 StringOutputStream command;
1288 command << "entityDeleteKey -key " << key.c_str();
1289 UndoableCommand undo(command.c_str());
1290 Scene_EntitySetKeyValue_Selected(key.c_str(), "");
1294 void EntityInspector_clearAllKeyValues()
1296 UndoableCommand undo("entityClear");
1298 // remove all keys except classname
1299 for(KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i)
1301 if(strcmp((*i).first.c_str(), "classname") != 0)
1303 Scene_EntitySetKeyValue_Selected((*i).first.c_str(), "");
1308 // =============================================================================
1311 static void EntityClassList_selection_changed(GtkTreeSelection* selection, gpointer data)
1313 GtkTreeModel* model;
1314 GtkTreeIter selected;
1315 if(gtk_tree_selection_get_selected(selection, &model, &selected))
1317 EntityClass* eclass;
1318 gtk_tree_model_get(model, &selected, 1, &eclass, -1);
1326 static gint EntityClassList_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
1328 if (event->type == GDK_2BUTTON_PRESS)
1330 EntityClassList_createEntity();
1336 static gint EntityClassList_keypress(GtkWidget* widget, GdkEventKey* event, gpointer data)
1338 unsigned int code = gdk_keyval_to_upper (event->keyval);
1340 if (event->keyval == GDK_Return)
1342 EntityClassList_createEntity();
1346 // select the entity that starts with the key pressed
1347 if (code <= 'Z' && code >= 'A')
1349 GtkTreeView* view = g_entityClassList;
1350 GtkTreeModel* model;
1352 if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(view), &model, &iter) == FALSE
1353 || gtk_tree_model_iter_next(model, &iter) == FALSE)
1355 gtk_tree_model_get_iter_first(model, &iter);
1358 for(std::size_t count = gtk_tree_model_iter_n_children(model, 0); count > 0; --count)
1361 gtk_tree_model_get(model, &iter, 0, &text, -1);
1363 if (toupper (text[0]) == (int)code)
1365 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
1366 gtk_tree_selection_select_path(gtk_tree_view_get_selection(view), path);
1367 if(GTK_WIDGET_REALIZED(view))
1369 gtk_tree_view_scroll_to_cell(view, path, 0, FALSE, 0, 0);
1371 gtk_tree_path_free(path);
1377 if(gtk_tree_model_iter_next(model, &iter) == FALSE)
1378 gtk_tree_model_get_iter_first(model, &iter);
1386 static void EntityProperties_selection_changed(GtkTreeSelection* selection, gpointer data)
1388 // find out what type of entity we are trying to create
1389 GtkTreeModel* model;
1391 if(gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE)
1398 gtk_tree_model_get(model, &iter, 0, &key, 1, &val, -1);
1400 gtk_entry_set_text(g_entityKeyEntry, key);
1401 gtk_entry_set_text(g_entityValueEntry, val);
1407 static void SpawnflagCheck_toggled(GtkWidget *widget, gpointer data)
1409 EntityInspector_applySpawnflags();
1412 static gint EntityEntry_keypress(GtkEntry* widget, GdkEventKey* event, gpointer data)
1414 if (event->keyval == GDK_Return)
1416 if(widget == g_entityKeyEntry)
1418 gtk_entry_set_text(g_entityValueEntry, "");
1419 gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), GTK_WIDGET(g_entityValueEntry));
1423 EntityInspector_applyKeyValue();
1427 if (event->keyval == GDK_Escape)
1429 gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), NULL);
1436 void EntityInspector_destroyWindow(GtkWidget* widget, gpointer data)
1438 g_entitysplit1_position = gtk_paned_get_position(GTK_PANED(g_entity_split1));
1439 g_entitysplit2_position = gtk_paned_get_position(GTK_PANED(g_entity_split2));
1441 g_entityInspector_windowConstructed = false;
1442 GlobalEntityAttributes_clear();
1445 GtkWidget* EntityInspector_constructWindow(GtkWindow* toplevel)
1447 GtkWidget* vbox = gtk_vbox_new(FALSE, 2);
1448 gtk_widget_show (vbox);
1449 gtk_container_set_border_width(GTK_CONTAINER (vbox), 2);
1451 g_signal_connect(G_OBJECT(vbox), "destroy", G_CALLBACK(EntityInspector_destroyWindow), 0);
1454 GtkWidget* split1 = gtk_vpaned_new();
1455 gtk_box_pack_start(GTK_BOX(vbox), split1, TRUE, TRUE, 0);
1456 gtk_widget_show (split1);
1458 g_entity_split1 = split1;
1461 GtkWidget* split2 = gtk_vpaned_new();
1462 gtk_paned_add1 (GTK_PANED (split1), split2);
1463 gtk_widget_show (split2);
1465 g_entity_split2 = split2;
1469 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1470 gtk_widget_show (scr);
1471 gtk_paned_add1 (GTK_PANED (split2), scr);
1472 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1473 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1476 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
1478 GtkTreeView* view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1479 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), FALSE);
1480 gtk_tree_view_set_headers_visible(view, FALSE);
1481 g_signal_connect(G_OBJECT(view), "button_press_event", G_CALLBACK(EntityClassList_button_press), 0);
1482 g_signal_connect(G_OBJECT(view), "key_press_event", G_CALLBACK(EntityClassList_keypress), 0);
1485 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1486 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("Key", renderer, "text", 0, 0);
1487 gtk_tree_view_append_column(view, column);
1491 GtkTreeSelection* selection = gtk_tree_view_get_selection(view);
1492 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(EntityClassList_selection_changed), 0);
1495 gtk_widget_show(GTK_WIDGET(view));
1497 gtk_container_add(GTK_CONTAINER(scr), GTK_WIDGET(view));
1499 g_object_unref(G_OBJECT(store));
1500 g_entityClassList = view;
1501 g_entlist_store = store;
1506 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1507 gtk_widget_show (scr);
1508 gtk_paned_add2 (GTK_PANED (split2), scr);
1509 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
1510 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1513 GtkTextView* text = GTK_TEXT_VIEW(gtk_text_view_new());
1514 gtk_widget_set_size_request(GTK_WIDGET(text), 0, -1); // allow shrinking
1515 gtk_text_view_set_wrap_mode(text, GTK_WRAP_WORD);
1516 gtk_text_view_set_editable(text, FALSE);
1517 gtk_widget_show(GTK_WIDGET(text));
1518 gtk_container_add(GTK_CONTAINER(scr), GTK_WIDGET(text));
1519 g_entityClassComment = text;
1525 GtkWidget* split2 = gtk_vpaned_new();
1526 gtk_paned_add2 (GTK_PANED (split1), split2);
1527 gtk_widget_show(split2);
1530 GtkWidget* vbox2 = gtk_vbox_new (FALSE, 2);
1531 gtk_widget_show (vbox2);
1532 gtk_paned_pack1(GTK_PANED(split2), vbox2, FALSE, FALSE);
1535 // Spawnflags (4 colums wide max, or window gets too wide.)
1536 GtkTable* table = GTK_TABLE(gtk_table_new(4, 4, FALSE));
1537 gtk_box_pack_start (GTK_BOX (vbox2), GTK_WIDGET(table), FALSE, TRUE, 0);
1538 gtk_widget_show(GTK_WIDGET(table));
1540 g_spawnflagsTable = table;
1542 for (int i = 0; i < MAX_FLAGS; i++)
1544 GtkCheckButton* check = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(""));
1545 gtk_widget_ref(GTK_WIDGET(check));
1546 g_object_set_data(G_OBJECT(check), "handler", gint_to_pointer(g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(SpawnflagCheck_toggled), 0)));
1547 g_entitySpawnflagsCheck[i] = check;
1553 GtkWidget* scr = gtk_scrolled_window_new (0, 0);
1554 gtk_widget_show (scr);
1555 gtk_box_pack_start (GTK_BOX (vbox2), scr, TRUE, TRUE, 0);
1556 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1557 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
1560 GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
1562 GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1563 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), FALSE);
1564 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
1567 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1568 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, 0);
1569 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1573 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1574 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 1, 0);
1575 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1579 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1580 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(EntityProperties_selection_changed), 0);
1583 gtk_widget_show(view);
1585 gtk_container_add(GTK_CONTAINER (scr), view);
1587 g_object_unref(G_OBJECT(store));
1589 g_entprops_store = store;
1595 GtkTable* table = GTK_TABLE(gtk_table_new(2, 2, FALSE));
1596 gtk_widget_show(GTK_WIDGET(table));
1597 gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(table), FALSE, TRUE, 0);
1598 gtk_table_set_row_spacings(table, 3);
1599 gtk_table_set_col_spacings(table, 5);
1602 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
1603 gtk_widget_show(GTK_WIDGET(entry));
1604 gtk_table_attach(table, GTK_WIDGET(entry), 1, 2, 0, 1,
1605 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
1606 (GtkAttachOptions)(0), 0, 0);
1607 gtk_widget_set_events(GTK_WIDGET(entry), GDK_KEY_PRESS_MASK);
1608 g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(EntityEntry_keypress), 0);
1609 g_entityKeyEntry = entry;
1613 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
1614 gtk_widget_show(GTK_WIDGET(entry));
1615 gtk_table_attach(table, GTK_WIDGET(entry), 1, 2, 1, 2,
1616 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
1617 (GtkAttachOptions)(0), 0, 0);
1618 gtk_widget_set_events(GTK_WIDGET(entry), GDK_KEY_PRESS_MASK);
1619 g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(EntityEntry_keypress), 0);
1620 g_entityValueEntry = entry;
1624 GtkLabel* label = GTK_LABEL(gtk_label_new("Value"));
1625 gtk_widget_show(GTK_WIDGET(label));
1626 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 1, 2,
1627 (GtkAttachOptions)(GTK_FILL),
1628 (GtkAttachOptions)(0), 0, 0);
1629 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1633 GtkLabel* label = GTK_LABEL(gtk_label_new("Key"));
1634 gtk_widget_show(GTK_WIDGET(label));
1635 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 0, 1,
1636 (GtkAttachOptions)(GTK_FILL),
1637 (GtkAttachOptions)(0), 0, 0);
1638 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1643 GtkBox* hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
1644 gtk_widget_show(GTK_WIDGET(hbox));
1645 gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(hbox), FALSE, TRUE, 0);
1648 GtkButton* button = GTK_BUTTON(gtk_button_new_with_label("Clear All"));
1649 gtk_widget_show(GTK_WIDGET(button));
1650 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(EntityInspector_clearAllKeyValues), 0);
1651 gtk_box_pack_start(hbox, GTK_WIDGET(button), TRUE, TRUE, 0);
1654 GtkButton* button = GTK_BUTTON(gtk_button_new_with_label("Delete Key"));
1655 gtk_widget_show(GTK_WIDGET(button));
1656 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(EntityInspector_clearKeyValue), 0);
1657 gtk_box_pack_start(hbox, GTK_WIDGET(button), TRUE, TRUE, 0);
1663 GtkWidget* scr = gtk_scrolled_window_new(0, 0);
1664 gtk_widget_show(scr);
1665 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scr), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1667 GtkWidget* viewport = gtk_viewport_new(0, 0);
1668 gtk_widget_show(viewport);
1669 gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
1671 g_attributeBox = GTK_VBOX(gtk_vbox_new(FALSE, 2));
1672 gtk_widget_show(GTK_WIDGET(g_attributeBox));
1674 gtk_container_add(GTK_CONTAINER(viewport), GTK_WIDGET(g_attributeBox));
1675 gtk_container_add(GTK_CONTAINER(scr), viewport);
1676 gtk_paned_pack2(GTK_PANED(split2), scr, FALSE, FALSE);
1683 // show the sliders in any case
1684 if(g_entitysplit2_position > 22)
1686 gtk_paned_set_position (GTK_PANED(g_entity_split2), g_entitysplit2_position);
1688 g_entitysplit2_position = 22;
1689 gtk_paned_set_position (GTK_PANED(g_entity_split2), 22);
1691 if((g_entitysplit1_position - g_entitysplit2_position) > 27)
1693 gtk_paned_set_position (GTK_PANED(g_entity_split1), g_entitysplit1_position);
1695 gtk_paned_set_position (GTK_PANED(g_entity_split1), g_entitysplit2_position + 27);
1699 g_entityInspector_windowConstructed = true;
1700 EntityClassList_fill();
1702 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1703 GlobalSelectionSystem().addSelectionChangeCallback(EntityInspectorSelectionChangedCaller());
1704 GlobalEntityCreator().setKeyValueChangedFunc(EntityInspector_keyValueChanged);
1707 gtk_container_set_focus_chain(GTK_CONTAINER(vbox), NULL);
1712 class EntityInspector : public ModuleObserver
1714 std::size_t m_unrealised;
1716 EntityInspector() : m_unrealised(1)
1721 if(--m_unrealised == 0)
1723 if(g_entityInspector_windowConstructed)
1725 //globalOutputStream() << "Entity Inspector: realise\n";
1726 EntityClassList_fill();
1732 if(++m_unrealised == 1)
1734 if(g_entityInspector_windowConstructed)
1736 //globalOutputStream() << "Entity Inspector: unrealise\n";
1737 EntityClassList_clear();
1743 EntityInspector g_EntityInspector;
1745 #include "preferencesystem.h"
1746 #include "stringio.h"
1748 void EntityInspector_construct()
1750 GlobalEntityClassManager().attach(g_EntityInspector);
1752 GlobalPreferenceSystem().registerPreference("EntitySplit1", IntImportStringCaller(g_entitysplit1_position), IntExportStringCaller(g_entitysplit1_position));
1753 GlobalPreferenceSystem().registerPreference("EntitySplit2", IntImportStringCaller(g_entitysplit2_position), IntExportStringCaller(g_entitysplit2_position));
1757 void EntityInspector_destroy()
1759 GlobalEntityClassManager().detach(g_EntityInspector);