]> git.donarmstrong.com Git - lilypond.git/blob - lily/g-staff-side.cc
db1b29cd69dee8a84838c3529d17aa3bdbe6d711
[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--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "g-staff-side.hh"
11 #include "staff-symbol.hh"
12
13 G_staff_side_item::G_staff_side_item ()
14 {
15   dir_ = CENTER;
16   to_position_l_ = 0;
17   set_elt_property (transparent_scm_sym, SCM_BOOL_T);
18   staff_support_b_ = true;
19   axis_ = Y_AXIS;
20 }
21
22
23
24 void
25 G_staff_side_item::do_pre_processing ()
26 {
27   if (!dir_)
28     dir_ = get_default_direction ();
29
30   if (axis_ == X_AXIS)
31     position_self ();
32 }
33
34 Direction
35 G_staff_side_item::get_default_direction () const
36 {
37   return DOWN;
38 }
39
40
41 void
42 G_staff_side_item::set_victim (Score_element *e)
43 {
44   add_dependency (e);
45   to_position_l_ = e;
46   to_position_l_->dim_cache_[axis_].parent_l_ = &dim_cache_[axis_];
47 }
48
49 void
50 G_staff_side_item::add_support (Score_element*e)
51 {
52   add_dependency (e);
53   support_l_arr_.push (e);
54 }
55
56
57 void
58 G_staff_side_item::do_substitute_element_pointer (Score_element*o, Score_element*n)
59 {
60   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
61   if (o == to_position_l_)
62     to_position_l_ = n;
63   else
64     support_l_arr_.unordered_substitute (o,n);
65 }
66
67 void
68 G_staff_side_item::position_self ()
69 {
70
71   Interval dim;
72   Dimension_cache *common = 0;
73   if (support_l_arr_.size ())
74     {
75       common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
76                              axis_);
77
78       for (int i=0; i < support_l_arr_.size (); i++)
79         {
80           Score_element * e = support_l_arr_ [i];
81           Real coord = e->relative_coordinate (common, axis_);
82           dim.unite (coord + e->extent (axis_));
83         }
84     }
85   else
86     {
87       dim = Interval(0,0);
88       common = dim_cache_[axis_].parent_l_;
89     }
90
91   
92   Interval sym_dim
93     = to_position_l_
94     ? to_position_l_->extent (axis_)
95     : Interval(0,0);
96
97   Real off = dim_cache_[axis_].relative_coordinate (common);
98
99   SCM pad = remove_elt_property (padding_scm_sym);
100   if (pad != SCM_BOOL_F)
101     {
102       off += gh_scm2double (SCM_CDR(pad)) * dir_;
103     }
104   dim_cache_[axis_].set_offset (dim[dir_] - sym_dim[-dir_] + off);
105 }
106
107 void
108 G_staff_side_item::do_post_processing ()
109 {
110   if (axis_ == Y_AXIS)
111     position_self ();
112 }
113
114
115 void
116 G_staff_side_item::do_add_processing ()
117 {
118   if (staff_support_b_
119       && axis_ == Y_AXIS && staff_symbol_l ())
120     {
121       add_support (staff_symbol_l ());
122     }
123 }