From: Joel Holdsworth Date: Wed, 20 Jun 2012 21:35:05 +0000 (+0100) Subject: Moved viewport from int64_ts to doubles, and added basic mouse zooming X-Git-Tag: pulseview-0.1.0~341 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fb0d32cb540e2ae39d80f7eab02779fb965d9f46;p=pulseview.git Moved viewport from int64_ts to doubles, and added basic mouse zooming --- diff --git a/logicsignal.cpp b/logicsignal.cpp index 584be441..53772873 100644 --- a/logicsignal.cpp +++ b/logicsignal.cpp @@ -43,12 +43,13 @@ LogicSignal::LogicSignal(QString name, shared_ptr data, } void LogicSignal::paint(QGLWidget &widget, const QRect &rect, - uint64_t scale, int64_t offset) + double scale, double offset) { Point2F *vertex; vector< pair > edges; + assert(scale > 0); assert(_data); const queue< shared_ptr > &snapshots = @@ -58,12 +59,15 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect, const shared_ptr &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::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++; diff --git a/logicsignal.h b/logicsignal.h index 324d072c..3f8f913d 100644 --- a/logicsignal.h +++ b/logicsignal.h @@ -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); diff --git a/signal.h b/signal.h index d55f6dbe..ac23a3fa 100644 --- 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; diff --git a/signaldata.cpp b/signaldata.cpp index 0ddb34a7..be44deea 100644 --- a/signaldata.cpp +++ b/signaldata.cpp @@ -22,18 +22,18 @@ 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 diff --git a/signaldata.h b/signaldata.h index 67ff2960..463d4fa6 100644 --- a/signaldata.h +++ b/signaldata.h @@ -23,13 +23,13 @@ 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; }; diff --git a/sigview.cpp b/sigview.cpp index df1eefec..4097ae5c 100644 --- a/sigview.cpp +++ b/sigview.cpp @@ -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(); } diff --git a/sigview.h b/sigview.h index ccbc8c84..c4ddc15b 100644 --- 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