]> git.donarmstrong.com Git - lilypond.git/blob - lily/elem-group.cc
release: 0.0.68pre
[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 IMPLEMENT_STATIC_NAME(Horizontal_group);
40 IMPLEMENT_IS_TYPE_B1(Horizontal_group, Elbement_group);
41 IMPLEMENT_IS_TYPE_B1(Vertical_group, Elbement_group);
42 IMPLEMENT_STATIC_NAME(Vertical_group);
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 IMPLEMENT_STATIC_NAME(Elbement_group);
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 IMPLEMENT_STATIC_NAME(Horizontal_vertical_group);
152
153 void
154 Horizontal_vertical_group::do_substitute_dependency(Score_elem*o,Score_elem*n)
155 {
156     Vertical_group::do_substitute_dependency(o,n);
157     Horizontal_group::do_substitute_dependency(o,n);
158 }
159
160 void
161 Horizontal_vertical_group::add_element(Score_elem*e)
162 {
163     Vertical_group::add_element(e);
164     Horizontal_group::add_element(e);
165 }
166
167 void
168 Horizontal_vertical_group::do_print()const
169 {
170     Vertical_group::do_print();
171 }
172
173 void
174 Vertical_group::do_print()const
175 {
176     Elbement_group::do_print();
177 }
178
179 void
180 Horizontal_group::do_print() const
181 {
182     Elbement_group::do_print();
183 }