Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Converting points using 'toControl' and 'toDisplay' gives wrong location on ubuntu10.10
Converting points using 'toControl' and 'toDisplay' gives wrong location on ubuntu10.10 [message #668033] Tue, 03 May 2011 13:18 Go to next message
atieq.rehman is currently offline atieq.rehmanFriend
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 #668609 is a reply to message #668033] Fri, 06 May 2011 12:13 Go to previous messageGo to next message
atieq.rehman is currently offline atieq.rehmanFriend
Messages: 12
Registered: March 2010
Junior Member
anyone there.... ? courageous enough to reply .....
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 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
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();
> }
> }
>
Previous Topic:Possible to clone browser control?
Next Topic:Problem with Gridlayout
Goto Forum:
  


Current Time: Thu Apr 25 11:32:52 GMT 2024

Powered by FUDForum. Page generated in 0.02726 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top