summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <smspillaz@gmail.com>2010-08-05 00:31:03 +0800
committerSam Spilsbury <smspillaz@gmail.com>2010-08-05 00:31:03 +0800
commitbefecf7fdbf3172bd3315498a331f612cb35e19b (patch)
treef57162fa2ea29490b3b697aface6a8b4b21b82a9
parent9d715f18424650b6d7ec342b33e63dd030acb08b (diff)
downloadhoverfx-befecf7fdbf3172bd3315498a331f612cb35e19b.tar.gz
hoverfx-befecf7fdbf3172bd3315498a331f612cb35e19b.tar.bz2
Fix animation system and add smart function hooks
-rw-r--r--src/hoverfx.cpp122
-rw-r--r--src/hoverfx.h17
2 files changed, 89 insertions, 50 deletions
diff --git a/src/hoverfx.cpp b/src/hoverfx.cpp
index daa306e..e7b20a6 100644
--- a/src/hoverfx.cpp
+++ b/src/hoverfx.cpp
@@ -1,7 +1,26 @@
#include "hoverfx.h"
+#include <cmath>
COMPIZ_PLUGIN_20090315 (hoverfx, HoverPluginVTable);
+void
+HoverWindow::toggleFunctions (bool enabled)
+{
+ gWindow->glPaintSetEnabled (this, enabled);
+ cWindow->damageRectSetEnabled (this, enabled);
+
+ if (HoverScreen::get (screen)->mHoveredWindows.size ())
+ HoverScreen::get (screen)->toggleFunctions (true);
+}
+
+void
+HoverScreen::toggleFunctions (bool enabled)
+{
+ cScreen->preparePaintSetEnabled (this, enabled);
+ gScreen->glPaintOutputSetEnabled (this, enabled);
+ cScreen->donePaintSetEnabled (this, enabled);
+}
+
/* Returns true if it makes sense for this window to be animated on hover */
bool
HoverWindow::shouldAnimate ()
@@ -42,13 +61,11 @@ HoverScreen::handleEvent (XEvent *event)
{
HOVER_WINDOW (w);
- hw->mOldScale = 1.0f;
- hw->mTargetScale = 1.0f;
- hw->mAnimate = false;
- hw->mCurrentScale = 1.0f;
+ hw->mOld = hw->mCurrent;
+ hw->mTarget = 1.0f;
+ hw->mAnimate = true;
+ hw->toggleFunctions (true);
hw->cWindow->addDamage ();
-
- cScreen->damageScreen ();
}
}
case EnterNotify:
@@ -62,11 +79,11 @@ HoverScreen::handleEvent (XEvent *event)
HOVER_WINDOW (w);
hw->mAnimate = true;
- hw->mOldScale = hw->mCurrentScale;
- hw->mTargetScale = optionGetScaleFactor ();
+ hw->mOld = hw->mCurrent;
+ hw->mTarget = optionGetScaleFactor ();
hw->mIsHovered = true;
-
- cScreen->damageScreen ();
+ mHoveredWindows.push_back (w);
+ hw->toggleFunctions (true);
}
}
@@ -82,12 +99,11 @@ HoverScreen::handleEvent (XEvent *event)
HOVER_WINDOW (w);
hw->mAnimate = true;
- hw->mOldScale = hw->mCurrentScale;
- hw->mTargetScale = 1.0f;
+ hw->mOld = hw->mCurrent;
+ hw->mTarget = 1.0f;
+ hw->toggleFunctions (true);
hw->mIsHovered = false;
- cScreen->damageScreen ();
-
}
}
break;
@@ -105,23 +121,33 @@ HoverScreen::handleEvent (XEvent *event)
void
HoverScreen::preparePaint (int ms)
{
- foreach (CompWindow *w, screen->windows ())
+ CompWindowList::iterator it;
+
+ for (it = mHoveredWindows.begin (); it != mHoveredWindows.end (); it++)
{
+ CompWindow *w = *it;
+
HOVER_WINDOW (w);
if (hw->mAnimate)
{
- float chunk = ms;
- float inc;
+ float steps = (float) ms / (float) optionGetTime ();
+ if (steps < 0.05)
+ steps = 0.05;
- inc = chunk * (hw->mTargetScale - hw->mOldScale);
- if (hw->mCurrentScale + inc <= hw->mTargetScale)
- hw->mCurrentScale += inc;
- else
+ hw->mCurrent += steps * (hw->mTarget - hw->mCurrent);
+ if (fabsf (hw->mTarget - hw->mCurrent) < 0.005)
+ {
+ hw->mAnimate = false;
+ hw->mCurrent = hw->mTarget;
+ }
+ if (hw->mCurrent == 1.0f)
{
- hw->mCurrentScale = hw->mTargetScale;
hw->mAnimate = false;
+ mHoveredWindows.remove (w);
+ it = mHoveredWindows.begin ();
+ hw->toggleFunctions (false);
}
}
}
@@ -136,9 +162,8 @@ HoverScreen::glPaintOutput (const GLScreenPaintAttrib &attrib,
CompOutput *output,
unsigned int mask)
{
- foreach (CompWindow *w, screen->windows ())
- if (HoverWindow::get (w)->mIsHovered)
- mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK;
+ if (mHoveredWindows.size ())
+ mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK;
return gScreen->glPaintOutput (attrib, transform, region, output, mask);
@@ -150,7 +175,7 @@ HoverWindow::glPaint (const GLWindowPaintAttrib &attrib,
const CompRegion &region,
unsigned int mask)
{
- if (mIsHovered)
+ if (mIsHovered || mAnimate)
{
GLMatrix wTransform (transform);
GLWindowPaintAttrib wAttrib (attrib);
@@ -158,7 +183,7 @@ HoverWindow::glPaint (const GLWindowPaintAttrib &attrib,
wTransform.translate (window->inputRect ().centerX (),
window->inputRect ().centerY (),
0.0f);
- wTransform.scale (mCurrentScale, mCurrentScale, 1.0f);
+ wTransform.scale (mCurrent, mCurrent, 1.0f);
wTransform.translate (-window->inputRect ().centerX (),
-window->inputRect ().centerY (),
0.0f);
@@ -174,25 +199,32 @@ HoverWindow::glPaint (const GLWindowPaintAttrib &attrib,
void
HoverScreen::donePaint ()
-{
- foreach (CompWindow *w, screen->windows ())
- {
- if (HoverWindow::get (w)->mAnimate || HoverWindow::get (w)->mIsHovered)
+{
+ foreach (CompWindow *w, mHoveredWindows)
+ if (HoverWindow::get (w)->mAnimate)
CompositeWindow::get (w)->addDamage ();
- }
+
+ cScreen->donePaint ();
+
+ if (!mHoveredWindows.size ())
+ toggleFunctions (false);
}
bool
-HoverWindow::damageRect (bool initial,
- CompRect &rect)
+HoverWindow::damageRect (bool initial,
+ const CompRect &rect)
{
bool status = false;
- if (mCurrentScale != 1.0f)
+ if (mCurrent != 1.0f)
{
- cWindow->damageTransformedRect (mCurrentScale, mCurrentScale,
- rect.centerX (), rect.centerY (), rect);
- status = true;
+ float xTranslate, yTranslate;
+
+ xTranslate = (window->inputRect ().width () - window->inputRect ().width () * mCurrent);
+ yTranslate = (window->inputRect ().height () - window->inputRect ().height () * mCurrent);
+
+ cWindow->damageTransformedRect (mCurrent * 1.1, mCurrent * 1.1,
+ xTranslate / 2, yTranslate / 2, rect);
}
status |= cWindow->damageRect (initial, rect);
@@ -207,12 +239,12 @@ HoverWindow::HoverWindow (CompWindow *w) :
gWindow (GLWindow::get (w)),
mIsHovered (false),
mAnimate (false),
- mOldScale (1.0f),
- mCurrentScale (1.0f),
- mTargetScale (1.0f)
+ mOld (1.0f),
+ mCurrent (1.0f),
+ mTarget (1.0f)
{
- CompositeWindowInterface::setHandler (cWindow);
- GLWindowInterface::setHandler (gWindow);
+ CompositeWindowInterface::setHandler (cWindow, false);
+ GLWindowInterface::setHandler (gWindow, false);
}
HoverScreen::HoverScreen (CompScreen *s) :
@@ -221,8 +253,8 @@ HoverScreen::HoverScreen (CompScreen *s) :
gScreen (GLScreen::get (screen))
{
ScreenInterface::setHandler (screen);
- CompositeScreenInterface::setHandler (cScreen);
- GLScreenInterface::setHandler (gScreen);
+ CompositeScreenInterface::setHandler (cScreen, false);
+ GLScreenInterface::setHandler (gScreen, false);
}
bool
diff --git a/src/hoverfx.h b/src/hoverfx.h
index 6183670..6e216ab 100644
--- a/src/hoverfx.h
+++ b/src/hoverfx.h
@@ -16,9 +16,14 @@ class HoverScreen :
public:
HoverScreen (CompScreen *);
-
+
CompositeScreen *cScreen;
GLScreen *gScreen;
+
+ CompWindowList mHoveredWindows;
+
+ void
+ toggleFunctions (bool);
void
preparePaint (int);
@@ -57,9 +62,11 @@ class HoverWindow :
bool mIsHovered;
bool mAnimate;
- float mOldScale;
- float mCurrentScale;
- float mTargetScale;
+ float mOld;
+ float mCurrent;
+ float mTarget;
+
+ void toggleFunctions (bool);
bool shouldAnimate ();
@@ -70,7 +77,7 @@ class HoverWindow :
unsigned int);
bool
- damageRect (bool, CompRect &);
+ damageRect (bool, const CompRect &);
};
#define HOVER_WINDOW(w) \