]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/span-bar.cc
release: 1.3.10
[lilypond.git] / lily / span-bar.cc
index 487f2b11d427f61aa4fdddd1f7afbea96b57ea42..2f43cd985f8b5b60aa14006ac9a8ffd866da2663 100644 (file)
@@ -5,7 +5,7 @@
 
   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-
+#include "dimension-cache.hh"
 #include "span-bar.hh"
 #include "lookup.hh"
 #include "dimensions.hh"
 #include "molecule.hh"
 #include "align-element.hh"
 #include "warn.hh"
+#include "group-interface.hh"
+
 
 void
 Span_bar::add_bar (Score_element*b)
 {
-  spanning_l_arr_.push (b);
+  Group_interface gi (this);
+  gi.add_element (b);
+
   add_dependency (b);
 }
 
-void
-Span_bar::do_substitute_element_pointer (Score_element*o, Score_element*n)
-{
-  spanning_l_arr_.unordered_substitute (o, n);
-}
-
-void
-Span_bar::set_align (Align_element *a)
-{
-  add_dependency (a);
-  Score_element * e = dynamic_cast<Score_element*>(a);
-  Item * i = dynamic_cast<Item*> (e);
-  e = dynamic_cast<Score_element*> (a);
-  i = dynamic_cast<Item*>(e);
-}
 
 Interval
-Span_bar::do_width () const
+Span_bar::width_callback (Dimension_cache const * c)
 {
-  Molecule m = lookup_l ()->bar (type_str_, 40 PT);
+  Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
+  Molecule m = s->lookup_l ()->bar (s->type_str_, 40 PT, s->paper_l ());
   
   return m.extent (X_AXIS);
 }
@@ -51,29 +41,33 @@ Span_bar::do_pre_processing ()
   Bar::do_pre_processing ();
   
   evaluate_empty ();
-  translate_axis (extra_x_off_, X_AXIS);
   
-  dim_cache_[Y_AXIS].set_empty (false); // a hack to make mark scripts work.
+  //  set_empty (false, Y_AXIS); // a hack to make mark scripts work.
 }
 
 void
 Span_bar::do_post_processing ()
 {
   Bar::do_post_processing ();
+  Interval i(get_spanned_interval ());
+
+  translate_axis (i.center (), Y_AXIS);
 }
 
 void
 Span_bar::evaluate_empty ()
 { 
-  if (spanning_l_arr_.size () < 1
+  if (!gh_pair_p (get_elt_property ("elements"))
     {
-      set_elt_property (transparent_scm_sym, SCM_BOOL_T);
-      set_empty (true);   
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_empty (X_AXIS);
+      set_empty (Y_AXIS);   
     }
   if (type_str_.empty_b ()) 
     {
-      set_elt_property (transparent_scm_sym, SCM_BOOL_T);
-      set_empty (true);
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_empty (X_AXIS);
+      set_empty (Y_AXIS);   
     }
   else if (type_str_ == "|:") 
     {
@@ -93,23 +87,33 @@ Interval
 Span_bar::get_spanned_interval () const
 {
   Interval y_int;
-  for (int i=0; i < spanning_l_arr_.size (); i++) 
+
+  for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
     {
-      Dimension_cache*common = 
-       common_group (spanning_l_arr_[i], Y_AXIS);
-       
-      Real y = spanning_l_arr_[i]->dim_cache_[Y_AXIS].relative_coordinate (common)  
-       -dim_cache_[Y_AXIS].relative_coordinate (common);
+      Score_element *bar = unsmob_element ( gh_car (s));
 
-      y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
+      if (!bar)
+       continue;
+      
+      Score_element*common = common_refpoint (bar, Y_AXIS);
+
+      Interval iv (bar->extent(Y_AXIS));
+      if (!iv.empty_b ())
+       {
+         Real y = bar->relative_coordinate (common, Y_AXIS)  
+           - relative_coordinate (common, Y_AXIS);
+
+         y_int.unite (y + iv);
+       }
     }
   return y_int;
 }
 
 Interval
-Span_bar::do_height () const
+Span_bar::height_callback (Dimension_cache const *c) 
 {
-  return get_spanned_interval ();
+  Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
+  return s->get_spanned_interval ();
 }
 
 Molecule*
@@ -119,12 +123,11 @@ Span_bar::do_brew_molecule_p () const
   Molecule*output = new Molecule;
   if (!iv.empty_b())
     {
-      output->add_molecule (lookup_l ()->bar (type_str_, iv.length ()));
-      output->translate_axis (iv.center (), Y_AXIS);
+      output->add_molecule (lookup_l ()->bar (type_str_, iv.length (), paper_l ()));
     }
   else
     {
-      warning("Huh? My children deflated (FIXME)");
+      programming_error("Huh? My children deflated (FIXME)");
     }
   return output;
 }
@@ -134,5 +137,7 @@ Span_bar::do_brew_molecule_p () const
 Span_bar::Span_bar ()
 {
   type_str_ = "";
-  extra_x_off_ = 0.0;
+  dim_cache_[X_AXIS]->set_callback (width_callback);
+  dim_cache_[Y_AXIS]->set_callback (height_callback);  
 }
+