Bug 184651 - ScaledGraphics does not support setClip(Path)
Summary: ScaledGraphics does not support setClip(Path)
Status: RESOLVED WORKSFORME
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Draw2d (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.7.1 (Indigo) M7   Edit
Assignee: Lidija Grahek CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-29 22:04 EDT by Zac CLA
Modified: 2011-03-25 13:18 EDT (History)
6 users (show)

See Also:
ahunter.eclipse: galileo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zac CLA 2007-04-29 22:04:05 EDT
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();
}
Comment 1 Max Rydahl Andersen CLA 2008-06-11 09:46:42 EDT
This actually affects any figures and I think the bug should rather be called "ScaledGraphics does no support gradient"
Comment 2 Randy Hudson CLA 2008-06-11 10:09:58 EDT
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.
Comment 3 Max Rydahl Andersen CLA 2008-06-11 10:16:00 EDT
Ok - so I should create a seperate bug for the missing gradient support in scaledgraphics ?
Comment 4 Anthony Hunter CLA 2008-06-11 10:42:49 EDT
(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.
Comment 5 Randy Hudson CLA 2008-06-11 22:46:15 EDT
> 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.
Comment 6 Alexander Nyßen CLA 2011-03-25 13:18:59 EDT
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();
	}
}