]> sigrok.org Git - pulseview.git/commitdiff
Initial interractive zoom support
authorJoel Holdsworth <redacted>
Sat, 16 Jun 2012 11:28:28 +0000 (12:28 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:04 +0000 (13:59 +0100)
logicsignal.cpp
signaldata.cpp
signaldata.h
sigview.cpp
sigview.h

index 1587bddd473002d4264d47abafd118d5c3c0cfd2..584be441acfad737330ea0ac87d1bda99b7ab029 100644 (file)
@@ -22,6 +22,8 @@
 #include <GL/gl.h>
 #include <GL/glext.h>
 
+#include <math.h>
+
 #include "logicdata.h"
 #include "logicdatasnapshot.h"
 #include "logicsignal.h"
@@ -29,6 +31,8 @@
 using namespace boost;
 using namespace std;
 
+const float Log2 = logf(2.0f);
+
 LogicSignal::LogicSignal(QString name, shared_ptr<LogicData> data,
        int probe_index) :
        Signal(name),
@@ -54,9 +58,14 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
 
        const shared_ptr<LogicDataSnapshot> &snapshot = snapshots.front();
 
-       const int64_t start = 0;
-       const int64_t end = 8000;
-       const int64_t quantization_length = 4;
+       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 int64_t quantization_length = 1LL << (int64_t)floorf(
+               max(logf(samples_per_pixel / Log2), 0.0f));
 
        snapshot->get_subsampled_edges(edges, start, end,
                quantization_length, _probe_index);
@@ -69,7 +78,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 = edge.first / quantization_length +
+               const int x = (int)((*i).first / samples_per_pixel) +
                        rect.left();
 
                vertex->x = x, vertex->y = 10 + rect.top() - 1;
@@ -92,12 +101,12 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
        {
                const int y = ((*i).second ? 10 : 40) + rect.top();
 
-               vertex->x = (*i).first / quantization_length +
+               vertex->x = (int)((*i).first / samples_per_pixel) +
                        rect.left() - 1;
                vertex->y = y;
                vertex++;
 
-               vertex->x = (*(i+1)).first / quantization_length +
+               vertex->x = (int)((*(i+1)).first / samples_per_pixel) +
                        rect.left();
                vertex->y = y;
                vertex++;
index fbc10133fc9ee5c88228086e3700a2a1e0d4daf6..0ddb34a7387d178d3a2ad8a6a578914ac2a997a9 100644 (file)
@@ -27,3 +27,13 @@ SignalData::SignalData(uint64_t samplerate) :
        _start_time(0)
 {
 }
+
+uint64_t SignalData::get_samplerate() const
+{
+       return _samplerate;
+}
+
+int64_t SignalData::get_start_time() const
+{
+       return _start_time;
+}
\ No newline at end of file
index 18c9b3d5767b6c4f4ecc303449602f6730e2cba1..67ff29605f1ea9031457aaa9bcd50b502ed886e6 100644 (file)
@@ -25,6 +25,10 @@ class SignalData
 public:
        SignalData(uint64_t samplerate);
 
+public:
+       uint64_t get_samplerate() const;
+       int64_t get_start_time() const;
+
 protected:
        const uint64_t _samplerate;
        const int64_t _start_time;
index 53fbdeaac148859251c7792ab726c40d6d174c4c..df1eefec2745fec15041766a4777d086d6e114eb 100644 (file)
@@ -23,6 +23,8 @@
 #include "sigsession.h"
 #include "signal.h"
 
+#include <QMouseEvent>
+
 #include <boost/foreach.hpp>
 
 using namespace boost;
@@ -82,3 +84,31 @@ void SigView::dataUpdated()
        update();
 }
 
+void SigView::mouseMoveEvent(QMouseEvent *event)
+{
+       assert(event);
+}
+
+void SigView::mousePressEvent(QMouseEvent *event)
+{
+       assert(event);
+}
+
+void SigView::mouseReleaseEvent(QMouseEvent *event)
+{
+       assert(event);
+
+       switch(event->button())
+       {
+       case Qt::LeftButton:
+               _scale = (_scale * 2) / 3;
+               break;
+
+       case Qt::RightButton:
+               _scale = (_scale * 3) / 2;
+               break;
+       }
+
+       updateGL();
+}
+
index 2c7ba1ddae34a97990fdf0b189be6d621676a939..ccbc8c84eb78d8e944bff478b00cfdcc68fc55e4 100644 (file)
--- a/sigview.h
+++ b/sigview.h
@@ -44,6 +44,11 @@ protected:
 
        void paintGL();
 
+private:
+       void mouseMoveEvent(QMouseEvent *event);
+       void mousePressEvent(QMouseEvent *event);
+       void mouseReleaseEvent(QMouseEvent *event);
+
 private slots:
        void dataUpdated();