* scm/beam.scm (check-slope-callbacks): check sign of slope.
[lilypond.git] / lily / balloon.cc
blobbda3fa20cbd9f8d55372a1062d31f0935176ce58
1 /*
2 balloon.cc -- implement Balloon
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
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"
19 class Balloon_interface
21 public:
22 DECLARE_SCHEME_CALLBACK (print, (SCM));
23 static bool has_interface (Grob*);
26 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
27 SCM
28 Balloon_interface::print (SCM smob)
30 Grob *me = unsmob_grob (smob);
32 SCM cb = me->get_property ("balloon-original-callback");
33 SCM stil = SCM_EOL;
35 if (ly_c_procedure_p (cb))
36 stil = scm_call_1 (cb, smob);
38 if (!unsmob_stencil (stil))
39 return stil;
41 SCM scm_off = me->get_property ("balloon-text-offset");
43 if (!is_number_pair (scm_off))
44 return stil;
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;
51 Real w = robust_scm2double (me->get_property ("balloon-padding"), .1);
52 box_extent.widen (w, w);
54 // FIXME
55 Stencil fr = Lookup::frame (box_extent, 0.1, 0.05);
57 fr.add_stencil (*s);
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);
63 SCM text = Text_item::interpret_markup (me->get_paper ()->self_scm (),
64 chain, bt);
66 Stencil *text_stil = unsmob_stencil (text);
68 Offset z1;
69 for (int i = X_AXIS; i < NO_AXES; i++)
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]));
76 Offset z2 = z1 + off;
78 fr.add_stencil (Line_interface::line (me, z1, z2));
80 text_stil->translate (z2);
81 fr.add_stencil (*text_stil);
83 fr = Stencil (orig_extent, fr.expr ());
84 return fr.smobbed_copy ();
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");