From: Joel Holdsworth Date: Mon, 24 Nov 2014 19:28:34 +0000 (+0000) Subject: RowItemPaintParams: Bundled scale and offset X-Git-Tag: pulseview-0.3.0~400 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=4c8a6a6d03e2a12f67d910a83589072b478114cb RowItemPaintParams: Bundled scale and offset --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 325ab6bd..5d838506 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -100,14 +100,6 @@ void AnalogSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) const int y = get_visual_y(); - const View *const view = owner_->view(); - assert(view); - - const double scale = view->scale(); - assert(scale > 0); - - const double offset = view->offset(); - if (!channel_->enabled()) return; @@ -119,12 +111,12 @@ void AnalogSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) const shared_ptr &snapshot = snapshots.front(); - const double pixels_offset = offset / scale; + const double pixels_offset = pp.pixels_offset(); const double samplerate = data_->samplerate(); const double start_time = data_->get_start_time(); const int64_t last_sample = snapshot->get_sample_count() - 1; - const double samples_per_pixel = samplerate * scale; - const double start = samplerate * (offset - start_time); + const double samples_per_pixel = samplerate * pp.scale(); + const double start = samplerate * (pp.offset() - start_time); const double end = start + samples_per_pixel * pp.width(); const int64_t start_sample = min(max((int64_t)floor(start), diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 1ee99cb9..3acf1b5c 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -153,8 +153,6 @@ void LogicSignal::paint_back(QPainter &p, const RowItemPaintParams &pp) void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) { - using pv::view::View; - QLineF *line; vector< pair > edges; @@ -165,14 +163,6 @@ void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) const int y = get_visual_y(); - const View *const view = owner_->view(); - assert(view); - - const double scale = view->scale(); - assert(scale > 0); - - const double offset = view->offset(); - if (!channel_->enabled()) return; @@ -193,11 +183,11 @@ void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) if (samplerate == 0.0) samplerate = 1.0; - const double pixels_offset = offset / scale; + const double pixels_offset = pp.pixels_offset(); const double start_time = data_->get_start_time(); const int64_t last_sample = snapshot->get_sample_count() - 1; - const double samples_per_pixel = samplerate * scale; - const double start = samplerate * (offset - start_time); + const double samples_per_pixel = samplerate * pp.scale(); + const double start = samplerate * (pp.offset() - start_time); const double end = start + samples_per_pixel * pp.width(); snapshot->get_subsampled_edges(edges, diff --git a/pv/view/rowitempaintparams.cpp b/pv/view/rowitempaintparams.cpp index 013c2a23..af5f675a 100644 --- a/pv/view/rowitempaintparams.cpp +++ b/pv/view/rowitempaintparams.cpp @@ -25,10 +25,14 @@ namespace pv { namespace view { -RowItemPaintParams::RowItemPaintParams(int left, int right) : +RowItemPaintParams::RowItemPaintParams( + int left, int right, double scale, double offset) : left_(left), - right_(right) { + right_(right), + scale_(scale), + offset_(offset) { assert(left <= right); + assert(scale > 0.0); } } // namespace view diff --git a/pv/view/rowitempaintparams.hpp b/pv/view/rowitempaintparams.hpp index 062b3cdd..5c71edcb 100644 --- a/pv/view/rowitempaintparams.hpp +++ b/pv/view/rowitempaintparams.hpp @@ -27,7 +27,7 @@ namespace view { class RowItemPaintParams { public: - RowItemPaintParams(int left, int right); + RowItemPaintParams(int left, int right, double scale, double offset); int left() const { return left_; @@ -37,13 +37,27 @@ public: return right_; } + double scale() const { + return scale_; + } + + double offset() const { + return offset_; + } + int width() const { return right_ - left_; } + double pixels_offset() const { + return offset_ / scale_; + } + private: int left_; int right_; + double scale_; + double offset_; }; } // namespace view diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index bc010b4b..f5f0ab59 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -70,7 +70,7 @@ void Viewport::paintEvent(QPaintEvent*) if (view_.cursors_shown()) view_.cursors().draw_viewport_background(p, rect()); - const RowItemPaintParams pp(0, width()); + const RowItemPaintParams pp(0, width(), view_.scale(), view_.offset()); // Plot the signal for (const shared_ptr r : row_items)