]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.3.10
[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 #include "group-interface.hh"
17
18
19 void
20 Span_bar::add_bar (Score_element*b)
21 {
22   Group_interface gi (this);
23   gi.add_element (b);
24
25   add_dependency (b);
26 }
27
28
29 Interval
30 Span_bar::width_callback (Dimension_cache const * c)
31 {
32   Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
33   Molecule m = s->lookup_l ()->bar (s->type_str_, 40 PT, s->paper_l ());
34   
35   return m.extent (X_AXIS);
36 }
37
38 void
39 Span_bar::do_pre_processing ()
40 {
41   Bar::do_pre_processing ();
42   
43   evaluate_empty ();
44   
45   //  set_empty (false, Y_AXIS); // a hack to make mark scripts work.
46 }
47
48 void
49 Span_bar::do_post_processing ()
50 {
51   Bar::do_post_processing ();
52   Interval i(get_spanned_interval ());
53
54   translate_axis (i.center (), Y_AXIS);
55 }
56
57 void
58 Span_bar::evaluate_empty ()
59
60   if (!gh_pair_p (get_elt_property ("elements"))) 
61     {
62       set_elt_property ("transparent", SCM_BOOL_T);
63       set_empty (X_AXIS);
64       set_empty (Y_AXIS);   
65     }
66   if (type_str_.empty_b ()) 
67     {
68       set_elt_property ("transparent", SCM_BOOL_T);
69       set_empty (X_AXIS);
70       set_empty (Y_AXIS);   
71     }
72   else if (type_str_ == "|:") 
73     {
74       type_str_ = ".|";
75     }
76   else if (type_str_ == ":|")
77     {
78       type_str_ = "|.";
79     }
80   else if (type_str_ == ":|:")
81     {
82       type_str_ = ".|.";
83     }
84 }
85
86 Interval
87 Span_bar::get_spanned_interval () const
88 {
89   Interval y_int;
90
91   for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
92     {
93       Score_element *bar = unsmob_element ( gh_car (s));
94
95       if (!bar)
96         continue;
97       
98       Score_element*common = common_refpoint (bar, Y_AXIS);
99
100       Interval iv (bar->extent(Y_AXIS));
101       if (!iv.empty_b ())
102         {
103           Real y = bar->relative_coordinate (common, Y_AXIS)  
104             - relative_coordinate (common, Y_AXIS);
105
106           y_int.unite (y + iv);
107         }
108     }
109   return y_int;
110 }
111
112 Interval
113 Span_bar::height_callback (Dimension_cache const *c) 
114 {
115   Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
116   return s->get_spanned_interval ();
117 }
118
119 Molecule*
120 Span_bar::do_brew_molecule_p () const
121 {
122   Interval iv (get_spanned_interval ());
123   Molecule*output = new Molecule;
124   if (!iv.empty_b())
125     {
126       output->add_molecule (lookup_l ()->bar (type_str_, iv.length (), paper_l ()));
127     }
128   else
129     {
130       programming_error("Huh? My children deflated (FIXME)");
131     }
132   return output;
133 }
134
135
136
137 Span_bar::Span_bar ()
138 {
139   type_str_ = "";
140   dim_cache_[X_AXIS]->set_callback (width_callback);
141   dim_cache_[Y_AXIS]->set_callback (height_callback);  
142 }
143