Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [e4-dev] Contacts Demo 'Fading' patch


Thanks Remy...here's an updated patch that explicitly checks whether the system supports 'advanced graphics' (ie.. setAlpha). While this won't fade on Fluxbox it shouldn't hang you up either...

<Chatzilla wit Remy determines that 'Fluxbox' needs even more help...;->

Here's a patch that should at least run without hanging on any box. Whether or not you see the fade effect will depend on whether 'setAlpha' works or not...YMMV (which is why I'm posting the patch)



Eric



Remy Chi Jian Suen <remy.suen@xxxxxxxxx>
Sent by: e4-dev-bounces@xxxxxxxxxxx

06/08/2009 02:27 PM

Please respond to
E4 Project developer mailing list <e4-dev@xxxxxxxxxxx>

To
E4 Project developer mailing list <e4-dev@xxxxxxxxxxx>
cc
Subject
Re: [e4-dev] Contacts Demo 'Fading' patch





On Mon, Jun 8, 2009 at 2:10 PM, Eric Moffatt<emoffatt@xxxxxxxxxx> wrote:
> 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.
> ..;-).

Note that if you use a Linux/gtk+ build and your window manager
doesn't support compositing (I use Fluxbox), you will be stuck in an
infinite loop because getAlpha() will always return 255. :)
http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-is-composited

Remy
_______________________________________________
e4-dev mailing list
e4-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/e4-dev

### 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 20:18:18 -0000
@@ -21,11 +21,72 @@
 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) {
+		GC gc = new GC(baseShell.getDisplay());
+		
+		// Ensure that the platform supports advanced graphics
+		gc.setAdvanced(true);
+		if (!gc.getAdvanced()) {
+			gc.dispose();
+			return null;
+		}
+		
+		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.setAdvanced(true);
+		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) {
+		if (animationShell == null)
+			return;
+		
+		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();
+			
+			// Special safety-check, some platforms lie about supporting advanced graphics..;-)
+			if (animationShell.getAlpha() == 255)
+				break;  // it's broken so this makes sense...;-)
+		}
+		animationShell.getBackgroundImage().dispose();
+		animationShell.dispose();
+	}
+	
 	public static void switchTheme(IWorkbench workbench, final String css) {
 		if (workbench instanceof Workbench) {
 			Workbench wb = (Workbench) workbench;
@@ -40,12 +101,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();

Back to the top