2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "axis-group-interface.hh"
11 #include "pointer-group-interface.hh"
13 #include "hara-kiri-group-spanner.hh"
17 Axis_group_interface::add_element (Grob *me, Grob *e)
19 SCM axes = me->get_property ("axes");
20 if (!scm_is_pair (axes))
21 programming_error ("axes should be nonempty");
23 for (SCM ax = axes; ax != SCM_EOL; ax = scm_cdr (ax))
25 Axis a = (Axis) scm_to_int (scm_car (ax));
27 if (!e->get_parent (a))
28 e->set_parent (me, a);
30 e->internal_set_object ((a == X_AXIS)
31 ? ly_symbol2scm ("axis-group-parent-X")
32 : ly_symbol2scm ("axis-group-parent-Y"),
36 /* must be ordered, because Align_interface also uses
37 Axis_group_interface */
38 Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
42 Axis_group_interface::has_axis (Grob *me, Axis a)
44 SCM axes = me->get_property ("axes");
46 return (SCM_BOOL_F != scm_memq (scm_from_int (a), axes));
50 Axis_group_interface::relative_group_extent (vector<Grob*> const &elts,
54 for (vsize i = 0; i < elts.size (); i++)
57 Interval dims = se->extent (common, a);
58 if (!dims.is_empty ())
64 MAKE_SCHEME_CALLBACK (Axis_group_interface, width, 1);
66 Axis_group_interface::width (SCM smob)
68 Grob *me = unsmob_grob (smob);
69 return generic_group_extent (me, X_AXIS);
72 MAKE_SCHEME_CALLBACK (Axis_group_interface, height, 1);
74 Axis_group_interface::height (SCM smob)
76 Grob *me = unsmob_grob (smob);
77 return generic_group_extent (me, Y_AXIS);
81 Axis_group_interface::generic_group_extent (Grob *me, Axis a)
83 extract_grob_set (me, "elements", elts);
84 Grob *common = common_refpoint_of_array (elts, me, a);
86 Real my_coord = me->relative_coordinate (common, a);
87 Interval r (relative_group_extent (elts, common, a));
89 return ly_interval2scm (r - my_coord);
93 Axis_group_interface::get_children (Grob *me, vector<Grob*> *found)
95 found->push_back (me);
97 if (!has_interface (me))
100 extract_grob_set (me, "elements", elements);
101 for (vsize i = 0; i < elements.size (); i++)
103 Grob *e = elements[i];
104 Axis_group_interface::get_children (e, found);
108 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
110 "An object that groups other layout objects.",