~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/canvas/src/mdc_line.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
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
 
7
 * License.
 
8
 * 
 
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.
 
13
 * 
 
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
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef _MDC_LINE_H_
 
21
#define _MDC_LINE_H_
 
22
 
 
23
#include "mdc_figure.h"
 
24
#include "base/trackable.h"
 
25
 
 
26
BEGIN_MDC_DECLS
 
27
 
 
28
class Connector;
 
29
 
 
30
 
 
31
enum LineEndType {
 
32
  NormalEnd,
 
33
  DashedNormalEnd,
 
34
  FilledTriangleEnd,
 
35
  HollowTriangleEnd,
 
36
  ChickenFootEnd,
 
37
  ChickenFoot0End,
 
38
  ChickenFoot1End,
 
39
  Cross0End,
 
40
  Cross1End,
 
41
  DashedChickenFootEnd,
 
42
  HollowDiamondEnd,
 
43
  FilledDiamondEnd,
 
44
  HollowCircleEnd,
 
45
  FilledCircleEnd,
 
46
  BoldStickEnd
 
47
};
 
48
 
 
49
enum LinePatternType {
 
50
  SolidPattern= 0,
 
51
  Dotted1Pattern,
 
52
  Dotted2Pattern,
 
53
  Dashed1Pattern,
 
54
  Dashed2Pattern,
 
55
  Dashed3Pattern,
 
56
  Dashed4Pattern,
 
57
  DashDot1Pattern,
 
58
  DashDot2Pattern,
 
59
  LastPattern
 
60
};
 
61
 
 
62
 
 
63
 
 
64
class Line;
 
65
 
 
66
 
 
67
class MYSQLCANVAS_PUBLIC_FUNC LineLayouter : public base::trackable
 
68
{
 
69
public:
 
70
  LineLayouter();
 
71
  virtual ~LineLayouter();
 
72
 
 
73
  boost::signals2::signal<void ()>* signal_changed() { return &_changed; }
 
74
 
 
75
  virtual Connector* get_start_connector() const= 0;
 
76
  virtual Connector* get_end_connector() const= 0;
 
77
 
 
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;
 
81
 
 
82
  virtual std::vector<ItemHandle*> create_handles(Line *line, InteractionLayer *ilayer);
 
83
  virtual void update_handles(Line *line, std::vector<ItemHandle*> &handles);
 
84
 
 
85
  virtual bool handle_dragged(Line *line, ItemHandle *handle, const MySQL::Geometry::Point &pos, bool dragging);
 
86
 
 
87
  virtual void update()= 0;
 
88
protected:
 
89
  struct Segment
 
90
  {
 
91
    MySQL::Geometry::Point p1;
 
92
    MySQL::Geometry::Point p2;
 
93
  };
 
94
 
 
95
  boost::signals2::signal<void ()> _changed;
 
96
};
 
97
 
 
98
 
 
99
 
 
100
 
 
101
class MYSQLCANVAS_PUBLIC_FUNC Line : public Figure
 
102
{
 
103
public:
 
104
  Line(Layer *layer, LineLayouter *layouter= 0);
 
105
  virtual ~Line();
 
106
 
 
107
  void set_layouter(LineLayouter *layouter);
 
108
  LineLayouter *get_layouter() { return _layouter; }
 
109
 
 
110
  virtual void resize_to(const MySQL::Geometry::Size &size);
 
111
  virtual void move_to(const MySQL::Geometry::Point &pos);
 
112
 
 
113
  virtual bool contains_point(const MySQL::Geometry::Point &point) const;
 
114
  
 
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;
 
118
 
 
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(); }
 
124
 
 
125
 
 
126
  void set_end_type(LineEndType start, LineEndType end);
 
127
  void set_line_pattern(LinePatternType pattern);
 
128
 
 
129
  void set_hops_crossings(bool flag);
 
130
  bool get_hops_crossings() const { return _hop_crossings; }
 
131
 
 
132
  virtual void mark_crossings(Line *line);
 
133
  
 
134
  virtual void create_handles(InteractionLayer *ilayer);
 
135
  virtual void update_handles();
 
136
 
 
137
  boost::signals2::signal<void ()>* signal_layout_changed() { return &_layout_changed; }
 
138
protected:
 
139
  LineLayouter *_layouter;
 
140
 
 
141
  boost::signals2::signal<void ()> _layout_changed;
 
142
 
 
143
  struct SegmentPoint
 
144
  {
 
145
    MySQL::Geometry::Point pos;
 
146
    Line *hop;
 
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) {}
 
150
  };
 
151
 
 
152
  // the points that define the line
 
153
  std::vector<MySQL::Geometry::Point> _vertices;
 
154
 
 
155
  // the points that define the final appearance of the line (including intersections)
 
156
  std::vector<SegmentPoint> _segments;
 
157
 
 
158
  LineEndType _start_type;
 
159
  LineEndType _end_type;
 
160
  LinePatternType _line_pattern;
 
161
 
 
162
  bool _hop_crossings;
 
163
 
 
164
  void update_bounds();
 
165
  void update_layout();
 
166
  
 
167
  void set_line_pattern(CairoCtx *cr, LinePatternType pattern);
 
168
  GLushort get_gl_pattern(LinePatternType pattern);
 
169
  
 
170
  double get_line_start_angle();
 
171
  double get_line_end_angle();
 
172
 
 
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);
 
177
  
 
178
private:
 
179
  virtual bool on_drag_handle(ItemHandle *handle, const MySQL::Geometry::Point &pos, bool dragging);
 
180
};
 
181
 
 
182
 
 
183
END_MDC_DECLS
 
184
 
 
185
#endif /* _MDC_LINE_H_ */