Skip to content

Commit

Permalink
Fix frame offset being incorrect for sound frames
Browse files Browse the repository at this point in the history
This was caused by offsetting using with recWidth instead of the normal frame width.
  • Loading branch information
MrStevns committed Mar 26, 2022
1 parent 34940a0 commit d93dc19
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions core_lib/src/interface/timelinecells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,20 @@ void TimeLineCells::paintFrames(QPainter& painter, QColor trackCol, const Layer*
painter.setPen(QPen(QBrush(QColor(40, 40, 40)), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));

int recTop = y + 1;
int recWidth = frameSize - 2;
int standardWidth = frameSize - 2;

int recHeight = height - 4;
layer->foreachKeyFrame([&](KeyFrame* key)
{
int framePos = key->pos();
int recLeft = getFrameX(framePos) - frameSize + 2;
int recWidth = standardWidth;
int recLeft = getFrameX(framePos) - recWidth;

if (key->length() > 1)
{
// This is especially for sound clips.
// Sound clips are the only type of KeyFrame with variable frame length.
recWidth = frameSize * key->length() - 2;
recWidth = frameSize * key->length();
}

// Paint the frame border
Expand Down Expand Up @@ -590,7 +592,7 @@ void TimeLineCells::paintFrames(QPainter& painter, QColor trackCol, const Layer*
});

if (!mMovingFrames && selected && mLayerPosMoveY != -1 && mLayerPosMoveY == mEditor->currentLayerIndex()) {
paintFrameCursorOnCurrentLayer(painter, recTop, recWidth, recHeight);
paintFrameCursorOnCurrentLayer(painter, recTop, standardWidth, recHeight);
}
}

Expand All @@ -614,8 +616,8 @@ void TimeLineCells::paintSelectedFrames(QPainter& painter, const Layer* layer, c
{
int mouseX = mMouseMoveX;
int posUnderCursor = getFrameNumber(mMousePressX);
int frameSize = mFrameSize;
int recWidth = frameSize - 2;
int standardWidth = mFrameSize - 2;
int recWidth = standardWidth;
int recHeight = mLayerHeight - 4;
int recTop = getLayerY(layerIndex) + 1;

Expand All @@ -627,7 +629,7 @@ void TimeLineCells::paintSelectedFrames(QPainter& painter, const Layer* layer, c
{
// This is a special case for sound clip.
// Sound clip is the only type of KeyFrame that has variable frame length.
recWidth = frameSize * key->length() - 2;
recWidth = mFrameSize * key->length();
}

painter.setBrush(QColor(60, 60, 60));
Expand All @@ -636,12 +638,12 @@ void TimeLineCells::paintSelectedFrames(QPainter& painter, const Layer* layer, c
int frameX = getFrameX(framePos);
if (mMovingFrames) {
int offset = (framePos - posUnderCursor) + mFrameOffset;
int newFrameX = getFrameX(getFrameNumber(getFrameX(offset)+mouseX))-recWidth;
int newFrameX = getFrameX(getFrameNumber(getFrameX(offset)+mouseX)) - standardWidth;
// Paint as frames are hovering
painter.drawRect(newFrameX, recTop-4, recWidth, recHeight);

} else {
int currentFrameX = frameX - recWidth;
int currentFrameX = frameX - standardWidth;
painter.drawRect(currentFrameX, recTop, recWidth, recHeight);
}
}
Expand Down

0 comments on commit d93dc19

Please sign in to comment.