]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket.cc
Run `make grand-replace'.
[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--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "horizontal-bracket.hh"        
10
11 #include "lookup.hh"
12 #include "side-position-interface.hh"
13 #include "pointer-group-interface.hh"
14 #include "directional-element-interface.hh"
15 #include "output-def.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "tuplet-bracket.hh"
18 #include "axis-group-interface.hh"
19 #include "spanner.hh"
20 #include "item.hh"
21
22
23 Stencil
24 Horizontal_bracket::make_bracket (Grob *me,
25                                   Real length,
26                                   Axis a, Direction dir)                                 
27 {
28   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
29                                                       Interval (1.0, 1.0));
30   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
31                                                 Interval (0, 0));
32   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
33                                                   Interval (0, 0));
34
35   
36   // Make sure that it points in the correct direction:
37   scale_drul (&edge_height, Real (-dir));
38  
39   Interval empty;
40   Offset start;
41   start[a] = length;
42
43   Drul_array<bool> connect_to_other =
44     robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
45                          Drul_array<bool> (false, false));
46
47   Direction d = LEFT;
48   do
49     {
50       if (connect_to_other[d])
51         {
52           edge_height[d] = 0.0;
53           flare[d] = 0.0;
54           shorten[d] = 0.0;
55         }
56     }
57   while (flip (&d) != LEFT);
58               
59   /*
60     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around. 
61   */
62   return Tuplet_bracket::make_bracket (me, other_axis (a), start, 
63                                        edge_height, empty, flare, shorten);
64 }
65
66
67 Stencil
68 Horizontal_bracket::make_enclosing_bracket (Grob *me, Grob *refpoint,
69                                             vector<Grob*> grobs,
70                                             Axis a, Direction dir)
71 {
72   Grob *common = common_refpoint_of_array (grobs, refpoint, a);
73   Interval ext = Axis_group_interface::relative_group_extent (grobs, common, a);
74
75   if (ext.is_empty ())
76     {
77       me->programming_error ("Can't enclose empty extents with bracket");
78       return Stencil ();
79     }
80   else
81     {
82       Stencil b = make_bracket (me, ext.length (), a, dir);
83       b.translate_axis (ext[LEFT] - refpoint->relative_coordinate (common, a), a);
84
85       return b;
86     }
87 }
88
89 /*
90   TODO:
91
92   Support texts on the brackets?
93 */
94 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
95 SCM
96 Horizontal_bracket::print (SCM smob)
97 {
98   Spanner *me = unsmob_spanner (smob);
99   extract_grob_set (me, "columns", gs);
100
101   vector<Grob*> enclosed = gs;
102   if (!gs.size ())
103     {
104       me->suicide ();
105       return SCM_EOL;
106     }
107
108   Direction d = LEFT;
109   do
110     {
111       Item *b = me->get_bound (d);
112       if (b->break_status_dir ())
113         enclosed.push_back (b);
114     }
115   while (flip (&d) != LEFT);
116   
117   Stencil b = make_enclosing_bracket (me, me, enclosed, X_AXIS, get_grob_direction (me));
118   return b.smobbed_copy ();
119 }
120
121 ADD_INTERFACE (Horizontal_bracket,
122                "A horizontal bracket encompassing notes.",
123
124                /* properties */           
125                "bracket-flare "
126                "columns "
127                "edge-height "
128                "shorten-pair "
129                "connect-to-neighbor "
130                );
131