]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.3.33
[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   Interval i(get_spanned_interval ());
57
58   translate_axis (i.center (), Y_AXIS);
59 }
60
61 void
62 Span_bar::evaluate_empty ()
63
64   if (!gh_pair_p (get_elt_property ("elements"))) 
65     {
66       set_elt_property ("transparent", SCM_BOOL_T);
67       set_empty (X_AXIS);
68       set_empty (Y_AXIS);   
69     }
70
71   SCM gl = get_elt_property ("glyph");
72   if (!gh_string_p (gl))
73     {
74       set_elt_property ("transparent", SCM_BOOL_T);
75       set_empty (X_AXIS);
76       set_empty (Y_AXIS);   
77     }
78   else {
79     String type_str = ly_scm2string (gl);
80     if (type_str == "|:") 
81     {
82       type_str= ".|";
83     }
84   else if (type_str== ":|")
85     {
86       type_str= "|.";
87     }
88   else if (type_str== ":|:")
89     {
90       type_str= ".|.";
91     }
92   }
93
94   /*
95     uhh. should do something with type_str ?!!
96    */
97 }
98
99 Interval
100 Span_bar::get_spanned_interval () const
101 {
102   Interval y_int;
103
104   for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
105     {
106       Score_element *bar = unsmob_element ( gh_car (s));
107
108       if (!bar)
109         continue;
110       
111       Score_element*common = common_refpoint (bar, Y_AXIS);
112
113       Interval iv (bar->extent(Y_AXIS));
114       if (!iv.empty_b ())
115         {
116           Real y = bar->relative_coordinate (common, Y_AXIS)  
117             - relative_coordinate (common, Y_AXIS);
118
119           y_int.unite (y + iv);
120         }
121     }
122   
123   return y_int;
124 }
125
126 Interval
127 Span_bar::height_callback (Dimension_cache const *c) 
128 {
129   Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
130   return s->get_spanned_interval ();
131 }
132
133 Real
134 Span_bar::get_bar_size () const
135 {
136    Interval iv (get_spanned_interval ());
137    if (iv.empty_b ())
138      {
139        programming_error("Huh? My children deflated (FIXME)");
140        iv = Interval (0,0);
141      }
142    return iv.length ();
143 }
144
145 Span_bar::Span_bar ()
146 {
147   group (this).set_interface ();
148   dim_cache_[X_AXIS]->set_callback (width_callback);
149   dim_cache_[Y_AXIS]->set_callback (height_callback);  
150 }
151