2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "hara-kiri-group-spanner.hh"
10 #include "axis-group-interface.hh"
11 #include "score-element.hh"
14 Axis_group_interface::add_element (Score_element*me,Score_element *e)
16 for (SCM ax = me->get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
18 Axis a = (Axis) gh_scm2int (gh_car (ax));
21 e->set_parent (me, a);
24 Pointer_group_interface (me).add_element (e);
25 me->add_dependency (e);
29 Axis_group_interface::axis_b (Score_element*me,Axis a )
32 urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
36 return me->has_extent_callback_b (group_extent_callback, a) ||
37 (me->has_extent_callback_b (Hara_kiri_group_spanner::y_extent, a));
41 Axis_group_interface::relative_group_extent (Axis a, Score_element *common, SCM elts)
44 for (SCM s = elts; gh_pair_p (s); s = gh_cdr (s))
46 Score_element * se = unsmob_element (gh_car (s));
47 Interval dims = se->extent (a);
49 r.unite (dims + se->relative_coordinate (common, a));
55 Axis_group_interface::group_extent_callback (Score_element *me, Axis a)
57 Score_element * common =(Score_element*) me;
59 for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
61 Score_element * se = unsmob_element (gh_car (s));
62 common = se->common_refpoint (common, a);
65 Real my_coord = me->relative_coordinate (common, a);
66 Interval r (relative_group_extent (a, common, me->get_elt_property ("elements")));
74 Axis_group_interface::set_axes (Score_element*me,Axis a1, Axis a2)
77 SCM sa1= gh_int2scm (a1);
78 SCM sa2 = gh_int2scm (a2);
80 SCM axes = me->get_elt_property ("axes");
83 || scm_memq (sa1, axes) == SCM_BOOL_F
84 || scm_memq (sa2, axes) == SCM_BOOL_F)
86 SCM ax = gh_cons (sa1, SCM_EOL);
88 ax= gh_cons (sa2, ax);
89 me->set_elt_property ("axes", ax);
92 if (a1 != X_AXIS && a2 != X_AXIS)
93 me->set_extent_callback (0, X_AXIS);
94 if (a1 != Y_AXIS && a2 != Y_AXIS)
95 me->set_extent_callback (0, Y_AXIS);
97 // if (!me->has_extent_callback_b (a1))
98 if (me->has_extent_callback_b (Score_element::molecule_extent, a1))
99 me->set_extent_callback (Axis_group_interface::group_extent_callback,a1);
100 if (me->has_extent_callback_b (Score_element::molecule_extent, a2))
101 me->set_extent_callback (Axis_group_interface::group_extent_callback,a2);
104 Link_array<Score_element>
105 Axis_group_interface::get_children (Score_element*me)
107 Link_array<Score_element> childs;
110 if (!has_interface (me))
113 for (SCM ep = me->get_elt_property ("elements"); gh_pair_p (ep); ep = gh_cdr (ep))
115 Score_element* e = unsmob_element (gh_car (ep));
117 childs.concat (Axis_group_interface::get_children (e));
124 Axis_group_interface::has_interface (Score_element*me)
126 return me && me->has_interface (ly_symbol2scm ("axis-group-interface"));
132 Axis_group_interface::set_interface (Score_element*me)
134 if (!has_interface (me))
136 me->set_interface (ly_symbol2scm ("axis-group-interface"));