Community
Participate
Working Groups
Hi, Currently, i am working with GEF to create some kinda diagrams and i have hit a problem. I tried filling an oval shape with gradient by setting a clip path to it and then filling it with graphics#fillgradient method. (See code example below) It works fine at 1st. However when i added on the zoom function, an exception is thrown (draw2d.ScaledGraphics has not implemented this new graphics function) and the gradient will fill the whole rectangle bound, instead of the oval. In addition, i have not been able to print out the gradient-filled oval. The size and position of the ovals have gone haywired. All rectangles works fine. May i ask if there is a solution to this problem or is there a work-around method? I will be glad as long as i can show the gradient on the ovals and also zoom them and print the ovals out. Any help is much appreciated! Thks! ============================================== CODE: implemented in Figure#fillShape() ============================================== Path path = new Path(null); //Add 2 arcs to create a path/clip for an oval path.addArc(....); path.addArc(....); try { graphics.setClip(path); graphics.fillGradient( getBound() ); } catch(Exception e) { e.printStackTrace(); }
This actually affects any figures and I think the bug should rather be called "ScaledGraphics does no support gradient"
In reply to comment #1) > This actually affects any figures and I think the bug should rather be called > "ScaledGraphics does no support gradient" The problem is with setClip(Path), not fillGradient. zoomPath was recently added for fillPath(Path) and drawPath(Path) in ScaledGraphics, so maybe this method could be used to implement setClip(Path). Note that the more useful method "clip(Path)" which intersects the Path and the current clipping is still not defined nor easily implemented given the lack of intersection support.
Ok - so I should create a seperate bug for the missing gradient support in scaledgraphics ?
(In reply to comment #3) > Ok - so I should create a seperate bug for the missing gradient support in > scaledgraphics ? > It would appear that we need this. We have Bug 132361 as well.
> It would appear that we need this. We have Bug 132361 as well. Patterns don't work either, but the above code uses the basic rectangular fill.
These issues seem to have been fixed by means of bug #267728. The following snippet may be used to demonstrate that this is working now. Resolving as WORKSFORME. import org.eclipse.draw2d.SWTGraphics; import org.eclipse.draw2d.ScaledGraphics; import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Path; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class PathWithGradient { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Shell"); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { SWTGraphics nativeGraphics = new SWTGraphics(e.gc); ScaledGraphics graphics = new ScaledGraphics(nativeGraphics); float scale = 10.0f; graphics.scale(scale); // Add 2 arcs to create a path/clip for an oval Path path = new Path(display); int diameter = 20; // path.addArc(x, y, width, height, startAngle, arcAngle) path.addArc(0, 0, diameter + 20, diameter, 0, 360); path.addArc(10, 10, diameter + 20, diameter, 0, 360); // path.addString("SWT", 0, 0, display.getSystemFont()); graphics.setBackgroundColor(display .getSystemColor(SWT.COLOR_GREEN)); graphics.setForegroundColor(display .getSystemColor(SWT.COLOR_BLUE)); graphics.setClip(path); float[] bounds = new float[4]; path.getBounds(bounds); // compensate for different rectangle calculations in SWT and Draw2d graphics.fillGradient( new PrecisionRectangle(bounds[0], bounds[1], bounds[2] + 1 * scale, bounds[3] + 1 * scale), true); } }); shell.setSize(800, 800); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }