From 1fbdc97128a394ca59444af695cbf8502efa53f8 Mon Sep 17 00:00:00 2001 From: shun_iwasawa Date: May 18 2017 10:45:18 +0000 Subject: fix viewer gadgets --- diff --git a/toonz/sources/include/tools/toolutils.h b/toonz/sources/include/tools/toolutils.h index d196f86..c17fad7 100644 --- a/toonz/sources/include/tools/toolutils.h +++ b/toonz/sources/include/tools/toolutils.h @@ -128,7 +128,7 @@ void drawBalloon( std::string text, // balloon text const TPixel32 &color, // ballon background color (text is black) TPoint delta, // text position (pixels; pos is the origin; y grows upward) - bool isPicking = false, + double pixelSize, bool isPicking = false, std::vector *otherBalloons = 0); // avoid other balloons positions; add the new ballons positions diff --git a/toonz/sources/tnztools/edittool.cpp b/toonz/sources/tnztools/edittool.cpp index 1f5749c..38dd0cb 100644 --- a/toonz/sources/tnztools/edittool.cpp +++ b/toonz/sources/tnztools/edittool.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include //============================================================================= // Scale Constraints @@ -290,12 +292,13 @@ class DragSplinePositionTool final : public DragChannelTool { double m_tolerance; public: - DragSplinePositionTool(const TStroke *spline, bool globalKeyframesEnabled) + DragSplinePositionTool(const TStroke *spline, bool globalKeyframesEnabled, + double pixelSize) : DragChannelTool(TStageObject::T_Path, globalKeyframesEnabled) , m_spline(spline) , m_offset(0.0) , m_splineLength(0) - , m_tolerance(0) {} + , m_tolerance(pixelSize * 10.0) {} double getLengthAtPos(const TPointD &pos) const { assert(m_spline); @@ -322,7 +325,6 @@ else return 0.0; m_firstPos = pos; start(); assert(m_spline); - m_tolerance = sqrt(tglGetPixelSize2()) * 10; m_splineLength = m_spline->getLength(); m_lengthAtCPs.clear(); int n = m_spline->getControlPointCount(); @@ -929,8 +931,8 @@ void EditTool::leftButtonDown(const TPointD &ppos, const TMouseEvent &e) { case Translation: if (const TStroke *spline = getSpline()) - m_dragTool = - new DragSplinePositionTool(spline, m_globalKeyframes.getValue()); + m_dragTool = new DragSplinePositionTool( + spline, m_globalKeyframes.getValue(), getPixelSize()); else m_dragTool = new DragPositionTool(m_lockPositionX.getValue(), m_lockPositionY.getValue(), @@ -1157,7 +1159,7 @@ void EditTool::draw() { return; } - double unit = sqrt(tglGetPixelSize2()); + double unit = getPixelSize(); /*-- ObjectのCenter位置を取得 --*/ glPushMatrix(); diff --git a/toonz/sources/tnztools/edittoolgadgets.cpp b/toonz/sources/tnztools/edittoolgadgets.cpp index b3a545c..1effcb5 100644 --- a/toonz/sources/tnztools/edittoolgadgets.cpp +++ b/toonz/sources/tnztools/edittoolgadgets.cpp @@ -19,10 +19,20 @@ #include "historytypes.h" +#include +#include + using namespace EditToolGadgets; GLdouble FxGadget::m_selectedColor[3] = {0.2, 0.8, 0.1}; +namespace { +int getDevPixRatio() { + static int devPixRatio = QApplication::desktop()->devicePixelRatio(); + return devPixRatio; +} +} + //************************************************************************************* // FxGadgetUndo definition //************************************************************************************* @@ -172,13 +182,15 @@ void FxGadget::setValue(const TPointParamP ¶m, const TPointD &pos) { //--------------------------------------------------------------------------- -void FxGadget::setPixelSize() { setPixelSize(sqrt(tglGetPixelSize2())); } +void FxGadget::setPixelSize() { + setPixelSize(sqrt(tglGetPixelSize2()) * getDevPixRatio()); +} //--------------------------------------------------------------------------- void FxGadget::drawTooltip(const TPointD &tooltipPos, std::string tooltipPosText) { - double unit = sqrt(tglGetPixelSize2()); + double unit = sqrt(tglGetPixelSize2()) * getDevPixRatio(); glPushMatrix(); glTranslated(tooltipPos.x, tooltipPos.y, 0.0); double sc = unit * 1.6; @@ -482,7 +494,7 @@ void AngleFxGadget::draw(bool picking) { else glColor3d(0, 0, 1); glPushName(getId()); - double pixelSize = sqrt(tglGetPixelSize2()); + double pixelSize = sqrt(tglGetPixelSize2()) * getDevPixRatio(); double r = pixelSize * 40; double a = pixelSize * 10, b = pixelSize * 5; tglDrawCircle(m_pos, r); diff --git a/toonz/sources/tnztools/skeletontool.cpp b/toonz/sources/tnztools/skeletontool.cpp index 3f425c9..43949a7 100644 --- a/toonz/sources/tnztools/skeletontool.cpp +++ b/toonz/sources/tnztools/skeletontool.cpp @@ -1096,8 +1096,8 @@ qDebug(" color = TPixel32(200, 200, 10, 200); else if (code == m_device) color = TPixel32(185, 255, 255); - ToolUtils::drawBalloon(pos, hook.m_name, color, TPoint(20, 20), isPicking(), - &balloons); + ToolUtils::drawBalloon(pos, hook.m_name, color, TPoint(20, 20), + getPixelSize(), isPicking(), &balloons); glPopName(); } @@ -1202,7 +1202,8 @@ glPopMatrix(); 255 * (191 - ialfa) / alfa, alfa); ToolUtils::drawBalloon(otherColumnsHooks[j].m_pos, otherColumnsHooks[j].m_name, // getHandle(), - color, TPoint(20, 20), false, &balloons); + color, TPoint(20, 20), getPixelSize(), false, + &balloons); HookData baseHook = currentColumnHooks[0]; baseHook.m_pos = otherColumnsHooks[j].m_pos; @@ -1228,7 +1229,7 @@ glPopMatrix(); TPixel32 color(100, 255, 100, 100); if (code == m_device) color = TPixel32(185, 255, 255); ToolUtils::drawBalloon(magicLink.m_h0.m_pos, name, color, TPoint(20, -20), - isPicking(), &balloons); + getPixelSize(), isPicking(), &balloons); glPopName(); } } @@ -1416,7 +1417,7 @@ void SkeletonTool::draw() { if (m_label != "") ToolUtils::drawBalloon(m_labelPos, m_label, TPixel32::Red, TPoint(20, -20), - false); + getPixelSize(), false); bool ikEnabled = m_mode.getValue() == INVERSE_KINEMATICS; assert(glGetError() == GL_NO_ERROR); diff --git a/toonz/sources/tnztools/toolutils.cpp b/toonz/sources/tnztools/toolutils.cpp index 3717d96..f77ed0d 100644 --- a/toonz/sources/tnztools/toolutils.cpp +++ b/toonz/sources/tnztools/toolutils.cpp @@ -1479,10 +1479,12 @@ const double ToolUtils::ConeSubVolume::m_values[] = { //--------------------------------------------------------------------------------------------- void ToolUtils::drawBalloon(const TPointD &pos, std::string text, - const TPixel32 &color, TPoint delta, bool isPicking, + const TPixel32 &color, TPoint delta, + double pixelSize, bool isPicking, std::vector *otherBalloons) { QString qText = QString::fromStdString(text); - QFont font("Arial", 10); // ,QFont::Bold); + QFont font("Arial"); // ,QFont::Bold); + font.setPixelSize(13); QFontMetrics fm(font); QRect textRect = fm.boundingRect(qText); @@ -1491,7 +1493,6 @@ void ToolUtils::drawBalloon(const TPointD &pos, std::string text, // avoid other balloons if (otherBalloons) { - double pixelSize = sqrt(tglGetPixelSize2()); std::vector &balloons = *otherBalloons; int n = (int)balloons.size(); TDimensionD balloonSize(pixelSize * (textRect.width() + mrg * 2), @@ -1517,7 +1518,6 @@ void ToolUtils::drawBalloon(const TPointD &pos, std::string text, int y0 = textRect.top() - mrg; int y1 = textRect.bottom() + mrg; - double pixelSize = sqrt(tglGetPixelSize2()); if (isPicking) { TTool::Viewer *viewer = TTool::getApplication()->getCurrentTool()->getTool()->getViewer(); diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp index 714d804..9016ac6 100644 --- a/toonz/sources/toonz/sceneviewer.cpp +++ b/toonz/sources/toonz/sceneviewer.cpp @@ -1254,7 +1254,7 @@ void SceneViewer::drawOverlay() { else { glPushMatrix(); tglMultMatrix(m_drawCameraAff); - m_pixelSize = sqrt(tglGetPixelSize2()); + m_pixelSize = sqrt(tglGetPixelSize2()) * getDevPixRatio(); ViewerDraw::drawCamera(f, m_pixelSize); glPopMatrix(); } @@ -1352,7 +1352,7 @@ void SceneViewer::drawOverlay() { if (tool->getToolType() & TTool::LevelTool && !app->getCurrentObject()->isSpline()) glScaled(m_dpiScale.x, m_dpiScale.y, 1); - m_pixelSize = sqrt(tglGetPixelSize2()); + m_pixelSize = sqrt(tglGetPixelSize2()) * getDevPixRatio(); tool->draw(); glPopMatrix(); // Used (only in the T_RGBPicker tool) to notify and set the currentColor