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