]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
patch::: 1.3.9.hwn2
[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 #include "dimension-cache.hh"
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
31 Interval
32 Span_bar::width_callback (Dimension_cache const * c)
33 {
34   Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
35   Molecule m = s->lookup_l ()->bar (s->type_str_, 40 PT, s->paper_l ());
36   
37   return m.extent (X_AXIS);
38 }
39
40 void
41 Span_bar::do_pre_processing ()
42 {
43   Bar::do_pre_processing ();
44   
45   evaluate_empty ();
46   
47   //  set_empty (false, Y_AXIS); // a hack to make mark scripts work.
48 }
49
50 void
51 Span_bar::do_post_processing ()
52 {
53   Bar::do_post_processing ();
54   Interval i(get_spanned_interval ());
55
56   translate_axis (i.center (), Y_AXIS);
57 }
58
59 void
60 Span_bar::evaluate_empty ()
61
62   if (spanning_l_arr_.size () < 1) 
63     {
64       set_elt_property ("transparent", SCM_BOOL_T);
65       set_empty (X_AXIS);
66       set_empty (Y_AXIS);   
67     }
68   if (type_str_.empty_b ()) 
69     {
70       set_elt_property ("transparent", SCM_BOOL_T);
71       set_empty (X_AXIS);
72       set_empty (Y_AXIS);   
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
93   for (int i=0; i < spanning_l_arr_.size (); i++) 
94     {
95       Score_element*common = common_refpoint (spanning_l_arr_[i], Y_AXIS);
96       Real y = spanning_l_arr_[i]->relative_coordinate (common, Y_AXIS)  
97         - relative_coordinate (common, Y_AXIS);
98
99       y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
100     }
101   return y_int;
102 }
103
104 Interval
105 Span_bar::height_callback (Dimension_cache const *c) 
106 {
107   Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
108   return s->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 (), paper_l ()));
119     }
120   else
121     {
122       programming_error("Huh? My children deflated (FIXME)");
123     }
124   return output;
125 }
126
127
128
129 Span_bar::Span_bar ()
130 {
131   type_str_ = "";
132   dim_cache_[X_AXIS]->set_callback (width_callback);
133   dim_cache_[Y_AXIS]->set_callback (height_callback);  
134 }
135