Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

high-dpi monitor compatibility

shun_iwasawaf8d7517edfee
diff --git a/ci-scripts/linux/travis-build.sh b/ci-scripts/linux/travis-build.sh
index d183a91ee..94f2166ef 100644
--- a/ci-scripts/linux/travis-build.sh
+++ b/ci-scripts/linux/travis-build.sh
@@ -3,7 +3,7 @@ pushd thirdparty/tiff-4.0.3
CFLAGS="-fPIC" CXXFLAGS="-fPIC" ./configure --disable-jbig && make
popd
cd toonz && mkdir build && cd build
-source /opt/qt55/bin/qt55-env.sh
+source /opt/qt56/bin/qt56-env.sh
cmake ../sources \
-DWITH_SYSTEM_SUPERLU:BOOL=OFF
# according to https://docs.travis-ci.com/user/ci-environment/#Virtualization-environments
diff --git a/ci-scripts/linux/travis-install.sh b/ci-scripts/linux/travis-install.sh
index b25bf7f24..91035d150 100644
--- a/ci-scripts/linux/travis-install.sh
+++ b/ci-scripts/linux/travis-install.sh
@@ -1,6 +1,6 @@
-sudo add-apt-repository --yes ppa:beineri/opt-qt551-trusty
+sudo add-apt-repository --yes ppa:beineri/opt-qt562-trusty
sudo apt-get update
-sudo apt-get install -y liblzo2-dev liblz4-dev libfreetype6-dev libpng-dev libsdl2-dev libglew-dev freeglut3-dev qt55script libsuperlu3-dev libpng-dev qt55svg qt55tools qt55multimedia wget libusb-1.0-0-dev libboost-all-dev liblzma-dev
+sudo apt-get install -y liblzo2-dev liblz4-dev libfreetype6-dev libpng-dev libsdl2-dev libglew-dev freeglut3-dev qt56script libsuperlu3-dev libpng-dev qt56svg qt56tools qt56multimedia wget libusb-1.0-0-dev libboost-all-dev liblzma-dev
# someone forgot to include liblz4.pc with the package, use the version from xenial, as it only depends on libc
wget http://mirrors.kernel.org/ubuntu/pool/main/l/lz4/liblz4-1_0.0~r131-2ubuntu2_amd64.deb -O liblz4.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/l/lz4/liblz4-dev_0.0~r131-2ubuntu2_amd64.deb -O liblz4-dev.deb
diff --git a/ci-scripts/osx/travis-build.sh b/ci-scripts/osx/travis-build.sh
index cbe2a2317..a86714144 100644
--- a/ci-scripts/osx/travis-build.sh
+++ b/ci-scripts/osx/travis-build.sh
@@ -4,7 +4,7 @@ pushd thirdparty/tiff-4.0.3
popd
cd toonz && mkdir build && cd build
cmake ../sources \
- -DQT_PATH=/usr/local/Cellar/[email protected]/5.5.1_1/lib/ \
+ -DQT_PATH=/usr/local/Cellar/qt5/5.6.1-1/lib/ \
-DTIFF_INCLUDE_DIR=../../thirdparty/tiff-4.0.3/libtiff/ \
-DSUPERLU_INCLUDE_DIR=../../thirdparty/superlu/SuperLU_4.1/include/
make
diff --git a/ci-scripts/osx/travis-install.sh b/ci-scripts/osx/travis-install.sh
index 5a2358d13..1d99806dc 100644
--- a/ci-scripts/osx/travis-install.sh
+++ b/ci-scripts/osx/travis-install.sh
@@ -1,5 +1,8 @@
#!/bin/bash
brew update
-brew install qt55 glew lz4 lzo libusb
+brew install glew lz4 lzo libusb
brew tap tcr/tcr
brew install clang-format
+# revert to the previous version of the formula to get qt5.6.1-1
+curl -O https://raw.githubusercontent.com/Homebrew/homebrew-core/fdfc724dd532345f5c6cdf47dc43e99654e6a5fd/Formula/qt5.rb
+brew install ./qt5.rb
diff --git a/doc/how_to_build_linux.md b/doc/how_to_build_linux.md
index 6212a2c31..1f6259e1f 100644
--- a/doc/how_to_build_linux.md
+++ b/doc/how_to_build_linux.md
@@ -6,7 +6,7 @@ Building OpenToonz from source requires the following dependencies:
- Git
- GCC or Clang
- CMake (3.4.1 or newer).
-- Qt5 (5.5 or newer)
+- Qt5 (5.6 or newer)
- Boost (1.55 or newer)
- SDL2
- LibPNG
diff --git a/toonz/sources/toonz/main.cpp b/toonz/sources/toonz/main.cpp
index 4b3967a54..adfb61981 100644
--- a/toonz/sources/toonz/main.cpp
+++ b/toonz/sources/toonz/main.cpp
@@ -263,6 +263,12 @@ int main(int argc, char *argv[]) {
}
}
+// Enables high-DPI scaling. This attribute must be set before QApplication is
+// constructed. Available from Qt 5.6.
+#if QT_VERSION >= 0x050600
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
+
QApplication a(argc, argv);
#ifdef MACOSX
diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
index 1b521a290..883cb7298 100644
--- a/toonz/sources/toonz/sceneviewer.cpp
+++ b/toonz/sources/toonz/sceneviewer.cpp
@@ -765,6 +765,7 @@ TPointD SceneViewer::winToWorld(const QPoint &pos) const {
} else
return TAffine() * TPointD(0, 0);
}
+
return getViewMatrix().inv() * pp;
}
@@ -2556,10 +2557,12 @@ void SceneViewer::invalidateToolStatus() {
*/
TRectD SceneViewer::getGeometry() const {
+ int devPixRatio = TApp::instance()->getDevPixRatio();
TTool *tool = TApp::instance()->getCurrentTool()->getTool();
- TPointD topLeft = tool->getMatrix().inv() * winToWorld(geometry().topLeft());
- TPointD bottomRight =
- tool->getMatrix().inv() * winToWorld(geometry().bottomRight());
+ TPointD topLeft =
+ tool->getMatrix().inv() * winToWorld(geometry().topLeft() * devPixRatio);
+ TPointD bottomRight = tool->getMatrix().inv() *
+ winToWorld(geometry().bottomRight() * devPixRatio);
TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
@@ -2578,3 +2581,14 @@ TRectD SceneViewer::getGeometry() const {
void SceneViewer::doDeleteSubCamera() {
PreviewSubCameraManager::instance()->deleteSubCamera(this);
}
+
+//-----------------------------------------------------------------------------
+/*! modify sizes for high DPI monitors
+*/
+int SceneViewer::width() const {
+ return QGLWidget::width() * TApp::instance()->getDevPixRatio();
+}
+
+int SceneViewer::height() const {
+ return QGLWidget::height() * TApp::instance()->getDevPixRatio();
+}
diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h
index 10276dc4b..2b19a18be 100644
--- a/toonz/sources/toonz/sceneviewer.h
+++ b/toonz/sources/toonz/sceneviewer.h
@@ -245,6 +245,10 @@ public:
TPoint worldToPos(const TPointD &worldPos) const override;
+ // modify sizes for high DPI monitors
+ int width() const;
+ int height() const;
+
protected:
// Paint vars
TAffine m_drawCameraAff;
diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp
index 9d7f76ec1..e233a777d 100644
--- a/toonz/sources/toonz/sceneviewerevents.cpp
+++ b/toonz/sources/toonz/sceneviewerevents.cpp
@@ -76,8 +76,9 @@ int modifiers = 0;
void initToonzEvent(TMouseEvent &toonzEvent, QMouseEvent *event,
int widgetHeight, double pressure, bool isTablet,
bool isClick) {
- toonzEvent.m_pos =
- TPoint(event->pos().x(), widgetHeight - 1 - event->pos().y());
+ int devPixRatio = TApp::instance()->getDevPixRatio();
+ toonzEvent.m_pos = TPoint(event->pos().x() * devPixRatio,
+ widgetHeight - 1 - event->pos().y() * devPixRatio);
toonzEvent.m_pressure = isTablet ? int(255 * pressure) : 255;
toonzEvent.setModifiers(event->modifiers() & Qt::ShiftModifier,
@@ -274,7 +275,7 @@ void SceneViewer::enterEvent(QEvent *) {
void SceneViewer::mouseMoveEvent(QMouseEvent *event) {
if (m_freezedStatus != NO_FREEZED) return;
- QPoint curPos = event->pos();
+ QPoint curPos = event->pos() * TApp::instance()->getDevPixRatio();
bool cursorSet = false;
m_lastMousePos = curPos;
@@ -417,7 +418,7 @@ void SceneViewer::mousePressEvent(QMouseEvent *event) {
if (m_mouseButton != Qt::NoButton) return;
- m_pos = event->pos();
+ m_pos = event->pos() * TApp::instance()->getDevPixRatio();
m_mouseButton = event->button();
// when using tablet, avoid unexpected drawing behavior occurs when
@@ -543,7 +544,8 @@ void SceneViewer::mouseReleaseEvent(QMouseEvent *event) {
TMouseEvent toonzEvent;
initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent,
false);
- TPointD pos = tool->getMatrix().inv() * winToWorld(event->pos());
+ TPointD pos = tool->getMatrix().inv() *
+ winToWorld(event->pos() * TApp::instance()->getDevPixRatio());
TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
@@ -620,8 +622,10 @@ void SceneViewer::wheelEvent(QWheelEvent *event) {
} else if (delta > 0) {
CommandManager::instance()->execute("MI_PrevDrawing");
}
- } else
- zoomQt(event->pos(), exp(0.001 * delta));
+ } else {
+ zoomQt(event->pos() * TApp::instance()->getDevPixRatio(),
+ exp(0.001 * delta));
+ }
}
event->accept();
}
@@ -1001,7 +1005,8 @@ void SceneViewer::mouseDoubleClickEvent(QMouseEvent *event) {
if (!tool || !tool->isEnabled()) return;
TMouseEvent toonzEvent;
initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, true);
- TPointD pos = tool->getMatrix().inv() * winToWorld(event->pos());
+ TPointD pos = tool->getMatrix().inv() *
+ winToWorld(event->pos() * TApp::instance()->getDevPixRatio());
TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
pos.x /= m_dpiScale.x;
@@ -1036,7 +1041,9 @@ void SceneViewer::contextMenuEvent(QContextMenuEvent *e) {
if (m_freezedStatus != NO_FREEZED) return;
if (m_isLocator) return;
- TPoint winPos(e->pos().x(), height() - e->pos().y());
+ int devPixRatio = TApp::instance()->getDevPixRatio();
+ TPoint winPos(e->pos().x() * devPixRatio,
+ height() - e->pos().y() * devPixRatio);
std::vector<int> columnIndices;
// enable to select all the columns regardless of the click position
for (int i = 0;
@@ -1047,8 +1054,8 @@ void SceneViewer::contextMenuEvent(QContextMenuEvent *e) {
SceneViewerContextMenu *menu = new SceneViewerContextMenu(this);
TTool *tool = TApp::instance()->getCurrentTool()->getTool();
- TPointD pos =
- ((tool) ? tool->getMatrix().inv() : TAffine()) * winToWorld(e->pos());
+ TPointD pos = ((tool) ? tool->getMatrix().inv() : TAffine()) *
+ winToWorld(e->pos() * devPixRatio);
menu->addEnterGroupCommands(pos);
menu->addLevelCommands(columnIndices);
diff --git a/toonz/sources/toonz/subcameramanager.cpp b/toonz/sources/toonz/subcameramanager.cpp
index c6a7b349c..5332188db 100644
--- a/toonz/sources/toonz/subcameramanager.cpp
+++ b/toonz/sources/toonz/subcameramanager.cpp
@@ -119,7 +119,7 @@ bool PreviewSubCameraManager::mousePressEvent(SceneViewer *viewer,
if (viewer->is3DView()) return true;
m_mousePressed = true;
- m_mousePressPos = event->pos();
+ m_mousePressPos = event->pos() * TApp::instance()->getDevPixRatio();
m_dragType = getSubCameraDragEnum(viewer, m_mousePressPos);
if (bitwiseExclude(m_dragType, OUTER))
@@ -133,8 +133,7 @@ bool PreviewSubCameraManager::mousePressEvent(SceneViewer *viewer,
bool PreviewSubCameraManager::mouseMoveEvent(SceneViewer *viewer,
QMouseEvent *event) {
if (viewer->is3DView()) return true;
-
- QPoint curPos(event->pos());
+ QPoint curPos(event->pos() * TApp::instance()->getDevPixRatio());
if (event->buttons() == Qt::LeftButton) {
if (!bitwiseContains(m_dragType, INNER)) {
if (abs(curPos.x() - m_mousePressPos.x()) > 10 ||
diff --git a/toonz/sources/toonz/tapp.cpp b/toonz/sources/toonz/tapp.cpp
index 014f8b0ab..61269aa66 100644
--- a/toonz/sources/toonz/tapp.cpp
+++ b/toonz/sources/toonz/tapp.cpp
@@ -57,6 +57,8 @@
#include <QDebug>
#include <QEvent>
#include <QCoreApplication>
+#include <QApplication>
+#include <QDesktopWidget>
//===================================================================
@@ -737,3 +739,10 @@ QString TApp::getCurrentRoomName() const {
return currentRoom->getName();
}
+
+//-----------------------------------------------------------------------------
+
+int TApp::getDevPixRatio() const {
+ static int devPixRatio = QApplication::desktop()->devicePixelRatio();
+ return devPixRatio;
+}
\ No newline at end of file
diff --git a/toonz/sources/toonz/tapp.h b/toonz/sources/toonz/tapp.h
index e057482f1..96e356d62 100644
--- a/toonz/sources/toonz/tapp.h
+++ b/toonz/sources/toonz/tapp.h
@@ -201,6 +201,11 @@ public:
void writeSettings();
+ // returns device-pixel ratio. It is 1 for normal monitors and 2 (or higher
+ // ratio) for high DPI monitors. Setting "Display > Set custom text size(DPI)"
+ // for Windows corresponds to this ratio.
+ int getDevPixRatio() const;
+
protected:
bool eventFilter(QObject *obj, QEvent *event) override;