]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon.cc
new file, move from
[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 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 "stencil.hh"
15 #include "lily-guile.hh"
16 #include "output-def.hh"
17 #include "misc.hh"
18
19 class Balloon_interface
20 {
21 public:
22   DECLARE_SCHEME_CALLBACK (print, (SCM));
23   static bool has_interface (Grob*);
24 };
25
26 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
27 SCM
28 Balloon_interface::print (SCM smob) 
29 {
30   Grob *me = unsmob_grob (smob);
31
32   SCM cb = me->get_property ("balloon-original-callback");
33   SCM stil = SCM_EOL;
34
35   if (ly_c_procedure_p (cb))
36     stil = scm_call_1 (cb, smob);
37
38   if (!unsmob_stencil (stil))
39     return stil;
40
41   SCM scm_off = me->get_property ("balloon-text-offset");
42
43   if (!is_number_pair (scm_off))
44     return stil;
45
46   Offset off = ly_scm2offset (scm_off);
47   Stencil *s = unsmob_stencil (stil);
48   Box orig_extent = s->extent_box ();
49   Box box_extent = orig_extent;
50
51   Real w = robust_scm2double (me->get_property ("balloon-padding"), .1);
52   box_extent.widen (w, w);
53
54   // FIXME
55   Stencil fr = Lookup::frame (box_extent, 0.1, 0.05);
56
57   fr.add_stencil (*s);
58   
59   SCM bt = me->get_property ("balloon-text");
60   SCM chain = Font_interface::text_font_alist_chain (me);
61   chain = scm_cons (me->get_property ("balloon-text-props"), chain);
62
63   SCM text = Text_item::interpret_markup (me->get_paper ()->self_scm (),
64                                           chain, bt);
65
66   Stencil *text_stil = unsmob_stencil (text);
67  
68   Offset z1;
69   for (int i = X_AXIS; i < NO_AXES; i++)
70     {
71       Axis a ((Axis)i);
72       z1[a] = box_extent [a].linear_combination (sign (off[a]));
73       text_stil->align_to (a, -sign (off[a]));
74     }
75
76   Offset z2 = z1 + off;
77  
78   fr.add_stencil (Line_interface::line (me, z1, z2));
79
80   text_stil->translate (z2);
81   fr.add_stencil (*text_stil);
82  
83   fr = Stencil (orig_extent, fr.expr ());
84   return fr.smobbed_copy ();
85 }
86
87 ADD_INTERFACE (Balloon_interface,"text-balloon-interface",
88                "A collection of routines to put text balloons around an object.",
89                "balloon-padding balloon-text-props balloon-text-offset balloon-text balloon-original-callback");
90