From d4fbad4d2931aa45308270eb995567314390e334 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 16 Jan 2019 06:20:17 +0100 Subject: pose-widget: enable hidpi --- pose-widget/pose-widget.cpp | 13 +++++-------- pose-widget/pose-widget.hpp | 15 ++++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index 9a097340..ff65d43a 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -24,14 +24,11 @@ using namespace pose_widget_impl; -pose_transform::pose_transform(QWidget* dst) : - dst(dst), - front(QImage{":/images/side1.png"}.convertToFormat(QImage::Format_ARGB32)), - back(QImage{":/images/side6.png"}.convertToFormat(QImage::Format_ARGB32)), - image(w, h, QImage::Format_ARGB32), - image2(w, h, QImage::Format_ARGB32), - fresh(false) +pose_transform::pose_transform(QWidget* dst, double dpr) : dst(dst) { + for (QImage* img : { &image, &image2, &front, &back }) + img->setDevicePixelRatio(dpr); + image.fill(Qt::transparent); image2.fill(Qt::transparent); } @@ -79,7 +76,7 @@ end: } } -pose_widget::pose_widget(QWidget* parent) : QWidget(parent), xform(this) +pose_widget::pose_widget(QWidget* parent) : QWidget(parent), xform{this, devicePixelRatioF()} { rotate_sync(0,0,0, 0,0,0); } diff --git a/pose-widget/pose-widget.hpp b/pose-widget/pose-widget.hpp index 87367b96..aa51957e 100644 --- a/pose-widget/pose-widget.hpp +++ b/pose-widget/pose-widget.hpp @@ -47,7 +47,7 @@ public: struct pose_transform final : QThread { - pose_transform(QWidget* dst); + pose_transform(QWidget* dst, double device_pixel_ratio); ~pose_transform() override; void rotate_async(double xAngle, double yAngle, double zAngle, double x, double y, double z); @@ -63,8 +63,7 @@ struct pose_transform final : QThread void project_quad_texture(); std::pair get_bounds(const vec2& size); - template - inline void with_image_lock(F&& fun); + template inline void with_image_lock(F&& fun); rmat rotation, rotation_; vec3 translation, translation_; @@ -73,8 +72,10 @@ struct pose_transform final : QThread QWidget* dst; - QImage front, back; - QImage image, image2; + QImage front{QImage{":/images/side1.png"}.convertToFormat(QImage::Format_ARGB32)}; + QImage back{QImage{":/images/side6.png"}.convertToFormat(QImage::Format_ARGB32)}; + QImage image{w, h, QImage::Format_ARGB32}; + QImage image2{w, h, QImage::Format_ARGB32}; struct uv_ // NOLINT(cppcoreguidelines-pro-type-member-init) { @@ -83,7 +84,7 @@ struct pose_transform final : QThread }; std::vector uv_vec; - std::atomic fresh; + std::atomic fresh{false}; static constexpr int w = 320, h = 240; }; @@ -103,4 +104,4 @@ private: } -using pose_widget_impl::pose_widget; +using pose_widget = pose_widget_impl::pose_widget; -- cgit v1.2.3