From eba52ab2093283d1dc54e342e88010ec72cfa701 Mon Sep 17 00:00:00 2001 From: hanwen Date: Sat, 17 Jan 2004 13:13:03 +0000 Subject: [PATCH] * input/regression/balloon.ly: new file. * lily/balloon.cc (brew_molecule): new file: draw boxes around objects, and make help texts. --- ChangeLog | 5 ++ Documentation/user/internals.itely | 3 +- input/regression/balloon.ly | 25 ++++++++ lily/balloon.cc | 98 ++++++++++++++++++++++++++++++ lily/box.cc | 7 +++ lily/include/box.hh | 1 + lily/include/text-item.hh | 4 +- lily/parser.yy | 3 + scm/define-grob-properties.scm | 11 ++++ 9 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 input/regression/balloon.ly create mode 100644 lily/balloon.cc diff --git a/ChangeLog b/ChangeLog index 99797d698b..129bdae74e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2004-01-17 Han-Wen Nienhuys + * input/regression/balloon.ly: new file. + + * lily/balloon.cc (brew_molecule): new file: draw boxes around + objects, and make help texts. + * scm/new-markup.scm (parse-simple-duration): parse duration string to log & dots. (Thanks Nicolas!) diff --git a/Documentation/user/internals.itely b/Documentation/user/internals.itely index d2d57309c4..9d35ceb79a 100644 --- a/Documentation/user/internals.itely +++ b/Documentation/user/internals.itely @@ -61,7 +61,8 @@ properties: @item Music properties These are used internally, and most users will not see or use them. -They use Scheme style naming: @code{pitch}, @code{tremolo-type}. +They use Scheme-style naming, i.e. lowercase words separated with +dashes: @code{pitch}, @code{tremolo-type}. @item Translation properties These influence the translation process, and most users will encounter them diff --git a/input/regression/balloon.ly b/input/regression/balloon.ly new file mode 100644 index 0000000000..cf06c5ab86 --- /dev/null +++ b/input/regression/balloon.ly @@ -0,0 +1,25 @@ + +\header { + texidoc = "With balloon texts, objects in the output can be marked, +with lines and explanatory text added." + } +\version "2.1.11" + +\score { + \notes { + + \relative c' { + + \once\property Voice.Stem \set #'molecule-callback = #Balloon_interface::brew_molecule + \once\property Voice.Stem \set #'original-callback = #Stem::brew_molecule + \once\property Voice.Stem \set #'balloon-text = #"I'm a stem" + \once\property Voice.Stem \set #'balloon-text-offset = #'(3 . 4) + \once\property Voice.Stem \set #'balloon-text-props + = #'((font-family . roman)) + + + c8 + } + } + \paper{ raggedright = ##t } +} diff --git a/lily/balloon.cc b/lily/balloon.cc new file mode 100644 index 0000000000..0604a81234 --- /dev/null +++ b/lily/balloon.cc @@ -0,0 +1,98 @@ +/* + balloon.cc -- implement Balloon objects + */ + +#include "text-item.hh" +#include "grob.hh" +#include "lookup.hh" +#include "font-interface.hh" +#include "molecule.hh" +#include "lily-guile.hh" +#include "paper-def.hh" +#include "misc.hh" + +struct Balloon_interface +{ + +public: + DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM)); + static bool has_interface (Grob*); +}; + +MAKE_SCHEME_CALLBACK (Balloon_interface, brew_molecule, 1); +SCM +Balloon_interface::brew_molecule (SCM smob) +{ + Grob *me= unsmob_grob (smob); + + SCM cb = me->get_grob_property ("original-callback"); + SCM scm_mol = SCM_EOL; + + if (gh_procedure_p (cb)) + { + scm_mol = scm_call_1 (cb, smob); + } + + if (!unsmob_molecule (scm_mol)) + return scm_mol; + + SCM scm_off = me->get_grob_property ("balloon-text-offset"); + + if (!is_number_pair (scm_off)) + return scm_mol; + + Offset off = ly_scm2offset (scm_off); + Molecule * m = unsmob_molecule (scm_mol); + Box orig_extent = m->extent_box (); + Box box_extent = orig_extent; + + SCM widen = me->get_grob_property ("balloon-padding"); + Real w = .1; + if (gh_number_p (widen)) + { + w = gh_scm2double (widen); + } + box_extent.widen (w, w); + + + Molecule fr = Lookup::frame (box_extent, 0.1, 0.05); + + + fr.add_molecule (*m); + + + + SCM bt = me->get_grob_property ("balloon-text"); + SCM chain = Font_interface::font_alist_chain (me); + chain = gh_cons (me->get_grob_property ("balloon-text-props"), chain); + + + SCM text = Text_item::interpret_markup (me->get_paper ()->self_scm (), chain, bt); + + + Molecule *text_mol = unsmob_molecule (text); + + Offset z1; + + for (int i = X_AXIS; i < NO_AXES; i++) + { + Axis a((Axis)i); + z1[a] = box_extent [a].linear_combination (sign (off[a])); + text_mol->align_to (a, -sign (off[a])); + } + + Offset z2 = z1 + off; + + fr.add_molecule (Lookup::line (0.1, z1, z2)); + + text_mol->translate (z2); + fr.add_molecule (*text_mol); + + fr = Molecule (orig_extent, fr.get_expr ()); + return fr.smobbed_copy (); +} + +ADD_INTERFACE (Balloon_interface,"text-balloon-interface", + "comic books.", + "balloon-padding balloon-text-props balloon-text-offset balloon-text balloon-original-callback"); + diff --git a/lily/box.cc b/lily/box.cc index c678caf76b..fc85114c59 100644 --- a/lily/box.cc +++ b/lily/box.cc @@ -75,3 +75,10 @@ Box::center () const return Offset (interval_a_[X_AXIS].center(), interval_a_[Y_AXIS].center()); } +void +Box::widen (Real x, Real y) +{ + interval_a_[X_AXIS].widen (x); + interval_a_[Y_AXIS].widen (y); + +} diff --git a/lily/include/box.hh b/lily/include/box.hh index cbdfc2da7a..252b695e7b 100644 --- a/lily/include/box.hh +++ b/lily/include/box.hh @@ -29,6 +29,7 @@ struct Box /// smallest box enclosing #b# void set_empty (); void add_point (Offset); + void widen (Real x, Real y); void scale (Real r); void unite (Box b); Box (); diff --git a/lily/include/text-item.hh b/lily/include/text-item.hh index 32d16bf152..a98d29c850 100644 --- a/lily/include/text-item.hh +++ b/lily/include/text-item.hh @@ -1,5 +1,5 @@ /* - text-item.hh -- declare Text_item + text-item.hh -- declare markup functions source file of the GNU LilyPond music typesetter @@ -19,7 +19,7 @@ class Text_item { public: DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM)); - DECLARE_SCHEME_CALLBACK (interpret_markup, (SCM,SCM, SCM)); + DECLARE_SCHEME_CALLBACK (interpret_markup, (SCM, SCM, SCM)); static bool has_interface (Grob*); static bool markup_p (SCM) ; diff --git a/lily/parser.yy b/lily/parser.yy index fc807b3111..fc618acb5e 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -2250,6 +2250,9 @@ markup: | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm { $$ = scm_list_n ($1, $2, $3, $4, SCM_UNDEFINED); } + | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm { + $$ = scm_list_n ($1, $2, $3, SCM_UNDEFINED); + } | MARKUP_IDENTIFIER { $$ = $1; } diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 6549ca6c03..3a5452eb13 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -91,6 +91,17 @@ attachments to prevent ugly slurs. [fixme: we need more documentation here]. where a horizontal beam fits that is larger than this number, make a kneed beam.") (grob-property-description 'axes list? "list of axis numbers. In the case of alignment grobs, this should contain only one number.") + +(grob-property-description 'balloon-text markup? "Text to add to help balloon") +(grob-property-description 'balloon-text-props list? "Font properties +for balloon text.") +(grob-property-description 'balloon-text-offset number-pair? + "Where to put text relative to balloon.") +(grob-property-description 'balloon-padding ly:dimension? "Text to add to help balloon") +(grob-property-description 'original-callback procedure? "The +original molecule drawer to draw the balloon around.") + + (grob-property-description 'bar-size ly:dimension? "size of a bar line.") (grob-property-description 'bars grob-list? "list of barline pointers.") (grob-property-description 'bar-size-procedure procedure? "Procedure that computes the size of a bar line.") -- 2.39.5