(staff_eligible): new function.
[lilypond.git] / lily / self-aligment-interface.cc
blobff47fb92f36d70f554bbbfce3bc0bc3edd0887ce
1 #include "self-alignment-interface.hh"
2 #include "warn.hh"
4 /*
5 Position centered on parent.
6 */
7 MAKE_SCHEME_CALLBACK (Self_alignment_interface,centered_on_parent,2);
8 SCM
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.empty_b () ? 0.0 : he.center ());
22 Position centered on parent.
24 MAKE_SCHEME_CALLBACK (Self_alignment_interface,centered_on_other_axis_parent,2);
25 SCM
26 Self_alignment_interface::centered_on_other_axis_parent (SCM element_smob,
27 SCM axis)
29 Grob *me = unsmob_grob (element_smob);
30 Axis a = (Axis) gh_scm2int (axis);
31 Grob *him = me->get_parent (other_axis (a));
32 Interval he = him->extent (him,a);
34 return gh_double2scm (he.empty_b () ? 0.0 : he.center ());
40 /**
41 callback that centers the element on itself
43 Requires that self-alignment-{X,Y} be set.
45 MAKE_SCHEME_CALLBACK (Self_alignment_interface,aligned_on_self,2);
46 SCM
47 Self_alignment_interface::aligned_on_self (SCM element_smob, SCM axis)
49 Grob *me = unsmob_grob (element_smob);
50 Axis a = (Axis) gh_scm2int (axis);
51 static SCM prop_syms[2];
53 if (!prop_syms[0])
55 prop_syms[X_AXIS] = ly_symbol2scm ("self-alignment-X");
56 prop_syms[Y_AXIS] = ly_symbol2scm ("self-alignment-Y");
59 SCM align (me->internal_get_grob_property (prop_syms[a]));
60 if (gh_number_p (align))
62 Interval ext (me->extent (me,a));
64 if (ext.empty_b ())
66 programming_error ("I'm empty. Can't align on self");
67 return gh_double2scm (0.0);
69 else
71 return gh_double2scm (- ext.linear_combination (gh_scm2double (align)));
74 else if (unsmob_grob (align))
76 return gh_double2scm (- unsmob_grob (align)->relative_coordinate (me, a));
78 return gh_double2scm (0.0);
82 ADD_INTERFACE (Self_alignment_interface, "self-alignment-interface",
83 "Position self using some alignment",
84 "self-alignment-X self-alignment-Y");