diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp index 0168255..b842061 100644 --- a/toonz/sources/toonz/sceneviewer.cpp +++ b/toonz/sources/toonz/sceneviewer.cpp @@ -297,7 +297,7 @@ void invalidateIcons() { s.m_paintIndex = mask & ToonzCheck::ePaint ? tc->getColorIndex() : -1; IconGenerator::instance()->setSettings(s); - // Force icons to refresh + // Force icons to refresh TXshLevel *sl = TApp::instance()->getCurrentLevel()->getLevel(); if (sl) { std::vector fids; @@ -2026,7 +2026,7 @@ double SceneViewer::projectToZ(const TPointD &delta) { GLint viewport[4]; double modelview[16], projection[16]; glGetIntegerv(GL_VIEWPORT, viewport); - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) projection[i] = (double)m_projectionMatrix.constData()[i]; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); @@ -2188,9 +2188,8 @@ void SceneViewer::zoomQt(bool forward, bool reset) { if (reset || ((m_zoomScale3D < 500 || !forward) && (m_zoomScale3D > 0.01 || forward))) { double oldZoomScale = m_zoomScale3D; - m_zoomScale3D = - reset ? 1 - : ImageUtils::getQuantizedZoomFactor(m_zoomScale3D, forward); + m_zoomScale3D = reset ? 1 : ImageUtils::getQuantizedZoomFactor( + m_zoomScale3D, forward); m_pan3D = -(m_zoomScale3D / oldZoomScale) * -m_pan3D; } @@ -2211,18 +2210,17 @@ void SceneViewer::zoomQt(bool forward, bool reset) { int i; for (i = 0; i < 2; i++) { - TAffine &viewAff = m_viewAff[i]; + TAffine &viewAff = m_viewAff[i]; if (m_isFlippedX) viewAff = viewAff * TScale(-1, 1); if (m_isFlippedX) viewAff = viewAff * TScale(1, -1); - double scale2 = std::abs(viewAff.det()); + double scale2 = std::abs(viewAff.det()); if (m_isFlippedX) viewAff = viewAff * TScale(-1, 1); if (m_isFlippedX) viewAff = viewAff * TScale(1, -1); if (reset || ((scale2 < 100000 || !forward) && (scale2 > 0.001 * 0.05 || forward))) { double oldZoomScale = sqrt(scale2) * dpiFactor; - double zoomScale = - reset ? 1 - : ImageUtils::getQuantizedZoomFactor(oldZoomScale, forward); + double zoomScale = reset ? 1 : ImageUtils::getQuantizedZoomFactor( + oldZoomScale, forward); // threshold value -0.001 is intended to absorb the error of calculation if ((oldZoomScale - zoomScaleFittingWithScreen) * @@ -2384,7 +2382,7 @@ void SceneViewer::zoomQt(const QPoint ¢er, double factor) { } else { // viewAff = TScale(factor) * viewAff; setViewMatrix(TScale(factor) * viewAff, i); - } + } } } } @@ -2525,9 +2523,9 @@ void SceneViewer::fitToCamera() { TPointD P11 = cameraAff * cameraRect.getP11(); TPointD p0 = TPointD(std::min({P00.x, P01.x, P10.x, P11.x}), std::min({P00.y, P01.y, P10.y, P11.y})); - TPointD p1 = TPointD(std::max({P00.x, P01.x, P10.x, P11.x}), + TPointD p1 = TPointD(std::max({P00.x, P01.x, P10.x, P11.x}), std::max({P00.y, P01.y, P10.y, P11.y})); - cameraRect = TRectD(p0.x, p0.y, p1.x, p1.y); + cameraRect = TRectD(p0.x, p0.y, p1.x, p1.y); // Pan if (!is3DView()) { @@ -2552,6 +2550,47 @@ void SceneViewer::fitToCamera() { //----------------------------------------------------------------------------- +void SceneViewer::fitToCameraOutline() { + TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); + int frame = TApp::instance()->getCurrentFrame()->getFrame(); + TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId(); + TStageObject *camera = xsh->getStageObject(cameraId); + TAffine cameraPlacement = camera->getPlacement(frame); + double cameraZ = camera->getZ(frame); + TAffine cameraAff = + getViewMatrix() * cameraPlacement * TScale((1000 + cameraZ) / 1000); + + QRect viewRect = rect(); + TRectD cameraRect = ViewerDraw::getCameraRect(); + TPointD P00 = cameraAff * cameraRect.getP00(); + TPointD P10 = cameraAff * cameraRect.getP10(); + TPointD P01 = cameraAff * cameraRect.getP01(); + TPointD P11 = cameraAff * cameraRect.getP11(); + TPointD p0 = TPointD(std::min({P00.x, P01.x, P10.x, P11.x}), + std::min({P00.y, P01.y, P10.y, P11.y})); + TPointD p1 = TPointD(std::max({P00.x, P01.x, P10.x, P11.x}), + std::max({P00.y, P01.y, P10.y, P11.y})); + cameraRect = TRectD(p0.x, p0.y, p1.x, p1.y); + + // Pan + if (!is3DView()) { + TPointD cameraCenter = (cameraRect.getP00() + cameraRect.getP11()) * 0.5; + panQt(QPoint(-cameraCenter.x, cameraCenter.y)); + } + + double xratio = (double)viewRect.width() / cameraRect.getLx(); + double yratio = (double)viewRect.height() / cameraRect.getLy(); + double ratio = std::min(xratio, yratio); + if (ratio == 0.0) return; + + // Scale and center on the center of \a rect. + QPoint c = viewRect.center(); + zoom(TPointD(c.x(), c.y()), ratio); + zoom(TPointD(c.x(), c.y()), 0.95); +} + +//----------------------------------------------------------------------------- + void SceneViewer::resetSceneViewer() { m_visualSettings.m_sceneProperties = TApp::instance()->getCurrentScene()->getScene()->getProperties(); @@ -2568,6 +2607,7 @@ void SceneViewer::resetSceneViewer() { m_phi3D = 30; m_isFlippedX = false; m_isFlippedY = false; + fitToCameraOutline(); emit onZoomChanged(); emit onFlipHChanged(m_isFlippedX); emit onFlipVChanged(m_isFlippedY); @@ -2580,8 +2620,8 @@ void SceneViewer::resetZoom() { TPointD realCenter(m_viewAff[m_viewMode].a13, m_viewAff[m_viewMode].a23); TAffine aff = getNormalZoomScale() * TRotation(realCenter, m_rotationAngle[m_viewMode]); - aff.a13 = realCenter.x; - aff.a23 = realCenter.y; + aff.a13 = realCenter.x; + aff.a23 = realCenter.y; if (m_isFlippedX) aff = aff * TScale(-1, 1); if (m_isFlippedY) aff = aff * TScale(1, -1); setViewMatrix(aff, m_viewMode); @@ -2638,17 +2678,16 @@ void SceneViewer::setActualPixelSize() { } else dpi = sl->getDpi(fid); - const double inch = Stage::inch; - TAffine tempAff = getNormalZoomScale(); - if (m_isFlippedX) tempAff = tempAff * TScale(-1, 1); - if (m_isFlippedY) tempAff = tempAff * TScale(1, -1); - TPointD tempScale = dpi; + const double inch = Stage::inch; + TAffine tempAff = getNormalZoomScale(); + if (m_isFlippedX) tempAff = tempAff * TScale(-1, 1); + if (m_isFlippedY) tempAff = tempAff * TScale(1, -1); + TPointD tempScale = dpi; if (m_isFlippedX) tempScale.x = -tempScale.x; if (m_isFlippedY) tempScale.y = -tempScale.y; for (int i = 0; i < m_viewAff.size(); ++i) - setViewMatrix(dpi == TPointD(0, 0) - ? tempAff - : TScale(tempScale.x / inch, tempScale.y / inch), + setViewMatrix(dpi == TPointD(0, 0) ? tempAff : TScale(tempScale.x / inch, + tempScale.y / inch), i); m_pos = QPoint(0, 0); @@ -2931,7 +2970,7 @@ void drawSpline(const TAffine &viewMatrix, const TRect &clipRect, bool camera3d, TStageObject *pegbar = objId != TStageObjectId::NoneId ? xsh->getStageObject(objId) : 0; - const TStroke *stroke = 0; + const TStroke *stroke = 0; if (pegbar && pegbar->getSpline()) stroke = pegbar->getSpline()->getStroke(); if (!stroke) return; diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h index 7d5eeca..819fc83 100644 --- a/toonz/sources/toonz/sceneviewer.h +++ b/toonz/sources/toonz/sceneviewer.h @@ -431,6 +431,7 @@ public slots: void onButtonPressed(FlipConsole::EGadget button); void fitToCamera(); + void fitToCameraOutline(); void swapCompared(); void regeneratePreviewFrame(); void regeneratePreview();