// Storing vector A->B
double a_to_b_x = xb - xa;
double a_to_b_y = yb - ya;
-
+
// Storing vector A->P
double a_to_p_x = xp - xa;
double a_to_p_y = yp - ya;
-
+
// Basically finding the squared magnitude
// of a_to_b
double atb2 = a_to_b_x * a_to_b_x + a_to_b_y * a_to_b_y;
-
+
// The dot product of a_to_p and a_to_b
double atp_dot_atb = a_to_p_x * a_to_b_x + a_to_p_y * a_to_b_y;
-
+
// The normalized "distance" from a to
// your closest point
double t = atp_dot_atb / atb2;
-
+
// Add the distance to A, moving
// towards B
double x = xa + a_to_b_x * t;
const Glib::RefPtr<Gdk::Pixbuf>& underlay_pixbuf,
const Glib::RefPtr<Gdk::Pixbuf>& handle_pixbuf,
const Glib::RefPtr<Gdk::Pixbuf>& active_handle_pixbuf,
- int min_pos_x,
+ int min_pos_x,
int min_pos_y,
int max_pos_x,
int max_pos_y,
int pbheight = _face_pixbuf->get_height ();
int width = get_width ();
int height = get_height ();
-
+
if ((width != pbwidth) || (height != pbheight)) {
x_scale = double (width) / double (pbwidth);
if (x_scale == 0.0) {
void
Fader::render (cairo_t* cr, cairo_rectangle_t*)
{
-
+
double xscale = 1.0;
double yscale = 1.0;
-
+
get_image_scales (xscale, yscale);
-
+
cairo_matrix_t matrix;
cairo_get_matrix (cr, &matrix);
cairo_matrix_scale (&matrix, xscale, yscale);
cairo_set_matrix (cr, &matrix);
-
+
get_handle_position (_last_drawn_x, _last_drawn_y);
if (_underlay_pixbuf != 0) {
}
gdk_cairo_set_source_pixbuf (cr,
- ((get_state () == Gtk::STATE_ACTIVE) && (_active_face_pixbuf != 0)) ?
- _active_face_pixbuf->gobj() :
+ ((get_state () == Gtk::STATE_ACTIVE) && (_active_face_pixbuf != 0)) ?
+ _active_face_pixbuf->gobj() :
_face_pixbuf->gobj(),
0,
0);
bool
Fader::on_button_press_event (GdkEventButton* ev)
{
- focus_handler();
-
+ focus_handler(this);
+
if (_read_only) {
return false;
}
-
+
if (ev->type != GDK_BUTTON_PRESS) {
return false;
}
double xscale = 1.0;
double yscale = 1.0;
-
+
get_image_scales (xscale, yscale);
-
+
double hw = _handle_pixbuf->get_width() * xscale;
double hh = _handle_pixbuf->get_height() * yscale;
if ((ev->x < (_grab_start_handle_x - hw/2)) || (ev->x > (_grab_start_handle_x + hw/2)) || (ev->y < (_grab_start_handle_y - hh/2)) || (ev->y > (_grab_start_handle_y + hh/2))) {
return false;
}
-
+
double ev_pos_x;
double ev_pos_y;
-
+
get_closest_point_on_line(_min_pos_x, _min_pos_y,
- _max_pos_x, _max_pos_y,
+ _max_pos_x, _max_pos_y,
ev->x, ev->y,
ev_pos_x, ev_pos_y );
add_modal_grab ();
-
+
_grab_window = ev->window;
_dragging = true;
-
+
gdk_pointer_grab(ev->window,false,
GdkEventMask (Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK),
NULL,
ev->time);
queue_draw();
-
+
return true;
}
if (_dragging) {
double ev_pos_x;
double ev_pos_y;
-
+
if (ev->window != _grab_window) {
_grab_window = ev->window;
return true;
}
get_closest_point_on_line(_min_pos_x, _min_pos_y,
- _max_pos_x, _max_pos_y,
+ _max_pos_x, _max_pos_y,
_grab_start_handle_x + (ev->x - _grab_start_mouse_x), _grab_start_handle_y + (ev->y - _grab_start_mouse_y),
ev_pos_x, ev_pos_y );
-
+
double const fract = sqrt((ev_pos_x - _min_pos_x) * (ev_pos_x - _min_pos_x) +
(ev_pos_y - _min_pos_y) * (ev_pos_y - _min_pos_y)) /
sqrt((double)((_max_pos_x - _min_pos_x) * (_max_pos_x - _min_pos_x) +
(_max_pos_y - _min_pos_y) * (_max_pos_y - _min_pos_y)));
-
+
adjustment.set_value (adjustment.get_lower() + (adjustment.get_upper() - adjustment.get_lower()) * fract);
}
return true;