]> git.donarmstrong.com Git - lilypond.git/blob - lily/vertical-align-engraver.cc
release: 1.3.34
[lilypond.git] / lily / vertical-align-engraver.cc
1 /*
2   vertical-align-grav.cc -- implement Vertical_align_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "translator-group.hh"
9 #include "axis-group-engraver.hh"
10 #include "paper-column.hh"
11 #include "vertical-align-engraver.hh"
12 #include "axis-align-spanner.hh"
13 #include "axis-group-spanner.hh"
14 #include "span-bar.hh"
15
16 Vertical_align_engraver::Vertical_align_engraver()
17 {
18   valign_p_ =0;
19 }
20
21 void
22 Vertical_align_engraver::do_creation_processing()
23 {
24   valign_p_ =new Axis_align_spanner;
25   valign_p_->set_axis (Y_AXIS);
26   valign_p_->set_elt_property ("stacking-dir",  gh_int2scm (DOWN));
27   
28   valign_p_->set_bound(LEFT,get_staff_info().command_pcol_l ());
29   announce_element (Score_element_info (valign_p_ , 0));
30 }
31
32 void
33 Vertical_align_engraver::do_removal_processing()
34 {
35   SCM min = get_property ("maxVerticalAlign");
36   SCM max = get_property ("minVerticalAlign");
37
38   if (gh_number_p (min) || gh_number_p (max))
39   {
40     min = gh_number_p (min) ? min : gh_double2scm (0.0);
41     max = gh_number_p (max) ? max : gh_double2scm (infinity_f);    
42     
43     valign_p_->set_elt_property ("threshold",
44                                  gh_cons (min,max));
45   }
46   valign_p_->set_bound(RIGHT,get_staff_info().command_pcol_l ());
47   typeset_element (valign_p_);
48   valign_p_ =0;
49 }
50
51
52 bool
53 Vertical_align_engraver::qualifies_b (Score_element_info i) const
54 {
55   int sz = i.origin_trans_l_arr ((Translator*)this).size()  ;
56
57   Axis_group_element * elt = dynamic_cast<Axis_group_element *> (i.elem_l_);
58
59   return sz > 1 && elt && !elt->parent_l (Y_AXIS) && elt->axis_b (Y_AXIS);
60 }
61
62 void
63 Vertical_align_engraver::acknowledge_element (Score_element_info i)
64 {
65   if (qualifies_b (i))
66     {
67       valign_p_->add_element (i.elem_l_);
68     }
69   /*
70     ? huh
71    */
72   else if (dynamic_cast<Span_bar*>(i.elem_l_) && i.origin_trans_l_arr (this).size ())
73     {
74       i.elem_l_->add_dependency (valign_p_);
75     }  
76 }
77
78
79
80 ADD_THIS_TRANSLATOR(Vertical_align_engraver);