]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.1.34
[lilypond.git] / lily / span-bar.cc
1 /*
2   span-bar.cc -- implement Span_bar
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 "span-bar.hh"
10 #include "lookup.hh"
11 #include "dimensions.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "align-element.hh"
15 #include "warn.hh"
16
17 void
18 Span_bar::add_bar (Score_element*b)
19 {
20   spanning_l_arr_.push (b);
21   add_dependency (b);
22 }
23
24 void
25 Span_bar::do_substitute_element_pointer (Score_element*o, Score_element*n)
26 {
27   spanning_l_arr_.unordered_substitute (o, n);
28 }
29
30 void
31 Span_bar::set_align (Align_element *a)
32 {
33   add_dependency (a);
34 }
35
36 Interval
37 Span_bar::do_width () const
38 {
39   Molecule m = lookup_l ()->bar (type_str_, 40 PT);
40   
41   return m.extent (X_AXIS);
42 }
43
44 void
45 Span_bar::do_pre_processing ()
46 {
47   Bar::do_pre_processing ();
48   
49   evaluate_empty ();
50   translate_axis (extra_x_off_, X_AXIS);
51   
52   dim_cache_[Y_AXIS].set_empty (false); // a hack to make mark scripts work.
53 }
54
55 void
56 Span_bar::do_post_processing ()
57 {
58   Bar::do_post_processing ();
59 }
60
61 void
62 Span_bar::evaluate_empty ()
63
64   if (spanning_l_arr_.size () < 1) 
65     {
66       transparent_b_ = true;
67       set_empty (true);   
68     }
69   if (type_str_.empty_b ()) 
70     {
71       transparent_b_=true;
72       set_empty (true);
73     }
74   else if (type_str_ == "|:") 
75     {
76       type_str_ = ".|";
77     }
78   else if (type_str_ == ":|")
79     {
80       type_str_ = "|.";
81     }
82   else if (type_str_ == ":|:")
83     {
84       type_str_ = ".|.";
85     }
86 }
87
88 Interval
89 Span_bar::get_spanned_interval () const
90 {
91   Interval y_int;
92   for (int i=0; i < spanning_l_arr_.size (); i++) 
93     {
94       Dimension_cache*common = 
95         common_group (spanning_l_arr_[i], Y_AXIS);
96         
97       Real y = spanning_l_arr_[i]->dim_cache_[Y_AXIS].relative_coordinate (common)  
98         -dim_cache_[Y_AXIS].relative_coordinate (common);
99
100       y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
101     }
102   return y_int;
103 }
104
105 Interval
106 Span_bar::do_height () const
107 {
108   return get_spanned_interval ();
109 }
110
111 Molecule*
112 Span_bar::do_brew_molecule_p () const
113 {
114   Interval iv (get_spanned_interval ());
115   Molecule*output = new Molecule;
116   if (!iv.empty_b())
117     {
118       output->add_molecule (lookup_l ()->bar (type_str_, iv.length ()));
119       output->translate_axis (iv.center (), Y_AXIS);
120     }
121   else
122     {
123       warning("Huh? My children deflated (FIXME)");
124     }
125   return output;
126 }
127
128
129
130 Span_bar::Span_bar ()
131 {
132   type_str_ = "";
133   extra_x_off_ = 0.0;
134 }