2 staff-side.cc -- implement Staff_side_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "side-position-interface.hh"
11 #include "staff-symbol.hh"
14 #include "dimensions.hh"
15 #include "dimension-cache.hh"
16 #include "staff-symbol-referencer.hh"
18 Side_position_interface::Side_position_interface (Score_element const *e)
20 elt_l_ = (Score_element*)e;
25 Side_position_interface::add_support (Score_element*e)
27 SCM sup = elt_l_->get_elt_property ("side-support");
28 elt_l_->set_elt_property ("side-support",
29 gh_cons (e->self_scm_,sup));
35 Side_position_interface::get_direction () const
37 SCM d = elt_l_->get_elt_property ("direction");
39 return to_dir (d) ? to_dir (d) : DOWN;
41 Direction relative_dir = UP;
42 SCM reldir = elt_l_->get_elt_property ("side-relative-direction"); // should use a lambda.
45 relative_dir = to_dir (reldir);
48 SCM other_elt = elt_l_->get_elt_property ("direction-source");
49 Score_element * e = unsmob_element(other_elt);
52 return (Direction)(relative_dir * Side_position_interface (e).get_direction ());
59 Callback that does the aligning.
62 Side_position_interface::side_position (Dimension_cache const * c)
64 Score_element * me = dynamic_cast<Score_element*> (c->element_l ());
67 Axis axis = c->axis ();
68 Score_element *common = me->parent_l (axis);
69 SCM support = me->get_elt_property ("side-support");
70 for (SCM s = support; s != SCM_EOL; s = gh_cdr (s))
72 Score_element * e = unsmob_element ( gh_car (s));
74 common = common->common_refpoint (e, axis);
77 for (SCM s = support; s != SCM_EOL; s = gh_cdr (s))
80 Score_element * e = unsmob_element ( gh_car (s));
83 Real coord = e->relative_coordinate (common, axis);
85 dim.unite (coord + e->extent (axis));
94 Real off = me->parent_l (axis)->relative_coordinate (common, axis);
97 Direction dir = Side_position_interface (me).get_direction ();
99 SCM pad = me->remove_elt_property ("padding");
100 if (gh_number_p (pad))
102 off += gh_scm2double (pad) * dir;
104 Real total_off = dim[dir] + off;
106 if (fabs (total_off) > 100 CM)
107 programming_error ("Huh ? Improbable staff side dim.");
113 Side_position_interface::self_alignment (Dimension_cache const *c)
115 String s ("self-alignment-");
116 Axis ax = c->axis ();
117 s += (ax == X_AXIS) ? "X" : "Y";
118 Score_element *elm = dynamic_cast<Score_element*> (c->element_l ());
119 SCM align (elm->get_elt_property (s));
122 Direction d = to_dir (align);
123 Interval ext(elm->extent (ax));
128 return - ext.center ();
136 directed_round (Real f, Direction d)
145 Side_position_interface::quantised_position (Dimension_cache const *c)
147 Score_element * me = dynamic_cast<Score_element*> (c->element_l ());
148 Side_position_interface s(me);
149 Direction d = s.get_direction ();
150 Staff_symbol_referencer_interface si (me);
152 if (si.has_interface_b ())
154 Real p = si.position_f ();
155 Real rp = directed_round (p, d);
164 return (rp - p) * si.staff_space () / 2.0;
170 Side_position_interface::aligned_side (Dimension_cache const *c)
172 Score_element * me = dynamic_cast<Score_element*> (c->element_l ());
173 Side_position_interface s(me);
174 Direction d = s.get_direction ();
175 Axis ax = c->axis ();
176 Real o = side_position (c);
178 Interval iv = me->extent (ax);
184 SCM pad = me->get_elt_property ("padding");
185 if (gh_number_p (pad))
186 o += d *gh_scm2double (pad) ;
195 Side_position_interface::set_axis (Axis a)
197 // prop transparent ?
198 if (elt_l_->get_elt_property ("side-support") == SCM_UNDEFINED)
199 elt_l_->set_elt_property ("side-support" ,SCM_EOL);
201 elt_l_->dim_cache_[a]->off_callbacks_.push (aligned_side);
206 Side_position_interface::set_quantised (Axis a)
208 Dimension_cache * c = elt_l_->dim_cache_[a];
210 c->off_callbacks_.push (quantised_position);
214 Side_position_interface::get_axis () const
216 Dimension_cache * c = elt_l_->dim_cache_[X_AXIS];
217 for (int i=0 ; i < c->off_callbacks_.size();i ++)
218 if (c->off_callbacks_[i] == side_position
219 ||c->off_callbacks_[i] == aligned_side)
227 Side_position_interface::set_direction (Direction d)
229 elt_l_->set_elt_property ("direction", gh_int2scm (d));
233 Side_position_interface::has_interface_b () const
235 return elt_l_->get_elt_property ("side-support") != SCM_UNDEFINED;
239 Side_position_interface::supported_b () const
241 SCM s =elt_l_->get_elt_property ("side-support");
242 return s != SCM_UNDEFINED && s != SCM_EOL;