2 align-elem.cc -- implement Align_elem
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "align-element.hh"
10 #include "interval.hh"
11 #include "direction.hh"
13 #include "dimension-cache.hh"
14 #include "axis-group-interface.hh"
17 This callback is set in the children of the align element. It does
18 not compute anything, but a side effect of a->do_side_processing ()
19 is that the elements are placed correctly. */
21 Align_element::alignment_callback (Dimension_cache
const *c
)
24 Score_element
* sc
= c
->element_l ()->parent_l (ax
);
25 Align_element
* a
= dynamic_cast<Align_element
*> (sc
);
26 if (a
&& a
->get_elt_property ("alignment-done") == SCM_UNDEFINED
)
28 a
->do_side_processing (ax
);
34 Align_element::add_element (Score_element
* s
)
36 s
->add_offset_callback (alignment_callback
, axis ());
37 axis_group (this).add_element (s
);
41 Hairy function to put elements where they should be. Can be tweaked
42 from the outside by setting minimum-space and extra-space in its
45 Align_element::do_side_processing (Axis a
)
47 set_elt_property ("alignment-done", SCM_BOOL_T
);
49 SCM d
= get_elt_property ("stacking-dir");
50 Direction stacking_dir
= gh_number_p(d
) ? to_dir (d
) : CENTER
;
57 Link_array
<Score_element
> elems
;
58 Link_array
<Score_element
> all_elts
59 = Group_interface__extract_elements (this, (Score_element
*) 0, "elements");
60 for (int i
=0; i
< all_elts
.size(); i
++)
62 Interval y
= all_elts
[i
]->extent(a
) + all_elts
[i
]->relative_coordinate (this, a
);
65 Score_element
*e
=dynamic_cast<Score_element
*>(all_elts
[i
]);
67 // todo: fucks up if item both in Halign & Valign.
68 SCM min_dims
= e
->remove_elt_property ("minimum-space");
69 if (gh_pair_p (min_dims
) &&
70 gh_number_p (gh_car (min_dims
))
71 && gh_number_p (gh_cdr (min_dims
)))
73 y
.unite (Interval (gh_scm2double (gh_car (min_dims
)),
74 gh_scm2double (gh_cdr (min_dims
))));
77 SCM extra_dims
= e
->remove_elt_property ("extra-space");
78 if (gh_pair_p (extra_dims
) &&
79 gh_number_p (gh_car (extra_dims
))
80 && gh_number_p (gh_cdr (extra_dims
)))
82 y
[LEFT
] += gh_scm2double (gh_car (extra_dims
));
83 y
[RIGHT
] += gh_scm2double (gh_cdr (extra_dims
));
92 Interval threshold
= Interval (0, Interval::infinity ());
93 SCM thr
= get_elt_property ("threshold");
96 threshold
[SMALLER
] = gh_scm2double (gh_car (thr
));
97 threshold
[BIGGER
] = gh_scm2double (gh_cdr (thr
));
101 for (int i
=0 ; i
< elems
.size(); i
++)
103 Real dy
= - stacking_dir
* dims
[i
][-stacking_dir
];
105 dy
+= stacking_dir
* dims
[i
-1][stacking_dir
];
109 dy
= (dy
>? threshold
[SMALLER
] )
110 <? threshold
[BIGGER
];
113 where_f
+= stacking_dir
* dy
;
114 elems
[i
]->translate_axis (where_f
, a
);
120 Align_element::get_count (Score_element
*s
)const
122 SCM e
= get_elt_property ("elements");
124 while (gh_pair_p (e
))
126 if (gh_car (e
) == s
->self_scm_
)
135 Align_element::axis () const
137 return Axis (gh_scm2int (gh_car (get_elt_property ("axes"))));
141 Align_element::set_axis (Axis a
)
143 axis_group (this).set_axes (a
, a
);
146 Align_element::Align_element ()
148 axis_group (this).set_interface ();