]> git.donarmstrong.com Git - lilypond.git/blob - lily/grid-line-span-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / grid-line-span-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21 #include "item.hh"
22 #include "grid-line-interface.hh"
23
24 #include "translator.icc"
25
26 class Grid_line_span_engraver : public Engraver
27 {
28   Item *spanline_;
29   vector<Item *> lines_;
30
31 public:
32   TRANSLATOR_DECLARATIONS (Grid_line_span_engraver);
33 protected:
34   void acknowledge_grid_point (Grob_info);
35   void stop_translation_timestep ();
36 };
37
38 Grid_line_span_engraver::Grid_line_span_engraver (Context *c)
39   : Engraver (c)
40 {
41   spanline_ = 0;
42 }
43
44 void
45 Grid_line_span_engraver::acknowledge_grid_point (Grob_info i)
46 {
47   int depth = i.origin_contexts (this).size ();
48   if (depth)
49     {
50       Item *it = dynamic_cast<Item *> (i.grob ());
51       lines_.push_back (it);
52
53       if (lines_.size () >= 2 && !spanline_)
54         {
55           spanline_ = make_item ("GridLine", SCM_EOL);
56           spanline_->set_parent (lines_[0], X_AXIS);
57         }
58     }
59 }
60
61 void
62 Grid_line_span_engraver::stop_translation_timestep ()
63 {
64   if (spanline_)
65     {
66       for (vsize i = 0; i < lines_.size (); i++)
67         Grid_line_interface::add_grid_point (spanline_, lines_[i]);
68
69       spanline_ = 0;
70     }
71   lines_.resize (0);
72 }
73
74 void
75 Grid_line_span_engraver::boot ()
76 {
77   ADD_ACKNOWLEDGER (Grid_line_span_engraver, grid_point);
78 }
79
80 ADD_TRANSLATOR (Grid_line_span_engraver,
81                 /* doc */
82                 "This engraver makes cross-staff lines: It catches all normal"
83                 " lines and draws a single span line across them.",
84
85                 /* create */
86                 "GridLine ",
87
88                 /* read */
89                 "",
90
91                 /* write */
92                 ""
93                );