view snippets/display/Snippet276.d @ 132:104f5ed240fc

More snippets from TomD, thanks!
author Frank Benoit <benoit@tionex.de>
date Tue, 29 Jul 2008 01:50:10 +0200
parents
children
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 * D Port:
 *     Thomas Demmer <t_demmer AT web DOT de>
 *******************************************************************************/
module display.Snippet276;

/*
 * Display snippet: map from control-relative to display-relative coordinates
 * 
 * For a list of all DWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import dwt.DWT;
import dwt.graphics.Point;

import dwt.widgets.Control;
import dwt.widgets.Display;
import dwt.widgets.Event;
import dwt.widgets.Label;
import dwt.widgets.Listener;
import dwt.widgets.Shell;

import dwt.dwthelper.utils;
import tango.io.Stdout;

void main (String[] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setBounds (200, 200, 400, 400);
    Label label = new Label (shell, DWT.NONE);
    label.setText ("click in shell to print display-relative coordinate");
    Listener listener = dgListener( (Event event) {
        Point point = new Point (event.x, event.y);
        Stdout(display.map (cast(Control)event.widget, null, point)).newline().flush();
    });
    shell.addListener (DWT.MouseDown, listener);
    label.addListener (DWT.MouseDown, listener);
    label.pack ();
    shell.open ();
    while (!shell.isDisposed ()){
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}