]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/span-bar.cc
release: 1.3.49
[lilypond.git] / lily / span-bar.cc
index 331201d4d0871304e20e588d4b3a531fe311955e..84a98332365bf4cf6f0a59f23a5c5f79e7c8bd64 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-
+#include "dimension-cache.hh"
 #include "span-bar.hh"
 #include "lookup.hh"
 #include "dimensions.hh"
-#include "atom.hh"
 #include "paper-def.hh"
 #include "molecule.hh"
-#include "align-element.hh"
+#include "warn.hh"
+#include "axis-group-interface.hh"
+#include "group-interface.hh"
 
 void
-Span_bar::add_bar (Bar*b)
+Span_bar::add_bar (Score_element*b)
 {
-  spanning_l_arr_.push (b);
-  add_dependency (b);
-}
+  Group_interface gi (this);
+  gi.add_element (b);
 
-void
-Span_bar::do_substitute_dependency (Score_element*o, Score_element*n)
-{
-  spanning_l_arr_.unordered_substitute (o, n);
+  add_dependency (b);
 }
 
-void
-Span_bar::set_align (Align_element *a)
-{
-  add_dependency (a);
-}
 
 Interval
-Span_bar::do_width () const
+Span_bar::width_callback (Dimension_cache const * c)
 {
-  return lookup_l ()->bar (type_str_, 40 PT).dim_.x (); // ugh
+  Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
+  String gl = ly_scm2string (s->get_elt_property ("glyph"));
+
+  /*
+    urg.
+   */
+  Molecule m = s->compound_barline (gl, 40 PT);
+  
+  return m.extent (X_AXIS);
 }
 
 void
-Span_bar::do_pre_processing ()
+Span_bar::before_line_breaking ()
 {
-  Bar::do_pre_processing ();
+  Bar::before_line_breaking ();
   
   evaluate_empty ();
 }
 
 void
-Span_bar::do_post_processing ()
+Span_bar::after_line_breaking ()
 {
-  Bar::do_post_processing ();
+  Bar::after_line_breaking ();
+  Interval i (get_spanned_interval ());
+  translate_axis (i.center (), Y_AXIS);
 }
 
 void
 Span_bar::evaluate_empty ()
 { 
-  if (spanning_l_arr_.size () < 1) 
-    {
-      transparent_b_ = true;
-      set_empty (true);   
-    }
-  if (type_str_.empty_b ()) 
-    {
-      transparent_b_=true;
-      set_empty (true);
-    }
-  else if (type_str_ == "|:") 
-    {
-      type_str_ = ".|";
-    }
-  else if (type_str_ == ":|")
+  if (!gh_pair_p (get_elt_property ("elements")))
     {
-      type_str_ = "|.";
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_extent_callback (0, X_AXIS);
+      set_extent_callback (0, Y_AXIS);   
     }
-  else if (type_str_ == ":|:")
+  
+  SCM gl = get_elt_property ("glyph");
+  if (!gh_string_p (gl))
     {
-      type_str_ = ".|.";
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_extent_callback (0, X_AXIS);
+      set_extent_callback (0, Y_AXIS);   
     }
+  else {
+    String type_str = ly_scm2string (gl);
+    if (type_str == "|:") 
+      {
+       type_str= ".|";
+      }
+    else if (type_str== ":|")
+      {
+       type_str= "|.";
+      }
+    else if (type_str== ":|:")
+      {
+       type_str= ".|.";
+      }
+
+    set_elt_property ("glyph", ly_str02scm (type_str.ch_C()));
+  }
 }
 
-Atom
-Span_bar::get_bar_sym (Real dy) const
+Interval
+Span_bar::get_spanned_interval () const
 {
-  if (dy < paper ()->staffheight_f () / 2)
-    return Atom ();
-  
-  return lookup_l ()->bar (type_str_, dy);
+  return Axis_group_interface::group_extent_callback (dim_cache_[Y_AXIS]);  
 }
 
-Molecule*
-Span_bar::brew_molecule_p () const
+
+Real
+Span_bar::get_bar_size () const
 {
-  Interval y_int;
-  for (int i=0; i < spanning_l_arr_.size (); i++) 
+  Interval iv (get_spanned_interval ());
+  if (iv.empty_b ())
     {
-      Graphical_axis_group *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 ());
+      programming_error("Huh? My children deflated (FIXME)");
+      iv = Interval (0,0);
     }
-
-  Atom s = get_bar_sym (y_int.length ());
-  Molecule*output = new Molecule (Atom (s));
-  output->translate_axis (y_int.center (), Y_AXIS);
-  return output;
+  return iv.length ();
 }
 
-IMPLEMENT_IS_TYPE_B1 (Span_bar,Bar);
-
 Span_bar::Span_bar ()
 {
-  type_str_ = "";
-}
+  group (this).set_interface ();
+  dim_cache_[X_AXIS]->set_extent_callback (width_callback);
+  
+  // dim_cache_[Y_AXIS]->set_extent_callback (Axis_group_interface::group_extent_callback);
 
-Span_bar*
-Span_bar::access_Span_bar ()
-{
-  return this;
+  dim_cache_[Y_AXIS]->set_extent_callback (0);
 }
+