Viewport scaling and display density independence
The view is scaled to be as large as possible, without changing the aspect, within the bounds of the window. On "retina" displays, or other displays where window units != pixels, the view should no longer draw incorrectly.
This commit is contained in:
parent
c8d933a142
commit
221a9b023d
7 changed files with 89 additions and 4 deletions
|
@ -2,6 +2,12 @@
|
|||
#include <QKeyEvent>
|
||||
#include <QApplication>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
// Required for screen DPI information
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
#endif
|
||||
|
||||
#include "common/common.h"
|
||||
#include "bootmanager.hxx"
|
||||
|
||||
|
@ -176,6 +182,24 @@ void GRenderWindow::PollEvents() {
|
|||
*/
|
||||
}
|
||||
|
||||
// On Qt 5.1+, this correctly gets the size of the framebuffer (pixels).
|
||||
//
|
||||
// Older versions get the window size (density independent pixels),
|
||||
// and hence, do not support DPI scaling ("retina" displays).
|
||||
// The result will be a viewport that is smaller than the extent of the window.
|
||||
void GRenderWindow::GetFramebufferSize(int* fbWidth, int* fbHeight)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
||||
int pixelRatio = child->QPaintDevice::devicePixelRatio();
|
||||
|
||||
*fbWidth = child->QPaintDevice::width() * pixelRatio;
|
||||
*fbHeight = child->QPaintDevice::height() * pixelRatio;
|
||||
#else
|
||||
*fbWidth = child->QPaintDevice::width();
|
||||
*fbHeight = child->QPaintDevice::height();
|
||||
#endif
|
||||
}
|
||||
|
||||
void GRenderWindow::BackupGeometry()
|
||||
{
|
||||
geometry = ((QGLWidget*)this)->saveGeometry();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue