|
Re: Gradient fill for ovals [message #195937 is a reply to message #195928] |
Wed, 14 September 2005 14:19 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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);
}
############################
|
|
|
Powered by
FUDForum. Page generated in 0.04500 seconds