]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket.cc
CC
[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 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 "paper-def.hh"
15
16 struct Horizontal_bracket
17 {
18   DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM));
19   static bool has_interface (Grob*);
20 };
21
22
23 /*
24   TODO:
25
26   This doesn't look very elegant: should support winged edges.
27
28   Support texts on the brackets?
29
30 */
31
32 MAKE_SCHEME_CALLBACK(Horizontal_bracket, brew_molecule, 1);
33
34 SCM
35 Horizontal_bracket::brew_molecule (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   Direction d = Directional_element_interface::get (me);
54   Real t = me->get_paper()->get_var ("linethickness");
55
56   SCM lthick = me->get_grob_property ("thickness");
57   if (gh_number_p (lthick))
58     t *= gh_scm2double (lthick);
59   
60   Molecule b = Lookup::bracket (X_AXIS, ext, t, - d* 1.0); 
61   
62   b.translate_axis ( - sp->get_bound (LEFT)->relative_coordinate (cx, X_AXIS), X_AXIS);
63
64   return b.smobbed_copy();  
65 }
66
67 ADD_INTERFACE (Horizontal_bracket,"horizontal-bracket-interface",
68   "A horizontal bracket encompassing notes.",
69   "thickness columns direction");
70