]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-interface.cc
bc386b628e862ff7b42174c106a35b4f8115724c
[lilypond.git] / lily / axis-group-interface.cc
1 /*
2   axis-group-interface.cc -- implement Axis_group_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "axis-group-interface.hh"
10
11 #include "pointer-group-interface.hh"
12 #include "grob.hh"
13 #include "hara-kiri-group-spanner.hh"
14 #include "warn.hh"
15
16 void
17 Axis_group_interface::add_element (Grob *me, Grob *e)
18 {
19   SCM axes = me->get_property ("axes");
20   if (!scm_is_pair (axes))
21     programming_error ("axes should be nonempty");
22
23   for (SCM ax = axes; ax != SCM_EOL; ax = scm_cdr (ax))
24     {
25       Axis a = (Axis) scm_to_int (scm_car (ax));
26
27       if (!e->get_parent (a))
28         e->set_parent (me, a);
29
30       e->internal_set_object ((a == X_AXIS)
31                               ? ly_symbol2scm ("axis-group-parent-X")
32                               : ly_symbol2scm ("axis-group-parent-Y"),
33                               me->self_scm ());
34     }
35
36   Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
37 }
38
39 bool
40 Axis_group_interface::has_axis (Grob *me, Axis a)
41 {
42   SCM axes = me->get_property ("axes");
43
44   return (SCM_BOOL_F != scm_memq (scm_from_int (a), axes));
45 }
46
47 Interval
48 Axis_group_interface::relative_group_extent (Link_array<Grob> const &elts,
49                                              Grob *common, Axis a)
50 {
51   Interval r;
52   for (int i = 0; i < elts.size (); i++)
53     {
54       Grob *se = elts[i];
55       Interval dims = se->extent (common, a);
56       if (!dims.is_empty ())
57         r.unite (dims);
58     }
59   return r;
60 }
61
62 MAKE_SCHEME_CALLBACK (Axis_group_interface, width, 1);
63 SCM
64 Axis_group_interface::width (SCM smob)
65 {
66   Grob *me = unsmob_grob (smob);
67   return generic_group_extent (me, X_AXIS);
68 }
69
70 MAKE_SCHEME_CALLBACK (Axis_group_interface, height, 1);
71 SCM
72 Axis_group_interface::height (SCM smob)
73 {
74   Grob *me = unsmob_grob (smob);
75   return generic_group_extent (me, Y_AXIS);
76 }
77   
78 SCM
79 Axis_group_interface::generic_group_extent (Grob *me, Axis a)
80 {
81   extract_grob_set (me, "elements", elts);
82   Grob *common = common_refpoint_of_array (elts, me, a);
83
84   Real my_coord = me->relative_coordinate (common, a);
85   Interval r (relative_group_extent (elts, common, a));
86
87   return ly_interval2scm (r - my_coord);
88 }
89
90 void
91 Axis_group_interface::get_children (Grob *me, Link_array<Grob> *found)
92 {
93   found->push (me);
94
95   if (!has_interface (me))
96     return;
97
98   extract_grob_set (me, "elements", elements);
99   for (int i = 0; i < elements.size (); i++)
100     {
101       Grob *e = elements[i];
102       Axis_group_interface::get_children (e, found);
103     }
104 }
105
106 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
107
108                "An object that groups other layout objects.",
109
110                /* properties */
111                "axes "
112                "elements ");