Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 166245 Details for
Bug 310697
Need a way to clip Path within the current clipping context
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
proposed patch
GEF_ClipPath (text/plain), 5.84 KB, created by
Alex Boyko
on 2010-04-27 15:40:10 EDT
(
hide
)
Description:
proposed patch
Filename:
MIME Type:
Creator:
Alex Boyko
Created:
2010-04-27 15:40:10 EDT
Size:
5.84 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.draw2d >Index: src/org/eclipse/draw2d/Graphics.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/Graphics.java,v >retrieving revision 1.27 >diff -u -r1.27 Graphics.java >--- src/org/eclipse/draw2d/Graphics.java 13 Jan 2009 22:03:40 -0000 1.27 >+++ src/org/eclipse/draw2d/Graphics.java 27 Apr 2010 19:30:39 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -72,6 +72,17 @@ > public abstract void clipRect(Rectangle r); > > /** >+ * Sets the clip region to the given rectangle. Anything outside this rectangle will not >+ * be drawn. Takes into account current clipping area set on the graphics. >+ * @param path the clip path >+ * >+ * @since 3.6 >+ */ >+ public void clipPath(Path path) { >+ throwNotImplemented(); >+ } >+ >+ /** > * Disposes this object, releasing any resources. > */ > public abstract void dispose(); >Index: src/org/eclipse/draw2d/SWTGraphics.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/SWTGraphics.java,v >retrieving revision 1.55 >diff -u -r1.55 SWTGraphics.java >--- src/org/eclipse/draw2d/SWTGraphics.java 24 Jul 2009 19:03:41 -0000 1.55 >+++ src/org/eclipse/draw2d/SWTGraphics.java 27 Apr 2010 19:30:39 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -21,7 +21,9 @@ > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.LineAttributes; > import org.eclipse.swt.graphics.Path; >+import org.eclipse.swt.graphics.PathData; > import org.eclipse.swt.graphics.Pattern; >+import org.eclipse.swt.graphics.Region; > import org.eclipse.swt.graphics.TextLayout; > import org.eclipse.swt.graphics.Transform; > import org.eclipse.swt.widgets.Display; >@@ -1051,6 +1053,36 @@ > } > > /** >+ * Simple implementation of clipping a Path within the context of current >+ * clipping rectangle for now (not region) <li>Note that this method wipes >+ * out the clipping rectangle area, hence if clients need to reset it call >+ * {@link #restoreState()} >+ * >+ * @see org.eclipse.draw2d.Graphics#clipPath(org.eclipse.swt.graphics.Path) >+ */ >+public void clipPath(Path path) { >+ initTransform(false); >+ if (((appliedState.graphicHints ^ currentState.graphicHints) & FILL_RULE_MASK) != 0) { >+ //If there is a pending change to the fill rule, apply it first. >+ gc.setFillRule(((currentState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER); >+ //As long as the FILL_RULE is stored in a single bit, just toggling it works. >+ appliedState.graphicHints ^= FILL_RULE_MASK; >+ } >+ Rectangle clipping = currentState.relativeClip != null ? getClip(new Rectangle()) : new Rectangle(); >+ if (!clipping.isEmpty()) { >+ Path flatPath = new Path(path.getDevice(), path, 0.01f); >+ PathData pathData = flatPath.getPathData(); >+ flatPath.dispose(); >+ Region region = new Region(path.getDevice()); >+ loadPath(region, pathData.points, pathData.types); >+ region.intersect(new org.eclipse.swt.graphics.Rectangle(clipping.x, clipping.y, clipping.width, clipping.height)); >+ gc.setClipping(region); >+ appliedState.relativeClip = currentState.relativeClip = null; >+ region.dispose(); >+ } >+} >+ >+/** > * @see Graphics#setClip(Rectangle) > */ > public void setClip(Rectangle rect) { >@@ -1356,4 +1388,40 @@ > return iArray; > } > >+static void loadPath(Region region, float[] points, byte[] types) { >+ int start = 0, end = 0; >+ for (int i = 0; i < types.length; i++) { >+ switch (types[i]) { >+ case SWT.PATH_MOVE_TO: { >+ if (start != end) { >+ int n = 0; >+ int[] temp = new int[end - start]; >+ for (int k = start; k < end; k++) { >+ temp[n++] = Math.round(points[k]); >+ } >+ region.add(temp); >+ } >+ start = end; >+ end += 2; >+ break; >+ } >+ case SWT.PATH_LINE_TO: { >+ end += 2; >+ break; >+ } >+ case SWT.PATH_CLOSE: { >+ if (start != end) { >+ int n = 0; >+ int[] temp = new int[end - start]; >+ for (int k = start; k < end; k++) { >+ temp[n++] = Math.round(points[k]); >+ } >+ region.add(temp); >+ } >+ start = end; >+ break; >+ } >+ } >+ } >+} > } >\ No newline at end of file >Index: src/org/eclipse/draw2d/ScaledGraphics.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/ScaledGraphics.java,v >retrieving revision 1.42 >diff -u -r1.42 ScaledGraphics.java >--- src/org/eclipse/draw2d/ScaledGraphics.java 13 Apr 2010 19:04:38 -0000 1.42 >+++ src/org/eclipse/draw2d/ScaledGraphics.java 27 Apr 2010 19:30:39 -0000 >@@ -714,6 +714,18 @@ > } > > /** >+ * @see org.eclipse.draw2d.Graphics#clipPath(org.eclipse.swt.graphics.Path) >+ */ >+ public void clipPath(Path path) { >+ Path scaledPath = createScaledPath(path); >+ try { >+ graphics.clipPath(scaledPath); >+ } finally { >+ scaledPath.dispose(); >+ } >+ } >+ >+ /** > * @see Graphics#setFillRule(int) > */ > public void setFillRule(int rule) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 310697
: 166245