Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Gradient Fills in SWT
Gradient Fills in SWT [message #455959] Tue, 24 May 2005 09:08 Go to next message
Prashant Deva is currently offline Prashant DevaFriend
Messages: 32
Registered: July 2009
Member
It seems that currently the only object that can be filled with a
gradient is a rectangle, using a call to GC.fillGradientRectangle()


Is there any way to do a gradient fill on other kinds of objects like
Rounded Rectangles, ovals and polygons , etc?
Also is there any way to draw lines in gradient colors?

Why doesn't SWT provide methods like GC.fillGradientRoundedRectangle(),
GC.fillGradientCircle()?

Why is the gradient method provided only for rectangles?
Is it possible in any way to do a gradient fill on other kind of objects?

PRASHANT
Re: Gradient Fills in SWT [message #456033 is a reply to message #455959] Tue, 24 May 2005 16:26 Go to previous messageGo to next message
Silenio Quarti is currently offline Silenio QuartiFriend
Messages: 31
Registered: July 2009
Member
You can use polygon Regions and GC.setClipping(Region) to draw non
rectanglar gradients.

You can also use 3.1 API GC.setBackgroundPattern() with a linear gradient
org.eclipse.swt.graphics.Pattern.
Re: Gradient Fills in SWT [message #465560 is a reply to message #455959] Thu, 15 December 2005 11:34 Go to previous message
Eclipse UserFriend
Originally posted by: waldimiro.hotmail.com

try this...


import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;


/**
* AdvancedPath
*
* @author Waldimiro Rossi
* @version 1.0
* @since 15.12.2005
* @see Path
*/
public class AdvancedPath extends Path {

/**
* Contructor
* @param device
*/
public AdvancedPath(Device device) {

super(device);
}

/**
* Adds to the receiver the circle specified by x, y, radius
*
* @param x the x coordinate of the rectangle to add
* @param y the y coordinate of the rectangle to add
* @param radius the width of the radius
*
* @exception SWTException <ul>
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
public void addCircle(float x, float y, float radius) {

if (this.isDisposed()) {

SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
}

this.addArc(x, y, radius, radius, 0, 360);
}

/**
* Adds to the receiver the round-cornered rectangle specified by x, y, width and height.
*
* @param x the x coordinate of the rectangle to add
* @param y the y coordinate of the rectangle to add
* @param width the width of the rectangle to add
* @param height the height of the rectangle to add
* @param arcWidth the width of the arc
* @param arcHeight the height of the arc
* @exception SWTException <ul>
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
public void addRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight) {

if (this.isDisposed()) {

SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
}

float cx = 0;
float cy = 0;

// Top left corner
cx = x;
cy = y;

this.cubicTo(cx, cy, cx, cy, x, y + arcHeight);
this.cubicTo(cx, cy, cx, cy, x + arcWidth, y);

// Top right corner
cx = width;
cy = y;

this.cubicTo(cx, cy, cx, cy, width - arcWidth, y);
this.cubicTo(cx, cy, cx, cy, width, y + arcHeight);

// Bottom right corner
cx = width;
cy = height;

this.cubicTo(cx, cy, cx, cy, width, height - arcHeight);
this.cubicTo(cx, cy, cx, cy, width - arcWidth, height);

// Bottom left corner
cx = x;
cy = height;

this.cubicTo(cx, cy, cx, cy, x + arcWidth, height);
this.cubicTo(cx, cy, cx, cy, x, height - arcHeight);
}
}
Previous Topic:Components
Next Topic:Problem running Snippet174 - OpenGL
Goto Forum:
  


Current Time: Sun Sep 15 17:58:23 GMT 2019

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

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

Back to the top