]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/axis-group-element.cc
release: 1.3.10
[lilypond.git] / lily / axis-group-element.cc
index 8aa8263668e3f13dfc3cb3b6442d782e13ac9db0..5992ea461455522ca4fa17bf50d877b6b6155042 100644 (file)
@@ -3,29 +3,18 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "axis-group-element.hh"
-#include "graphical-axis-group.hh"
-
-void
-Axis_group_element::do_unlink()
-{
-  remove_all();
-}
-
-void
-Axis_group_element::do_junk_links()
-{
-  elem_l_arr_.set_size (0);
-}
-
+#include "axis-group-element.hh"
+#include "dimension-cache.hh"
 
 Link_array<Score_element>
 Axis_group_element::get_extra_dependencies() const
 {
-  return elem_l_arr ();
+  Link_array<Score_element> e(elem_l_arr ());
+  return e;
 }
 
 Link_array<Score_element>
@@ -35,8 +24,12 @@ Axis_group_element::elem_l_arr () const
     ugh. I know
   */
   Link_array<Score_element> r;
-  for (int i=0; i < elem_l_arr_.size (); i++)
-    r.push (elem_l_arr_[i]->access_Score_element());
+  for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
+    {
+      SCM e=gh_car (s); 
+      r.push (unsmob_element (e));
+    }
+      
   return r;
 }
 
@@ -45,11 +38,12 @@ Axis_group_element::get_children ()
 {
   Link_array<Score_element> childs;
   Link_array<Score_element> elems = elem_l_arr ();
+
   for (int i=0; i < elems.size (); i++) 
     {
       Score_element* e = elems[i];
       childs.push (e) ;
-      Axis_group_element * axis_group= e->access_Axis_group_element ();
+      Axis_group_element * axis_group= dynamic_cast <Axis_group_element *> (e);
       if (axis_group)
        childs.concat (axis_group->get_children ());      
     }
@@ -57,30 +51,82 @@ Axis_group_element::get_children ()
   return childs;
 }
 
+Axis_group_element::Axis_group_element()
+{
+  axes_[0] = (Axis)-1 ; 
+  axes_[1] = (Axis)-1 ;
+
+  set_elt_property ("elements", SCM_EOL);
+  set_elt_property ("transparent", SCM_BOOL_T);
+}
+
 void
-Axis_group_element::do_print() const
+Axis_group_element::set_axes (Axis a1, Axis a2)
 {
-  Graphical_axis_group::do_print();
+  axes_[0] = a1 ; 
+  axes_[1] = a2 ;
+  if (a1 != X_AXIS && a2 != X_AXIS)
+    set_empty (X_AXIS);
+  if (a1 != Y_AXIS && a2 != Y_AXIS)
+    set_empty (Y_AXIS);
+  
+  dim_cache_[a1]->set_callback(extent_callback);
+  dim_cache_[a2]->set_callback (extent_callback);
 }
 
-Axis_group_element::Axis_group_element(Axis a1, Axis a2)
-  : Graphical_axis_group (a1,a2)
+Interval
+Axis_group_element::extent_callback (Dimension_cache const *c) 
 {
-  transparent_b_ = true;
+  Axis a = c->axis ();
+  Axis_group_element * me
+    = dynamic_cast<Axis_group_element*> (c->element_l ()); 
+
+  Interval r;
+  for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
+    {
+      SCM e=gh_car (s); 
+      Score_element * se = SMOB_TO_TYPE (Score_element, e);
+
+      Interval dims = se->extent (a);
+      if (!dims.empty_b ())
+       r.unite (dims + se->relative_coordinate (me, a));
+    }
+
+  return r;
 }
 
-Axis_group_element::Axis_group_element ()
-  : Graphical_axis_group (X_AXIS, Y_AXIS)
+
+/*
+  UGH.
+ */
+void
+Axis_group_element::add_extra_element (Score_element *e)
 {
-  transparent_b_ = true;
+  add_element (e);
 }
 
-Axis_group_element*
-Axis_group_element::access_Axis_group_element ()
+
+void
+Axis_group_element::add_element (Score_element *e)
 {
-  return this;
+  used_b_ =true;
+  e->used_b_ = true;
+  
+  for (int i = 0; i < 2; i++)
+    {
+      if (!e->parent_l (axes_[i]))
+       e->set_parent (this, axes_[i]);
+    }
+  set_elt_property ("elements",
+                   gh_cons (e->self_scm_,
+                            get_elt_property ("elements")));
+                            
+  assert (e->parent_l(Y_AXIS) == this || e->parent_l (X_AXIS) == this);
 }
 
 
 
-IMPLEMENT_IS_TYPE_B2(Axis_group_element, Score_element, Graphical_axis_group);
+
+
+
+