2
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23
#include "mdc_figure.h"
24
#include "base/trackable.h"
49
enum LinePatternType {
67
class MYSQLCANVAS_PUBLIC_FUNC LineLayouter : public base::trackable
71
virtual ~LineLayouter();
73
boost::signals2::signal<void ()>* signal_changed() { return &_changed; }
75
virtual Connector* get_start_connector() const= 0;
76
virtual Connector* get_end_connector() const= 0;
78
virtual std::vector<MySQL::Geometry::Point> get_points()= 0;
79
virtual MySQL::Geometry::Point get_start_point()= 0;
80
virtual MySQL::Geometry::Point get_end_point()= 0;
82
virtual std::vector<ItemHandle*> create_handles(Line *line, InteractionLayer *ilayer);
83
virtual void update_handles(Line *line, std::vector<ItemHandle*> &handles);
85
virtual bool handle_dragged(Line *line, ItemHandle *handle, const MySQL::Geometry::Point &pos, bool dragging);
87
virtual void update()= 0;
91
MySQL::Geometry::Point p1;
92
MySQL::Geometry::Point p2;
95
boost::signals2::signal<void ()> _changed;
101
class MYSQLCANVAS_PUBLIC_FUNC Line : public Figure
104
Line(Layer *layer, LineLayouter *layouter= 0);
107
void set_layouter(LineLayouter *layouter);
108
LineLayouter *get_layouter() { return _layouter; }
110
virtual void resize_to(const MySQL::Geometry::Size &size);
111
virtual void move_to(const MySQL::Geometry::Point &pos);
113
virtual bool contains_point(const MySQL::Geometry::Point &point) const;
115
virtual void draw_contents(CairoCtx *cr);
116
virtual void stroke_outline(CairoCtx *cr, float offset= 0) const;
117
virtual void stroke_outline_gl(float offset= 0) const;
119
void set_vertices(const std::vector<MySQL::Geometry::Point> &points);
120
void add_vertex(const MySQL::Geometry::Point &pos);
121
void set_vertex(size_t vertex, const MySQL::Geometry::Point &pos);
122
inline MySQL::Geometry::Point get_vertex(size_t vertex) { return _vertices[vertex]; }
123
size_t count_vertices() { return _vertices.size(); }
126
void set_end_type(LineEndType start, LineEndType end);
127
void set_line_pattern(LinePatternType pattern);
129
void set_hops_crossings(bool flag);
130
bool get_hops_crossings() const { return _hop_crossings; }
132
virtual void mark_crossings(Line *line);
134
virtual void create_handles(InteractionLayer *ilayer);
135
virtual void update_handles();
137
boost::signals2::signal<void ()>* signal_layout_changed() { return &_layout_changed; }
139
LineLayouter *_layouter;
141
boost::signals2::signal<void ()> _layout_changed;
145
MySQL::Geometry::Point pos;
147
inline bool operator==(const SegmentPoint &sp) const { return sp.pos == pos && sp.hop == hop; };
148
inline bool operator!=(const SegmentPoint &sp) const { return sp.pos != pos || sp.hop != hop; };
149
SegmentPoint(const MySQL::Geometry::Point &p, Line *l) : pos(p), hop(l) {}
152
// the points that define the line
153
std::vector<MySQL::Geometry::Point> _vertices;
155
// the points that define the final appearance of the line (including intersections)
156
std::vector<SegmentPoint> _segments;
158
LineEndType _start_type;
159
LineEndType _end_type;
160
LinePatternType _line_pattern;
164
void update_bounds();
165
void update_layout();
167
void set_line_pattern(CairoCtx *cr, LinePatternType pattern);
168
GLushort get_gl_pattern(LinePatternType pattern);
170
double get_line_start_angle();
171
double get_line_end_angle();
173
void draw_line_ends(CairoCtx *cr);
174
void draw_line_ends_gl();
175
virtual void draw_outline_ring(CairoCtx *cr, const MySQL::Drawing::Color &color);
176
virtual void draw_outline_ring_gl(const MySQL::Drawing::Color &color);
179
virtual bool on_drag_handle(ItemHandle *handle, const MySQL::Geometry::Point &pos, bool dragging);
185
#endif /* _MDC_LINE_H_ */