Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Gradient fill for ovals
Gradient fill for ovals [message #195928] Wed, 14 September 2005 13:52 Go to next message
pablo is currently offline pabloFriend
Messages: 1
Registered: July 2009
Junior Member
Hi, I wonder if there is any way of filling an ellipse with gradient
colors in draw2d.

I've been trying around with fillGradientRectangle but I can't get to show
only the ellipse

Thanks!
Re: Gradient fill for ovals [message #195937 is a reply to message #195928] Wed, 14 September 2005 14:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: radicr.stop.spam.gmail.com

You could try using the Path

import org.eclipse.swt.graphics.Path;

protected void fillShape(Graphics graphics) {
Path path = new Path(null); //
path.addArc(left, top + height + Y_OFFSET / 2, width + X_OFFSET * 2,
height / 5 + Y_OFFSET, 270, 180);
try {
graphics.setClip(path); // setClip with Path as an argument wont
work with ScalledGraphics, maybe in next releases
}catch (Exception ex) {
}
graphics.setForegroundColor(ColorConstants.blue);
graphics.setBackgroundColor(ColorConstants.red);
graphics.fillGradient(left, top, width, height, true);
....
}

HTH,
Radovan

"Pablo" <antequera@gmail.com> wrote in message
news:293f995fa4a73aaa3e9beeaa8caef57a$1@www.eclipse.org...
> Hi, I wonder if there is any way of filling an ellipse with gradient
> colors in draw2d.
>
> I've been trying around with fillGradientRectangle but I can't get to show
> only the ellipse
>
> Thanks!
>
Re: Gradient fill for ovals [message #196024 is a reply to message #195937] Thu, 15 September 2005 11:35 Go to previous message
Eclipse UserFriend
Originally posted by: ssssss.gmail.com

Thanks, but I'm working on WSAD 5.1.2 so Path is not available here.

However I've been able to use Java2D following this tutorial
http://www-128.ibm.com/developerworks/java/library/j-2dswt and using its
piece of code.

However,it seemed like the awtImage wasn't large enough so I got
IndexOutOfBounsException in the awtImage.getRGB method.

I changed the prepareRendering method to include the X and Y position in
the checkOffScreenImages like this:

checkOffScreenImages(clipW+clipX, clipH+clipY);

Maybe not the best solution, but it worked. This is my code:

###################
...
protected void fillShape(Graphics graphics) {
Graphics2DRenderer renderer = new Graphics2DRenderer();
Dimension controlSize = getSize();

// prepares the Graphics2D renderer
renderer.prepareRendering(graphics);
// gets the Graphics2D context
Graphics2D g2d = renderer.getGraphics2D();

// does the Java 2D painting
// paints the background with a color gradient
g2d.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

GradientPaint gp =
new GradientPaint(
(float) getBounds().x,
(float) getBounds().y,
java.awt.Color.yellow,
(float) getBounds().x+(float) controlSize.width,
(float) getBounds().y+(float) controlSize.height,
java.awt.Color.white);
g2d.setPaint(gp);

g2d.fillOval(
getBounds().x,
getBounds().y,
controlSize.width,
controlSize.height);

// now that we are done with Java 2D, renders Graphics2D operation
// on the Draw2D graphics context
renderer.render(graphics);
}
############################
Previous Topic:reference GraphicalEditor from an EditPart
Next Topic:Document typo?
Goto Forum:
  


Current Time: Sun Jan 19 20:32:14 GMT 2025

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

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

Back to the top