diff --git a/synfig-studio/src/gui/selectdraghelper.h b/synfig-studio/src/gui/selectdraghelper.h index c82141f..06b0161 100644 --- a/synfig-studio/src/gui/selectdraghelper.h +++ b/synfig-studio/src/gui/selectdraghelper.h @@ -62,6 +62,7 @@ private: State pointer_state; int pointer_tracking_start_x, pointer_tracking_start_y; int last_pointer_x, last_pointer_y; + Gdk::Point active_item_start_position; void start_tracking_pointer(int x, int y); void start_tracking_pointer(double x, double y); @@ -126,6 +127,12 @@ public: State get_state() const; /// The point where user clicked void get_initial_tracking_point(int &px, int &py) const; + /// The point where active item was initially placed + void get_active_item_initial_point(int &px, int &py) const; + + //! Retrieve the position of a given item + //! @param[out] position the location the provided item + virtual void get_item_position(const T &item, Gdk::Point &position) = 0; //! Retrieve the item placed at a point //! @param[out] item the item in the given position @@ -263,6 +270,13 @@ void SelectDragHelper::get_initial_tracking_point(int& px, int& py) const py = pointer_tracking_start_y; } +template +void SelectDragHelper::get_active_item_initial_point(int& px, int& py) const +{ + px = active_item_start_position.get_x(); + py = active_item_start_position.get_y(); +} + template bool @@ -678,6 +692,7 @@ void SelectDragHelper::start_dragging(const T* pointed_item) { made_dragging_move = false; active_item = pointed_item; + get_item_position(*active_item, active_item_start_position); if (canvas_interface) { action_group_drag = new synfigapp::Action::PassiveGrouper(canvas_interface->get_instance().get(), drag_action_name); diff --git a/synfig-studio/src/gui/widgets/widget_curves.cpp b/synfig-studio/src/gui/widgets/widget_curves.cpp index 8349a25..96eb3d3 100644 --- a/synfig-studio/src/gui/widgets/widget_curves.cpp +++ b/synfig-studio/src/gui/widgets/widget_curves.cpp @@ -508,10 +508,6 @@ Widget_Curves::Widget_Curves(): channel_point_sd.set_zoom_enabled(true); channel_point_sd.set_scroll_enabled(true); channel_point_sd.set_canvas_interface(canvas_interface); - channel_point_sd.signal_drag_started().connect([&](){ - const ChannelPoint *pointed_item = channel_point_sd.get_active_item(); - active_point_initial_value = pointed_item->get_value(time_plot_data->dt); - }); channel_point_sd.signal_drag_canceled().connect([&]() { overlapped_waypoints.clear(); }); @@ -1054,6 +1050,14 @@ Widget_Curves::ChannelPointSD::ChannelPointSD(Widget_Curves& widget) { } +void Widget_Curves::ChannelPointSD::get_item_position(const Widget_Curves::ChannelPoint& item, Gdk::Point& position) +{ + const Time &time = item.time_point.get_time(); + Real value = item.get_value(widget.time_plot_data->dt); + position.set_x(widget.time_plot_data->get_pixel_t_coord(time)); + position.set_y(widget.time_plot_data->get_pixel_y_coord(value)); +} + bool Widget_Curves::ChannelPointSD::find_item_at_position(int pos_x, int pos_y, Widget_Curves::ChannelPoint& cp) { cp.invalidate(); @@ -1145,19 +1149,20 @@ void Widget_Curves::ChannelPointSD::delta_drag(int total_dx, int total_dy, bool dx = total_dx * widget.time_plot_data->k/widget.canvas_interface->get_canvas()->rend_desc().get_frame_rate(); dy = total_dy; } else { - Real delta_value = get_active_item()->get_value(widget.time_plot_data->dt) - widget.active_point_initial_value; - int ddy = widget.time_plot_data->get_delta_pixel_from_delta_y_coord(delta_value); - dy = total_dy - ddy; - + Gdk::Point current_pos; + get_item_position(*get_active_item(), current_pos); int x0, y0; - get_initial_tracking_point(x0, y0); + get_active_item_initial_point(x0, y0); + + int y1 = y0 + total_dy; + dy = y1 - current_pos.get_y(); + int x1 = x0 + total_dx; // snap to frames float fps = widget.canvas_interface->get_canvas()->rend_desc().get_frame_rate(); Time next_t = widget.time_plot_data->get_t_from_pixel_coord(x1).round(fps); - - Time delta_time = next_t - get_active_item()->time_point.get_time(); - dx = widget.time_plot_data->get_delta_pixel_from_delta_t_coord(Real(delta_time)); + x1 = widget.time_plot_data->get_pixel_t_coord(next_t); + dx = x1 - current_pos.get_x(); } std::vector selection = get_selected_items(); diff --git a/synfig-studio/src/gui/widgets/widget_curves.h b/synfig-studio/src/gui/widgets/widget_curves.h index 2755329..9c63aed 100644 --- a/synfig-studio/src/gui/widgets/widget_curves.h +++ b/synfig-studio/src/gui/widgets/widget_curves.h @@ -85,6 +85,9 @@ private: public: ChannelPointSD(Widget_Curves &widget); virtual ~ChannelPointSD() override {} + + void get_item_position(const ChannelPoint &item, Gdk::Point &position) override; + bool find_item_at_position(int pos_x, int pos_y, ChannelPoint & cp) override; bool find_items_in_rect(Gdk::Rectangle rect, std::vector & list) override; void get_all_items(std::vector & items) override; @@ -106,8 +109,6 @@ private: int waypoint_edge_length; - synfig::Real active_point_initial_value; - std::vector::iterator> > overlapped_waypoints; void on_waypoint_clicked(const ChannelPoint &cp, unsigned int button, Gdk::Point /*point*/);