]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/horizontal-bracket.cc
Run `make grand-replace'.
[lilypond.git] / lily / horizontal-bracket.cc
index ed5eac5debdd99819fd9996cc28981894cef9d72..13eec0c3ff00664bfefd55b2d245700eb61d5ef2 100644 (file)
-/*   
-  horizontal-bracket.cc --  implement  Horizontal_bracket
+/*
+  horizontal-bracket.cc -- implement Horizontal_bracket
 
   source file of the GNU LilyPond music typesetter
 
-(c) 2002--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2002--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
+*/
 
- */
+#include "horizontal-bracket.hh"       
 
-#include "side-position-interface.hh"
 #include "lookup.hh"
-#include "group-interface.hh"
+#include "side-position-interface.hh"
+#include "pointer-group-interface.hh"
 #include "directional-element-interface.hh"
 #include "output-def.hh"
 #include "staff-symbol-referencer.hh"
-#include "tuplet-bracket.hh"   // ugh.
+#include "tuplet-bracket.hh"
+#include "axis-group-interface.hh"
+#include "spanner.hh"
+#include "item.hh"
+
 
-struct Horizontal_bracket
+Stencil
+Horizontal_bracket::make_bracket (Grob *me,
+                                 Real length,
+                                 Axis a, Direction dir)                                 
 {
-  DECLARE_SCHEME_CALLBACK (print, (SCM));
-  static bool has_interface (Grob*);
-};
+  Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
+                                                     Interval (1.0, 1.0));
+  Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
+                                               Interval (0, 0));
+  Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
+                                                 Interval (0, 0));
 
+  
+  // Make sure that it points in the correct direction:
+  scale_drul (&edge_height, Real (-dir));
+  Interval empty;
+  Offset start;
+  start[a] = length;
+
+  Drul_array<bool> connect_to_other =
+    robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
+                        Drul_array<bool> (false, false));
+
+  Direction d = LEFT;
+  do
+    {
+      if (connect_to_other[d])
+       {
+         edge_height[d] = 0.0;
+         flare[d] = 0.0;
+         shorten[d] = 0.0;
+       }
+    }
+  while (flip (&d) != LEFT);
+             
+  /*
+    ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around. 
+  */
+  return Tuplet_bracket::make_bracket (me, other_axis (a), start, 
+                                      edge_height, empty, flare, shorten);
+}
+
+
+Stencil
+Horizontal_bracket::make_enclosing_bracket (Grob *me, Grob *refpoint,
+                                           vector<Grob*> grobs,
+                                           Axis a, Direction dir)
+{
+  Grob *common = common_refpoint_of_array (grobs, refpoint, a);
+  Interval ext = Axis_group_interface::relative_group_extent (grobs, common, a);
+
+  if (ext.is_empty ())
+    {
+      me->programming_error ("Can't enclose empty extents with bracket");
+      return Stencil ();
+    }
+  else
+    {
+      Stencil b = make_bracket (me, ext.length (), a, dir);
+      b.translate_axis (ext[LEFT] - refpoint->relative_coordinate (common, a), a);
+
+      return b;
+    }
+}
 
 /*
   TODO:
 
-  This doesn't look very elegant: should support winged edges.
-
   Support texts on the brackets?
 */
 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
-
 SCM
 Horizontal_bracket::print (SCM smob)
 {
-  Grob * me = unsmob_grob (smob);
-  Spanner *sp = dynamic_cast<Spanner*> (me);
-  Link_array<Grob> gs = Pointer_group_interface__extract_grobs (me, (Grob*)0, "columns");
+  Spanner *me = unsmob_spanner (smob);
+  extract_grob_set (me, "columns", gs);
 
+  vector<Grob*> enclosed = gs;
   if (!gs.size ())
     {
       me->suicide ();
       return SCM_EOL;
     }
-  Grob * cx = common_refpoint_of_array (gs, me, X_AXIS);
-  cx = cx->common_refpoint (sp->get_bound (LEFT), X_AXIS);
-  cx = cx->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
-
-  Interval ext = gs.top ()->extent (cx, X_AXIS);
-  ext.unite (gs[0]->extent (cx, X_AXIS));
-
-  Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
-                                                     Interval (1.0, 1.0));
 
+  Direction d = LEFT;
+  do
+    {
+      Item *b = me->get_bound (d);
+      if (b->break_status_dir ())
+       enclosed.push_back (b);
+    }
+  while (flip (&d) != LEFT);
   
-  Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
-                                               Interval (0, 0));
-
-  Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
-                                                 Interval (0, 0));
-
-  Interval empty;
-  Stencil b
-    = Tuplet_bracket::make_bracket (me, Y_AXIS, Offset (ext.length (), 0),
-                                   edge_height, empty, flare, shorten);
-    
-  b.translate_axis (ext[LEFT] - sp->get_bound (LEFT)->relative_coordinate (cx, X_AXIS), X_AXIS);
-
-  return b.smobbed_copy ();  
+  Stencil b = make_enclosing_bracket (me, me, enclosed, X_AXIS, get_grob_direction (me));
+  return b.smobbed_copy ();
 }
 
-ADD_INTERFACE (Horizontal_bracket, "horizontal-bracket-interface",
-  "A horizontal bracket encompassing notes.",
-  "columns bracket-flare shorten-pair edge-height");
+ADD_INTERFACE (Horizontal_bracket,
+              "A horizontal bracket encompassing notes.",
+
+              /* properties */           
+              "bracket-flare "
+              "columns "
+              "edge-height "
+              "shorten-pair "
+              "connect-to-neighbor "
+              );