make canvas flag use NoEventText for its label, and try to set the font (unsuccessful...
[ardour.git] / gtk2_ardour / canvas-flag.cc
1 #include <iostream>
2
3 #include "ardour_ui.h"
4 #include "canvas-flag.h"
5 #include "time_axis_view_item.h"
6
7 using namespace Gnome::Canvas;
8 using namespace std;
9
10 CanvasFlag::CanvasFlag (MidiRegionView& region,
11                         Group&          parent,
12                         double          height,
13                         guint           outline_color_rgba,
14                         guint           fill_color_rgba,
15                         double          x,
16                         double          y)
17         : Group(parent, x, y)
18         , _text(0)
19         , _height(height)
20         , _outline_color_rgba(outline_color_rgba)
21         , _fill_color_rgba(fill_color_rgba)
22         , _region(region)
23         , _line(0)
24         , _rect(0)
25 {
26         /* XXX this connection is needed if ::on_event() is changed to actually do anything */
27         signal_event().connect (sigc::mem_fun (*this, &CanvasFlag::on_event));
28 }
29
30 void
31 CanvasFlag::delete_allocated_objects()
32 {
33         delete _text;
34         _text = 0;
35
36         delete _line;
37         _line = 0;
38
39         delete _rect;
40         _rect = 0;
41 }
42
43 void
44 CanvasFlag::set_text(const string& a_text)
45 {
46         delete_allocated_objects();
47
48         _text = new NoEventText (*this, 0.0, 0.0, a_text);
49         _text->property_justification() = Gtk::JUSTIFY_CENTER;
50         _text->property_fill_color_rgba() = _outline_color_rgba;
51         _text->property_font_desc() = TimeAxisViewItem::NAME_FONT;
52         double flagwidth  = _text->property_text_width()  + 10.0;
53         double flagheight = _text->property_text_height() + 3.0;
54         _text->property_x() = flagwidth / 2.0;
55         _text->property_y() = flagheight / 2.0;
56         _text->show();
57         _line = new SimpleLine(*this, 0.0, 0.0, 0.0, _height);
58         _line->property_color_rgba() = _outline_color_rgba;
59         _rect = new SimpleRect(*this, 0.0, 0.0, flagwidth, flagheight);
60         _rect->property_outline_color_rgba() = _outline_color_rgba;
61         _rect->property_fill_color_rgba() = _fill_color_rgba;
62         _text->raise_to_top();
63
64         /* XXX these two connections are needed if ::on_event() is changed to actually do anything */
65         //_rect->signal_event().connect (sigc::mem_fun (*this, &CanvasFlag::on_event));
66         //_text->signal_event().connect (sigc::mem_fun (*this, &CanvasFlag::on_event));
67 }
68
69 CanvasFlag::~CanvasFlag()
70 {
71         delete_allocated_objects();
72 }
73
74 bool
75 CanvasFlag::on_event(GdkEvent* /*ev*/)
76 {
77         /* XXX if you change this function to actually do anything, be sure
78            to fix the connections commented out elsewhere in this file.
79         */
80         return false;
81 }
82
83 void
84 CanvasFlag::set_height (double h)
85 {
86         _height = h;
87
88         if (_line) {
89                 _line->property_y2() = _height;
90         }
91 }