3
* Copyright (C) 2007 Murray Cumming
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
21
#include "canvas_line_movable.h"
22
#include <goocanvasmm/canvas.h>
23
#include <gdkmm/cursor.h>
30
CanvasLineMovable::CanvasLineMovable()
31
: Goocanvas::Polyline(0.0, 0.0, 0.0, 0.0),
34
signal_motion_notify_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_motion_notify_event));
35
signal_button_press_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_button_press_event));
36
signal_button_release_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_button_release_event));
38
signal_enter_notify_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_enter_notify_event));
39
signal_leave_notify_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_leave_notify_event));
42
CanvasLineMovable::~CanvasLineMovable()
46
Glib::RefPtr<CanvasLineMovable> CanvasLineMovable::create()
48
return Glib::RefPtr<CanvasLineMovable>(new CanvasLineMovable());
51
void CanvasLineMovable::get_xy(double& x, double& y) const
53
Goocanvas::Points points = property_points();
54
points.get_coordinate(0, x, y);
57
void CanvasLineMovable::set_xy(double x, double y)
59
//Discover the offset:
62
Goocanvas::Points old_points = property_points();
63
old_points.get_coordinate(0, old_x, old_y);
65
const double offset_x = x - old_x;
66
const double offset_y = y - old_y;
68
//Apply the offset to all points:
69
const int count = old_points.get_num_points();
70
Goocanvas::Points new_points(count);
71
for(int i = 0; i < count; ++i)
75
old_points.get_coordinate(i, this_x, this_y);
76
new_points.set_coordinate(i, this_x + offset_x, this_y + offset_y);
79
property_points() = new_points;
82
void CanvasLineMovable::get_width_height(double& width, double& height) const
84
//width/height still makes sense for a line
85
//(it can be thought of as a diagonal line between two rectangle corners):
86
Goocanvas::Points points = property_points();
89
points.get_coordinate(0, x1, y1);
93
points.get_coordinate(1, x2, y2);
98
//std::cout << "CanvasLineMovable::get_width_height(): width=" << width << std::endl;
101
void CanvasLineMovable::set_width_height(double width, double height)
103
//width/height still makes sense for a line
104
//(it can be thought of as a diagonal line between two rectangle corners):
105
Goocanvas::Points points = property_points();
108
points.get_coordinate(0, x1, y1);
109
points.set_coordinate(1, x1+width, y1+height);
110
property_points() = points;
112
//std::cout << "CanvasLineMovable::set_width_height(): end x=" << x1+width << std::endl;
115
Goocanvas::Canvas* CanvasLineMovable::get_parent_canvas_widget()