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