Vector3Attribute.h

Go to the documentation of this file.
00001 #ifndef VECTOR3ATTRIBUTE_H_
00002 #define VECTOR3ATTRIBUTE_H_
00003 
00004 typedef BasicVector3<double> DoubleVector3;
00005 
00006 class Vector3Entry
00007 {
00008     public:
00009         GtkEntry* m_x;
00010         GtkEntry* m_y;
00011         GtkEntry* m_z;
00012         Vector3Entry () :
00013             m_x(0), m_y(0), m_z(0)
00014         {
00015         }
00016 };
00017 
00018 class Vector3Attribute: public EntityAttribute
00019 {
00020         std::string m_classname;
00021         std::string m_key;
00022         Vector3Entry m_vector3;
00023         NonModalEntry m_nonModal;
00024         GtkBox* m_hbox;
00025     public:
00026         Vector3Attribute (const std::string& classname, const std::string& key) :
00027             m_classname(classname), m_key(key), m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
00028         {
00029             m_hbox = GTK_BOX(gtk_hbox_new(TRUE, 4));
00030             gtk_widget_show(GTK_WIDGET(m_hbox));
00031             {
00032                 GtkEntry* entry = numeric_entry_new();
00033                 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
00034                 m_vector3.m_x = entry;
00035                 m_nonModal.connect(m_vector3.m_x);
00036             }
00037             {
00038                 GtkEntry* entry = numeric_entry_new();
00039                 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
00040                 m_vector3.m_y = entry;
00041                 m_nonModal.connect(m_vector3.m_y);
00042             }
00043             {
00044                 GtkEntry* entry = numeric_entry_new();
00045                 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
00046                 m_vector3.m_z = entry;
00047                 m_nonModal.connect(m_vector3.m_z);
00048             }
00049         }
00050 
00051         GtkWidget* getWidget () const
00052         {
00053             return GTK_WIDGET(m_hbox);
00054         }
00055         void apply (void)
00056         {
00057             StringOutputStream vector3(64);
00058             vector3 << entry_get_float(m_vector3.m_x) << " " << entry_get_float(m_vector3.m_y) << " "
00059                     << entry_get_float(m_vector3.m_z);
00060             entitySetValue(m_classname, m_key, vector3.c_str());
00061         }
00062         typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
00063 
00064         void update (void)
00065         {
00066             StringOutputStream buffer(32);
00067             const std::string& value = entityGetValueForKey(m_key);
00068             if (value.length() > 0) {
00069                 DoubleVector3 x_y_z;
00070                 if (!string_parse_vector3(value.c_str(), x_y_z)) {
00071                     x_y_z = DoubleVector3(0, 0, 0);
00072                 }
00073 
00074                 buffer << x_y_z.x();
00075                 gtk_entry_set_text(m_vector3.m_x, buffer.c_str());
00076                 buffer.clear();
00077 
00078                 buffer << x_y_z.y();
00079                 gtk_entry_set_text(m_vector3.m_y, buffer.c_str());
00080                 buffer.clear();
00081 
00082                 buffer << x_y_z.z();
00083                 gtk_entry_set_text(m_vector3.m_z, buffer.c_str());
00084                 buffer.clear();
00085             } else {
00086                 gtk_entry_set_text(m_vector3.m_x, "0");
00087                 gtk_entry_set_text(m_vector3.m_y, "0");
00088                 gtk_entry_set_text(m_vector3.m_z, "0");
00089             }
00090         }
00091         typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
00092 };
00093 
00094 #endif /* VECTOR3ATTRIBUTE_H_ */

Generated by  doxygen 1.6.2