Skip to content

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

C

[Port] Onion Skin Opacity control (Tahoma2D #1471)

YimingWua3661a2d3884
diff --git a/ports/tahoma2d-pr-1471/README.md b/ports/tahoma2d-pr-1471/README.md
new file mode 100644
index 000000000..ded73ddd7
--- /dev/null
+++ b/ports/tahoma2d-pr-1471/README.md
@@ -0,0 +1,62 @@
+# Port workspace: Tahoma2D PR #1471 — Onion Skin Opacity control
+
+Upstream pull request: https://github.com/tahoma2d/tahoma2d/pull/1471
+
+Original author: @manongjohn
+
+Upstream commits:
+
+- `e519635f45e36ea5ed76ebda36b56063c08ef5b0` — Onion Skin Opacity control
+- `8bf7d3766e9f79a6c84c8d8e100657fa10e6bbf2` — Prioritize higher opacity
+ with overlapping onion-skin markers
+
+Target base used to start this port:
+
+- `OpenAnimationLibrary/opentoonz-dev@93591170f157640cb7b1f17f2678394d1c2af4f6`
+
+## Current status
+
+The feature is adapted to current OpenToonz source. The exact upstream
+mail-formatted patch remains in `upstream.patch`, including the original author
+and commit metadata.
+
+## OpenToonz adaptations
+
+1. Marker state stores true opacity in the `[0, 1]` range; `-1` selects the
+ existing automatic fade calculation.
+2. Fixed and relative markers at the same frame are de-duplicated and use the
+ larger custom opacity.
+3. Removing a marker verifies the requested position, so removing a missing
+ marker cannot erase its neighbor.
+4. `isMos()`, `isFos()`, and opacity getters remain const-correct.
+5. The popup uses OpenToonz's `contextMenuEvent()` path and supports both Xsheet
+ and Timeline orientation.
+6. Popup updates use the onion-skin handle notification and do not mark the
+ scene as modified.
+7. The unrelated Column Transparency behavior change from the upstream patch
+ is not included.
+8. Custom opacity is propagated through vector, raster, Toonz Raster, guided
+ drawing, OpenGL, and plastic-deformation rendering paths.
+
+## Validation checklist
+
+- Fixed and relative markers can each use Auto or a custom value.
+- Overlapping fixed/relative markers choose the more visible result as intended.
+- Removing a nonexistent marker does not remove a neighboring marker.
+- Xsheet and Timeline popup placement/orientation are correct.
+- Vector, Toonz Raster, Raster, mesh/plastic deformation, and OpenGL drawing paths agree.
+- Shift and Trace, Guided Drawing, whole-scene onion skin, and light-table behavior do not regress.
+- Existing scenes load without altered onion-skin marker behavior.
+- Windows, macOS, and Linux builds compile cleanly.
+
+## Reproducing the source commits locally
+
+```bash
+git remote add tahoma2d https://github.com/tahoma2d/tahoma2d.git
+git fetch tahoma2d e519635f45e36ea5ed76ebda36b56063c08ef5b0 8bf7d3766e9f79a6c84c8d8e100657fa10e6bbf2
+git cherry-pick -x e519635f45e36ea5ed76ebda36b56063c08ef5b0
+git cherry-pick -x 8bf7d3766e9f79a6c84c8d8e100657fa10e6bbf2
+```
+
+Resolve conflicts by porting the individual feature hunks according to the
+notes above; do not accept complete Tahoma2D versions of the affected files.
diff --git a/ports/tahoma2d-pr-1471/upstream.patch b/ports/tahoma2d-pr-1471/upstream.patch
new file mode 100644
index 000000000..01df84020
--- /dev/null
+++ b/ports/tahoma2d-pr-1471/upstream.patch
@@ -0,0 +1,905 @@
+From e519635f45e36ea5ed76ebda36b56063c08ef5b0 Mon Sep 17 00:00:00 2001
+From: manongjohn <[email protected]>
+Date: Tue, 14 May 2024 22:03:31 -0400
+Subject: [PATCH 1/2] Onion Skin Opacity control
+
+---
+ toonz/sources/include/toonz/onionskinmask.h | 16 +-
+ toonz/sources/include/toonz/stageplayer.h | 1 +
+ toonz/sources/toonz/sceneviewer.cpp | 1 +
+ toonz/sources/toonz/xshcolumnviewer.cpp | 1 +
+ toonz/sources/toonz/xshrowviewer.cpp | 292 +++++++++++++++++++-
+ toonz/sources/toonz/xshrowviewer.h | 33 +++
+ toonz/sources/toonzlib/onionskinmask.cpp | 95 +++++--
+ toonz/sources/toonzlib/stage.cpp | 21 +-
+ toonz/sources/toonzlib/stageplayer.cpp | 1 +
+ toonz/sources/toonzlib/stagevisitor.cpp | 56 ++--
+ 10 files changed, 459 insertions(+), 58 deletions(-)
+
+diff --git a/toonz/sources/include/toonz/onionskinmask.h b/toonz/sources/include/toonz/onionskinmask.h
+index 428af3600..2f13008fc 100644
+--- a/toonz/sources/include/toonz/onionskinmask.h
++++ b/toonz/sources/include/toonz/onionskinmask.h
+@@ -62,12 +62,12 @@ class DVAPI OnionSkinMask {
+
+ int getMos(int index) const {
+ assert(0 <= index && index < (int)m_mos.size());
+- return m_mos[index];
++ return m_mos[index].first;
+ }
+
+ int getFos(int index) const {
+ assert(0 <= index && index < (int)m_fos.size());
+- return m_fos[index];
++ return m_fos[index].first;
+ }
+
+ void setMos(int drow, bool on); //!< Sets a Mobile OS frame shifted by drow
+@@ -75,8 +75,13 @@ class DVAPI OnionSkinMask {
+ void setFos(int row,
+ bool on); //!< Sets a Fixed OS frame to the specified xsheet row
+
+- bool isMos(int drow) const;
+- bool isFos(int row) const;
++ void setMosOpacity(int drow, double opacity);
++ double getMosOpacity(int drow);
++ void setFosOpacity(int row, double opacity);
++ double getFosOpacity(int row);
++
++ bool isMos(int drow);
++ bool isFos(int row);
+
+ bool getMosRange(int &drow0, int &drow1) const;
+
+@@ -146,7 +151,8 @@ since underlying onion-skinned drawings must be visible.
+ void clearGhostFlipKey() { m_ghostFlipKeys.clear(); }
+
+ private:
+- std::vector<int> m_fos, m_mos; //!< Fixed and Mobile Onion Skin indices
++ std::vector<std::pair<int, double>> m_fos,
++ m_mos; //!< Fixed and Mobile Onion Skin indices and opacity
+ bool m_enabled; //!< Whether onion skin is enabled
+ bool m_wholeScene; //!< Whether the OS works on the entire scene
+ bool m_everyFrame; //!< Whether the OS renders every frame or only on new exposures.
+diff --git a/toonz/sources/include/toonz/stageplayer.h b/toonz/sources/include/toonz/stageplayer.h
+index a0eb08f6c..d302f5bf4 100644
+--- a/toonz/sources/include/toonz/stageplayer.h
++++ b/toonz/sources/include/toonz/stageplayer.h
+@@ -76,6 +76,7 @@ class DVAPI Player {
+
+ int m_onionSkinDistance; //!< Temporal distance from an onion skin
+ //!'companion' (supposedly)
++ double m_fade; //! Onion skin opacity to use. -1 = autocalculated
+
+ int m_ancestorColumnIndex; //!< Index of this object's hierarchycal root
+ //!(top-most column)
+diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
+index ec560b60a..df07e0cf0 100644
+--- a/toonz/sources/toonz/sceneviewer.cpp
++++ b/toonz/sources/toonz/sceneviewer.cpp
+@@ -2474,6 +2474,7 @@ void SceneViewer::drawSceneOverlay() {
+ player.m_guidedBackStroke = -1;
+ player.m_isVisibleinOSM = false;
+ player.m_onionSkinDistance = c_noOnionSkin;
++ player.m_fade = -1.0;
+ player.m_dpiAff = getDpiAffine(sl, frameId);
+ player.m_ancestorColumnIndex = -1;
+ player.m_opacity = scene->getOverlayOpacity();
+diff --git a/toonz/sources/toonz/xshcolumnviewer.cpp b/toonz/sources/toonz/xshcolumnviewer.cpp
+index bc0542bef..c84360a68 100644
+--- a/toonz/sources/toonz/xshcolumnviewer.cpp
++++ b/toonz/sources/toonz/xshcolumnviewer.cpp
+@@ -2683,6 +2683,7 @@ void ColumnTransparencyPopup::onSliderChange(int val) {
+ m_value->setText(QString::number(val));
+ connect(m_value, SIGNAL(textChanged(const QString &)), this,
+ SLOT(onValueChanged(const QString &)));
++ onSliderReleased();
+ }
+
+ //----------------------------------------------------------------
+diff --git a/toonz/sources/toonz/xshrowviewer.cpp b/toonz/sources/toonz/xshrowviewer.cpp
+index 228bed397..a02cb1231 100644
+--- a/toonz/sources/toonz/xshrowviewer.cpp
++++ b/toonz/sources/toonz/xshrowviewer.cpp
+@@ -37,6 +37,206 @@
+
+ namespace XsheetGUI {
+
++OnionSkinPopup::OnionSkinPopup(QWidget *parent, bool isVertical)
++ : QWidget(parent, Qt::Popup) {
++ if (isVertical) {
++ setMaximumWidth(75);
++ m_slider = new QSlider(Qt::Vertical, this);
++ } else
++ m_slider = new QSlider(Qt::Horizontal, this);
++ m_slider->setMinimum(1);
++ m_slider->setMaximum(100);
++
++ m_value = new DVGui::IntLineEdit(this, 1, 1, 100);
++
++ m_autoCB = new QCheckBox(tr("Auto"), this);
++ m_autoCB->setChecked(true);
++
++ QGridLayout *mainLayout = new QGridLayout();
++ mainLayout->setMargin(3);
++ mainLayout->setHorizontalSpacing(6);
++ mainLayout->setVerticalSpacing(6);
++ {
++ if (isVertical) {
++ QVBoxLayout *vlayout = new QVBoxLayout;
++ vlayout->setMargin(0);
++ vlayout->setSpacing(3);
++ {
++ vlayout->addWidget(new QLabel(tr("Opacity"), this), 0,
++ Qt::AlignHCenter);
++ QHBoxLayout *hlayout = new QHBoxLayout;
++ hlayout->setMargin(0);
++ hlayout->setSpacing(3);
++ hlayout->setAlignment(Qt::AlignHCenter);
++ {
++ hlayout->addStretch(1);
++ hlayout->addWidget(m_value);
++ hlayout->addWidget(new QLabel("%"));
++ hlayout->addStretch(1);
++ }
++ vlayout->addLayout(hlayout, 0);
++ vlayout->addWidget(m_slider, 0, Qt::AlignHCenter);
++ vlayout->addWidget(m_autoCB, 0, Qt::AlignHCenter);
++ }
++ mainLayout->addLayout(vlayout, 0, 1);
++ } else {
++ mainLayout->addWidget(new QLabel(tr("Opacity:"), this), 0, 0,
++ Qt::AlignRight | Qt::AlignVCenter);
++ QHBoxLayout *hlayout = new QHBoxLayout;
++ hlayout->setMargin(0);
++ hlayout->setSpacing(3);
++ {
++ hlayout->addWidget(m_slider);
++ hlayout->addWidget(m_value);
++ hlayout->addWidget(new QLabel("%"));
++ hlayout->addWidget(m_autoCB, 0);
++ }
++ mainLayout->addLayout(hlayout, 0, 1);
++ }
++ }
++ setLayout(mainLayout);
++
++ bool ret = connect(m_slider, SIGNAL(sliderReleased()), this,
++ SLOT(onSliderReleased()));
++ ret = ret && connect(m_slider, SIGNAL(sliderMoved(int)), this,
++ SLOT(onSliderChange(int)));
++ ret = ret && connect(m_slider, SIGNAL(valueChanged(int)), this,
++ SLOT(onSliderValueChanged(int)));
++ ret = ret && connect(m_value, SIGNAL(textChanged(const QString &)), this,
++ SLOT(onValueChanged(const QString &)));
++ ret = ret && connect(m_autoCB, SIGNAL(clicked(bool)), this,
++ SLOT(onAutoClicked(bool)));
++
++ assert(ret);
++}
++
++//----------------------------------------------------------------
++bool descending(int i, int j) { return (i > j); }
++
++void OnionSkinPopup::setOnionSkinData(int currentRow, int os, bool isFixed) {
++ OnionSkinMask osMask =
++ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
++
++ bool autoOpacity = false;
++
++ m_os = os;
++ m_isFixed = isFixed;
++ m_distance = 0;
++
++ std::vector<int> rows;
++ osMask.getAll(currentRow, rows);
++ std::vector<int>::iterator it = rows.begin();
++ while (it != rows.end() && *it < currentRow) it++;
++ std::sort(rows.begin(), it, descending);
++
++ int frontPos = 0, backPos = 0;
++ for (int i = 0; i < (int)rows.size(); i++) {
++ if (rows[i] == currentRow) continue;
++ if (osMask.isEveryFrame()) {
++ m_distance = (rows[i] - currentRow) < 0 ? --backPos : ++frontPos;
++ }
++ if ((m_isFixed && m_os == rows[i]) || (!m_isFixed && (rows[i] - currentRow) == os)) break;
++ }
++
++ double opacity =
++ isFixed ? osMask.getFosOpacity(os) : osMask.getMosOpacity(os);
++
++ if (opacity == -1.0) {
++ autoOpacity = true;
++ opacity = OnionSkinMask::getOnionSkinFade(m_distance);
++ }
++
++ // Adjust for slider
++ opacity = 100.0 - (opacity * 100.0);
++
++ m_initializing = true;
++ m_slider->setValue((int)opacity);
++ m_autoCB->setChecked(autoOpacity);
++ m_initializing = false;
++}
++
++//----------------------------------------------------------------
++
++void OnionSkinPopup::onSliderReleased() {
++ if (m_initializing) return;
++
++ OnionSkinMask osMask =
++ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
++
++ double opacity =
++ m_autoCB->isChecked() ? -1.0 : (100 - m_slider->value()) / 100.0;
++
++ if (m_isFixed)
++ osMask.setFosOpacity(m_os, opacity);
++ else
++ osMask.setMosOpacity(m_os, opacity);
++
++ TApp::instance()->getCurrentOnionSkin()->setOnionSkinMask(osMask);
++
++ TApp::instance()->getCurrentScene()->notifySceneChanged();
++ TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
++}
++
++//-----------------------------------------------------------------------
++
++void OnionSkinPopup::onSliderValueChanged(int val) {
++ if (m_slider->isSliderDown()) return;
++ m_value->setText(QString::number(val));
++ onSliderReleased();
++}
++
++//-----------------------------------------------------------------------
++
++void OnionSkinPopup::onSliderChange(int val) {
++ if (m_autoCB->isChecked()) m_autoCB->setChecked(false);
++
++ disconnect(m_value, SIGNAL(textChanged(const QString &)), 0, 0);
++ m_value->setText(QString::number(val));
++ connect(m_value, SIGNAL(textChanged(const QString &)), this,
++ SLOT(onValueChanged(const QString &)));
++ onSliderReleased();
++}
++
++//----------------------------------------------------------------
++
++void OnionSkinPopup::onValueChanged(const QString &str) {
++ if (m_autoCB->isChecked()) m_autoCB->setChecked(false);
++
++ int val = str.toInt();
++ m_slider->setValue(val);
++}
++
++//-----------------------------------------------------------------------
++
++void OnionSkinPopup::onAutoClicked(bool checked) {
++ if (m_initializing || m_slider->isSliderDown()) return;
++
++ if (checked) {
++ // Go back to automatic calculation
++ double opacity = OnionSkinMask::getOnionSkinFade(m_distance);
++
++ // Adjust for slider
++ opacity = 100.0 - (opacity * 100.0);
++
++ m_slider->blockSignals(true);
++ m_value->blockSignals(true);
++
++ m_slider->setValue((int)opacity);
++ m_value->setText(QString::number((int)opacity));
++
++ m_slider->blockSignals(false);
++ m_value->blockSignals(false);
++ }
++
++ onSliderReleased();
++}
++
++//-----------------------------------------------------------------------
++
++void OnionSkinPopup::mouseReleaseEvent(QMouseEvent *e) {
++ // hide();
++}
++
+ //=============================================================================
+ // RowArea
+ //-----------------------------------------------------------------------------
+@@ -54,7 +254,8 @@ RowArea::RowArea(XsheetViewer *parent, Qt::WindowFlags flags)
+ , m_r1(5)
+ , m_isPanning(false)
+ , m_contextMenuRow(-1)
+- , m_editTagEnabled(false) {
++ , m_editTagEnabled(false)
++ , m_onionSkinPopup(0) {
+ setFocusPolicy(Qt::NoFocus);
+ setMouseTracking(true);
+
+@@ -641,9 +842,11 @@ void RowArea::drawOnionSkinSelection(QPainter &p) {
+ if (m_showOnionToSet == Mos && currentRow + mos == m_row) continue;
+
+ p.setPen(mos < 0 ? backDotOutlineColor : frontDotOutlineColor);
+- if (osMask.isEnabled())
+- p.setBrush(mos < 0 ? backDotColor : frontDotColor);
+- else
++ if (osMask.isEnabled()) {
++ QColor dotColor = mos < 0 ? backDotColor : frontDotColor;
++ if (osMask.getMosOpacity(mos) != -1.0) dotColor = dotColor.darker(200);
++ p.setBrush(dotColor);
++ } else
+ p.setBrush(Qt::NoBrush);
+ QPoint topLeft = m_viewer->positionToXY(CellPosition(currentRow + mos, -1));
+ if (!m_viewer->orientation()->isVerticalTimeline())
+@@ -669,12 +872,14 @@ void RowArea::drawOnionSkinSelection(QPainter &p) {
+ p.setPen(QColor(25, 118, 170, 255));
+ else
+ p.setPen(QColor(0, 255, 255, 128));
+- if (osMask.isEnabled())
++ if (osMask.isEnabled()) {
++ QColor dotColor(0, 255, 255, 148);
+ // Depending on the brightness, make sure dot can be seen on onion area
+ if (m_viewer->getOnionSkinAreaBgColor().value() > 128)
+- p.setBrush(QBrush(QColor(0, 165, 255, 148)));
+- else
+- p.setBrush(QBrush(QColor(0, 255, 255, 148)));
++ dotColor = QColor(0, 165, 255, 148);
++ if (osMask.getFosOpacity(fos) != -1.0) dotColor = dotColor.darker(200);
++ p.setBrush(dotColor);
++ }
+ else
+ p.setBrush(Qt::NoBrush);
+ QPoint topLeft = m_viewer->positionToXY(CellPosition(fos, -1));
+@@ -1324,9 +1529,9 @@ void RowArea::mouseMoveEvent(QMouseEvent *event) {
+ else
+ m_tooltip = tr("Current Frame");
+ } else if (m_showOnionToSet == Fos)
+- m_tooltip = tr("Fixed Onion Skin Toggle");
++ m_tooltip = tr("Fixed Onion Skin Toggle\nRight-Click to adjust opacity");
+ else if (m_showOnionToSet == Mos)
+- m_tooltip = tr("Relative Onion Skin Toggle");
++ m_tooltip = tr("Relative Onion Skin Toggle\nRight-Click to adjust opacity");
+ else
+ m_tooltip = tr("%1+Click\t- Set Playback Start Marker\n%2+Click \t- Set "
+ "Playback End Marker\n%3+Click\t- Remove Playback Markers")
+@@ -1361,13 +1566,76 @@ void RowArea::mouseReleaseEvent(QMouseEvent *event) {
+ //-----------------------------------------------------------------------------
+
+ void RowArea::contextMenuEvent(QContextMenuEvent *event) {
++ const Orientation *o = m_viewer->orientation();
++
+ if (m_resetMenuTimer) m_resetMenuTimer->stop();
+
+ TPoint pos(event->pos().x(), event->pos().y());
+ m_contextMenuRow = m_viewer->xyToPosition(pos).frame();
+
+- OnionSkinMask osMask =
+- TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
++ // Check if we're over onion skin marker
++ int currentRow = TApp::instance()->getCurrentFrame()->getFrame();
++ QPoint topLeft = m_viewer->positionToXY(CellPosition(m_contextMenuRow, -1));
++ if (!m_viewer->orientation()->isVerticalTimeline())
++ topLeft.setY(0);
++ else
++ topLeft.setX(0);
++ QPoint mouseInCell = event->pos() - topLeft;
++ QPoint frameAdj = m_viewer->getFrameZoomAdjustment();
++
++ if (!CommandManager::instance()->getAction(MI_ShiftTrace)->isChecked() &&
++ Preferences::instance()->isOnionSkinEnabled() &&
++ o->rect(PredefinedRect::ONION_AREA)
++ .adjusted(0, 0, -frameAdj.x(), -frameAdj.y())
++ .contains(mouseInCell) &&
++ m_contextMenuRow != currentRow) {
++ OnionSkinMask osMask =
++ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
++
++ if (o->rect(PredefinedRect::ONION_FIXED_DOT_AREA)
++ .adjusted(0, 0, -frameAdj.x(), -frameAdj.y())
++ .contains(mouseInCell)) {
++ int fosCount = osMask.getFosCount();
++ int fos;
++ for (int i = 0; i < fosCount; i++) {
++ fos = osMask.getFos(i);
++ if (fos == m_contextMenuRow) {
++ if (!m_onionSkinPopup)
++ m_onionSkinPopup = new OnionSkinPopup(
++ this, !m_viewer->orientation()->isVerticalTimeline());
++
++ m_onionSkinPopup->move(event->globalPos().x(),
++ event->globalPos().y());
++ m_onionSkinPopup->setOnionSkinData(currentRow, fos, true);
++ m_onionSkinPopup->show();
++
++ event->accept();
++ return;
++ }
++ }
++ } else if (o->rect(PredefinedRect::ONION_DOT_AREA)
++ .adjusted(0, 0, -frameAdj.x(), -frameAdj.y())
++ .contains(mouseInCell)) {
++ int mosCount = osMask.getMosCount();
++ int mos;
++ for (int i = 0; i < mosCount; i++) {
++ // mos : frame offset from the current frame
++ mos = osMask.getMos(i);
++ if (currentRow + mos == m_contextMenuRow) {
++ if (!m_onionSkinPopup)
++ m_onionSkinPopup = new OnionSkinPopup(
++ this, !m_viewer->orientation()->isVerticalTimeline());
++
++ m_onionSkinPopup->move(event->globalPos().x(),
++ event->globalPos().y());
++ m_onionSkinPopup->setOnionSkinData(currentRow, mos, false);
++ m_onionSkinPopup->show();
++ event->accept();
++ return;
++ }
++ }
++ }
++ }
+
+ QMenu *menu = new QMenu(this);
+ menu->addAction(CommandManager::instance()->getAction(MI_SetStartMarker));
+diff --git a/toonz/sources/toonz/xshrowviewer.h b/toonz/sources/toonz/xshrowviewer.h
+index 1493687ee..46e6b3d4e 100644
+--- a/toonz/sources/toonz/xshrowviewer.h
++++ b/toonz/sources/toonz/xshrowviewer.h
+@@ -4,6 +4,9 @@
+ #define XSHROWVIEWER_H
+
+ #include <QWidget>
++#include <QLineEdit>
++#include <QSlider>
++#include <QCheckBox>
+
+ // forward declaration
+ class XsheetViewer;
+@@ -16,6 +19,34 @@ class DragTool;
+ //=============================================================================
+ // RowArea
+ //-----------------------------------------------------------------------------
++class OnionSkinPopup final : public QWidget {
++ Q_OBJECT
++
++ QSlider *m_slider;
++ QLineEdit *m_value;
++ QCheckBox *m_autoCB;
++
++ int m_os;
++ bool m_isFixed;
++ int m_distance;
++
++ bool m_initializing;
++
++public:
++ OnionSkinPopup(QWidget *parent, bool isVertical = true);
++ void setOnionSkinData(int currentRow, int os, bool isFixed);
++
++protected:
++ void mouseReleaseEvent(QMouseEvent *e) override;
++
++protected slots:
++ void onSliderReleased();
++ void onSliderChange(int val);
++ void onSliderValueChanged(int);
++ void onValueChanged(const QString &);
++ void onAutoClicked(bool);
++};
+
+ //! La classe si occupa della visualizzazione dell'area che gestisce le righe.
+ class RowArea final : public QWidget {
+@@ -48,6 +79,8 @@ class RowArea final : public QWidget {
+ int m_contextMenuRow;
+ bool m_editTagEnabled;
+
++ OnionSkinPopup *m_onionSkinPopup;
++
+ // returns true if the frame area can have extra space
+ bool checkExpandFrameArea();
+ void drawRows(QPainter &p, int r0, int r1);
+diff --git a/toonz/sources/toonzlib/onionskinmask.cpp b/toonz/sources/toonzlib/onionskinmask.cpp
+index 1f0a0738b..3361080d2 100644
+--- a/toonz/sources/toonzlib/onionskinmask.cpp
++++ b/toonz/sources/toonzlib/onionskinmask.cpp
+@@ -85,12 +85,13 @@ void OnionSkinMask::getAll(int currentRow, std::vector<int> &output) const {
+ output.clear();
+ output.reserve(m_fos.size() + m_mos.size());
+
+- std::vector<int>::const_iterator fosIt, fosEnd(m_fos.end());
+- std::vector<int>::const_iterator mosIt, mosEnd(m_mos.end());
++ std::vector<std::pair<int, double>>::const_iterator fosIt, fosEnd(m_fos.end());
++ std::vector<std::pair<int, double>>::const_iterator mosIt,
++ mosEnd(m_mos.end());
+
+ for (fosIt = m_fos.begin(), mosIt = m_mos.begin();
+ fosIt != fosEnd && mosIt != mosEnd;) {
+- int fos = *fosIt, mos = *mosIt + currentRow;
++ int fos = fosIt->first, mos = mosIt->first + currentRow;
+
+ if (fos < mos) {
+ if (fos != currentRow) output.push_back(fos);
+@@ -104,10 +105,10 @@ void OnionSkinMask::getAll(int currentRow, std::vector<int> &output) const {
+ }
+
+ for (; fosIt != fosEnd; ++fosIt)
+- if (*fosIt != currentRow) output.push_back(*fosIt);
++ if (fosIt->first != currentRow) output.push_back(fosIt->first);
+
+ for (; mosIt != mosEnd; ++mosIt) {
+- int mos = *mosIt + currentRow;
++ int mos = mosIt->first + currentRow;
+ if (mos != currentRow) output.push_back(mos);
+ }
+ }
+@@ -117,39 +118,97 @@ void OnionSkinMask::getAll(int currentRow, std::vector<int> &output) const {
+ void OnionSkinMask::setMos(int drow, bool on) {
+ assert(drow != 0);
+
+- typedef std::vector<int>::iterator Iter;
+- std::pair<Iter, Iter> r = std::equal_range(m_mos.begin(), m_mos.end(), drow);
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_mos.begin(); r != m_mos.end(); r++) {
++ if (r->first >= drow) break;
++ }
+
+ if (on) {
+- if (r.first == r.second) m_mos.insert(r.first, drow);
++ if (r == m_mos.end() || r->first != drow)
++ m_mos.insert(r, std::make_pair(drow, -1));
+ } else {
+- if (r.first != r.second) m_mos.erase(r.first, r.second);
++ if (r != m_mos.end()) m_mos.erase(r);
+ }
+ }
+
+ //-------------------------------------------------------------------
+
+ void OnionSkinMask::setFos(int row, bool on) {
+- typedef std::vector<int>::iterator Iter;
+- std::pair<Iter, Iter> r = std::equal_range(m_fos.begin(), m_fos.end(), row);
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_fos.begin(); r != m_fos.end(); r++) {
++ if (r->first >= row) break;
++ }
+
+ if (on) {
+- if (r.first == r.second) m_fos.insert(r.first, row);
++ if (r == m_fos.end() || r->first != row)
++ m_fos.insert(r, std::make_pair(row, -1));
+ } else {
+- if (r.first != r.second) m_fos.erase(r.first, r.second);
++ if (r != m_fos.end()) m_fos.erase(r);
++ }
++}
++
++//-------------------------------------------------------------------
++
++void OnionSkinMask::setMosOpacity(int drow, double opacity) {
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_mos.begin(); r != m_mos.end(); r++) {
++ if (r->first == drow) {
++ r->second = opacity;
++ break;
++ }
++ }
++}
++
++//-------------------------------------------------------------------
++
++double OnionSkinMask::getMosOpacity(int drow) {
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_mos.begin(); r != m_mos.end(); r++)
++ if (r->first == drow) return r->second;
++
++ return -1.0;
++}
++
++//-------------------------------------------------------------------
++
++void OnionSkinMask::setFosOpacity(int row, double opacity) {
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_fos.begin(); r != m_fos.end(); r++) {
++ if (r->first == row) {
++ r->second = opacity;
++ break;
++ }
+ }
+ }
+
+ //-------------------------------------------------------------------
+
+-bool OnionSkinMask::isFos(int row) const {
+- return std::binary_search(m_fos.begin(), m_fos.end(), row);
++double OnionSkinMask::getFosOpacity(int drow) {
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_fos.begin(); r != m_fos.end(); r++)
++ if (r->first == drow) return r->second;
++
++ return -1.0;
+ }
+
+ //-------------------------------------------------------------------
+
+-bool OnionSkinMask::isMos(int drow) const {
+- return std::binary_search(m_mos.begin(), m_mos.end(), drow);
++bool OnionSkinMask::isFos(int row) {
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_fos.begin(); r != m_fos.end(); r++)
++ if (r->first == row) return true;
++
++ return false;
++}
++
++//-------------------------------------------------------------------
++
++bool OnionSkinMask::isMos(int drow) {
++ std::vector<std::pair<int, double>>::iterator r;
++ for (r = m_mos.begin(); r != m_mos.end(); r++)
++ if (r->first == drow) return true;
++
++ return false;
+ }
+
+ //-------------------------------------------------------------------
+@@ -159,7 +218,7 @@ bool OnionSkinMask::getMosRange(int &drow0, int &drow1) const {
+ drow0 = 0, drow1 = -1;
+ return false;
+ } else {
+- drow0 = m_mos.front(), drow1 = m_mos.back();
++ drow0 = m_mos.front().first, drow1 = m_mos.back().first;
+ return true;
+ }
+ }
+diff --git a/toonz/sources/toonzlib/stage.cpp b/toonz/sources/toonzlib/stage.cpp
+index 74c3551bf..016dd1421 100644
+--- a/toonz/sources/toonzlib/stage.cpp
++++ b/toonz/sources/toonzlib/stage.cpp
+@@ -274,7 +274,7 @@ StageBuilder::StageBuilder()
+ , m_camera3d(false)
+ , m_currentColumnIndex(-1)
+ , m_ancestorColumnIndex(-1)
+- , m_fade(0)
++ , m_fade(-1.0)
+ , m_shiftTraceGhostId(NO_GHOST)
+ , m_editingShift(false)
+ , m_showShiftOrigin(false)
+@@ -412,6 +412,7 @@ void StageBuilder::addCell(PlayerSet &players, ToonzScene *scene, TXsheet *xsh,
+ player.m_guidedBackStroke = m_guidedBackStroke;
+ player.m_dpiAff = sl ? getDpiAffine(sl, cell.m_frameId) : TAffine();
+ player.m_onionSkinDistance = m_onionSkinDistance;
++ player.m_fade = m_fade;
+ // when visiting the subxsheet, valuate the subxsheet column index
+ bool isCurrent = (subSheetColIndex >= 0)
+ ? (subSheetColIndex == m_currentColumnIndex)
+@@ -647,15 +648,21 @@ void StageBuilder::addCellWithOnionSkin(PlayerSet &players, ToonzScene *scene,
+ if (m_onionSkinMask.isEveryFrame() ||
+ !alreadyAdded(xsh, row, i, rows, col)) {
+ m_onionSkinDistance = (rows[i] - row) < 0 ? --backPos : ++frontPos;
++
++ m_fade = m_onionSkinMask.getFosOpacity(rows[i]);
++ if (m_fade == -1.0)
++ m_fade = m_onionSkinMask.getMosOpacity(rows[i] - row);
+ addCell(players, scene, xsh, rows[i], col, level, subSheetColIndex);
+ }
+ #endif
+ }
+
+ m_onionSkinDistance = 0;
++ m_fade = 0.0;
+ addCell(players, scene, xsh, row, col, level, subSheetColIndex);
+
+ m_onionSkinDistance = c_noOnionSkin;
++ m_fade = -1.0;
+ } else
+ addCell(players, scene, xsh, row, col, level, subSheetColIndex);
+ }
+@@ -747,6 +754,7 @@ void StageBuilder::addSimpleLevelFrame(PlayerSet &players,
+ player.m_guidedBackStroke = m_guidedBackStroke;
+ player.m_isVisibleinOSM = ghostRow >= 0;
+ player.m_onionSkinDistance = m_onionSkinDistance;
++ player.m_fade = m_fade;
+ player.m_dpiAff = getDpiAffine(level, ghostFid);
+ player.m_ancestorColumnIndex = -1;
+
+@@ -808,6 +816,7 @@ void StageBuilder::addSimpleLevelFrame(PlayerSet &players,
+ while (it != rows.end() && *it < row) ++it;
+ std::sort(rows.begin(), it, descending);
+ m_onionSkinDistance = 0;
++ m_fade = 0.0;
+ int frontPos = 0, backPos = 0;
+
+ for (int i = 0; i < (int)rows.size(); i++) {
+@@ -830,6 +839,10 @@ void StageBuilder::addSimpleLevelFrame(PlayerSet &players,
+ player.m_onionSkinDistance = rows[i] - row;
+ #else
+ player.m_onionSkinDistance = rows[i] - row < 0 ? --backPos : ++frontPos;
++
++ player.m_fade = m_onionSkinMask.getFosOpacity(rows[i]);
++ if (player.m_fade == -1.0)
++ player.m_fade = m_onionSkinMask.getMosOpacity(rows[i] - row);
+ #endif
+ player.m_dpiAff = getDpiAffine(level, fid2);
+ }
+@@ -839,8 +852,10 @@ void StageBuilder::addSimpleLevelFrame(PlayerSet &players,
+ player.m_sl = level;
+ player.m_frame = level->guessIndex(fid);
+ player.m_fid = fid;
+- if (!m_onionSkinMask.isEmpty() && m_onionSkinMask.isEnabled())
+- player.m_onionSkinDistance = 0;
++ if (!m_onionSkinMask.isEmpty() && m_onionSkinMask.isEnabled()) {
++ player.m_onionSkinDistance = 0;
++ player.m_fade = 0.0;
++ }
+ player.m_isCurrentColumn = true;
+ player.m_isCurrentXsheetLevel = true;
+ player.m_isEditingLevel = true;
+diff --git a/toonz/sources/toonzlib/stageplayer.cpp b/toonz/sources/toonzlib/stageplayer.cpp
+index ebd9f9267..c46e237de 100644
+--- a/toonz/sources/toonzlib/stageplayer.cpp
++++ b/toonz/sources/toonzlib/stageplayer.cpp
+@@ -36,6 +36,7 @@ Stage::Player::Player()
+ , m_dpiAff()
+ , m_z(0)
+ , m_onionSkinDistance(c_noOnionSkin)
++ , m_fade(-1.0)
+ , m_ancestorColumnIndex(-1)
+ , m_isCurrentColumn(false)
+ , m_isCurrentXsheetLevel(false)
+diff --git a/toonz/sources/toonzlib/stagevisitor.cpp b/toonz/sources/toonzlib/stagevisitor.cpp
+index e3fc35014..dff42fc6b 100644
+--- a/toonz/sources/toonzlib/stagevisitor.cpp
++++ b/toonz/sources/toonzlib/stagevisitor.cpp
+@@ -876,10 +876,12 @@ void RasterPainter::onVectorImage(TVectorImage *vi,
+ double m[4] = {1.0, 1.0, 1.0, 1.0}, c[4];
+
+ // Weighted addition to RGB and matte multiplication
+- m[3] = 1.0 -
+- ((player.m_onionSkinDistance == 0)
+- ? 0.1
+- : OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance));
++ m[3] =
++ 1.0 - ((player.m_onionSkinDistance == 0)
++ ? 0.1
++ : (player.m_fade != -1.0 ? player.m_fade
++ : OnionSkinMask::getOnionSkinFade(
++ player.m_onionSkinDistance)));
+ if (player.m_isLightTableEnabled && !player.m_isCurrentColumn) m[3] *= 0.30;
+
+ c[0] = (1.0 - m[3]) * bgColor.r, c[1] = (1.0 - m[3]) * bgColor.g,
+@@ -943,11 +945,12 @@ void RasterPainter::onVectorImage(TVectorImage *vi,
+
+ double guidedM[4] = {1.0, 1.0, 1.0, 1.0}, guidedC[4];
+ TPixel32 bgColor = TPixel32::Blue;
+- guidedM[3] =
+- 1.0 -
+- ((player.m_onionSkinDistance == 0)
+- ? 0.1
+- : OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance));
++ guidedM[3] = 1.0 - ((player.m_onionSkinDistance == 0)
++ ? 0.1
++ : (player.m_fade != -1.0
++ ? player.m_fade
++ : OnionSkinMask::getOnionSkinFade(
++ player.m_onionSkinDistance)));
+
+ guidedC[0] = (1.0 - guidedM[3]) * bgColor.r,
+ guidedC[1] = (1.0 - guidedM[3]) * bgColor.g,
+@@ -1030,10 +1033,12 @@ void RasterPainter::onRasterImage(TRasterImage *ri,
+ // 1 opaco -> 0 completamente trasparente
+ // inverto quindi il risultato della funzione stando attento al caso 0
+ // (in cui era scolpito il valore 0.9)
+- double onionSkiFade = player.m_onionSkinDistance == 0
+- ? 0.9
+- : (1.0 - OnionSkinMask::getOnionSkinFade(
+- player.m_onionSkinDistance));
++ double onionSkiFade =
++ player.m_onionSkinDistance == 0
++ ? 0.9
++ : (1.0 - (player.m_fade != -1.0 ? player.m_fade
++ : OnionSkinMask::getOnionSkinFade(
++ player.m_onionSkinDistance)));
+ if (player.m_isLightTableEnabled && !player.m_isCurrentColumn)
+ onionSkiFade *= 0.30;
+ alpha = tcrop(tround(onionSkiFade * 255.0), 0, 255);
+@@ -1099,10 +1104,12 @@ void RasterPainter::onToonzImage(TToonzImage *ti, const Stage::Player &player) {
+ // I therefore reverse the result of the function by being attentive to
+ // case 0
+ // (where the value 0.9 was carved)
+- double onionSkiFade = player.m_onionSkinDistance == 0
+- ? 0.9
+- : (1.0 - OnionSkinMask::getOnionSkinFade(
+- player.m_onionSkinDistance));
++ double onionSkiFade =
++ player.m_onionSkinDistance == 0
++ ? 0.9
++ : (1.0 - (player.m_fade != -1.0 ? player.m_fade
++ : OnionSkinMask::getOnionSkinFade(
++ player.m_onionSkinDistance)));
+ if (player.m_isLightTableEnabled && !player.m_isCurrentColumn)
+ onionSkiFade *= 0.30;
+ alpha = tcrop(tround(onionSkiFade * 255.0), 0, 255);
+@@ -1201,7 +1208,9 @@ void OpenGlPainter::onVectorImage(TVectorImage *vi,
+ if (player.m_onionSkinDistance != c_noOnionSkin) {
+ TPixel32 bgColor = TPixel32::White;
+ fader = TOnionFader(
+- bgColor, OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance));
++ bgColor, (player.m_fade != -1.0 ? player.m_fade
++ : OnionSkinMask::getOnionSkinFade(
++ player.m_onionSkinDistance)));
+ cf = &fader;
+ }
+
+@@ -1256,7 +1265,11 @@ void OpenGlPainter::onRasterImage(TRasterImage *ri,
+
+ if (c_noOnionSkin != player.m_onionSkinDistance) {
+ double fade =
+- 0.5 - 0.45 * (1 - 1 / (1 + 0.15 * abs(player.m_onionSkinDistance)));
++ (player.m_fade != -1.0
++ ? player.m_fade
++ : 0.5 -
++ 0.45 *
++ (1 - 1 / (1 + 0.15 * abs(player.m_onionSkinDistance))));
+ if ((int)matteChan.size() < r->getLx() * r->getLy())
+ matteChan.resize(r->getLx() * r->getLy());
+
+@@ -1537,7 +1550,10 @@ void onPlasticDeformedImage(TStageObject *playerObj,
+ (player.m_onionSkinDistance < 0) ? backOnionColor : frontOnionColor;
+
+ pixScale[3] =
+- 1.0 - OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance);
++ 1.0 -
++ (player.m_fade != -1.0
++ ? player.m_fade
++ : OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance));
+ pixScale[0] =
+ (refColor.r / 255.0) * pixScale[3]; // refColor is not premultiplied
+ pixScale[1] = (refColor.g / 255.0) * pixScale[3];
+
+From 8bf7d3766e9f79a6c84c8d8e100657fa10e6bbf2 Mon Sep 17 00:00:00 2001
+From: manongjohn <[email protected]>
+Date: Tue, 14 May 2024 23:10:02 -0400
+Subject: [PATCH 2/2] Prioritize higher opacity w/ overlapping onion skin
+ markers
+
+---
+ toonz/sources/toonzlib/stage.cpp | 17 +++++++++++------
+ 1 file changed, 11 insertions(+), 6 deletions(-)
+
+diff --git a/toonz/sources/toonzlib/stage.cpp b/toonz/sources/toonzlib/stage.cpp
+index 016dd1421..f48f00d65 100644
+--- a/toonz/sources/toonzlib/stage.cpp
++++ b/toonz/sources/toonzlib/stage.cpp
+@@ -649,9 +649,11 @@ void StageBuilder::addCellWithOnionSkin(PlayerSet &players, ToonzScene *scene,
+ !alreadyAdded(xsh, row, i, rows, col)) {
+ m_onionSkinDistance = (rows[i] - row) < 0 ? --backPos : ++frontPos;
+
+- m_fade = m_onionSkinMask.getFosOpacity(rows[i]);
+- if (m_fade == -1.0)
+- m_fade = m_onionSkinMask.getMosOpacity(rows[i] - row);
++ double fosFade = m_onionSkinMask.getFosOpacity(rows[i]);
++ double mosFade = m_onionSkinMask.getMosOpacity(rows[i] - row);
++ m_fade = fosFade == -1.0
++ ? mosFade
++ : (mosFade == -1 ? fosFade : std::min(fosFade, mosFade));
+ addCell(players, scene, xsh, rows[i], col, level, subSheetColIndex);
+ }
+ #endif
+@@ -840,9 +842,12 @@ void StageBuilder::addSimpleLevelFrame(PlayerSet &players,
+ #else
+ player.m_onionSkinDistance = rows[i] - row < 0 ? --backPos : ++frontPos;
+
+- player.m_fade = m_onionSkinMask.getFosOpacity(rows[i]);
+- if (player.m_fade == -1.0)
+- player.m_fade = m_onionSkinMask.getMosOpacity(rows[i] - row);
++ double fosFade = m_onionSkinMask.getFosOpacity(rows[i]);
++ double mosFade = m_onionSkinMask.getMosOpacity(rows[i] - row);
++ player.m_fade =
++ fosFade == -1.0
++ ? mosFade
++ : (mosFade == -1 ? fosFade : std::min(fosFade, mosFade));
+ #endif
+ player.m_dpiAff = getDpiAffine(level, fid2);
+ }
diff --git a/toonz/sources/include/toonz/onionskinmask.h b/toonz/sources/include/toonz/onionskinmask.h
index 8762237b1..ab3640e63 100644
--- a/toonz/sources/include/toonz/onionskinmask.h
+++ b/toonz/sources/include/toonz/onionskinmask.h
@@ -62,12 +62,12 @@ public:
int getMos(int index) const {
assert(0 <= index && index < (int)m_mos.size());
- return m_mos[index];
+ return m_mos[index].first;
}
int getFos(int index) const {
assert(0 <= index && index < (int)m_fos.size());
- return m_fos[index];
+ return m_fos[index].first;
}
void setMos(int drow, bool on); //!< Sets a Mobile OS frame shifted by drow
@@ -75,6 +75,13 @@ public:
void setFos(int row,
bool on); //!< Sets a Fixed OS frame to the specified xsheet row
+ //! Sets opacity in [0, 1], or -1 to use the automatic fade.
+ void setMosOpacity(int drow, double opacity);
+ double getMosOpacity(int drow) const;
+ //! Sets opacity in [0, 1], or -1 to use the automatic fade.
+ void setFosOpacity(int row, double opacity);
+ double getFosOpacity(int row) const;
+
bool isMos(int drow) const;
bool isFos(int row) const;
@@ -139,9 +146,16 @@ since underlying onion-skinned drawings must be visible.
void clearGhostFlipKey() { m_ghostFlipKeys.clear(); }
private:
- std::vector<int> m_fos, m_mos; //!< Fixed and Mobile Onion Skin indices
- bool m_enabled; //!< Whether onion skin is enabled
- bool m_wholeScene; //!< Whether the OS works on the entire scene
+ using Marker = std::pair<int, double>;
+ using MarkerList = std::vector<Marker>;
+
+ static MarkerList::iterator findMarker(MarkerList &markers, int position);
+ static MarkerList::const_iterator findMarker(const MarkerList &markers,
+ int position);
+
+ MarkerList m_fos, m_mos; //!< Fixed and Mobile Onion Skin markers
+ bool m_enabled; //!< Whether onion skin is enabled
+ bool m_wholeScene; //!< Whether the OS works on the entire scene
ShiftTraceStatus m_shiftTraceStatus;
bool m_showShiftOrigin;
diff --git a/toonz/sources/include/toonz/stageplayer.h b/toonz/sources/include/toonz/stageplayer.h
index 4c9fae120..a012ad02c 100644
--- a/toonz/sources/include/toonz/stageplayer.h
+++ b/toonz/sources/include/toonz/stageplayer.h
@@ -76,6 +76,7 @@ public:
int m_onionSkinDistance; //!< Temporal distance from an onion skin
//!'companion' (supposedly)
+ double m_onionSkinOpacity; //!< Custom onion skin opacity, or -1 for Auto
int m_ancestorColumnIndex; //!< Index of this object's hierarchycal root
//!(top-most column)
diff --git a/toonz/sources/toonz/xshrowviewer.cpp b/toonz/sources/toonz/xshrowviewer.cpp
index cb1a46f78..19fb8201d 100644
--- a/toonz/sources/toonz/xshrowviewer.cpp
+++ b/toonz/sources/toonz/xshrowviewer.cpp
@@ -8,6 +8,7 @@
#include "toonz/tonionskinmaskhandle.h"
#include "xsheetdragtool.h"
#include "toonzqt/gutil.h"
+#include "toonzqt/intfield.h"
#include "onionskinmaskgui.h"
#include "cellselection.h"
#include "menubarcommandids.h"
@@ -32,13 +33,203 @@
#include <QPainter>
#include <QMouseEvent>
+#include <QContextMenuEvent>
#include <QMenu>
#include <QToolTip>
+#include <QCheckBox>
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QSignalBlocker>
+#include <QSlider>
+#include <QVBoxLayout>
//=============================================================================
namespace XsheetGUI {
+//=============================================================================
+// OnionSkinOpacityPopup
+//-----------------------------------------------------------------------------
+
+OnionSkinOpacityPopup::OnionSkinOpacityPopup(QWidget *parent, bool vertical)
+ : QWidget(parent, Qt::Popup)
+ , m_slider(new QSlider(vertical ? Qt::Vertical : Qt::Horizontal, this))
+ , m_value(new DVGui::IntLineEdit(this, 1, 1, 100))
+ , m_autoCheckBox(new QCheckBox(tr("Auto"), this))
+ , m_marker(0)
+ , m_distance(0)
+ , m_isFixed(false)
+ , m_initializing(false) {
+ if (vertical) setMaximumWidth(75);
+
+ m_slider->setRange(1, 100);
+ m_autoCheckBox->setChecked(true);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->setContentsMargins(3, 3, 3, 3);
+ mainLayout->setHorizontalSpacing(6);
+ mainLayout->setVerticalSpacing(6);
+
+ if (vertical) {
+ QVBoxLayout *valueLayout = new QVBoxLayout;
+ valueLayout->setContentsMargins(0, 0, 0, 0);
+ valueLayout->setSpacing(3);
+ valueLayout->addWidget(new QLabel(tr("Opacity"), this), 0,
+ Qt::AlignHCenter);
+
+ QHBoxLayout *percentLayout = new QHBoxLayout;
+ percentLayout->setContentsMargins(0, 0, 0, 0);
+ percentLayout->setSpacing(3);
+ percentLayout->addStretch();
+ percentLayout->addWidget(m_value);
+ percentLayout->addWidget(new QLabel("%", this));
+ percentLayout->addStretch();
+
+ valueLayout->addLayout(percentLayout);
+ valueLayout->addWidget(m_slider, 0, Qt::AlignHCenter);
+ valueLayout->addWidget(m_autoCheckBox, 0, Qt::AlignHCenter);
+ mainLayout->addLayout(valueLayout, 0, 0);
+ } else {
+ mainLayout->addWidget(new QLabel(tr("Opacity:"), this), 0, 0,
+ Qt::AlignRight | Qt::AlignVCenter);
+ QHBoxLayout *valueLayout = new QHBoxLayout;
+ valueLayout->setContentsMargins(0, 0, 0, 0);
+ valueLayout->setSpacing(3);
+ valueLayout->addWidget(m_slider);
+ valueLayout->addWidget(m_value);
+ valueLayout->addWidget(new QLabel("%", this));
+ valueLayout->addWidget(m_autoCheckBox);
+ mainLayout->addLayout(valueLayout, 0, 1);
+ }
+
+ setLayout(mainLayout);
+
+ connect(m_slider, &QSlider::sliderReleased, this,
+ &OnionSkinOpacityPopup::commitOpacity);
+ connect(m_slider, &QSlider::sliderMoved, this,
+ &OnionSkinOpacityPopup::onSliderMoved);
+ connect(m_slider, &QSlider::valueChanged, this,
+ &OnionSkinOpacityPopup::onSliderValueChanged);
+ connect(m_value, &QLineEdit::textChanged, this,
+ &OnionSkinOpacityPopup::onValueChanged);
+ connect(m_autoCheckBox, &QCheckBox::clicked, this,
+ &OnionSkinOpacityPopup::onAutoClicked);
+}
+
+//-----------------------------------------------------------------------------
+
+void OnionSkinOpacityPopup::setMarker(int currentRow, int marker,
+ bool isFixed) {
+ OnionSkinMask mask =
+ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
+ int markerRow = isFixed ? marker : currentRow + marker;
+
+ m_marker = marker;
+ m_isFixed = isFixed;
+ m_distance = markerRow - currentRow;
+
+ if (Preferences::instance()->isAnimationSheetEnabled()) {
+ std::vector<int> rows;
+ mask.getAll(currentRow, rows);
+ std::vector<int>::iterator firstFront = rows.begin();
+ while (firstFront != rows.end() && *firstFront < currentRow) ++firstFront;
+ std::sort(rows.begin(), firstFront,
+ [](int first, int second) { return first > second; });
+
+ int frontDistance = 0;
+ int backDistance = 0;
+ for (int row : rows) {
+ int distance = row < currentRow ? --backDistance : ++frontDistance;
+ if (row == markerRow) {
+ m_distance = distance;
+ break;
+ }
+ }
+ }
+
+ double opacity = isFixed ? mask.getFosOpacity(marker)
+ : mask.getMosOpacity(marker);
+ bool automatic = opacity < 0.0;
+ if (automatic)
+ opacity = 1.0 - OnionSkinMask::getOnionSkinFade(m_distance);
+ int percent = tcrop(tround(opacity * 100.0), 1, 100);
+
+ m_initializing = true;
+ const QSignalBlocker sliderBlocker(m_slider);
+ const QSignalBlocker valueBlocker(m_value);
+ const QSignalBlocker autoBlocker(m_autoCheckBox);
+ m_slider->setValue(percent);
+ m_value->setText(QString::number(percent));
+ m_autoCheckBox->setChecked(automatic);
+ m_initializing = false;
+}
+
+//-----------------------------------------------------------------------------
+
+void OnionSkinOpacityPopup::commitOpacity() {
+ if (m_initializing) return;
+
+ OnionSkinMask mask =
+ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
+ double opacity =
+ m_autoCheckBox->isChecked() ? -1.0 : m_slider->value() / 100.0;
+ if (m_isFixed)
+ mask.setFosOpacity(m_marker, opacity);
+ else
+ mask.setMosOpacity(m_marker, opacity);
+
+ TOnionSkinMaskHandle *handle = TApp::instance()->getCurrentOnionSkin();
+ handle->setOnionSkinMask(mask);
+ handle->notifyOnionSkinMaskChanged();
+}
+
+//-----------------------------------------------------------------------------
+
+void OnionSkinOpacityPopup::onSliderMoved(int value) {
+ m_autoCheckBox->setChecked(false);
+ const QSignalBlocker valueBlocker(m_value);
+ m_value->setText(QString::number(value));
+ commitOpacity();
+}
+
+//-----------------------------------------------------------------------------
+
+void OnionSkinOpacityPopup::onSliderValueChanged(int value) {
+ if (m_initializing || m_slider->isSliderDown()) return;
+ m_autoCheckBox->setChecked(false);
+ const QSignalBlocker valueBlocker(m_value);
+ m_value->setText(QString::number(value));
+ commitOpacity();
+}
+
+//-----------------------------------------------------------------------------
+
+void OnionSkinOpacityPopup::onValueChanged(const QString &text) {
+ if (m_initializing) return;
+ m_autoCheckBox->setChecked(false);
+ const QSignalBlocker sliderBlocker(m_slider);
+ m_slider->setValue(text.toInt());
+ commitOpacity();
+}
+
+//-----------------------------------------------------------------------------
+
+void OnionSkinOpacityPopup::onAutoClicked(bool checked) {
+ if (m_initializing) return;
+ if (checked) {
+ int percent = tcrop(
+ tround((1.0 - OnionSkinMask::getOnionSkinFade(m_distance)) * 100.0),
+ 1, 100);
+ const QSignalBlocker sliderBlocker(m_slider);
+ const QSignalBlocker valueBlocker(m_value);
+ m_slider->setValue(percent);
+ m_value->setText(QString::number(percent));
+ }
+ commitOpacity();
+}
+
//=============================================================================
// RowArea
//-----------------------------------------------------------------------------
@@ -54,7 +245,8 @@ RowArea::RowArea(XsheetViewer *parent, Qt::WindowFlags flags)
, m_tooltip(tr(""))
, m_r0(0)
, m_r1(5)
- , m_isPanning(false) {
+ , m_isPanning(false)
+ , m_onionSkinOpacityPopup(nullptr) {
setFocusPolicy(Qt::NoFocus);
setMouseTracking(true);
connect(TApp::instance()->getCurrentOnionSkin(),
@@ -631,9 +823,11 @@ void RowArea::drawOnionSkinSelection(QPainter &p) {
if (m_showOnionToSet == Mos && currentRow + mos == m_row) continue;
p.setPen(mos < 0 ? backDotOutlineColor : frontDotOutlineColor);
- if (osMask.isEnabled())
- p.setBrush(mos < 0 ? backDotColor : frontDotColor);
- else
+ if (osMask.isEnabled()) {
+ QColor dotColor = mos < 0 ? backDotColor : frontDotColor;
+ if (osMask.getMosOpacity(mos) >= 0.0) dotColor = dotColor.darker(200);
+ p.setBrush(dotColor);
+ } else
p.setBrush(Qt::NoBrush);
QPoint topLeft = m_viewer->positionToXY(CellPosition(currentRow + mos, -1));
if (!m_viewer->orientation()->isVerticalTimeline())
@@ -659,13 +853,16 @@ void RowArea::drawOnionSkinSelection(QPainter &p) {
p.setPen(QColor(25, 118, 170, 255));
else
p.setPen(QColor(0, 255, 255, 128));
- if (osMask.isEnabled())
+ if (osMask.isEnabled()) {
// Depending on the brightness, make sure dot can be seen on onion area
+ QColor dotColor;
if (m_viewer->getOnionSkinAreaBgColor().value() > 128)
- p.setBrush(QBrush(QColor(0, 165, 255, 148)));
+ dotColor = QColor(0, 165, 255, 148);
else
- p.setBrush(QBrush(QColor(0, 255, 255, 148)));
- else
+ dotColor = QColor(0, 255, 255, 148);
+ if (osMask.getFosOpacity(fos) >= 0.0) dotColor = dotColor.darker(200);
+ p.setBrush(dotColor);
+ } else
p.setBrush(Qt::NoBrush);
QPoint topLeft = m_viewer->positionToXY(CellPosition(fos, -1));
if (!m_viewer->orientation()->isVerticalTimeline())
@@ -1322,10 +1519,21 @@ void RowArea::mouseMoveEvent(QMouseEvent *event) {
m_tooltip = tr("Double Click to Toggle Onion Skin");
else
m_tooltip = tr("Current Frame");
- } else if (m_showOnionToSet == Fos)
- m_tooltip = tr("Fixed Onion Skin Toggle");
- else if (m_showOnionToSet == Mos)
- m_tooltip = tr("Relative Onion Skin Toggle");
+ } else if (m_showOnionToSet == Fos) {
+ OnionSkinMask mask =
+ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
+ m_tooltip = mask.isFos(row)
+ ? tr("Fixed Onion Skin Toggle\n"
+ "Right-click to adjust opacity")
+ : tr("Fixed Onion Skin Toggle");
+ } else if (m_showOnionToSet == Mos) {
+ OnionSkinMask mask =
+ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
+ m_tooltip = mask.isMos(row - currentRow)
+ ? tr("Relative Onion Skin Toggle\n"
+ "Right-click to adjust opacity")
+ : tr("Relative Onion Skin Toggle");
+ }
}
//-----------------------------------------------------------------------------
@@ -1347,6 +1555,8 @@ void RowArea::mouseReleaseEvent(QMouseEvent *event) {
//-----------------------------------------------------------------------------
void RowArea::contextMenuEvent(QContextMenuEvent *event) {
+ if (showOnionSkinOpacityPopup(event)) return;
+
OnionSkinMask osMask =
TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
@@ -1425,6 +1635,52 @@ void RowArea::contextMenuEvent(QContextMenuEvent *event) {
menu->exec(event->globalPos());
}
+//-----------------------------------------------------------------------------
+
+bool RowArea::showOnionSkinOpacityPopup(QContextMenuEvent *event) {
+ if (CommandManager::instance()->getAction(MI_ShiftTrace)->isChecked() ||
+ !Preferences::instance()->isOnionSkinEnabled())
+ return false;
+
+ int currentRow = TApp::instance()->getCurrentFrame()->getFrame();
+ int row = m_viewer->xyToPosition(event->pos()).frame();
+ if (row < 0 || row == currentRow) return false;
+
+ const Orientation *orientation = m_viewer->orientation();
+ QPoint topLeft = m_viewer->positionToXY(CellPosition(row, -1));
+ if (orientation->isVerticalTimeline())
+ topLeft.setX(0);
+ else
+ topLeft.setY(0);
+
+ QPoint frameAdjustment = m_viewer->getFrameZoomAdjustment();
+ QPoint mouseInCell = event->pos() - topLeft;
+ auto containsMouse = [&](PredefinedRect rect) {
+ return orientation->rect(rect)
+ .adjusted(0, 0, -frameAdjustment.x(), -frameAdjustment.y())
+ .contains(mouseInCell);
+ };
+
+ OnionSkinMask mask =
+ TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
+ bool isFixed = containsMouse(PredefinedRect::ONION_FIXED_DOT_AREA);
+ int marker = isFixed ? row : row - currentRow;
+ bool markerExists =
+ isFixed ? mask.isFos(marker)
+ : containsMouse(PredefinedRect::ONION_DOT_AREA) &&
+ mask.isMos(marker);
+ if (!markerExists) return false;
+
+ if (!m_onionSkinOpacityPopup)
+ m_onionSkinOpacityPopup = new OnionSkinOpacityPopup(
+ this, !orientation->isVerticalTimeline());
+ m_onionSkinOpacityPopup->setMarker(currentRow, marker, isFixed);
+ m_onionSkinOpacityPopup->move(event->globalPos());
+ m_onionSkinOpacityPopup->show();
+ event->accept();
+ return true;
+}
+
//-----------------------------------------------------------------------------
// Checks if there is a cell non empty at current row and column to enable the
// auto markers item-menu.
diff --git a/toonz/sources/toonz/xshrowviewer.h b/toonz/sources/toonz/xshrowviewer.h
index 3b0fd956c..260dc32d5 100644
--- a/toonz/sources/toonz/xshrowviewer.h
+++ b/toonz/sources/toonz/xshrowviewer.h
@@ -8,11 +8,42 @@
// forward declaration
class XsheetViewer;
class QMenu;
+class QCheckBox;
+class QLineEdit;
+class QSlider;
namespace XsheetGUI {
class DragTool;
+//=============================================================================
+// OnionSkinOpacityPopup
+//-----------------------------------------------------------------------------
+
+class OnionSkinOpacityPopup final : public QWidget {
+ Q_OBJECT
+
+ QSlider *m_slider;
+ QLineEdit *m_value;
+ QCheckBox *m_autoCheckBox;
+ int m_marker;
+ int m_distance;
+ bool m_isFixed;
+ bool m_initializing;
+
+ void commitOpacity();
+
+public:
+ OnionSkinOpacityPopup(QWidget *parent, bool vertical);
+ void setMarker(int currentRow, int marker, bool isFixed);
+
+private slots:
+ void onSliderMoved(int value);
+ void onSliderValueChanged(int value);
+ void onValueChanged(const QString &text);
+ void onAutoClicked(bool checked);
+};
+
//=============================================================================
// RowArea
//-----------------------------------------------------------------------------
@@ -43,6 +74,7 @@ class RowArea final : public QWidget {
// panning by middle-drag
bool m_isPanning;
+ OnionSkinOpacityPopup *m_onionSkinOpacityPopup;
// returns true if the frame area can have extra space
bool checkExpandFrameArea();
@@ -71,6 +103,7 @@ class RowArea final : public QWidget {
// Return the number of the last non-empty cell found. You can set the
// direction of the search.
int getNonEmptyCell(int row, int column, Direction);
+ bool showOnionSkinOpacityPopup(QContextMenuEvent *event);
public:
RowArea(XsheetViewer *parent, Qt::WindowFlags flags = Qt::WindowFlags());
diff --git a/toonz/sources/toonzlib/onionskinmask.cpp b/toonz/sources/toonzlib/onionskinmask.cpp
index 0000031e0..ee7ea742c 100644
--- a/toonz/sources/toonzlib/onionskinmask.cpp
+++ b/toonz/sources/toonzlib/onionskinmask.cpp
@@ -74,71 +74,127 @@ void OnionSkinMask::getAll(int currentRow, std::vector<int> &output) const {
output.clear();
output.reserve(m_fos.size() + m_mos.size());
- std::vector<int>::const_iterator fosIt, fosEnd(m_fos.end());
- std::vector<int>::const_iterator mosIt, mosEnd(m_mos.end());
+ MarkerList::const_iterator fosIt, fosEnd(m_fos.end());
+ MarkerList::const_iterator mosIt, mosEnd(m_mos.end());
for (fosIt = m_fos.begin(), mosIt = m_mos.begin();
fosIt != fosEnd && mosIt != mosEnd;) {
- int fos = *fosIt, mos = *mosIt + currentRow;
+ int fos = fosIt->first, mos = mosIt->first + currentRow;
if (fos < mos) {
if (fos != currentRow) output.push_back(fos);
++fosIt;
- } else {
+ } else if (mos < fos) {
if (mos != currentRow) output.push_back(mos);
+ ++mosIt;
+ } else {
+ if (fos != currentRow) output.push_back(fos);
+ ++fosIt;
++mosIt;
}
}
for (; fosIt != fosEnd; ++fosIt)
- if (*fosIt != currentRow) output.push_back(*fosIt);
+ if (fosIt->first != currentRow) output.push_back(fosIt->first);
for (; mosIt != mosEnd; ++mosIt) {
- int mos = *mosIt + currentRow;
+ int mos = mosIt->first + currentRow;
if (mos != currentRow) output.push_back(mos);
}
}
//-------------------------------------------------------------------
+OnionSkinMask::MarkerList::iterator OnionSkinMask::findMarker(
+ MarkerList &markers, int position) {
+ return std::lower_bound(
+ markers.begin(), markers.end(), position,
+ [](const Marker &marker, int value) { return marker.first < value; });
+}
+
+//-------------------------------------------------------------------
+
+OnionSkinMask::MarkerList::const_iterator OnionSkinMask::findMarker(
+ const MarkerList &markers, int position) {
+ return std::lower_bound(
+ markers.begin(), markers.end(), position,
+ [](const Marker &marker, int value) { return marker.first < value; });
+}
+
+//-------------------------------------------------------------------
+
void OnionSkinMask::setMos(int drow, bool on) {
assert(drow != 0);
- typedef std::vector<int>::iterator Iter;
- std::pair<Iter, Iter> r = std::equal_range(m_mos.begin(), m_mos.end(), drow);
+ MarkerList::iterator marker = findMarker(m_mos, drow);
if (on) {
- if (r.first == r.second) m_mos.insert(r.first, drow);
+ if (marker == m_mos.end() || marker->first != drow)
+ m_mos.insert(marker, Marker(drow, -1.0));
} else {
- if (r.first != r.second) m_mos.erase(r.first, r.second);
+ if (marker != m_mos.end() && marker->first == drow) m_mos.erase(marker);
}
}
//-------------------------------------------------------------------
void OnionSkinMask::setFos(int row, bool on) {
- typedef std::vector<int>::iterator Iter;
- std::pair<Iter, Iter> r = std::equal_range(m_fos.begin(), m_fos.end(), row);
+ MarkerList::iterator marker = findMarker(m_fos, row);
if (on) {
- if (r.first == r.second) m_fos.insert(r.first, row);
+ if (marker == m_fos.end() || marker->first != row)
+ m_fos.insert(marker, Marker(row, -1.0));
} else {
- if (r.first != r.second) m_fos.erase(r.first, r.second);
+ if (marker != m_fos.end() && marker->first == row) m_fos.erase(marker);
}
}
//-------------------------------------------------------------------
+void OnionSkinMask::setMosOpacity(int drow, double opacity) {
+ assert(opacity == -1.0 || (opacity >= 0.0 && opacity <= 1.0));
+ MarkerList::iterator marker = findMarker(m_mos, drow);
+ if (marker != m_mos.end() && marker->first == drow)
+ marker->second = opacity;
+}
+
+//-------------------------------------------------------------------
+
+double OnionSkinMask::getMosOpacity(int drow) const {
+ MarkerList::const_iterator marker = findMarker(m_mos, drow);
+ return marker != m_mos.end() && marker->first == drow ? marker->second : -1.0;
+}
+
+//-------------------------------------------------------------------
+
+void OnionSkinMask::setFosOpacity(int row, double opacity) {
+ assert(opacity == -1.0 || (opacity >= 0.0 && opacity <= 1.0));
+ MarkerList::iterator marker = findMarker(m_fos, row);
+ if (marker != m_fos.end() && marker->first == row)
+ marker->second = opacity;
+}
+
+//-------------------------------------------------------------------
+
+double OnionSkinMask::getFosOpacity(int row) const {
+ MarkerList::const_iterator marker = findMarker(m_fos, row);
+ return marker != m_fos.end() && marker->first == row ? marker->second : -1.0;
+}
+
+//-------------------------------------------------------------------
+
bool OnionSkinMask::isFos(int row) const {
- return std::binary_search(m_fos.begin(), m_fos.end(), row);
+ MarkerList::const_iterator marker = findMarker(m_fos, row);
+ return marker != m_fos.end() && marker->first == row;
}
//-------------------------------------------------------------------
bool OnionSkinMask::isMos(int drow) const {
- return std::binary_search(m_mos.begin(), m_mos.end(), drow);
+ MarkerList::const_iterator marker = findMarker(m_mos, drow);
+ return marker != m_mos.end() && marker->first == drow;
}
//-------------------------------------------------------------------
@@ -148,7 +204,7 @@ bool OnionSkinMask::getMosRange(int &drow0, int &drow1) const {
drow0 = 0, drow1 = -1;
return false;
} else {
- drow0 = m_mos.front(), drow1 = m_mos.back();
+ drow0 = m_mos.front().first, drow1 = m_mos.back().first;
return true;
}
}
diff --git a/toonz/sources/toonzlib/stage.cpp b/toonz/sources/toonzlib/stage.cpp
index 0602a7294..71a3e37ca 100644
--- a/toonz/sources/toonzlib/stage.cpp
+++ b/toonz/sources/toonzlib/stage.cpp
@@ -117,6 +117,14 @@ void updateOnionSkinSize(const PlayerSet &players) {
bool descending(int i, int j) { return (i > j); }
+//----------------------------------------------------------------
+
+double getOnionSkinOpacity(const OnionSkinMask &mask, int row,
+ int currentRow) {
+ return std::max(mask.getFosOpacity(row),
+ mask.getMosOpacity(row - currentRow));
+}
+
//----------------------------------------------------------------
} // namespace
@@ -193,7 +201,7 @@ public:
std::vector<int> m_masks;
int m_onionSkinDistance;
- double m_fade;
+ double m_onionSkinOpacity;
ShiftTraceGhostId m_shiftTraceGhostId;
bool m_editingShift;
@@ -287,7 +295,7 @@ StageBuilder::StageBuilder()
, m_camera3d(false)
, m_currentColumnIndex(-1)
, m_ancestorColumnIndex(-1)
- , m_fade(0)
+ , m_onionSkinOpacity(-1.0)
, m_shiftTraceGhostId(NO_GHOST)
, m_editingShift(false)
, m_showShiftOrigin(false)
@@ -442,6 +450,7 @@ void StageBuilder::addCell(PlayerSet &players, ToonzScene *scene, TXsheet *xsh,
player.m_dpiAff = sl ? getDpiAffine(sl, cell.m_frameId) : TAffine();
player.m_onionSkinDistance = m_onionSkinDistance;
+ player.m_onionSkinOpacity = m_onionSkinOpacity;
// when visiting the subxsheet, valuate the subxsheet column index
bool isCurrent = (subSheetColIndex >= 0)
? (subSheetColIndex == m_currentColumnIndex)
@@ -666,19 +675,26 @@ void StageBuilder::addCellWithOnionSkin(PlayerSet &players, ToonzScene *scene,
#ifdef NUOVO_ONION
m_onionSkinDistance = rows[i] - row;
+ m_onionSkinOpacity =
+ getOnionSkinOpacity(m_onionSkinMask, rows[i], row);
+ addCell(players, scene, xsh, rows[i], col, level, subSheetColIndex);
#else
if (!Preferences::instance()->isAnimationSheetEnabled() ||
!alreadyAdded(xsh, row, i, rows, col)) {
m_onionSkinDistance = (rows[i] - row) < 0 ? --backPos : ++frontPos;
+ m_onionSkinOpacity =
+ getOnionSkinOpacity(m_onionSkinMask, rows[i], row);
addCell(players, scene, xsh, rows[i], col, level, subSheetColIndex);
}
#endif
}
m_onionSkinDistance = 0;
+ m_onionSkinOpacity = -1.0;
addCell(players, scene, xsh, row, col, level, subSheetColIndex);
m_onionSkinDistance = c_noOnionSkin;
+ m_onionSkinOpacity = -1.0;
} else
addCell(players, scene, xsh, row, col, level, subSheetColIndex);
}
@@ -761,6 +777,7 @@ void StageBuilder::addSimpleLevelFrame(PlayerSet &players,
player.m_guidedBackStroke = m_guidedBackStroke;
player.m_isVisibleinOSM = ghostRow >= 0;
player.m_onionSkinDistance = m_onionSkinDistance;
+ player.m_onionSkinOpacity = m_onionSkinOpacity;
player.m_dpiAff = getDpiAffine(level, ghostFid);
player.m_ancestorColumnIndex = -1;
@@ -845,6 +862,8 @@ void StageBuilder::addSimpleLevelFrame(PlayerSet &players,
#else
player.m_onionSkinDistance = rows[i] - row < 0 ? --backPos : ++frontPos;
#endif
+ player.m_onionSkinOpacity =
+ getOnionSkinOpacity(m_onionSkinMask, rows[i], row);
player.m_dpiAff = getDpiAffine(level, fid2);
}
}
diff --git a/toonz/sources/toonzlib/stageplayer.cpp b/toonz/sources/toonzlib/stageplayer.cpp
index e6e0d5d0c..323fdd29a 100644
--- a/toonz/sources/toonzlib/stageplayer.cpp
+++ b/toonz/sources/toonzlib/stageplayer.cpp
@@ -34,6 +34,7 @@ Stage::Player::Player()
, m_dpiAff()
, m_z(0)
, m_onionSkinDistance(c_noOnionSkin)
+ , m_onionSkinOpacity(-1.0)
, m_ancestorColumnIndex(-1)
, m_isCurrentColumn(false)
, m_isCurrentXsheetLevel(false)
diff --git a/toonz/sources/toonzlib/stagevisitor.cpp b/toonz/sources/toonzlib/stagevisitor.cpp
index 1ee4ea551..474433410 100644
--- a/toonz/sources/toonzlib/stagevisitor.cpp
+++ b/toonz/sources/toonzlib/stagevisitor.cpp
@@ -89,6 +89,15 @@ using namespace Stage;
namespace {
+double getOnionSkinOpacity(const Stage::Player &player) {
+ if (player.m_onionSkinDistance == 0) return 0.9;
+ if (player.m_onionSkinOpacity >= 0.0) return player.m_onionSkinOpacity;
+ return 1.0 -
+ OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance);
+}
+
+//----------------------------------------------------------------
+
QImage rasterToQImage(const TRaster32P &ras) {
QImage image(ras->getRawData(), ras->getLx(), ras->getLy(),
QImage::Format_ARGB32_Premultiplied);
@@ -937,10 +946,7 @@ void RasterPainter::onVectorImage(TVectorImage *vi,
double m[4] = {1.0, 1.0, 1.0, 1.0}, c[4];
// Weighted addition to RGB and matte multiplication
- m[3] = 1.0 -
- ((player.m_onionSkinDistance == 0)
- ? 0.1
- : OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance));
+ m[3] = getOnionSkinOpacity(player);
c[0] = (1.0 - m[3]) * bgColor.r, c[1] = (1.0 - m[3]) * bgColor.g,
c[2] = (1.0 - m[3]) * bgColor.b;
c[3] = 0.0;
@@ -1006,11 +1012,7 @@ void RasterPainter::onVectorImage(TVectorImage *vi,
double guidedM[4] = {1.0, 1.0, 1.0, 1.0}, guidedC[4];
TPixel32 bgColor = TPixel32::Blue;
- guidedM[3] =
- 1.0 -
- ((player.m_onionSkinDistance == 0)
- ? 0.1
- : OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance));
+ guidedM[3] = getOnionSkinOpacity(player);
guidedC[0] = (1.0 - guidedM[3]) * bgColor.r,
guidedC[1] = (1.0 - guidedM[3]) * bgColor.g,
@@ -1089,11 +1091,8 @@ void RasterPainter::onRasterImage(TRasterImage *ri,
// 1 opaque -> 0 completely transparent
// So I invert the result of the function, being careful about case 0
// (where the value 0.9 was carved)
- double onionSkiFade = player.m_onionSkinDistance == 0
- ? 0.9
- : (1.0 - OnionSkinMask::getOnionSkinFade(
- player.m_onionSkinDistance));
- alpha = tcrop(tround(onionSkiFade * 255.0), 0, 255);
+ double onionSkinOpacity = getOnionSkinOpacity(player);
+ alpha = tcrop(tround(onionSkinOpacity * 255.0), 0, 255);
if (player.m_isShiftAndTraceEnabled &&
!Preferences::instance()->areOnionColorsUsedForShiftAndTraceGhosts())
onionMode = Node::eOnionSkinNone;
@@ -1152,11 +1151,8 @@ void RasterPainter::onToonzImage(TToonzImage *ti, const Stage::Player &player) {
// I therefore reverse the result of the function by being attentive to
// case 0
// (where the value 0.9 was carved)
- double onionSkiFade = player.m_onionSkinDistance == 0
- ? 0.9
- : (1.0 - OnionSkinMask::getOnionSkinFade(
- player.m_onionSkinDistance));
- alpha = tcrop(tround(onionSkiFade * 255.0), 0, 255);
+ double onionSkinOpacity = getOnionSkinOpacity(player);
+ alpha = tcrop(tround(onionSkinOpacity * 255.0), 0, 255);
if (player.m_isShiftAndTraceEnabled &&
!Preferences::instance()->areOnionColorsUsedForShiftAndTraceGhosts())
@@ -1238,7 +1234,6 @@ void OpenGlPainter::onVectorImage(TVectorImage *vi,
}
TColorFunction *cf = 0;
- TOnionFader fader;
TPalette *vPalette = vi->getPalette();
@@ -1247,18 +1242,21 @@ void OpenGlPainter::onVectorImage(TVectorImage *vi,
// vPalette's mutex here...
if (player.m_onionSkinDistance != c_noOnionSkin) {
TPixel32 bgColor = TPixel32::White;
- fader = TOnionFader(
- bgColor, OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance));
- cf = &fader;
+ double opacity = getOnionSkinOpacity(player);
+ double m[4] = {1.0, 1.0, 1.0, opacity};
+ double c[4] = {(1.0 - opacity) * bgColor.r,
+ (1.0 - opacity) * bgColor.g,
+ (1.0 - opacity) * bgColor.b, 0.0};
+ cf = new TGenericColorFunction(m, c);
}
TVectorRenderData rd =
isViewer() ? TVectorRenderData(TVectorRenderData::ViewerSettings(),
m_viewAff * player.m_placement, m_clipRect,
- vPalette)
+ vPalette, cf)
: TVectorRenderData(TVectorRenderData::ProductionSettings(),
m_viewAff * player.m_placement, m_clipRect,
- vPalette);
+ vPalette, cf);
rd.m_alphaChannel = m_alphaEnabled;
rd.m_is3dView = m_camera3d;
@@ -1269,6 +1267,7 @@ void OpenGlPainter::onVectorImage(TVectorImage *vi,
tglDraw(rd, vi);
vPalette->setFrame(oldFrame);
+ delete cf;
}
//-----------------------------------------------------------------------------
@@ -1302,8 +1301,12 @@ void OpenGlPainter::onRasterImage(TRasterImage *ri,
r->lock();
if (c_noOnionSkin != player.m_onionSkinDistance) {
- double fade =
- 0.5 - 0.45 * (1 - 1 / (1 + 0.15 * abs(player.m_onionSkinDistance)));
+ double opacity =
+ player.m_onionSkinOpacity >= 0.0
+ ? player.m_onionSkinOpacity
+ : 0.5 - 0.45 *
+ (1 - 1 /
+ (1 + 0.15 * abs(player.m_onionSkinDistance)));
if ((int)matteChan.size() < r->getLx() * r->getLy())
matteChan.resize(r->getLx() * r->getLy());
@@ -1314,7 +1317,7 @@ void OpenGlPainter::onRasterImage(TRasterImage *ri,
while (pix < endPix) {
matteChan[k++] = pix->m;
- pix->m = (int)(pix->m * fade);
+ pix->m = (int)(pix->m * opacity);
pix++;
}
}
@@ -1572,8 +1575,7 @@ void onPlasticDeformedImage(TStageObject *playerObj,
const TPixel32 &refColor =
(player.m_onionSkinDistance < 0) ? backOnionColor : frontOnionColor;
- pixScale[3] =
- 1.0 - OnionSkinMask::getOnionSkinFade(player.m_onionSkinDistance);
+ pixScale[3] = getOnionSkinOpacity(player);
pixScale[0] =
(refColor.r / 255.0) * pixScale[3]; // refColor is not premultiplied
pixScale[1] = (refColor.g / 255.0) * pixScale[3];