]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/self-aligment-interface.cc
* lily/context.cc (Context): take key argument in ctor.
[lilypond.git] / lily / self-aligment-interface.cc
index 365409461f8f8ec7f21abd3b45ea825960096974..e1db1ded12d752bfd2263892f50627596559a791 100644 (file)
+/*
+  self-alignment-interface.cc
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
 #include "self-alignment-interface.hh"
 #include "warn.hh"
 
-/*
-  Position centered on parent.
- */
-MAKE_SCHEME_CALLBACK (Self_alignment_interface,centered_on_parent,2);
+/* Position centered on parent.  */
+MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_parent, 2);
 SCM
 Self_alignment_interface::centered_on_parent (SCM element_smob, SCM axis)
 {
   Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) gh_scm2int (axis);
+  Axis a = (Axis) scm_to_int (axis);
   Grob *him = me->get_parent (a);
-  Interval he = him->extent (him,a);
+  Interval he = him->extent (him, a);
   
-  return  gh_double2scm (he.is_empty () ? 0.0 : he.center ());
+  return  scm_make_real (he.is_empty () ? 0.0 : he.center ());
 }
 
-MAKE_SCHEME_CALLBACK (Self_alignment_interface,aligned_on_parent,2);
+MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_parent, 2);
 SCM
 Self_alignment_interface::aligned_on_parent (SCM element_smob, SCM axis)
 {
   Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) gh_scm2int (axis);
+  Axis a = (Axis) scm_to_int (axis);
   Grob *him = me->get_parent (a);
-  Interval he = him->extent (him,a);
+  Interval he = him->extent (him, a);
   
-  SCM sym= (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X"): ly_symbol2scm ("self-alignment-Y");
-  SCM align_prop (me->internal_get_grob_property (sym));
+  SCM sym= (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X")
+    : ly_symbol2scm ("self-alignment-Y");
+  SCM align_prop (me->internal_get_property (sym));
 
-  if (!gh_number_p (align_prop))
-    return gh_int2scm (0);
+  if (!scm_is_number (align_prop))
+    return scm_int2num (0);
 
   Real x = 0.0;
-
-  Real align = gh_scm2double (align_prop);
+  Real align = scm_to_double (align_prop);
       
-  Interval ext (me->extent (me,a));
+  Interval ext (me->extent (me, a));
   if (ext.is_empty ())
-    {
-      programming_error ("I'm empty. Can't align on self");
-      
-    }
+    programming_error ("I'm empty. Can't align on self");
   else
     x -= ext.linear_combination (align) ;
 
   if (!he.is_empty ())
-    {
-      x += he.linear_combination (align);
-    }
+    x += he.linear_combination (align);
 
-  return gh_double2scm (x);
+  return scm_make_real (x);
 }
 
-/*
-  Position centered on parent.
- */
-MAKE_SCHEME_CALLBACK (Self_alignment_interface,centered_on_other_axis_parent,2);
+/* Position centered on parent. */
+MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_other_axis_parent, 2);
 SCM
-Self_alignment_interface::centered_on_other_axis_parent (SCM element_smob,
+Self_alignment_interface::centered_on_other_axis_parent (SCM element_smob, 
                                                         SCM axis)
 {
   Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) gh_scm2int (axis);
+  Axis a = (Axis) scm_to_int (axis);
   Grob *him = me->get_parent (other_axis (a));
-  Interval he = him->extent (him,a);
+  Interval he = him->extent (him, a);
   
-  return  gh_double2scm (he.is_empty () ? 0.0 : he.center ());
+  return  scm_make_real (he.is_empty () ? 0.0 : he.center ());
 }
 
-
-
-
-/**
-  callback that centers the element on itself
-
-  Requires that self-alignment-{X,Y} be set.
- */
-MAKE_SCHEME_CALLBACK (Self_alignment_interface,aligned_on_self,2);
+/** callback that centers the element on itself
+    Requires that self-alignment-{X, Y} be set.  */
+MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_self, 2);
 SCM
 Self_alignment_interface::aligned_on_self (SCM element_smob, SCM axis)
 {
   Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) gh_scm2int (axis);
+  Axis a = (Axis) scm_to_int (axis);
 
-  SCM sym= (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X"): ly_symbol2scm ("self-alignment-Y");
+  SCM sym= (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X")
+    : ly_symbol2scm ("self-alignment-Y");
   
-  SCM align (me->internal_get_grob_property (sym));
-  if (gh_number_p (align))
+  SCM align (me->internal_get_property (sym));
+  if (scm_is_number (align))
     {
-      Interval ext (me->extent (me,a));
-
+      Interval ext (me->extent (me, a));
       if (ext.is_empty ())
-       {
-         programming_error ("I'm empty. Can't align on self");
-         return gh_double2scm (0.0);
-       }
+       programming_error ("I'm empty. Can't align on self");
       else
-       {
-         return gh_double2scm (- ext.linear_combination (gh_scm2double (align)));
-       }
-    }
-  else if (unsmob_grob (align))
-    {
-      return gh_double2scm (- unsmob_grob (align)->relative_coordinate (me,  a));
+       return scm_make_real (- ext.linear_combination (scm_to_double (align)));
     }
-  return gh_double2scm (0.0);
+  return scm_make_real (0.0);
 }
 
 
 ADD_INTERFACE (Self_alignment_interface, "self-alignment-interface",
-  "Position self using some alignment",
-  "self-alignment-X self-alignment-Y");
+              "Position this object on itself and/or on its parent. To this end, the following functions "
+              " are provided: \n"
+              "@table @code \n"
+              "@item Self_alignment_interface::aligned_on_self\n"
+              "  Align self on reference point, using @code{self-alignment-X} and "
+              "@code{self-alignment-Y}."
+              "@item Self_alignment_interface::aligned_on_parent\n"
+              "@item Self_alignment_interface::centered_on_parent\n"
+              "  Shift the object so its own reference point is centered on the  "
+              " extent of the parent \n"
+              "@item Self_alignment_interface::centered_on_other_axis_parent\n"
+              " For X-axis, center on the Y-parent, and vice versa.\n "
+              "@end table\n", 
+              "self-alignment-X self-alignment-Y");