| Summary: | Add support for clipRect functionality similar that J2D implements | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | antti.tirkkonen |
| Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | ||
| Version: | 4.0 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
Build Identifier: Currently there is no way of giving intersection of clips. This would be very usefull from nested "figures" point of view. GEF/Draw2d would benefit a lot as at the moment they are implementing it by them selves. Also this would enable possibility to support rotate in Draw2d/GEF/GMF. I did some dummy implementation for Windows: void clipRect(int /* long */clipRgn) { int /* long */hRgn = clipRgn; int /* long */gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { if (hRgn != 0) { int /* long */region = Gdip.Region_new(hRgn); Gdip.Graphics_SetClip(gdipGraphics, region, Gdip.CombineModeIntersect); Gdip.Region_delete(region); } else { Gdip.Graphics_ResetClip(gdipGraphics); } } else { POINT pt = null; if (hRgn != 0 && !OS.IsWinCE) { pt = new POINT(); OS.GetWindowOrgEx(handle, pt); OS.OffsetRgn(hRgn, -pt.x, -pt.y); } OS.SelectClipRgn(handle, hRgn); if (hRgn != 0 && !OS.IsWinCE) { OS.OffsetRgn(hRgn, pt.x, pt.y); } } if (hRgn != 0 && hRgn != clipRgn) { OS.DeleteObject(hRgn); } } public void clipRect(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); int /* long */hRgn = OS.CreateRectRgn(x, y, x + width, y + height); clip(hRgn); OS.DeleteObject(hRgn); } Reproducible: Always Steps to Reproduce: import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Transform; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class NestedRectangles { static Shell shell; public static void main(String[] args) { Display display = Display.getDefault(); shell = new Shell(display); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.setBackground(new Color(null, 255, 0, 0)); Rectangle bounds1 = new Rectangle(100, 100, 200, 100); e.gc.fillRectangle(bounds1); e.gc.setClipping(bounds1); Transform transform = new Transform(Display.getCurrent()); Rectangle bounds2 = new Rectangle(100, 100, 100, 200); transform.translate(bounds2.x + bounds2.width / 2, bounds2.y + bounds2.height / 2); transform.rotate(15); transform.translate(-(bounds2.x + bounds2.width / 2), -(bounds2.y + bounds2.height / 2)); e.gc.setTransform(transform); e.gc.clip(bounds2.x, bounds2.y, bounds2.width, bounds2.height); e.gc.setBackground(new Color(null, 0, 255, 0)); e.gc.fillRectangle(bounds2); e.gc.setBackground(new Color(null, 0, 0, 255)); e.gc.fillRectangle(bounds2.x - 20, bounds2.y + 50, bounds2.width + 40, 20); e.gc.setTransform(null); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }