]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
5e737330a0640a094f034e412f3bb0c6ca902278
[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   to_position_l_ = 0;
20   set_elt_property ("transparent", SCM_BOOL_T);
21   axis_ = Y_AXIS;
22 }
23
24 void
25 Staff_side_element::do_pre_processing ()
26 {
27   if (!get_direction ())
28     set_direction (get_default_direction ());
29
30   if (axis_ == X_AXIS)
31     position_self ();
32 }
33
34 Direction
35 Staff_side_element::get_default_direction () const
36 {
37   return DOWN;
38 }
39
40
41 void
42 Staff_side_element::set_victim (Score_element *e)
43 {
44   add_dependency (e);
45   to_position_l_ = e;
46   to_position_l_->set_parent (this, axis_);
47 }
48
49 void
50 Staff_side_element::add_support (Score_element*e)
51 {
52   add_dependency (e);
53   support_l_arr_.push (e);
54 }
55
56
57 void
58 Staff_side_element::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 Staff_side_element::position_self ()
69 {
70   if (to_position_l_ &&
71       to_position_l_->get_elt_property ("transparent") != SCM_UNDEFINED)
72     return;
73
74   Axis other = Axis ((axis_ + 1) % NO_AXES);
75   if (parent_l (axis_)->empty_b (axis_)
76       &&parent_l (axis_)->empty_b (other)) // guh
77     {
78       warning (_("No support; erasing script"));
79       to_position_l_->set_empty (X_AXIS,Y_AXIS);
80       to_position_l_->set_elt_property ("transparent", SCM_BOOL_T);
81       set_empty (X_AXIS, Y_AXIS);
82       return ;
83     }
84   
85   Interval dim;
86   Graphical_element *common = 0;
87   if (support_l_arr_.size ())
88     {
89       common = common_refpoint (typecast_array (support_l_arr_, (Graphical_element*)0),
90                                 axis_);
91
92       for (int i=0; i < support_l_arr_.size (); i++)
93         {
94           Score_element * e = support_l_arr_ [i];
95           Real coord = e->relative_coordinate (common, axis_);
96
97           dim.unite (coord + e->extent (axis_));
98         }
99     }
100   else
101      common = parent_l (axis_);
102
103   if (dim.empty_b ())
104     {
105       dim = Interval(0,0);
106     }
107
108   
109   Interval sym_dim
110     = to_position_l_
111     ? to_position_l_->extent (axis_)
112     : Interval(0,0);
113
114   Real off =  relative_coordinate (common, axis_);
115
116   SCM pad = remove_elt_property ("padding");
117   if (pad != SCM_UNDEFINED)
118     {
119       off += gh_scm2double (pad) * get_direction ();
120     }
121   Real total_off = dim[get_direction ()] + off;
122
123   /*
124     "no-staff-support" is ugh bugfix to get staccato dots right.
125    */
126   if (to_position_l_ && to_position_l_->get_elt_property ("no-staff-support") == SCM_UNDEFINED)
127      total_off += - sym_dim[-get_direction ()];
128   
129   dim_cache_[axis_]->set_offset (total_off);
130   if (fabs (total_off) > 100 CM)
131     programming_error ("Huh ? Improbable staff side dim.");
132 }
133
134 void
135 Staff_side_element::do_post_processing ()
136 {
137   if (axis_ == Y_AXIS)
138     position_self ();
139 }
140
141
142 void
143 Staff_side_element::do_add_processing ()
144 {
145   if (get_elt_property ("no-staff-support") == SCM_UNDEFINED
146       && axis_ == Y_AXIS && staff_symbol_l ())
147     {
148       add_support (staff_symbol_l ());
149     }
150 }
151
152 Interval
153 Staff_side_element::do_height () const
154 {
155   Interval i;
156   if (to_position_l_)
157     return to_position_l_->extent (Y_AXIS);
158   return i;
159 }
160
161 void
162 Staff_side_element::do_print () const
163 {
164 #ifndef NPRINT
165   if (to_position_l_)
166     DEBUG_OUT << "positioning " << to_position_l_->name();
167
168   DEBUG_OUT << "axis == " << axis_name_str (axis_)
169        << ", dir == " << to_str ((int)get_direction () );
170 #endif
171 }
172
173
174 Interval
175 Staff_side_item::do_width () const
176 {
177   Interval i;
178   if (to_position_l_)
179     return to_position_l_->extent (X_AXIS);
180   return i;
181 }
182
183 void
184 Staff_side_item::do_print () const
185 {
186   Staff_side_element::do_print ();
187 }
188
189 void
190 Staff_side_spanner::do_print () const
191 {
192   Staff_side_element::do_print ();
193 }
194