]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.1.33
[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   if (no_width_b_)
40     {
41       return Interval (0,0);
42     }
43   
44   Molecule m = lookup_l ()->bar (type_str_, 40 PT);
45   
46   return m.extent (X_AXIS);
47 }
48
49 void
50 Span_bar::do_pre_processing ()
51 {
52   Bar::do_pre_processing ();
53   
54   evaluate_empty ();
55   translate_axis (extra_x_off_, X_AXIS);
56   
57   dim_cache_[Y_AXIS].set_empty (false); // a hack to make mark scripts work.
58 }
59
60 void
61 Span_bar::do_post_processing ()
62 {
63   Bar::do_post_processing ();
64 }
65
66 void
67 Span_bar::evaluate_empty ()
68
69   if (spanning_l_arr_.size () < 1) 
70     {
71       transparent_b_ = true;
72       set_empty (true);   
73     }
74   if (type_str_.empty_b ()) 
75     {
76       transparent_b_=true;
77       set_empty (true);
78     }
79   else if (type_str_ == "|:") 
80     {
81       type_str_ = ".|";
82     }
83   else if (type_str_ == ":|")
84     {
85       type_str_ = "|.";
86     }
87   else if (type_str_ == ":|:")
88     {
89       type_str_ = ".|.";
90     }
91 }
92
93 Interval
94 Span_bar::get_spanned_interval () const
95 {
96   Interval y_int;
97   for (int i=0; i < spanning_l_arr_.size (); i++) 
98     {
99       Dimension_cache*common = 
100         common_group (spanning_l_arr_[i], Y_AXIS);
101         
102       Real y = spanning_l_arr_[i]->dim_cache_[Y_AXIS].relative_coordinate (common)  
103         -dim_cache_[Y_AXIS].relative_coordinate (common);
104
105       y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
106     }
107   return y_int;
108 }
109
110 Interval
111 Span_bar::do_height () const
112 {
113   return get_spanned_interval ();
114 }
115
116 Molecule*
117 Span_bar::do_brew_molecule_p () const
118 {
119   Interval iv (get_spanned_interval ());
120   Molecule*output = new Molecule;
121   if (!iv.empty_b())
122     {
123       output->add_molecule (lookup_l ()->bar (type_str_, iv.length ()));
124       output->translate_axis (iv.center (), Y_AXIS);
125     }
126   else
127     {
128       warning("Huh? My children deflated (FIXME)");
129     }
130   return output;
131 }
132
133
134
135 Span_bar::Span_bar ()
136 {
137   type_str_ = "";
138   extra_x_off_ = 0.0;
139   no_width_b_ = false;
140 }