]> git.donarmstrong.com Git - lilypond.git/blob - lily/elem-group.cc
release: 0.0.77.jcn1
[lilypond.git] / lily / elem-group.cc
1 /*
2  elem-group.cc -- implement Horizontal_vertical_group
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "elem-group.hh"
10 #include "interval.hh"
11 #include "item.hh"
12 #include "debug.hh"
13
14 bool
15 Elbement_group::contains_b(Score_elem const*e)const
16 {
17     return elem_l_arr_.find_l(e);
18 }
19
20 Interval
21 Vertical_group::do_height()const 
22 {
23     Interval r;
24     for (int i=0; i < elem_l_arr_.size(); i++) 
25         r.unite(elem_l_arr_[i]->height());
26     return r;
27 }
28
29 Interval
30 Horizontal_group::do_width()const 
31 {
32     Interval r;
33     for (int i=0; i < elem_l_arr_.size(); i++) 
34         if (elem_l_arr_[i]->item()) // makes no at preprocessing for spanners. 
35             r.unite(elem_l_arr_[i]->width());
36     return r;
37 }
38
39
40 IMPLEMENT_IS_TYPE_B1(Horizontal_group, Elbement_group);
41 IMPLEMENT_IS_TYPE_B1(Vertical_group, Elbement_group);
42
43
44 void
45 Elbement_group::add_element(Score_elem*i_l)
46 {
47     assert(i_l!= this);
48     assert(! contains_b(i_l));
49
50     elem_l_arr_.push(i_l);
51     add_dependency(i_l);
52 }
53
54 void
55 Horizontal_group::add_element(Score_elem*elt)
56 {
57     elt->x_group_element_i_ ++;
58     Elbement_group::add_element(elt);
59 }
60
61 void
62 Vertical_group::add_element(Score_elem*e)
63 {
64     e->y_group_element_i_++;
65     Elbement_group::add_element(e);
66 }
67
68
69 void
70 Horizontal_group::translate_x(Real x)
71 {
72     for (int i=0; i < elem_l_arr_.size(); i++) 
73         elem_l_arr_[i]->translate_x(x);
74 }
75
76 void
77 Vertical_group::translate_y(Real y)
78 {
79     for (int i=0; i < elem_l_arr_.size(); i++) 
80         elem_l_arr_[i]->translate_y(y);
81 }
82
83
84 IMPLEMENT_IS_TYPE_B1(Elbement_group, Score_elem);
85
86 void
87 Elbement_group::do_print() const
88 {
89 #ifndef NPRINT
90     for (int i=0; i < elem_l_arr_.size(); i++) 
91         mtor << elem_l_arr_[i]->name() << ' ';
92 #endif
93 }
94
95 void
96 Horizontal_group::do_substitute_dependency(Score_elem* old, Score_elem *new_l)
97 {
98     int i;
99
100     while ((i=elem_l_arr_.find_i(old))>=0) {
101         old->x_group_element_i_--;
102         
103         if (new_l){ 
104             new_l->x_group_element_i_ ++;
105             elem_l_arr_[i] = new_l;
106         }else {     
107             elem_l_arr_.del(i);
108         }
109     }
110 }
111
112 void
113 Vertical_group::do_substitute_dependency(Score_elem* old, Score_elem *new_l)
114 {
115     int i;
116
117     while ((i=elem_l_arr_.find_i(old))>=0) {
118         old->y_group_element_i_--;
119         
120         if (new_l){ 
121             new_l->y_group_element_i_ ++;
122             elem_l_arr_[i] = new_l;
123         }else {     
124             elem_l_arr_.del(i);
125         }
126     }
127 }
128
129 Vertical_group::Vertical_group(Vertical_group 
130                                const &s)
131     : Elbement_group(s)
132 {
133    for (int i=0; i < elem_l_arr_.size(); i++) 
134         elem_l_arr_[i]->y_group_element_i_ ++;   
135 }
136
137 Horizontal_group::Horizontal_group(Horizontal_group 
138                                    const &s)
139     : Elbement_group(s)
140 {
141    for (int i=0; i < elem_l_arr_.size(); i++) 
142         elem_l_arr_[i]->x_group_element_i_ ++;   
143 }
144
145 Elbement_group::Elbement_group()
146 {
147     transparent_b_ = true;
148 }
149
150 IMPLEMENT_IS_TYPE_B2(Horizontal_vertical_group, Horizontal_group, Vertical_group);
151
152
153 Horizontal_vertical_group::Horizontal_vertical_group()
154 {
155 }
156
157 void
158 Horizontal_vertical_group::do_substitute_dependency(Score_elem*o,Score_elem*n)
159 {
160     Vertical_group::do_substitute_dependency(o,n);
161     Horizontal_group::do_substitute_dependency(o,n);
162 }
163
164 void
165 Horizontal_vertical_group::add_element(Score_elem*e)
166 {
167     Vertical_group::add_element(e);
168     Horizontal_group::add_element(e);
169 }
170
171 void
172 Horizontal_vertical_group::do_print()const
173 {
174     Vertical_group::do_print();
175 }
176
177 void
178 Vertical_group::do_print()const
179 {
180     Elbement_group::do_print();
181 }
182
183 void
184 Horizontal_group::do_print() const
185 {
186     Elbement_group::do_print();
187 }