Skip to content
Permalink
Browse files

Make sure there's always a frame to paint on

- This reworks the whole handleDrawingOnEmptyFrame by always making sure there's a frame to paint on. No matter which frame frame is selected, the user can always expect to draw on the canvas. If the first frame is empty and the action is "draw on previous keyframe" then a keyframe will be created. The same will happen for "duplicate previous keyframe" in case there's none. This should also eliminate other checks that requires there to be a keyframe because there will always be one now.
  • Loading branch information...
CandyFace committed Apr 19, 2019
1 parent fa4a27c commit c24487d739eb5291713539afd53234c13235a0ab
Showing with 16 additions and 77 deletions.
  1. +16 −66 core_lib/src/interface/scribblearea.cpp
  2. +0 −1 core_lib/src/interface/scribblearea.h
  3. +0 −10 core_lib/src/tool/polylinetool.cpp
@@ -464,15 +464,6 @@ void ScribbleArea::tabletEvent(QTabletEvent *e)

void ScribbleArea::pointerPressEvent(PointerEvent* event)
{
mIgnoreInput = false;
if (currentTool()->isDrawingTool()) {
if (!isKeyframeSane())
{
mIgnoreInput = true;
return;
}
}

if (event->button() & Qt::LeftButton || event->button() & Qt::RightButton)
{
mOffset = getCurrentOffset();
@@ -520,8 +511,6 @@ void ScribbleArea::pointerMoveEvent(PointerEvent* event)
{
updateCanvasCursor();

if (mIgnoreInput) { return; }

if (event->buttons() & (Qt::LeftButton | Qt::RightButton))
{
mOffset = getCurrentOffset();
@@ -546,8 +535,6 @@ void ScribbleArea::pointerMoveEvent(PointerEvent* event)

void ScribbleArea::pointerReleaseEvent(PointerEvent* event)
{
if (mIgnoreInput) { return; }

if (currentTool()->isAdjusting())
{
currentTool()->stopAdjusting();
@@ -586,37 +573,17 @@ void ScribbleArea::handleDoubleClick()

bool ScribbleArea::isLayerPaintable() const
{
if (!isKeyframeSane())
return false;

Layer* layer = mEditor->layers()->currentLayer();
if (layer == nullptr) { return false; }

return layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR;
}

bool ScribbleArea::isKeyframeSane() const
{
Layer* layer = mEditor->layers()->currentLayer();
// ---- checks ------
if (layer == nullptr) { return false; }

int action = mPrefs->getInt(SETTING::DRAW_ON_EMPTY_FRAME_ACTION);
KeyFrame* lastKeyframe = layer->getLastKeyFrameAtPosition(mEditor->currentFrame());
KeyFrame* currentKeyframe = layer->getKeyFrameAt(mEditor->currentFrame());

// the first frame has to exist to use this action
if (action == DUPLICATE_PREVIOUS_KEY) {
if (lastKeyframe == nullptr) { return false; }
}
if (currentKeyframe == nullptr) {
// We can assume keyframe is sane here because a
// keyframe will be created before drawing on the canvas.
if (action != (CREATE_NEW_KEY | DUPLICATE_PREVIOUS_KEY)) {
return false;
}
}

// ---- end checks ------

return true;
}

@@ -943,47 +910,30 @@ void ScribbleArea::handleDrawingOnEmptyFrame()

switch (action)
{
case CREATE_NEW_KEY:
mEditor->addNewKey();
mEditor->scrubTo(frameNumber); // Refresh timeline.

// Hack to clear previous frame's content.
if (layer->type() == Layer::BITMAP && previousKeyFrame)
{
auto asBitmapImage = dynamic_cast<BitmapImage *> (previousKeyFrame);

if (asBitmapImage)
{
drawCanvas(frameNumber, asBitmapImage->bounds());
}
}

if (layer->type() == Layer::VECTOR)
{
auto asVectorImage = dynamic_cast<VectorImage *> (previousKeyFrame);

if (asVectorImage)
{
auto copy(*asVectorImage);
copy.selectAll();

drawCanvas(frameNumber, copy.getSelectionRect().toRect());
}
case KEEP_DRAWING_ON_PREVIOUS_KEY:
{
if (previousKeyFrame == nullptr) {
mEditor->addNewKey();
}

break;
}
case DUPLICATE_PREVIOUS_KEY:
{
if (previousKeyFrame)
{
KeyFrame* dupKey = previousKeyFrame->clone();
layer->addKeyFrame(frameNumber, dupKey);
mEditor->scrubTo(frameNumber); // Refresh timeline.
mEditor->scrubTo(frameNumber);
break;
}
break;
// if the previous keyframe doesn't exist,
// fallthrough and create empty keyframe
}
case KEEP_DRAWING_ON_PREVIOUS_KEY:
// No action needed.
case CREATE_NEW_KEY:
mEditor->addNewKey();

// Refresh canvas
drawCanvas(frameNumber, mCanvas.rect());
break;
default:
break;
@@ -245,7 +245,6 @@ public slots:
bool mMouseInUse = false;
bool mMouseRightButtonInUse = false;
bool mPenHeldDown = false;
bool mIgnoreInput = false;

// Double click handling for tablet input
void handleDoubleClick();
@@ -180,11 +180,6 @@ bool PolylineTool::keyPressEvent(QKeyEvent* event)

void PolylineTool::drawPolyline(QList<QPointF> points, QPointF endPoint)
{
if (!mScribbleArea->isKeyframeSane())
{
return;
}

if (points.size() > 0)
{
QPen pen(mEditor->color()->frontColor(),
@@ -238,11 +233,6 @@ void PolylineTool::cancelPolyline()

void PolylineTool::endPolyline(QList<QPointF> points)
{
if (!mScribbleArea->isKeyframeSane())
{
return;
}

Layer* layer = mEditor->layers()->currentLayer();

if (layer->type() == Layer::VECTOR)

0 comments on commit c24487d

Please sign in to comment.
You can’t perform that action at this time.