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 "staff-side.hh"
11 #include "staff-symbol.hh"
14 #include "dimensions.hh"
15 #include "dimension-cache.hh"
17 Side_position_interface::Side_position_interface (Score_element *e)
24 Side_position_interface::add_support (Score_element*e)
26 SCM sup = elt_l_->get_elt_property ("side-support");
27 elt_l_->set_elt_property ("side-support",
28 gh_cons (e->self_scm_,sup));
34 Side_position_interface::get_direction () const
36 SCM d = elt_l_->get_elt_property ("direction");
38 return to_dir (d) ? to_dir (d) : DOWN;
40 Direction relative_dir = UP;
41 SCM reldir = elt_l_->get_elt_property ("side-relative-direction"); // should use a lambda.
44 relative_dir = to_dir (reldir);
47 SCM other_elt = elt_l_->get_elt_property ("direction-source");
48 if (SMOB_IS_TYPE_B (Score_element, other_elt))
50 Score_element * e = SMOB_TO_TYPE(Score_element,other_elt);
52 return 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 Graphical_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 if (!SMOB_IS_TYPE_B (Score_element, gh_car (s)))
75 Score_element * e = SMOB_TO_TYPE(Score_element, gh_car (s));
76 common = common->common_refpoint (e, axis);
79 for (SCM s = support; s != SCM_EOL; s = gh_cdr (s))
81 if (!SMOB_IS_TYPE_B (Score_element, gh_car (s)))
84 Score_element * e = SMOB_TO_TYPE(Score_element, gh_car (s));
85 Real coord = e->relative_coordinate (common, axis);
87 dim.unite (coord + e->extent (axis));
96 Real off = me->parent_l (axis)->relative_coordinate (common, axis);
99 Direction dir = Side_position_interface (me).get_direction ();
101 SCM pad = me->remove_elt_property ("padding");
102 if (pad != SCM_UNDEFINED)
104 off += gh_scm2double (pad) * dir;
106 Real total_off = dim[dir] + off;
108 if (fabs (total_off) > 100 CM)
109 programming_error ("Huh ? Improbable staff side dim.");
115 Side_position_interface::self_alignment (Dimension_cache const *c)
117 String s ("self-alignment-");
118 Axis ax = c->axis ();
119 s += (ax == X_AXIS) ? "X" : "Y";
120 Score_element *elm = dynamic_cast<Score_element*> (c->element_l ());
121 SCM align (elm->get_elt_property (s));
124 Direction d = to_dir (align);
125 Interval ext(elm->extent (ax));
130 return - ext.center ();
138 Side_position_interface::aligned_side (Dimension_cache const *c)
140 Score_element * me = dynamic_cast<Score_element*> (c->element_l ());
141 Side_position_interface s(me);
142 Direction d = s.get_direction ();
143 Axis ax = s.get_axis ();
144 Real o = side_position (c);
146 Interval iv = me->extent (ax);
152 SCM pad = me->get_elt_property ("padding");
153 if (gh_number_p (pad))
154 o += d *gh_scm2double (pad) ;
161 Side_position_interface::set_axis (Axis a)
163 // prop transparent ?
164 if (elt_l_->get_elt_property ("side-support") == SCM_UNDEFINED)
165 elt_l_->set_elt_property ("side-support" ,SCM_EOL);
167 Axis other = Axis ((a +1)%2);
168 elt_l_->dim_cache_[a]->set_offset_callback (aligned_side);
169 elt_l_->dim_cache_[other]->set_offset_callback (0);
174 Side_position_interface::get_axis () const
176 Offset_cache_callback c = elt_l_->dim_cache_[X_AXIS]->off_callback_l_ ;
177 if (c == side_position
186 Side_position_interface::set_direction (Direction d)
188 elt_l_->set_elt_property ("direction", gh_int2scm (d));
192 Side_position_interface::is_staff_side_b () const
194 return elt_l_->get_elt_property ("side-support") != SCM_UNDEFINED;
198 Side_position_interface::supported_b () const
200 return elt_l_->get_elt_property ("side-support") != SCM_EOL;