diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-04-05 15:36:48 -0400 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-04-05 15:36:48 -0400 |
commit | 18faa5cc2c19a069ab6ff5a80c31e8bf9e16dcac (patch) | |
tree | 864a3b66af4feb757b8ac076bf16ed02d5546acb /src/widget/wdisplay.cpp | |
parent | fa128ebc7c1c7be0b0a3e927bf75d7e1c1debce3 (diff) |
Eliminate unnecessary widget renders from control changes.
Instead of re-rendering on every control change (via
WWidget::onConnectedControlChanged), check for changes in what we would render
first.
Updated: WDisplay, WKnob, WKnobComposed, WSliderComposed, WStatusLight
Left unchanged: WWaveformViewer, WPushButton, WOverview, WVuMeter
Diffstat (limited to 'src/widget/wdisplay.cpp')
-rw-r--r-- | src/widget/wdisplay.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index 81177b3d62..3942efa2e2 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -27,6 +27,7 @@ WDisplay::WDisplay(QWidget * parent) : WWidget(parent), + m_iCurrentPixmap(0), m_pPixmapBack(NULL), m_bDisabledLoaded(false) { setPositions(0); @@ -112,7 +113,7 @@ void WDisplay::setPixmap(QVector<PaintablePointer>* pPixmaps, int iPos, } } -int WDisplay::getActivePixmapIndex() const { +int WDisplay::getPixmapForParameter(double dParameter) const { // When there are an even number of pixmaps by convention we want a value of // 0.5 to align to the lower of the two middle pixmaps. In Mixxx < 1.12.0 we // accomplished this by the below formula: @@ -149,7 +150,16 @@ int WDisplay::getActivePixmapIndex() const { // Subtracting an epsilon prevents out of bound values at the end of the // range and biases the middle value towards the lower of the 2 center // pixmaps when there are an even number of pixmaps. - return static_cast<int>(getControlParameterDisplay() * numPixmaps() - 0.00001); + return static_cast<int>(dParameter * numPixmaps() - 0.00001); +} + +void WDisplay::onConnectedControlChanged(double dParameter, double dValue) { + Q_UNUSED(dValue); + int pixmap = getPixmapForParameter(dParameter); + if (pixmap != m_iCurrentPixmap) { + // paintEvent updates m_iCurrentPixmap. + update(); + } } void WDisplay::paintEvent(QPaintEvent* ) { @@ -171,7 +181,11 @@ void WDisplay::paintEvent(QPaintEvent* ) { return; } - int idx = getActivePixmapIndex(); + int idx = getPixmapForParameter(getControlParameterDisplay()); + + // onConnectedControlChanged uses this to detect no-ops but it does not + // clamp so don't clamp. + m_iCurrentPixmap = idx; // Clamp active pixmap index to valid ranges. if (idx < 0) { |