]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
``slikken kreng''
[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 "warn.hh"
14 #include "item.hh"
15 #include "staff-symbol.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "spanner.hh"
18
19
20
21 MAKE_SCHEME_CALLBACK (Staff_symbol,brew_molecule,1);
22
23 SCM
24 Staff_symbol::brew_molecule (SCM smob)
25 {
26   Grob *me = unsmob_grob (smob);
27   Spanner* sp = dynamic_cast<Spanner*> (me);
28   Grob * common
29     = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
30   
31   Real width  = 0.0;
32
33   /*
34     For raggedright without ragged staffs, simply set width to the linewidth.
35
36     (ok -- lousy UI, since width is in staff spaces)
37
38     --hwn.
39    */
40   
41   SCM width_scm = me->get_grob_property ("width");
42   if (gh_number_p (width_scm))
43     {
44
45       /*
46         don't multiply by Staff_symbol_referencer::staff_space (me),
47         since that would make aligning staff symbols of different sizes to
48         one right margin hell.
49       */      
50       width = gh_scm2double (width_scm);
51     }
52   else
53     {
54       width = sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS);
55     }
56
57   // respect indentation, if any
58   width -= sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS);
59
60   if (width < 0)
61     {
62       warning (_f ("staff symbol: indentation yields beyond end of line"));
63       width = 0;
64     }
65
66   Real t = me->get_paper ()->get_var ("linethickness");
67   SCM my_thick = me->get_grob_property("thickness");
68   if (gh_number_p (my_thick))
69     t *= gh_scm2double (my_thick);
70   
71   int l = Staff_symbol::line_count (me);
72   
73   Real height = (l-1) * staff_space (me) /2;
74   Molecule m;
75   for (int i=0; i < l; i++)
76     {
77       Molecule a =
78         Lookup::filledbox (Box (Interval (0,width),
79                                          Interval (-t/2, t/2)));
80
81       a.translate_axis (height - i * staff_space (me), Y_AXIS);
82       m.add_molecule (a);
83     }
84
85   return m.smobbed_copy ();
86 }
87
88 int
89 Staff_symbol::get_steps (Grob*me) 
90 {
91   return line_count (me) * 2;
92 }
93
94 int
95 Staff_symbol::line_count (Grob*me) 
96 {
97   SCM c = me->get_grob_property ("line-count");
98   if (gh_number_p (c))
99     return gh_scm2int (c);
100   else
101     return 0;
102 }
103
104 Real
105 Staff_symbol::staff_space (Grob*me)
106 {
107   Real ss = 1.0;
108   
109   SCM s = me->get_grob_property ("staff-space");
110   if (gh_number_p (s))
111     ss *= gh_scm2double (s);
112   return ss;
113 }
114
115
116
117
118 ADD_INTERFACE (Staff_symbol,"staff-symbol-interface",
119   "This spanner draws the lines of a staff.  The center (i.e. middle line
120 or space) is position 0. The length of the symbol may be set by hand
121 through the @code{width} property.
122 ",
123                
124   "width staff-space thickness line-count");
125