Skip to content

Commit

Permalink
Implement GUI to enable/disable multi layer onion skinning
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStevns committed Aug 21, 2024
1 parent 6ff03f0 commit cc486f0
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 32 deletions.
11 changes: 10 additions & 1 deletion app/src/onionskinwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void OnionSkinWidget::makeConnections()

connect(ui->onionSkinMode, &QCheckBox::stateChanged, this, &OnionSkinWidget::onionSkinModeChange);
connect(ui->onionWhilePlayback, &QCheckBox::stateChanged, this, &OnionSkinWidget::playbackStateChanged);
connect(ui->onionSkinMultiLayer, &QCheckBox::stateChanged, this, &OnionSkinWidget::onionSkinMultipleLayersEnabled);

PreferenceManager* prefs = editor()->preference();
connect(prefs, &PreferenceManager::optionChanged, this, &OnionSkinWidget::updateUI);
Expand Down Expand Up @@ -123,8 +124,10 @@ void OnionSkinWidget::updateUI()
ui->onionSkinMode->setChecked(prefs->getString(SETTING::ONION_TYPE) == "absolute");

QSignalBlocker b6(ui->onionWhilePlayback);
ui->onionWhilePlayback->setChecked(prefs->getInt(SETTING::ONION_WHILE_PLAYBACK));
ui->onionWhilePlayback->setChecked(prefs->isOn(SETTING::ONION_WHILE_PLAYBACK));

QSignalBlocker b7(ui->onionSkinMultiLayer);
ui->onionSkinMultiLayer->setChecked(prefs->isOn(SETTING::ONION_MUTLIPLE_LAYERS));
}

void OnionSkinWidget::prevFramesGroupClicked(bool isOn)
Expand Down Expand Up @@ -193,3 +196,9 @@ void OnionSkinWidget::playbackStateChanged(int value)
PreferenceManager* prefs = editor()->preference();
prefs->set(SETTING::ONION_WHILE_PLAYBACK, value);
}

void OnionSkinWidget::onionSkinMultipleLayersEnabled(bool value)
{
PreferenceManager* prefs = editor()->preference();
prefs->set(SETTING::ONION_MUTLIPLE_LAYERS, value);
}
1 change: 1 addition & 0 deletions app/src/onionskinwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private slots:
void onionPrevFramesNumChange(int);
void onionNextFramesNumChange(int);
void onionSkinModeChange(int);
void onionSkinMultipleLayersEnabled(bool value);

private:
void makeConnections();
Expand Down
14 changes: 14 additions & 0 deletions app/ui/onionskin.ui
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="onionSkinMultiLayer">
<property name="text">
<string>Show On All Layers</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="onionSkinMode">
<property name="text">
Expand Down
56 changes: 33 additions & 23 deletions core_lib/src/canvaspainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,32 +200,42 @@ void CanvasPainter::paint(const QRect& blitRect)
mPostLayersPixmapCacheValid = true;
}

void CanvasPainter::paintOnionSkin(QPainter& painter, const QRect& blitRect)
void CanvasPainter::paintOnionSkinOnLayer(QPainter& painter, const QRect& blitRect, Layer* layer)
{
for (int i = 0; i < mObject->getLayerCount(); i++) {
Layer* layer = mObject->getLayer(i);
if (layer == nullptr) { continue; }

if (!layer->visible()) { continue; }

mOnionSkinSubPainter.paint(painter, layer, mOnionSkinPainterOptions, mFrameNumber, [&] (OnionSkinPaintState state, int onionFrameNumber) {
if (state == OnionSkinPaintState::PREV) {
switch (layer->type())
{
case Layer::BITMAP: { paintBitmapOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizePrevFrames); break; }
case Layer::VECTOR: { paintVectorOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizePrevFrames); break; }
default: break;
}
mOnionSkinSubPainter.paint(painter, layer, mOnionSkinPainterOptions, mFrameNumber, [&] (OnionSkinPaintState state, int onionFrameNumber) {
if (state == OnionSkinPaintState::PREV) {
switch (layer->type())
{
case Layer::BITMAP: { paintBitmapOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizePrevFrames); break; }
case Layer::VECTOR: { paintVectorOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizePrevFrames); break; }
default: break;
}
if (state == OnionSkinPaintState::NEXT) {
switch (layer->type())
{
case Layer::BITMAP: { paintBitmapOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizeNextFrames); break; }
case Layer::VECTOR: { paintVectorOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizeNextFrames); break; }
default: break;
}
}
if (state == OnionSkinPaintState::NEXT) {
switch (layer->type())
{
case Layer::BITMAP: { paintBitmapOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizeNextFrames); break; }
case Layer::VECTOR: { paintVectorOnionSkinFrame(painter, blitRect, layer, onionFrameNumber, mOnionSkinPainterOptions.colorizeNextFrames); break; }
default: break;
}
});
}
});
}

void CanvasPainter::paintOnionSkin(QPainter& painter, const QRect& blitRect)
{
if (!mOptions.bOnionSkinMultiLayer || mOptions.eLayerVisibility == LayerVisibility::CURRENTONLY) {
Layer* layer = mObject->getLayer(mCurrentLayerIndex);
paintOnionSkinOnLayer(painter, blitRect, layer);
} else {
for (int i = 0; i < mObject->getLayerCount(); i++) {
Layer* layer = mObject->getLayer(i);

if (layer == nullptr) { continue; }
if (!layer->visible()) { continue; }

paintOnionSkinOnLayer(painter, blitRect, layer);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/canvaspainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct CanvasPainterOptions

LayerVisibility eLayerVisibility = LayerVisibility::RELATED;
float fLayerVisibilityThreshold = 0.f;
bool bOnionSkinMultiLayer = false;
float scaling = 1.0f;
QPainter::CompositionMode cmBufferBlendMode = QPainter::CompositionMode_SourceOver;
OnionSkinPainterOptions mOnionSkinOptions;
Expand Down Expand Up @@ -80,6 +81,7 @@ class CanvasPainter
*/
void initializePainter(QPainter& painter, QPaintDevice& device, const QRect& blitRect);

void paintOnionSkinOnLayer(QPainter& painter, const QRect& blitRect, Layer* layer);
void paintOnionSkin(QPainter& painter, const QRect& blitRect);

void renderPostLayers(QPainter& painter, const QRect& blitRect);
Expand Down
6 changes: 2 additions & 4 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ bool ScribbleArea::init()

mMakeInvisible = false;

mMultiLayerOnionSkin = mPrefs->isOn(SETTING::MULTILAYER_ONION);

mLayerVisibility = static_cast<LayerVisibility>(mPrefs->getInt(SETTING::LAYER_VISIBILITY));

mDeltaFactor = mEditor->preference()->isOn(SETTING::INVERT_SCROLL_ZOOM_DIRECTION) ? -1 : 1;
Expand Down Expand Up @@ -148,8 +146,7 @@ void ScribbleArea::settingUpdated(SETTING setting)
case SETTING::ONION_WHILE_PLAYBACK:
invalidateAllCache();
break;
case SETTING::MULTILAYER_ONION:
mMultiLayerOnionSkin = mPrefs->isOn(SETTING::MULTILAYER_ONION);
case SETTING::ONION_MUTLIPLE_LAYERS:
invalidateAllCache();
break;
case SETTING::LAYER_VISIBILITY_THRESHOLD:
Expand Down Expand Up @@ -1103,6 +1100,7 @@ void ScribbleArea::prepCanvas(int frame)
Object* object = mEditor->object();

CanvasPainterOptions o;
o.bOnionSkinMultiLayer = mPrefs->isOn(SETTING::ONION_MUTLIPLE_LAYERS);
o.bAntiAlias = mPrefs->isOn(SETTING::ANTIALIAS);
o.bThinLines = mPrefs->isOn(SETTING::INVISIBLE_LINES);
o.bOutlines = mPrefs->isOn(SETTING::OUTLINES);
Expand Down
1 change: 0 additions & 1 deletion core_lib/src/interface/scribblearea.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public slots:
LayerVisibility mLayerVisibility = LayerVisibility::ALL;
bool mMakeInvisible = false;
qreal mCurveSmoothingLevel = 0.0;
bool mMultiLayerOnionSkin = false; // Future use. If required, just add a checkbox to update it.
int mDeltaFactor = 1;

/* Under certain circumstances a mouse press event will fire after a tablet release event.
Expand Down
4 changes: 2 additions & 2 deletions core_lib/src/managers/preferencemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void PreferenceManager::loadPrefs()
// Onion Skin
set(SETTING::PREV_ONION, settings.value(SETTING_PREV_ONION, false).toBool());
set(SETTING::NEXT_ONION, settings.value(SETTING_NEXT_ONION, false).toBool());
set(SETTING::MULTILAYER_ONION, settings.value(SETTING_MULTILAYER_ONION, false).toBool());
set(SETTING::ONION_MUTLIPLE_LAYERS, settings.value(SETTING_MULTILAYER_ONION, false).toBool());
set(SETTING::ONION_BLUE, settings.value(SETTING_ONION_BLUE, false).toBool());
set(SETTING::ONION_RED, settings.value(SETTING_ONION_RED, false).toBool());

Expand Down Expand Up @@ -403,7 +403,7 @@ void PreferenceManager::set(SETTING option, bool value)
case SETTING::NEXT_ONION:
settings.setValue(SETTING_NEXT_ONION, value);
break;
case SETTING::MULTILAYER_ONION:
case SETTING::ONION_MUTLIPLE_LAYERS:
settings.setValue(SETTING_MULTILAYER_ONION, value);
break;
case SETTING::INVISIBLE_LINES:
Expand Down
2 changes: 1 addition & 1 deletion core_lib/src/util/preferencesdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum class SETTING
ONION_PREV_FRAMES_NUM,
ONION_NEXT_FRAMES_NUM,
ONION_WHILE_PLAYBACK,
ONION_MUTLIPLE_LAYERS,
ONION_TYPE,
FLIP_ROLL_MSEC,
FLIP_ROLL_DRAWINGS,
Expand Down Expand Up @@ -78,7 +79,6 @@ enum class SETTING
QUICK_SIZING,
INVERT_DRAG_ZOOM_DIRECTION,
INVERT_SCROLL_ZOOM_DIRECTION,
MULTILAYER_ONION,
LANGUAGE,
LAYOUT_LOCK,
DRAW_ON_EMPTY_FRAME_ACTION,
Expand Down

0 comments on commit cc486f0

Please sign in to comment.