1 #include "self-alignment-interface.hh"
5 Position centered on parent.
7 MAKE_SCHEME_CALLBACK (Self_alignment_interface,centered_on_parent,2);
9 Self_alignment_interface::centered_on_parent (SCM element_smob, SCM axis)
11 Grob *me = unsmob_grob (element_smob);
12 Axis a = (Axis) gh_scm2int (axis);
13 Grob *him = me->get_parent (a);
14 Interval he = him->extent (him,a);
16 return gh_double2scm (he.is_empty () ? 0.0 : he.center ());
19 MAKE_SCHEME_CALLBACK (Self_alignment_interface,aligned_on_parent,2);
21 Self_alignment_interface::aligned_on_parent (SCM element_smob, SCM axis)
23 Grob *me = unsmob_grob (element_smob);
24 Axis a = (Axis) gh_scm2int (axis);
25 Grob *him = me->get_parent (a);
26 Interval he = him->extent (him,a);
28 SCM sym= (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X"): ly_symbol2scm ("self-alignment-Y");
29 SCM align_prop (me->internal_get_grob_property (sym));
31 if (!gh_number_p (align_prop))
32 return gh_int2scm (0);
36 Real align = gh_scm2double (align_prop);
38 Interval ext (me->extent (me,a));
41 programming_error ("I'm empty. Can't align on self");
45 x -= ext.linear_combination (align) ;
49 x += he.linear_combination (align);
52 return gh_double2scm (x);
56 Position centered on parent.
58 MAKE_SCHEME_CALLBACK (Self_alignment_interface,centered_on_other_axis_parent,2);
60 Self_alignment_interface::centered_on_other_axis_parent (SCM element_smob,
63 Grob *me = unsmob_grob (element_smob);
64 Axis a = (Axis) gh_scm2int (axis);
65 Grob *him = me->get_parent (other_axis (a));
66 Interval he = him->extent (him,a);
68 return gh_double2scm (he.is_empty () ? 0.0 : he.center ());
75 callback that centers the element on itself
77 Requires that self-alignment-{X,Y} be set.
79 MAKE_SCHEME_CALLBACK (Self_alignment_interface,aligned_on_self,2);
81 Self_alignment_interface::aligned_on_self (SCM element_smob, SCM axis)
83 Grob *me = unsmob_grob (element_smob);
84 Axis a = (Axis) gh_scm2int (axis);
86 SCM sym= (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X"): ly_symbol2scm ("self-alignment-Y");
88 SCM align (me->internal_get_grob_property (sym));
89 if (gh_number_p (align))
91 Interval ext (me->extent (me,a));
95 programming_error ("I'm empty. Can't align on self");
96 return gh_double2scm (0.0);
100 return gh_double2scm (- ext.linear_combination (gh_scm2double (align)));
103 else if (unsmob_grob (align))
105 return gh_double2scm (- unsmob_grob (align)->relative_coordinate (me, a));
107 return gh_double2scm (0.0);
111 ADD_INTERFACE (Self_alignment_interface, "self-alignment-interface",
112 "Position self using some alignment",
113 "self-alignment-X self-alignment-Y");