16#include "onionskinsubpainter.h"
22#include "onionskinpainteroptions.h"
24OnionSkinSubPainter::OnionSkinSubPainter()
28void OnionSkinSubPainter::paint(
QPainter& painter,
const Layer* layer,
const OnionSkinPainterOptions& options,
int frameIndex,
const std::function<
void(OnionSkinPaintState,
int)>& state)
const
30 if (!options.enabledWhilePlaying && options.isPlaying) {
return; }
32 if (layer->visible() ==
false)
35 if (layer->keyFrameCount() == 0)
38 qreal minOpacity =
static_cast<qreal
>(options.minOpacity / 100);
39 qreal maxOpacity =
static_cast<qreal
>(options.maxOpacity / 100);
41 if (options.skinPrevFrames && frameIndex >= 1)
44 qreal prevOpacityIncrement = (maxOpacity - minOpacity) / options.framesToSkinPrev;
45 qreal opacity = maxOpacity;
47 int onionFrameNumber = layer->getPreviousFrameNumber(frameIndex, options.isAbsolute);
48 KeyFrame* currentAbsoluteFrame = layer->getLastKeyFrameAtPosition(frameIndex);
49 int currentAbsoluteFrameNumber = currentAbsoluteFrame ? currentAbsoluteFrame->pos() : -1;
51 int onionPosition = 0;
52 while (onionPosition < options.framesToSkinPrev)
55 if (onionFrameNumber < 1) {
62 if (!options.isAbsolute || onionFrameNumber != currentAbsoluteFrameNumber) {
63 state(OnionSkinPaintState::PREV, onionFrameNumber);
64 opacity = opacity - prevOpacityIncrement;
68 onionFrameNumber = layer->getPreviousFrameNumber(onionFrameNumber, options.isAbsolute);
72 state(OnionSkinPaintState::CURRENT, frameIndex);
74 if (options.skinNextFrames)
77 qreal nextOpacityIncrement = (maxOpacity - minOpacity) / options.framesToSkinNext;
78 qreal opacity = maxOpacity;
80 int onionFrameNumber = layer->getNextFrameNumber(frameIndex, options.isAbsolute);
81 int onionPosition = 0;
83 while (onionPosition < options.framesToSkinNext && onionFrameNumber > 0)
87 state(OnionSkinPaintState::NEXT, onionFrameNumber);
88 opacity = opacity - nextOpacityIncrement;
90 onionFrameNumber = layer->getNextFrameNumber(onionFrameNumber, options.isAbsolute);
void setOpacity(qreal opacity)