Skip to content

Commit 2b52e17

Browse files
roehlingwjwwood
authored andcommitted
Correctly scale the render panel on high resolution displays (#1078)
1 parent 3f1b388 commit 2b52e17

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/rviz/ogre_helpers/render_system.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ int checkBadDrawable( Display* display, XErrorEvent* error )
342342
}
343343
#endif // Q_WS_X11
344344

345-
Ogre::RenderWindow* RenderSystem::makeRenderWindow( intptr_t window_id, unsigned int width, unsigned int height )
345+
Ogre::RenderWindow* RenderSystem::makeRenderWindow( intptr_t window_id, unsigned int width, unsigned int height, double pixel_ratio )
346346
{
347347
static int windowCounter = 0; // Every RenderWindow needs a unique name, oy.
348348

@@ -372,6 +372,7 @@ Ogre::RenderWindow* RenderSystem::makeRenderWindow( intptr_t window_id, unsigned
372372
#else
373373
params["macAPI"] = "carbon";
374374
#endif
375+
params["contentScalingFactor"] = std::to_string(pixel_ratio);
375376

376377
std::ostringstream stream;
377378
stream << "OgreWindow(" << windowCounter++ << ")";

src/rviz/ogre_helpers/render_system.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RenderSystem
4646
public:
4747
static RenderSystem* get();
4848

49-
Ogre::RenderWindow* makeRenderWindow( intptr_t window_id, unsigned int width, unsigned int height );
49+
Ogre::RenderWindow* makeRenderWindow( intptr_t window_id, unsigned int width, unsigned int height, double pixel_ratio = 1.0 );
5050

5151
Ogre::Root* root() { return ogre_root_; }
5252

src/rviz/ogre_helpers/render_widget.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#include <QPaintEvent>
3939
#include <QShowEvent>
4040
#include <QVBoxLayout>
41+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
42+
#include <QWindow>
43+
#endif
4144

4245
namespace rviz
4346
{
@@ -83,8 +86,12 @@ RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent )
8386

8487
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
8588
QApplication::syncX();
89+
double pixel_ratio = 1.0;
90+
#else
91+
QWindow* window = windowHandle();
92+
double pixel_ratio = window ? window->devicePixelRatio() : 1.0;
8693
#endif
87-
render_window_ = render_system_->makeRenderWindow( win_id, width(), height() );
94+
render_window_ = render_system_->makeRenderWindow( win_id, width(), height(), pixel_ratio );
8895
}
8996

9097
RenderWidget::~RenderWidget()

src/rviz/visualization_manager.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include <QCursor>
3434
#include <QPixmap>
3535
#include <QTimer>
36+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
37+
#include <QWindow>
38+
#endif
3639

3740
#include <boost/bind.hpp>
3841

@@ -149,7 +152,7 @@ VisualizationManager::VisualizationManager( RenderPanel* render_panel, WindowMan
149152
display_property_tree_model_ = new PropertyTreeModel( root_display_group_ );
150153
display_property_tree_model_->setDragDropClass( "display" );
151154
connect( display_property_tree_model_, SIGNAL( configChanged() ), this, SIGNAL( configChanged() ));
152-
155+
153156
tool_manager_ = new ToolManager( this );
154157
connect( tool_manager_, SIGNAL( configChanged() ), this, SIGNAL( configChanged() ));
155158
connect( tool_manager_, SIGNAL( toolChanged( Tool* ) ), this, SLOT( onToolChanged( Tool* ) ));
@@ -524,6 +527,17 @@ void VisualizationManager::handleMouseEvent( const ViewportMouseEvent& vme )
524527
if( current_tool )
525528
{
526529
ViewportMouseEvent _vme = vme;
530+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
531+
QWindow* window = vme.panel->windowHandle();
532+
if (window)
533+
{
534+
double pixel_ratio = window->devicePixelRatio();
535+
_vme.x = static_cast<int>(pixel_ratio * _vme.x);
536+
_vme.y = static_cast<int>(pixel_ratio * _vme.y);
537+
_vme.last_x = static_cast<int>(pixel_ratio * _vme.last_x);
538+
_vme.last_y = static_cast<int>(pixel_ratio * _vme.last_y);
539+
}
540+
#endif
527541
flags = current_tool->processMouseEvent( _vme );
528542
vme.panel->setCursor( current_tool->getCursor() );
529543
}

0 commit comments

Comments
 (0)