]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
''
[lilypond.git] / lily / staff-symbol.cc
1 /*
2   staff-symbol.cc -- implement Staff_symbol
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "lookup.hh"
10 #include "dimensions.hh"
11 #include "paper-def.hh"
12 #include "molecule.hh"
13 #include "debug.hh"
14 #include "item.hh"
15 #include "staff-symbol.hh"
16 #include "spanner.hh"
17
18
19
20 MAKE_SCHEME_CALLBACK (Staff_symbol,brew_molecule,1);
21
22 SCM
23 Staff_symbol::brew_molecule (SCM smob)
24 {
25   Grob *me = unsmob_grob (smob);
26   Spanner* sp = dynamic_cast<Spanner*> (me);
27   Grob * common
28     = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
29   
30   bool ragged = to_boolean (me->paper_l ()->get_scmvar ("raggedright"));
31   Real width;
32   if (ragged)
33     {
34       // *prevent* staff symbol from being ragged right
35       width =
36         me->paper_l ()->get_var ("linewidth")
37         - sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS)
38         ;
39     }
40   else
41     {
42       width =
43         // right_shift     - left_shift
44         + sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS)
45         - sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS)
46         ;
47     }
48
49   Real t = me->paper_l ()->get_var ("stafflinethickness");
50   int l = Staff_symbol::line_count (me);
51   
52   Real height = (l-1) * staff_space (me) /2;
53   Molecule m;
54   for (int i=0; i < l; i++)
55     {
56       Molecule a =
57         Lookup::filledbox (Box (Interval (0,width),
58                                          Interval (-t/2, t/2)));
59
60       a.translate_axis (height - i * staff_space (me), Y_AXIS);
61       m.add_molecule (a);
62     }
63
64   return m.smobbed_copy ();
65 }
66
67 int
68 Staff_symbol::steps_i (Grob*me) 
69 {
70   return line_count (me) * 2;
71 }
72
73 int
74 Staff_symbol::line_count (Grob*me) 
75 {
76   SCM c = me->get_grob_property ("line-count");
77   if (gh_number_p (c))
78     return gh_scm2int (c);
79   else
80     return 0;
81 }
82
83 Real
84 Staff_symbol::staff_space (Grob*me)
85 {
86   Real ss = 1.0;
87   
88   SCM s = me->get_grob_property ("staff-space");
89   if (gh_number_p (s))
90     ss *= gh_scm2double (s);
91   return ss;
92 }
93
94 bool
95 Staff_symbol::has_interface (Grob*m)
96 {
97   return m && m->has_interface (ly_symbol2scm ("staff-symbol-interface"));
98 }
99
100
101
102 ADD_INTERFACE (Staff_symbol,"staff-symbol-interface",
103   "This spanner draws the lines of a staff.  The middle line is
104 position 0.",
105   "staff-space line-count invisible-staff");
106