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