From 666d6122952711723135349feed7623399618b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Borgese?= Date: Fri, 18 Apr 2008 17:43:00 +0000 Subject: [PATCH] Add wobblyness when opening windows. svn path=/trunk/KDE/kdebase/workspace/; revision=798624 --- effects/wobblywindows.cpp | 70 ++++++++++++++++++++++++++++++++++++--- effects/wobblywindows.h | 15 +++++++-- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/effects/wobblywindows.cpp b/effects/wobblywindows.cpp index 5196b20635..64b2d748d1 100644 --- a/effects/wobblywindows.cpp +++ b/effects/wobblywindows.cpp @@ -258,7 +258,7 @@ void WobblyWindowsEffect::windowUserMovedResized(EffectWindow* w, bool first, bo } WindowWobblyInfos& wwi = windows[w]; - wwi.onConstrain = true; + wwi.status = Moving; const QRectF& rect = w->geometry(); qreal x_increment = rect.width() / (wwi.width-1.0); @@ -288,11 +288,28 @@ void WobblyWindowsEffect::windowUserMovedResized(EffectWindow* w, bool first, bo if (windows.contains(w)) { WindowWobblyInfos& wwi = windows[w]; - wwi.onConstrain = false; + wwi.status = Moving; } } } +void WobblyWindowsEffect::windowAdded(EffectWindow* w) +{ + if(windows.contains(w)) + { + // could this happen ?? + WindowWobblyInfos& wwi = windows[w]; + wobblyOpenInit(wwi); + } + else + { + WindowWobblyInfos new_wwi; + initWobblyInfo(new_wwi, w->geometry()); + wobblyOpenInit(new_wwi); + windows[w] = new_wwi; + } +} + void WobblyWindowsEffect::windowClosed(EffectWindow* w) { if(windows.contains(w)) @@ -300,7 +317,52 @@ void WobblyWindowsEffect::windowClosed(EffectWindow* w) WindowWobblyInfos& wwi = windows[w]; freeWobblyInfo(wwi); windows.remove(w); + // wobblyCloseInit(new_wwi); + // w->refWindow(); } + //else + //{ + // WindowWobblyInfos new_wwi; + // initWobblyInfo(new_wwi, w->geometry()); + // wobblyCloseInit(new_wwi); + // windows[w] = new_wwi; + // w->refWindow(); + //} +} + +void WobblyWindowsEffect::wobblyOpenInit(WindowWobblyInfos& wwi) const +{ + Pair middle = wwi.origin[0]; + middle.x += wwi.origin[15].x; + middle.y += wwi.origin[15].y; + middle.x /= 2; + middle.y /= 2; + + for (unsigned int j=0; j<4; ++j) + { + for (unsigned int i=0; i<4; ++i) + { + unsigned int idx = j*4 + i; + wwi.constraint[idx] = false; + wwi.position[idx].x = (wwi.position[idx].x + 3*middle.x)/4; + wwi.position[idx].y = (wwi.position[idx].y + 3*middle.y)/4; + } + } + wwi.status = Openning; +} + +void WobblyWindowsEffect::wobblyCloseInit(WindowWobblyInfos& wwi) const +{ + // for closing, not yet used... + for (unsigned int j=0; j<4; ++j) + { + for (unsigned int i=0; i<4; ++i) + { + unsigned int idx = j*4 + i; + wwi.constraint[idx] = false; + } + } + wwi.status = Closing; } void WobblyWindowsEffect::initWobblyInfo(WindowWobblyInfos& wwi, QRect geometry) const @@ -322,7 +384,7 @@ void WobblyWindowsEffect::initWobblyInfo(WindowWobblyInfos& wwi, QRect geometry) wwi.bezierSurface = new Pair[wwi.bezierCount]; - wwi.onConstrain = true; + wwi.status = Moving; qreal x = geometry.x(), y = geometry.y(); qreal width = geometry.width(), height = geometry.height(); @@ -907,7 +969,7 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow* w, qreal time) kDebug() << "sum_acc : " << acc_sum << " *** sum_vel :" << vel_sum; #endif - if (!wwi.onConstrain && acc_sum < m_stopAcceleration && vel_sum < m_stopVelocity) + if (wwi.status != Moving && acc_sum < m_stopAcceleration && vel_sum < m_stopVelocity) { freeWobblyInfo(wwi); windows.remove(w); diff --git a/effects/wobblywindows.h b/effects/wobblywindows.h index bbbf9de6a5..88ed47fa7e 100644 --- a/effects/wobblywindows.h +++ b/effects/wobblywindows.h @@ -41,7 +41,8 @@ class WobblyWindowsEffect : public Effect virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); virtual void postPaintScreen(); virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last ); - virtual void windowClosed( EffectWindow* c ); + virtual void windowAdded( EffectWindow* w ); + virtual void windowClosed( EffectWindow* w ); // Wobbly model parameters void setRaideur(qreal raideur); @@ -64,6 +65,14 @@ class WobblyWindowsEffect : public Effect bool updateWindowWobblyDatas(EffectWindow* w, qreal time); + enum WindowStatus + { + Free, + Moving, + Openning, + Closing + }; + struct WindowWobblyInfos { Pair* origin; @@ -86,7 +95,7 @@ class WobblyWindowsEffect : public Effect unsigned int bezierHeight; unsigned int bezierCount; - bool onConstrain; + WindowStatus status; }; QHash< const EffectWindow*, WindowWobblyInfos > windows; @@ -115,6 +124,8 @@ class WobblyWindowsEffect : public Effect void initWobblyInfo(WindowWobblyInfos& wwi, QRect geometry) const; void freeWobblyInfo(WindowWobblyInfos& wwi) const; + void wobblyOpenInit(WindowWobblyInfos& wwi) const; + void wobblyCloseInit(WindowWobblyInfos& wwi) const; WobblyWindowsEffect::Pair computeBezierPoint(const WindowWobblyInfos& wwi, Pair point) const;