X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fhorizontal-bracket.cc;h=df8b79173b774cdb3cb793bc43d7bf997afc1341;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=8c206bb7292a06e518414eb6a7890db688dab1df;hpb=30eb1ded55e8d8b17495b96a3741750fe34d3599;p=lilypond.git diff --git a/lily/horizontal-bracket.cc b/lily/horizontal-bracket.cc index 8c206bb729..df8b79173b 100644 --- a/lily/horizontal-bracket.cc +++ b/lily/horizontal-bracket.cc @@ -1,91 +1,135 @@ /* - horizontal-bracket.cc -- implement Horizontal_bracket + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2002--2015 Han-Wen Nienhuys - (c) 2002--2005 Han-Wen Nienhuys + 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 . */ -#include "side-position-interface.hh" +#include "horizontal-bracket.hh" + #include "lookup.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 "horizontal-bracket.hh" // ugh. - -/* - TODO: - - This doesn't look very elegant: should support winged edges. - - Support texts on the brackets? -*/ +#include "tuplet-bracket.hh" +#include "axis-group-interface.hh" +#include "spanner.hh" +#include "item.hh" Stencil -Horizontal_bracket::make_bracket (Grob *me, Grob *common, - Link_array grobs, Axis a, Direction dir) +Horizontal_bracket::make_bracket (Grob *me, + Real length, + Axis a, Direction dir) { - Axis other = other_axis (a); - - Grob *cx = common_refpoint_of_array (grobs, common, a); - - Interval ext = grobs.top ()->extent (cx, a); - ext.unite (grobs[0]->extent (cx, a)); - Drul_array edge_height = robust_scm2interval (me->get_property ("edge-height"), - Interval (1.0, 1.0)); + Interval (1.0, 1.0)); Drul_array flare = robust_scm2interval (me->get_property ("bracket-flare"), - Interval (0, 0)); + Interval (0, 0)); Drul_array shorten = robust_scm2interval (me->get_property ("shorten-pair"), - Interval (0, 0)); + Interval (0, 0)); // Make sure that it points in the correct direction: scale_drul (&edge_height, Real (-dir)); Interval empty; Offset start; - start[a] = ext.length (); - Stencil b - = Tuplet_bracket::make_bracket (me, other, start, - edge_height, empty, flare, shorten); + start[a] = length; - b.translate_axis (ext[LEFT], a); + Drul_array connect_to_other + = robust_scm2booldrul (me->get_property ("connect-to-neighbor"), + Drul_array (false, false)); - return b; + for (LEFT_and_RIGHT (d)) + { + if (connect_to_other[d]) + { + edge_height[d] = 0.0; + flare[d] = 0.0; + shorten[d] = 0.0; + } + } + + /* + 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 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: + + 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 (me); - + Spanner *me = Spanner::unsmob (smob); extract_grob_set (me, "columns", gs); + + vector enclosed = gs; if (!gs.size ()) { me->suicide (); return SCM_EOL; } - Grob *cx = me->common_refpoint (sp->get_bound (LEFT), X_AXIS); - cx = cx->common_refpoint (sp->get_bound (RIGHT), X_AXIS); - - Stencil b = make_bracket (me, cx, gs, X_AXIS, get_grob_direction (me)); - - b.translate_axis (- sp->get_bound (LEFT)->relative_coordinate (cx, X_AXIS), X_AXIS); + for (LEFT_and_RIGHT (d)) + { + Item *b = me->get_bound (d); + if (b->break_status_dir ()) + enclosed.push_back (b); + } + 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.", +ADD_INTERFACE (Horizontal_bracket, + "A horizontal bracket encompassing notes.", - /* props */ - "columns " - "bracket-flare " - "shorten-pair " - "edge-height"); + /* properties */ + "bracket-flare " + "columns " + "edge-height " + "shorten-pair " + "connect-to-neighbor " + );