]> git.donarmstrong.com Git - lilypond.git/blob - lily/g-staff-side.cc
72f952d89f9294367a38cbf573fe95fe77366629
[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 }
19
20
21 void
22 G_staff_side_item::do_pre_processing ()
23 {
24   if (!dir_)
25     set_default_direction ();
26
27   if (axis_ == X_AXIS)
28     position_self ();
29 }
30
31 void
32 G_staff_side_item::set_default_direction ()
33 {
34   dir_ = DOWN;
35 }
36
37
38 void
39 G_staff_side_item::set_victim (Score_element *e)
40 {
41   add_dependency (e);
42   to_position_l_ = e;
43   to_position_l_->dim_cache_[Y_AXIS].parent_l_ = &dim_cache_[Y_AXIS];
44 }
45
46 void
47 G_staff_side_item::add_support (Score_element*e)
48 {
49   add_dependency (e);
50   support_l_arr_.push (e);
51 }
52
53
54 void
55 G_staff_side_item::do_substitute_dependency (Score_element*o, Score_element*n)
56 {
57   if (o == to_position_l_)
58     to_position_l_ = n;
59   else
60     support_l_arr_.unordered_substitute (o,n);
61 }
62
63 void
64 G_staff_side_item::position_self ()
65 {
66   if (!support_l_arr_.size ())
67     return ;
68   
69   Dimension_cache *common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
70                                           axis_);
71
72   Interval dim;
73   for (int i=0; i < support_l_arr_.size (); i++)
74     {
75       Score_element * e = support_l_arr_ [i];
76       Real coord = e->relative_coordinate (common, axis_);
77       dim.unite (coord + e->extent (axis_));
78     }
79
80   Interval sym_dim = to_position_l_->extent (axis_);
81   Real off = dim_cache_[axis_].relative_coordinate (common) - padding_f_ * dir_;
82   
83   dim_cache_[axis_].set_offset (dim[dir_] - sym_dim[-dir_] - off);
84 }
85
86 void
87 G_staff_side_item::do_post_processing ()
88 {
89   if (axis_ == Y_AXIS)
90     position_self ();
91 }
92