]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon.cc
* input/regression/balloon.ly: new file.
[lilypond.git] / lily / balloon.cc
1 /*
2   balloon.cc -- implement Balloon objects
3  */
4
5 #include "text-item.hh"
6 #include "grob.hh"
7 #include "lookup.hh"
8 #include "font-interface.hh"
9 #include "molecule.hh"
10 #include "lily-guile.hh"
11 #include "paper-def.hh"
12 #include "misc.hh"
13
14 struct Balloon_interface
15 {
16   
17 public:
18   DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM));
19   static bool has_interface (Grob*);
20 };
21
22 MAKE_SCHEME_CALLBACK (Balloon_interface, brew_molecule, 1);
23 SCM
24 Balloon_interface::brew_molecule (SCM smob) 
25 {
26   Grob *me= unsmob_grob (smob);
27
28   SCM cb = me->get_grob_property ("original-callback");
29   SCM scm_mol  =  SCM_EOL;
30
31   if (gh_procedure_p (cb))
32     {
33       scm_mol = scm_call_1 (cb, smob);
34     }
35
36   if (!unsmob_molecule (scm_mol))
37     return scm_mol;
38
39   SCM scm_off = me->get_grob_property ("balloon-text-offset");
40
41   if (!is_number_pair (scm_off))
42     return scm_mol;
43
44   Offset off = ly_scm2offset (scm_off);
45   Molecule * m = unsmob_molecule (scm_mol);
46   Box orig_extent = m->extent_box ();
47   Box box_extent = orig_extent;
48
49   SCM widen = me->get_grob_property ("balloon-padding");
50   Real w = .1;
51   if (gh_number_p (widen))
52     {
53       w = gh_scm2double (widen);
54     }
55   box_extent.widen (w, w);
56   
57   
58   Molecule fr = Lookup::frame (box_extent, 0.1, 0.05);
59
60   
61   fr.add_molecule (*m);
62
63
64
65   SCM bt = me->get_grob_property ("balloon-text");
66   SCM chain = Font_interface::font_alist_chain (me);
67   chain = gh_cons (me->get_grob_property ("balloon-text-props"), chain);
68
69
70   SCM text = Text_item::interpret_markup (me->get_paper ()->self_scm (), chain, bt);
71
72   
73   Molecule *text_mol = unsmob_molecule (text);
74   
75   Offset z1;
76
77   for (int i = X_AXIS; i < NO_AXES; i++)
78     {
79       Axis  a((Axis)i);
80       z1[a] = box_extent [a].linear_combination (sign (off[a]));
81       text_mol->align_to (a, -sign (off[a]));
82     }
83
84   Offset z2 = z1 + off;
85   
86   fr.add_molecule (Lookup::line (0.1, z1, z2));
87
88   text_mol->translate (z2);
89   fr.add_molecule (*text_mol);
90   
91   fr = Molecule (orig_extent, fr.get_expr ());
92   return fr.smobbed_copy ();
93 }
94
95 ADD_INTERFACE (Balloon_interface,"text-balloon-interface",
96                "comic books.",
97                "balloon-padding balloon-text-props balloon-text-offset balloon-text balloon-original-callback");
98