Add display method for \bendAfter.
[lilypond/mpolesky.git] / lily / self-aligment-interface.cc
blob47607b096f84ab1fbf4742a26314dca52fa79305
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "self-alignment-interface.hh"
22 #include "warn.hh"
23 #include "paper-column.hh"
24 #include "grob.hh"
26 MAKE_SCHEME_CALLBACK (Self_alignment_interface, y_aligned_on_self, 1);
27 SCM
28 Self_alignment_interface::y_aligned_on_self (SCM element)
30 return aligned_on_self (unsmob_grob (element), Y_AXIS, false, 0, 0);
33 MAKE_SCHEME_CALLBACK (Self_alignment_interface, x_aligned_on_self, 1);
34 SCM
35 Self_alignment_interface::x_aligned_on_self (SCM element)
37 return aligned_on_self (unsmob_grob (element), X_AXIS, false, 0, 0);
40 MAKE_SCHEME_CALLBACK (Self_alignment_interface, pure_y_aligned_on_self, 3);
41 SCM
42 Self_alignment_interface::pure_y_aligned_on_self (SCM smob, SCM start, SCM end)
44 return aligned_on_self (unsmob_grob (smob), Y_AXIS, true, robust_scm2int (start, 0), robust_scm2int (end, INT_MAX));
47 SCM
48 Self_alignment_interface::aligned_on_self (Grob *me, Axis a, bool pure, int start, int end)
50 SCM sym = (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X")
51 : ly_symbol2scm ("self-alignment-Y");
53 SCM align (me->internal_get_property (sym));
54 if (scm_is_number (align))
56 Interval ext (me->maybe_pure_extent (me, a, pure, start, end));
57 if (ext.is_empty ())
58 programming_error ("cannot align on self: empty element");
59 else
60 return scm_from_double (- ext.linear_combination (scm_to_double (align)));
62 return scm_from_double (0.0);
67 SCM
68 Self_alignment_interface::centered_on_object (Grob *him, Axis a)
70 return scm_from_double (robust_relative_extent (him, him, a).center ());
74 MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_x_parent, 1);
75 SCM
76 Self_alignment_interface::centered_on_x_parent (SCM smob)
78 return centered_on_object (unsmob_grob (smob)->get_parent (X_AXIS), X_AXIS);
82 MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_y_parent, 1);
83 SCM
84 Self_alignment_interface::centered_on_y_parent (SCM smob)
86 return centered_on_object (unsmob_grob (smob)->get_parent (Y_AXIS), Y_AXIS);
90 MAKE_SCHEME_CALLBACK (Self_alignment_interface, x_centered_on_y_parent, 1);
91 SCM
92 Self_alignment_interface::x_centered_on_y_parent (SCM smob)
94 return centered_on_object (unsmob_grob (smob)->get_parent (Y_AXIS), X_AXIS);
97 MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_x_parent,1);
98 SCM
99 Self_alignment_interface::aligned_on_x_parent (SCM smob)
101 return aligned_on_parent (unsmob_grob (smob), X_AXIS);
104 MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_y_parent,1);
106 Self_alignment_interface::aligned_on_y_parent (SCM smob)
108 return aligned_on_parent (unsmob_grob (smob), Y_AXIS);
112 Self_alignment_interface::aligned_on_parent (Grob *me, Axis a)
114 Grob *him = me->get_parent (a);
115 if (Paper_column::has_interface (him))
116 return scm_from_double (0.0);
118 Interval he = him->extent (him, a);
120 SCM sym = (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X")
121 : ly_symbol2scm ("self-alignment-Y");
122 SCM align_prop (me->internal_get_property (sym));
124 if (!scm_is_number (align_prop))
125 return scm_from_int (0);
127 Real x = 0.0;
128 Real align = scm_to_double (align_prop);
130 Interval ext (me->extent (me, a));
131 if (ext.is_empty ())
132 programming_error ("cannot align on self: empty element");
133 else
134 x -= ext.linear_combination (align);
136 if (!he.is_empty ())
137 x += he.linear_combination (align);
139 return scm_from_double (x);
142 void
143 Self_alignment_interface::set_center_parent (Grob *me, Axis a)
145 add_offset_callback (me,
146 (a==X_AXIS) ? centered_on_x_parent_proc : centered_on_y_parent_proc,
150 void
151 Self_alignment_interface::set_align_self (Grob *me, Axis a)
153 add_offset_callback (me,
154 (a==X_AXIS) ? x_aligned_on_self_proc : y_aligned_on_self_proc,
158 ADD_INTERFACE (Self_alignment_interface,
159 "Position this object on itself and/or on its parent. To this"
160 " end, the following functions are provided:\n"
161 "\n"
162 "@table @code\n"
163 "@item Self_alignment_interface::[xy]_aligned_on_self\n"
164 "Align self on reference point, using"
165 " @code{self-alignment-X} and @code{self-alignment-Y}."
166 "@item Self_alignment_interface::aligned_on_[xy]_parent\n"
167 "@item Self_alignment_interface::centered_on_[xy]_parent\n"
168 "Shift the object so its own reference point is centered on"
169 " the extent of the parent\n"
170 "@end table\n",
172 /* properties */
173 "self-alignment-X "
174 "self-alignment-Y "