]> git.donarmstrong.com Git - lilypond.git/commitdiff
Scheme function to draw lines based on grob layout
authorDavid Nalesnik <david.nalesnik@gmail.com>
Wed, 26 Aug 2015 14:46:07 +0000 (09:46 -0500)
committerDavid Nalesnik <david.nalesnik@gmail.com>
Wed, 2 Sep 2015 12:24:31 +0000 (07:24 -0500)
A number of C++ stencil callbacks use Line_interface::line to draw
lines based on line-interface properties defining a particular grob.
This allows control of aspects such as line style (based on the setting
of Grob.style) and fine-tuning of dashed lines through dash-fraction
and dash-period.

This patch gives access to Line_interface::line in Scheme through the
callback ly:line-interface::line.  (The simpler name ly:line was ruled
out in an effort to distinguish it from other functions such as
ly:bracket and ly:circle which do not take a grob argument.)  Users
will be able to create custom stencils with more functionality
(including rewriting certain C++ callbacks--such as Hairpin::print--to
allow for easy modifications without loss of capability.)

lily/line-interface-scheme.cc [new file with mode: 0644]

diff --git a/lily/line-interface-scheme.cc b/lily/line-interface-scheme.cc
new file mode 100644 (file)
index 0000000..dee6a15
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 2010--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "line-interface.hh"
+
+#include "stencil.hh"
+#include "grob.hh"
+
+LY_DEFINE (ly_line_interface__line, "ly:line-interface::line",
+           5, 0, 0, (SCM grob, SCM startx, SCM starty, SCM endx, SCM endy),
+           "Make a line using layout information from grob @var{grob}.")
+{
+  LY_ASSERT_SMOB (Grob, grob, 1);
+
+  Grob *me = unsmob<Grob> (grob);
+
+  LY_ASSERT_TYPE (scm_is_number, startx, 2);
+  LY_ASSERT_TYPE (scm_is_number, starty, 3);
+  LY_ASSERT_TYPE (scm_is_number, endx, 4);
+  LY_ASSERT_TYPE (scm_is_number, endy, 5);
+
+  Offset from = Offset (scm_to_double (startx), scm_to_double (starty));
+  Offset to = Offset (scm_to_double (endx), scm_to_double (endy));
+
+  Stencil stil = Line_interface::line (me, from, to);
+
+  return stil.smobbed_copy ();
+}