Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » drawing an oval Cursor
drawing an oval Cursor [message #452024] Sun, 13 March 2005 16:29 Go to next message
Koen van Dijken is currently offline Koen van DijkenFriend
Messages: 67
Registered: July 2009
Member
Hi,

I've been struggling to create an oval cursor of which the diameter is
variable (but always < 32). With the following code it always shows as a
large black rectangle. Can anybody tell me what I am doing wrong?

protected void setCursor() {
if(cursor != null)
cursor.dispose();

int hotSpotX = diameter / 2;
int hotSpotY = diameter / 2;

PaletteData palette = new PaletteData(new RGB[] {
ColorConstants.white.getRGB(),
ColorConstants.black.getRGB() });

ImageData source = new ImageData(diameter, diameter, 1, palette);
source.transparentPixel = palette.getPixel(ColorConstants.white
.getRGB());

Image image = new Image(Display.getCurrent(), source);
try {
GC gc = new GC(image);
try {
gc.setForeground(ColorConstants.black);
gc.setLineWidth(1);
gc.drawOval(0, 0, diameter - 1, diameter - 1);

ImageData mask = source.getTransparencyMask();

cursor = new Cursor(Display.getCurrent(), source, mask,
hotSpotX, hotSpotY);
} finally {
gc.dispose();
}
} finally {
image.dispose();
}
}


Koen
Re: drawing an oval Cursor [message #452245 is a reply to message #452024] Tue, 15 March 2005 18:47 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Take a look ta this snippet:

For black and white:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet92.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup

or for colours:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet119.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup

"Koen van Dijken" <kvdijken@tiscali.nl> wrote in message
news:d11ppn$l7$1@www.eclipse.org...
> Hi,
>
> I've been struggling to create an oval cursor of which the diameter is
> variable (but always < 32). With the following code it always shows as a
> large black rectangle. Can anybody tell me what I am doing wrong?
>
> protected void setCursor() {
> if(cursor != null)
> cursor.dispose();
>
> int hotSpotX = diameter / 2;
> int hotSpotY = diameter / 2;
>
> PaletteData palette = new PaletteData(new RGB[] {
> ColorConstants.white.getRGB(),
> ColorConstants.black.getRGB() });
>
> ImageData source = new ImageData(diameter, diameter, 1, palette);
> source.transparentPixel = palette.getPixel(ColorConstants.white
> .getRGB());
>
> Image image = new Image(Display.getCurrent(), source);
> try {
> GC gc = new GC(image);
> try {
> gc.setForeground(ColorConstants.black);
> gc.setLineWidth(1);
> gc.drawOval(0, 0, diameter - 1, diameter - 1);
>
> ImageData mask = source.getTransparencyMask();
>
> cursor = new Cursor(Display.getCurrent(), source, mask,
> hotSpotX, hotSpotY);
> } finally {
> gc.dispose();
> }
> } finally {
> image.dispose();
> }
> }
>
>
> Koen
>
>
Previous Topic:advanced GUI with resizable sections
Next Topic:SWT in Swing Component
Goto Forum:
  


Current Time: Thu Apr 25 16:31:39 GMT 2024

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

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

Back to the top