]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon.cc
*** empty log message ***
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "text-item.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   static bool has_interface (Grob*);
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   SCM cb = me->get_property ("balloon-original-callback");
32   SCM stil = SCM_EOL;
33
34   if (ly_c_procedure_p (cb))
35     stil = scm_call_1 (cb, smob);
36
37   if (!unsmob_stencil (stil))
38     return stil;
39
40   SCM scm_off = me->get_property ("balloon-text-offset");
41
42   if (!is_number_pair (scm_off))
43     return stil;
44
45   Offset off = ly_scm2offset (scm_off);
46   Stencil *s = unsmob_stencil (stil);
47   Box orig_extent = s->extent_box ();
48   Box box_extent = orig_extent;
49
50   Real w = robust_scm2double (me->get_property ("balloon-padding"), .1);
51   box_extent.widen (w, w);
52
53   // FIXME
54   Stencil fr = Lookup::frame (box_extent, 0.1, 0.05);
55
56   fr.add_stencil (*s);
57   
58   SCM bt = me->get_property ("balloon-text");
59   SCM chain = Font_interface::text_font_alist_chain (me);
60   chain = scm_cons (me->get_property ("balloon-text-props"), chain);
61
62   SCM text = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
63                                           chain, bt);
64
65   Stencil *text_stil = unsmob_stencil (text);
66  
67   Offset z1;
68   for (int i = X_AXIS; i < NO_AXES; i++)
69     {
70       Axis a ((Axis)i);
71       z1[a] = box_extent [a].linear_combination (sign (off[a]));
72       text_stil->align_to (a, -sign (off[a]));
73     }
74
75   Offset z2 = z1 + off;
76  
77   fr.add_stencil (Line_interface::line (me, z1, z2));
78
79   text_stil->translate (z2);
80   fr.add_stencil (*text_stil);
81  
82   fr = Stencil (orig_extent, fr.expr ());
83   return fr.smobbed_copy ();
84 }
85
86 ADD_INTERFACE (Balloon_interface,"text-balloon-interface",
87                "A collection of routines to put text balloons around an object.",
88                "balloon-padding balloon-text-props balloon-text-offset balloon-text balloon-original-callback");
89