Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 310697
Collapse All | Expand All

(-)src/org/eclipse/draw2d/Graphics.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 72-77 Link Here
72
	public abstract void clipRect(Rectangle r);
72
	public abstract void clipRect(Rectangle r);
73
	
73
	
74
	/**
74
	/**
75
	 * Sets the clip region to the given rectangle.  Anything outside this rectangle will not
76
	 * be drawn. Takes into account current clipping area set on the graphics.
77
	 * @param path the clip path
78
	 * 
79
	 * @since 3.6
80
	 */
81
	public void clipPath(Path path) {
82
		throwNotImplemented();
83
	}
84
	
85
	/**
75
	 * Disposes this object, releasing any resources.
86
	 * Disposes this object, releasing any resources.
76
	 */
87
	 */
77
	public abstract void dispose();
88
	public abstract void dispose();
(-)src/org/eclipse/draw2d/SWTGraphics.java (-1 / +69 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 21-27 Link Here
21
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.LineAttributes;
22
import org.eclipse.swt.graphics.LineAttributes;
23
import org.eclipse.swt.graphics.Path;
23
import org.eclipse.swt.graphics.Path;
24
import org.eclipse.swt.graphics.PathData;
24
import org.eclipse.swt.graphics.Pattern;
25
import org.eclipse.swt.graphics.Pattern;
26
import org.eclipse.swt.graphics.Region;
25
import org.eclipse.swt.graphics.TextLayout;
27
import org.eclipse.swt.graphics.TextLayout;
26
import org.eclipse.swt.graphics.Transform;
28
import org.eclipse.swt.graphics.Transform;
27
import org.eclipse.swt.widgets.Display;
29
import org.eclipse.swt.widgets.Display;
Lines 1051-1056 Link Here
1051
}
1053
}
1052
1054
1053
/**
1055
/**
1056
 * Simple implementation of clipping a Path within the context of current
1057
 * clipping rectangle for now (not region) <li>Note that this method wipes
1058
 * out the clipping rectangle area, hence if clients need to reset it call
1059
 * {@link #restoreState()}
1060
 * 
1061
 * @see org.eclipse.draw2d.Graphics#clipPath(org.eclipse.swt.graphics.Path)
1062
 */
1063
public void clipPath(Path path) {
1064
	initTransform(false);
1065
	if (((appliedState.graphicHints ^ currentState.graphicHints) & FILL_RULE_MASK) != 0) {
1066
		//If there is a pending change to the fill rule, apply it first.
1067
		gc.setFillRule(((currentState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER);
1068
		//As long as the FILL_RULE is stored in a single bit, just toggling it works.
1069
		appliedState.graphicHints ^= FILL_RULE_MASK;
1070
	}
1071
	Rectangle clipping = currentState.relativeClip != null ? getClip(new Rectangle()) : new Rectangle();
1072
	if (!clipping.isEmpty()) {
1073
		Path flatPath = new Path(path.getDevice(), path, 0.01f);
1074
		PathData pathData = flatPath.getPathData();
1075
		flatPath.dispose();
1076
		Region region = new Region(path.getDevice());
1077
		loadPath(region, pathData.points, pathData.types);
1078
		region.intersect(new org.eclipse.swt.graphics.Rectangle(clipping.x, clipping.y, clipping.width, clipping.height));
1079
		gc.setClipping(region);
1080
		appliedState.relativeClip = currentState.relativeClip = null;
1081
		region.dispose();
1082
	}
1083
}
1084
1085
/**
1054
 * @see Graphics#setClip(Rectangle)
1086
 * @see Graphics#setClip(Rectangle)
1055
 */
1087
 */
1056
public void setClip(Rectangle rect) {
1088
public void setClip(Rectangle rect) {
Lines 1356-1359 Link Here
1356
	return iArray;
1388
	return iArray;
1357
}
1389
}
1358
1390
1391
static void loadPath(Region region, float[] points, byte[] types) {
1392
	int start = 0, end = 0;
1393
	for (int i = 0; i < types.length; i++) {
1394
		switch (types[i]) {
1395
			case SWT.PATH_MOVE_TO: {
1396
				if (start != end) {
1397
					int n = 0;
1398
					int[] temp = new int[end - start];
1399
					for (int k = start; k < end; k++) {
1400
						temp[n++] = Math.round(points[k]);
1401
					}
1402
					region.add(temp);
1403
				}
1404
				start = end;
1405
				end += 2;
1406
				break;
1407
			}
1408
			case SWT.PATH_LINE_TO: {
1409
				end += 2;
1410
				break;
1411
			}
1412
			case SWT.PATH_CLOSE: {
1413
				if (start != end) {
1414
					int n = 0;
1415
					int[] temp = new int[end - start];
1416
					for (int k = start; k < end; k++) {
1417
						temp[n++] = Math.round(points[k]);
1418
					}
1419
					region.add(temp);
1420
				}
1421
				start = end;
1422
				break;
1423
			}
1424
		}
1425
	}
1426
}
1359
}
1427
}
(-)src/org/eclipse/draw2d/ScaledGraphics.java (+12 lines)
Lines 714-719 Link Here
714
	}
714
	}
715
	
715
	
716
	/**
716
	/**
717
	 * @see org.eclipse.draw2d.Graphics#clipPath(org.eclipse.swt.graphics.Path)
718
	 */
719
	public void clipPath(Path path) {
720
		Path scaledPath = createScaledPath(path);
721
		try {
722
			graphics.clipPath(scaledPath);
723
		} finally {
724
			scaledPath.dispose();
725
		}
726
	}
727
	
728
	/**
717
	 * @see Graphics#setFillRule(int)
729
	 * @see Graphics#setFillRule(int)
718
	 */
730
	 */
719
	public void setFillRule(int rule) {
731
	public void setFillRule(int rule) {

Return to bug 310697