Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2023 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #pragma once
23 :
24 : #include <variant>
25 :
26 : #include "modularity/imoduleinterface.h"
27 :
28 : #include "../types/types.h"
29 :
30 : #include "paintoptions.h"
31 :
32 : namespace muse::draw {
33 : class Painter;
34 : }
35 :
36 : namespace mu::engraving {
37 : class Score;
38 : class EngravingItem;
39 : class Page;
40 :
41 : class Accidental;
42 : class ActionIcon;
43 : class Arpeggio;
44 :
45 : class BarLine;
46 : class Beam;
47 : class Box;
48 : class Bracket;
49 :
50 : class Chord;
51 : class Clef;
52 :
53 : class Dynamic;
54 :
55 : class EngravingItem;
56 :
57 : class FiguredBassItem;
58 :
59 : class FretDiagram;
60 :
61 : class Harmony;
62 :
63 : class Image;
64 :
65 : class IndicatorIcon;
66 :
67 : enum class KerningType : unsigned char;
68 : class KeySig;
69 :
70 : class LedgerLine;
71 : class SLine;
72 : class LineSegment;
73 : class Lyrics;
74 :
75 : class NoteDot;
76 :
77 : class Parenthesis;
78 :
79 : class Rest;
80 :
81 : class ShadowNote;
82 : class Spanner;
83 : class Slur;
84 : class SlurSegment;
85 : class SlurTie;
86 : class Spacer;
87 : class StaffText;
88 : class Stem;
89 :
90 : class TextBase;
91 : class Text;
92 : class TextLineBaseSegment;
93 : class TieSegment;
94 : class TimeSig;
95 : }
96 :
97 : namespace mu::engraving::rendering {
98 : class IScoreRenderer : MODULE_GLOBAL_INTERFACE
99 : {
100 6467 : INTERFACE_ID(IScoreRenderer)
101 :
102 : public:
103 16 : virtual ~IScoreRenderer() = default;
104 :
105 : // Main interface
106 :
107 : virtual void layoutScore(Score* score, const Fraction& st, const Fraction& et) const = 0;
108 : virtual void layoutHeadersFooters(Score* score) const = 0;
109 :
110 : struct ScorePaintOptions : public PaintOptions
111 : {
112 : bool isSetViewport = true;
113 : bool isMultiPage = false;
114 : bool printPageBackground = true;
115 : RectF frameRect;
116 : int fromPage = -1; // 0 is first
117 : int toPage = -1;
118 : int copyCount = 1;
119 : int trimMarginPixelSize = -1;
120 : int deviceDpi = -1;
121 :
122 : std::function<void(muse::draw::Painter* painter, const Page* page, const RectF& pageRect)> onPaintPageSheet;
123 : std::function<void()> onNewPage;
124 : };
125 :
126 : virtual SizeF pageSizeInch(const Score* score) const = 0;
127 : virtual SizeF pageSizeInch(const Score* score, const ScorePaintOptions& opt) const = 0;
128 : virtual void paintScore(muse::draw::Painter* painter, Score* score, const ScorePaintOptions& opt) const = 0;
129 : virtual void paintItem(muse::draw::Painter& painter, const EngravingItem* item, const PaintOptions& opt) const = 0;
130 :
131 : // Temporary compatibility interface
132 : using Supported = std::variant<std::monostate,
133 : Accidental*,
134 : ActionIcon*,
135 : Arpeggio*,
136 : BarLine*,
137 : Box*,
138 : Bracket*,
139 : Clef*,
140 : Dynamic*,
141 : FiguredBassItem*,
142 : FretDiagram*,
143 : Harmony*,
144 : Image*,
145 : IndicatorIcon*,
146 : KeySig*,
147 : LedgerLine*,
148 : SLine*,
149 : LineSegment*,
150 : Lyrics*,
151 : NoteDot*,
152 : Parenthesis*,
153 : Rest*,
154 : ShadowNote*,
155 : Spanner*,
156 : Slur*,
157 : SlurTie*,
158 : Spacer*,
159 : StaffText*,
160 : Stem*,
161 : TextBase*,
162 : Text*,
163 : TimeSig*
164 : >;
165 :
166 : template<typename T>
167 9 : static void check_supported_static(T item)
168 : {
169 : if constexpr (std::is_same<T, EngravingItem*>::value) {
170 : // supported
171 : } else {
172 9 : Supported check(item);
173 : (void)check;
174 : }
175 9 : }
176 :
177 : template<typename T>
178 9 : void layoutItem(T item)
179 : {
180 : #ifndef NDEBUG
181 9 : check_supported_static(item);
182 : #endif
183 9 : doLayoutItem(static_cast<EngravingItem*>(item));
184 9 : }
185 :
186 : //! TODO Investigation is required, probably these functions or their calls should not be.
187 : // Other
188 : virtual void layoutTextLineBaseSegment(TextLineBaseSegment* item) = 0;
189 : virtual void layoutBeam1(Beam* item) = 0;
190 : virtual void layoutStem(Chord* item) = 0;
191 :
192 : // Layout Text 1
193 : virtual void layoutText1(TextBase* item, bool base = false) = 0;
194 :
195 0 : void drawItem(const EngravingItem* item, muse::draw::Painter* p, const PaintOptions& opt)
196 : {
197 0 : doDrawItem(item, p, opt);
198 0 : }
199 :
200 : virtual void computeBezier(TieSegment* tieSeg, PointF shoulderOffset = PointF()) = 0;
201 : virtual void computeBezier(SlurSegment* slurSeg, PointF shoulderOffser = PointF()) = 0;
202 :
203 : virtual bool scoreHasTimestampHeadersFooters(const Score* score) const = 0;
204 :
205 : private:
206 : // Layout Single Item
207 : virtual void doLayoutItem(EngravingItem* item) = 0;
208 :
209 : virtual void doDrawItem(const EngravingItem* item, muse::draw::Painter* p, const PaintOptions& opt) = 0;
210 : };
211 : }
|