]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket.cc
Merge with git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond.git
[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--2006 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
20
21 Stencil
22 Horizontal_bracket::make_bracket (Grob *me,
23                                   Real length,
24                                   Axis a, Direction dir)                                 
25 {
26   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
27                                                       Interval (1.0, 1.0));
28   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
29                                                 Interval (0, 0));
30   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
31                                                   Interval (0, 0));
32
33   
34   // Make sure that it points in the correct direction:
35   scale_drul (&edge_height, Real (-dir));
36  
37   Interval empty;
38   Offset start;
39   start[a] = length;
40
41   Drul_array<bool> connect_to_other =
42     robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
43                          Drul_array<bool> (false, false));
44
45   Direction d = LEFT;
46   do
47     {
48       if (connect_to_other[d])
49         {
50           edge_height[d] = 0.0;
51           flare[d] = 0.0;
52           shorten[d] = 0.0;
53         }
54     }
55   while (flip (&d) != LEFT);
56               
57   /*
58     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around. 
59   */
60   return Tuplet_bracket::make_bracket (me, other_axis (a), start, 
61                                        edge_height, empty, flare, shorten);
62 }
63
64
65 Stencil
66 Horizontal_bracket::make_enclosing_bracket (Grob *me, Grob *refpoint,
67                                             vector<Grob*> grobs,
68                                             Axis a, Direction dir)
69 {
70   Grob *common = common_refpoint_of_array (grobs, refpoint, a);
71   Interval ext = Axis_group_interface::relative_group_extent (grobs, common, a);
72
73   Stencil b = make_bracket (me, ext.length(), a, dir);
74   b.translate_axis (ext[LEFT] - refpoint->relative_coordinate (common, a), a);
75
76   return b;
77 }
78
79
80 /*
81   TODO:
82
83   Support texts on the brackets?
84 */
85
86 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
87 SCM
88 Horizontal_bracket::print (SCM smob)
89 {
90   Spanner *me = unsmob_spanner (smob);
91   extract_grob_set (me, "columns", gs);
92
93   vector<Grob*> enclosed = gs;
94   if (!gs.size ())
95     {
96       me->suicide ();
97       return SCM_EOL;
98     }
99
100   Direction d = LEFT;
101   do
102     {
103       Item *b = me->get_bound (d);
104       if (b->break_status_dir ())
105         enclosed.push_back (b);
106     }
107   while (flip (&d) != LEFT);
108   
109   Stencil b = make_enclosing_bracket (me, me, enclosed, X_AXIS, get_grob_direction (me));
110   return b.smobbed_copy ();
111 }
112
113 ADD_INTERFACE (Horizontal_bracket,
114
115                "horizontal-bracket-interface",
116                "A horizontal bracket encompassing notes.",
117
118                /* props */                
119                "bracket-flare "
120                "columns "
121                "edge-height "
122                "shorten-pair "
123                "connect-to-neighbor "
124                );
125