]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 1.1.67
[lilypond.git] / lily / staff-side.cc
1 /*   
2   g-staff-side.cc --  implement Staff_side_element
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 "staff-side.hh"
11 #include "staff-symbol.hh"
12 #include "debug.hh"
13 #include "warn.hh"
14 #include "dimensions.hh"
15 #include "dimension-cache.hh"
16
17 Staff_side_element::Staff_side_element ()
18 {
19   dir_ = CENTER;
20   to_position_l_ = 0;
21   set_elt_property (transparent_scm_sym, SCM_BOOL_T);
22   axis_ = Y_AXIS;
23 }
24
25
26
27 void
28 Staff_side_element::do_pre_processing ()
29 {
30   if (!dir_)
31     dir_ = get_default_direction ();
32
33   if (axis_ == X_AXIS)
34     position_self ();
35 }
36
37 Direction
38 Staff_side_element::get_default_direction () const
39 {
40   return DOWN;
41 }
42
43
44 void
45 Staff_side_element::set_victim (Score_element *e)
46 {
47   add_dependency (e);
48   to_position_l_ = e;
49   to_position_l_->dim_cache_[axis_]->parent_l_ = dim_cache_[axis_];
50 }
51
52 void
53 Staff_side_element::add_support (Score_element*e)
54 {
55   add_dependency (e);
56   support_l_arr_.push (e);
57 }
58
59
60 void
61 Staff_side_element::do_substitute_element_pointer (Score_element*o, Score_element*n)
62 {
63   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
64   if (o == to_position_l_)
65     to_position_l_ = n;
66   else
67     support_l_arr_.unordered_substitute (o,n);
68 }
69
70 void
71 Staff_side_element::position_self ()
72 {
73   if (to_position_l_ &&
74       to_position_l_->get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
75     return;
76
77   Interval dim;
78   Dimension_cache *common = 0;
79   if (support_l_arr_.size ())
80     {
81       common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
82                              axis_);
83
84       for (int i=0; i < support_l_arr_.size (); i++)
85         {
86           Score_element * e = support_l_arr_ [i];
87           Real coord = e->relative_coordinate (common, axis_);
88
89           dim.unite (coord + e->extent (axis_));
90         }
91     }
92   else
93      common = dim_cache_[axis_]->parent_l_;
94
95   if (dim.empty_b ())
96     {
97       dim = Interval(0,0);
98     }
99
100   
101   Interval sym_dim
102     = to_position_l_
103     ? to_position_l_->extent (axis_)
104     : Interval(0,0);
105
106   Real off =  dim_cache_[axis_]->relative_coordinate (common);
107  
108
109
110   SCM pad = remove_elt_property (padding_scm_sym);
111   if (pad != SCM_BOOL_F)
112     {
113       off += gh_scm2double (SCM_CDR(pad)) * dir_;
114     }
115   Real total_off = dim[dir_] + off;
116
117   /*
118     no_staff_support_scm_sym is ugh bugfix to get staccato dots right.
119    */
120   if (to_position_l_ && to_position_l_->get_elt_property (no_staff_support_scm_sym) == SCM_BOOL_F)
121      total_off += - sym_dim[-dir_];
122   
123   dim_cache_[axis_]->set_offset (total_off);
124   if (fabs (total_off) > 100 CM)
125     programming_error ("Huh ? Improbable staff side dim.");
126 }
127
128 void
129 Staff_side_element::do_post_processing ()
130 {
131   if (axis_ == Y_AXIS)
132     position_self ();
133 }
134
135
136 void
137 Staff_side_element::do_add_processing ()
138 {
139   if (get_elt_property (no_staff_support_scm_sym) == SCM_BOOL_F
140       && axis_ == Y_AXIS && staff_symbol_l ())
141     {
142       add_support (staff_symbol_l ());
143     }
144 }
145
146 Interval
147 Staff_side_element::do_height () const
148 {
149   Interval i;
150   if (to_position_l_)
151     return to_position_l_->extent (Y_AXIS);
152   return i;
153 }
154
155 void
156 Staff_side_element::do_print () const
157 {
158 #ifndef NPRINT
159   if (to_position_l_)
160     DOUT << "positioning " << to_position_l_->name();
161
162   DOUT << "axis == " << axis_name_str (axis_)
163        << ", dir == " << to_str (dir_ );
164 #endif
165 }
166
167
168 Interval
169 Staff_side_item::do_width () const
170 {
171   Interval i;
172   if (to_position_l_)
173     return to_position_l_->extent (X_AXIS);
174   return i;
175 }
176
177 void
178 Staff_side_item::do_print () const
179 {
180   Staff_side_element::do_print ();
181 }
182
183 void
184 Staff_side_spanner::do_print () const
185 {
186   Staff_side_element::do_print ();
187 }