From ee7f7eed4ed1544bd4ddc4ad92e8f3986e939947 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Fri, 17 May 2024 20:06:57 +0200 Subject: [PATCH] Force repaint in NativeGraphicsSource to fix broken animation When the FigureCanvas is created with SWT.DOUBLE_BUFFERED, animations are not painted correctly. This is because an instance of NativeGraphicsSource is used internally, which doesn't paint synchronously. Because the animation is done inside the UI thread, this paint operation is only processed after the animation is done. Resolves https://github.com/eclipse/gef-classic/issues/376 --- org.eclipse.draw2d/src/org/eclipse/draw2d/Animation.java | 2 +- .../src/org/eclipse/draw2d/NativeGraphicsSource.java | 5 ++++- .../org/eclipse/zest/tests/examples/AbstractGraphTest.java | 2 +- .../src/org/eclipse/zest/tests/examples/GraphSWTTests.java | 2 -- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/Animation.java b/org.eclipse.draw2d/src/org/eclipse/draw2d/Animation.java index 6893d0119..beab126da 100644 --- a/org.eclipse.draw2d/src/org/eclipse/draw2d/Animation.java +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/Animation.java @@ -251,7 +251,7 @@ public static void run() { * @since 3.2 */ public static void run(int duration) { - if (state == 0) { + if (state == 0 || state == PLAYBACK) { return; } try { diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/NativeGraphicsSource.java b/org.eclipse.draw2d/src/org/eclipse/draw2d/NativeGraphicsSource.java index f308d6414..2d2195e67 100644 --- a/org.eclipse.draw2d/src/org/eclipse/draw2d/NativeGraphicsSource.java +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/NativeGraphicsSource.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2024 IBM Corporation and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -56,6 +56,9 @@ public Graphics getGraphics(Rectangle r) { // canvas.update(); + // canvas.update() paints too much and only works on Windows. Use + // readAndDispatch() to only paint the redraw() event. + canvas.getDisplay().readAndDispatch(); return null; } diff --git a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/AbstractGraphTest.java b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/AbstractGraphTest.java index b357c3d6f..444b2b12b 100644 --- a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/AbstractGraphTest.java +++ b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/AbstractGraphTest.java @@ -129,7 +129,7 @@ private void doTest(Snippet annotation, Statement statement) throws Throwable { robot = new GraphicalRobot(graph); shell = graph.getShell(); // Wait for layout to be applied - waitEventLoop(0); + waitEventLoop(10); // Run the actual test statement.evaluate(); } catch (Throwable e) { diff --git a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphSWTTests.java b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphSWTTests.java index fa7cfc4dc..9b5fd6ea1 100644 --- a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphSWTTests.java +++ b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/examples/GraphSWTTests.java @@ -78,7 +78,6 @@ import org.eclipse.draw2d.Label; import org.eclipse.draw2d.geometry.Point; -import org.junit.Ignore; import org.junit.Test; /** @@ -110,7 +109,6 @@ protected boolean hasGraph(Lookup lookup, Snippet snippet) throws ReflectiveOper * @see here */ @Test - @Ignore @Snippet(type = AnimationSnippet.class) public void testAnimationSnippet() { AtomicInteger repaintCount = new AtomicInteger();