]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/side-position-interface.cc
release: 1.3.49
[lilypond.git] / lily / side-position-interface.cc
index ba8861c5024c0c08401cd8d1b0173c75f76af0e7..c11f2e8909ab363f96c40b3aacde3e13d6d28142 100644 (file)
@@ -71,7 +71,7 @@ Side_position_interface::side_position (Dimension_cache const * c)
   SCM support = me->get_elt_property ("side-support");
   for (SCM s = support; s != SCM_EOL; s = gh_cdr (s))
     {
-      Score_element * e  = unsmob_element ( gh_car (s));
+      Score_element * e  = unsmob_element (gh_car (s));
       if (e)
        common = common->common_refpoint (e, axis);
     }
@@ -93,18 +93,21 @@ Side_position_interface::side_position (Dimension_cache const * c)
       dim = Interval(0,0);
     }
 
-  Real off =  me->parent_l (axis)->relative_coordinate (common, axis);
-
-
   Direction dir = Side_position_interface (me).get_direction ();
     
-  SCM pad = me->remove_elt_property ("padding");
-  if (gh_number_p (pad))
+  Real off =  me->parent_l (axis)->relative_coordinate (common, axis);
+  SCM minimum = me->remove_elt_property ("minimum-space");
+
+  Real total_off = dim[dir] + off;
+  SCM padding = me->remove_elt_property ("padding");
+  if (gh_number_p (padding))
     {
-      off += gh_scm2double (pad) * dir;
+      total_off += gh_scm2double (padding) * dir;
+    }
+  if (gh_number_p (minimum) && total_off * dir < gh_scm2double (minimum))
+    {
+      total_off = gh_scm2double (minimum) * dir;
     }
-  Real total_off = dim[dir] + off;
-
   if (fabs (total_off) > 100 CM)
     programming_error ("Huh ? Improbable staff side dim.");
 
@@ -126,7 +129,13 @@ Side_position_interface::aligned_on_self (Dimension_cache const *c)
     {
       Direction d = to_dir (align);
       Interval ext(elm->extent (ax));
-      if (d)
+
+      if (ext.empty_b ())
+       {
+         programming_error ("I'm empty. Can't align on self");
+         return 0.0;
+       }
+      else if (d)
        {
          return - ext[d];
        }
@@ -136,6 +145,8 @@ Side_position_interface::aligned_on_self (Dimension_cache const *c)
     return 0.0;
 }
 
+
+
 Real
 directed_round (Real f, Direction d)
 {
@@ -230,26 +241,23 @@ Side_position_interface::set_axis (Axis a)
   if (elt_l_->get_elt_property ("side-support") == SCM_UNDEFINED)
     elt_l_->set_elt_property ("side-support" ,SCM_EOL);
 
-  elt_l_->dim_cache_[a]->off_callbacks_.push (aligned_side);
+  if (!elt_l_->has_offset_callback_b (aligned_side, a))
+    elt_l_->add_offset_callback (aligned_side, a);
 }
 
 
 void
 Side_position_interface::set_quantised (Axis a)
 {
-  Dimension_cache * c = elt_l_->dim_cache_[a];
-  
-  c->off_callbacks_.push (quantised_position);
+  elt_l_->add_offset_callback (quantised_position, a);
 }
 
 Axis
 Side_position_interface::get_axis () const
 {
-  Dimension_cache * c =  elt_l_->dim_cache_[X_AXIS];
-  for (int i=0 ; i < c->off_callbacks_.size();i ++)
-    if (c->off_callbacks_[i] == side_position
-       ||c->off_callbacks_[i] == aligned_side)
-      return X_AXIS;
+  if (elt_l_->has_offset_callback_b (&side_position, X_AXIS)
+      || elt_l_->has_offset_callback_b (&aligned_side , X_AXIS))
+    return X_AXIS;
 
   
   return Y_AXIS;
@@ -261,6 +269,18 @@ Side_position_interface::set_direction (Direction d)
   elt_l_->set_elt_property ("direction", gh_int2scm (d));
 }
 
+void
+Side_position_interface::set_minimum_space (Real m)
+{
+  elt_l_->set_elt_property ("minimum-space", gh_double2scm (m));
+}
+
+void
+Side_position_interface::set_padding (Real p)
+{
+  elt_l_->set_elt_property ("padding", gh_double2scm (p));
+}
+
 bool
 Side_position_interface::has_interface_b () const
 {