Mercurial > projects > dwt-addons
diff dwtx/draw2d/Cursors.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children | 2d6540440fe6 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/draw2d/Cursors.d Sun Aug 03 00:52:14 2008 +0200 @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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 + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + *******************************************************************************/ +module dwtx.draw2d.Cursors; + +import dwt.dwthelper.utils; + +import dwt.DWT; +import dwt.graphics.Cursor; +import dwtx.draw2d.PositionConstants; + +/** + * A collection of cursors. + */ +public class Cursors { + +/** + * Returns the cursor corresponding to the given direction, defined in + * {@link PositionConstants}. Note that {@link #getDirectionalCursor(int, bool)} should + * be used for applications which want to run properly when running in a mirrored + * environment. The behavior is the same as calling {@link #getDirectionalCursor(int, + * bool) getDirectionalCursor(direction, false)}. + * + * @param direction the relative direction of the desired cursor + * @return The appropriate directional cursor + */ +public static Cursor getDirectionalCursor(int direction) { + return getDirectionalCursor(direction, false); +} + +/** + * Returns the cursor corresponding to the given direction and mirroring. The direction + * must be one of: + * <UL> + * <LI>{@link PositionConstants#NORTH} + * <LI>{@link PositionConstants#SOUTH} + * <LI>{@link PositionConstants#EAST} + * <LI>{@link PositionConstants#WEST} + * <LI>{@link PositionConstants#NORTH_EAST} + * <LI>{@link PositionConstants#NORTH_WEST} + * <LI>{@link PositionConstants#SOUTH_EAST} + * <LI>{@link PositionConstants#SOUTH_WEST} + * </UL> + * <P>The behavior is undefined for other values. If <code>isMirrored</code> is set to + * <code>true</code>, EAST and WEST will be inverted. + * @param direction the relative direction of the desired cursor + * @param isMirrored <code>true</code> if EAST and WEST should be inverted + * @return The appropriate directional cursor + */ +public static Cursor getDirectionalCursor(int direction, bool isMirrored) { + if (isMirrored && (direction & PositionConstants.EAST_WEST) !is 0) + direction = direction ^ PositionConstants.EAST_WEST; + switch (direction) { + case PositionConstants.NORTH : + return SIZEN; + case PositionConstants.SOUTH: + return SIZES; + case PositionConstants.EAST : + return SIZEE; + case PositionConstants.WEST: + return SIZEW; + case PositionConstants.SOUTH_EAST: + return SIZESE; + case PositionConstants.SOUTH_WEST: + return SIZESW; + case PositionConstants.NORTH_EAST: + return SIZENE; + case PositionConstants.NORTH_WEST: + return SIZENW; + default: + break; + } + return null; +} + +/** + * @see DWT#CURSOR_ARROW + */ +public static const Cursor ARROW; +/** + * @see DWT#CURSOR_SIZEN + */ +public static const Cursor SIZEN; +/** + * @see DWT#CURSOR_SIZENE + */ +public static const Cursor SIZENE; +/** + * @see DWT#CURSOR_SIZEE + */ +public static const Cursor SIZEE; +/** + * @see DWT#CURSOR_SIZESE + */ +public static const Cursor SIZESE; +/** + * @see DWT#CURSOR_SIZES + */ +public static const Cursor SIZES; +/** + * @see DWT#CURSOR_SIZESW + */ +public static const Cursor SIZESW; +/** + * @see DWT#CURSOR_SIZEW + */ +public static const Cursor SIZEW; +/** + * @see DWT#CURSOR_SIZENW + */ +public static const Cursor SIZENW; +/** + * @see DWT#CURSOR_APPSTARTING + */ +public static const Cursor APPSTARTING; +/** + * @see DWT#CURSOR_CROSS + */ +public static const Cursor CROSS; +/** + * @see DWT#CURSOR_HAND + */ +public static const Cursor HAND; +/** + * @see DWT#CURSOR_HELP + */ +public static const Cursor HELP; +/** + * @see DWT#CURSOR_IBEAM + */ +public static const Cursor IBEAM; +/** + * @see DWT#CURSOR_NO + */ +public static const Cursor NO; +/** + * @see DWT#CURSOR_SIZEALL + */ +public static const Cursor SIZEALL; +/** + * @see DWT#CURSOR_SIZENESW + */ +public static const Cursor SIZENESW; +/** + * @see DWT#CURSOR_SIZENWSE + */ +public static const Cursor SIZENWSE; +/** + * @see DWT#CURSOR_SIZEWE + */ +public static const Cursor SIZEWE; +/** + * @see DWT#CURSOR_SIZENS + */ +public static const Cursor SIZENS; +/** + * @see DWT#CURSOR_UPARROW + */ +public static const Cursor UPARROW; +/** + * @see DWT#CURSOR_WAIT + */ +public static const Cursor WAIT; + +static this() { + ARROW = new Cursor(null, DWT.CURSOR_ARROW); + SIZEN = new Cursor(null, DWT.CURSOR_SIZEN); + SIZENE = new Cursor(null, DWT.CURSOR_SIZENE); + SIZEE = new Cursor(null, DWT.CURSOR_SIZEE); + SIZESE = new Cursor(null, DWT.CURSOR_SIZESE); + SIZES = new Cursor(null, DWT.CURSOR_SIZES); + SIZESW = new Cursor(null, DWT.CURSOR_SIZESW); + SIZEW = new Cursor(null, DWT.CURSOR_SIZEW); + SIZENW = new Cursor(null, DWT.CURSOR_SIZENW); + SIZENS = new Cursor(null, DWT.CURSOR_SIZENS); + SIZEWE = new Cursor(null, DWT.CURSOR_SIZEWE); + APPSTARTING = new Cursor(null, DWT.CURSOR_APPSTARTING); + CROSS = new Cursor(null, DWT.CURSOR_CROSS); + HAND = new Cursor(null, DWT.CURSOR_HAND); + HELP = new Cursor(null, DWT.CURSOR_HELP); + IBEAM = new Cursor(null, DWT.CURSOR_IBEAM); + NO = new Cursor(null, DWT.CURSOR_NO); + SIZEALL = new Cursor(null, DWT.CURSOR_SIZEALL); + SIZENESW = new Cursor(null, DWT.CURSOR_SIZENESW); + SIZENWSE = new Cursor(null, DWT.CURSOR_SIZENWSE); + UPARROW = new Cursor(null, DWT.CURSOR_UPARROW); + WAIT = new Cursor(null, DWT.CURSOR_WAIT); +} + +}