2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "axis-group-interface.hh"
11 #include "hara-kiri-group-spanner.hh"
15 Axis_group_interface::add_element (Grob *me, Grob *e)
17 SCM axes = me->get_property ("axes");
18 if (!scm_is_pair (axes))
19 programming_error ("axes should be nonempty");
21 for (SCM ax = axes; ax != SCM_EOL; ax = scm_cdr (ax))
23 Axis a = (Axis) scm_to_int (scm_car (ax));
25 if (!e->get_parent (a))
26 e->set_parent (me, a);
28 e->internal_set_property ((a == X_AXIS)
29 ? ly_symbol2scm ("axis-group-parent-X")
30 : ly_symbol2scm ("axis-group-parent-Y"),
34 Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
35 me->add_dependency (e);
39 Axis_group_interface::has_axis (Grob *me, Axis a)
42 urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
44 return me->has_extent_callback (group_extent_callback_proc, a)
45 || (me->has_extent_callback (Hara_kiri_group_spanner::y_extent_proc, a));
49 Axis_group_interface::relative_group_extent (SCM elts, Grob *common, Axis a)
52 for (SCM s = elts; scm_is_pair (s); s = scm_cdr (s))
54 Grob *se = unsmob_grob (scm_car (s));
55 Interval dims = se->extent (common, a);
56 if (!dims.is_empty ())
64 MAKE_SCHEME_CALLBACK (Axis_group_interface, group_extent_callback, 2);
66 Axis_group_interface::group_extent_callback (SCM element_smob, SCM scm_axis)
68 Grob *me = unsmob_grob (element_smob);
69 Axis a = (Axis) scm_to_int (scm_axis);
71 SCM elts = me->get_property ("elements");
72 Grob *common = common_refpoint_of_list (elts, me, a);
74 Real my_coord = me->relative_coordinate (common, a);
75 Interval r (relative_group_extent (elts, common, a));
77 return ly_interval2scm (r - my_coord);
81 Axis_group_interface::set_axes (Grob *me, Axis a1, Axis a2)
83 SCM sa1 = scm_int2num (a1);
84 SCM sa2 = scm_int2num (a2);
86 SCM axes = me->get_property ("axes");
88 if (!scm_is_pair (axes)
89 || scm_c_memq (sa1, axes) == SCM_BOOL_F
90 || scm_c_memq (sa2, axes) == SCM_BOOL_F)
92 SCM ax = scm_cons (sa1, SCM_EOL);
94 ax = scm_cons (sa2, ax);
95 me->set_property ("axes", ax);
98 if (a1 != X_AXIS && a2 != X_AXIS)
99 me->set_extent (SCM_EOL, X_AXIS);
100 if (a1 != Y_AXIS && a2 != Y_AXIS)
101 me->set_extent (SCM_EOL, Y_AXIS);
104 why so convoluted ? (fixme/documentme?)
106 if (me->has_extent_callback (Grob::stencil_extent_proc, a1))
107 me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a1);
108 if (me->has_extent_callback (Grob::stencil_extent_proc, a2))
109 me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a2);
113 Axis_group_interface::get_children (Grob *me)
115 Link_array<Grob> childs;
118 if (!has_interface (me))
121 for (SCM ep = me->get_property ("elements"); scm_is_pair (ep); ep = scm_cdr (ep))
123 Grob *e = unsmob_grob (scm_car (ep));
125 childs.concat (Axis_group_interface::get_children (e));
131 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
132 "An object that groups other layout objects.",