Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Fill an oval with a gradient
Fill an oval with a gradient [message #226323] Thu, 09 November 2006 11:59 Go to next message
Andreas Walter is currently offline Andreas WalterFriend
Messages: 8
Registered: July 2009
Junior Member
Hi everybody,

I'm trying to fill an oval with a gradient, but the Graphics class
only allows to fill a rectangle with a gradient. The (not very
efficient) solution I implemented so far is filling a rectangle with
the gradient (with fillRectangle(Rectangle r)), then painting all points
within that rectangle that are not contained in the oval with the
background color to 'delete' the gradient points outside the oval, and
finally draw the oval around the 'rest' of the gradient. The Graphics
class offers a method setClip(Path) which seems to offer the needed
functionality, but I haven't figured out so far how I could use it,
especially since the Path object has to be constructed with a Device
object, and I dont't know how to get that, because I don't know how to
access the Display from my figure class. Any help would be appreciated.

Thanks in advance,
Andreas
Re: Fill an oval with a gradient [message #239624 is a reply to message #226323] Tue, 06 November 2007 08:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Did you find a better solution for this?

I would love to see any code example that fills a gradient on something
else than a rectangle :)

Best Regards,

Tomas Zijdemans


Andreas Walter wrote:
> Hi everybody,
>
> I'm trying to fill an oval with a gradient, but the Graphics class
> only allows to fill a rectangle with a gradient. The (not very
> efficient) solution I implemented so far is filling a rectangle with
> the gradient (with fillRectangle(Rectangle r)), then painting all points
> within that rectangle that are not contained in the oval with the
> background color to 'delete' the gradient points outside the oval, and
> finally draw the oval around the 'rest' of the gradient. The Graphics
> class offers a method setClip(Path) which seems to offer the needed
> functionality, but I haven't figured out so far how I could use it,
> especially since the Path object has to be constructed with a Device
> object, and I dont't know how to get that, because I don't know how to
> access the Display from my figure class. Any help would be appreciated.
>
> Thanks in advance,
> Andreas
Re: Fill an oval with a gradient [message #239695 is a reply to message #239624] Thu, 08 November 2007 21:07 Go to previous message
Rene Dekker is currently offline Rene DekkerFriend
Messages: 9
Registered: July 2009
Junior Member
Not sure why you have a problem with this. Here is a snippet of code that
works for me:

@Override
public void paintClientArea( Graphics graphics )
{
graphics.pushState();
Color lightBlue = new Color( null, 245, 245, 255 );
Rectangle rect = new Rectangle( bounds );
rect.height = 30;
graphics.setBackgroundPattern( new Pattern( null, rect.x, rect.y,
rect.x, rect.y + rect.height, lightBlue,
ColorConstants.darkBlue ) );
graphics.fillOval( rect );
graphics.popState();
}


Tomas Zijdemans wrote:

> Did you find a better solution for this?

> I would love to see any code example that fills a gradient on something
> else than a rectangle :)

> Best Regards,

> Tomas Zijdemans


> Andreas Walter wrote:
>> Hi everybody,
>>
>> I'm trying to fill an oval with a gradient, but the Graphics class
>> only allows to fill a rectangle with a gradient. The (not very
>> efficient) solution I implemented so far is filling a rectangle with
>> the gradient (with fillRectangle(Rectangle r)), then painting all points
>> within that rectangle that are not contained in the oval with the
>> background color to 'delete' the gradient points outside the oval, and
>> finally draw the oval around the 'rest' of the gradient. The Graphics
>> class offers a method setClip(Path) which seems to offer the needed
>> functionality, but I haven't figured out so far how I could use it,
>> especially since the Path object has to be constructed with a Device
>> object, and I dont't know how to get that, because I don't know how to
>> access the Display from my figure class. Any help would be appreciated.
>>
>> Thanks in advance,
>> Andreas
Previous Topic:change the container of model
Next Topic:compound elements
Goto Forum:
  


Current Time: Mon Oct 25 17:12:10 GMT 2021

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

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

Back to the top