]> git.donarmstrong.com Git - lilypond.git/blob - lily/dots.cc
* lily/include/directional-element-interface.hh:
[lilypond.git] / lily / dots.cc
1 /*
2   dots.cc -- implement Dots
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "dots.hh"
10 #include "item.hh"
11 #include "molecule.hh"
12 #include "paper-def.hh"
13 #include "font-interface.hh"
14 #include "lookup.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "directional-element-interface.hh"
17
18
19 MAKE_SCHEME_CALLBACK (Dots,quantised_position_callback,2);
20 SCM
21 Dots::quantised_position_callback (SCM element_smob, SCM axis)
22 {
23   Grob *me = unsmob_grob (element_smob);
24   Axis a = (Axis) gh_scm2int (axis);
25   assert (a == Y_AXIS);
26     
27   SCM d= me->get_grob_property ("dot-count");
28   if (gh_number_p (d) && gh_scm2int (d))
29     {
30       if (!get_grob_direction (me))
31         set_grob_direction (me, UP);
32
33       if (Staff_symbol_referencer::on_staffline (me))
34         return gh_double2scm (Staff_symbol_referencer::staff_space (me) / 2.0 * get_grob_direction (me));
35     }
36
37   return gh_double2scm (0.0);
38 }
39
40
41 MAKE_SCHEME_CALLBACK (Dots,brew_molecule,1);
42 SCM  
43 Dots::brew_molecule (SCM d)
44 {
45   Grob *sc = unsmob_grob (d);
46   Molecule mol;
47   
48   SCM c = sc->get_grob_property ("dot-count");
49
50   if (gh_number_p (c))
51     {
52       Molecule d = Font_interface::get_default_font (sc)->find_by_name (String ("dots-dot"));
53       Real dw = d.extent (X_AXIS).length ();
54       
55
56       /*
57         we need to add a real blank box, to assure that
58         side-positioning doth not cancel the left-most padding.  */
59
60       /*
61         TODO: this should  be handled by side-position padding.
62        */
63       mol = Lookup::blank (Box (Interval (0,0),
64                                 Interval (0,0)));
65   
66       for (int i = gh_scm2int (c); i--;)
67         {
68           d.translate_axis (2*dw,X_AXIS);
69           mol.add_at_edge (X_AXIS, RIGHT, d, dw, 0);
70         }
71     }
72   return mol.smobbed_copy ();
73 }
74
75
76
77
78 ADD_INTERFACE (Dots, "dots-interface",
79   "The dots to go with a notehead/rest.  A separate interface, since they "
80 " are a party in collision resolution. "
81 " #'direction is the Direction to handle staff-line collisions in.",
82   "direction dot-count");
83
84