]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/balloon.cc
Run grand replace for 2015.
[lilypond.git] / lily / balloon.cc
index 52154535588d58e823d21369594ca18e5fa1d3b7..b412a435d24005998aa4fbb389e145edcb1f97ef 100644 (file)
 /*
-  balloon.cc -- implement Balloon
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 2004--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "text-item.hh"
+#include "text-interface.hh"
 #include "grob.hh"
+#include "item.hh"
 #include "line-interface.hh"
 #include "lookup.hh"
 #include "font-interface.hh"
 #include "lily-guile.hh"
 #include "output-def.hh"
 #include "misc.hh"
+#include "spanner.hh"
 
 class Balloon_interface
 {
 public:
   DECLARE_SCHEME_CALLBACK (print, (SCM));
-  static bool has_interface (Grob*);
+  DECLARE_SCHEME_CALLBACK (print_spanner, (SCM));
+  DECLARE_GROB_INTERFACE ();
+
+  static SCM internal_balloon_print (Grob *me, Grob *p, Offset off);
 };
 
 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
 SCM
-Balloon_interface::print (SCM smob) 
+Balloon_interface::print (SCM smob)
+{
+  Grob *me = Grob::unsmob (smob);
+
+  if (Item *item = dynamic_cast<Item *> (me))
+    if (!Item::break_visible (item))
+      return SCM_EOL;
+
+  Grob *p = me->get_parent (X_AXIS);
+
+  Offset off (me->relative_coordinate (p, X_AXIS),
+              me->relative_coordinate (p, Y_AXIS));
+
+  return internal_balloon_print (me, p, off);
+}
+
+MAKE_SCHEME_CALLBACK (Balloon_interface, print_spanner, 1);
+SCM
+Balloon_interface::print_spanner (SCM smob)
 {
-  Grob *me = unsmob_grob (smob);
+  Spanner *me = Spanner::unsmob (smob);
+  Spanner *orig = dynamic_cast<Spanner *> (me->original ());
 
-  SCM cb = me->get_property ("balloon-original-callback");
-  SCM stil = SCM_EOL;
+  if (orig)
+    {
+      Direction spanner_placement = robust_scm2dir (me->get_property ("spanner-placement"), LEFT);
 
-  if (ly_c_procedure_p (cb))
-    stil = scm_call_1 (cb, smob);
+      Spanner *wanted = (spanner_placement != RIGHT)
+                        ? orig->broken_intos_[0]
+                        : orig->broken_intos_.back ();
 
-  if (!unsmob_stencil (stil))
-    return stil;
+      if (me != wanted)
+        return SCM_EOL;
+    }
 
-  SCM scm_off = me->get_property ("balloon-text-offset");
+  Spanner *p = dynamic_cast<Spanner *> (me->get_parent (Y_AXIS));
 
-  if (!is_number_pair (scm_off))
-    return stil;
+  if (!p)
+    return SCM_EOL;
 
-  Offset off = ly_scm2offset (scm_off);
-  Stencil *s = unsmob_stencil (stil);
-  Box orig_extent = s->extent_box ();
-  Box box_extent = orig_extent;
+  Offset off (me->relative_coordinate (me->get_bound (LEFT), X_AXIS),
+              me->relative_coordinate (p, Y_AXIS));
+  return internal_balloon_print (me, p, off);
+}
 
-  Real w = robust_scm2double (me->get_property ("balloon-padding"), .1);
-  box_extent.widen (w, w);
+SCM
+Balloon_interface::internal_balloon_print (Grob *me, Grob *p, Offset off)
+{
+  Box b (p->extent (p, X_AXIS),
+         p->extent (p, Y_AXIS));
+  Real padding = robust_scm2double (me->get_property ("padding"), .1);
+  b.widen (padding, padding);
 
   // FIXME
-  Stencil fr = Lookup::frame (box_extent, 0.1, 0.05);
+  Stencil fr;
+  if (to_boolean (me->get_property ("annotation-balloon")))
+    fr = Lookup::frame (b, 0.1, 0.05);
 
-  fr.add_stencil (*s);
-  
-  SCM bt = me->get_property ("balloon-text");
+  SCM bt = me->get_property ("text");
   SCM chain = Font_interface::text_font_alist_chain (me);
-  chain = scm_cons (me->get_property ("balloon-text-props"), chain);
-
-  SCM text = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
-                                         chain, bt);
+  SCM stencil = Text_interface::interpret_markup (me->layout ()->self_scm (),
+                                                  chain, bt);
+  Stencil *text_stil = Stencil::unsmob (stencil);
 
-  Stencil *text_stil = unsmob_stencil (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]));
+      z1[a] = b[a].linear_combination (sign (off[a]));
       text_stil->align_to (a, -sign (off[a]));
     }
 
   Offset z2 = z1 + off;
-  fr.add_stencil (Line_interface::line (me, z1, z2));
+
+  if (to_boolean (me->get_property ("annotation-line")))
+    fr.add_stencil (Line_interface::line (me, z1, z2));
 
   text_stil->translate (z2);
   fr.add_stencil (*text_stil);
-  fr = Stencil (orig_extent, fr.expr ());
+
+  fr.translate (-off);
   return fr.smobbed_copy ();
 }
 
-ADD_INTERFACE (Balloon_interface, "text-balloon-interface",
-              "A collection of routines to put text balloons around an object.",
-              "balloon-padding balloon-text-props balloon-text-offset balloon-text balloon-original-callback");
+ADD_INTERFACE (Balloon_interface,
+               "A collection of routines to put text balloons around an"
+               " object.",
+
+               /* properties */
+               "annotation-balloon "
+               "annotation-line "
+               "padding "
+               "spanner-placement "
+               "text "
+              );