]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-element.cc
release: 1.3.10
[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 "axis-group-element.hh"
11 #include "dimension-cache.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   /*
24     ugh. I know
25   */
26   Link_array<Score_element> r;
27   for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
28     {
29       SCM e=gh_car (s); 
30       r.push (unsmob_element (e));
31     }
32       
33   return r;
34 }
35
36 Link_array<Score_element> 
37 Axis_group_element::get_children ()
38 {
39   Link_array<Score_element> childs;
40   Link_array<Score_element> elems = elem_l_arr ();
41
42   for (int i=0; i < elems.size (); i++) 
43     {
44       Score_element* e = elems[i];
45       childs.push (e) ;
46       Axis_group_element * axis_group= dynamic_cast <Axis_group_element *> (e);
47       if (axis_group)
48         childs.concat (axis_group->get_children ());      
49     }
50   
51   return childs;
52 }
53
54 Axis_group_element::Axis_group_element()
55 {
56   axes_[0] = (Axis)-1 ; 
57   axes_[1] = (Axis)-1 ;
58
59   set_elt_property ("elements", SCM_EOL);
60   set_elt_property ("transparent", SCM_BOOL_T);
61 }
62
63 void
64 Axis_group_element::set_axes (Axis a1, Axis a2)
65 {
66   axes_[0] = a1 ; 
67   axes_[1] = a2 ;
68   if (a1 != X_AXIS && a2 != X_AXIS)
69     set_empty (X_AXIS);
70   if (a1 != Y_AXIS && a2 != Y_AXIS)
71     set_empty (Y_AXIS);
72   
73   dim_cache_[a1]->set_callback(extent_callback);
74   dim_cache_[a2]->set_callback (extent_callback);
75 }
76
77 Interval
78 Axis_group_element::extent_callback (Dimension_cache const *c) 
79 {
80   Axis a = c->axis ();
81   Axis_group_element * me
82     = dynamic_cast<Axis_group_element*> (c->element_l ()); 
83
84   Interval r;
85   for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
86     {
87       SCM e=gh_car (s); 
88       Score_element * se = SMOB_TO_TYPE (Score_element, e);
89
90       Interval dims = se->extent (a);
91       if (!dims.empty_b ())
92         r.unite (dims + se->relative_coordinate (me, a));
93     }
94
95   return r;
96 }
97
98
99 /*
100   UGH.
101  */
102 void
103 Axis_group_element::add_extra_element (Score_element *e)
104 {
105   add_element (e);
106 }
107
108
109 void
110 Axis_group_element::add_element (Score_element *e)
111 {
112   used_b_ =true;
113   e->used_b_ = true;
114   
115   for (int i = 0; i < 2; i++)
116     {
117       if (!e->parent_l (axes_[i]))
118         e->set_parent (this, axes_[i]);
119     }
120   set_elt_property ("elements",
121                     gh_cons (e->self_scm_,
122                              get_elt_property ("elements")));
123                              
124   assert (e->parent_l(Y_AXIS) == this || e->parent_l (X_AXIS) == this);
125 }
126
127
128
129
130
131
132