changeset 313:1517c76cd678

* Make View getStartFrame etc non-virtual for easier inlining * Make getStartFrame use getFrameForX instead of vice versa
author Chris Cannam
date Tue, 16 Oct 2007 15:13:41 +0000
parents 6de6f78b13a1
children 7b96a3261e1c
files view/View.cpp view/View.h
diffstat 2 files changed, 10 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/view/View.cpp	Wed Oct 10 15:18:02 2007 +0000
+++ b/view/View.cpp	Tue Oct 16 15:13:41 2007 +0000
@@ -287,16 +287,7 @@
 long
 View::getStartFrame() const
 {
-    size_t w2 = (width() / 2) * m_zoomLevel;
-    size_t frame = m_centreFrame;
-    if (frame >= w2) {
-	frame -= w2;
-	return (frame / m_zoomLevel * m_zoomLevel);
-    } else {
-	frame = w2 - frame;
-	frame = frame / m_zoomLevel * m_zoomLevel;
-	return -(long)frame - m_zoomLevel;
-    }
+    return getFrameForX(0);
 }
 
 size_t
@@ -349,7 +340,10 @@
 long
 View::getFrameForX(int x) const
 {
-    return (long(x) * long(m_zoomLevel)) + getStartFrame();
+    long z = (long)m_zoomLevel;
+    long frame = m_centreFrame - (width()/2) * z;
+    frame = (frame / z) * z; // this is start frame
+    return frame + x * z;
 }
 
 float
--- a/view/View.h	Wed Oct 10 15:18:02 2007 +0000
+++ b/view/View.h	Tue Oct 16 15:13:41 2007 +0000
@@ -61,13 +61,13 @@
      * This is a calculated value based on the centre-frame, widget
      * width and zoom level.  The result may be negative.
      */
-    virtual long getStartFrame() const;
+    long getStartFrame() const;
 
     /**
      * Set the widget pan based on the given first visible frame.  The
      * frame value may be negative.
      */
-    virtual void setStartFrame(long);
+    void setStartFrame(long);
 
     /**
      * Return the centre frame of the visible widget.  This is an
@@ -75,19 +75,19 @@
      * frame values (start, end) are calculated from this based on the
      * zoom and other factors.
      */
-    virtual size_t getCentreFrame() const { return m_centreFrame; }
+    size_t getCentreFrame() const { return m_centreFrame; }
 
     /**
      * Set the centre frame of the visible widget.
      */
-    virtual void setCentreFrame(size_t f) { setCentreFrame(f, true); }
+    void setCentreFrame(size_t f) { setCentreFrame(f, true); }
 
     /**
      * Retrieve the last visible sample frame on the widget.
      * This is a calculated value based on the centre-frame, widget
      * width and zoom level.
      */
-    virtual size_t getEndFrame() const;
+    size_t getEndFrame() const;
 
     /**
      * Return the pixel x-coordinate corresponding to a given sample