]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-element.cc
release: 1.3.11
[lilypond.git] / lily / axis-group-element.cc
1 /*
2   axis-group-element.cc -- implement Axis_group_element
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "axis-group-element.hh"
10 #include "dimension-cache.hh"
11 #include "group-interface.hh"
12
13 Link_array<Score_element>
14 Axis_group_element::get_extra_dependencies() const
15 {
16   Link_array<Score_element> e(elem_l_arr ());
17   return e;
18 }
19
20 Link_array<Score_element>
21 Axis_group_element::elem_l_arr () const
22 {  
23   return
24     Group_interface__extract_elements (this, (Score_element*)0, "elements");
25 }
26
27 Link_array<Score_element> 
28 Axis_group_element::get_children ()
29 {
30   Link_array<Score_element> childs;
31   Link_array<Score_element> elems = elem_l_arr ();
32
33   for (int i=0; i < elems.size (); i++) 
34     {
35       Score_element* e = elems[i];
36       childs.push (e) ;
37       Axis_group_element * axis_group= dynamic_cast <Axis_group_element *> (e);
38       if (axis_group)
39         childs.concat (axis_group->get_children ());      
40     }
41   
42   return childs;
43 }
44
45 Axis_group_element::Axis_group_element()
46 {
47   axes_[0] = (Axis)-1 ; 
48   axes_[1] = (Axis)-1 ;
49
50   set_elt_property ("elements", SCM_EOL);
51   set_elt_property ("transparent", SCM_BOOL_T);
52 }
53
54 void
55 Axis_group_element::set_axes (Axis a1, Axis a2)
56 {
57   axes_[0] = a1 ; 
58   axes_[1] = a2 ;
59   if (a1 != X_AXIS && a2 != X_AXIS)
60     set_empty (X_AXIS);
61   if (a1 != Y_AXIS && a2 != Y_AXIS)
62     set_empty (Y_AXIS);
63   
64   dim_cache_[a1]->set_callback(extent_callback);
65   dim_cache_[a2]->set_callback (extent_callback);
66 }
67
68 Interval
69 Axis_group_element::extent_callback (Dimension_cache const *c) 
70 {
71   Axis a = c->axis ();
72   Axis_group_element * me
73     = dynamic_cast<Axis_group_element*> (c->element_l ()); 
74
75   Interval r;
76   for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
77     {
78       SCM e=gh_car (s); 
79       Score_element * se = SMOB_TO_TYPE (Score_element, e);
80
81       Interval dims = se->extent (a);
82       if (!dims.empty_b ())
83         r.unite (dims + se->relative_coordinate (me, a));
84     }
85
86   return r;
87 }
88
89
90
91 void
92 Axis_group_element::add_element (Score_element *e)
93 {
94   used_b_ =true;
95   e->used_b_ = true;
96   
97   for (int i = 0; i < 2; i++)
98     {
99       if (!e->parent_l (axes_[i]))
100         e->set_parent (this, axes_[i]);
101     }
102   Group_interface gi (this);
103   gi.add_element (e);
104 }
105