]> git.donarmstrong.com Git - lilypond.git/blob - lily/enclosing-bracket.cc
8fe151317012478f836552b4917118db9cadfda1
[lilypond.git] / lily / enclosing-bracket.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "stencil.hh"
22 #include "horizontal-bracket.hh"
23 #include "grob.hh"
24 #include "axis-group-interface.hh"
25 #include "pointer-group-interface.hh"
26
27 struct Enclosing_bracket
28 {
29   DECLARE_GROB_INTERFACE ();
30
31 public:
32   DECLARE_SCHEME_CALLBACK (print, (SCM));
33   DECLARE_SCHEME_CALLBACK (width, (SCM));
34 };
35
36 ADD_INTERFACE (Enclosing_bracket,
37                "Brackets alongside bass figures.",
38
39                /* properties */
40                "bracket-flare "
41                "edge-height "
42                "elements "
43                "padding "
44                "shorten-pair "
45                "thickness "
46               );
47
48 /* ugh: should make bracket interface. */
49
50 MAKE_SCHEME_CALLBACK (Enclosing_bracket, width, 1);
51 SCM
52 Enclosing_bracket::width (SCM grob)
53 {
54   /*
55      UGH. cut & paste code.
56   */
57   Grob *me = unsmob_grob (grob);
58   extract_grob_set (me, "elements", elements);
59   if (elements.empty ())
60     {
61       me->suicide ();
62       return SCM_EOL;
63     }
64
65   Grob *common_x = common_refpoint_of_array (elements, me, X_AXIS);
66   Interval xext = Axis_group_interface::relative_group_extent (elements, common_x, X_AXIS);
67
68   Stencil left_br = Horizontal_bracket::make_bracket (me, 10.0, Y_AXIS, LEFT);
69   Stencil right_br = Horizontal_bracket::make_bracket (me, 10.0, Y_AXIS, LEFT);
70
71   xext.widen (robust_scm2double (me->get_property ("padding"), 0.25));
72   left_br.translate_axis (xext[LEFT], X_AXIS);
73   right_br.translate_axis (xext[RIGHT], X_AXIS);
74
75   left_br.add_stencil (right_br);
76   left_br.translate_axis (-me->relative_coordinate (common_x, X_AXIS), X_AXIS);
77
78   return ly_interval2scm (left_br.extent (X_AXIS));
79 }
80
81 MAKE_SCHEME_CALLBACK (Enclosing_bracket, print, 1);
82 SCM
83 Enclosing_bracket::print (SCM grob)
84 {
85   Grob *me = unsmob_grob (grob);
86   extract_grob_set (me, "elements", elements);
87   if (elements.empty ())
88     {
89       me->suicide ();
90       return SCM_EOL;
91     }
92
93   Grob *common_x = common_refpoint_of_array (elements, me, X_AXIS);
94   Interval xext = Axis_group_interface::relative_group_extent (elements, common_x, X_AXIS);
95   if (xext.is_empty ())
96     {
97       me->programming_error ("elements have no X extent.");
98       xext = Interval (0, 0);
99     }
100
101   Stencil left_br = Horizontal_bracket::make_enclosing_bracket (me, me, elements,
102                     Y_AXIS, LEFT);
103   Stencil right_br = Horizontal_bracket::make_enclosing_bracket (me, me, elements,
104                      Y_AXIS, RIGHT);
105
106   xext.widen (robust_scm2double (me->get_property ("padding"), 0.25));
107   left_br.translate_axis (xext[LEFT], X_AXIS);
108   right_br.translate_axis (xext[RIGHT], X_AXIS);
109
110   left_br.add_stencil (right_br);
111   left_br.translate_axis (-me->relative_coordinate (common_x, X_AXIS), X_AXIS);
112
113   return left_br.smobbed_copy ();
114 }
115