Mercurial > hg > svgui
changeset 1326:97c68bffbda6 zoom
More ZoomLevel updates
author | Chris Cannam |
---|---|
date | Thu, 20 Sep 2018 10:45:24 +0100 |
parents | bc2cb82050a0 |
children | 646e713a4632 |
files | layer/TimeRulerLayer.cpp view/Overview.cpp view/Overview.h view/Pane.cpp view/Pane.h view/View.cpp view/ViewProxy.h |
diffstat | 7 files changed, 67 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/TimeRulerLayer.cpp Wed Sep 19 15:42:22 2018 +0100 +++ b/layer/TimeRulerLayer.cpp Thu Sep 20 10:45:24 2018 +0100 @@ -230,7 +230,7 @@ int minPixelSpacing = 50; sv_frame_t incFrame = lrint((incms * sampleRate) / 1000); - int incX = int(round(v->getZoomLevel().framesToPixels(incFrame))); + int incX = int(round(v->getZoomLevel().framesToPixels(double(incFrame)))); int ticks = 10; if (incX < minPixelSpacing * 2) { ticks = quarter ? 4 : 5;
--- a/view/Overview.cpp Wed Sep 19 15:42:22 2018 +0100 +++ b/view/Overview.cpp Thu Sep 20 10:45:24 2018 +0100 @@ -124,7 +124,7 @@ } void -Overview::viewZoomLevelChanged(View *v, int, bool) +Overview::viewZoomLevelChanged(View *v, ZoomLevel, bool) { if (v == this) return; if (m_views.find(v) != m_views.end()) { @@ -190,7 +190,9 @@ emit zoomLevelChanged(m_zoomLevel, m_followZoom); } - sv_frame_t centreFrame = startFrame + m_zoomLevel * (width() / 2); + sv_frame_t centreFrame = startFrame + + sv_frame_t(round(m_zoomLevel.pixelsToFrames(width()/2))); + if (centreFrame > (startFrame + getModelsEndFrame())/2) { centreFrame = (startFrame + getModelsEndFrame())/2; } @@ -311,7 +313,7 @@ if (!m_clickedInRange) return; int xoff = int(e->x()) - int(m_clickPos.x()); - sv_frame_t frameOff = xoff * m_zoomLevel; + sv_frame_t frameOff = sv_frame_t(round(m_zoomLevel.pixelsToFrames(xoff))); sv_frame_t newCentreFrame = m_dragCentreFrame; if (frameOff > 0) { @@ -328,7 +330,8 @@ } if (std::max(m_centreFrame, newCentreFrame) - - std::min(m_centreFrame, newCentreFrame) > m_zoomLevel) { + std::min(m_centreFrame, newCentreFrame) > + m_zoomLevel.pixelsToFrames(1)) { sv_frame_t rf = alignToReference(newCentreFrame); #ifdef DEBUG_OVERVIEW cerr << "Overview::mouseMoveEvent: x " << e->x() << " and click x " << m_clickPos.x() << " -> frame " << newCentreFrame << " -> rf " << rf << endl;
--- a/view/Overview.h Wed Sep 19 15:42:22 2018 +0100 +++ b/view/Overview.h Thu Sep 20 10:45:24 2018 +0100 @@ -46,7 +46,7 @@ virtual void globalCentreFrameChanged(sv_frame_t); virtual void viewCentreFrameChanged(View *, sv_frame_t); - virtual void viewZoomLevelChanged(View *, int, bool); + virtual void viewZoomLevelChanged(View *, ZoomLevel, bool); virtual void viewManagerPlaybackFrameChanged(sv_frame_t); virtual void setBoxColour(QColor);
--- a/view/Pane.cpp Wed Sep 19 15:42:22 2018 +0100 +++ b/view/Pane.cpp Thu Sep 20 10:45:24 2018 +0100 @@ -201,7 +201,7 @@ int count = 0; int current = 0; - int level = 1; + ZoomLevel level; //!!! pull out into function (presumably in View) bool haveConstraint = false; @@ -215,18 +215,21 @@ if (haveConstraint) { while (true) { + //!!! this won't terminate if level is in the PixelsPerFrame zone if (getZoomLevel() == level) current = count; - int newLevel = getZoomConstraintBlockSize(level + 1, - ZoomConstraint::RoundUp); + ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(), + ZoomConstraint::RoundUp); if (newLevel == level) break; level = newLevel; if (++count == 50) break; } } else { // if we have no particular constraints, we can really spread out + //!!! this is nonsense in PixelsPerFrame zone while (true) { + using namespace std::rel_ops; if (getZoomLevel() >= level) current = count; - int step = level / 10; + int step = level.level / 10; int pwr = 0; while (step > 0) { ++pwr; @@ -238,12 +241,13 @@ --pwr; } // cerr << level << endl; - level += step; - if (++count == 100 || level > 262144) break; + level.level += step; + if (++count == 100 || level.level > 262144) break; } } -// cerr << "Have " << count << " zoom levels" << endl; + //!!! + SVCERR << "Have " << count << " zoom levels" << endl; m_hthumb->setMinimumValue(0); m_hthumb->setMaximumValue(count); @@ -1145,8 +1149,8 @@ QImage * Pane::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1) { - int x0 = int(f0 / getZoomLevel()); - int x1 = int(f1 / getZoomLevel()); + int x0 = int(round(getZoomLevel().framesToPixels(double(f0)))); + int x1 = int(round(getZoomLevel().framesToPixels(double(f1)))); QImage *image = new QImage(x1 - x0 + m_scaleWidth, height(), QImage::Format_RGB32); @@ -1881,9 +1885,9 @@ int x1 = r.x() + r.width(); int y1 = r.y() + r.height(); - int w = x1 - x0; - sv_frame_t newStartFrame = getFrameForX(x0); + sv_frame_t newEndFrame = getFrameForX(x1); + sv_frame_t dist = newEndFrame - newStartFrame; sv_frame_t visibleFrames = getEndFrame() - getStartFrame(); if (newStartFrame <= -visibleFrames) { @@ -1893,14 +1897,9 @@ if (newStartFrame >= getModelsEndFrame()) { newStartFrame = getModelsEndFrame() - 1; } - - double ratio = double(w) / double(width()); -// cerr << "ratio: " << ratio << endl; - int newZoomLevel = (int)nearbyint(m_zoomLevel * ratio); - if (newZoomLevel < 1) newZoomLevel = 1; - -// cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl; - setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); + + ZoomLevel newZoomLevel = ZoomLevel::fromRatio(width(), dist); + setZoomLevel(getZoomConstraintLevel(newZoomLevel)); setStartFrame(newStartFrame); QString unit; @@ -2379,21 +2378,18 @@ } } else { + using namespace std::rel_ops; // Zoom in or out - int newZoomLevel = m_zoomLevel; + ZoomLevel newZoomLevel = m_zoomLevel; if (sign > 0) { - if (newZoomLevel <= 2) { - newZoomLevel = 1; - } else { - newZoomLevel = getZoomConstraintBlockSize - (newZoomLevel - 1, ZoomConstraint::RoundDown); - } - } else { // sign < 0 - newZoomLevel = getZoomConstraintBlockSize - (newZoomLevel + 1, ZoomConstraint::RoundUp); + newZoomLevel = getZoomConstraintLevel(newZoomLevel.decremented(), + ZoomConstraint::RoundDown); + } else { + newZoomLevel = getZoomConstraintLevel(newZoomLevel.incremented(), + ZoomConstraint::RoundUp); } if (newZoomLevel != m_zoomLevel) { @@ -2422,9 +2418,11 @@ // Scroll left or right by a fixed number of pixels if (getStartFrame() < 0 && - getEndFrame() >= getModelsEndFrame()) return; - - int delta = (pixels * m_zoomLevel); + getEndFrame() >= getModelsEndFrame()) { + return; + } + + int delta = int(round(m_zoomLevel.pixelsToFrames(pixels))); if (m_centreFrame < delta) { setCentreFrame(0); @@ -2443,8 +2441,7 @@ //!!! dupe with updateHeadsUpDisplay int count = 0; - int level = 1; - + ZoomLevel level; //!!! pull out into function (presumably in View) bool haveConstraint = false; @@ -2458,17 +2455,19 @@ if (haveConstraint) { while (true) { + //!!! this won't terminate if level is in the PixelsPerFrame zone if (m_hthumb->getMaximumValue() - value == count) break; - int newLevel = getZoomConstraintBlockSize(level + 1, - ZoomConstraint::RoundUp); + ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(), + ZoomConstraint::RoundUp); if (newLevel == level) break; level = newLevel; if (++count == 50) break; } } else { + //!!! this is nonsense in PixelsPerFrame zone while (true) { if (m_hthumb->getMaximumValue() - value == count) break; - int step = level / 10; + int step = level.level / 10; int pwr = 0; while (step > 0) { ++pwr; @@ -2480,8 +2479,8 @@ --pwr; } // cerr << level << endl; - level += step; - if (++count == 100 || level > 262144) break; + level.level += step; + if (++count == 100 || level.level > 262144) break; } } @@ -2747,7 +2746,7 @@ } void -Pane::viewZoomLevelChanged(View *v, int z, bool locked) +Pane::viewZoomLevelChanged(View *v, ZoomLevel z, bool locked) { // cerr << "Pane[" << this << "]::zoomLevelChanged (global now " // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << endl;
--- a/view/Pane.h Wed Sep 19 15:42:22 2018 +0100 +++ b/view/Pane.h Thu Sep 20 10:45:24 2018 +0100 @@ -87,7 +87,7 @@ // view slots virtual void toolModeChanged() override; virtual void zoomWheelsEnabledChanged() override; - virtual void viewZoomLevelChanged(View *v, int z, bool locked) override; + virtual void viewZoomLevelChanged(View *, ZoomLevel, bool locked) override; virtual void modelAlignmentCompletionChanged() override; // local slots, not overrides
--- a/view/View.cpp Wed Sep 19 15:42:22 2018 +0100 +++ b/view/View.cpp Thu Sep 20 10:45:24 2018 +0100 @@ -54,7 +54,7 @@ QFrame(w), m_id(getNextId()), m_centreFrame(0), - m_zoomLevel(1024), + m_zoomLevel(ZoomLevel::FramesPerPixel, 1024), m_followPan(true), m_followZoom(true), m_followPlay(PlaybackScrollPageWithCentre), @@ -64,7 +64,7 @@ m_cache(0), m_buffer(0), m_cacheCentreFrame(0), - m_cacheZoomLevel(1024), + m_cacheZoomLevel(ZoomLevel::FramesPerPixel, 1024), m_selectionCached(false), m_deleting(false), m_haveSelectedLayer(false), @@ -319,7 +319,8 @@ void View::setStartFrame(sv_frame_t f) { - setCentreFrame(f + m_zoomLevel * (width() / 2)); + setCentreFrame(f + sv_frame_t(round + (m_zoomLevel.pixelsToFrames(width() / 2)))); } bool
--- a/view/ViewProxy.h Wed Sep 19 15:42:22 2018 +0100 +++ b/view/ViewProxy.h Thu Sep 20 10:45:24 2018 +0100 @@ -75,12 +75,20 @@ bool &log) const { return m_view->getValueExtents(unit, min, max, log); } - virtual int getZoomLevel() const { - int z = m_view->getZoomLevel(); -// cerr << "getZoomLevel: from " << z << " to "; - z = z / m_scaleFactor; -// cerr << z << endl; - if (z < 1) z = 1; + virtual ZoomLevel getZoomLevel() const { + ZoomLevel z = m_view->getZoomLevel(); + //!!! + cerr << "getZoomLevel: from " << z << " to "; + if (z.zone == ZoomLevel::FramesPerPixel) { + z.level /= m_scaleFactor; + if (z.level < 1) { + z.level = 1; + } + } else { + //!!!??? + z.level *= m_scaleFactor; + } + cerr << z << endl; return z; } virtual QRect getPaintRect() const {