initial commit of hand merging, plus getting "ancient" waf script to work correctly
[ardour.git] / libs / canvas / flag.cc
1 #include "canvas/flag.h"
2 #include "canvas/text.h"
3 #include "canvas/rectangle.h"
4 #include "canvas/line.h"
5
6 using namespace std;
7 using namespace ArdourCanvas;
8
9 Flag::Flag (Group* parent, Distance height, Color outline_color, Color fill_color, Duple position)
10         : Group (parent)
11         , _height (height)
12         , _outline_color (outline_color)
13         , _fill_color (fill_color)
14 {
15         _text = new Text (this);
16         _text->set_alignment (Pango::ALIGN_CENTER);
17         _text->set_color (_outline_color);
18
19         _line = new Line (this);
20         _line->set_outline_color (_outline_color);
21         set_height (_height);
22
23         _rectangle = new Rectangle (this);
24         _rectangle->set_outline_color (_outline_color);
25         _rectangle->set_fill_color (_fill_color);
26
27         _text->raise_to_top ();
28
29         set_position (position);
30 }
31
32 void
33 Flag::set_text (string const & text)
34 {
35         _text->set (text);
36         boost::optional<Rect> bbox = _text->bounding_box ();
37         assert (bbox);
38
39         Duple flag_size (bbox.get().width() + 10, bbox.get().height() + 3);
40         
41         _text->set_position (flag_size / 2);
42         _rectangle->set (Rect (0, 0, flag_size.x, flag_size.y));
43 }
44
45 void
46 Flag::set_height (Distance)
47 {
48         _line->set (Duple (0, 0), Duple (0, _height));
49 }