incomplete merge of master into windows (requires upcoming changes to master to be...
[ardour.git] / gtk2_ardour / canvas-flag.cc
1 /*
2     Copyright (C) 2012 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21
22 #include "gtkmm2ext/utils.h"
23 #include "gtkmm2ext/rgb_macros.h"
24
25 #include "ardour_ui.h"
26 #include "canvas-flag.h"
27 #include "canvas-noevent-pixbuf.h"
28 #include "time_axis_view_item.h"
29 #include "utils.h"
30
31 using namespace Gnome::Canvas;
32 using namespace std;
33
34 CanvasFlag::CanvasFlag (MidiRegionView& region,
35                         Group&          parent,
36                         double          height,
37                         guint           outline_color_rgba,
38                         guint           fill_color_rgba,
39                         double          x,
40                         double          y)
41         : Group(parent, x, y)
42         , _name_pixbuf(0)
43         , _height(height)
44         , _outline_color_rgba(outline_color_rgba)
45         , _fill_color_rgba(fill_color_rgba)
46         , _region(region)
47         , name_pixbuf_width (0)
48         , _line(0)
49         , _rect(0)
50 {
51 }
52
53 void
54 CanvasFlag::delete_allocated_objects()
55 {
56         delete _name_pixbuf;
57         _name_pixbuf = 0;
58
59         delete _line;
60         _line = 0;
61
62         delete _rect;
63         _rect = 0;
64 }
65
66 void
67 CanvasFlag::set_text (const string& text)
68 {
69         delete_allocated_objects();
70
71         _name_pixbuf = new ArdourCanvas::NoEventPixbuf (*this);
72         name_pixbuf_width = Gtkmm2ext::pixel_width (text, TimeAxisViewItem::NAME_FONT) + 2;
73         Gdk::Color c;
74         set_color (c, _outline_color_rgba);
75         _name_pixbuf->property_pixbuf() = Gtkmm2ext::pixbuf_from_string (text, TimeAxisViewItem::NAME_FONT, name_pixbuf_width, 
76                                                                          TimeAxisViewItem::NAME_HEIGHT, c);
77         _name_pixbuf->property_x() = 10.0;
78         _name_pixbuf->property_y() = 2.0;
79         _name_pixbuf->show();
80
81         double flagwidth  = name_pixbuf_width + 8.0;
82         double flagheight = TimeAxisViewItem::NAME_HEIGHT + 3.0;
83         _line = new SimpleLine(*this, 0.0, 0.0, 0.0, _height);
84         _line->property_color_rgba() = _outline_color_rgba;
85         _rect = new SimpleRect(*this, 0.0, 0.0, flagwidth, flagheight);
86         _rect->property_outline_color_rgba() = _outline_color_rgba;
87         _rect->property_fill_color_rgba() = _fill_color_rgba;
88
89         _name_pixbuf->raise_to_top();
90 }
91
92 CanvasFlag::~CanvasFlag()
93 {
94         delete_allocated_objects();
95 }
96
97 void
98 CanvasFlag::set_height (double h)
99 {
100         _height = h;
101
102         if (_line) {
103                 _line->property_y2() = _height;
104         }
105 }