2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 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_grob_property ("axes"); ax
!= SCM_EOL
; ax
= ly_cdr (ax
))
18 Axis a
= (Axis
) gh_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::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
));
41 Axis_group_interface::relative_group_extent (Axis a
, Grob
*common
, SCM elts
)
44 for (SCM s
= elts
; gh_pair_p (s
); s
= ly_cdr (s
))
46 Grob
* se
= unsmob_grob (ly_car (s
));
47 Interval dims
= se
->extent (common
, a
);
54 MAKE_SCHEME_CALLBACK (Axis_group_interface
,group_extent_callback
,2);
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 SCM elts
= me
->get_grob_property ("elements");
62 Grob
* common
= common_refpoint_of_list (elts
, me
, a
);
64 Real my_coord
= me
->relative_coordinate (common
, a
);
65 Interval
r (relative_group_extent (a
, common
,elts
));
67 return ly_interval2scm (r
- my_coord
);
71 Axis_group_interface::set_axes (Grob
*me
,Axis a1
, Axis a2
)
73 SCM sa1
= scm_int2num (a1
);
74 SCM sa2
= scm_int2num (a2
);
76 SCM axes
= me
->get_grob_property ("axes");
79 || scm_memq (sa1
, axes
) == SCM_BOOL_F
80 || scm_memq (sa2
, axes
) == SCM_BOOL_F
)
82 SCM ax
= gh_cons (sa1
, SCM_EOL
);
84 ax
= gh_cons (sa2
, ax
);
85 me
->set_grob_property ("axes", ax
);
88 if (a1
!= X_AXIS
&& a2
!= X_AXIS
)
89 me
->set_extent (SCM_EOL
, X_AXIS
);
90 if (a1
!= Y_AXIS
&& a2
!= Y_AXIS
)
91 me
->set_extent (SCM_EOL
, Y_AXIS
);
94 why so convoluted ? (fixme/documentme?)
96 if (me
->has_extent_callback_b (Grob::molecule_extent_proc
, a1
))
97 me
->set_extent (Axis_group_interface::group_extent_callback_proc
,a1
);
98 if (me
->has_extent_callback_b (Grob::molecule_extent_proc
, a2
))
99 me
->set_extent (Axis_group_interface::group_extent_callback_proc
,a2
);
103 Axis_group_interface::get_children (Grob
*me
)
105 Link_array
<Grob
> childs
;
108 if (!has_interface (me
))
111 for (SCM ep
= me
->get_grob_property ("elements"); gh_pair_p (ep
); ep
= ly_cdr (ep
))
113 Grob
* e
= unsmob_grob (ly_car (ep
));
115 childs
.concat (Axis_group_interface::get_children (e
));
123 ADD_INTERFACE (Axis_group_interface
, "axis-group-interface",
124 "a group of coupled grobs",