]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-delimiter.cc
release: 1.3.101
[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 "axis-group-interface.hh"
12 #include "system-start-delimiter.hh"
13 #include "paper-def.hh"
14 #include "molecule.hh"
15 #include "font-interface.hh"
16 #include "all-font-metrics.hh"
17 #include "score-element.hh"
18 #include "lookup.hh"
19
20 Molecule
21 System_start_delimiter::staff_bracket (Score_element*me,Real height)  
22 {
23   Paper_def* p= me->paper_l ();
24   Real arc_height = gh_scm2double (me->get_elt_property("arch-height")) ;
25   
26   SCM at = gh_list (ly_symbol2scm ("bracket"),
27                     me->get_elt_property ("arch-angle"), 
28                     me->get_elt_property ("arch-width"), 
29                     gh_double2scm (arc_height),
30                     me->get_elt_property ("bracket-width"),
31                     gh_double2scm (height),
32                     me->get_elt_property ("arch-thick"),
33                     me->get_elt_property ("bracket-thick"),
34                     SCM_UNDEFINED);
35
36   Real h = height + 2 * arc_height;
37   Box b (Interval (0, 1.5), Interval (-h/2, h/2));
38   Molecule mol (b, at);
39   mol.align_to (X_AXIS, CENTER);
40   return mol;
41 }
42
43 void
44 System_start_delimiter::set_interface (Score_element*me)
45 {
46   me->set_interface (ly_symbol2scm ("system-start-delimiter-interface"));
47 }
48
49 bool
50 System_start_delimiter::has_interface (Score_element*me)
51 {
52   return  me->has_interface (ly_symbol2scm ("system-start-delimiter-interface"));
53 }
54
55 Molecule
56 System_start_delimiter::simple_bar (Score_element*me,Real h) 
57 {
58   Real w = me->paper_l ()->get_var ("stafflinethickness") *
59     gh_scm2double (me->get_elt_property ("thickness"));
60   return Lookup::filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
61 }
62
63 MAKE_SCHEME_CALLBACK(System_start_delimiter,after_line_breaking,1);
64
65 SCM
66 System_start_delimiter::after_line_breaking (SCM smob)
67 {
68   try_collapse (unsmob_element (smob));
69   return SCM_UNSPECIFIED;
70 }
71
72 void
73 System_start_delimiter::try_collapse (Score_element*me)
74 {
75   SCM   gl = me->get_elt_property ("glyph");
76   
77   if (scm_ilength (me->get_elt_property ("elements")) <=  1 && gl == ly_symbol2scm ("bar-line"))
78     {
79       me->suicide ();
80     }
81   
82 }
83
84
85 MAKE_SCHEME_CALLBACK(System_start_delimiter,brew_molecule,1);
86
87 SCM
88 System_start_delimiter::brew_molecule (SCM smob)
89 {
90   Score_element * me = unsmob_element (smob);
91   Interval ext = ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm(), gh_int2scm (Y_AXIS)));
92   Real l = ext.length (); 
93   Molecule m;
94
95   SCM s = me->get_elt_property ("collapse-height");
96   if (gh_number_p (s) && l < gh_scm2double (s))
97     {
98       me->suicide();
99       return SCM_EOL;
100     }
101
102   s = me->get_elt_property ("glyph");
103   if (!gh_symbol_p(s))
104     return SCM_EOL;
105   
106   if (s == ly_symbol2scm ("bracket"))
107     m = staff_bracket (me,l);
108   else if (s == ly_symbol2scm ("brace"))
109     m =  staff_brace (me,l);
110   else if (s == ly_symbol2scm ("bar-line"))
111     m = simple_bar (me,l);
112   
113   
114   m.translate_axis (ext.center (), Y_AXIS);
115   return m.create_scheme ();
116 }
117
118 /*
119   Ugh. Suck me plenty.
120  */
121 Molecule
122 System_start_delimiter::staff_brace (Score_element*me,Real y)  
123 {
124   int staff_size  = 20;         // URG.
125
126   // URG
127   Real step  = 1.0;
128   int minht  = 2 * staff_size;
129   int maxht = 7 *  minht;
130   int idx = int (((maxht - step) <? y - minht) / step);
131   idx = idx >? 0;
132
133   Font_metric *fm = Font_interface::get_default_font (me);
134   
135   SCM at =gh_list (ly_symbol2scm ("char"), gh_int2scm (idx), SCM_UNDEFINED);
136   at = fontify_atom (fm, at);
137   
138   Box b (Interval (0,0), Interval (-y/2, y/2));
139
140   return Molecule(b, at);
141 }
142