EntityAttribute.h

Go to the documentation of this file.
00001 #ifndef ENTITYATTRIBUTE_H_
00002 #define ENTITYATTRIBUTE_H_
00003 
00004 #include "../../entity.h"
00005 
00006 namespace
00007 {
00008     typedef std::list<std::string> Values;
00009     typedef std::map<std::string, Values> KeyValues;
00010     typedef std::map<std::string, KeyValues> ClassKeyValues;
00011     ClassKeyValues g_selectedKeyValues; 
00013     const EntityClass* g_current_attributes = 0;
00014     std::string g_currentSelectedKey;
00015 }
00016 
00027 class EntityAttribute
00028 {
00029     public:
00030         virtual ~EntityAttribute (void)
00031         {
00032         }
00033         // An EntityAttribute must return a GtkWidget that is used to interact with
00034         // its values.
00035         virtual GtkWidget* getWidget () const = 0;
00036         // Update the GTK widgets based on the current value of the key.
00037         virtual void update () = 0;
00038 
00039         void entitySetValue (const std::string& classname, const std::string& key,
00040                 const std::string& value)
00041         {
00042             std::string command = "entitySetKeyValue -classname \"" + classname + "\" -key \"" + key + "\" -value \"" + value
00043                     + "\"";
00044             UndoableCommand undo(command);
00045             Scene_EntitySetKeyValue_Selected(classname.c_str(), key.c_str(), value.c_str());
00046         }
00047 
00053         const std::string entityGetValueForKey (const std::string& key)
00054         {
00055             ASSERT_MESSAGE(g_current_attributes != 0, "g_current_attributes is zero");
00056             ClassKeyValues::iterator it = g_selectedKeyValues.find(g_current_attributes->m_name);
00057             if (it != g_selectedKeyValues.end()) {
00058                 KeyValues &possibleValues = (*it).second;
00059                 KeyValues::const_iterator i = possibleValues.find(key);
00060                 if (i != possibleValues.end()) {
00061                     const Values &values = (*i).second;
00062                     ASSERT_MESSAGE(!values.empty(), "Values don't exist");
00063                     return *values.begin();
00064                 }
00065             }
00066             return "";
00067         }
00068 
00069         inline double angle_normalised (double angle)
00070         {
00071             return float_mod(angle, 360.0);
00072         }
00073 
00074         GtkEntry* numeric_entry_new (void)
00075         {
00076             GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
00077             gtk_widget_show(GTK_WIDGET(entry));
00078             widget_set_size(GTK_WIDGET(entry), 10, 0);
00079             return entry;
00080         }
00081 };
00082 
00083 #endif /* ENTITYATTRIBUTE_H_ */

Generated by  doxygen 1.6.2