]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket.cc
8c206bb7292a06e518414eb6a7890db688dab1df
[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 #include "side-position-interface.hh"
10 #include "lookup.hh"
11 #include "pointer-group-interface.hh"
12 #include "directional-element-interface.hh"
13 #include "output-def.hh"
14 #include "staff-symbol-referencer.hh"
15 #include "tuplet-bracket.hh"    // ugh.
16 #include "horizontal-bracket.hh"        // ugh.
17
18 /*
19   TODO:
20
21   This doesn't look very elegant: should support winged edges.
22
23   Support texts on the brackets?
24 */
25
26 Stencil
27 Horizontal_bracket::make_bracket (Grob *me, Grob *common,
28                                   Link_array<Grob> grobs, Axis a, Direction dir)
29 {
30   Axis other = other_axis (a);
31   
32   Grob *cx = common_refpoint_of_array (grobs, common, a);
33
34   Interval ext = grobs.top ()->extent (cx, a);
35   ext.unite (grobs[0]->extent (cx, a));
36
37   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
38                                                       Interval (1.0, 1.0));
39   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
40                                                 Interval (0, 0));
41   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
42                                                   Interval (0, 0));
43
44   // Make sure that it points in the correct direction:
45   scale_drul (&edge_height, Real (-dir));
46
47   Interval empty;
48   Offset start;
49   start[a] = ext.length ();
50   Stencil b
51     = Tuplet_bracket::make_bracket (me, other, start, 
52                                     edge_height, empty, flare, shorten);
53
54   b.translate_axis (ext[LEFT], a);
55
56   return b;
57 }
58
59 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
60 SCM
61 Horizontal_bracket::print (SCM smob)
62 {
63   Grob *me = unsmob_grob (smob);
64   Spanner *sp = dynamic_cast<Spanner *> (me);
65
66   extract_grob_set (me, "columns", gs);
67   if (!gs.size ())
68     {
69       me->suicide ();
70       return SCM_EOL;
71     }
72
73   Grob *cx = me->common_refpoint (sp->get_bound (LEFT), X_AXIS);
74   cx = cx->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
75
76   Stencil b = make_bracket (me, cx, gs, X_AXIS, get_grob_direction (me));
77  
78   b.translate_axis (- sp->get_bound (LEFT)->relative_coordinate (cx, X_AXIS), X_AXIS);
79
80   return b.smobbed_copy ();
81 }
82
83 ADD_INTERFACE (Horizontal_bracket, "horizontal-bracket-interface",
84                "A horizontal bracket encompassing notes.",
85
86                /* props */                
87                "columns "
88                "bracket-flare "
89                "shorten-pair "
90                "edge-height");
91