]> git.donarmstrong.com Git - lilypond.git/blob - lily/vertical-align-elem.cc
release: 0.1.7
[lilypond.git] / lily / vertical-align-elem.cc
1 /*
2   vertical-align-item.cc -- implement Vertical_align_elem
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "vertical-align-elem.hh"
10 #include "interval.hh"
11
12 void
13 Vertical_align_element::add(Score_elem*el_l)
14 {
15     assert( ! contains_b(el_l));
16     elem_l_arr_.push(el_l);
17     add_dependency(el_l);
18 }
19
20 void
21 Vertical_align_element::do_substitute_dependency(Score_elem*o,Score_elem*n)
22 {
23     int i;
24     while((i = elem_l_arr_.find_i(o))>=0) 
25         if (n) 
26             elem_l_arr_[i] = n;
27         else
28             elem_l_arr_.del(i);
29 }
30
31 /**
32   Align elements top to bottom. 
33   The first element has its top at y =0.0 afterwards
34
35   TODO configurable, like Horizontal_align_item
36  */
37 void
38 Vertical_align_element::do_post_processing()
39 {
40     Array<Interval> dims;
41     for (int i=0; i < elem_l_arr_.size(); i++ ) {
42         Interval y = elem_l_arr_[i]->height() ;
43         if (y.empty_b())
44             y = Interval(0,0);
45         
46         dims.push(y);
47     }
48
49     Real where_f=0;
50     for ( int i=0 ;  i < elem_l_arr_.size(); i++) {
51         elem_l_arr_[i]->translate( - dims[i][1] - where_f, Y_AXIS);
52         where_f += dims[i].length();
53     }
54 }
55
56 bool
57 Vertical_align_element::contains_b(Score_elem const *e)const
58 {
59     return elem_l_arr_.find_l(e);
60 }
61
62 Vertical_align_element::Vertical_align_element()
63 {
64     transparent_b_ = true;
65     empty_b_ =true;
66 }
67
68
69 IMPLEMENT_IS_TYPE_B1(Vertical_align_element, Score_elem);
70