AnglesAttribute.h
Go to the documentation of this file.00001 #ifndef ANGLESATTRIBUTE_H_
00002 #define ANGLESATTRIBUTE_H_
00003
00004 class AnglesEntry
00005 {
00006 public:
00007 GtkEntry* m_roll;
00008 GtkEntry* m_pitch;
00009 GtkEntry* m_yaw;
00010 AnglesEntry () :
00011 m_roll(0), m_pitch(0), m_yaw(0)
00012 {
00013 }
00014 };
00015
00016 typedef BasicVector3<double> DoubleVector3;
00017
00018 class AnglesAttribute: public EntityAttribute
00019 {
00020 std::string m_classname;
00021 std::string m_key;
00022 AnglesEntry m_angles;
00023 NonModalEntry m_nonModal;
00024 GtkBox* m_hbox;
00025 public:
00026 AnglesAttribute (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_angles.m_pitch = entry;
00035 m_nonModal.connect(m_angles.m_pitch);
00036 }
00037 {
00038 GtkEntry* entry = numeric_entry_new();
00039 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
00040 m_angles.m_yaw = entry;
00041 m_nonModal.connect(m_angles.m_yaw);
00042 }
00043 {
00044 GtkEntry* entry = numeric_entry_new();
00045 gtk_box_pack_start(m_hbox, GTK_WIDGET(entry), TRUE, TRUE, 0);
00046 m_angles.m_roll = entry;
00047 m_nonModal.connect(m_angles.m_roll);
00048 }
00049 }
00050
00051 GtkWidget* getWidget () const
00052 {
00053 return GTK_WIDGET(m_hbox);
00054 }
00055 void apply (void)
00056 {
00057 StringOutputStream angles(64);
00058 angles << angle_normalised(entry_get_float(m_angles.m_pitch)) << " " << angle_normalised(entry_get_float(
00059 m_angles.m_yaw)) << " " << angle_normalised(entry_get_float(m_angles.m_roll));
00060 entitySetValue(m_classname, m_key, angles.c_str());
00061 }
00062 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
00063
00064 void update (void)
00065 {
00066 StringOutputStream angle(32);
00067 const std::string& value = entityGetValueForKey(m_key);
00068 if (value.length() > 0) {
00069 DoubleVector3 pitch_yaw_roll;
00070 if (!string_parse_vector3(value.c_str(), pitch_yaw_roll)) {
00071 pitch_yaw_roll = DoubleVector3(0, 0, 0);
00072 }
00073
00074 angle << angle_normalised(pitch_yaw_roll.x());
00075 gtk_entry_set_text(m_angles.m_pitch, angle.c_str());
00076 angle.clear();
00077
00078 angle << angle_normalised(pitch_yaw_roll.y());
00079 gtk_entry_set_text(m_angles.m_yaw, angle.c_str());
00080 angle.clear();
00081
00082 angle << angle_normalised(pitch_yaw_roll.z());
00083 gtk_entry_set_text(m_angles.m_roll, angle.c_str());
00084 angle.clear();
00085 } else {
00086 gtk_entry_set_text(m_angles.m_pitch, "0");
00087 gtk_entry_set_text(m_angles.m_yaw, "0");
00088 gtk_entry_set_text(m_angles.m_roll, "0");
00089 }
00090 }
00091 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
00092 };
00093
00094 #endif