]> git.donarmstrong.com Git - lilypond.git/commitdiff
* input/regression/balloon.ly: new file.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 17 Jan 2004 13:13:03 +0000 (13:13 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 17 Jan 2004 13:13:03 +0000 (13:13 +0000)
* lily/balloon.cc (brew_molecule): new file: draw boxes around
objects, and make help texts.

ChangeLog
Documentation/user/internals.itely
input/regression/balloon.ly [new file with mode: 0644]
lily/balloon.cc [new file with mode: 0644]
lily/box.cc
lily/include/box.hh
lily/include/text-item.hh
lily/parser.yy
scm/define-grob-properties.scm

index 99797d698bd035293c213779fb5aa6f0858c5a5d..129bdae74e37f7d3e0ca26f98026a518f6b1c152 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2004-01-17  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * 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!)
 
index d2d57309c4639e186f4416d217a790f4ee71ad06..9d35ceb79a1f5eaa87e23c31d84ef5ce490c4632 100644 (file)
@@ -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 (file)
index 0000000..cf06c5a
--- /dev/null
@@ -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 (file)
index 0000000..0604a81
--- /dev/null
@@ -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");
+
index c678caf76b40e978b31d0c6d10e1a3136161aa38..fc85114c59b24373d2d8a5836604bdcfb2015f6e 100644 (file)
@@ -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);
+  
+}
index cbdfc2da7aef9724821eb5a7ac37c313d051f153..252b695e7bc32e2df24c2db0dd87666075d1100c 100644 (file)
@@ -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 ();
index 32d16bf1522886e302dd2cbd2f0131e4b256b056..a98d29c8508478560a923dcdcf311d51ae658d5c 100644 (file)
@@ -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) ;
 
index fc807b3111a7a6a9958d8713951f08c6b9ccba92..fc618acb5e67226222ca9bac7337cc7d7047088a 100644 (file)
@@ -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;
        }
index 6549ca6c037f19b5b3ff6768862a4e3253b6ac4a..3a5452eb13a74e5b3d04eb39964b3384f2d6e127 100644 (file)
@@ -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.")