2 self-alignment-interface.cc -- implement Self_alignment_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "self-alignment-interface.hh"
12 MAKE_SCHEME_CALLBACK (Self_alignment_interface, y_aligned_on_self, 1);
14 Self_alignment_interface::y_aligned_on_self (SCM element)
16 return aligned_on_self (unsmob_grob (element), Y_AXIS);
19 MAKE_SCHEME_CALLBACK (Self_alignment_interface, x_aligned_on_self, 1);
21 Self_alignment_interface::x_aligned_on_self (SCM element)
23 return aligned_on_self (unsmob_grob (element), X_AXIS);
27 Self_alignment_interface::aligned_on_self (Grob *me, Axis a)
29 SCM sym = (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X")
30 : ly_symbol2scm ("self-alignment-Y");
32 SCM align (me->internal_get_property (sym));
33 if (scm_is_number (align))
35 Interval ext (me->extent (me, a));
37 programming_error ("can't align on self: empty element");
39 return scm_from_double (- ext.linear_combination (scm_to_double (align)));
41 return scm_from_double (0.0);
47 MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_x_parent, 1);
49 Self_alignment_interface::centered_on_x_parent (SCM smob)
51 return centered_on_parent (unsmob_grob (smob), X_AXIS);
55 MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_y_parent, 1);
57 Self_alignment_interface::centered_on_y_parent (SCM smob)
59 return centered_on_parent (unsmob_grob (smob), Y_AXIS);
63 Self_alignment_interface::centered_on_parent (Grob *me, Axis a)
65 Grob *him = me->get_parent (a);
66 Interval he = him->extent (him, a);
68 return scm_from_double (he.is_empty () ? 0.0 : he.center ());
71 MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_x_parent,1);
73 Self_alignment_interface::aligned_on_x_parent (SCM smob)
75 return aligned_on_parent (unsmob_grob (smob), X_AXIS);
78 MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_y_parent,1);
80 Self_alignment_interface::aligned_on_y_parent (SCM smob)
82 return aligned_on_parent (unsmob_grob (smob), Y_AXIS);
86 Self_alignment_interface::aligned_on_parent (Grob *me, Axis a)
88 Grob *him = me->get_parent (a);
89 Interval he = him->extent (him, a);
91 SCM sym = (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X")
92 : ly_symbol2scm ("self-alignment-Y");
93 SCM align_prop (me->internal_get_property (sym));
95 if (!scm_is_number (align_prop))
96 return scm_from_int (0);
99 Real align = scm_to_double (align_prop);
101 Interval ext (me->extent (me, a));
103 programming_error ("can't align on self: empty element");
105 x -= ext.linear_combination (align);
108 x += he.linear_combination (align);
110 return scm_from_double (x);
113 ADD_INTERFACE (Self_alignment_interface, "self-alignment-interface",
114 "Position this object on itself and/or on its parent. To this end, the following functions "
117 "@item Self_alignment_interface::aligned_on_self\n"
118 " Align self on reference point, using @code{self-alignment-X} and "
119 "@code{self-alignment-Y}."
120 "@item Self_alignment_interface::aligned_on_parent\n"
121 "@item Self_alignment_interface::centered_on_parent\n"
122 " Shift the object so its own reference point is centered on the "
123 " extent of the parent \n"
124 "@item Self_alignment_interface::centered_on_other_axis_parent\n"
125 " For X-axis, center on the Y-parent, and vice versa.\n "
131 "self-alignment-Y ");