2 balloon.cc -- implement Balloon objects
5 #include "text-item.hh"
7 #include "line-interface.hh"
9 #include "font-interface.hh"
11 #include "lily-guile.hh"
12 #include "paper-def.hh"
15 struct Balloon_interface
19 DECLARE_SCHEME_CALLBACK (print, (SCM));
20 static bool has_interface (Grob*);
23 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
25 Balloon_interface::print (SCM smob)
27 Grob *me= unsmob_grob (smob);
29 SCM cb = me->get_property ("balloon-original-callback");
30 SCM scm_mol = SCM_EOL;
32 if (gh_procedure_p (cb))
34 scm_mol = scm_call_1 (cb, smob);
37 if (!unsmob_stencil (scm_mol))
40 SCM scm_off = me->get_property ("balloon-text-offset");
42 if (!is_number_pair (scm_off))
45 Offset off = ly_scm2offset (scm_off);
46 Stencil * m = unsmob_stencil (scm_mol);
47 Box orig_extent = m->extent_box ();
48 Box box_extent = orig_extent;
50 Real w = robust_scm2double (me->get_property ("balloon-padding"), .1);
51 box_extent.widen (w, w);
54 Stencil fr = Lookup::frame (box_extent, 0.1, 0.05);
61 SCM bt = me->get_property ("balloon-text");
62 SCM chain = Font_interface::font_alist_chain (me);
63 chain = gh_cons (me->get_property ("balloon-text-props"), chain);
66 SCM text = Text_item::interpret_markup (me->get_paper ()->self_scm (), chain, bt);
69 Stencil *text_mol = unsmob_stencil (text);
73 for (int i = X_AXIS; i < NO_AXES; i++)
76 z1[a] = box_extent [a].linear_combination (sign (off[a]));
77 text_mol->align_to (a, -sign (off[a]));
82 fr.add_stencil (Line_interface::line (me, z1, z2));
84 text_mol->translate (z2);
85 fr.add_stencil (*text_mol);
87 fr = Stencil (orig_extent, fr.get_expr ());
88 return fr.smobbed_copy ();
91 ADD_INTERFACE (Balloon_interface,"text-balloon-interface",
92 "A collection of routines to put text balloons around an object.",
93 "balloon-padding balloon-text-props balloon-text-offset balloon-text balloon-original-callback");