Skip to content

Commit

Permalink
Default and setting Interpolations (#2344)
Browse files Browse the repository at this point in the history
* Add default interpolation options
* Add interpolation options to xsheet context menu
  • Loading branch information
manongjohn authored and shun-iwasawa committed Dec 19, 2018
1 parent cfa6ff1 commit 63e2882
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 14 deletions.
35 changes: 26 additions & 9 deletions toonz/sources/toonz/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,23 @@ void MainWindow::defineActions() {
createRightClickMenuAction(MI_ResetInterpolation, tr("Reset Interpolation"),
"");

createRightClickMenuAction(MI_UseLinearInterpolation,
tr("Linear Interpolation"), "");
createRightClickMenuAction(MI_UseSpeedInOutInterpolation,
tr("Speed In / Speed Out Interpolation"), "");
createRightClickMenuAction(MI_UseEaseInOutInterpolation,
tr("Ease In / Ease Out Interpolation"), "");
createRightClickMenuAction(MI_UseEaseInOutPctInterpolation,
tr("Ease In / Ease Out (%) Interpolation"), "");
createRightClickMenuAction(MI_UseExponentialInterpolation,
tr("Exponential Interpolation"), "");
createRightClickMenuAction(MI_UseExpressionInterpolation,
tr("Expression Interpolation"), "");
createRightClickMenuAction(MI_UseFileInterpolation, tr("File Interpolation"),
"");
createRightClickMenuAction(MI_UseConstantInterpolation,
tr("Constant Interpolation"), "");

createRightClickMenuAction(MI_FoldColumns, tr("Fold Column"), "");

createRightClickMenuAction(MI_ActivateThisColumnOnly, tr("Show This Only"),
Expand Down Expand Up @@ -2315,9 +2332,9 @@ RecentFiles::~RecentFiles() {}

void RecentFiles::addFilePath(QString path, FileType fileType) {
QList<QString> files =
(fileType == Scene)
? m_recentScenes
: (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
(fileType == Scene) ? m_recentScenes : (fileType == Level)
? m_recentLevels
: m_recentFlipbookImages;
int i;
for (i = 0; i < files.size(); i++)
if (files.at(i) == path) files.removeAt(i);
Expand Down Expand Up @@ -2442,9 +2459,9 @@ void RecentFiles::saveRecentFiles() {

QList<QString> RecentFiles::getFilesNameList(FileType fileType) {
QList<QString> files =
(fileType == Scene)
? m_recentScenes
: (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
(fileType == Scene) ? m_recentScenes : (fileType == Level)
? m_recentLevels
: m_recentFlipbookImages;
QList<QString> names;
int i;
for (i = 0; i < files.size(); i++) {
Expand All @@ -2471,9 +2488,9 @@ void RecentFiles::refreshRecentFilesMenu(FileType fileType) {
menu->setEnabled(false);
else {
CommandId clearActionId =
(fileType == Scene)
? MI_ClearRecentScene
: (fileType == Level) ? MI_ClearRecentLevel : MI_ClearRecentImage;
(fileType == Scene) ? MI_ClearRecentScene : (fileType == Level)
? MI_ClearRecentLevel
: MI_ClearRecentImage;
menu->setActions(names);
menu->addSeparator();
QAction *clearAction = CommandManager::instance()->getAction(clearActionId);
Expand Down
9 changes: 9 additions & 0 deletions toonz/sources/toonz/menubarcommandids.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@
#define MI_SetConstantSpeed "MI_SetConstantSpeed"
#define MI_ResetInterpolation "MI_ResetInterpolation"

#define MI_UseLinearInterpolation "MI_UseLinearInterpolation"
#define MI_UseSpeedInOutInterpolation "MI_UseSpeedInOutInterpolation"
#define MI_UseEaseInOutInterpolation "MI_UseEaseInOutInterpolation"
#define MI_UseEaseInOutPctInterpolation "MI_UseEaseInOutPctInterpolation"
#define MI_UseExponentialInterpolation "MI_UseExponentialInterpolation"
#define MI_UseExpressionInterpolation "MI_UseExpressionInterpolation"
#define MI_UseFileInterpolation "MI_UseFileInterpolation"
#define MI_UseConstantInterpolation "MI_UseConstantInterpolation"

#define MI_ActivateThisColumnOnly "MI_ActivateThisColumnOnly"
#define MI_ActivateSelectedColumns "MI_ActivateSelectedColumns"
#define MI_ActivateAllColumns "MI_ActivateAllColumns"
Expand Down
9 changes: 5 additions & 4 deletions toonz/sources/toonz/preferencespopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ void PreferencesPopup::onStartupPopupChanged(int index) {
//-----------------------------------------------------------------------------

void PreferencesPopup::onKeyframeTypeChanged(int index) {
m_pref->setKeyframeType(index + 2);
m_pref->setKeyframeType(index + 1);
}
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -1888,11 +1888,12 @@ PreferencesPopup::PreferencesPopup()

//--- Animation ------------------------------
QStringList list;
list << tr("Linear") << tr("Speed In / Speed Out") << tr("Ease In / Ease Out")
<< tr("Ease In / Ease Out %");
list << tr("Constant") << tr("Linear") << tr("Speed In / Speed Out")
<< tr("Ease In / Ease Out") << tr("Ease In / Ease Out %")
<< tr("Exponential") << tr("Expression ") << tr("File");
m_keyframeType->addItems(list);
int keyframeType = m_pref->getKeyframeType();
m_keyframeType->setCurrentIndex(keyframeType - 2);
m_keyframeType->setCurrentIndex(keyframeType - 1);
m_animationStepField->setValue(m_pref->getAnimationStep());

//--- Preview ------------------------------
Expand Down
26 changes: 25 additions & 1 deletion toonz/sources/toonz/xshcellviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3389,6 +3389,7 @@ void CellArea::createKeyLineMenu(QMenu &menu, int row, int col) {
menu.addAction(cmdManager->getAction(MI_SetAcceleration));
menu.addAction(cmdManager->getAction(MI_SetDeceleration));
menu.addAction(cmdManager->getAction(MI_SetConstantSpeed));
menu.addSeparator();
} else {
// Se le due chiavi non sono linear aggiungo il comando ResetInterpolation
bool isR0FullK = pegbar->isFullKeyframe(r0);
Expand All @@ -3398,9 +3399,32 @@ void CellArea::createKeyLineMenu(QMenu &menu, int row, int col) {
TDoubleKeyframe::Type r1Type =
pegbar->getParam(TStageObject::T_X)->getKeyframeAt(r1).m_prevType;
if (isGlobalKeyFrameWithSameTypeDiffFromLinear(pegbar, r0) &&
isGlobalKeyFrameWithSamePrevTypeDiffFromLinear(pegbar, r1))
isGlobalKeyFrameWithSamePrevTypeDiffFromLinear(pegbar, r1)) {
menu.addAction(cmdManager->getAction(MI_ResetInterpolation));
menu.addSeparator();
}
}

TDoubleKeyframe::Type rType =
pegbar->getParam(TStageObject::T_X)->getKeyframeAt(r0).m_type;

if (rType != TDoubleKeyframe::Linear)
menu.addAction(cmdManager->getAction(MI_UseLinearInterpolation));
if (rType != TDoubleKeyframe::SpeedInOut)
menu.addAction(cmdManager->getAction(MI_UseSpeedInOutInterpolation));
if (rType != TDoubleKeyframe::EaseInOut)
menu.addAction(cmdManager->getAction(MI_UseEaseInOutInterpolation));
if (rType != TDoubleKeyframe::EaseInOutPercentage)
menu.addAction(cmdManager->getAction(MI_UseEaseInOutPctInterpolation));
if (rType != TDoubleKeyframe::Exponential)
menu.addAction(cmdManager->getAction(MI_UseExponentialInterpolation));
if (rType != TDoubleKeyframe::Expression)
menu.addAction(cmdManager->getAction(MI_UseExpressionInterpolation));
if (rType != TDoubleKeyframe::File)
menu.addAction(cmdManager->getAction(MI_UseFileInterpolation));
if (rType != TDoubleKeyframe::Constant)
menu.addAction(cmdManager->getAction(MI_UseConstantInterpolation));

#ifdef LINETEST
menu.addSeparator();
int paramStep = getParamStep(pegbar, r0);
Expand Down
57 changes: 57 additions & 0 deletions toonz/sources/toonz/xsheetcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,63 @@ class ResetArrowCommand final : public MenuItemHandler {

} ResetArrowCommand;

//-----------------------------------------------------------------------------
// Unify commands for all types of interpolation
class SetInterpolation final : public MenuItemHandler {
TDoubleKeyframe::Type m_type;

public:
SetInterpolation(CommandId cmdId, TDoubleKeyframe::Type type)
: MenuItemHandler(cmdId), m_type(type) {}

void execute() override {
TApp *app = TApp::instance();
TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
int row = app->getCurrentFrame()->getFrame();

TStageObjectId objectId = app->getCurrentObject()->getObjectId();
TStageObject *pegbar = xsh->getStageObject(objectId);
if (!pegbar) return;

int r0, r1;
double ease0, ease1;

pegbar->getKeyframeSpan(row, r0, ease0, r1, ease1);

KeyFrameHandleCommandUndo *undo =
new KeyFrameHandleCommandUndo(objectId, r0, r1);

TStageObject::Keyframe k0 = pegbar->getKeyframe(r0);
TStageObject::Keyframe k1 = pegbar->getKeyframe(r1);

for (int i = 0; i < TStageObject::T_ChannelCount; i++) {
k0.m_channels[i].m_type = m_type;
k1.m_channels[i].m_prevType = m_type;
}
pegbar->setKeyframeWithoutUndo(r0, k0);
pegbar->setKeyframeWithoutUndo(r1, k1);

TUndoManager::manager()->add(undo);

TApp::instance()->getCurrentScene()->setDirtyFlag(true);
TApp::instance()->getCurrentObject()->notifyObjectIdChanged(false);
}

} UseLinearInterpolation(MI_UseLinearInterpolation, TDoubleKeyframe::Linear),
UseSpeedInOutInterpolation(MI_UseSpeedInOutInterpolation,
TDoubleKeyframe::SpeedInOut),
UseEaseInOutInterpolation(MI_UseEaseInOutInterpolation,
TDoubleKeyframe::EaseInOut),
UseEaseInOutPctInterpolation(MI_UseEaseInOutPctInterpolation,
TDoubleKeyframe::EaseInOutPercentage),
UseExponentialInterpolation(MI_UseExponentialInterpolation,
TDoubleKeyframe::Exponential),
UseExpressionInterpolation(MI_UseExpressionInterpolation,
TDoubleKeyframe::Expression),
UseFileInterpolation(MI_UseFileInterpolation, TDoubleKeyframe::File),
UseConstantInterpolation(MI_UseConstantInterpolation,
TDoubleKeyframe::Constant);

//===========================================================
// To Be Reworked
//===========================================================
Expand Down

0 comments on commit 63e2882

Please sign in to comment.