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