index e434c10c568cf1cc8575b8433e5625619eeb6204..8615df7a97064865933626a9d38b95e6f0fdbd8a 100644 (file)
namespace UI {
namespace Widget {
namespace UI {
namespace Widget {
- Rotateable::Rotateable():
+Rotateable::Rotateable():
axis(-M_PI/4),
maxdecl(M_PI/4)
axis(-M_PI/4),
maxdecl(M_PI/4)
- {
+{
dragging = false;
working = false;
modifier = 0;
dragging = false;
working = false;
modifier = 0;
signal_button_press_event().connect(sigc::mem_fun(*this, &Rotateable::on_click));
signal_motion_notify_event().connect(sigc::mem_fun(*this, &Rotateable::on_motion));
signal_button_release_event().connect(sigc::mem_fun(*this, &Rotateable::on_release));
signal_button_press_event().connect(sigc::mem_fun(*this, &Rotateable::on_click));
signal_motion_notify_event().connect(sigc::mem_fun(*this, &Rotateable::on_motion));
signal_button_release_event().connect(sigc::mem_fun(*this, &Rotateable::on_release));
- }
+}
- bool Rotateable::on_click(GdkEventButton *event) {
+bool Rotateable::on_click(GdkEventButton *event) {
if (event->button == 1) {
if (event->button == 1) {
- drag_started_x = event->x;
- drag_started_y = event->y;
- modifier = get_single_modifier(modifier, event->state);
- dragging = true;
- working = false;
- current_axis = axis;
- return true;
+ drag_started_x = event->x;
+ drag_started_y = event->y;
+ modifier = get_single_modifier(modifier, event->state);
+ dragging = true;
+ working = false;
+ current_axis = axis;
+ return true;
}
return false;
}
return false;
- }
-
- guint Rotateable::get_single_modifier(guint old, guint state) {
-
- if (old == 0) {
- if (state & GDK_CONTROL_MASK)
- return 1; // ctrl
- if (state & GDK_SHIFT_MASK)
- return 2; // shift
- return 0;
+}
+
+guint Rotateable::get_single_modifier(guint old, guint state) {
+
+ if (old == 0 || old == 3) {
+ if (state & GDK_CONTROL_MASK)
+ return 1; // ctrl
+ if (state & GDK_SHIFT_MASK)
+ return 2; // shift
+ if (state & GDK_MOD1_MASK)
+ return 3; // alt
+ return 0;
} else {
} else {
- if (!(state & GDK_CONTROL_MASK) && !(state & GDK_SHIFT_MASK))
- return 0; // none
- if (old == 1)
- if (state & GDK_SHIFT_MASK && !(state & GDK_CONTROL_MASK))
- return 2; // shift
- else
- return 1;
- if (old == 2)
- if (state & GDK_CONTROL_MASK && !(state & GDK_SHIFT_MASK))
- return 1; // ctrl
- else
- return 2;
- return old;
+ if (!(state & GDK_CONTROL_MASK) && !(state & GDK_SHIFT_MASK)) {
+ if (state & GDK_MOD1_MASK)
+ return 3; // alt
+ else
+ return 0; // none
+ }
+ if (old == 1) {
+ if (state & GDK_SHIFT_MASK && !(state & GDK_CONTROL_MASK))
+ return 2; // shift
+ if (state & GDK_MOD1_MASK && !(state & GDK_CONTROL_MASK))
+ return 3; // alt
+ return 1;
+ }
+ if (old == 2) {
+ if (state & GDK_CONTROL_MASK && !(state & GDK_SHIFT_MASK))
+ return 1; // ctrl
+ if (state & GDK_MOD1_MASK && !(state & GDK_SHIFT_MASK))
+ return 3; // alt
+ return 2;
+ }
+ return old;
}
}
- }
+}
- bool Rotateable::on_motion(GdkEventMotion *event) {
+bool Rotateable::on_motion(GdkEventMotion *event) {
if (dragging) {
if (dragging) {
- double dist = NR::L2(NR::Point(event->x, event->y) - NR::Point(drag_started_x, drag_started_y));
- double angle = atan2(event->y - drag_started_y, event->x - drag_started_x);
- if (dist > 20) {
- working = true;
- double force = CLAMP (-(angle - current_axis)/maxdecl, -1, 1);
- if (fabs(force) < 0.002)
- force = 0; // snap to zero
- if (modifier != get_single_modifier(modifier, event->state)) {
- // user has switched modifiers in mid drag, close past drag and start a new
- // one, redefining axis temporarily
- do_release(force, modifier);
- current_axis = angle;
- modifier = get_single_modifier(modifier, event->state);
- } else {
- do_motion(force, modifier);
- }
- }
- gobble_motion_events(GDK_BUTTON1_MASK);
- return true;
+ double dist = NR::L2(NR::Point(event->x, event->y) - NR::Point(drag_started_x, drag_started_y));
+ double angle = atan2(event->y - drag_started_y, event->x - drag_started_x);
+ if (dist > 20) {
+ working = true;
+ double force = CLAMP (-(angle - current_axis)/maxdecl, -1, 1);
+ if (fabs(force) < 0.002)
+ force = 0; // snap to zero
+ if (modifier != get_single_modifier(modifier, event->state)) {
+ // user has switched modifiers in mid drag, close past drag and start a new
+ // one, redefining axis temporarily
+ do_release(force, modifier);
+ current_axis = angle;
+ modifier = get_single_modifier(modifier, event->state);
+ } else {
+ do_motion(force, modifier);
+ }
+ }
+ gobble_motion_events(GDK_BUTTON1_MASK);
+ return true;
}
return false;
}
return false;
- }
+}
- bool Rotateable::on_release(GdkEventButton *event) {
+bool Rotateable::on_release(GdkEventButton *event) {
if (dragging && working) {
if (dragging && working) {
- double angle = atan2(event->y - drag_started_y, event->x - drag_started_x);
- double force = CLAMP (-(angle - current_axis)/maxdecl, -1, 1);
- if (fabs(force) < 0.002)
- force = 0; // snap to zero
- do_release(force, modifier);
- dragging = false;
- working = false;
- current_axis = axis;
- return true;
+ double angle = atan2(event->y - drag_started_y, event->x - drag_started_x);
+ double force = CLAMP (-(angle - current_axis)/maxdecl, -1, 1);
+ if (fabs(force) < 0.002)
+ force = 0; // snap to zero
+ do_release(force, modifier);
+ current_axis = axis;
+ dragging = false;
+ working = false;
+ return true;
}
}
+ dragging = false;
+ working = false;
return false;
return false;
- }
+}
- Rotateable::~Rotateable() {
- }
+Rotateable::~Rotateable() {
+}