]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-interface.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "axis-group-interface.hh"
11
12 #include "hara-kiri-group-spanner.hh"
13
14 void
15 Axis_group_interface::add_element (Grob*me,Grob *e)
16 {
17   for (SCM ax = me->get_property ("axes"); ax != SCM_EOL ; ax = scm_cdr (ax))
18     {
19       Axis a = (Axis) scm_to_int (scm_car (ax));
20       
21       if (!e->get_parent (a))
22         e->set_parent (me, a);
23     }
24
25   Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
26   me->add_dependency (e);
27 }
28
29 bool
30 Axis_group_interface::has_axis (Grob*me,Axis a)
31 {
32   /*
33     urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
34    */
35   return me->has_extent_callback (group_extent_callback_proc, a) ||
36  (me->has_extent_callback (Hara_kiri_group_spanner::y_extent_proc, a));
37 }
38
39 Interval
40 Axis_group_interface::relative_group_extent (Axis a, Grob *common, SCM elts)
41 {
42   Interval r;
43   for (SCM s = elts; scm_is_pair (s); s = scm_cdr (s))
44     {
45       Grob * se = unsmob_grob (scm_car (s));
46       Interval dims = se->extent (common, a);
47       if (!dims.is_empty ())
48         r.unite (dims);
49     }
50   return r;
51 }
52
53 MAKE_SCHEME_CALLBACK (Axis_group_interface,group_extent_callback,2);
54 SCM
55 Axis_group_interface::group_extent_callback (SCM element_smob, SCM scm_axis)
56 {
57   Grob *me = unsmob_grob (element_smob);
58   Axis a = (Axis) scm_to_int (scm_axis);
59
60   SCM elts = me->get_property ("elements");
61   Grob * common = common_refpoint_of_list (elts, me, a);
62
63   Real my_coord = me->relative_coordinate (common, a);
64   Interval r (relative_group_extent (a, common, elts));
65
66   return ly_interval2scm (r - my_coord);
67 }
68
69 void
70 Axis_group_interface::set_axes (Grob*me,Axis a1, Axis a2)
71 {
72   SCM sa1= scm_int2num (a1);
73   SCM sa2 = scm_int2num (a2);
74
75   SCM axes = me->get_property ("axes");
76   
77   if (!scm_is_pair (axes)
78       || scm_c_memq (sa1, axes) == SCM_BOOL_F
79       || scm_c_memq (sa2, axes) == SCM_BOOL_F)
80     {
81       SCM ax = scm_cons (sa1, SCM_EOL);
82       if (a1 != a2)
83         ax= scm_cons (sa2, ax);
84       me->set_property ("axes", ax);
85     }
86
87   if (a1 != X_AXIS && a2 != X_AXIS)
88     me->set_extent (SCM_EOL, X_AXIS);
89   if (a1 != Y_AXIS && a2 != Y_AXIS)
90     me->set_extent (SCM_EOL, Y_AXIS);
91
92   /*
93     why so convoluted ? (fixme/documentme?) 
94    */
95   if (me->has_extent_callback (Grob::stencil_extent_proc, a1))
96     me->set_extent (Axis_group_interface::group_extent_callback_proc,a1);
97   if (me->has_extent_callback (Grob::stencil_extent_proc, a2))
98     me->set_extent (Axis_group_interface::group_extent_callback_proc,a2);
99 }
100
101 Link_array<Grob> 
102 Axis_group_interface::get_children (Grob*me)
103 {
104   Link_array<Grob> childs;
105   childs.push (me) ;
106
107   if (!has_interface (me))
108     return childs;
109   
110   for (SCM ep = me->get_property ("elements"); scm_is_pair (ep); ep = scm_cdr (ep))
111     {
112       Grob* e = unsmob_grob (scm_car (ep));
113       if (e)
114         childs.concat (Axis_group_interface::get_children (e));
115     }
116   
117   return childs;
118 }
119
120
121
122 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
123   "An object that groups other layout objects.",
124   "axes elements");