]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon.cc
1921bcb9ef1435fb08128eed6e72ce81fa86f921
[lilypond.git] / lily / balloon.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "text-interface.hh"
21 #include "grob.hh"
22 #include "line-interface.hh"
23 #include "lookup.hh"
24 #include "font-interface.hh"
25 #include "lily-guile.hh"
26 #include "output-def.hh"
27 #include "misc.hh"
28
29 class Balloon_interface
30 {
31 public:
32   DECLARE_SCHEME_CALLBACK (print, (SCM));
33   DECLARE_GROB_INTERFACE ();
34 };
35
36 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
37 SCM
38 Balloon_interface::print (SCM smob)
39 {
40   Grob *me = unsmob_grob (smob);
41
42   Grob *p = me->get_parent (X_AXIS);
43   
44   Offset off (me->relative_coordinate (p, X_AXIS),
45               me->relative_coordinate (p, Y_AXIS));
46
47   Box b (p->extent (p, X_AXIS),
48          p->extent (p, Y_AXIS));
49
50   Real padding = robust_scm2double (me->get_property ("padding"), .1);
51   b.widen (padding, padding);
52
53   // FIXME
54   Stencil fr = Lookup::frame (b, 0.1, 0.05);
55
56   SCM bt = me->get_property ("text");
57   SCM chain = Font_interface::text_font_alist_chain (me);
58
59   SCM stencil = Text_interface::interpret_markup (me->layout ()->self_scm (),
60                                                   chain, bt);
61
62   Stencil *text_stil = unsmob_stencil (stencil);
63
64   Offset z1;
65   for (int i = X_AXIS; i < NO_AXES; i++)
66     {
67       Axis a ((Axis)i);
68       z1[a] = b[a].linear_combination (sign (off[a]));
69       text_stil->align_to (a, -sign (off[a]));
70     }
71
72   Offset z2 = z1 + off;
73
74   fr.add_stencil (Line_interface::line (me, z1, z2));
75
76   text_stil->translate (z2);
77   fr.add_stencil (*text_stil);
78
79   fr.translate (-off);
80   return fr.smobbed_copy ();
81 }
82
83 ADD_INTERFACE (Balloon_interface,
84                "A collection of routines to put text balloons around an"
85                " object.",
86
87                /* properties */
88                "padding "
89                "text "
90                );
91