]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/axis-group-interface.cc
* lily/note-column.cc (translate_rests): call flush_extent_cache()
[lilypond.git] / lily / axis-group-interface.cc
index f15c84ca5ca1946da02f701a727bbdbbd2fef3bd..6a41e1eaffae3088cb4c67e4ac5edaf51282ed6e 100644 (file)
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
 #include "axis-group-interface.hh"
-#include "score-element.hh"
-#include "dimension-cache.hh"
-
-Axis_group_interface::Axis_group_interface (Score_element*s)
-{
-  elt_l_ = s;
-}
-
-Axis_group_interface
-Axis_group_interface (Score_element*s)
-{
-  return Axis_group_interface (s);
-}
+#include "hara-kiri-group-spanner.hh"
 
 void
-Axis_group_interface::add_element (Score_element *e)
+Axis_group_interface::add_element (Grob*me, Grob *e)
 {
-  elt_l_->used_b_ = true;
-  e->used_b_ = true;
-
-  for (SCM ax = elt_l_->get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
+  for (SCM ax = me->get_property ("axes"); ax != SCM_EOL ; ax = scm_cdr (ax))
     {
-      Axis a = (Axis) gh_scm2int (gh_car (ax));
+      Axis a = (Axis) scm_to_int (scm_car (ax));
       
-      if (!e->parent_l (a))
-       e->set_parent (elt_l_, a);
+      if (!e->get_parent (a))
+       e->set_parent (me, a);
+
+      e->internal_set_property ((a == X_AXIS)
+                               ? ly_symbol2scm ("axis-group-parent-X")
+                               : ly_symbol2scm ("axis-group-parent-Y"),
+                               me->self_scm ()
+                               );
     }
-
-  Group_interface (elt_l_).add_element (e);
-
-  elt_l_->add_dependency (e);
+    
+  Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
+  me->add_dependency (e);
 }
 
-
 bool
-Axis_group_interface::axis_b (Axis a )const
+Axis_group_interface::has_axis (Grob*me, Axis a)
 {
-  return elt_l_->dim_cache_[a]->extent_callback_l_ == group_extent_callback;
+  /*
+    urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
+   */
+  return me->has_extent_callback (group_extent_callback_proc, a) ||
+ (me->has_extent_callback (Hara_kiri_group_spanner::y_extent_proc, a));
 }
 
 Interval
-Axis_group_interface::group_extent_callback (Dimension_cache const *c) 
+Axis_group_interface::relative_group_extent (Axis a, Grob *common, SCM elts)
 {
-  Axis a = c->axis ();
-  Score_element * me = c->element_l ();
-
   Interval r;
-  for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
+  for (SCM s = elts; scm_is_pair (s); s = scm_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));
+      Grob * se = unsmob_grob (scm_car (s));
+      Interval dims = se->extent (common, a);
+      if (!dims.is_empty ())
+       r.unite (dims);
     }
-
   return r;
 }
 
-
-void
-Axis_group_interface::set_interface ()
+MAKE_SCHEME_CALLBACK (Axis_group_interface, group_extent_callback, 2);
+SCM
+Axis_group_interface::group_extent_callback (SCM element_smob, SCM scm_axis)
 {
-  if (!has_interface_b ())
-    {
-      elt_l_->set_elt_property ("elements", SCM_EOL);
-      elt_l_->set_elt_property ("transparent", SCM_BOOL_T);
-      elt_l_->set_elt_property ("axes" , SCM_EOL);
-      group (elt_l_, "interfaces").add_thing (ly_symbol2scm ("Axis_group"));
-    }
+  Grob *me = unsmob_grob (element_smob);
+  Axis a = (Axis) scm_to_int (scm_axis);
+
+  SCM elts = me->get_property ("elements");
+  Grob * common = common_refpoint_of_list (elts, me, a);
+
+  Real my_coord = me->relative_coordinate (common, a);
+  Interval r (relative_group_extent (a, common, elts));
+
+  return ly_interval2scm (r - my_coord);
 }
 
 void
-Axis_group_interface::set_axes (Axis a1, Axis a2)
+Axis_group_interface::set_axes (Grob*me, Axis a1, Axis a2)
 {
-  // set_interface () ? 
-
-  SCM ax = gh_cons (gh_int2scm (a1), SCM_EOL);
-  if (a1 != a2)
-    ax= gh_cons (gh_int2scm (a2), ax);
+  SCM sa1= scm_int2num (a1);
+  SCM sa2 = scm_int2num (a2);
 
+  SCM axes = me->get_property ("axes");
   
-  elt_l_->set_elt_property ("axes", ax);
+  if (!scm_is_pair (axes)
+      || scm_c_memq (sa1, axes) == SCM_BOOL_F
+      || scm_c_memq (sa2, axes) == SCM_BOOL_F)
+    {
+      SCM ax = scm_cons (sa1, SCM_EOL);
+      if (a1 != a2)
+       ax = scm_cons (sa2, ax);
+      me->set_property ("axes", ax);
+    }
 
   if (a1 != X_AXIS && a2 != X_AXIS)
-    elt_l_->set_empty (X_AXIS);
+    me->set_extent (SCM_EOL, X_AXIS);
   if (a1 != Y_AXIS && a2 != Y_AXIS)
-    elt_l_->set_empty (Y_AXIS);
-  
-  elt_l_->dim_cache_[a1]->set_callback (Axis_group_interface::group_extent_callback);
-  elt_l_->dim_cache_[a2]->set_callback (Axis_group_interface::group_extent_callback);
+    me->set_extent (SCM_EOL, Y_AXIS);
+
+  /*
+    why so convoluted ? (fixme/documentme?) 
+   */
+  if (me->has_extent_callback (Grob::stencil_extent_proc, a1))
+    me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a1);
+  if (me->has_extent_callback (Grob::stencil_extent_proc, a2))
+    me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a2);
 }
 
-Link_array<Score_element
-Axis_group_interface::get_children ()
+Link_array<Grob
+Axis_group_interface::get_children (Grob*me)
 {
-  Link_array<Score_element> childs;
-  childs.push (elt_l_) ;
+  Link_array<Grob> childs;
+  childs.push (me) ;
 
-  if (!has_interface_b ())
+  if (!has_interface (me))
     return childs;
   
-  for (SCM ep = elt_l_->get_elt_property ("elements"); gh_pair_p (ep); ep = gh_cdr (ep))
+  for (SCM ep = me->get_property ("elements"); scm_is_pair (ep); ep = scm_cdr (ep))
     {
-      Score_element* e = unsmob_element (gh_car (ep));
+      Grob* e = unsmob_grob (scm_car (ep));
       if (e)
-       childs.concat (Axis_group_interface (e).get_children ());
+       childs.concat (Axis_group_interface::get_children (e));
     }
   
   return childs;
 }
 
-bool
-Axis_group_interface::has_interface_b ()
-{
-  SCM memq = scm_memq (ly_symbol2scm ("Axis_group"),
-             elt_l_->get_elt_property ("interfaces"));
-  
-  return (memq != SCM_BOOL_F);
-}
 
 
+ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
+  "An object that groups other layout objects.",
+  "axes elements");