diff --git a/toonz/sources/include/toonzqt/lutcalibrator.h b/toonz/sources/include/toonzqt/lutcalibrator.h index 986fcdf..951a57d 100644 --- a/toonz/sources/include/toonzqt/lutcalibrator.h +++ b/toonz/sources/include/toonzqt/lutcalibrator.h @@ -29,7 +29,8 @@ class QOpenGLContext; class QColor; class DVAPI LutCalibrator : public QOpenGLFunctions { - bool m_isValid = false; + bool m_isValid = false; + bool m_isInitialized = false; struct LutTextureShader { QOpenGLShader* vert = nullptr; @@ -58,6 +59,7 @@ public: void initialize(); bool isValid() { return m_isValid; } + bool isInitialized() { return m_isInitialized; } ~LutCalibrator() {} diff --git a/toonz/sources/include/toonzqt/styleeditor.h b/toonz/sources/include/toonzqt/styleeditor.h index 484bdad..1f53f58 100644 --- a/toonz/sources/include/toonzqt/styleeditor.h +++ b/toonz/sources/include/toonzqt/styleeditor.h @@ -152,6 +152,8 @@ class DVAPI HexagonalColorWheel final : public GLWidgetForHighDpi { QOpenGLFramebufferObject *m_fbo = NULL; LutCalibrator *m_lutCalibrator = NULL; + bool m_firstInitialized = true; + private: void drawCurrentColorMark(); void clickLeftWheel(const QPoint &pos); diff --git a/toonz/sources/toonz/imageviewer.cpp b/toonz/sources/toonz/imageviewer.cpp index 9a924e5..96d4f51 100644 --- a/toonz/sources/toonz/imageviewer.cpp +++ b/toonz/sources/toonz/imageviewer.cpp @@ -442,7 +442,7 @@ void ImageViewer::initializeGL() { initializeOpenGLFunctions(); // to be computed once through the software - if (m_lutCalibrator) { + if (m_lutCalibrator && !m_lutCalibrator->isInitialized()) { m_lutCalibrator->initialize(); connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(onContextAboutToBeDestroyed())); @@ -450,6 +450,13 @@ void ImageViewer::initializeGL() { // glClearColor(1.0,1.0,1.0,1); glClear(GL_COLOR_BUFFER_BIT); + + if (m_firstInitialized) + m_firstInitialized = false; + else { + resizeGL(width(), height()); + update(); + } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/imageviewer.h b/toonz/sources/toonz/imageviewer.h index ecdb095..757b741 100644 --- a/toonz/sources/toonz/imageviewer.h +++ b/toonz/sources/toonz/imageviewer.h @@ -71,7 +71,8 @@ class ImageViewer final : public GLWidgetForHighDpi { bool m_panning = false; double m_scaleFactor; // used for zoom gesture - bool m_stylusUsed = false; + bool m_stylusUsed = false; + bool m_firstInitialized = true; int getDragType(const TPoint &pos, const TRect &loadBox); void updateLoadbox(const TPoint &curPos); diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index e451ad2..523277f 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -1056,7 +1056,6 @@ void MainWindow::onCurrentRoomChanged(int newRoomIndex) { TPanel *pane = paneList.at(i); if (pane->isFloating() && !pane->isHidden()) { QRect oldGeometry = pane->geometry(); - // Just setting the new parent is not enough for the new layout manager. // Must be removed from the old and added to the new. oldRoom->removeDockWidget(pane); diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp index 3e50de4..2d27437 100644 --- a/toonz/sources/toonz/sceneviewer.cpp +++ b/toonz/sources/toonz/sceneviewer.cpp @@ -929,7 +929,7 @@ void SceneViewer::initializeGL() { registerContext(); // to be computed once through the software - if (m_lutCalibrator) { + if (m_lutCalibrator && !m_lutCalibrator->isInitialized()) { m_lutCalibrator->initialize(); connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(onContextAboutToBeDestroyed())); @@ -937,6 +937,13 @@ void SceneViewer::initializeGL() { // glClearColor(1.0,1.0,1.0,1); glClear(GL_COLOR_BUFFER_BIT); + + if (m_firstInitialized) + m_firstInitialized = false; + else { + resizeGL(width(), height()); + update(); + } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h index ec2ccb3..72f488d 100644 --- a/toonz/sources/toonz/sceneviewer.h +++ b/toonz/sources/toonz/sceneviewer.h @@ -181,6 +181,8 @@ class SceneViewer final : public GLWidgetForHighDpi, double m_rotationAngle[2]; + bool m_firstInitialized = true; + public: enum ReferenceMode { NORMAL_REFERENCE = 1, diff --git a/toonz/sources/toonzqt/lutcalibrator.cpp b/toonz/sources/toonzqt/lutcalibrator.cpp index fec60f8..acbc173 100644 --- a/toonz/sources/toonzqt/lutcalibrator.cpp +++ b/toonz/sources/toonzqt/lutcalibrator.cpp @@ -20,7 +20,7 @@ inline bool execWarning(const QString& s) { DVGui::MsgBox(DVGui::WARNING, s); return false; } -}; +}; // namespace #ifdef WIN32 @@ -161,13 +161,14 @@ QStringList getMonitorNames() { return nameList; } -}; +}; // namespace #endif //----------------------------------------------------------------------------- void LutCalibrator::initialize() { initializeOpenGLFunctions(); + m_isInitialized = true; if (!LutManager::instance()->isValid()) return; @@ -191,6 +192,7 @@ void LutCalibrator::initialize() { //----------------------------------------------------------------------------- void LutCalibrator::cleanup() { + m_isInitialized = false; if (!isValid()) return; // release shader if (m_shader.program) { @@ -213,6 +215,7 @@ void LutCalibrator::cleanup() { delete m_lutTex; m_lutTex = NULL; } + m_isValid = false; } //----------------------------------------------------------------------------- @@ -560,7 +563,7 @@ void LutManager::convert(float& r, float& g, float& b) { for (int bb = 0; bb < 2; bb++) { float* val = &m_lut.data[locals::getCoord( index[0][rr], index[1][gg], index[2][bb], m_lut.meshSize)]; - for (int chan = 0; chan < 3; chan++, val++) + for (int chan = 0; chan < 3; chan++, val++) vertex_color[rr][gg][bb][chan] = *val; } float result[3]; diff --git a/toonz/sources/toonzqt/styleeditor.cpp b/toonz/sources/toonzqt/styleeditor.cpp index 00c0944..2791965 100644 --- a/toonz/sources/toonzqt/styleeditor.cpp +++ b/toonz/sources/toonzqt/styleeditor.cpp @@ -577,7 +577,7 @@ void HexagonalColorWheel::initializeGL() { initializeOpenGLFunctions(); // to be computed once through the software - if (m_lutCalibrator) { + if (m_lutCalibrator && !m_lutCalibrator->isInitialized()) { m_lutCalibrator->initialize(); connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(onContextAboutToBeDestroyed())); @@ -585,6 +585,15 @@ void HexagonalColorWheel::initializeGL() { QColor const color = getBGColor(); glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + + // Without the following lines, the wheel in a floating style editor + // dissapears on switching the room due to context switching. + if (m_firstInitialized) + m_firstInitialized = false; + else { + resizeGL(width(), height()); + update(); + } } //----------------------------------------------------------------------------- @@ -813,7 +822,7 @@ void HexagonalColorWheel::mouseReleaseEvent(QMouseEvent *event) { //----------------------------------------------------------------------------- /*! compute hue and saturation position. saturation value must be clamped -*/ + */ void HexagonalColorWheel::clickLeftWheel(const QPoint &pos) { QLineF p(m_wp[0] + m_wheelPosition, QPointF(pos)); QLineF horizontal(0, 0, 1, 0); @@ -824,7 +833,7 @@ void HexagonalColorWheel::clickLeftWheel(const QPoint &pos) { // d is a length from center to edge of the wheel when saturation = 100 float d = m_triHeight / cosf(phi / 180.0f * 3.1415f); - int h = (int)theta; + int h = (int)theta; if (h > 359) h = 359; // clamping int s = (int)(std::min(p.length() / d, 1.0) * 100.0f); @@ -2326,7 +2335,7 @@ void SpecialStyleChooserPage::loadItems() { tagId == 2002 || // ?? tagId == 3000 || // vector brush tagId == 4001 // mypaint brush - ) + ) continue; TColorStyle *style = TColorStyle::create(tagId); @@ -3128,7 +3137,7 @@ QFrame *StyleEditor::createBottomWidget() { bool ret = true; ret = ret && connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked())); - ret = ret && connect(m_autoButton, SIGNAL(toggled(bool)), this, + ret = ret && connect(m_autoButton, SIGNAL(toggled(bool)), this, SLOT(autoCheckChanged(bool))); ret = ret && connect(m_oldColor, SIGNAL(clicked(const TColorStyle &)), this, SLOT(onOldStyleClicked(const TColorStyle &))); @@ -3191,9 +3200,9 @@ QFrame *StyleEditor::createVectorPage() { bool ret = true; ret = ret && connect(specialButton, SIGNAL(toggled(bool)), this, SLOT(onSpecialButtonToggled(bool))); - ret = ret && connect(customButton, SIGNAL(toggled(bool)), this, + ret = ret && connect(customButton, SIGNAL(toggled(bool)), this, SLOT(onCustomButtonToggled(bool))); - ret = ret && connect(vectorBrushButton, SIGNAL(toggled(bool)), this, + ret = ret && connect(vectorBrushButton, SIGNAL(toggled(bool)), this, SLOT(onVectorBrushButtonToggled(bool))); assert(ret); return vectorOutsideFrame; @@ -3230,9 +3239,9 @@ void StyleEditor::showEvent(QShowEvent *) { bool ret = true; ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), SLOT(onStyleSwitched())); - ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)), + ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)), SLOT(onStyleChanged(bool))); - ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this, + ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this, SLOT(onStyleSwitched())); if (m_cleanupPaletteHandle) ret = @@ -3381,10 +3390,9 @@ void StyleEditor::copyEditedStyleToPalette(bool isDragging) { m_editedStyle->setIsEditedFlag(true); } - palette->setStyle( - styleIndex, - m_editedStyle->clone()); // Must be done *before* setting the eventual - // palette keyframe + palette->setStyle(styleIndex, + m_editedStyle->clone()); // Must be done *before* setting + // the eventual palette keyframe if (!isDragging) { if (!(*m_oldStyle == *m_editedStyle)) { // do not register undo if the edited color is special one (e.g. changing