]> sigrok.org Git - pulseview.git/commitdiff
Moved viewport from int64_ts to doubles, and added basic mouse zooming
authorJoel Holdsworth <redacted>
Wed, 20 Jun 2012 21:35:05 +0000 (22:35 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:05 +0000 (13:59 +0100)
logicsignal.cpp
logicsignal.h
signal.h
signaldata.cpp
signaldata.h
sigview.cpp
sigview.h

index 584be441acfad737330ea0ac87d1bda99b7ab029..5377287362065aed52da22a35b0a867cd9bd9542 100644 (file)
@@ -43,12 +43,13 @@ LogicSignal::LogicSignal(QString name, shared_ptr<LogicData> data,
 }
 
 void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
-       uint64_t scale, int64_t offset)
+       double scale, double offset)
 {
        Point2F *vertex;
 
        vector< pair<int64_t, bool> > edges;
 
+       assert(scale > 0);
        assert(_data);
 
        const queue< shared_ptr<LogicDataSnapshot> > &snapshots =
@@ -58,12 +59,15 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
 
        const shared_ptr<LogicDataSnapshot> &snapshot = snapshots.front();
 
-       const uint64_t samplerate = _data->get_samplerate();
-       const int64_t start_time = _data->get_start_time();
-       const float samples_per_pixel = samplerate * scale / 1e15f;
-       const int64_t start = samplerate * (offset - start_time) /
-               1000000000000000ULL;
-       const int64_t end = start + samples_per_pixel * rect.width();
+       const double pixels_offset = offset / scale;
+       const double samplerate = _data->get_samplerate();
+       const double start_time = _data->get_start_time();
+       const int64_t last_sample = (int64_t)snapshot->get_sample_count() - 1;
+       const double samples_per_pixel = samplerate * scale;
+       const int64_t start = min(max((int64_t)(samplerate * (offset - start_time)),
+               (int64_t)0), last_sample);
+       const int64_t end = min((int64_t)(start + samples_per_pixel * rect.width()),
+               last_sample);
        const int64_t quantization_length = 1LL << (int64_t)floorf(
                max(logf(samples_per_pixel / Log2), 0.0f));
 
@@ -78,7 +82,7 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
        for(vector<LogicDataSnapshot::EdgePair>::const_iterator i = edges.begin() + 1;
            i != edges.end() - 1; i++)
        {
-               const int x = (int)((*i).first / samples_per_pixel) +
+               const int x = (int)((*i).first / samples_per_pixel - pixels_offset) +
                        rect.left();
 
                vertex->x = x, vertex->y = 10 + rect.top() - 1;
@@ -101,12 +105,12 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
        {
                const int y = ((*i).second ? 10 : 40) + rect.top();
 
-               vertex->x = (int)((*i).first / samples_per_pixel) +
+               vertex->x = (int)((*i).first / samples_per_pixel - pixels_offset) +
                        rect.left() - 1;
                vertex->y = y;
                vertex++;
 
-               vertex->x = (int)((*(i+1)).first / samples_per_pixel) +
+               vertex->x = (int)((*(i+1)).first / samples_per_pixel - pixels_offset) +
                        rect.left();
                vertex->y = y;
                vertex++;
index 324d072cc92e2bc90f274fe434e82616d4fa1b07..3f8f913db75f23297a3ddfb3803b58ed0688fd19 100644 (file)
@@ -41,12 +41,12 @@ public:
         * Paints the signal into a QGLWidget.
         * @param widget the QGLWidget to paint into.
         * @param rect the rectangular area to draw the trace into.
-        * @param scale the scale in femtoseconds per pixel.
+        * @param scale the scale in seconds per pixel.
         * @param offset the time to show at the left hand edge of
-        *   the view in femtoseconds.
+        *   the view in seconds.
         **/
-       void paint(QGLWidget &widget, const QRect &rect, uint64_t scale,
-               int64_t offset);
+       void paint(QGLWidget &widget, const QRect &rect, double scale,
+               double offset);
 
 private:
        static void paint_lines(Point2F *points, int count);
index d55f6dbed429d4624a6bc22a011d43bed4c808f3..ac23a3fa214a81255855934d13cb2f64430e9b07 100644 (file)
--- a/signal.h
+++ b/signal.h
@@ -40,12 +40,12 @@ public:
         * Paints the signal into a QGLWidget.
         * @param widget the QGLWidget to paint into.
         * @param rect the rectangular area to draw the trace into.
-        * @param scale the scale in femtoseconds per pixel.
+        * @param scale the scale in seconds per pixel.
         * @param offset the time to show at the left hand edge of
-        *   the view in femtoseconds.
+        *   the view in seconds.
         **/
        virtual void paint(QGLWidget &widget, const QRect &rect,
-               uint64_t scale, int64_t offset) = 0;
+               double scale, double offset) = 0;
 
 protected:
        QString _name;
index 0ddb34a7387d178d3a2ad8a6a578914ac2a997a9..be44deea943c710e0b31679102b28a621939e1ee 100644 (file)
 
 using namespace std;
 
-SignalData::SignalData(uint64_t samplerate) :
+SignalData::SignalData(double samplerate) :
        _samplerate(samplerate),
        _start_time(0)
 {
 }
 
-uint64_t SignalData::get_samplerate() const
+double SignalData::get_samplerate() const
 {
        return _samplerate;
 }
 
-int64_t SignalData::get_start_time() const
+double SignalData::get_start_time() const
 {
        return _start_time;
 }
\ No newline at end of file
index 67ff29605f1ea9031457aaa9bcd50b502ed886e6..463d4fa6c117adc22ea7d9f9cc097707102cad25 100644 (file)
 class SignalData
 {
 public:
-       SignalData(uint64_t samplerate);
+       SignalData(double samplerate);
 
 public:
-       uint64_t get_samplerate() const;
-       int64_t get_start_time() const;
+       double get_samplerate() const;
+       double get_start_time() const;
 
 protected:
-       const uint64_t _samplerate;
-       const int64_t _start_time;
+       const double _samplerate;
+       const double _start_time;
 };
index df1eefec2745fec15041766a4777d086d6e114eb..4097ae5c25fe1f316b4cd9359dbe44b79bd8a8cf 100644 (file)
@@ -35,7 +35,7 @@ const int SigView::SignalHeight = 50;
 SigView::SigView(SigSession &session, QWidget *parent) :
        QGLWidget(parent),
         _session(session),
-       _scale(1000000000ULL),
+       _scale(1e-6),
        _offset(0)
 {
        connect(&_session, SIGNAL(dataUpdated()),
@@ -98,17 +98,21 @@ void SigView::mouseReleaseEvent(QMouseEvent *event)
 {
        assert(event);
 
+       const double cursor_offset = _offset + _scale * (double)event->x();
+
        switch(event->button())
        {
        case Qt::LeftButton:
-               _scale = (_scale * 2) / 3;
+               _scale *= 2.0 / 3.0;
                break;
 
        case Qt::RightButton:
-               _scale = (_scale * 3) / 2;
+               _scale *= 3.0 / 2.0;
                break;
        }
 
+       _offset = cursor_offset - _scale * (double)event->x();
+
        updateGL();
 }
 
index ccbc8c84eb78d8e944bff478b00cfdcc68fc55e4..c4ddc15b527cbd294b1d6d0f413f5cabd684e521 100644 (file)
--- a/sigview.h
+++ b/sigview.h
@@ -55,8 +55,8 @@ private slots:
 private:
        SigSession &_session;
 
-       uint64_t _scale;
-       int64_t _offset;
+       double _scale;
+       double _offset;
 };
 
 #endif // SIGVIEW_H