[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: Draw outside clip
|
- From: Michael Szediwy <michael@xxxxxxxxxx>
- Date: Fri, 09 May 2008 10:08:58 +0200
- Newsgroups: eclipse.platform.swt
- Organization: EclipseCorner
- User-agent: Thunderbird 2.0.0.14 (Windows/20080421)
Here is an example:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Slider;
public class Test {
private Slider slider;
private Canvas canvas;
private class MyPaintListener implements PaintListener {
public void paintControl (PaintEvent e) {
Point center= canvas.getSize();
int scale= 100;
long now= System.currentTimeMillis();
int val= slider.getSelection();
val*= val;
e.gc.setLineWidth(3);
e.gc.setLineStyle(SWT.LINE_DOT);
e.gc.drawLine(center.x / 2 - scale * val, center.y / 2 + scale * val,
center.x / 2 + scale * val, center.y / 2 - scale * val);
System.out.println("Took " + (System.currentTimeMillis() - now) + ", "
+ (scale * val));
}
};
public void createControl (Composite parent) {
GridData gridData1= new GridData();
gridData1.horizontalAlignment= GridData.FILL;
gridData1.grabExcessHorizontalSpace= true;
gridData1.verticalAlignment= GridData.CENTER;
createCanvas(parent);
parent.setLayout(new GridLayout());
slider= new Slider(parent, SWT.NONE);
slider.setLayoutData(gridData1);
slider.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected (SelectionEvent e) {
System.out.println("there");
}
public void widgetSelected (SelectionEvent e) {
System.out.println("hi " + slider.getSelection());
canvas.redraw();
canvas.redraw();
canvas.redraw();
canvas.redraw();
canvas.redraw();
}
});
}
private void createCanvas (Composite parent) {
GridData gridData= new GridData();
gridData.horizontalAlignment= GridData.FILL;
gridData.grabExcessHorizontalSpace= true;
gridData.grabExcessVerticalSpace= true;
gridData.verticalAlignment= GridData.FILL;
canvas= new Canvas(parent, SWT.NONE);
canvas.setLayoutData(gridData);
canvas.addPaintListener(new MyPaintListener());
}
public static void main (String[] args) {
Display display= new Display();
Shell shell= new Shell(display);
shell.setSize(500, 400);
shell.setLayout(new GridLayout());
Test test= new Test();
test.createControl(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
Michael Szediwy wrote:
Hi,
this is a stupid question, maybe. If I draw a polyline on a canvas with
a certain size (maybe 50000 pixel) whose points lie outside the
clipping area the whole application begins to hang. I'm testing on a
Windows XP machine.
Is anything known about such problems?
Cheers
Michael