lilypond-1.5.1
[lilypond.git] / lily / axis-group-interface.cc
blobc974f3fa767b453ec10012c747befb6c6d4090a3
1 /*
2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "hara-kiri-group-spanner.hh"
10 #include "axis-group-interface.hh"
11 #include "grob.hh"
13 void
14 Axis_group_interface::add_element (Grob*me,Grob *e)
16 for (SCM ax = me->get_grob_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
18 Axis a = (Axis) gh_scm2int (gh_car (ax));
20 if (!e->parent_l (a))
21 e->set_parent (me, a);
24 Pointer_group_interface::add_element (me, "elements", e);
25 me->add_dependency (e);
28 bool
29 Axis_group_interface::axis_b (Grob*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_proc, a) ||
37 (me->has_extent_callback_b (Hara_kiri_group_spanner::y_extent_proc, a));
40 Interval
41 Axis_group_interface::relative_group_extent (Axis a, Grob *common, SCM elts)
43 Interval r;
44 for (SCM s = elts; gh_pair_p (s); s = gh_cdr (s))
46 Grob * se = unsmob_grob (gh_car (s));
47 Interval dims = se->extent (common, a);
48 if (!dims.empty_b ())
49 r.unite (dims);
51 return r;
54 MAKE_SCHEME_CALLBACK (Axis_group_interface,group_extent_callback,2);
55 SCM
56 Axis_group_interface::group_extent_callback (SCM element_smob, SCM scm_axis)
58 Grob *me = unsmob_grob (element_smob);
59 Axis a = (Axis) gh_scm2int (scm_axis);
61 Grob * common = (Grob*) me;
63 for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
65 Grob * se = unsmob_grob (gh_car (s));
66 common = se->common_refpoint (common, a);
69 Real my_coord = me->relative_coordinate (common, a);
70 Interval r (relative_group_extent (a, common, me->get_grob_property ("elements")));
72 return ly_interval2scm (r - my_coord);
75 void
76 Axis_group_interface::set_axes (Grob*me,Axis a1, Axis a2)
78 // set_interface () ?
79 SCM sa1= gh_int2scm (a1);
80 SCM sa2 = gh_int2scm (a2);
82 SCM axes = me->get_grob_property ("axes");
84 if (!gh_pair_p (axes)
85 || scm_memq (sa1, axes) == SCM_BOOL_F
86 || scm_memq (sa2, axes) == SCM_BOOL_F)
88 SCM ax = gh_cons (sa1, SCM_EOL);
89 if (a1 != a2)
90 ax= gh_cons (sa2, ax);
91 me->set_grob_property ("axes", ax);
94 if (a1 != X_AXIS && a2 != X_AXIS)
95 me->set_extent_callback (SCM_EOL, X_AXIS);
96 if (a1 != Y_AXIS && a2 != Y_AXIS)
97 me->set_extent_callback (SCM_EOL, Y_AXIS);
100 why so convoluted ? (fixme/documentme?)
102 if (me->has_extent_callback_b (Grob::molecule_extent_proc, a1))
103 me->set_extent_callback (Axis_group_interface::group_extent_callback_proc,a1);
104 if (me->has_extent_callback_b (Grob::molecule_extent_proc, a2))
105 me->set_extent_callback (Axis_group_interface::group_extent_callback_proc,a2);
108 Link_array<Grob>
109 Axis_group_interface::get_children (Grob*me)
111 Link_array<Grob> childs;
112 childs.push (me) ;
114 if (!has_interface (me))
115 return childs;
117 for (SCM ep = me->get_grob_property ("elements"); gh_pair_p (ep); ep = gh_cdr (ep))
119 Grob* e = unsmob_grob (gh_car (ep));
120 if (e)
121 childs.concat (Axis_group_interface::get_children (e));
124 return childs;
127 bool
128 Axis_group_interface::has_interface (Grob*me)
130 return me && me->has_interface (ly_symbol2scm ("axis-group-interface"));
133 void
134 Axis_group_interface::set_interface (Grob*me)
136 if (!has_interface (me))
138 me->set_interface (ly_symbol2scm ("axis-group-interface"));