-/*
- axis-group-interface.cc -- implement Axis_group_interface
-
+/*
+ axis-group-interface.cc -- implement Axis_group_interface
+
source file of the GNU LilyPond music typesetter
-
- (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
- */
-#include "hara-kiri-group-spanner.hh"
+
+ (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+*/
+
#include "axis-group-interface.hh"
-#include "score-element.hh"
+
+#include "pointer-group-interface.hh"
+#include "grob.hh"
+#include "hara-kiri-group-spanner.hh"
+#include "warn.hh"
void
-Axis_group_interface::add_element (Score_element*me,Score_element *e)
+Axis_group_interface::add_element (Grob *me, Grob *e)
{
- for (SCM ax = me->get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
+ SCM axes = me->get_property ("axes");
+ if (!scm_is_pair (axes))
+ programming_error ("axes should be nonempty");
+
+ for (SCM ax = axes; ax != SCM_EOL; ax = scm_cdr (ax))
{
- Axis a = (Axis) gh_scm2int (gh_car (ax));
-
- if (!e->parent_l (a))
+ Axis a = (Axis) scm_to_int (scm_car (ax));
+
+ if (!e->get_parent (a))
e->set_parent (me, a);
+
+ e->internal_set_object ((a == X_AXIS)
+ ? ly_symbol2scm ("axis-group-parent-X")
+ : ly_symbol2scm ("axis-group-parent-Y"),
+ me->self_scm ());
}
- Pointer_group_interface (me).add_element (e);
- me->add_dependency (e);
+ /* must be ordered, because Align_interface also uses
+ Axis_group_interface */
+ Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
}
bool
-Axis_group_interface::axis_b (Score_element*me,Axis a )
+Axis_group_interface::has_axis (Grob *me, Axis a)
{
- /*
- urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
+ SCM axes = me->get_property ("axes");
-
- */
- return me->has_extent_callback_b (group_extent_callback, a) ||
- (me->has_extent_callback_b (Hara_kiri_group_spanner::y_extent, a));
+ return (SCM_BOOL_F != scm_memq (scm_from_int (a), axes));
}
Interval
-Axis_group_interface::relative_group_extent (Axis a, Score_element *common, SCM elts)
+Axis_group_interface::relative_group_extent (vector<Grob*> const &elts,
+ Grob *common, Axis a)
{
Interval r;
- for (SCM s = elts; gh_pair_p (s); s = gh_cdr (s))
+ for (vsize i = 0; i < elts.size (); i++)
{
- Score_element * se = unsmob_element (gh_car (s));
- Interval dims = se->extent (a);
- if (!dims.empty_b ())
- r.unite (dims + se->relative_coordinate (common, a));
+ Grob *se = elts[i];
+ Interval dims = se->extent (common, a);
+ if (!dims.is_empty ())
+ r.unite (dims);
}
return r;
}
-Interval
-Axis_group_interface::group_extent_callback (Score_element *me, Axis a)
+MAKE_SCHEME_CALLBACK (Axis_group_interface, width, 1);
+SCM
+Axis_group_interface::width (SCM smob)
{
- Score_element * common =(Score_element*) me;
-
- for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
- {
- Score_element * se = unsmob_element (gh_car (s));
- common = se->common_refpoint (common, a);
- }
-
- Real my_coord = me->relative_coordinate (common, a);
- Interval r (relative_group_extent (a, common, me->get_elt_property ("elements")));
-
- return r - my_coord;
+ Grob *me = unsmob_grob (smob);
+ return generic_group_extent (me, X_AXIS);
}
-
-
-void
-Axis_group_interface::set_axes (Score_element*me,Axis a1, Axis a2)
+MAKE_SCHEME_CALLBACK (Axis_group_interface, height, 1);
+SCM
+Axis_group_interface::height (SCM smob)
{
- // set_interface () ?
- SCM sa1= gh_int2scm (a1);
- SCM sa2 = gh_int2scm (a2);
-
- SCM prop = me->get_elt_property ("axes");
+ Grob *me = unsmob_grob (smob);
+ return generic_group_extent (me, Y_AXIS);
+}
- if (!gh_pair_p (prop)
- || scm_memq (sa1, prop) == SCM_BOOL_F
- || scm_memq (sa2, prop) == SCM_BOOL_F)
- {
- SCM ax = gh_cons (sa1, SCM_EOL);
- if (a1 != a2)
- ax= gh_cons (sa2, ax);
- me->set_elt_property ("axes", ax);
- }
+SCM
+Axis_group_interface::generic_group_extent (Grob *me, Axis a)
+{
+ extract_grob_set (me, "elements", elts);
+ Grob *common = common_refpoint_of_array (elts, me, a);
- if (a1 != X_AXIS && a2 != X_AXIS)
- me->set_extent_callback (0, X_AXIS);
- if (a1 != Y_AXIS && a2 != Y_AXIS)
- me->set_extent_callback (0, Y_AXIS);
-
- // if (!me->has_extent_callback_b (a1))
- if (me->has_extent_callback_b (Score_element::molecule_extent, a1))
- me->set_extent_callback (Axis_group_interface::group_extent_callback,a1);
- if (me->has_extent_callback_b (Score_element::molecule_extent, a2))
- me->set_extent_callback (Axis_group_interface::group_extent_callback,a2);
+ Real my_coord = me->relative_coordinate (common, a);
+ Interval r (relative_group_extent (elts, common, a));
+
+ return ly_interval2scm (r - my_coord);
}
-Link_array<Score_element>
-Axis_group_interface::get_children (Score_element*me)
+void
+Axis_group_interface::get_children (Grob *me, vector<Grob*> *found)
{
- Link_array<Score_element> childs;
- childs.push (me) ;
+ found->push_back (me);
if (!has_interface (me))
- return childs;
-
- for (SCM ep = me->get_elt_property ("elements"); gh_pair_p (ep); ep = gh_cdr (ep))
+ return;
+
+ extract_grob_set (me, "elements", elements);
+ for (vsize i = 0; i < elements.size (); i++)
{
- Score_element* e = unsmob_element (gh_car (ep));
- if (e)
- childs.concat (Axis_group_interface::get_children (e));
+ Grob *e = elements[i];
+ Axis_group_interface::get_children (e, found);
}
-
- return childs;
-}
-
-bool
-Axis_group_interface::has_interface (Score_element*me)
-{
- return me && me->has_interface (ly_symbol2scm ("axis-group-interface"));
}
+ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
+ "An object that groups other layout objects.",
-void
-Axis_group_interface::set_interface (Score_element*me)
-{
- if (!has_interface (me))
- {
- me->set_interface (ly_symbol2scm ("axis-group-interface"));
- }
-}
+ /* properties */
+ "axes "
+ "elements ");