Skip to content

Commit

Permalink
The flux viewer now properly supports partial redraws.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Jan 29, 2025
1 parent 9177ac4 commit 3e808c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/gui2/fluxview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ class FluxViewImpl : public FluxView

painter.setBrush(Qt::NoBrush);

for (int pixel = startPos / _nanosecondsPerPixel;
pixel < t.gradient.size();
pixel++)
int start = std::max(0, (int)(startPos / _nanosecondsPerPixel));
int end = std::min(
(int)t.gradient.size(), (int)(endPos / _nanosecondsPerPixel));

for (int pixel = start; pixel < end; pixel++)
{
int c = t.gradient[pixel] * 255;
painter.setPen(QPen(QColor(0, c, c), 1.5));
Expand Down
9 changes: 7 additions & 2 deletions src/gui2/fluxvisualiserwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FluxVisualiserWidgetImpl : public FluxVisualiserWidget
_numTracks = 0;
_totalDuration = 0;
_fluxView = FluxView::create();
_fluxView->setScale(_nanosecondsPerPixel);
repaint();
}

Expand Down Expand Up @@ -95,14 +96,18 @@ class FluxVisualiserWidgetImpl : public FluxVisualiserWidget
painter.setRenderHint(QPainter::Antialiasing);
_viewNavigator->transform(painter);

QRectF world =
painter.worldTransform().inverted().mapRect(QRectF(event->rect()));
nanoseconds_t left = world.left() * _nanosecondsPerPixel;
nanoseconds_t right = world.right() * _nanosecondsPerPixel;
painter.setPen(palette().color(QPalette::Text));
painter.setBrush(Qt::NoBrush);

for (int i = 0; i < _numTracks; i++)
{
painter.save();
painter.translate(HBORDER, VBORDER + VSCALE_TRACK_SIZE * i);
_fluxView->redraw(painter, 0, 100, i);
painter.translate(0, VSCALE_TRACK_SIZE * i);
_fluxView->redraw(painter, left, right, i);
painter.restore();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui2/viewnavigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class ViewNavigator : public QObject
static std::unique_ptr<ViewNavigator> create(QWidget* obj);

public:
virtual void transform(QPainter& painter) = 0;
virtual void transform(QPainter& painter) = 0;
};

0 comments on commit 3e808c6

Please sign in to comment.