]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-interface.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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--2006 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   /* must be ordered, because Align_interface also uses
37      Axis_group_interface  */
38   Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
39 }
40
41 bool
42 Axis_group_interface::has_axis (Grob *me, Axis a)
43 {
44   SCM axes = me->get_property ("axes");
45
46   return (SCM_BOOL_F != scm_memq (scm_from_int (a), axes));
47 }
48
49 Interval
50 Axis_group_interface::relative_group_extent (vector<Grob*> const &elts,
51                                              Grob *common, Axis a)
52 {
53   Interval r;
54   for (vsize i = 0; i < elts.size (); i++)
55     {
56       Grob *se = elts[i];
57       Interval dims = se->extent (common, a);
58       if (!dims.is_empty ())
59         r.unite (dims);
60     }
61   return r;
62 }
63
64 MAKE_SCHEME_CALLBACK (Axis_group_interface, width, 1);
65 SCM
66 Axis_group_interface::width (SCM smob)
67 {
68   Grob *me = unsmob_grob (smob);
69   return generic_group_extent (me, X_AXIS);
70 }
71
72 MAKE_SCHEME_CALLBACK (Axis_group_interface, height, 1);
73 SCM
74 Axis_group_interface::height (SCM smob)
75 {
76   Grob *me = unsmob_grob (smob);
77   return generic_group_extent (me, Y_AXIS);
78 }
79   
80 SCM
81 Axis_group_interface::generic_group_extent (Grob *me, Axis a)
82 {
83   extract_grob_set (me, "elements", elts);
84   Grob *common = common_refpoint_of_array (elts, me, a);
85
86   Real my_coord = me->relative_coordinate (common, a);
87   Interval r (relative_group_extent (elts, common, a));
88
89   return ly_interval2scm (r - my_coord);
90 }
91
92 void
93 Axis_group_interface::get_children (Grob *me, vector<Grob*> *found)
94 {
95   found->push_back (me);
96
97   if (!has_interface (me))
98     return;
99
100   extract_grob_set (me, "elements", elements);
101   for (vsize i = 0; i < elements.size (); i++)
102     {
103       Grob *e = elements[i];
104       Axis_group_interface::get_children (e, found);
105     }
106 }
107
108 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
109
110                "An object that groups other layout objects.",
111
112                /* properties */
113                "axes "
114                "elements ");