Converting points using 'toControl' and 'toDisplay' gives wrong location on ubuntu10.10 [message #668033] |
Tue, 03 May 2011 13:18 |
atieq.rehman Messages: 12 Registered: March 2010 |
Junior Member |
|
|
drawing some image/control with Spinner while extracting relative location of image/control by using toDisplay and toControl function works fine on windows but wrongly display the controls on ubuntu 10.10 platform
sample output for both platforms is
http://img197.imageshack.us/i/screenshotdln.png/
sample code is as listed below
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
public class FieldCue {
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(250, 300);
shell.setLayout(new GridLayout());
Canvas composite = new Canvas(shell, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.marginWidth = 20;
layout.marginHeight = 20;
composite.setLayout(layout);
final Spinner spinner = new Spinner(composite, SWT.BORDER);
spinner.setMinimum(0);
spinner.setMaximum(100);
GridData data = new GridData(GridData.FILL, GridData.CENTER, false, false);
data.minimumWidth = 150;
data.widthHint = 150;
spinner.setLayoutData(data);
composite.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Rectangle ibounds = new Rectangle(10, 10, 10, 10);
Rectangle sbounds = spinner.getBounds();
Point rel = spinner.toDisplay(sbounds.width, 0);
Point p = spinner.getParent().toControl(rel);
e.gc.drawRectangle(p.x, p.y, ibounds.width, ibounds.height);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|
|
|
|
Re: Converting points using 'toControl' and 'toDisplay' gives wrong location on ubuntu10.10 [message #668706 is a reply to message #668033] |
Fri, 06 May 2011 17:34 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
It looks like something has changed in more recent versions of GTK. I've
logged https://bugs.eclipse.org/bugs/show_bug.cgi?id=345004 .
Grant
"Atieq-ur-Rehman" <atieq.rehman@hotmail.com> wrote in message
news:ipouri$s76$1@news.eclipse.org...
> drawing some image/control with Spinner while extracting relative location
> of image/control by using toDisplay and toControl function works fine on
> windows but wrongly display the controls on ubuntu 10.10 platform
>
> sample output for both platforms is
> http://img197.imageshack.us/i/screenshotdln.png/
>
> sample code is as listed below
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.PaintEvent;
> import org.eclipse.swt.events.PaintListener;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.graphics.Rectangle;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Canvas;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Spinner;
>
> public class FieldCue {
> public static void main(String[] args) {
> final Display display = new Display();
> Shell shell = new Shell(display);
> shell.setSize(250, 300);
> shell.setLayout(new GridLayout());
>
> Canvas composite = new Canvas(shell, SWT.NONE);
> composite.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> GridLayout layout = new GridLayout();
> layout.marginWidth = 20;
> layout.marginHeight = 20;
> composite.setLayout(layout);
>
> final Spinner spinner = new Spinner(composite, SWT.BORDER);
> spinner.setMinimum(0);
> spinner.setMaximum(100);
> GridData data = new GridData(GridData.FILL, GridData.CENTER, false,
> false);
> data.minimumWidth = 150;
> data.widthHint = 150;
> spinner.setLayoutData(data);
>
> composite.addPaintListener(new PaintListener() {
> @Override
> public void paintControl(PaintEvent e) {
> Rectangle ibounds = new Rectangle(10, 10, 10, 10);
> Rectangle sbounds = spinner.getBounds();
> Point rel = spinner.toDisplay(sbounds.width, 0);
>
> Point p = spinner.getParent().toControl(rel);
> e.gc.drawRectangle(p.x, p.y, ibounds.width, ibounds.height);
> }
> });
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
>
|
|
|
Powered by
FUDForum. Page generated in 0.02831 seconds