Advanced Graphics flickering [message #455940] |
Mon, 23 May 2005 14:14  |
Eclipse User |
|
|
|
I saw that SWT 3.1M5 added support for some cool graphical stuff, some of
which I've been really waiting for in SWT. I tried the Snippet10 example,
and it worked fine out of the box. I wanted to test some animation, so I
added a simple timer to rotate the text, and that was when I noticed the
problem. As the text rotates, it flickers fairly badly. Has anyone else
noticed this? At this point, my company is deciding between SWT and
wxWidgets for this project, but we'd **much** rather use SWT if it can do
what we need.
Here's the code I was using (adapted from Snippet10):
/*
* Drawing with transformations, paths and alpha blending
*
* For a list of all SWT example snippets see
*
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import java.util.*;
public class GraphicsTest {
static int theta = 0;
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Advanced Graphics");
FontData fd = shell.getFont().getFontData()[0];
final Font font = new Font(display, fd.getName(), 60, SWT.BOLD |
SWT.ITALIC);
final Image image = new Image(display, 640, 480);
final Rectangle rect = image.getBounds();
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(rect.x, rect.y, rect.width, rect.height);
gc.dispose();
shell.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
GC gc = event.gc;
Transform tr = new Transform(display);
tr.translate(50, 120);
tr.rotate(theta);
gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width /
2, rect.height / 2);
gc.setAlpha(100);
gc.setTransform(tr);
Path path = new Path(display);
path.addString("SWT", 0, 0, font);
gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillPath(path);
gc.drawPath(path);
tr.dispose();
path.dispose();
}
});
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
theta = (theta+1)%360;
display.asyncExec(new Runnable() {
public void run() {
shell.redraw();
}
});
}
};
timer.scheduleAtFixedRate(timerTask, 0, 100);
shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
image.dispose();
font.dispose();
display.dispose();
}
}
|
|
|
|
|
|
|
Re: Advanced Graphics flickering [message #455989 is a reply to message #455950] |
Tue, 24 May 2005 11:43  |
Eclipse User |
|
|
|
Got the example working under Linux, but performance still blew. However,
upgrading to Cairo 0.4.0 worked MUCH better. As a word of warning to you
Gentoo users out there, Cairo 0.1.23 is probably not a very good choice,
so make sure you upgrade.
|
|
|
Powered by
FUDForum. Page generated in 0.05512 seconds