Compute arrow bbox manually to appease crazy canvas.
[ardour.git] / libs / canvas / canvas / arrow.h
1 /*
2     Copyright (C) 2011 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 /** @file  canvas/arrow.h
22  *  @brief Declaration of the Arrow canvas object.
23  */
24
25 #ifndef __CANVAS_ARROW_H__
26 #define __CANVAS_ARROW_H__
27
28 #include "canvas/visibility.h"
29 #include "canvas/container.h"
30
31 namespace ArdourCanvas {
32
33 class Canvas;
34 class Line;
35 class Polygon;
36
37 /** A composite item which draws a line with arrow heads
38  *  at either or both ends.
39  *
40  *  The arrow heads are identified by the indices 0 and 1;
41  *  head 0 is at the (x0, y0) end of the line, and head 1
42  *  at the (x1, y1) end.
43  *
44  *  @todo Draws vertical lines only; could be generalised
45  *  to draw lines at any angle.
46  */
47         
48 class LIBCANVAS_API Arrow : public Container
49 {
50 public:
51         Arrow (Canvas*);
52         Arrow (Item*);
53
54         void compute_bounding_box () const;
55
56         void set_show_head (int, bool);
57         void set_head_outward (int, bool);
58         void set_head_height (int, Distance);
59         void set_head_width (int, Distance);
60         void set_outline_width (Distance);
61         void set_color (Color);
62
63         Coord x () const;
64         Coord y1 () const;
65
66         void set_x (Coord);
67         void set_y0 (Coord);
68         void set_y1 (Coord);
69         
70         bool covers (Duple const &) const;
71
72 private:
73         void setup_polygon (int);
74         void setup ();
75
76         /** Representation of a single arrow head */
77         struct Head {
78                 Polygon* polygon; ///< the polygon which represents its shape
79                 bool outward;     ///< true if this head points out from the line
80                 Distance height;  ///< the height of the head
81                 Distance width;   ///< the maximum width of the head
82         };
83
84         /** our arrow heads; _heads[0] is at the (x0, y0) end of the line,
85          *  and _heads[1] at the (x1, y1) end.
86          */
87         Head _heads[2];
88
89         /** our line */
90         Line* _line;
91 };
92
93 }
94
95 #endif