2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "hara-kiri-group-spanner.hh"
10 #include "axis-group-interface.hh"
14 Axis_group_interface::add_element (Grob*me,Grob *e)
16 for (SCM ax = me->get_property ("axes"); ax != SCM_EOL ; ax = ly_cdr (ax))
18 Axis a = (Axis) ly_scm2int (ly_car (ax));
20 if (!e->get_parent (a))
21 e->set_parent (me, a);
24 Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
25 me->add_dependency (e);
29 Axis_group_interface::has_axis (Grob*me,Axis a)
32 urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
34 return me->has_extent_callback (group_extent_callback_proc, a) ||
35 (me->has_extent_callback (Hara_kiri_group_spanner::y_extent_proc, a));
39 Axis_group_interface::relative_group_extent (Axis a, Grob *common, SCM elts)
42 for (SCM s = elts; ly_c_pair_p (s); s = ly_cdr (s))
44 Grob * se = unsmob_grob (ly_car (s));
45 Interval dims = se->extent (common, a);
46 if (!dims.is_empty ())
52 MAKE_SCHEME_CALLBACK (Axis_group_interface,group_extent_callback,2);
54 Axis_group_interface::group_extent_callback (SCM element_smob, SCM scm_axis)
56 Grob *me = unsmob_grob (element_smob);
57 Axis a = (Axis) ly_scm2int (scm_axis);
59 SCM elts = me->get_property ("elements");
60 Grob * common = common_refpoint_of_list (elts, me, a);
62 Real my_coord = me->relative_coordinate (common, a);
63 Interval r (relative_group_extent (a, common, elts));
65 return ly_interval2scm (r - my_coord);
69 Axis_group_interface::set_axes (Grob*me,Axis a1, Axis a2)
71 SCM sa1= scm_int2num (a1);
72 SCM sa2 = scm_int2num (a2);
74 SCM axes = me->get_property ("axes");
76 if (!ly_c_pair_p (axes)
77 || scm_c_memq (sa1, axes) == SCM_BOOL_F
78 || scm_c_memq (sa2, axes) == SCM_BOOL_F)
80 SCM ax = scm_cons (sa1, SCM_EOL);
82 ax= scm_cons (sa2, ax);
83 me->set_property ("axes", ax);
86 if (a1 != X_AXIS && a2 != X_AXIS)
87 me->set_extent (SCM_EOL, X_AXIS);
88 if (a1 != Y_AXIS && a2 != Y_AXIS)
89 me->set_extent (SCM_EOL, Y_AXIS);
92 why so convoluted ? (fixme/documentme?)
94 if (me->has_extent_callback (Grob::stencil_extent_proc, a1))
95 me->set_extent (Axis_group_interface::group_extent_callback_proc,a1);
96 if (me->has_extent_callback (Grob::stencil_extent_proc, a2))
97 me->set_extent (Axis_group_interface::group_extent_callback_proc,a2);
101 Axis_group_interface::get_children (Grob*me)
103 Link_array<Grob> childs;
106 if (!has_interface (me))
109 for (SCM ep = me->get_property ("elements"); ly_c_pair_p (ep); ep = ly_cdr (ep))
111 Grob* e = unsmob_grob (ly_car (ep));
113 childs.concat (Axis_group_interface::get_children (e));
121 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
122 "An object that groups other layout objects.",