]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-element.cc
patch::: 1.3.35.jcn1
[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--2000 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::elem_l_arr () const
15 {  
16   return
17     Group_interface__extract_elements (this, (Score_element*)0, "elements");
18 }
19
20 Link_array<Score_element> 
21 Axis_group_element::get_children ()
22 {
23   Link_array<Score_element> childs;
24   Link_array<Score_element> elems = elem_l_arr ();
25
26   for (int i=0; i < elems.size (); i++) 
27     {
28       Score_element* e = elems[i];
29       childs.push (e) ;
30       Axis_group_element * axis_group= dynamic_cast <Axis_group_element *> (e);
31       if (axis_group)
32         childs.concat (axis_group->get_children ());      
33     }
34   
35   return childs;
36 }
37
38 Axis_group_element::Axis_group_element()
39 {
40   set_elt_property ("elements", SCM_EOL);
41   set_elt_property ("transparent", SCM_BOOL_T);
42 }
43
44 void
45 Axis_group_element::set_axes (Axis a1, Axis a2)
46 {
47   SCM ax = gh_cons (gh_int2scm (a1), SCM_EOL);
48   if (a1 != a2)
49     ax= gh_cons (gh_int2scm (a2), ax);
50
51   
52   set_elt_property ("axes", ax);
53
54   if (a1 != X_AXIS && a2 != X_AXIS)
55     set_empty (X_AXIS);
56   if (a1 != Y_AXIS && a2 != Y_AXIS)
57     set_empty (Y_AXIS);
58   
59   dim_cache_[a1]->set_callback(extent_callback);
60   dim_cache_[a2]->set_callback (extent_callback);
61 }
62
63 Interval
64 Axis_group_element::extent_callback (Dimension_cache const *c) 
65 {
66   Axis a = c->axis ();
67   Axis_group_element * me
68     = dynamic_cast<Axis_group_element*> (c->element_l ()); 
69
70   Interval r;
71   for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
72     {
73       SCM e=gh_car (s); 
74       Score_element * se = SMOB_TO_TYPE (Score_element, e);
75
76       Interval dims = se->extent (a);
77       if (!dims.empty_b ())
78         r.unite (dims + se->relative_coordinate (me, a));
79     }
80
81   return r;
82 }
83
84
85 bool
86 Axis_group_element::axis_b (Axis a )const
87 {
88   return dim_cache_[a]->extent_callback_l_ == extent_callback;
89 }
90
91
92 void
93 Axis_group_element::add_element (Score_element *e)
94 {
95   used_b_ =true;
96   e->used_b_ = true;
97
98   for (SCM ax = get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
99     {
100       Axis a = (Axis) gh_scm2int (gh_car (ax));
101       
102       if (!e->parent_l (a))
103         e->set_parent (this, a);
104     }
105   Group_interface gi (this);
106   gi.add_element (e);
107
108   add_dependency (e);
109 }
110