some C++-ification of GnomeCanvasBlah
[ardour.git] / gtk2_ardour / ghostregion.cc
1 #include "canvas-simplerect.h"
2 #include "ghostregion.h"
3 #include "automation_time_axis.h"
4 #include "rgb_macros.h"
5
6 using namespace Editing;
7
8 GhostRegion::GhostRegion (AutomationTimeAxisView& atv, double initial_pos)
9         : trackview (atv)
10 {
11   //group = gnome_canvas_item_new (GNOME_CANVAS_GROUP(trackview.canvas_display),
12   //                         gnome_canvas_group_get_type(),
13   //                         "x", initial_pos,
14   //                         "y", 0.0,
15   //                         NULL);
16         group = new Gnome::Canvas::Group (*trackview.canvas_display);
17         group->set_property ("x", initial_pos);
18         group->set_property ("y", 0.0);
19
20         base_rect = new Gnome::Canvas::SimpleRect (*group);
21         base_rect->set_property ("x1", (double) 0.0);
22         base_rect->set_property ("y1", (double) 0.0);
23         base_rect->set_property ("y2", (double) trackview.height);
24         base_rect->set_property ("outline_what", (guint32) 0);
25         base_rect->set_property ("outline_color_rgba", color_map[cGhostTrackBaseOutline]);
26         base_rect->set_property ("fill_color_rgba", color_map[cGhostTrackBaseFill]);
27         group->lower_to_bottom ();
28
29         atv.add_ghost (this);
30 }
31
32 GhostRegion::~GhostRegion ()
33 {
34         GoingAway (this);
35         gtk_object_destroy (GTK_OBJECT(group));
36 }
37
38 void
39 GhostRegion::set_samples_per_unit (double spu)
40 {
41         for (vector<GnomeCanvasItem*>::iterator i = waves.begin(); i != waves.end(); ++i) {
42                 gnome_canvas_item_set ((*i), "samples_per_unit", spu, NULL);
43         }               
44 }
45
46 void
47 GhostRegion::set_duration (double units)
48 {
49         base_rect->set_property ("x2", units);
50 }
51
52 void
53 GhostRegion::set_height ()
54 {
55         gdouble ht;
56         vector<GnomeCanvasItem*>::iterator i;
57         uint32_t n;
58
59         base_rect->set_property ("y2", (double) trackview.height);
60         ht = ((trackview.height) / (double) waves.size());
61         
62         for (n = 0, i = waves.begin(); i != waves.end(); ++i, ++n) {
63                 gdouble yoff = n * ht;
64                 gnome_canvas_item_set ((*i), "height", ht, "y", yoff, NULL);
65         }
66 }
67