Skip to content

Commit 534179c

Browse files
committed
Remove draw method from TextBase class
I think this was the only DOM class that still had its own draw method. I have moved it to the respective draw module where it belongs.
1 parent dd339d8 commit 534179c

File tree

8 files changed

+68
-31
lines changed

8 files changed

+68
-31
lines changed

src/engraving/dom/textbase.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <stack>
2525

2626
#include "draw/fontmetrics.h"
27-
#include "draw/painter.h"
2827

2928
#include "iengravingfont.h"
3029

@@ -855,18 +854,6 @@ bool TextFragment::operator ==(const TextFragment& f) const
855854
return format == f.format && text == f.text;
856855
}
857856

858-
//---------------------------------------------------------
859-
// draw
860-
//---------------------------------------------------------
861-
862-
void TextFragment::draw(Painter* p, const TextBase* t) const
863-
{
864-
Font f(font(t));
865-
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
866-
p->setFont(f);
867-
p->drawText(pos, text);
868-
}
869-
870857
//---------------------------------------------------------
871858
// font
872859
//---------------------------------------------------------
@@ -988,19 +975,6 @@ Font TextFragment::font(const TextBase* t) const
988975
return font;
989976
}
990977

991-
//---------------------------------------------------------
992-
// draw
993-
//---------------------------------------------------------
994-
995-
void TextBlock::draw(Painter* p, const TextBase* t) const
996-
{
997-
p->translate(0.0, m_y);
998-
for (const TextFragment& f : m_fragments) {
999-
f.draw(p, t);
1000-
}
1001-
p->translate(0.0, -m_y);
1002-
}
1003-
1004978
//---------------------------------------------------------
1005979
// layout
1006980
//---------------------------------------------------------

src/engraving/dom/textbase.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ class TextFragment
231231
bool operator ==(const TextFragment& f) const;
232232

233233
TextFragment split(int column);
234-
void draw(muse::draw::Painter*, const TextBase*) const;
235234
muse::draw::Font font(const TextBase*) const;
236235
int columns() const;
237236
void changeFormat(FormatId id, const FormatValue& data);
@@ -249,7 +248,7 @@ class TextBlock
249248

250249
bool operator ==(const TextBlock& x) const { return m_fragments == x.m_fragments; }
251250
bool operator !=(const TextBlock& x) const { return m_fragments != x.m_fragments; }
252-
void draw(muse::draw::Painter*, const TextBase*) const;
251+
253252
void layout(const TextBase*);
254253
const std::list<TextFragment>& fragments() const { return m_fragments; }
255254
std::list<TextFragment>& fragments() { return m_fragments; }

src/engraving/rendering/editmode/editmoderenderer.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void EditModeRenderer::drawTextBase(const TextBase* item, muse::draw::Painter* p
240240
TextBase::sort(r1, c1, r2, c2);
241241
size_t row = 0;
242242
for (const TextBlock& t : ldata->blocks) {
243-
t.draw(painter, item);
243+
draw(t, item, painter);
244244
if (row >= r1 && row <= r2) {
245245
RectF br;
246246
if (row == r1 && r1 == r2) {
@@ -278,3 +278,20 @@ void EditModeRenderer::drawTextBase(const TextBase* item, muse::draw::Painter* p
278278
painter->drawRect(r);
279279
pen = Pen(item->configuration()->defaultColor(), 0.0);
280280
}
281+
282+
void EditModeRenderer::draw(const TextBlock& textBlock, const TextBase* item, muse::draw::Painter* painter)
283+
{
284+
painter->translate(0.0, textBlock.y());
285+
for (const TextFragment& f : textBlock.fragments()) {
286+
draw(f, item, painter);
287+
}
288+
painter->translate(0.0, -textBlock.y());
289+
}
290+
291+
void EditModeRenderer::draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter)
292+
{
293+
Font f(textFragment.font(item));
294+
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
295+
painter->setFont(f);
296+
painter->drawText(textFragment.pos, textFragment.text);
297+
}

src/engraving/rendering/editmode/editmoderenderer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class BarLine;
3838
class Dynamic;
3939
class SlurTieSegment;
4040
class TextBase;
41+
class TextBlock;
42+
class TextFragment;
4143
}
4244

4345
namespace mu::engraving::rendering::editmode {
@@ -59,7 +61,10 @@ class EditModeRenderer : public IEditModeRenderer
5961
const PaintOptions& opt);
6062
static void drawSlurTieSegment(const SlurTieSegment* item, muse::draw::Painter* painter, const EditData& ed, double currentViewScaling,
6163
const PaintOptions& opt);
64+
6265
static void drawTextBase(const TextBase* item, muse::draw::Painter* painter, const EditData& ed, double currentViewScaling,
6366
const PaintOptions& opt);
67+
static void draw(const TextBlock& textBlock, const TextBase* item, muse::draw::Painter* painter);
68+
static void draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter);
6469
};
6570
}

src/engraving/rendering/score/tdraw.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,10 +1646,27 @@ void TDraw::drawTextBase(const TextBase* item, Painter* painter, const PaintOpti
16461646
painter->setBrush(BrushStyle::NoBrush);
16471647
painter->setPen(item->textColor(opt));
16481648
for (const TextBlock& t : ldata->blocks) {
1649-
t.draw(painter, item);
1649+
draw(t, item, painter);
16501650
}
16511651
}
16521652

1653+
void TDraw::draw(const TextBlock& textBlock, const TextBase* item, Painter* painter)
1654+
{
1655+
painter->translate(0.0, textBlock.y());
1656+
for (const TextFragment& f : textBlock.fragments()) {
1657+
draw(f, item, painter);
1658+
}
1659+
painter->translate(0.0, -textBlock.y());
1660+
}
1661+
1662+
void TDraw::draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter)
1663+
{
1664+
Font f(textFragment.font(item));
1665+
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
1666+
painter->setFont(f);
1667+
painter->drawText(textFragment.pos, textFragment.text);
1668+
}
1669+
16531670
void TDraw::drawTextLineBaseSegment(const TextLineBaseSegment* item, Painter* painter, const PaintOptions& opt)
16541671
{
16551672
const TextLineBase* tl = item->textLineBase();

src/engraving/rendering/score/tdraw.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ class TabDurationSymbol;
150150
class Tapping;
151151
class TempoText;
152152
class TextBase;
153+
class TextBlock;
154+
class TextFragment;
153155
class Text;
154156
class TextLine;
155157
class TextLineSegment;
@@ -316,6 +318,8 @@ class TDraw
316318
static void draw(const WhammyBarSegment* item, muse::draw::Painter* painter, const PaintOptions& opt);
317319

318320
static void drawTextBase(const TextBase* item, muse::draw::Painter* painter, const PaintOptions& opt);
321+
static void draw(const TextBlock& textBlock, const TextBase* item, muse::draw::Painter* painter);
322+
static void draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter);
319323
static void drawTextLineBaseSegment(const TextLineBaseSegment* item, muse::draw::Painter* painter, const PaintOptions& opt);
320324

321325
static void setMask(const EngravingItem* item, muse::draw::Painter* painter);

src/engraving/rendering/single/singledraw.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,10 +1535,27 @@ void SingleDraw::drawTextBase(const TextBase* item, Painter* painter, const Pain
15351535
painter->setBrush(BrushStyle::NoBrush);
15361536
painter->setPen(item->textColor(opt));
15371537
for (const TextBlock& t : ldata->blocks) {
1538-
t.draw(painter, item);
1538+
draw(t, item, painter);
15391539
}
15401540
}
15411541

1542+
void SingleDraw::draw(const TextBlock& textBlock, const TextBase* item, muse::draw::Painter* painter)
1543+
{
1544+
painter->translate(0.0, textBlock.y());
1545+
for (const TextFragment& f : textBlock.fragments()) {
1546+
draw(f, item, painter);
1547+
}
1548+
painter->translate(0.0, -textBlock.y());
1549+
}
1550+
1551+
void SingleDraw::draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter)
1552+
{
1553+
Font f(textFragment.font(item));
1554+
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
1555+
painter->setFont(f);
1556+
painter->drawText(textFragment.pos, textFragment.text);
1557+
}
1558+
15421559
void SingleDraw::drawTextLineBaseSegment(const TextLineBaseSegment* item, Painter* painter, const PaintOptions& opt)
15431560
{
15441561
const TextLineBase* tl = item->textLineBase();

src/engraving/rendering/single/singledraw.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class Tapping;
142142
class TempoText;
143143
class Text;
144144
class TextBase;
145+
class TextBlock;
146+
class TextFragment;
145147
class TextLine;
146148
class TextLineSegment;
147149
class TextLineBaseSegment;
@@ -281,6 +283,8 @@ class SingleDraw
281283
static void draw(const WhammyBarSegment* item, muse::draw::Painter* painter, const PaintOptions& opt);
282284

283285
static void drawTextBase(const TextBase* item, muse::draw::Painter* painter, const PaintOptions& opt);
286+
static void draw(const TextBlock& textBlock, const TextBase* item, muse::draw::Painter* painter);
287+
static void draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter);
284288
static void drawTextLineBaseSegment(const TextLineBaseSegment* item, muse::draw::Painter* painter, const PaintOptions& opt);
285289
};
286290
}

0 commit comments

Comments
 (0)