]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket.cc
ed5eac5debdd99819fd9996cc28981894cef9d72
[lilypond.git] / lily / horizontal-bracket.cc
1 /*   
2   horizontal-bracket.cc --  implement  Horizontal_bracket
3
4   source file of the GNU LilyPond music typesetter
5
6 (c) 2002--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8  */
9
10 #include "side-position-interface.hh"
11 #include "lookup.hh"
12 #include "group-interface.hh"
13 #include "directional-element-interface.hh"
14 #include "output-def.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "tuplet-bracket.hh"    // ugh.
17
18 struct Horizontal_bracket
19 {
20   DECLARE_SCHEME_CALLBACK (print, (SCM));
21   static bool has_interface (Grob*);
22 };
23
24
25 /*
26   TODO:
27
28   This doesn't look very elegant: should support winged edges.
29
30   Support texts on the brackets?
31 */
32 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
33
34 SCM
35 Horizontal_bracket::print (SCM smob)
36 {
37   Grob * me = unsmob_grob (smob);
38   Spanner *sp = dynamic_cast<Spanner*> (me);
39   Link_array<Grob> gs = Pointer_group_interface__extract_grobs (me, (Grob*)0, "columns");
40
41   if (!gs.size ())
42     {
43       me->suicide ();
44       return SCM_EOL;
45     }
46   Grob * cx = common_refpoint_of_array (gs, me, X_AXIS);
47   cx = cx->common_refpoint (sp->get_bound (LEFT), X_AXIS);
48   cx = cx->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
49
50   Interval ext = gs.top ()->extent (cx, X_AXIS);
51   ext.unite (gs[0]->extent (cx, X_AXIS));
52
53   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
54                                                       Interval (1.0, 1.0));
55
56   
57   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
58                                                 Interval (0, 0));
59
60   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
61                                                   Interval (0, 0));
62
63   Interval empty;
64   Stencil b
65     = Tuplet_bracket::make_bracket (me, Y_AXIS, Offset (ext.length (), 0),
66                                     edge_height, empty, flare, shorten);
67     
68   b.translate_axis (ext[LEFT] - sp->get_bound (LEFT)->relative_coordinate (cx, X_AXIS), X_AXIS);
69
70   return b.smobbed_copy ();  
71 }
72
73 ADD_INTERFACE (Horizontal_bracket, "horizontal-bracket-interface",
74   "A horizontal bracket encompassing notes.",
75   "columns bracket-flare shorten-pair edge-height");
76