From 6f6c78229e4e1dee80d36c89c27e2e58e23e0eb3 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Wed, 21 Sep 2011 06:31:12 +0000 Subject: Need to get it off the drive: Part canvas drawing speed boosts. Working on meter speed. --- muse2/muse/arranger/pcanvas.cpp | 80 ++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 25 deletions(-) (limited to 'muse2/muse/arranger/pcanvas.cpp') diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index d6ae1300..0de8d278 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -3,7 +3,7 @@ // Linux Music Editor // $Id: pcanvas.cpp,v 1.48.2.26 2009/11/22 11:08:33 spamatica Exp $ // (C) Copyright 1999 Werner Schweer (ws@seh.de) -// Additions, modifications (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) +// (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -1754,19 +1754,16 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec //QRect rr = p.transform().mapRect(r); // Gives inconsistent positions. Source shows wrong operation for our needs. QRect rr = map(r); // Use our own map instead. + QRect mr = map(rect); + // Item bounding box x is in tick coordinates, same as rectangle. - //if(item->bbox().intersect(rect).isNull()) - //if((item->bbox() & rect).isNull()) - if((rr & map(rect)).isNull()) + if((rr & mr).isNull()) { //printf("PartCanvas::drawItem rectangle is null\n"); return; } - //printf("PartCanvas::drawItem called map rx:%d rw:%d rrx:%d rrw:%d\n", r.x(), r.width(), rr.x(), rr.width()); - //printf("PartCanvas::drawItem called map rx:%d rw:%d\n", r.x(), r.width()); - - p.save(); + //p.save(); p.setWorldMatrixEnabled(false); // NOTE: Optimization: For each item, hasHiddenEvents() is called once in Canvas::draw(), and we use cachedHasHiddenEvents(). @@ -1815,6 +1812,15 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec if(ye_2 < ys_0) ye_2 = ys_0; + int mrxs_0 = mr.x(); + int mrxe_0 = mrxs_0 + mr.width(); + bool lbt = ((NPart*)item)->leftBorderTouches; + bool rbt = ((NPart*)item)->rightBorderTouches; + int lbx = lbt?xs_1:xs_0; + int rbx = rbt?xe_1:xe_0; + int lbx_c = lbx < mrxs_0 ? mrxs_0 : lbx; + int rbx_c = rbx > mrxe_0 ? mrxe_0 : rbx; + int cidx = part->colorIndex(); if (item->isMoving()) { @@ -1873,8 +1879,11 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec p.setBrush(brush); p.setPen(Qt::NoPen); + if(het) { + // TODO: Make this part respect the requested drawing rectangle (rr & mr), for speed ! + pts = 0; if(het == (Part::LeftEventsHidden | Part::RightEventsHidden)) { @@ -1988,7 +1997,8 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec } else { - p.fillRect(rr, brush); + //p.fillRect(rr, brush); + p.fillRect(rr & mr, brush); // Respect the requested drawing rectangle. Gives speed boost! } // Draw a pattern brush on muted parts... @@ -1998,8 +2008,9 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec //brush.setStyle(Qt::DiagCrossPattern); brush.setStyle(Qt::Dense7Pattern); - p.fillRect(rr, brush); // FIXME: Some shifting going on + //p.fillRect(rr, brush); // FIXME: Some shifting going on //p.fillRect(QRect(rr.x(), rr.y(), rr.width() + 1, rr.height() + 1), brush); // Same here + p.fillRect(rr & mr, brush); // Respect the requested drawing rectangle. Gives speed boost! } p.setWorldMatrixEnabled(true); @@ -2035,7 +2046,10 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec p.setBrush(Qt::NoBrush); p.drawRect(r); - #else + //#else + #endif + + #if 1 // // Now draw the borders, using custom segments... // @@ -2089,18 +2103,20 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec penSelect2V.setDashOffset(1.0); penNormal2V.setDashOffset(1.0); //penHidden2.setDashPattern(customDashPattern); + + // FIXME: Some shifting still going on. Values likely not quite right here. + int xdiff = mrxs_0 - lbx; + if(xdiff > 0) + { + int doff = xdiff % 10; + penSelect1H.setDashOffset(doff); + penNormal1H.setDashOffset(doff); + doff = xdiff % 5; + penSelect2H.setDashOffset(doff); + penNormal2H.setDashOffset(doff); + } } - bool lbt = ((NPart*)item)->leftBorderTouches; - bool rbt = ((NPart*)item)->rightBorderTouches; - - QLine l1(lbt?xs_1:xs_0, ys_0, rbt?xe_1:xe_0, ys_0); // Top - //QLine l2(rbt?xe_1:xe_0, rbt?ys_1:ys_2, rbt?xe_1:xe_0, rbt?ye_1:ye_2); // Right - QLine l2(rbt?xe_1:xe_0, ys_0, rbt?xe_1:xe_0, ye_0); // Right - QLine l3(lbt?xs_1:xs_0, ye_0, rbt?xe_1:xe_0, ye_0); // Bottom - //QLine l4(xs_0, lbt?ys_1:ys_2, xs_0, lbt?ye_1:ye_2); // Left - QLine l4(xs_0, ys_0, xs_0, ye_0); // Left - //if(het & Part::RightEventsHidden) // p.setPen(((NPart*)item)->rightBorderTouches ? penHidden1 : penHidden2); //else @@ -2110,7 +2126,12 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec else p.setPen(part->selected() ? penSelect2V : penNormal2V); } - p.drawLine(l2); // Right line + + if(rbx >= mrxs_0 && rbx <= mrxe_0) // Respect the requested drawing rectangle. Gives speed boost! + { + QLine l2(rbx, ys_0, rbx, ye_0); // Right + p.drawLine(l2); // Right line + } /* int xx = rbt?xe_1:xe_0; @@ -2138,7 +2159,12 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec else p.setPen(part->selected() ? penSelect2V : penNormal2V); } - p.drawLine(l4); // Left line + + if(xs_0 >= mrxs_0 && xs_0 <= mrxe_0) + { + QLine l4(xs_0, ys_0, xs_0, ye_0); // Left + p.drawLine(l4); // Left line + } /* xx = xs_0; @@ -2158,7 +2184,11 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec */ p.setPen(part->selected() ? penSelect2H : penNormal2H); + + // Respect the requested drawing rectangle. Gives speed boost! + QLine l1(lbx_c, ys_0, rbx_c, ys_0); p.drawLine(l1); // Top line + QLine l3(lbx_c, ye_0, rbx_c, ye_0); p.drawLine(l3); // Bottom line #endif @@ -2189,8 +2219,8 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec p.drawText(tr, Qt::AlignBottom|Qt::AlignLeft, part->name()); } - p.restore(); - //p.setWorldMatrixEnabled(true); + //p.restore(); + p.setWorldMatrixEnabled(true); } //--------------------------------------------------------- -- cgit v1.2.3