Skip to content

Commit

Permalink
Misc code refactoring & cleanup for PR#1131 Iss978_flip_new
Browse files Browse the repository at this point in the history
- Refine UI texts
- Use QVector<int> as potentially better practices
- Variable init values & Function naming
  • Loading branch information
chchwy committed Feb 5, 2019
1 parent b554aa1 commit fe450b7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void MainWindow2::createMenus()
connect(pPlaybackManager, &PlaybackManager::playStateChanged, mTimeLine, &TimeLine::setPlaying);
connect(pPlaybackManager, &PlaybackManager::playStateChanged, this, &MainWindow2::changePlayState);
connect(pPlaybackManager, &PlaybackManager::playStateChanged, mEditor, &Editor::updateCurrentFrame);
connect(ui->actionFlip_inbetween, &QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipBtwn);
connect(ui->actionFlip_inbetween, &QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipInBetween);
connect(ui->actionFlip_rolling, &QAction::triggered, pPlaybackManager, &PlaybackManager::playFlipRoll);

connect(ui->actionAdd_Frame, &QAction::triggered, mCommands, &ActionCommands::addNewKey);
Expand Down
6 changes: 3 additions & 3 deletions app/ui/mainwindow2.ui
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -966,12 +966,12 @@
</action>
<action name="actionFlip_inbetween">
<property name="text">
<string>Flip inbetween</string>
<string>Flip In-Between</string>
</property>
</action>
<action name="actionFlip_rolling">
<property name="text">
<string>Flip rolling</string>
<string>Flip Rolling</string>
</property>
</action>
</widget>
Expand Down
4 changes: 2 additions & 2 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1976,10 +1976,10 @@ void ScribbleArea::setCurrentTool(ToolType eToolMode)

mPrevToolType = currentTool()->type();

// --- change cursor ---
// change cursor
setCursor(currentTool()->cursor());
updateCanvasCursor();
qDebug() << "fn: setCurrentTool " << "call: setCursor()" << "current tool" << currentTool()->typeName();
//qDebug() << "fn: setCurrentTool " << "call: setCursor()" << "current tool" << currentTool()->typeName();
}

void ScribbleArea::setTemporaryTool(ToolType eToolMode)
Expand Down
61 changes: 36 additions & 25 deletions core_lib/src/managers/playbackmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ bool PlaybackManager::init()
{
mTimer = new QTimer(this);
mTimer->setTimerType(Qt::PreciseTimer);

mFlipTimer = new QTimer(this);
mFlipTimer->setTimerType(Qt::PreciseTimer);

QSettings settings (PENCIL2D, PENCIL2D);
mFps = settings.value(SETTING_FPS).toInt();

Expand All @@ -53,13 +56,13 @@ bool PlaybackManager::init()

Status PlaybackManager::load(Object* o)
{
const ObjectData* e = o->data();
const ObjectData* data = o->data();

mIsLooping = e->isLooping();
mIsRangedPlayback = e->isRangedPlayback();
mMarkInFrame = e->getMarkInFrameNumber();
mMarkOutFrame = e->getMarkOutFrameNumber();
mFps = e->getFrameRate();
mIsLooping = data->isLooping();
mIsRangedPlayback = data->isRangedPlayback();
mMarkInFrame = data->getMarkInFrameNumber();
mMarkOutFrame = data->getMarkOutFrameNumber();
mFps = data->getFrameRate();

updateStartFrame();
updateEndFrame();
Expand Down Expand Up @@ -147,6 +150,7 @@ void PlaybackManager::stop()
void PlaybackManager::playFlipRoll()
{
if (isPlaying()) { return; }

int start = editor()->currentFrame();
int tmp = start;
mFlipList.clear();
Expand All @@ -157,44 +161,51 @@ void PlaybackManager::playFlipRoll()
int prev = editor()->layers()->currentLayer()->getPreviousKeyFramePosition(tmp);
if (prev < tmp)
{
mFlipList.prepend(QString::number(prev));
mFlipList.prepend(prev);
tmp = prev;
}
}
if (mFlipList.isEmpty()) { return; }

// run the roll...
mFlipRollInterval = settings.value(SETTING_FLIP_ROLL_MSEC).toInt();
mFlipList.append(QString::number(start));
mFlipList.append(start);
mFlipTimer->setInterval(mFlipRollInterval);
editor()->scrubTo(mFlipList[0].toInt());

editor()->scrubTo(mFlipList[0]);
mFlipTimer->start();
emit playStateChanged(true);
}

void PlaybackManager::playFlipBtwn()
void PlaybackManager::playFlipInBetween()
{
if (isPlaying()) { return; }

LayerManager* layerMgr = editor()->layers();
int start = editor()->currentFrame();
int prev = editor()->layers()->currentLayer()->getPreviousKeyFramePosition(start);
int next = editor()->layers()->currentLayer()->getNextKeyFramePosition(start);
if (editor()->layers()->currentLayer()->keyExists(prev) &&
editor()->layers()->currentLayer()->keyExists(next))

int prev = layerMgr->currentLayer()->getPreviousKeyFramePosition(start);
int next = layerMgr->currentLayer()->getNextKeyFramePosition(start);

if (layerMgr->currentLayer()->keyExists(prev) &&
layerMgr->currentLayer()->keyExists(next))
{
mFlipList.clear();
mFlipList.append(QString::number(prev));
mFlipList.append(QString::number(start));
mFlipList.append(QString::number(next));
mFlipList.append(QString::number(start));
mFlipList.append(prev);
mFlipList.append(start);
mFlipList.append(next);
mFlipList.append(start);
}
else
{
return;
}
// run the flip inbetween...
// run the flip in-between...
QSettings settings(PENCIL2D, PENCIL2D);
mFlipInbetweenInterval = settings.value(SETTING_FLIP_INBETWEEN_MSEC).toInt();

mFlipTimer->setInterval(mFlipInbetweenInterval);
editor()->scrubTo(mFlipList[0].toInt());
editor()->scrubTo(mFlipList[0]);
mFlipTimer->start();
emit playStateChanged(true);
}
Expand Down Expand Up @@ -308,12 +319,12 @@ void PlaybackManager::playSounds(int frame)

/**
* @brief PlaybackManager::skipFrame()
* Small errors will accumulate while playing animation
* If the error time is larger than a frame interval, skip a frame.
* Small errors accumulate while playing animation
* If the error is greater than a frame interval, skip a frame
*/
bool PlaybackManager::skipFrame()
{
// uncomment these debug output to see what happens
// uncomment these debug outputs to see what happens
//float expectedTime = (mPlayingFrameCounter) * (1000.f / mFps);
//qDebug("Expected: %.2f ms", expectedTime);
//qDebug("Actual: %d ms", mElapsedTimer->elapsed());
Expand Down Expand Up @@ -382,15 +393,15 @@ void PlaybackManager::timerTick()
void PlaybackManager::flipTimerTick()
{
int curr = editor()->currentFrame();
int pos = mFlipList.indexOf(QString::number(curr));
int pos = mFlipList.indexOf(curr);
if (pos == mFlipList.count() - 1)
{
mFlipTimer->stop();
emit playStateChanged(false);
}
else
{
editor()->scrubTo(mFlipList[pos + 1].toInt());
editor()->scrubTo(mFlipList[pos + 1]);
mFlipList.removeAt(pos);
}
}
Expand Down
14 changes: 8 additions & 6 deletions core_lib/src/managers/playbackmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GNU General Public License for more details.
#define PLAYBACKMANAGER_H

#include "basemanager.h"
#include <QVector>

class QTimer;
class QElapsedTimer;
Expand All @@ -42,7 +43,7 @@ class PlaybackManager : public BaseManager
void play();
void stop();
void playFlipRoll();
void playFlipBtwn();
void playFlipInBetween();

int fps() { return mFps; }
int startFrame() { return mStartFrame; }
Expand Down Expand Up @@ -88,18 +89,19 @@ class PlaybackManager : public BaseManager
int mActiveSoundFrame = 0;

int mFps = 12;
int mFlipRollInterval;
int mFlipInbetweenInterval;
int mFlipRollMax;

int mFlipRollInterval = 100;
int mFlipInbetweenInterval = 100;
int mFlipRollMax = 5;

QTimer* mTimer = nullptr;
QTimer* mFlipTimer = nullptr;
QElapsedTimer* mElapsedTimer = nullptr;
int mPlayingFrameCounter = 0; // how many frames has passed after pressing play

bool mCheckForSoundsHalfway = false;
QList<int> mListOfActiveSoundFrames;
QStringList mFlipList;
QVector<int> mListOfActiveSoundFrames;
QVector<int> mFlipList;
};

#endif // PLAYBACKMANAGER_H

0 comments on commit fe450b7

Please sign in to comment.