effects/fallapart: Port to DeformEffect

This commit is contained in:
Vlad Zahorodnii 2021-05-27 13:16:35 +03:00
parent 61d3134aa5
commit 8d378cd4cd
2 changed files with 14 additions and 13 deletions

View file

@ -18,7 +18,7 @@ namespace KWin
bool FallApartEffect::supported()
{
return effects->isOpenGLCompositing() && effects->animationsSupported();
return DeformEffect::supported() && effects->animationsSupported();
}
FallApartEffect::FallApartEffect()
@ -57,9 +57,8 @@ void FallApartEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data,
animationIt->progress += time / animationTime(1000.);
data.setTransformed();
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
// Request the window to be divided into cells
data.quads = data.quads.makeGrid(blockSize);
} else {
unredirect(w);
windows.remove(w);
w->unrefWindow();
}
@ -67,14 +66,16 @@ void FallApartEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data,
effects->prePaintWindow(w, data, presentTime);
}
void FallApartEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
void FallApartEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, WindowQuadList &quads)
{
Q_UNUSED(w)
auto animationIt = windows.constFind(w);
if (animationIt != windows.constEnd() && isRealWindow(w)) {
const qreal t = animationIt->progress;
WindowQuadList new_quads;
// Request the window to be divided into cells
quads = quads.makeGrid(blockSize);
int cnt = 0;
foreach (WindowQuad quad, data.quads) { // krazy:exclude=foreach
for (WindowQuad &quad : quads) {
// make fragments move in various directions, based on where
// they are (left pieces generally move to the left, etc.)
QPointF p1(quad[ 0 ].x(), quad[ 0 ].y());
@ -113,13 +114,10 @@ void FallApartEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Win
y = dist * sin(angle);
quad[ j ].move(center.x() + x, center.y() + y);
}
new_quads.append(quad);
++cnt;
}
data.quads = new_quads;
data.multiplyOpacity(interpolate(1.0, 0.0, t));
}
effects->paintWindow(w, mask, region, data);
}
void FallApartEffect::postPaintScreen()
@ -166,6 +164,7 @@ void FallApartEffect::slotWindowClosed(EffectWindow* c)
c->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
windows[ c ].progress = 0;
c->refWindow();
redirect(c);
}
void FallApartEffect::slotWindowDeleted(EffectWindow* c)
@ -188,6 +187,7 @@ void FallApartEffect::slotWindowDataChanged(EffectWindow* w, int role)
return;
}
unredirect(it.key());
it.key()->unrefWindow();
windows.erase(it);
}

View file

@ -10,7 +10,7 @@
#ifndef KWIN_FALLAPART_H
#define KWIN_FALLAPART_H
#include <kwineffects.h>
#include <kwindeformeffect.h>
namespace KWin
{
@ -21,8 +21,7 @@ struct FallApartAnimation
qreal progress = 0;
};
class FallApartEffect
: public Effect
class FallApartEffect : public DeformEffect
{
Q_OBJECT
Q_PROPERTY(int blockSize READ configuredBlockSize)
@ -31,7 +30,6 @@ public:
void reconfigure(ReconfigureFlags) override;
void prePaintScreen(ScreenPrePaintData& data, std::chrono::milliseconds presentTime) override;
void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, std::chrono::milliseconds presentTime) override;
void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) override;
void postPaintScreen() override;
bool isActive() const override;
@ -46,6 +44,9 @@ public:
static bool supported();
protected:
void deform(EffectWindow *w, int mask, WindowPaintData &data, WindowQuadList &quads) override;
public Q_SLOTS:
void slotWindowClosed(KWin::EffectWindow *c);
void slotWindowDeleted(KWin::EffectWindow *w);