]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
* lily/include/debug.hh: deprecate.
[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   bool paper_raggedright = to_boolean (me->paper_l ()->get_scmvar ("raggedright"));
32   bool grob_raggedright = to_boolean (me->get_grob_property ("ragged-right"));
33   Real width;
34
35   SCM width_scm = me->get_grob_property ("width");
36   if (gh_number_p (width_scm)) // user-defined width
37     {
38       width = gh_scm2double (width_scm) *
39         Staff_symbol_referencer::staff_space (me);
40     }
41   else // determine width automatically
42     {
43       if (paper_raggedright && !grob_raggedright)
44         {
45           // *prevent* staff symbol from being ragged right; instead, use
46           // paper variable "linewidth"
47           width = me->paper_l ()->get_var ("linewidth");
48         }
49       else // determine width from my own bounds
50         {
51           width = sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS);
52         }
53     }
54
55   // respect indentation, if any
56   width -= sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS);
57
58   if (width < 0)
59     {
60       warning (_f ("staff symbol: indentation yields beyond end of line"));
61       width = 0;
62     }
63
64   Real t = me->paper_l ()->get_var ("linethickness");
65   SCM my_thick = me->get_grob_property("thickness");
66   if (gh_number_p(my_thick))
67     t *= gh_scm2double (my_thick);
68   
69   int l = Staff_symbol::line_count (me);
70   
71   Real height = (l-1) * staff_space (me) /2;
72   Molecule m;
73   for (int i=0; i < l; i++)
74     {
75       Molecule a =
76         Lookup::filledbox (Box (Interval (0,width),
77                                          Interval (-t/2, t/2)));
78
79       a.translate_axis (height - i * staff_space (me), Y_AXIS);
80       m.add_molecule (a);
81     }
82
83   return m.smobbed_copy ();
84 }
85
86 int
87 Staff_symbol::steps_i (Grob*me) 
88 {
89   return line_count (me) * 2;
90 }
91
92 int
93 Staff_symbol::line_count (Grob*me) 
94 {
95   SCM c = me->get_grob_property ("line-count");
96   if (gh_number_p (c))
97     return gh_scm2int (c);
98   else
99     return 0;
100 }
101
102 Real
103 Staff_symbol::staff_space (Grob*me)
104 {
105   Real ss = 1.0;
106   
107   SCM s = me->get_grob_property ("staff-space");
108   if (gh_number_p (s))
109     ss *= gh_scm2double (s);
110   return ss;
111 }
112
113
114
115
116 ADD_INTERFACE (Staff_symbol,"staff-symbol-interface",
117   "This spanner draws the lines of a staff.  The center (i.e. middle line
118 or space) is position 0.",
119                
120   "ragged-right staff-space thickness line-count");
121