[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[e4-dev] Contacts Demo 'Fading' patch
|
Here's a patch that I cribbed from the
'FaderAnimationFeedback' in 3.5 that adds a slick 'cross fade' effect to
the CSS style switching. Try it out. ..;-).
Back to compatibility,
Eric
### Eclipse Workspace Patch 1.0
#P org.eclipse.e4.demo.contacts
Index: src/org/eclipse/e4/demo/contacts/handlers/ThemeUtil.java
===================================================================
RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/handlers/ThemeUtil.java,v
retrieving revision 1.4
diff -u -r1.4 ThemeUtil.java
--- src/org/eclipse/e4/demo/contacts/handlers/ThemeUtil.java 29 May 2009 12:04:15 -0000 1.4
+++ src/org/eclipse/e4/demo/contacts/handlers/ThemeUtil.java 8 Jun 2009 17:26:48 -0000
@@ -21,11 +21,55 @@
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.workbench.ui.IWorkbench;
import org.eclipse.e4.workbench.ui.internal.Workbench;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ThemeUtil {
+ private static Shell initAnimation(Shell baseShell) {
+ Rectangle psRect = baseShell.getBounds();
+ Shell animationShell = new Shell(baseShell, SWT.NO_TRIM | SWT.ON_TOP);
+ animationShell.setBounds(psRect);
+
+ // Capture the background image
+// long startTime = System.currentTimeMillis();
+ Image backingStore = new Image(animationShell.getDisplay(), psRect);
+ GC gc = new GC(baseShell.getDisplay());
+ gc.copyArea(backingStore, psRect.x, psRect.y);
+ gc.dispose();
+
+ animationShell.setAlpha(255);
+ animationShell.setBackgroundImage(backingStore);
+ animationShell.setVisible(true);
+// System.out.println("Capture time = " + (System.currentTimeMillis()- startTime)); //$NON-NLS-1$
+
+ return animationShell;
+ }
+
+ private static void runAnimation(Shell animationShell) {
+ Rectangle ab = animationShell.getBounds();
+ long area = ab.width * ab.height;
+
+ // Naive attempt to use fewer steps on large shells
+ int stepSize = 25;
+ if (area < 500000) stepSize = 10;
+ else if (area < 1000000) stepSize = 17;
+
+ // 'Fade' the animation shell
+ while (animationShell.getAlpha() > 0) {
+ int newAlpha = (int) (animationShell.getAlpha() - stepSize);
+ if (newAlpha < 0) newAlpha = 0;
+ animationShell.setAlpha(newAlpha);
+ animationShell.update();
+ }
+ animationShell.getBackgroundImage().dispose();
+ animationShell.dispose();
+ }
+
public static void switchTheme(IWorkbench workbench, final String css) {
if (workbench instanceof Workbench) {
Workbench wb = (Workbench) workbench;
@@ -40,12 +84,17 @@
URL url = FileLocator.resolve(new URL(
"platform:/plugin/org.eclipse.e4.demo.contacts/css/"
+ css));
+
+ Shell animationShell = initAnimation(shell);
InputStreamReader streamReader = new InputStreamReader(
url.openStream());
engine.reset();
engine.parseStyleSheet(streamReader);
engine.applyStyles(shell, true, false);
+ shell.update();
+
+ runAnimation(animationShell);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();