]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon.cc
Run `make grand-replace'.
[lilypond.git] / lily / balloon.cc
1 /*
2   balloon.cc -- implement Balloon
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "text-interface.hh"
10 #include "grob.hh"
11 #include "line-interface.hh"
12 #include "lookup.hh"
13 #include "font-interface.hh"
14 #include "lily-guile.hh"
15 #include "output-def.hh"
16 #include "misc.hh"
17
18 class Balloon_interface
19 {
20 public:
21   DECLARE_SCHEME_CALLBACK (print, (SCM));
22   DECLARE_GROB_INTERFACE ();
23 };
24
25 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
26 SCM
27 Balloon_interface::print (SCM smob)
28 {
29   Grob *me = unsmob_grob (smob);
30
31   Grob *p = me->get_parent (X_AXIS);
32   
33   Offset off (me->relative_coordinate (p, X_AXIS),
34               me->relative_coordinate (p, Y_AXIS));
35
36   Box b (p->extent (p, X_AXIS),
37          p->extent (p, Y_AXIS));
38
39   Real padding = robust_scm2double (me->get_property ("padding"), .1);
40   b.widen (padding, padding);
41
42   // FIXME
43   Stencil fr = Lookup::frame (b, 0.1, 0.05);
44
45   SCM bt = me->get_property ("text");
46   SCM chain = Font_interface::text_font_alist_chain (me);
47
48   SCM stencil = Text_interface::interpret_markup (me->layout ()->self_scm (),
49                                                   chain, bt);
50
51   Stencil *text_stil = unsmob_stencil (stencil);
52
53   Offset z1;
54   for (int i = X_AXIS; i < NO_AXES; i++)
55     {
56       Axis a ((Axis)i);
57       z1[a] = b[a].linear_combination (sign (off[a]));
58       text_stil->align_to (a, -sign (off[a]));
59     }
60
61   Offset z2 = z1 + off;
62
63   fr.add_stencil (Line_interface::line (me, z1, z2));
64
65   text_stil->translate (z2);
66   fr.add_stencil (*text_stil);
67
68   fr.translate (-off);
69   return fr.smobbed_copy ();
70 }
71
72 ADD_INTERFACE (Balloon_interface,
73                "A collection of routines to put text balloons around an"
74                " object.",
75
76                /* properties */
77                "padding "
78                "text "
79                );
80