DirectionAttribute.h

Go to the documentation of this file.
00001 #ifndef DIRECTIONATTRIBUTE_H_
00002 #define DIRECTIONATTRIBUTE_H_
00003 
00004 static const char* directionButtons[] = { "up", "down", "z-axis" };
00005 
00006 class DirectionAttribute: public EntityAttribute
00007 {
00008         std::string m_classname;
00009         std::string m_key;
00010         GtkEntry* m_entry;
00011         NonModalEntry m_nonModal;
00012         RadioHBox m_radio;
00013         NonModalRadio m_nonModalRadio;
00014         GtkHBox* m_hbox;
00015     public:
00016         DirectionAttribute (const std::string& classname, const std::string& key) :
00017             m_classname(classname), m_key(key), m_entry(0), m_nonModal(ApplyCaller(*this), UpdateCaller(*this)),
00018                     m_radio(RadioHBox_new(STRING_ARRAY_RANGE(directionButtons))), m_nonModalRadio(ApplyRadioCaller(
00019                             *this))
00020         {
00021             GtkEntry* entry = numeric_entry_new();
00022             m_entry = entry;
00023             m_nonModal.connect(m_entry);
00024 
00025             m_nonModalRadio.connect(m_radio.m_radio);
00026 
00027             m_hbox = GTK_HBOX(gtk_hbox_new(FALSE, 4));
00028             gtk_widget_show(GTK_WIDGET(m_hbox));
00029 
00030             gtk_box_pack_start(GTK_BOX(m_hbox), GTK_WIDGET(m_radio.m_hbox), TRUE, TRUE, 0);
00031             gtk_box_pack_start(GTK_BOX(m_hbox), GTK_WIDGET(m_entry), TRUE, TRUE, 0);
00032         }
00033 
00034         GtkWidget* getWidget () const
00035         {
00036             return GTK_WIDGET(m_hbox);
00037         }
00038         void apply (void)
00039         {
00040             StringOutputStream angle(32);
00041             angle << angle_normalised(entry_get_float(m_entry));
00042             entitySetValue(m_classname, m_key, angle.c_str());
00043         }
00044         typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
00045 
00046         void update (void)
00047         {
00048             const std::string& value = entityGetValueForKey(m_key);
00049             if (value.length() > 0) {
00050                 const float f = string::toFloat(value);
00051                 if (f == -1) {
00052                     gtk_widget_set_sensitive(GTK_WIDGET(m_entry), FALSE);
00053                     radio_button_set_active_no_signal(m_radio.m_radio, 0);
00054                     gtk_entry_set_text(m_entry, "");
00055                 } else if (f == -2) {
00056                     gtk_widget_set_sensitive(GTK_WIDGET(m_entry), FALSE);
00057                     radio_button_set_active_no_signal(m_radio.m_radio, 1);
00058                     gtk_entry_set_text(m_entry, "");
00059                 } else {
00060                     gtk_widget_set_sensitive(GTK_WIDGET(m_entry), TRUE);
00061                     radio_button_set_active_no_signal(m_radio.m_radio, 2);
00062                     StringOutputStream angle(32);
00063                     angle << angle_normalised(f);
00064                     gtk_entry_set_text(m_entry, angle.c_str());
00065                 }
00066             } else {
00067                 gtk_entry_set_text(m_entry, "0");
00068             }
00069         }
00070         typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
00071 
00072         void applyRadio (void)
00073         {
00074             const int index = radio_button_get_active(m_radio.m_radio);
00075             if (index == 0) {
00076                 entitySetValue(m_classname, m_key, "-1");
00077             } else if (index == 1) {
00078                 entitySetValue(m_classname, m_key, "-2");
00079             } else if (index == 2) {
00080                 apply();
00081             }
00082         }
00083         typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
00084 };
00085 
00086 #endif /* DIRECTIONATTRIBUTE_H_ */

Generated by  doxygen 1.6.2