]> git.donarmstrong.com Git - lilypond.git/blob - lily/g-staff-side.cc
78bd34f7da25e726c1b61fa6a91f6a5c9cb5a7e2
[lilypond.git] / lily / g-staff-side.cc
1 /*   
2   g-staff-side.cc --  implement G_staff_side_item
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "g-staff-side.hh"
11
12 G_staff_side_item::G_staff_side_item ()
13 {
14   dir_ = CENTER;
15   to_position_l_ = 0;
16   transparent_b_ = true;
17   padding_f_ = 0;
18   axis_ = Y_AXIS;
19 }
20
21
22 void
23 G_staff_side_item::do_pre_processing ()
24 {
25   if (!dir_)
26     set_default_direction ();
27
28   if (axis_ == X_AXIS)
29     position_self ();
30 }
31
32 void
33 G_staff_side_item::set_default_direction ()
34 {
35   dir_ = DOWN;
36 }
37
38
39 void
40 G_staff_side_item::set_victim (Score_element *e)
41 {
42   add_dependency (e);
43   to_position_l_ = e;
44   to_position_l_->dim_cache_[axis_].parent_l_ = &dim_cache_[axis_];
45 }
46
47 void
48 G_staff_side_item::add_support (Score_element*e)
49 {
50   add_dependency (e);
51   support_l_arr_.push (e);
52 }
53
54
55 void
56 G_staff_side_item::do_substitute_dependency (Score_element*o, Score_element*n)
57 {
58   if (o == to_position_l_)
59     to_position_l_ = n;
60   else
61     support_l_arr_.unordered_substitute (o,n);
62 }
63
64 void
65 G_staff_side_item::position_self ()
66 {
67   Interval dim;
68   Dimension_cache *common = 0;
69   if (support_l_arr_.size ())
70     {
71       common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
72                              axis_);
73
74       for (int i=0; i < support_l_arr_.size (); i++)
75         {
76           Score_element * e = support_l_arr_ [i];
77           Real coord = e->relative_coordinate (common, axis_);
78           dim.unite (coord + e->extent (axis_));
79         }
80     }
81   else
82     {
83       dim = Interval(0,0);
84       common = dim_cache_[axis_].parent_l_;
85     }
86   Interval sym_dim = to_position_l_->extent (axis_);
87   Real off = dim_cache_[axis_].relative_coordinate (common) - padding_f_ * dir_;
88   
89   dim_cache_[axis_].set_offset (dim[dir_] - sym_dim[-dir_] - off);
90 }
91
92 void
93 G_staff_side_item::do_post_processing ()
94 {
95   if (axis_ == Y_AXIS)
96     position_self ();
97 }
98