Skip to content

Commit

Permalink
Zinc widget: reworked the way we handle a change in the device pixel …
Browse files Browse the repository at this point in the history
…ratio.

Don't use a timer after all... since we now have a call to `resizeEvent()` rather than a couple to `resize()`.
  • Loading branch information
agarny committed Aug 21, 2020
1 parent d58a684 commit 95eb294
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
27 changes: 7 additions & 20 deletions src/plugins/widget/ZincWidget/src/zincwidget.cpp
Expand Up @@ -70,14 +70,6 @@ ZincWidget::ZincWidget(QWidget *pParent) :
Core::CommonWidget(this),
mZincWidgetSceneViewerCallback(this)
{
// Create and start a timer to check our device pixel ratio

mTimer = new QTimer(this);

connect(mTimer, &QTimer::timeout,
this, &ZincWidget::checkDevicePixelRatio);

mTimer->start(1000);
}

//==============================================================================
Expand Down Expand Up @@ -127,7 +119,7 @@ void ZincWidget::setContext(const OpenCMISS::Zinc::Context &pContext)

mSceneViewer.setProjectionMode(OpenCMISS::Zinc::Sceneviewer::PROJECTION_MODE_PERSPECTIVE);

doCheckDevicePixelRatio(true);
checkDevicePixelRatio(true);

// Further customise our scene viewer

Expand Down Expand Up @@ -333,7 +325,7 @@ double ZincWidget::fps() const

//==============================================================================

void ZincWidget::doCheckDevicePixelRatio(bool pForceSettingViewportSize)
void ZincWidget::checkDevicePixelRatio(bool pForceSettingViewportSize)
{
// Check our device pixel ratio

Expand Down Expand Up @@ -367,15 +359,6 @@ void ZincWidget::doCheckDevicePixelRatio(bool pForceSettingViewportSize)

//==============================================================================

void ZincWidget::checkDevicePixelRatio()
{
// Check our device pixel ratio

doCheckDevicePixelRatio();
}

//==============================================================================

void ZincWidget::initializeGL()
{
// Start our FPS clock
Expand All @@ -396,6 +379,10 @@ void ZincWidget::initializeGL()

void ZincWidget::paintGL()
{
// Make sure that we are using the correct device pixel ratio

checkDevicePixelRatio();

// Have our scene viewer render its scene

mSceneViewer.renderScene();
Expand Down Expand Up @@ -424,7 +411,7 @@ void ZincWidget::resizeGL(int pWidth, int pHeight)
// Update the viewport size of our scene viewer by forcing our device pixel
// ratio to be checked

doCheckDevicePixelRatio(true);
checkDevicePixelRatio(true);
}

//==============================================================================
Expand Down
8 changes: 1 addition & 7 deletions src/plugins/widget/ZincWidget/src/zincwidget.h
Expand Up @@ -43,7 +43,6 @@ along with this program. If not, see <https://gnu.org/licenses>.
//==============================================================================

class QMenu;
class QTimer;

//==============================================================================

Expand Down Expand Up @@ -135,8 +134,6 @@ class ZINCWIDGET_EXPORT ZincWidget : public QOpenGLWidget,
QSize sizeHint() const override;

private:
QTimer *mTimer;

int mDevicePixelRatio = -1;

OpenCMISS::Zinc::Context mContext;
Expand All @@ -155,15 +152,12 @@ class ZINCWIDGET_EXPORT ZincWidget : public QOpenGLWidget,
OpenCMISS::Zinc::Sceneviewerinput::ButtonType buttonMap(const Qt::MouseButton &pButton) const;
OpenCMISS::Zinc::Sceneviewerinput::ModifierFlags modifierMap(const Qt::KeyboardModifiers &pModifiers) const;

void doCheckDevicePixelRatio(bool pForceSettingViewportSize = false);
void checkDevicePixelRatio(bool pForceSettingViewportSize = false);

signals:
void contextAboutToBeDestroyed();
void graphicsInitialized();
void devicePixelRatioChanged(int pDevicePixelRatio);

private slots:
void checkDevicePixelRatio();
};

//==============================================================================
Expand Down

0 comments on commit 95eb294

Please sign in to comment.