]> git.donarmstrong.com Git - lilypond.git/blob - lily/line-interface.cc
* lily/line-interface.cc (line): remove thickness from calling interface.
[lilypond.git] / lily / line-interface.cc
1 /*   
2 line-interface.cc --  implement Line_interface
3
4 source file of the GNU LilyPond music typesetter
5
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8  */
9
10 #include "line-interface.hh"
11 #include "molecule.hh"
12 #include "grob.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "lookup.hh"
15 #include "paper-def.hh"
16
17
18 Molecule
19 Line_interface::make_dashed_line (Real thick, Offset from, Offset to,
20                              Real dash_period, Real dash_fraction)
21 {
22   dash_fraction = (dash_fraction >? 0) <? 1.0;
23   Real on = dash_fraction * dash_period + thick; 
24   Real off = dash_period - on;
25   
26   SCM at = scm_list_n (ly_symbol2scm ("dashed-line"),
27                         gh_double2scm (thick), 
28                         gh_double2scm (on),
29                         gh_double2scm (off),
30                         gh_double2scm (to[X_AXIS] - from[X_AXIS]),
31                         gh_double2scm (to[Y_AXIS] - from[Y_AXIS]),
32                         SCM_UNDEFINED);
33   
34   Box box;
35   box.add_point (Offset (0,0));
36   box.add_point (to - from);
37
38   box[X_AXIS].widen (thick/2);
39   box[Y_AXIS].widen (thick/2);  
40
41   Molecule m = Molecule (box, at);
42   m.translate (from);
43   return m;
44 }
45
46 Molecule
47 Line_interface::make_line (Real th, Offset from, Offset to)
48 {
49   SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
50                         gh_double2scm (th), 
51                         gh_double2scm (from[X_AXIS]),
52                         gh_double2scm (from[Y_AXIS]),
53                         gh_double2scm (to[X_AXIS]),
54                         gh_double2scm (to[Y_AXIS]),
55                         SCM_UNDEFINED);
56
57   Box box;
58   box.add_point (from);
59   box.add_point (to);
60
61   box[X_AXIS].widen (th/2);
62   box[Y_AXIS].widen (th/2);  
63
64   return Molecule (box, at);
65 }
66
67
68 /*
69   TODO: read THICK from ME
70  */
71 Molecule
72 Line_interface::line (Grob *me, Offset from, Offset to)
73 {
74   Real thick = me->get_paper()->get_realvar (ly_symbol2scm ("linethickness"));  
75   thick *= robust_scm2double (me->get_grob_property ("thickness"), 1.0); // todo: staff sym referencer? 
76
77   SCM type = me->get_grob_property ("style");
78
79   SCM dash_fraction = me->get_grob_property ("dash-fraction");
80   if (gh_number_p (dash_fraction) || type == ly_symbol2scm ("dotted-line"))
81     {
82       Real fraction =
83         robust_scm2double (dash_fraction, (type == ly_symbol2scm ("dotted-line")) ? 0.0 : 0.4);
84
85       fraction = (fraction >? 0) <? 1.0;
86       Real period = Staff_symbol_referencer::staff_space (me)
87         * robust_scm2double (me->get_grob_property ("dash-period"), 1.0);
88
89       if (period < 0)
90         return Molecule ();
91   
92       return make_dashed_line (thick, from, to, period, fraction);
93     }
94   else
95     {
96       return make_line (thick, from, to);
97     }
98 }
99
100 ADD_INTERFACE(Line_interface, "line-interface",
101               "Generic line objects. Any object using lines supports this. ",
102               "dash-period dash-fraction thickness style")