diff --git a/src/engraving/infrastructure/paint.cpp b/src/engraving/infrastructure/paint.cpp index d8b22befcd..062ff1b341 100644 --- a/src/engraving/infrastructure/paint.cpp +++ b/src/engraving/infrastructure/paint.cpp @@ -136,7 +136,7 @@ void Paint::paintScore(draw::Painter* painter, Score* score, const Options& opt) } std::vector elements = page->items(drawRect.translated(-pagePos)); - paintElements(*painter, elements, opt.isPrinting); + paintItems(*painter, elements, opt.isPrinting); if (disableClipping) { painter->setClipping(false); @@ -207,38 +207,38 @@ SizeF Paint::pageSizeInch(const Score* score, const Options& opt) return pageRect.size() / mu::engraving::DPI; } -void Paint::paintElement(mu::draw::Painter& painter, const EngravingItem* element) +void Paint::paintItem(mu::draw::Painter& painter, const EngravingItem* item) { TRACEFUNC; - if (element->skipDraw()) { + if (item->skipDraw()) { return; } - element->itemDiscovered = false; - PointF elementPosition(element->pagePos()); + item->itemDiscovered = false; + PointF itemPosition(item->pagePos()); - painter.translate(elementPosition); - element->draw(&painter); - painter.translate(-elementPosition); + painter.translate(itemPosition); + EngravingItem::layout()->drawItem(item, &painter); + painter.translate(-itemPosition); } -void Paint::paintElements(mu::draw::Painter& painter, const std::vector& elements, bool isPrinting) +void Paint::paintItems(mu::draw::Painter& painter, const std::vector& items, bool isPrinting) { TRACEFUNC; - std::vector sortedElements(elements.begin(), elements.end()); + std::vector sortedItems(items.begin(), items.end()); - std::sort(sortedElements.begin(), sortedElements.end(), mu::engraving::elementLessThan); + std::sort(sortedItems.begin(), sortedItems.end(), mu::engraving::elementLessThan); - for (const EngravingItem* element : sortedElements) { - if (!element->isInteractionAvailable()) { + for (const EngravingItem* item : sortedItems) { + if (!item->isInteractionAvailable()) { continue; } - paintElement(painter, element); + paintItem(painter, item); } #ifdef MUE_ENABLE_ENGRAVING_PAINT_DEBUGGER if (!isPrinting) { - DebugPaint::paintElementsDebug(painter, sortedElements); + DebugPaint::paintElementsDebug(painter, sortedItems); } #else UNUSED(isPrinting); diff --git a/src/engraving/infrastructure/paint.h b/src/engraving/infrastructure/paint.h index 83165863b0..4f7eff540e 100644 --- a/src/engraving/infrastructure/paint.h +++ b/src/engraving/infrastructure/paint.h @@ -53,8 +53,8 @@ public: }; static void paintScore(draw::Painter* painter, Score* score, const Options& opt); - static void paintElement(draw::Painter& painter, const EngravingItem* element); - static void paintElements(draw::Painter& painter, const std::vector& elements, bool isPrinting); + static void paintItem(draw::Painter& painter, const EngravingItem* item); + static void paintItems(draw::Painter& painter, const std::vector& items, bool isPrinting); static SizeF pageSizeInch(const Score* score); static SizeF pageSizeInch(const Score* score, const Options& opt); diff --git a/src/engraving/layout/dev/layout.cmake b/src/engraving/layout/dev/layout.cmake index 5a560dcfca..2e865f2fac 100644 --- a/src/engraving/layout/dev/layout.cmake +++ b/src/engraving/layout/dev/layout.cmake @@ -1,6 +1,8 @@ set(LAYOUT_DEV_SRC + ${CMAKE_CURRENT_LIST_DIR}/tdraw.cpp + ${CMAKE_CURRENT_LIST_DIR}/tdraw.h ${CMAKE_CURRENT_LIST_DIR}/tlayout.cpp ${CMAKE_CURRENT_LIST_DIR}/tlayout.h ${CMAKE_CURRENT_LIST_DIR}/layout.cpp diff --git a/src/engraving/layout/dev/layout.cpp b/src/engraving/layout/dev/layout.cpp index 2fd81fcfd4..5137779bc6 100644 --- a/src/engraving/layout/dev/layout.cpp +++ b/src/engraving/layout/dev/layout.cpp @@ -27,6 +27,7 @@ #include "libmscore/harmony.h" #include "libmscore/chord.h" +#include "tdraw.h" #include "tlayout.h" #include "chordlayout.h" #include "layoutcontext.h" @@ -50,6 +51,11 @@ void Layout::doLayoutItem(EngravingItem* item) TLayout::layoutItem(item, ctx); } +void Layout::doDrawItem(const EngravingItem* item, draw::Painter* p) +{ + TDraw::drawItem(item, p); +} + void Layout::layoutText1(TextBase* item, bool base) { LayoutContext ctx(item->score()); diff --git a/src/engraving/layout/dev/layout.h b/src/engraving/layout/dev/layout.h index 51ce5461cc..ff63037529 100644 --- a/src/engraving/layout/dev/layout.h +++ b/src/engraving/layout/dev/layout.h @@ -55,6 +55,8 @@ public: private: // Layout Single Item void doLayoutItem(EngravingItem* item) override; + + void doDrawItem(const EngravingItem* item, draw::Painter* p) override; }; } diff --git a/src/engraving/layout/dev/tdraw.cpp b/src/engraving/layout/dev/tdraw.cpp new file mode 100644 index 0000000000..934a058a3a --- /dev/null +++ b/src/engraving/layout/dev/tdraw.cpp @@ -0,0 +1,55 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2023 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see . + */ +#include "tdraw.h" + +#include "libmscore/accidental.h" + +#include "libmscore/note.h" + +#include "infrastructure/rtti.h" + +using namespace mu::engraving; +using namespace mu::engraving::rtti; +using namespace mu::engraving::layout::dev; + +void TDraw::drawItem(const EngravingItem* item, draw::Painter* painter) +{ + switch (item->type()) { + case ElementType::ACCIDENTAL: draw(item_cast(item), painter); + break; + default: + item->draw(painter); + } +} + +void TDraw::draw(const Accidental* item, draw::Painter* painter) +{ + TRACE_DRAW_ITEM; + if (item->layoutData().isSkipDraw) { + return; + } + + painter->setPen(item->curColor()); + for (const Accidental::LayoutData::Sym& e : item->layoutData().syms) { + item->drawSymbol(e.sym, painter, PointF(e.x, e.y)); + } +} diff --git a/src/engraving/layout/dev/tdraw.h b/src/engraving/layout/dev/tdraw.h new file mode 100644 index 0000000000..fb5cc52d10 --- /dev/null +++ b/src/engraving/layout/dev/tdraw.h @@ -0,0 +1,178 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2023 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see . + */ +#ifndef MU_ENGRAVING_TDRAW_DEV_H +#define MU_ENGRAVING_TDRAW_DEV_H + +#include "libmscore/engravingitem.h" + +namespace mu::engraving { +class Accidental; +class ActionIcon; +class Ambitus; +class Arpeggio; +class Articulation; + +class BagpipeEmbellishment; +class BarLine; +class Beam; +class Bend; + +class Box; +class HBox; +class VBox; +class FBox; +class TBox; + +class Bracket; +class Breath; + +class Chord; +class ChordLine; +class Clef; +class Capo; + +class DeadSlapped; +class Dynamic; + +class Expression; + +class Fermata; +class FiguredBassItem; +class FiguredBass; +class Fingering; +class FretDiagram; +class FretCircle; + +class Glissando; +class GlissandoSegment; +class GraceNotesGroup; +class GradualTempoChangeSegment; +class GradualTempoChange; + +class HairpinSegment; +class Hairpin; +class HarpPedalDiagram; +class HarmonicMarkSegment; +class Harmony; +class Hook; + +class Image; +class InstrumentChange; +class InstrumentName; +class Jump; + +class KeySig; + +class LayoutBreak; +class LedgerLine; +class LetRing; +class LetRingSegment; +class LineSegment; +class Lyrics; +class LyricsLine; +class LyricsLineSegment; + +class Marker; +class MeasureBase; +class MeasureNumber; +class MeasureNumberBase; +class MeasureRepeat; +class MMRest; +class MMRestRange; + +class Note; +class NoteDot; + +class Ornament; + +class Ottava; +class OttavaSegment; + +class PalmMute; +class PalmMuteSegment; +class Pedal; +class PedalSegment; +class PickScrapeSegment; +class PlayTechAnnotation; + +class RasgueadoSegment; +class RehearsalMark; +class Rest; + +class ShadowNote; +class SLine; +class Slur; +class Spacer; +class SpannerSegment; +class StaffLines; +class StaffState; +class StaffText; +class StaffTypeChange; +class Stem; +class StemSlash; +class Sticking; +class StretchedBend; + +class BSymbol; +class Symbol; +class FSymbol; + +class SystemDivider; +class SystemText; + +class TabDurationSymbol; +class TempoText; +class TextBase; +class Text; +class TextLine; +class TextLineSegment; +class TextLineBase; +class TextLineBaseSegment; +class Tie; +class TimeSig; +class Tremolo; +class TremoloBar; +class TrillSegment; +class TripletFeel; +class Trill; +class Tuplet; + +class VibratoSegment; +class Vibrato; +class Volta; +class VoltaSegment; + +class WhammyBarSegment; +} + +namespace mu::engraving::layout::dev { +class TDraw +{ +public: + + static void drawItem(const EngravingItem* item, draw::Painter* p); // factory + + static void draw(const Accidental* item, draw::Painter* p); +}; +} + +#endif // MU_ENGRAVING_TDRAW_DEV_H diff --git a/src/engraving/layout/dev/tlayout.cpp b/src/engraving/layout/dev/tlayout.cpp index 9f1d781afc..9954dab1e1 100644 --- a/src/engraving/layout/dev/tlayout.cpp +++ b/src/engraving/layout/dev/tlayout.cpp @@ -398,6 +398,7 @@ static void layoutAccidental(const Accidental* item, const LayoutContext& ctx, A // TODO: remove Accidental in layout // don't show accidentals for tab or slash notation if (item->onTabStaff() || (item->note() && item->note()->fixed())) { + data.isSkipDraw = true; return; } diff --git a/src/engraving/layout/ilayout.h b/src/engraving/layout/ilayout.h index 32a9a3070b..e5701a6932 100644 --- a/src/engraving/layout/ilayout.h +++ b/src/engraving/layout/ilayout.h @@ -28,6 +28,10 @@ #include "types/fraction.h" +namespace mu::draw { +class Painter; +} + namespace mu::engraving { class Score; class EngravingItem; @@ -157,9 +161,17 @@ public: // Layout Text 1 virtual void layoutText1(TextBase* item, bool base = false) = 0; + //! --- DRAW --- + void drawItem(const EngravingItem* item, draw::Painter* p) + { + doDrawItem(item, p); + } + private: // Layout Single Item virtual void doLayoutItem(EngravingItem* item) = 0; + + virtual void doDrawItem(const EngravingItem* item, draw::Painter* p) = 0; }; } diff --git a/src/engraving/layout/stable/layout.cmake b/src/engraving/layout/stable/layout.cmake index a5802bb6f6..92f5dca8a3 100644 --- a/src/engraving/layout/stable/layout.cmake +++ b/src/engraving/layout/stable/layout.cmake @@ -1,6 +1,8 @@ set(LAYOUT_STABLE_SRC + ${CMAKE_CURRENT_LIST_DIR}/tdraw.cpp + ${CMAKE_CURRENT_LIST_DIR}/tdraw.h ${CMAKE_CURRENT_LIST_DIR}/tlayout.cpp ${CMAKE_CURRENT_LIST_DIR}/tlayout.h ${CMAKE_CURRENT_LIST_DIR}/layout.cpp diff --git a/src/engraving/layout/stable/layout.cpp b/src/engraving/layout/stable/layout.cpp index e520b3fdb0..3ca7c8c617 100644 --- a/src/engraving/layout/stable/layout.cpp +++ b/src/engraving/layout/stable/layout.cpp @@ -27,6 +27,7 @@ #include "libmscore/harmony.h" #include "libmscore/chord.h" +#include "tdraw.h" #include "tlayout.h" #include "chordlayout.h" #include "layoutcontext.h" @@ -50,6 +51,11 @@ void Layout::doLayoutItem(EngravingItem* item) TLayout::layoutItem(item, ctx); } +void Layout::doDrawItem(const EngravingItem* item, draw::Painter* p) +{ + TDraw::drawItem(item, p); +} + void Layout::layoutText1(TextBase* item, bool base) { LayoutContext ctx(item->score()); diff --git a/src/engraving/layout/stable/layout.h b/src/engraving/layout/stable/layout.h index 4f3f78f361..7d28cc033e 100644 --- a/src/engraving/layout/stable/layout.h +++ b/src/engraving/layout/stable/layout.h @@ -55,6 +55,8 @@ public: private: // Layout Single Item void doLayoutItem(EngravingItem* item) override; + + void doDrawItem(const EngravingItem* item, draw::Painter* p) override; }; } diff --git a/src/engraving/layout/stable/tdraw.cpp b/src/engraving/layout/stable/tdraw.cpp new file mode 100644 index 0000000000..08dff9c0bc --- /dev/null +++ b/src/engraving/layout/stable/tdraw.cpp @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2023 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see . + */ +#include "tdraw.h" + +#include "libmscore/accidental.h" + +#include "libmscore/note.h" + +#include "infrastructure/rtti.h" + +using namespace mu::engraving; +using namespace mu::engraving::rtti; +using namespace mu::engraving::layout::stable; + +void TDraw::drawItem(const EngravingItem* item, draw::Painter* painter) +{ + switch (item->type()) { + case ElementType::ACCIDENTAL: draw(item_cast(item), painter); + break; + default: + item->draw(painter); + } +} + +void TDraw::draw(const Accidental* item, draw::Painter* painter) +{ + TRACE_DRAW_ITEM; + // don't show accidentals for tab or slash notation + if (item->onTabStaff() || (item->note() && item->note()->fixed())) { + return; + } + + painter->setPen(item->curColor()); + for (const Accidental::LayoutData::Sym& e : item->layoutData().syms) { + item->drawSymbol(e.sym, painter, PointF(e.x, e.y)); + } +} diff --git a/src/engraving/layout/stable/tdraw.h b/src/engraving/layout/stable/tdraw.h new file mode 100644 index 0000000000..d5f1c1f1a4 --- /dev/null +++ b/src/engraving/layout/stable/tdraw.h @@ -0,0 +1,178 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2023 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see . + */ +#ifndef MU_ENGRAVING_TDRAW_STABLE_H +#define MU_ENGRAVING_TDRAW_STABLE_H + +#include "libmscore/engravingitem.h" + +namespace mu::engraving { +class Accidental; +class ActionIcon; +class Ambitus; +class Arpeggio; +class Articulation; + +class BagpipeEmbellishment; +class BarLine; +class Beam; +class Bend; + +class Box; +class HBox; +class VBox; +class FBox; +class TBox; + +class Bracket; +class Breath; + +class Chord; +class ChordLine; +class Clef; +class Capo; + +class DeadSlapped; +class Dynamic; + +class Expression; + +class Fermata; +class FiguredBassItem; +class FiguredBass; +class Fingering; +class FretDiagram; +class FretCircle; + +class Glissando; +class GlissandoSegment; +class GraceNotesGroup; +class GradualTempoChangeSegment; +class GradualTempoChange; + +class HairpinSegment; +class Hairpin; +class HarpPedalDiagram; +class HarmonicMarkSegment; +class Harmony; +class Hook; + +class Image; +class InstrumentChange; +class InstrumentName; +class Jump; + +class KeySig; + +class LayoutBreak; +class LedgerLine; +class LetRing; +class LetRingSegment; +class LineSegment; +class Lyrics; +class LyricsLine; +class LyricsLineSegment; + +class Marker; +class MeasureBase; +class MeasureNumber; +class MeasureNumberBase; +class MeasureRepeat; +class MMRest; +class MMRestRange; + +class Note; +class NoteDot; + +class Ornament; + +class Ottava; +class OttavaSegment; + +class PalmMute; +class PalmMuteSegment; +class Pedal; +class PedalSegment; +class PickScrapeSegment; +class PlayTechAnnotation; + +class RasgueadoSegment; +class RehearsalMark; +class Rest; + +class ShadowNote; +class SLine; +class Slur; +class Spacer; +class SpannerSegment; +class StaffLines; +class StaffState; +class StaffText; +class StaffTypeChange; +class Stem; +class StemSlash; +class Sticking; +class StretchedBend; + +class BSymbol; +class Symbol; +class FSymbol; + +class SystemDivider; +class SystemText; + +class TabDurationSymbol; +class TempoText; +class TextBase; +class Text; +class TextLine; +class TextLineSegment; +class TextLineBase; +class TextLineBaseSegment; +class Tie; +class TimeSig; +class Tremolo; +class TremoloBar; +class TrillSegment; +class TripletFeel; +class Trill; +class Tuplet; + +class VibratoSegment; +class Vibrato; +class Volta; +class VoltaSegment; + +class WhammyBarSegment; +} + +namespace mu::engraving::layout::stable { +class TDraw +{ +public: + + static void drawItem(const EngravingItem* item, draw::Painter* p); // factory + + static void draw(const Accidental* item, draw::Painter* p); +}; +} + +#endif // MU_ENGRAVING_TDRAW_STABLE_H diff --git a/src/engraving/libmscore/accidental.cpp b/src/engraving/libmscore/accidental.cpp index 731f236e47..7d1d2f65ee 100644 --- a/src/engraving/libmscore/accidental.cpp +++ b/src/engraving/libmscore/accidental.cpp @@ -371,22 +371,14 @@ AccidentalType Accidental::value2subtype(AccidentalVal v) void Accidental::setLayoutData(const LayoutData& data) { m_layoutData = data; + setSkipDraw(data.isSkipDraw); setbbox(data.bbox); setPos(data.pos); } -void Accidental::draw(mu::draw::Painter* painter) const +void Accidental::draw(mu::draw::Painter*) const { - TRACE_ITEM_DRAW; - // don't show accidentals for tab or slash notation - if (onTabStaff() || (note() && note()->fixed())) { - return; - } - - painter->setPen(curColor()); - for (const LayoutData::Sym& e : m_layoutData.syms) { - score()->engravingFont()->draw(e.sym, painter, magS(), PointF(e.x, e.y)); - } + UNREACHABLE; } //--------------------------------------------------------- diff --git a/src/engraving/libmscore/accidental.h b/src/engraving/libmscore/accidental.h index 6017e354ff..a956871c68 100644 --- a/src/engraving/libmscore/accidental.h +++ b/src/engraving/libmscore/accidental.h @@ -123,6 +123,7 @@ public: : sym(_sym), x(_x), y(_y) {} }; + bool isSkipDraw = false; std::vector syms; RectF bbox; PointF pos; diff --git a/src/engraving/libmscore/scorefile.cpp b/src/engraving/libmscore/scorefile.cpp index 795401a0d8..1c79e295a2 100644 --- a/src/engraving/libmscore/scorefile.cpp +++ b/src/engraving/libmscore/scorefile.cpp @@ -174,7 +174,7 @@ void Score::print(mu::draw::Painter* painter, int pageNo) } painter->save(); painter->translate(e->pagePos()); - e->draw(painter); + EngravingItem::layout()->drawItem(e, painter); painter->restore(); } MScore::pdfPrinting = false; diff --git a/src/framework/draw/painter.h b/src/framework/draw/painter.h index 808eb15fc9..e095aa9b00 100644 --- a/src/framework/draw/painter.h +++ b/src/framework/draw/painter.h @@ -293,17 +293,21 @@ public: private: Painter* m_painter = nullptr; }; +} #ifdef MUE_ENABLE_DRAW_TRACE #define TRACE_ITEM_DRAW \ mu::draw::PainterItemMarker __drawItemMarker(painter, typeName()) + #define TRACE_DRAW_ITEM \ + mu::draw::PainterItemMarker __drawItemMarker(painter, item->typeName()) + #define TRACE_ITEM_DRAW_C(painter, itemName) \ mu::draw::PainterItemMarker __drawItemMarker(painter, itemName) #else #define TRACE_ITEM_DRAW + #define TRACE_DRAW_ITEM #define TRACE_ITEM_DRAW_C(painter, objName) #endif -} #endif // MU_DRAW_PAINTER_H diff --git a/src/importexport/imagesexport/internal/svgwriter.cpp b/src/importexport/imagesexport/internal/svgwriter.cpp index da910a6661..97e3c5a7f0 100644 --- a/src/importexport/imagesexport/internal/svgwriter.cpp +++ b/src/importexport/imagesexport/internal/svgwriter.cpp @@ -147,7 +147,7 @@ mu::Ret SvgWriter::write(INotationPtr notation, QIODevice& destinationDevice, co if (measure->isMeasure() && mu::engraving::toMeasure(measure)->visible(staffIndex)) { mu::engraving::StaffLines* sl = mu::engraving::toMeasure(measure)->staffLines(static_cast(staffIndex)); printer.setElement(sl); - engraving::Paint::paintElement(painter, sl); + engraving::Paint::paintItem(painter, sl); } } } else { // Draw staff lines once per system @@ -164,7 +164,7 @@ mu::Ret SvgWriter::write(INotationPtr notation, QIODevice& destinationDevice, co firstSL->setLines(lines); printer.setElement(firstSL); - engraving::Paint::paintElement(painter, firstSL); + engraving::Paint::paintItem(painter, firstSL); } } } @@ -224,7 +224,7 @@ mu::Ret SvgWriter::write(INotationPtr notation, QIODevice& destinationDevice, co printer.setElement(element); // Paint it - engraving::Paint::paintElement(painter, element); + engraving::Paint::paintItem(painter, element); } painter.endDraw(); // Writes MuseScore SVG file to disk, finally diff --git a/src/palette/CMakeLists.txt b/src/palette/CMakeLists.txt index 87d088c175..96ba143e68 100644 --- a/src/palette/CMakeLists.txt +++ b/src/palette/CMakeLists.txt @@ -45,6 +45,8 @@ set(MODULE_SRC ${CMAKE_CURRENT_LIST_DIR}/internal/paletteactionscontroller.h ${CMAKE_CURRENT_LIST_DIR}/internal/palettelayout.cpp ${CMAKE_CURRENT_LIST_DIR}/internal/palettelayout.h + ${CMAKE_CURRENT_LIST_DIR}/internal/palettedraw.cpp + ${CMAKE_CURRENT_LIST_DIR}/internal/palettedraw.h ${CMAKE_CURRENT_LIST_DIR}/internal/ipaletteprovider.h ${CMAKE_CURRENT_LIST_DIR}/internal/paletteprovider.cpp diff --git a/src/palette/internal/palettecelliconengine.cpp b/src/palette/internal/palettecelliconengine.cpp index 93fc1b3882..1855853921 100644 --- a/src/palette/internal/palettecelliconengine.cpp +++ b/src/palette/internal/palettecelliconengine.cpp @@ -32,6 +32,7 @@ #include "engraving/style/defaultstyle.h" #include "palettelayout.h" +#include "palettedraw.h" #include "log.h" @@ -189,35 +190,35 @@ void PaletteCellIconEngine::paintScoreElement(Painter& painter, EngravingItem* i PaintContext ctx; ctx.painter = &painter; - item->scanElements(&ctx, paintPaletteElement); + item->scanElements(&ctx, paintPaletteItem); painter.restore(); } -void PaletteCellIconEngine::paintPaletteElement(void* context, EngravingItem* element) +void PaletteCellIconEngine::paintPaletteItem(void* context, EngravingItem* item) { PaintContext* ctx = static_cast(context); Painter* painter = ctx->painter; painter->save(); - painter->translate(element->pos()); // necessary for drawing child elements + painter->translate(item->pos()); // necessary for drawing child elements - Color colorBackup = element->getProperty(Pid::COLOR).value(); - Color frameColorBackup = element->getProperty(Pid::FRAME_FG_COLOR).value(); - bool colorsInversionEnabledBackup = element->colorsInversionEnabled(); + Color colorBackup = item->getProperty(Pid::COLOR).value(); + Color frameColorBackup = item->getProperty(Pid::FRAME_FG_COLOR).value(); + bool colorsInversionEnabledBackup = item->colorsInversionEnabled(); - element->setColorsInverionEnabled(ctx->colorsInversionEnabled); + item->setColorsInverionEnabled(ctx->colorsInversionEnabled); if (!ctx->useElementColors) { Color color = configuration()->elementsColor(); - element->setProperty(Pid::COLOR, color); - element->setProperty(Pid::FRAME_FG_COLOR, color); + item->setProperty(Pid::COLOR, color); + item->setProperty(Pid::FRAME_FG_COLOR, color); } - element->draw(painter); + PaletteDraw::drawItem(item, painter); - element->setColorsInverionEnabled(colorsInversionEnabledBackup); - element->setProperty(Pid::COLOR, colorBackup); - element->setProperty(Pid::FRAME_FG_COLOR, frameColorBackup); + item->setColorsInverionEnabled(colorsInversionEnabledBackup); + item->setProperty(Pid::COLOR, colorBackup); + item->setProperty(Pid::FRAME_FG_COLOR, frameColorBackup); painter->restore(); } diff --git a/src/palette/internal/palettecelliconengine.h b/src/palette/internal/palettecelliconengine.h index d2f8674834..c9aa6807d0 100644 --- a/src/palette/internal/palettecelliconengine.h +++ b/src/palette/internal/palettecelliconengine.h @@ -52,7 +52,7 @@ public: bool colorsInversionEnabled = false; }; - static void paintPaletteElement(void* context, mu::engraving::EngravingItem* element); + static void paintPaletteItem(void* context, mu::engraving::EngravingItem* element); private: void paintCell(draw::Painter& painter, const RectF& rect, bool selected, bool current, qreal dpi) const; diff --git a/src/palette/internal/palettedraw.cpp b/src/palette/internal/palettedraw.cpp new file mode 100644 index 0000000000..6737f785fe --- /dev/null +++ b/src/palette/internal/palettedraw.cpp @@ -0,0 +1,57 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2021 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see . + */ +#include "palettedraw.h" + +#include "draw/painter.h" + +#include "libmscore/accidental.h" + +#include "libmscore/note.h" + +#include "infrastructure/rtti.h" + +using namespace mu::palette; +using namespace mu::engraving; +using namespace mu::engraving::rtti; + +void PaletteDraw::drawItem(const EngravingItem* item, draw::Painter* painter) +{ + switch (item->type()) { + case ElementType::ACCIDENTAL: draw(item_cast(item), painter); + break; + default: + item->draw(painter); + } +} + +void PaletteDraw::draw(const Accidental* item, draw::Painter* painter) +{ + // don't show accidentals for tab or slash notation + if (item->onTabStaff() || (item->note() && item->note()->fixed())) { + return; + } + + painter->setPen(item->curColor()); + for (const Accidental::LayoutData::Sym& e : item->layoutData().syms) { + item->drawSymbol(e.sym, painter, PointF(e.x, e.y)); + } +} diff --git a/src/palette/internal/palettedraw.h b/src/palette/internal/palettedraw.h new file mode 100644 index 0000000000..c102fc2f1d --- /dev/null +++ b/src/palette/internal/palettedraw.h @@ -0,0 +1,134 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2021 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see . + */ +#ifndef MU_PALETTE_PALETTEDRAW_H +#define MU_PALETTE_PALETTEDRAW_H + +#include "libmscore/engravingitem.h" + +namespace mu::engraving { +class MStyle; +class IEngravingFont; +class Score; + +class Accidental; +class ActionIcon; +class Ambitus; +class Arpeggio; +class Articulation; + +class BagpipeEmbellishment; +class BarLine; +class Bend; +class Bracket; +class Breath; + +class Capo; +class Chord; +class ChordLine; +class Clef; + +class Dynamic; + +class Expression; + +class Fermata; +class Fingering; +class FretDiagram; +class FSymbol; + +class Glissando; +class GlissandoSegment; +class GradualTempoChange; +class GradualTempoChangeSegment; + +class Hairpin; +class HairpinSegment; +class HarpPedalDiagram; + +class InstrumentChange; + +class Jump; + +class KeySig; + +class LayoutBreak; +class LetRing; +class LetRingSegment; +class SLine; +class LineSegment; + +class Marker; +class MeasureNumber; +class MeasureRepeat; + +class NoteHead; + +class Ornament; +class Ottava; +class OttavaSegment; + +class PalmMute; +class PalmMuteSegment; +class Pedal; +class PedalSegment; +class PlayTechAnnotation; + +class RehearsalMark; + +class Slur; +class Spacer; +class StaffText; +class StaffTypeChange; +class Symbol; +class SystemText; + +class TempoText; +class Text; +class TextBase; +class TextLine; +class TextLineSegment; +class TextLineBaseSegment; +class TimeSig; +class Tremolo; +class TremoloBar; +class Trill; +class TrillSegment; + +class Vibrato; +class VibratoSegment; +class Volta; +class VoltaSegment; +} + +namespace mu::palette { +class PaletteDraw +{ +public: + + static void drawItem(const engraving::EngravingItem* item, draw::Painter* p); // factory + +private: + static void draw(const engraving::Accidental* item, draw::Painter* p); +}; +} + +#endif // MU_PALETTE_PALETTEDRAW_H diff --git a/src/palette/view/widgets/palettewidget.cpp b/src/palette/view/widgets/palettewidget.cpp index ff77db94d5..aa8964f79c 100644 --- a/src/palette/view/widgets/palettewidget.cpp +++ b/src/palette/view/widgets/palettewidget.cpp @@ -635,7 +635,7 @@ QPixmap PaletteWidget::pixmapForCellAt(int paletteIdx) const PaletteCellIconEngine::PaintContext ctx; ctx.painter = &painter; - element->scanElements(&ctx, PaletteCellIconEngine::paintPaletteElement); + element->scanElements(&ctx, PaletteCellIconEngine::paintPaletteItem); element->setPos(pos); return pm; @@ -1112,7 +1112,7 @@ void PaletteWidget::paintEvent(QPaintEvent* /*event*/) ctx.useElementColors = m_paintOptions.useElementColors; ctx.colorsInversionEnabled = m_paintOptions.colorsInverionsEnabled; - el->scanElements(&ctx, PaletteCellIconEngine::paintPaletteElement); + el->scanElements(&ctx, PaletteCellIconEngine::paintPaletteItem); painter.restore(); } }