Skip to content

Correctly scale the render panel on high resolution displays #1078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/rviz/ogre_helpers/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ int checkBadDrawable( Display* display, XErrorEvent* error )
}
#endif // Q_WS_X11

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

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

std::ostringstream stream;
stream << "OgreWindow(" << windowCounter++ << ")";
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/ogre_helpers/render_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RenderSystem
public:
static RenderSystem* get();

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

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

Expand Down
9 changes: 8 additions & 1 deletion src/rviz/ogre_helpers/render_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include <QPaintEvent>
#include <QShowEvent>
#include <QVBoxLayout>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QWindow>
#endif

namespace rviz
{
Expand Down Expand Up @@ -83,8 +86,12 @@ RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent )

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QApplication::syncX();
double pixel_ratio = 1.0;
#else
QWindow* window = windowHandle();
double pixel_ratio = window ? window->devicePixelRatio() : 1.0;
#endif
render_window_ = render_system_->makeRenderWindow( win_id, width(), height() );
render_window_ = render_system_->makeRenderWindow( win_id, width(), height(), pixel_ratio );
}

RenderWidget::~RenderWidget()
Expand Down
16 changes: 15 additions & 1 deletion src/rviz/visualization_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <QCursor>
#include <QPixmap>
#include <QTimer>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QWindow>
#endif

#include <boost/bind.hpp>

Expand Down Expand Up @@ -149,7 +152,7 @@ VisualizationManager::VisualizationManager( RenderPanel* render_panel, WindowMan
display_property_tree_model_ = new PropertyTreeModel( root_display_group_ );
display_property_tree_model_->setDragDropClass( "display" );
connect( display_property_tree_model_, SIGNAL( configChanged() ), this, SIGNAL( configChanged() ));

tool_manager_ = new ToolManager( this );
connect( tool_manager_, SIGNAL( configChanged() ), this, SIGNAL( configChanged() ));
connect( tool_manager_, SIGNAL( toolChanged( Tool* ) ), this, SLOT( onToolChanged( Tool* ) ));
Expand Down Expand Up @@ -524,6 +527,17 @@ void VisualizationManager::handleMouseEvent( const ViewportMouseEvent& vme )
if( current_tool )
{
ViewportMouseEvent _vme = vme;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QWindow* window = vme.panel->windowHandle();
if (window)
{
double pixel_ratio = window->devicePixelRatio();
_vme.x = static_cast<int>(pixel_ratio * _vme.x);
_vme.y = static_cast<int>(pixel_ratio * _vme.y);
_vme.last_x = static_cast<int>(pixel_ratio * _vme.last_x);
_vme.last_y = static_cast<int>(pixel_ratio * _vme.last_y);
}
#endif
flags = current_tool->processMouseEvent( _vme );
vme.panel->setCursor( current_tool->getCursor() );
}
Expand Down