In export format dialog, show preview of generated part of description. Fix to #0004941
[ardour.git] / gtk2_ardour / canvas-flag.cc
1 #include <iostream>
2
3 #include "gtkmm2ext/utils.h"
4 #include "gtkmm2ext/rgb_macros.h"
5
6 #include "ardour_ui.h"
7 #include "canvas-flag.h"
8 #include "canvas-noevent-pixbuf.h"
9 #include "time_axis_view_item.h"
10 #include "utils.h"
11
12 using namespace Gnome::Canvas;
13 using namespace std;
14
15 CanvasFlag::CanvasFlag (MidiRegionView& region,
16                         Group&          parent,
17                         double          height,
18                         guint           outline_color_rgba,
19                         guint           fill_color_rgba,
20                         double          x,
21                         double          y)
22         : Group(parent, x, y)
23         , _name_pixbuf(0)
24         , _height(height)
25         , _outline_color_rgba(outline_color_rgba)
26         , _fill_color_rgba(fill_color_rgba)
27         , _region(region)
28         , name_pixbuf_width (0)
29         , _line(0)
30         , _rect(0)
31 {
32 }
33
34 void
35 CanvasFlag::delete_allocated_objects()
36 {
37         delete _name_pixbuf;
38         _name_pixbuf = 0;
39
40         delete _line;
41         _line = 0;
42
43         delete _rect;
44         _rect = 0;
45 }
46
47 void
48 CanvasFlag::set_text (const string& text)
49 {
50         delete_allocated_objects();
51
52         _name_pixbuf = new ArdourCanvas::NoEventPixbuf (*this);
53         name_pixbuf_width = Gtkmm2ext::pixel_width (text, TimeAxisViewItem::NAME_FONT) + 2;
54         Gdk::Color c;
55         set_color (c, _outline_color_rgba);
56         _name_pixbuf->property_pixbuf() = Gtkmm2ext::pixbuf_from_string (text, TimeAxisViewItem::NAME_FONT, name_pixbuf_width, 
57                                                                          TimeAxisViewItem::NAME_HEIGHT, c);
58         _name_pixbuf->property_x() = 10.0;
59         _name_pixbuf->property_y() = 2.0;
60         _name_pixbuf->show();
61
62         double flagwidth  = name_pixbuf_width + 8.0;
63         double flagheight = TimeAxisViewItem::NAME_HEIGHT + 3.0;
64         _line = new SimpleLine(*this, 0.0, 0.0, 0.0, _height);
65         _line->property_color_rgba() = _outline_color_rgba;
66         _rect = new SimpleRect(*this, 0.0, 0.0, flagwidth, flagheight);
67         _rect->property_outline_color_rgba() = _outline_color_rgba;
68         _rect->property_fill_color_rgba() = _fill_color_rgba;
69
70         _name_pixbuf->raise_to_top();
71 }
72
73 CanvasFlag::~CanvasFlag()
74 {
75         delete_allocated_objects();
76 }
77
78 void
79 CanvasFlag::set_height (double h)
80 {
81         _height = h;
82
83         if (_line) {
84                 _line->property_y2() = _height;
85         }
86 }