]> git.donarmstrong.com Git - lilypond.git/blob - lily/self-aligment-interface.cc
* lily/accidental-placement.cc (stagger_apes): try to arrange accs
[lilypond.git] / lily / self-aligment-interface.cc
1 #include "side-position-interface.hh"
2 #include "warn.hh"
3
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)
10 {
11   Grob *me = unsmob_grob (element_smob);
12   Axis a = (Axis) gh_scm2int (axis);
13   Grob *him = me->get_parent (a);
14
15   return gh_double2scm (him->extent (him,a).center ());  
16 }
17
18
19
20
21 /**
22   callback that centers the element on itself
23
24   Requires that self-alignment-{X,Y} be set.
25  */
26 MAKE_SCHEME_CALLBACK (Self_alignment_interface,aligned_on_self,2);
27 SCM
28 Self_alignment_interface::aligned_on_self (SCM element_smob, SCM axis)
29 {
30   Grob *me = unsmob_grob (element_smob);
31   Axis a = (Axis) gh_scm2int (axis);
32   static SCM  prop_syms[2];
33
34   if (!prop_syms[0])
35     {
36       prop_syms[X_AXIS] = ly_symbol2scm ("self-alignment-X");
37       prop_syms[Y_AXIS] = ly_symbol2scm ("self-alignment-Y");
38     }
39   
40   SCM align (me->internal_get_grob_property (prop_syms[a]));
41   if (gh_number_p (align))
42     {
43       Interval ext (me->extent (me,a));
44
45       if (ext.empty_b ())
46         {
47           programming_error ("I'm empty. Can't align on self");
48           return gh_double2scm (0.0);
49         }
50       else
51         {
52           return gh_double2scm (- ext.linear_combination (gh_scm2double (align)));
53         }
54     }
55   else if (unsmob_grob (align))
56     {
57       return gh_double2scm (- unsmob_grob (align)->relative_coordinate (me,  a));
58     }
59   return gh_double2scm (0.0);
60 }
61
62
63 ADD_INTERFACE (Self_alignment_interface, "self-alignment-interface",
64   "Position self using some alignment",
65   "self-alignment-X self-alignment-Y");
66