2 enclosing-bracket.cc -- implement Enclosing_bracket
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "horizontal-bracket.hh"
13 #include "axis-group-interface.hh"
14 #include "pointer-group-interface.hh"
16 struct Enclosing_bracket
18 DECLARE_GROB_INTERFACE ();
21 DECLARE_SCHEME_CALLBACK (print
, (SCM
));
22 DECLARE_SCHEME_CALLBACK (width
, (SCM
));
26 ADD_INTERFACE (Enclosing_bracket
,
27 "Brackets alongside bass figures.",
38 /* ugh: should make bracket interface. */
41 MAKE_SCHEME_CALLBACK (Enclosing_bracket
, width
, 1);
43 Enclosing_bracket::width (SCM grob
)
46 UGH. cut & paste code.
48 Grob
*me
= unsmob_grob (grob
);
49 extract_grob_set (me
, "elements", elements
);
50 if (elements
.empty ())
56 Grob
*common_x
= common_refpoint_of_array (elements
, me
, X_AXIS
);
57 Interval xext
= Axis_group_interface::relative_group_extent (elements
, common_x
, X_AXIS
);
59 Stencil left_br
= Horizontal_bracket::make_bracket (me
, 10.0, Y_AXIS
, LEFT
);
60 Stencil right_br
= Horizontal_bracket::make_bracket (me
, 10.0, Y_AXIS
, LEFT
);
63 xext
.widen (robust_scm2double (me
->get_property ("padding"), 0.25));
64 left_br
.translate_axis (xext
[LEFT
], X_AXIS
);
65 right_br
.translate_axis (xext
[RIGHT
], X_AXIS
);
67 left_br
.add_stencil (right_br
);
68 left_br
.translate_axis (-me
->relative_coordinate (common_x
, X_AXIS
), X_AXIS
);
70 return ly_interval2scm (left_br
.extent (X_AXIS
));
73 MAKE_SCHEME_CALLBACK (Enclosing_bracket
, print
, 1);
75 Enclosing_bracket::print (SCM grob
)
77 Grob
*me
= unsmob_grob (grob
);
78 extract_grob_set (me
, "elements", elements
);
79 if (elements
.empty ())
85 Grob
*common_x
= common_refpoint_of_array (elements
, me
, X_AXIS
);
86 Interval xext
= Axis_group_interface::relative_group_extent (elements
, common_x
, X_AXIS
);
89 me
->programming_error ("elements have no X extent.");
90 xext
= Interval (0, 0);
93 Stencil left_br
= Horizontal_bracket::make_enclosing_bracket (me
, me
, elements
,
95 Stencil right_br
= Horizontal_bracket::make_enclosing_bracket (me
, me
, elements
,
98 xext
.widen (robust_scm2double (me
->get_property ("padding"), 0.25));
99 left_br
.translate_axis (xext
[LEFT
], X_AXIS
);
100 right_br
.translate_axis (xext
[RIGHT
], X_AXIS
);
102 left_br
.add_stencil (right_br
);
103 left_br
.translate_axis (-me
->relative_coordinate (common_x
, X_AXIS
), X_AXIS
);
105 return left_br
.smobbed_copy ();