summaryrefslogtreecommitdiff
path: root/muse2/muse/widgets/view.cpp
diff options
context:
space:
mode:
authorTim E. Real <termtech@rogers.com>2011-08-16 07:40:48 +0000
committerTim E. Real <termtech@rogers.com>2011-08-16 07:40:48 +0000
commit96cd2ef23505deaadb030ea0f1ef284e8a753452 (patch)
tree8c77de1c9dabb19f57cd2f41341b23c03981038c /muse2/muse/widgets/view.cpp
parent6ea3ca331aeef0b0702ff2d3c3e529cd226c5d8b (diff)
More drawing fixes, improved accuracy (grids, timescales, edges, markers guaranteed to align now).
Much drawing changed to device (pixel) space instead of virtual space, for accuracy. Fixed display of audio automation graphs. (But not editing).
Diffstat (limited to 'muse2/muse/widgets/view.cpp')
-rw-r--r--muse2/muse/widgets/view.cpp142
1 files changed, 122 insertions, 20 deletions
diff --git a/muse2/muse/widgets/view.cpp b/muse2/muse/widgets/view.cpp
index 49f559c6..57955c19 100644
--- a/muse2/muse/widgets/view.cpp
+++ b/muse2/muse/widgets/view.cpp
@@ -19,6 +19,8 @@
#include "math.h"
+#include "al/sig.h"
+
// Don't use this, it was just for debugging.
// It's much slower than muse-1 no matter how hard I tried.
// The left/right pixmap shifters in seXPos setYPos
@@ -494,26 +496,33 @@ void View::pdraw(QPainter& p, const QRect& r)
int w = r.width();
int h = r.height();
if (xmag <= 0) {
- x -= 1;
+ // TODO These adjustments are required, otherwise gaps. Tried, unable to remove them for now. p4.0.30
+ x -= 1;
w += 2;
- x = (x + xpos + rmapx(xorg)) * (-xmag);
+ //x = (x + xpos + rmapx(xorg)) * (-xmag);
+ x = lrint((double(x + xpos) + rmapx_f(xorg)) * double(-xmag));
w = w * (-xmag);
}
else {
- x = (x + xpos + rmapx(xorg)) / xmag;
- w = (w + xmag - 1) / xmag;
+ //x = (x + xpos + rmapx(xorg)) / xmag;
+ x = lrint((double(x + xpos) + rmapx_f(xorg)) / double(xmag));
+ //w = (w + xmag - 1) / xmag;
+ w = lrint(double(w) / double(xmag));
x -= 1;
w += 2;
}
if (ymag <= 0) {
y -= 1;
h += 2;
- y = (y + ypos + rmapy(yorg)) * (-ymag);
+ //y = (y + ypos + rmapy(yorg)) * (-ymag);
+ y = lrint((double(y + ypos) + rmapy_f(yorg)) * double(-ymag));
h = h * (-ymag);
}
else {
- y = (y + ypos + rmapy(yorg)) / ymag;
- h = (h + ymag - 1) / ymag;
+ //y = (y + ypos + rmapy(yorg)) / ymag;
+ y = lrint((double(y + ypos) + rmapy_f(yorg)) / double(ymag));
+ //h = (h + ymag - 1) / ymag;
+ h = lrint(double(h) / double(ymag));
y -= 1;
h += 2;
}
@@ -538,13 +547,93 @@ void View::setPainter(QPainter& p)
p.resetMatrix(); // Q3 support says use resetMatrix instead, but resetMatrix advises resetTransform instead...
//p.resetTransform();
- p.translate(double(-(xpos+rmapx(xorg))), double(-(ypos+rmapy(yorg))));
- double xMag = (xmag < 0) ? 1.0/(-xmag) : double(xmag);
- double yMag = (ymag < 0) ? 1.0/(-ymag) : double(ymag);
+ //p.translate(double(-(xpos+rmapx(xorg))), double(-(ypos+rmapy(yorg))));
+ p.translate( -(double(xpos) + rmapx_f(xorg)) , -(double(ypos) + rmapy(yorg)));
+ //double xMag = (xmag < 0) ? 1.0/(-xmag) : double(xmag);
+ //double yMag = (ymag < 0) ? 1.0/(-ymag) : double(ymag);
+ double xMag = (xmag < 0) ? 1.0/double(-xmag) : double(xmag);
+ double yMag = (ymag < 0) ? 1.0/double(-ymag) : double(ymag);
p.scale(xMag, yMag);
}
//---------------------------------------------------------
+// drawTickRaster
+//---------------------------------------------------------
+
+void View::drawTickRaster(QPainter& p, int x, int y, int w, int h, int raster)
+ {
+ // Changed to draw in device coordinate space instead of virtual, transformed space. Tim. p4.0.30
+
+ //int mx = mapx(x);
+ int my = mapy(y);
+ //int mw = mapx(x + w) - mx;
+ //int mw = mapx(x + w) - mx - 1;
+ //int mh = mapy(y + h) - my;
+ //int mh = mapy(y + h) - my - 1;
+
+ //p.save();
+ bool wmtxen = p.worldMatrixEnabled();
+ p.setWorldMatrixEnabled(false);
+
+ int xx,bar1, bar2, beat;
+ unsigned tick;
+ AL::sigmap.tickValues(x, &bar1, &beat, &tick);
+ AL::sigmap.tickValues(x+w, &bar2, &beat, &tick);
+ ++bar2;
+ ///int y2 = y + h;
+ //int y2 = my + mh;
+ int y2 = mapy(y + h) - 1;
+ //printf("View::drawTickRaster x:%d y:%d w:%d h:%d mx:%d my:%d mw:%d mh:%d y2:%d bar1:%d bar2:%d\n", x, y, w, h, mx, my, mw, mh, y2, bar1, bar2);
+ //printf("View::drawTickRaster x:%d y:%d w:%d h:%d my:%d mh:%d y2:%d bar1:%d bar2:%d\n", x, y, w, h, my, mh, y2, bar1, bar2);
+ for (int bar = bar1; bar < bar2; ++bar) {
+ ///unsigned x = AL::sigmap.bar2tick(bar, 0, 0);
+ unsigned xb = AL::sigmap.bar2tick(bar, 0, 0);
+ int xt = mapx(xb);
+ p.setPen(Qt::black);
+ ///p.drawLine(x, y, x, y2);
+ p.drawLine(xt, my, xt, y2);
+ int z, n;
+ ///AL::sigmap.timesig(x, z, n);
+ AL::sigmap.timesig(xb, z, n);
+ ///int q = p.xForm(QPoint(raster, 0)).x() - p.xForm(QPoint(0, 0)).x();
+ ///int q = p.combinedTransform().map(QPoint(raster, 0)).x() - p.combinedTransform().map(QPoint(0, 0)).x();
+ //int q = rmapx(raster);
+ int qq = raster;
+ //if (q < 8) // grid too dense
+ if (rmapx(raster) < 8) // grid too dense
+ qq *= 2;
+ p.setPen(Qt::lightGray);
+ if (raster>=4) {
+ ///int xx = x + qq;
+ //int xx = mapx(xb + qq);
+ xx = xb + qq;
+ int xxx = AL::sigmap.bar2tick(bar, z, 0);
+ //int xxx = mapx(AL::sigmap.bar2tick(bar, z, 0));
+ while (xx <= xxx) {
+ ///p.drawLine(xx, y, xx, y2);
+ int x = mapx(xx);
+ p.drawLine(x, my, x, y2);
+ xx += qq;
+ //xx += rmapx(qq);
+ }
+ //xx = xxx;
+ }
+ p.setPen(Qt::gray);
+ for (int beat = 1; beat < z; beat++) {
+ ///int xx = AL::sigmap.bar2tick(bar, beat, 0);
+ xx = mapx(AL::sigmap.bar2tick(bar, beat, 0));
+ //printf(" bar:%d z:%d beat:%d xx:%d\n", bar, z, beat, xx);
+ ///p.drawLine(xx, y, xx, y2);
+ p.drawLine(xx, my, xx, y2);
+ }
+
+ }
+ //p.setWorldMatrixEnabled(true);
+ p.setWorldMatrixEnabled(wmtxen);
+ //p.restore();
+ }
+
+//---------------------------------------------------------
// map
//---------------------------------------------------------
@@ -681,29 +770,40 @@ int View::rmapyDev(int y) const
QRect View::map(const QRect& r) const
{
- int x, y, w, h;
+ //int x, y, w, h;
+ double x, y, w, h;
+ int xx, yy, ww, hh;
//printf("View::map xmag:%d xpos:%d xorg:%d\n", xmag, xpos, xorg);
if (xmag < 0) {
- x = lrint(double(r.x())/double(-xmag) - rmapx_f(xorg)) - xpos;
- w = lrint(double(r.width()) / double(-xmag));
+ //x = lrint(double(r.x())/double(-xmag) - rmapx_f(xorg)) - xpos;
+ x = double(r.x())/double(-xmag) - rmapx_f(xorg) - xpos;
+ //w = lrint(double(r.width()) / double(-xmag));
+ w = double(r.width()) / double(-xmag);
+ xx = lrint(x);
+ ww = lrint(x + w) - xx;
}
else {
- x = r.x()*xmag - xpos - lrint(rmapx_f(xorg));
- w = r.width() * xmag;
+ xx = r.x()*xmag - xpos - lrint(rmapx_f(xorg));
+ ww = r.width() * xmag;
}
if (ymag < 0) {
- y = lrint(double(r.y())/double(-ymag) - rmapy_f(yorg)) - ypos;
- h = lrint(double(r.height()) / double(-ymag));
+ //y = lrint(double(r.y())/double(-ymag) - rmapy_f(yorg)) - ypos;
+ y = double(r.y())/double(-ymag) - rmapy_f(yorg) - ypos;
+ //h = lrint(double(r.height()) / double(-ymag));
+ h = double(r.height()) / double(-ymag);
+ yy = lrint(y);
+ hh = lrint(y + h) - yy;
}
else {
- y = r.y()*ymag - ypos - lrint(rmapy_f(yorg));
- h = r.height() * ymag;
+ yy = r.y()*ymag - ypos - lrint(rmapy_f(yorg));
+ hh = r.height() * ymag;
}
- return QRect(x, y, w, h);
+ return QRect(xx, yy, ww, hh);
}
QPoint View::map(const QPoint& p) const
{
+ /*
int x, y;
if (xmag < 0) {
x = lrint(double(p.x())/double(-xmag) - rmapx_f(xorg)) - xpos;
@@ -718,6 +818,8 @@ QPoint View::map(const QPoint& p) const
y = p.y()*ymag - ypos - lrint(rmapy_f(yorg));
}
return QPoint(x, y);
+ */
+ return QPoint(mapx(p.x()), mapy(p.y()));
}
int View::mapx(int x) const