Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 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 : #include "drawdatapaint.h"
23 :
24 : #include "log.h"
25 :
26 : using namespace muse;
27 : using namespace muse::draw;
28 :
29 26 : static void drawItem(IPaintProviderPtr& provider, const DrawData::Item& item, const std::map<int, DrawData::State>& states,
30 : const Color& overlay)
31 : {
32 : // first draw obj itself
33 460 : for (const DrawData::Data& d : item.datas) {
34 434 : DrawData::State st = states.at(d.state);
35 434 : if (overlay.isValid()) {
36 140 : st.pen.setColor(overlay);
37 140 : st.brush.setColor(overlay);
38 : }
39 :
40 434 : provider->setPen(st.pen);
41 434 : provider->setBrush(st.brush);
42 434 : provider->setFont(st.font);
43 434 : provider->setTransform(st.transform);
44 434 : provider->setAntialiasing(st.isAntialiasing);
45 434 : provider->setCompositionMode(st.compositionMode);
46 :
47 441 : for (const DrawPath& path : d.paths) {
48 7 : provider->setPen(path.pen);
49 7 : provider->setBrush(path.brush);
50 7 : provider->drawPath(path.path);
51 : }
52 :
53 696 : for (const DrawPolygon& pl : d.polygons) {
54 262 : if (pl.polygon.empty()) {
55 0 : continue;
56 : }
57 262 : provider->drawPolygon(&pl.polygon[0], pl.polygon.size(), pl.mode);
58 : }
59 :
60 698 : for (const DrawText& t : d.texts) {
61 264 : if (t.mode == DrawText::Point) {
62 264 : provider->drawText(t.rect.topLeft(), t.text);
63 : } else {
64 0 : provider->drawText(t.rect, t.alignment, t.textFlags, t.text);
65 : }
66 : }
67 :
68 434 : for (const DrawPixmap& px : d.pixmaps) {
69 0 : if (px.mode == DrawPixmap::Single) {
70 0 : provider->drawPixmap(px.rect.topLeft(), px.pm);
71 : } else {
72 0 : provider->drawTiledPixmap(px.rect, px.pm, px.offset);
73 : }
74 : }
75 434 : }
76 :
77 : // second draw chilren
78 39 : for (const DrawData::Item& ch : item.chilren) {
79 13 : drawItem(provider, ch, states, overlay);
80 : }
81 26 : }
82 :
83 13 : void DrawDataPaint::paint(Painter* painter, const DrawDataPtr& data, const Color& overlay)
84 : {
85 13 : IPaintProviderPtr provider = painter->provider();
86 13 : drawItem(provider, data->item, data->states, overlay);
87 13 : }
|