]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/span-bar.cc
patch::: 1.3.8.uu1
[lilypond.git] / lily / span-bar.cc
index 1c9a8ba15962356d32c56b5979a206656c058ed3..fe85a4e6b65761619778a9606405c3fe8da735de 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-
-#include "dimen.hh"
+#include "dimension-cache.hh"
 #include "span-bar.hh"
 #include "lookup.hh"
-#include "symbol.hh"
+#include "dimensions.hh"
 #include "paper-def.hh"
 #include "molecule.hh"
-#include "vertical-align-elem.hh"
+#include "align-element.hh"
+#include "warn.hh"
 
 void
-Span_bar::add(Bar*b)
+Span_bar::add_bar (Score_element*b)
 {
-    b->spanned_i_ ++;
-    spanning_l_arr_.push(b);
-    add_dependency( b );
+  spanning_l_arr_.push (b);
+  add_dependency (b);
 }
 
-
-
 void
-Span_bar::do_substitute_dependency(Score_elem*o, Score_elem*n)
+Span_bar::do_substitute_element_pointer (Score_element*o, Score_element*n)
 {
-    Bar * bold = 0;
-    if  (o->is_type_b(Bar::static_name() )) 
-       bold = (Bar*)o->item();
-    else
-       return;
-
-    bold->spanned_i_ --;
-    Bar * b =0;
-    if (n && n->is_type_b(Bar::static_name() )) {
-       b = (Bar*)n->item();
-       b->spanned_i_ ++;
-    }
-    
-    spanning_l_arr_.substitute( bold , b);
+  spanning_l_arr_.unordered_substitute (o, n);
 }
 
 
-void
-Span_bar::set(Vertical_align_element *a)
+Interval
+Span_bar::do_width () const
 {
-    add_dependency( a );
+  Molecule m = lookup_l ()->bar (type_str_, 40 PT, paper_l ());
+  
+  return m.extent (X_AXIS);
 }
-    
 
-Interval
-Span_bar::do_width() const
+void
+Span_bar::do_pre_processing ()
 {
-    return paper()->lookup_l()->bar(type_str_, 40 PT).dim.x(); // ugh
+  Bar::do_pre_processing ();
+  
+  evaluate_empty ();
+  
+  set_empty (false, Y_AXIS); // a hack to make mark scripts work.
 }
+
 void
-Span_bar::do_pre_processing()
+Span_bar::do_post_processing ()
 {
-    if ( spanning_l_arr_.size () < 1) {
-       transparent_b_ = true;
-       empty_b_ =true;
-    } else {
-       if (type_str_ == "")
-           type_str_ = spanning_l_arr_[0]->type_str_;
-       if (type_str_ =="") {
-           transparent_b_=true;
-           empty_b_ = true;
-       } else if ( type_str_ == "|:") {
-           type_str_ = ".|";
-       } else if ( type_str_ == ":|"){
-           type_str_ = "|.";
-       }
+  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) 
+    {
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_empty (true, X_AXIS, Y_AXIS);   
+
+    }
+  if (type_str_.empty_b ()) 
+    {
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_empty (true);
+    }
+  else if (type_str_ == "|:") 
+    {
+      type_str_ = ".|";
+    }
+  else if (type_str_ == ":|")
+    {
+      type_str_ = "|.";
+    }
+  else if (type_str_ == ":|:")
+    {
+      type_str_ = ".|.";
     }
 }
 
-Symbol
-Span_bar::get_bar_sym(Real dy) const
+Interval
+Span_bar::get_spanned_interval () const
 {
-    return paper()->lookup_l()->bar(type_str_, dy);
+  Interval y_int;
+
+  for (int i=0; i < spanning_l_arr_.size (); i++) 
+    {
+      Graphical_element*common = common_refpoint (spanning_l_arr_[i], Y_AXIS);
+      Real y = spanning_l_arr_[i]->relative_coordinate (common, Y_AXIS)  
+       - relative_coordinate (common, Y_AXIS);
+
+      y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
+    }
+  return y_int;
 }
 
+Interval
+Span_bar::do_height () const
+{
+  return get_spanned_interval ();
+}
 
 Molecule*
-Span_bar::brew_molecule_p()const
+Span_bar::do_brew_molecule_p () const
 {
-    Interval y_int;
-    for (int i=0; i < spanning_l_arr_.size(); i++) {
-       Axis_group_element *common = 
-           common_group(spanning_l_arr_[i], Y_AXIS);
-       
-       Real y = spanning_l_arr_[i]->relative_coordinate(common, Y_AXIS)  
-           -relative_coordinate(common,Y_AXIS);
-
-       y_int.unite( y + spanning_l_arr_[i]->height() );
+  Interval iv (get_spanned_interval ());
+  Molecule*output = new Molecule;
+  if (!iv.empty_b())
+    {
+      output->add_molecule (lookup_l ()->bar (type_str_, iv.length (), paper_l ()));
     }
-
-    Symbol s = get_bar_sym(y_int.length());
-    Molecule*output = new Molecule(Atom(s));
-    output->translate (  y_int[-1], Y_AXIS );
-    return output;
+  else
+    {
+      programming_error("Huh? My children deflated (FIXME)");
+    }
+  return output;
 }
 
 
-IMPLEMENT_IS_TYPE_B1(Span_bar,Bar);
 
-Span_bar::Span_bar()
+Span_bar::Span_bar ()
 {
-    type_str_ = "";
+  type_str_ = "";
 }
+