]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-delimiter.cc
763b3a57738bee97c75cff3c3d1897b02d6df259
[lilypond.git] / lily / system-start-delimiter.cc
1 /*   
2   system-start-delimiter.cc --  implement System_start_delimiter
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include <math.h>
10
11 #include "system-start-delimiter.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "axis-group-interface.hh"
15 #include "lookup.hh"
16 #include "all-font-metrics.hh"
17
18 Molecule
19 System_start_delimiter::staff_bracket (Real height) const 
20 {
21   Paper_def* p= paper_l ();
22   Real arc_height = p->get_var("bracket_arch_height");
23   SCM at = gh_list (ly_symbol2scm ("bracket"),
24                     gh_double2scm (p->get_var("bracket_arch_angle")),
25                     gh_double2scm (p->get_var("bracket_arch_width")),
26                     gh_double2scm (arc_height),
27                     gh_double2scm (p->get_var("bracket_width")),
28                     gh_double2scm (height),
29                     gh_double2scm (p->get_var("bracket_arch_thick")),
30                     gh_double2scm (p->get_var("bracket_thick")),
31                     SCM_UNDEFINED);
32
33   Real staff_space = p->get_var ("interline");
34   Real h = height + 2 * arc_height;
35   Box b (Interval (0, 1.5 * staff_space), Interval (-h/2, h/2));
36   Molecule mol (b, at);
37   mol.align_to (X_AXIS, CENTER);
38   return mol;
39 }
40
41 System_start_delimiter::System_start_delimiter ()
42 {
43   set_extent_callback (0, Y_AXIS);
44   Pointer_group_interface (this).set_interface();
45 }
46
47 Molecule
48 System_start_delimiter::simple_bar (Real h) const
49 {
50   Real w = paper_l ()->get_var ("barthick_score");
51   return lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
52 }
53
54 void
55 System_start_delimiter::after_line_breaking ()
56 {
57   SCM   gl = get_elt_property ("glyph");
58   
59   if (scm_ilength (get_elt_pointer ("elements")) <=  1 && gl == ly_symbol2scm ("bar-line"))
60     {
61       set_elt_property ("transparent", SCM_BOOL_T);
62       set_extent_callback (0, X_AXIS);
63       set_extent_callback (0, Y_AXIS);
64     }
65 }
66
67 Molecule
68 System_start_delimiter::do_brew_molecule ()const
69 {
70   Interval ext = Axis_group_interface::group_extent_callback (this, Y_AXIS);
71   Real l = ext.length (); 
72   Molecule m;
73
74   SCM s = get_elt_property ("collapse-height");
75   if (gh_number_p (s) && l < gh_scm2double (s))
76     {
77       System_start_delimiter * me = (System_start_delimiter*)this;
78       me->set_elt_property ("transparent", SCM_BOOL_T);
79       me->set_extent_callback (0, X_AXIS);
80       me->set_extent_callback (0, Y_AXIS);
81       return m;
82     }
83
84   
85   s = get_elt_property ("glyph");
86   if (!gh_symbol_p(s))
87     return m;
88   
89   if (s == ly_symbol2scm ("bracket"))
90     m = staff_bracket (l);
91   else if ( s == ly_symbol2scm ("brace"))
92     m =  staff_brace (l);
93   else if (s == ly_symbol2scm ("bar-line"))
94     m = simple_bar (l);
95   
96   
97   m.translate_axis (ext.center (), Y_AXIS);
98   return m;
99 }
100
101 /*
102   ugh. Suck me plenty.
103  */
104 Molecule
105 System_start_delimiter::staff_brace (Real y)  const
106 {
107   Real staffht  = paper_l ()->get_var ("staffheight");
108   int staff_size  = int (rint (staffht ));
109
110   // URG
111   Real step  = 1.0;
112   int minht  = 2 * staff_size;
113   int maxht = 7 *  minht;
114   int idx = int (((maxht - step) <? y - minht) / step);
115   idx = idx >? 0;
116
117   SCM l = scm_eval (gh_list (ly_symbol2scm ("style-to-cmr"),
118                             ly_str02scm ("brace"),
119                             SCM_UNDEFINED));
120   
121   String nm = "feta-braces";
122   if (l != SCM_BOOL_F)
123     nm = ly_scm2string (gh_cdr (l));
124   nm += to_str (staff_size);
125   SCM e =gh_list (ly_symbol2scm ("char"), gh_int2scm (idx), SCM_UNDEFINED);
126   SCM at = (e);
127
128   at = fontify_atom (find_font (nm), at);
129   
130   Box b (Interval (0,0), Interval (-y/2, y/2));
131
132   return Molecule(b, at);
133 }
134