View | Details | Raw Unified | Return to bug 173693 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/draw2d/SWTGraphics.java (-550 / +601 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 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 38-44 Link Here
38
 * WARNING: This class is not intended to be subclassed.
38
 * WARNING: This class is not intended to be subclassed.
39
 */
39
 */
40
public class SWTGraphics
40
public class SWTGraphics
41
	extends Graphics
41
    extends Graphics
42
{
42
{
43
43
44
/**
44
/**
Lines 46-63 Link Here
46
 * @since 3.1
46
 * @since 3.1
47
 */
47
 */
48
interface Clipping {
48
interface Clipping {
49
	/**
49
    /**
50
	 * Sets the clip's bounding rectangle into the provided argument and returns it for convenince.
50
     * Sets the clip's bounding rectangle into the provided argument and returns it for convenince.
51
	 * @param rect the rect
51
     * @param rect the rect
52
	 * @return the given rect
52
     * @return the given rect
53
	 * @since 3.1
53
     * @since 3.1
54
	 */
54
     */
55
	Rectangle getBoundingBox(Rectangle rect);
55
    Rectangle getBoundingBox(Rectangle rect);
56
	Clipping getCopy();
56
    Clipping getCopy();
57
	void intersect(int left, int top, int right, int bottom);
57
    void intersect(int left, int top, int right, int bottom);
58
	void scale(float horizontal, float vertical);
58
    void scale(float horizontal, float vertical);
59
	void setOn(GC gc, int translateX, int translateY);
59
    void setOn(GC gc, int translateX, int translateY);
60
	void translate(float dx, float dy);
60
    void translate(float dx, float dy);
61
}
61
}
62
62
63
/**
63
/**
Lines 66-188 Link Here
66
 * @since 3.1
66
 * @since 3.1
67
 */
67
 */
68
static class LazyState {
68
static class LazyState {
69
	Color bgColor;
69
    Color bgColor;
70
	Color fgColor;
70
    Color fgColor;
71
	Font font;
71
    Font font;
72
	int graphicHints;
72
    int graphicHints;
73
	int lineWidth;
73
    int lineWidth;
74
	Clipping relativeClip;
74
    Clipping relativeClip;
75
}
75
}
76
76
77
static class RectangleClipping implements Clipping {
77
static class RectangleClipping implements Clipping {
78
	private float top, left, bottom, right;
78
    private float top, left, bottom, right;
79
	
79
    
80
	RectangleClipping(float left, float top, float right, float bottom) {
80
    RectangleClipping(float left, float top, float right, float bottom) {
81
		this.left = left;
81
        this.left = left;
82
		this.right = right;
82
        this.right = right;
83
		this.bottom = bottom;
83
        this.bottom = bottom;
84
		this.top = top;
84
        this.top = top;
85
	}
85
    }
86
	
86
    
87
	RectangleClipping(org.eclipse.swt.graphics.Rectangle rect) {
87
    RectangleClipping(org.eclipse.swt.graphics.Rectangle rect) {
88
		left = rect.x;
88
        left = rect.x;
89
		top = rect.y;
89
        top = rect.y;
90
		right = rect.x + rect.width;
90
        right = rect.x + rect.width;
91
		bottom = rect.y + rect.height;
91
        bottom = rect.y + rect.height;
92
	}
92
    }
93
	
93
    
94
	RectangleClipping(Rectangle rect) {
94
    RectangleClipping(Rectangle rect) {
95
		left = rect.x;
95
        left = rect.x;
96
		top = rect.y;
96
        top = rect.y;
97
		right = rect.right();
97
        right = rect.right();
98
		bottom = rect.bottom();
98
        bottom = rect.bottom();
99
	}
99
    }
100
	
100
    
101
	public Rectangle getBoundingBox(Rectangle rect) {
101
    public Rectangle getBoundingBox(Rectangle rect) {
102
		rect.x = (int)left;
102
        rect.x = (int)left;
103
		rect.y = (int)top;
103
        rect.y = (int)top;
104
		rect.width = (int)Math.ceil(right) - rect.x;
104
        rect.width = (int)Math.ceil(right) - rect.x;
105
		rect.height = (int)Math.ceil(bottom) - rect.y;
105
        rect.height = (int)Math.ceil(bottom) - rect.y;
106
		return rect;
106
        return rect;
107
	}
107
    }
108
	
108
    
109
	public Clipping getCopy() {
109
    public Clipping getCopy() {
110
		return new RectangleClipping(left, top, right, bottom);
110
        return new RectangleClipping(left, top, right, bottom);
111
	}
111
    }
112
	
112
    
113
	public void intersect(int left, int top, final int right, final int bottom) {
113
    public void intersect(int left, int top, final int right, final int bottom) {
114
		this.left = Math.max(this.left, left);
114
        this.left = Math.max(this.left, left);
115
		this.right = Math.min(this.right, right);
115
        this.right = Math.min(this.right, right);
116
		this.top = Math.max(this.top, top);
116
        this.top = Math.max(this.top, top);
117
		this.bottom = Math.min(this.bottom, bottom);
117
        this.bottom = Math.min(this.bottom, bottom);
118
		if (right < left || bottom < top) {
118
        if (right < left || bottom < top) {
119
			//width and height of -1 to avoid ceiling function from re-adding a pixel.
119
            //width and height of -1 to avoid ceiling function from re-adding a pixel.
120
			this.right = left - 1;
120
            this.right = left - 1;
121
			this.bottom = top - 1;
121
            this.bottom = top - 1;
122
		}
122
        }
123
	}
123
    }
124
	
124
    
125
	public void scale(float horz, float vert) {
125
    public void scale(float horz, float vert) {
126
		left /= horz;
126
        left /= horz;
127
		right /= horz;
127
        right /= horz;
128
		top /= vert;
128
        top /= vert;
129
		bottom /= vert;
129
        bottom /= vert;
130
	}
130
    }
131
	
131
    
132
	public void setOn(GC gc, int translateX, int translateY) {
132
    public void setOn(GC gc, int translateX, int translateY) {
133
		int xInt = (int)Math.floor(left);
133
        int xInt = (int)Math.floor(left);
134
		int yInt = (int)Math.floor(top);
134
        int yInt = (int)Math.floor(top);
135
		gc.setClipping(xInt + translateX, yInt + translateY,
135
        gc.setClipping(xInt + translateX, yInt + translateY,
136
				(int)Math.ceil(right) - xInt,
136
                (int)Math.ceil(right) - xInt,
137
				(int)Math.ceil(bottom) - yInt);
137
                (int)Math.ceil(bottom) - yInt);
138
	}
138
    }
139
	
139
    
140
	public void translate(float dx, float dy) {
140
    public void translate(float dx, float dy) {
141
		left += dx;
141
        left += dx;
142
		right += dx;
142
        right += dx;
143
		top += dy;
143
        top += dy;
144
		bottom += dy;
144
        bottom += dy;
145
	}
145
    }
146
}
146
}
147
147
148
/**
148
/**
149
 * Contains the entire state of the Graphics.
149
 * Contains the entire state of the Graphics.
150
 */
150
 */
151
static class State
151
static class State
152
	extends LazyState
152
    extends LazyState
153
	implements Cloneable
153
    implements Cloneable
154
{
154
{
155
	float affineMatrix[];
155
    float affineMatrix[];
156
	int alpha;
156
    int alpha;
157
	Pattern bgPattern;
157
    Pattern bgPattern;
158
	int dx, dy;
158
    int dx, dy;
159
	
159
    
160
	Pattern fgPattern;
160
    Pattern fgPattern;
161
	int lineDash[];
161
    int lineDash[];
162
	
162
    
163
	public Object clone() throws CloneNotSupportedException {
163
    public Object clone() throws CloneNotSupportedException {
164
		return super.clone();
164
        return super.clone();
165
	}
165
    }
166
	
166
    
167
	/**
167
    /**
168
	 * Copies all state information from the given State to this State
168
     * Copies all state information from the given State to this State
169
	 * @param state The State to copy from
169
     * @param state The State to copy from
170
	 */
170
     */
171
	public void copyFrom(State state) {
171
    public void copyFrom(State state) {
172
		bgColor = state.bgColor;
172
        bgColor = state.bgColor;
173
		fgColor = state.fgColor;
173
        fgColor = state.fgColor;
174
		lineWidth = state.lineWidth;
174
        lineWidth = state.lineWidth;
175
		dx = state.dx;
175
        dx = state.dx;
176
		dy = state.dy;
176
        dy = state.dy;
177
		bgPattern = state.bgPattern;
177
        bgPattern = state.bgPattern;
178
		fgPattern = state.fgPattern;
178
        fgPattern = state.fgPattern;
179
		font = state.font;
179
        font = state.font;
180
		lineDash = state.lineDash;
180
        lineDash = state.lineDash;
181
		graphicHints = state.graphicHints;
181
        graphicHints = state.graphicHints;
182
		affineMatrix = state.affineMatrix;
182
        affineMatrix = state.affineMatrix;
183
		relativeClip = state.relativeClip;
183
        relativeClip = state.relativeClip;
184
		alpha = state.alpha;
184
        alpha = state.alpha;
185
	}
185
    }
186
}
186
}
187
187
188
static final int AA_MASK;
188
static final int AA_MASK;
Lines 210-238 Link Here
210
static final int XOR_SHIFT;
210
static final int XOR_SHIFT;
211
211
212
static {
212
static {
213
	XOR_SHIFT = 3;
213
    XOR_SHIFT = 3;
214
	CAP_SHIFT = 4;
214
    CAP_SHIFT = 4;
215
	JOIN_SHIFT = 6;
215
    JOIN_SHIFT = 6;
216
	AA_SHIFT = 8;
216
    AA_SHIFT = 8;
217
	TEXT_AA_SHIFT = 10;
217
    TEXT_AA_SHIFT = 10;
218
	INTERPOLATION_SHIFT = 12;
218
    INTERPOLATION_SHIFT = 12;
219
	FILL_RULE_SHIFT = 14;
219
    FILL_RULE_SHIFT = 14;
220
	ADVANCED_SHIFT = 15;
220
    ADVANCED_SHIFT = 15;
221
221
222
	LINE_STYLE_MASK = 7;
222
    LINE_STYLE_MASK = 7;
223
	AA_MASK = 3 << AA_SHIFT;
223
    AA_MASK = 3 << AA_SHIFT;
224
	CAP_MASK = 3 << CAP_SHIFT;
224
    CAP_MASK = 3 << CAP_SHIFT;
225
	FILL_RULE_MASK = 1 << FILL_RULE_SHIFT;
225
    FILL_RULE_MASK = 1 << FILL_RULE_SHIFT;
226
	INTERPOLATION_MASK = 3 << INTERPOLATION_SHIFT;
226
    INTERPOLATION_MASK = 3 << INTERPOLATION_SHIFT;
227
	JOIN_MASK = 3 << JOIN_SHIFT;
227
    JOIN_MASK = 3 << JOIN_SHIFT;
228
	TEXT_AA_MASK = 3 << TEXT_AA_SHIFT;
228
    TEXT_AA_MASK = 3 << TEXT_AA_SHIFT;
229
	XOR_MASK = 1 << XOR_SHIFT;
229
    XOR_MASK = 1 << XOR_SHIFT;
230
	ADVANCED_GRAPHICS_MASK = 1 << ADVANCED_SHIFT;
230
    ADVANCED_GRAPHICS_MASK = 1 << ADVANCED_SHIFT;
231
	
231
    
232
	ADVANCED_HINTS_MASK = TEXT_AA_MASK | AA_MASK | INTERPOLATION_MASK;
232
    ADVANCED_HINTS_MASK = TEXT_AA_MASK | AA_MASK | INTERPOLATION_MASK;
233
	ADVANCED_HINTS_DEFAULTS = ((SWT.DEFAULT + AA_WHOLE_NUMBER) << TEXT_AA_SHIFT)
233
    ADVANCED_HINTS_DEFAULTS = ((SWT.DEFAULT + AA_WHOLE_NUMBER) << TEXT_AA_SHIFT)
234
			| ((SWT.DEFAULT + AA_WHOLE_NUMBER) << AA_SHIFT)
234
            | ((SWT.DEFAULT + AA_WHOLE_NUMBER) << AA_SHIFT)
235
			| ((SWT.DEFAULT + INTERPOLATION_WHOLE_NUMBER) << INTERPOLATION_SHIFT);
235
            | ((SWT.DEFAULT + INTERPOLATION_WHOLE_NUMBER) << INTERPOLATION_SHIFT);
236
}
236
}
237
237
238
private final LazyState appliedState = new LazyState();
238
private final LazyState appliedState = new LazyState();
Lines 254-261 Link Here
254
 * @param gc the GC
254
 * @param gc the GC
255
 */
255
 */
256
public SWTGraphics(GC gc) {
256
public SWTGraphics(GC gc) {
257
	this.gc = gc;
257
    this.gc = gc;
258
	init();
258
    init();
259
}
259
}
260
260
261
/**
261
/**
Lines 263-271 Link Here
263
 * {@link #checkGC()}.
263
 * {@link #checkGC()}.
264
 */
264
 */
265
protected final void checkFill() {
265
protected final void checkFill() {
266
	if (!currentState.bgColor.equals(appliedState.bgColor) && currentState.bgPattern == null)
266
    if (!currentState.bgColor.equals(appliedState.bgColor) && currentState.bgPattern == null)
267
		gc.setBackground(appliedState.bgColor = currentState.bgColor);
267
        gc.setBackground(appliedState.bgColor = currentState.bgColor);
268
	checkGC();
268
    checkGC();
269
}
269
}
270
270
271
/**
271
/**
Lines 274-287 Link Here
274
 * interpolation, and other settings.
274
 * interpolation, and other settings.
275
 */
275
 */
276
protected final void checkGC() {
276
protected final void checkGC() {
277
	if (appliedState.relativeClip != currentState.relativeClip) {
277
    if (appliedState.relativeClip != currentState.relativeClip) {
278
		appliedState.relativeClip = currentState.relativeClip;
278
        appliedState.relativeClip = currentState.relativeClip;
279
		currentState.relativeClip.setOn(gc, translateX, translateY);
279
        currentState.relativeClip.setOn(gc, translateX, translateY);
280
	}
280
    }
281
	if (appliedState.graphicHints != currentState.graphicHints) {
281
    if (appliedState.graphicHints != currentState.graphicHints) {
282
		reconcileHints(appliedState.graphicHints, currentState.graphicHints);
282
        reconcileHints(appliedState.graphicHints, currentState.graphicHints);
283
		appliedState.graphicHints = currentState.graphicHints;
283
        appliedState.graphicHints = currentState.graphicHints;
284
	}
284
    }
285
}
285
}
286
286
287
/**
287
/**
Lines 289-315 Link Here
289
 * changes will be pushed to the GC.  Also calls {@link #checkGC()}.
289
 * changes will be pushed to the GC.  Also calls {@link #checkGC()}.
290
 */
290
 */
291
protected final void checkPaint() {
291
protected final void checkPaint() {
292
	checkGC();
292
    checkGC();
293
	if (!currentState.fgColor.equals(appliedState.fgColor) && currentState.fgPattern == null)
293
    if (!currentState.fgColor.equals(appliedState.fgColor) && currentState.fgPattern == null)
294
		gc.setForeground(appliedState.fgColor = currentState.fgColor);
294
        gc.setForeground(appliedState.fgColor = currentState.fgColor);
295
	if (appliedState.lineWidth != currentState.lineWidth)
295
    if (appliedState.lineWidth != currentState.lineWidth)
296
		gc.setLineWidth(appliedState.lineWidth = currentState.lineWidth);
296
        gc.setLineWidth(appliedState.lineWidth = currentState.lineWidth);
297
	if (!currentState.bgColor.equals(appliedState.bgColor) && currentState.bgPattern == null)
297
    if (!currentState.bgColor.equals(appliedState.bgColor) && currentState.bgPattern == null)
298
		gc.setBackground(appliedState.bgColor = currentState.bgColor);
298
        gc.setBackground(appliedState.bgColor = currentState.bgColor);
299
}
299
}
300
300
301
/**
301
/**
302
 * @since 3.1
302
 * @since 3.1
303
 */
303
 */
304
private void checkSharedClipping() {
304
private void checkSharedClipping() {
305
	if (sharedClipping) {
305
    if (sharedClipping) {
306
		sharedClipping = false;
306
        sharedClipping = false;
307
		
307
        
308
		boolean previouslyApplied = (appliedState == currentState.relativeClip);
308
        boolean previouslyApplied = (appliedState == currentState.relativeClip);
309
		currentState.relativeClip = currentState.relativeClip.getCopy();
309
        currentState.relativeClip = currentState.relativeClip.getCopy();
310
		if (previouslyApplied)
310
        if (previouslyApplied)
311
			appliedState.relativeClip = currentState.relativeClip;
311
            appliedState.relativeClip = currentState.relativeClip;
312
	}
312
    }
313
}
313
}
314
314
315
/**
315
/**
Lines 317-1155 Link Here
317
 * {@link #checkPaint()} and {@link #checkFill()}.
317
 * {@link #checkPaint()} and {@link #checkFill()}.
318
 */
318
 */
319
protected final void checkText() {
319
protected final void checkText() {
320
	checkPaint();
320
    checkPaint();
321
	if (!appliedState.font.equals(currentState.font))
321
    if (!appliedState.font.equals(currentState.font))
322
		gc.setFont(appliedState.font = currentState.font);
322
        gc.setFont(appliedState.font = currentState.font);
323
}
323
}
324
324
325
/**
325
/**
326
 * @see Graphics#clipRect(Rectangle)
326
 * @see Graphics#clipRect(Rectangle)
327
 */
327
 */
328
public void clipRect(Rectangle rect) {
328
public void clipRect(Rectangle rect) {
329
	if (currentState.relativeClip == null)
329
    if (currentState.relativeClip == null)
330
		throw new IllegalStateException("The current clipping area does not " + //$NON-NLS-1$
330
        throw new IllegalStateException("The current clipping area does not " + //$NON-NLS-1$
331
		"support intersection."); //$NON-NLS-1$
331
        "support intersection."); //$NON-NLS-1$
332
	checkSharedClipping();
332
    checkSharedClipping();
333
	currentState.relativeClip.intersect(rect.x, rect.y, rect.right(), rect.bottom());
333
    currentState.relativeClip.intersect(rect.x, rect.y, rect.right(), rect.bottom());
334
	appliedState.relativeClip = null;
334
    appliedState.relativeClip = null;
335
}
335
}
336
336
337
/**
337
/**
338
 * @see Graphics#dispose()
338
 * @see Graphics#dispose()
339
 */
339
 */
340
public void dispose() {
340
public void dispose() {
341
	while (stackPointer > 0)
341
    while (stackPointer > 0)
342
		popState();
342
        popState();
343
	if (transform != null)
343
    if (transform != null)
344
		transform.dispose();
344
        transform.dispose();
345
}
345
}
346
346
347
/**
347
/**
348
 * @see Graphics#drawArc(int, int, int, int, int, int)
348
 * @see Graphics#drawArc(int, int, int, int, int, int)
349
 */
349
 */
350
public void drawArc(int x, int y, int width, int height, int offset, int length) {
350
public void drawArc(int x, int y, int width, int height, int offset, int length) {
351
	checkPaint();
351
    checkPaint();
352
	gc.drawArc(x + translateX, y + translateY, width, height, offset, length);
352
    gc.drawArc(x + translateX, y + translateY, width, height, offset, length);
353
}
353
}
354
354
355
/**
355
/**
356
 * @see Graphics#drawFocus(int, int, int, int)
356
 * @see Graphics#drawFocus(int, int, int, int)
357
 */
357
 */
358
public void drawFocus(int x, int y, int w, int h) {
358
public void drawFocus(int x, int y, int w, int h) {
359
	checkPaint();
359
    checkPaint();
360
	gc.drawFocus(x + translateX, y + translateY, w + 1, h + 1);
360
    gc.drawFocus(x + translateX, y + translateY, w + 1, h + 1);
361
}
361
}
362
362
363
/**
363
/**
364
 * @see Graphics#drawImage(Image, int, int)
364
 * @see Graphics#drawImage(Image, int, int)
365
 */
365
 */
366
public void drawImage(Image srcImage, int x, int y) {
366
public void drawImage(Image srcImage, int x, int y) {
367
	checkGC();
367
    checkGC();
368
	gc.drawImage(srcImage, x + translateX, y + translateY);
368
    gc.drawImage(srcImage, x + translateX, y + translateY);
369
}
369
}
370
370
371
/**
371
/**
372
 * @see Graphics#drawImage(Image, int, int, int, int, int, int, int, int)
372
 * @see Graphics#drawImage(Image, int, int, int, int, int, int, int, int)
373
 */
373
 */
374
public void drawImage(Image srcImage,
374
public void drawImage(Image srcImage,
375
		int x1, int y1, int w1, int h1,
375
        int x1, int y1, int w1, int h1,
376
		int x2, int y2, int w2, int h2) {
376
        int x2, int y2, int w2, int h2) {
377
	checkGC();
377
    checkGC();
378
	gc.drawImage(srcImage, x1, y1, w1, h1, x2 + translateX, y2 + translateY, w2, h2);
378
    gc.drawImage(srcImage, x1, y1, w1, h1, x2 + translateX, y2 + translateY, w2, h2);
379
}
379
}
380
380
381
/**
381
/**
382
 * @see Graphics#drawLine(int, int, int, int)
382
 * @see Graphics#drawLine(int, int, int, int)
383
 */
383
 */
384
public void drawLine(int x1, int y1, int x2, int y2) {
384
public void drawLine(int x1, int y1, int x2, int y2) {
385
	checkPaint();
385
    checkPaint();
386
	gc.drawLine(x1 + translateX, y1 + translateY, x2 + translateX, y2 + translateY);
386
    gc.drawLine(x1 + translateX, y1 + translateY, x2 + translateX, y2 + translateY);
387
}
387
}
388
388
389
/**
389
/**
390
 * @see Graphics#drawOval(int, int, int, int)
390
 * @see Graphics#drawOval(int, int, int, int)
391
 */
391
 */
392
public void drawOval(int x, int y, int width, int height) {
392
public void drawOval(int x, int y, int width, int height) {
393
	checkPaint();
393
    checkPaint();
394
	gc.drawOval(x + translateX, y + translateY, width, height);
394
    gc.drawOval(x + translateX, y + translateY, width, height);
395
}
395
}
396
396
397
/**
397
/**
398
 * This method requires advanced graphics support. A check should be made to
399
 * ensure advanced graphics is supported in the user's environment before
400
 * calling this method. See {@link GC#getAdvanced()}.
401
 * 
398
 * @see Graphics#drawPath(Path)
402
 * @see Graphics#drawPath(Path)
399
 */
403
 */
400
public void drawPath(Path path) {
404
public void drawPath(Path path) {
401
	checkPaint();
405
    checkPaint();
402
	initTransform(false);
406
    initTransform(false);
403
	gc.drawPath(path);
407
    gc.drawPath(path);
404
}
408
}
405
409
406
/**
410
/**
407
 * @see Graphics#drawPoint(int, int)
411
 * @see Graphics#drawPoint(int, int)
408
 */
412
 */
409
public void drawPoint(int x, int y) {
413
public void drawPoint(int x, int y) {
410
	checkPaint();
414
    checkPaint();
411
	gc.drawPoint(x + translateX, y + translateY);
415
    gc.drawPoint(x + translateX, y + translateY);
412
}
416
}
413
417
414
/**
418
/**
415
 * @see Graphics#drawPolygon(int[])
419
 * @see Graphics#drawPolygon(int[])
416
 */
420
 */
417
public void drawPolygon(int[] points) {
421
public void drawPolygon(int[] points) {
418
	checkPaint();
422
    checkPaint();
419
	try {
423
    try {
420
		translatePointArray(points, translateX, translateY);
424
        translatePointArray(points, translateX, translateY);
421
		gc.drawPolygon(points);
425
        gc.drawPolygon(points);
422
	} finally {
426
    } finally {
423
		translatePointArray(points, -translateX, -translateY);
427
        translatePointArray(points, -translateX, -translateY);
424
	}
428
    }
425
}
429
}
426
430
427
/**
431
/**
428
 * @see Graphics#drawPolygon(PointList)
432
 * @see Graphics#drawPolygon(PointList)
429
 */
433
 */
430
public void drawPolygon(PointList points) {
434
public void drawPolygon(PointList points) {
431
	drawPolygon(points.toIntArray());
435
    drawPolygon(points.toIntArray());
432
}
436
}
433
437
434
/**
438
/**
435
 * @see Graphics#drawPolyline(int[])
439
 * @see Graphics#drawPolyline(int[])
436
 */
440
 */
437
public void drawPolyline(int[] points) {
441
public void drawPolyline(int[] points) {
438
	checkPaint();
442
    checkPaint();
439
	try {
443
    try {
440
		translatePointArray(points, translateX, translateY);
444
        translatePointArray(points, translateX, translateY);
441
		gc.drawPolyline(points);
445
        gc.drawPolyline(points);
442
	} finally {
446
    } finally {
443
		translatePointArray(points, -translateX, -translateY);
447
        translatePointArray(points, -translateX, -translateY);
444
	}	
448
    }   
445
}
449
}
446
450
447
/**
451
/**
448
 * @see Graphics#drawPolyline(PointList)
452
 * @see Graphics#drawPolyline(PointList)
449
 */
453
 */
450
public void drawPolyline(PointList points) {
454
public void drawPolyline(PointList points) {
451
	drawPolyline(points.toIntArray());
455
    drawPolyline(points.toIntArray());
452
}
456
}
453
457
454
/**
458
/**
455
 * @see Graphics#drawRectangle(int, int, int, int)
459
 * @see Graphics#drawRectangle(int, int, int, int)
456
 */
460
 */
457
public void drawRectangle(int x, int y, int width, int height) {
461
public void drawRectangle(int x, int y, int width, int height) {
458
	checkPaint();
462
    checkPaint();
459
	gc.drawRectangle(x + translateX, y + translateY, width, height);
463
    gc.drawRectangle(x + translateX, y + translateY, width, height);
460
}
464
}
461
465
462
/**
466
/**
463
 * @see Graphics#drawRoundRectangle(Rectangle, int, int)
467
 * @see Graphics#drawRoundRectangle(Rectangle, int, int)
464
 */
468
 */
465
public void drawRoundRectangle(Rectangle r, int arcWidth, int arcHeight) {
469
public void drawRoundRectangle(Rectangle r, int arcWidth, int arcHeight) {
466
	checkPaint();
470
    checkPaint();
467
	gc.drawRoundRectangle(r.x + translateX, r.y + translateY, r.width, r.height, 
471
    gc.drawRoundRectangle(r.x + translateX, r.y + translateY, r.width, r.height, 
468
							arcWidth, arcHeight);
472
                            arcWidth, arcHeight);
469
}
473
}
470
474
471
/**
475
/**
472
 * @see Graphics#drawString(String, int, int)
476
 * @see Graphics#drawString(String, int, int)
473
 */
477
 */
474
public void drawString(String s, int x, int y) {
478
public void drawString(String s, int x, int y) {
475
	checkText();
479
    checkText();
476
	gc.drawString(s, x + translateX, y + translateY, true);
480
    gc.drawString(s, x + translateX, y + translateY, true);
477
}
481
}
478
482
479
/**
483
/**
480
 * @see Graphics#drawText(String, int, int)
484
 * @see Graphics#drawText(String, int, int)
481
 */
485
 */
482
public void drawText(String s, int x, int y) {
486
public void drawText(String s, int x, int y) {
483
	checkText();
487
    checkText();
484
	gc.drawText(s, x + translateX, y + translateY, true);
488
    gc.drawText(s, x + translateX, y + translateY, true);
485
}
489
}
486
490
487
/**
491
/**
488
 * @see Graphics#drawTextLayout(TextLayout, int, int, int, int, Color, Color)
492
 * @see Graphics#drawTextLayout(TextLayout, int, int, int, int, Color, Color)
489
 */
493
 */
490
public void drawTextLayout(TextLayout layout, int x, int y, int selectionStart,
494
public void drawTextLayout(TextLayout layout, int x, int y, int selectionStart,
491
		int selectionEnd, Color selectionForeground, Color selectionBackground) {
495
        int selectionEnd, Color selectionForeground, Color selectionBackground) {
492
	//$TODO probably just call checkPaint since Font and BG color don't apply
496
    //$TODO probably just call checkPaint since Font and BG color don't apply
493
	checkText();
497
    checkText();
494
	layout.draw(gc, x + translateX, y + translateY, selectionStart, selectionEnd,
498
    layout.draw(gc, x + translateX, y + translateY, selectionStart, selectionEnd,
495
			selectionForeground, selectionBackground);
499
            selectionForeground, selectionBackground);
496
}
500
}
497
501
498
/**
502
/**
499
 * @see Graphics#fillArc(int, int, int, int, int, int)
503
 * @see Graphics#fillArc(int, int, int, int, int, int)
500
 */
504
 */
501
public void fillArc(int x, int y, int width, int height, int offset, int length) {
505
public void fillArc(int x, int y, int width, int height, int offset, int length) {
502
	checkFill();
506
    checkFill();
503
	gc.fillArc(x + translateX, y + translateY, width, height, offset, length);
507
    gc.fillArc(x + translateX, y + translateY, width, height, offset, length);
504
}
508
}
505
509
506
/**
510
/**
507
 * @see Graphics#fillGradient(int, int, int, int, boolean)
511
 * @see Graphics#fillGradient(int, int, int, int, boolean)
508
 */
512
 */
509
public void fillGradient(int x, int y, int w, int h, boolean vertical) {
513
public void fillGradient(int x, int y, int w, int h, boolean vertical) {
510
	checkPaint();
514
    checkPaint();
511
	gc.fillGradientRectangle(x + translateX, y + translateY, w, h, vertical);
515
    gc.fillGradientRectangle(x + translateX, y + translateY, w, h, vertical);
512
}
516
}
513
517
514
/**
518
/**
515
 * @see Graphics#fillOval(int, int, int, int)
519
 * @see Graphics#fillOval(int, int, int, int)
516
 */
520
 */
517
public void fillOval(int x, int y, int width, int height) {
521
public void fillOval(int x, int y, int width, int height) {
518
	checkFill();
522
    checkFill();
519
	gc.fillOval(x + translateX, y + translateY, width, height);
523
    gc.fillOval(x + translateX, y + translateY, width, height);
520
}
524
}
521
525
522
/**
526
/**
527
 * This method requires advanced graphics support. A check should be made to
528
 * ensure advanced graphics is supported in the user's environment before
529
 * calling this method. See {@link GC#getAdvanced()}.
530
 * 
523
 * @see Graphics#fillPath(Path)
531
 * @see Graphics#fillPath(Path)
524
 */
532
 */
525
public void fillPath(Path path) {
533
public void fillPath(Path path) {
526
	checkFill();
534
    checkFill();
527
	initTransform(false);
535
    initTransform(false);
528
	gc.fillPath(path);
536
    gc.fillPath(path);
529
}
537
}
530
538
531
/**
539
/**
532
 * @see Graphics#fillPolygon(int[])
540
 * @see Graphics#fillPolygon(int[])
533
 */
541
 */
534
public void fillPolygon(int[] points) {
542
public void fillPolygon(int[] points) {
535
	checkFill();
543
    checkFill();
536
	try {
544
    try {
537
		translatePointArray(points, translateX, translateY);
545
        translatePointArray(points, translateX, translateY);
538
		gc.fillPolygon(points);
546
        gc.fillPolygon(points);
539
	} finally {
547
    } finally {
540
		translatePointArray(points, -translateX, -translateY);
548
        translatePointArray(points, -translateX, -translateY);
541
	}
549
    }
542
}
550
}
543
551
544
/**
552
/**
545
 * @see Graphics#fillPolygon(PointList)
553
 * @see Graphics#fillPolygon(PointList)
546
 */
554
 */
547
public void fillPolygon(PointList points) {
555
public void fillPolygon(PointList points) {
548
	fillPolygon(points.toIntArray());
556
    fillPolygon(points.toIntArray());
549
}
557
}
550
558
551
/**
559
/**
552
 * @see Graphics#fillRectangle(int, int, int, int)
560
 * @see Graphics#fillRectangle(int, int, int, int)
553
 */
561
 */
554
public void fillRectangle(int x, int y, int width, int height) {
562
public void fillRectangle(int x, int y, int width, int height) {
555
	checkFill();
563
    checkFill();
556
	gc.fillRectangle(x + translateX, y + translateY, width, height);
564
    gc.fillRectangle(x + translateX, y + translateY, width, height);
557
}
565
}
558
566
559
/**
567
/**
560
 * @see Graphics#fillRoundRectangle(Rectangle, int, int)
568
 * @see Graphics#fillRoundRectangle(Rectangle, int, int)
561
 */
569
 */
562
public void fillRoundRectangle(Rectangle r, int arcWidth, int arcHeight) {
570
public void fillRoundRectangle(Rectangle r, int arcWidth, int arcHeight) {
563
	checkFill();
571
    checkFill();
564
	gc.fillRoundRectangle(r.x + translateX, r.y + translateY, r.width, r.height, 
572
    gc.fillRoundRectangle(r.x + translateX, r.y + translateY, r.width, r.height, 
565
							arcWidth, arcHeight);
573
                            arcWidth, arcHeight);
566
}
574
}
567
575
568
/**
576
/**
569
 * @see Graphics#fillString(String, int, int)
577
 * @see Graphics#fillString(String, int, int)
570
 */
578
 */
571
public void fillString(String s, int x, int y) {
579
public void fillString(String s, int x, int y) {
572
	checkText();
580
    checkText();
573
	gc.drawString(s, x + translateX, y + translateY, false);
581
    gc.drawString(s, x + translateX, y + translateY, false);
574
}
582
}
575
583
576
/**
584
/**
577
 * @see Graphics#fillText(String, int, int)
585
 * @see Graphics#fillText(String, int, int)
578
 */
586
 */
579
public void fillText(String s, int x, int y) {
587
public void fillText(String s, int x, int y) {
580
	checkText();
588
    checkText();
581
	gc.drawText(s, x + translateX, y + translateY, false);
589
    gc.drawText(s, x + translateX, y + translateY, false);
582
}
590
}
583
591
584
/**
592
/**
585
 * @see Graphics#getAlpha()
593
 * @see Graphics#getAlpha()
586
 */
594
 */
587
public int getAlpha() {
595
public int getAlpha() {
588
	return currentState.alpha;
596
    return currentState.alpha;
589
}
597
}
590
598
591
/**
599
/**
592
 * @see Graphics#getAntialias()
600
 * @see Graphics#getAntialias()
593
 */
601
 */
594
public int getAntialias() {
602
public int getAntialias() {
595
	return ((currentState.graphicHints & AA_MASK) >> AA_SHIFT) - AA_WHOLE_NUMBER;
603
    return ((currentState.graphicHints & AA_MASK) >> AA_SHIFT) - AA_WHOLE_NUMBER;
596
}
604
}
597
605
598
/**
606
/**
599
 * @see Graphics#getBackgroundColor()
607
 * @see Graphics#getBackgroundColor()
600
 */
608
 */
601
public Color getBackgroundColor() {
609
public Color getBackgroundColor() {
602
	return currentState.bgColor;
610
    return currentState.bgColor;
603
}
611
}
604
612
605
/**
613
/**
606
 * @see Graphics#getClip(Rectangle)
614
 * @see Graphics#getClip(Rectangle)
607
 */
615
 */
608
public Rectangle getClip(Rectangle rect) {
616
public Rectangle getClip(Rectangle rect) {
609
	if (currentState.relativeClip != null) {
617
    if (currentState.relativeClip != null) {
610
		currentState.relativeClip.getBoundingBox(rect);
618
        currentState.relativeClip.getBoundingBox(rect);
611
		return rect;
619
        return rect;
612
	}
620
    }
613
	throw new IllegalStateException(
621
    throw new IllegalStateException(
614
			"Clipping can no longer be queried due to transformations"); //$NON-NLS-1$
622
            "Clipping can no longer be queried due to transformations"); //$NON-NLS-1$
615
}
623
}
616
624
617
/**
625
/**
618
 * @see Graphics#getFillRule()
626
 * @see Graphics#getFillRule()
619
 */
627
 */
620
public int getFillRule() {
628
public int getFillRule() {
621
	return ((currentState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER; 
629
    return ((currentState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER; 
622
}
630
}
623
631
624
/**
632
/**
625
 * @see Graphics#getFont()
633
 * @see Graphics#getFont()
626
 */
634
 */
627
public Font getFont() {
635
public Font getFont() {
628
	return currentState.font;
636
    return currentState.font;
629
}
637
}
630
638
631
/**
639
/**
632
 * @see Graphics#getFontMetrics()
640
 * @see Graphics#getFontMetrics()
633
 */
641
 */
634
public FontMetrics getFontMetrics() {
642
public FontMetrics getFontMetrics() {
635
	checkText();
643
    checkText();
636
	return gc.getFontMetrics();
644
    return gc.getFontMetrics();
637
}
645
}
638
646
639
/**
647
/**
640
 * @see Graphics#getForegroundColor()
648
 * @see Graphics#getForegroundColor()
641
 */
649
 */
642
public Color getForegroundColor() {
650
public Color getForegroundColor() {
643
	return currentState.fgColor;
651
    return currentState.fgColor;
644
}
652
}
645
653
646
/**
654
/**
647
 * @see Graphics#getInterpolation()
655
 * @see Graphics#getInterpolation()
648
 */
656
 */
649
public int getInterpolation() {
657
public int getInterpolation() {
650
	return ((currentState.graphicHints & INTERPOLATION_MASK) >> INTERPOLATION_SHIFT)
658
    return ((currentState.graphicHints & INTERPOLATION_MASK) >> INTERPOLATION_SHIFT)
651
			- INTERPOLATION_WHOLE_NUMBER;
659
            - INTERPOLATION_WHOLE_NUMBER;
652
}
660
}
653
661
654
/**
662
/**
655
 * @see Graphics#getLineCap()
663
 * @see Graphics#getLineCap()
656
 */
664
 */
657
public int getLineCap() {
665
public int getLineCap() {
658
	return (currentState.graphicHints & CAP_MASK) >> CAP_SHIFT;
666
    return (currentState.graphicHints & CAP_MASK) >> CAP_SHIFT;
659
}
667
}
660
668
661
/**
669
/**
662
 * @see Graphics#getLineJoin()
670
 * @see Graphics#getLineJoin()
663
 */
671
 */
664
public int getLineJoin() {
672
public int getLineJoin() {
665
	return (currentState.graphicHints & JOIN_MASK) >> JOIN_SHIFT;
673
    return (currentState.graphicHints & JOIN_MASK) >> JOIN_SHIFT;
666
}
674
}
667
675
668
/**
676
/**
669
 * @see Graphics#getLineStyle()
677
 * @see Graphics#getLineStyle()
670
 */
678
 */
671
public int getLineStyle() {
679
public int getLineStyle() {
672
	return currentState.graphicHints & LINE_STYLE_MASK;
680
    return currentState.graphicHints & LINE_STYLE_MASK;
673
}
681
}
674
682
675
/**
683
/**
676
 * @see Graphics#getLineWidth()
684
 * @see Graphics#getLineWidth()
677
 */
685
 */
678
public int getLineWidth() {
686
public int getLineWidth() {
679
	return currentState.lineWidth;
687
    return currentState.lineWidth;
680
}
688
}
681
689
682
/**
690
/**
683
 * @see Graphics#getTextAntialias()
691
 * @see Graphics#getTextAntialias()
684
 */
692
 */
685
public int getTextAntialias() {
693
public int getTextAntialias() {
686
	return ((currentState.graphicHints & TEXT_AA_MASK) >> TEXT_AA_SHIFT) - AA_WHOLE_NUMBER;
694
    return ((currentState.graphicHints & TEXT_AA_MASK) >> TEXT_AA_SHIFT) - AA_WHOLE_NUMBER;
687
}
695
}
688
696
689
/**
697
/**
690
 * @see Graphics#getXORMode()
698
 * @see Graphics#getXORMode()
691
 */
699
 */
692
public boolean getXORMode() {
700
public boolean getXORMode() {
693
	return (currentState.graphicHints & XOR_MASK) != 0;
701
    return (currentState.graphicHints & XOR_MASK) != 0;
694
}
702
}
695
703
696
/**
704
/**
697
 * Called by constructor, initializes all State information for currentState
705
 * Called by constructor, initializes all State information for currentState
698
 */
706
 */
699
protected void init() {
707
protected void init() {
700
	currentState.bgColor = appliedState.bgColor = gc.getBackground();
708
    currentState.bgColor = appliedState.bgColor = gc.getBackground();
701
	currentState.fgColor = appliedState.fgColor = gc.getForeground();
709
    currentState.fgColor = appliedState.fgColor = gc.getForeground();
702
	currentState.font = appliedState.font = gc.getFont();
710
    currentState.font = appliedState.font = gc.getFont();
703
	currentState.lineWidth = appliedState.lineWidth = gc.getLineWidth();
711
    currentState.lineWidth = appliedState.lineWidth = gc.getLineWidth();
704
	currentState.graphicHints |= gc.getLineStyle();
712
    currentState.graphicHints |= gc.getLineStyle();
705
	currentState.graphicHints |= gc.getLineCap() << CAP_SHIFT;
713
    currentState.graphicHints |= gc.getLineCap() << CAP_SHIFT;
706
	currentState.graphicHints |= gc.getLineJoin() << JOIN_SHIFT;
714
    currentState.graphicHints |= gc.getLineJoin() << JOIN_SHIFT;
707
	currentState.graphicHints |= gc.getAdvanced() ? ADVANCED_GRAPHICS_MASK : 0;
715
    currentState.graphicHints |= gc.getAdvanced() ? ADVANCED_GRAPHICS_MASK : 0;
708
	currentState.graphicHints |= gc.getXORMode() ? XOR_MASK : 0;
716
    currentState.graphicHints |= gc.getXORMode() ? XOR_MASK : 0;
709
	
717
    
710
	appliedState.graphicHints = currentState.graphicHints;
718
    appliedState.graphicHints = currentState.graphicHints;
711
	
719
    
712
	currentState.relativeClip = new RectangleClipping(gc.getClipping());
720
    currentState.relativeClip = new RectangleClipping(gc.getClipping());
713
	currentState.lineDash = gc.getLineDash();
721
    currentState.lineDash = gc.getLineDash();
714
	currentState.alpha = gc.getAlpha();
722
    currentState.alpha = gc.getAlpha();
715
}
723
}
716
724
717
private void initTransform(boolean force) {
725
private void initTransform(boolean force) {
718
	if (!force && translateX == 0 && translateY == 0)
726
    if (!force && translateX == 0 && translateY == 0)
719
		return;
727
        return;
720
	if (transform == null) {
728
    if (transform == null) {
721
		transform = new Transform(Display.getCurrent());
729
        transform = new Transform(Display.getCurrent());
722
		elementsNeedUpdate = true;
730
        elementsNeedUpdate = true;
723
		transform.translate(translateX, translateY);
731
        transform.translate(translateX, translateY);
724
		translateX = 0;
732
        translateX = 0;
725
		translateY = 0;
733
        translateY = 0;
726
		gc.setTransform(transform);
734
        gc.setTransform(transform);
727
		currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
735
        currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
728
	}
736
    }
729
}
737
}
730
738
731
/**
739
/**
732
 * @see Graphics#popState()
740
 * @see Graphics#popState()
733
 */
741
 */
734
public void popState() {
742
public void popState() {
735
	stackPointer--;
743
    stackPointer--;
736
	restoreState((State)stack.get(stackPointer));
744
    restoreState((State)stack.get(stackPointer));
737
}
745
}
738
746
739
/**
747
/**
740
 * @see Graphics#pushState()
748
 * @see Graphics#pushState()
741
 */
749
 */
742
public void pushState() {
750
public void pushState() {
743
	if (currentState.relativeClip == null)
751
    if (currentState.relativeClip == null)
744
		throw new IllegalStateException("The clipping has been modified in" + //$NON-NLS-1$
752
        throw new IllegalStateException("The clipping has been modified in" + //$NON-NLS-1$
745
				"a way that cannot be saved and restored."); //$NON-NLS-1$
753
                "a way that cannot be saved and restored."); //$NON-NLS-1$
746
	try {
754
    try {
747
		State s;
755
        State s;
748
		currentState.dx = translateX;
756
        currentState.dx = translateX;
749
		currentState.dy = translateY;
757
        currentState.dy = translateY;
750
				
758
                
751
		if (elementsNeedUpdate) {
759
        if (elementsNeedUpdate) {
752
			elementsNeedUpdate = false;
760
            elementsNeedUpdate = false;
753
			transform.getElements(currentState.affineMatrix = new float[6]);
761
            transform.getElements(currentState.affineMatrix = new float[6]);
754
		}
762
        }
755
		if (stack.size() > stackPointer) {
763
        if (stack.size() > stackPointer) {
756
			s = (State)stack.get(stackPointer);
764
            s = (State)stack.get(stackPointer);
757
			s.copyFrom(currentState);
765
            s.copyFrom(currentState);
758
		} else {
766
        } else {
759
			stack.add(currentState.clone());
767
            stack.add(currentState.clone());
760
		}
768
        }
761
		sharedClipping = true;
769
        sharedClipping = true;
762
		stackPointer++;
770
        stackPointer++;
763
	} catch (CloneNotSupportedException e) {
771
    } catch (CloneNotSupportedException e) {
764
		throw new RuntimeException(e);
772
        throw new RuntimeException(e);
765
	}
773
    }
766
}
774
}
767
775
768
private void reconcileHints(int applied, int hints) {
776
private void reconcileHints(int applied, int hints) {
769
	if (applied != hints) {
777
    if (applied != hints) {
770
		int changes = hints ^ applied;
778
        int changes = hints ^ applied;
771
		
779
        
772
		if ((changes & LINE_STYLE_MASK) != 0)
780
        if ((changes & LINE_STYLE_MASK) != 0)
773
			gc.setLineStyle(hints & LINE_STYLE_MASK);
781
            gc.setLineStyle(hints & LINE_STYLE_MASK);
774
		
782
        
775
		if ((changes & XOR_MASK) != 0)
783
        if ((changes & XOR_MASK) != 0)
776
			gc.setXORMode((hints & XOR_MASK) != 0);
784
            gc.setXORMode((hints & XOR_MASK) != 0);
777
		
785
        
778
		//Check to see if there is anything remaining
786
        //Check to see if there is anything remaining
779
		changes &= ~(XOR_MASK | LINE_STYLE_MASK);
787
        changes &= ~(XOR_MASK | LINE_STYLE_MASK);
780
		if (changes == 0)
788
        if (changes == 0)
781
			return;
789
            return;
782
		
790
        
783
		if ((changes & JOIN_MASK) != 0)
791
        if ((changes & JOIN_MASK) != 0)
784
			gc.setLineJoin((hints & JOIN_MASK) >> JOIN_SHIFT);
792
            gc.setLineJoin((hints & JOIN_MASK) >> JOIN_SHIFT);
785
		if ((changes & CAP_MASK) != 0)
793
        if ((changes & CAP_MASK) != 0)
786
			gc.setLineCap((hints & CAP_MASK) >> CAP_SHIFT);
794
            gc.setLineCap((hints & CAP_MASK) >> CAP_SHIFT);
787
		
795
        
788
		if ((changes & INTERPOLATION_MASK) != 0)
796
        if ((changes & INTERPOLATION_MASK) != 0)
789
			gc.setInterpolation(((hints & INTERPOLATION_MASK) >> INTERPOLATION_SHIFT) - INTERPOLATION_WHOLE_NUMBER);
797
            gc.setInterpolation(((hints & INTERPOLATION_MASK) >> INTERPOLATION_SHIFT) - INTERPOLATION_WHOLE_NUMBER);
790
		
798
        
791
		if ((changes & FILL_RULE_MASK) != 0)
799
        if ((changes & FILL_RULE_MASK) != 0)
792
			gc.setFillRule(((hints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER);
800
            gc.setFillRule(((hints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER);
793
		
801
        
794
		if ((changes & AA_MASK) != 0)
802
        if ((changes & AA_MASK) != 0)
795
			gc.setAntialias(((hints & AA_MASK) >> AA_SHIFT) - AA_WHOLE_NUMBER);
803
            gc.setAntialias(((hints & AA_MASK) >> AA_SHIFT) - AA_WHOLE_NUMBER);
796
		if ((changes & TEXT_AA_MASK) != 0)
804
        if ((changes & TEXT_AA_MASK) != 0)
797
			gc.setTextAntialias(((hints & TEXT_AA_MASK) >> TEXT_AA_SHIFT) - AA_WHOLE_NUMBER);
805
            gc.setTextAntialias(((hints & TEXT_AA_MASK) >> TEXT_AA_SHIFT) - AA_WHOLE_NUMBER);
798
		
806
        
799
		// If advanced was flagged, but none of the conditions which trigger advanced
807
        // If advanced was flagged, but none of the conditions which trigger advanced
800
		// actually got applied, force advanced graphics on.
808
        // actually got applied, force advanced graphics on.
801
		if ((changes & ADVANCED_GRAPHICS_MASK) != 0) {
809
        if ((changes & ADVANCED_GRAPHICS_MASK) != 0) {
802
			if ((hints & ADVANCED_GRAPHICS_MASK) != 0 && !gc.getAdvanced())
810
            if ((hints & ADVANCED_GRAPHICS_MASK) != 0 && !gc.getAdvanced())
803
				gc.setAdvanced(true);
811
                gc.setAdvanced(true);
804
		}
812
        }
805
	}
813
    }
806
}
814
}
807
815
808
/**
816
/**
809
 * @see Graphics#restoreState()
817
 * @see Graphics#restoreState()
810
 */
818
 */
811
public void restoreState() {
819
public void restoreState() {
812
	restoreState((State)stack.get(stackPointer - 1));
820
    restoreState((State)stack.get(stackPointer - 1));
813
}
821
}
814
822
815
/**
823
/**
816
 * Sets all State information to that of the given State, called by restoreState()
824
 * Sets all State information to that of the given State, called by restoreState()
817
 * @param s the State
825
 * @param s the State
818
 */
826
 */
819
protected void restoreState(State s) {	
827
protected void restoreState(State s) {  
820
	/*
828
    /*
821
	 * We must set the transformation matrix first since it affects things like clipping
829
     * We must set the transformation matrix first since it affects things like clipping
822
	 * regions and patterns.
830
     * regions and patterns.
823
	 */
831
     */
824
	setAffineMatrix(s.affineMatrix);
832
    setAffineMatrix(s.affineMatrix);
825
	currentState.relativeClip = s.relativeClip;
833
    currentState.relativeClip = s.relativeClip;
826
	sharedClipping = true;
834
    sharedClipping = true;
827
	
835
    
828
	//If the GC is currently advanced, but it was not when pushed, revert
836
    //If the GC is currently advanced, but it was not when pushed, revert
829
	if (gc.getAdvanced() && (s.graphicHints & ADVANCED_GRAPHICS_MASK) == 0) {
837
    if (gc.getAdvanced() && (s.graphicHints & ADVANCED_GRAPHICS_MASK) == 0) {
830
		//Set applied clip to null to force a re-setting of the clipping.
838
        //Set applied clip to null to force a re-setting of the clipping.
831
		appliedState.relativeClip = null;
839
        appliedState.relativeClip = null;
832
		gc.setAdvanced(false);
840
        gc.setAdvanced(false);
833
		appliedState.graphicHints &= ~ADVANCED_HINTS_MASK;
841
        appliedState.graphicHints &= ~ADVANCED_HINTS_MASK;
834
		appliedState.graphicHints |= ADVANCED_HINTS_DEFAULTS;
842
        appliedState.graphicHints |= ADVANCED_HINTS_DEFAULTS;
835
	}
843
    }
836
844
837
	setBackgroundColor(s.bgColor);
845
    setBackgroundColor(s.bgColor);
838
	setBackgroundPattern(s.bgPattern);
846
    setBackgroundPattern(s.bgPattern);
839
	
847
    
840
	setForegroundColor(s.fgColor);
848
    setForegroundColor(s.fgColor);
841
	setForegroundPattern(s.fgPattern);
849
    setForegroundPattern(s.fgPattern);
842
850
843
	setAlpha(s.alpha);
851
    setAlpha(s.alpha);
844
	setLineWidth(s.lineWidth);
852
    setLineWidth(s.lineWidth);
845
	setFont(s.font);
853
    setFont(s.font);
846
	//This method must come last because above methods will incorrectly set advanced state
854
    //This method must come last because above methods will incorrectly set advanced state
847
	setGraphicHints(s.graphicHints);
855
    setGraphicHints(s.graphicHints);
848
856
849
	translateX = currentState.dx = s.dx;
857
    translateX = currentState.dx = s.dx;
850
	translateY = currentState.dy = s.dy;
858
    translateY = currentState.dy = s.dy;
851
}
859
}
852
860
853
/**
861
/**
862
 * This method requires advanced graphics support. A check should be made to
863
 * ensure advanced graphics is supported in the user's environment before
864
 * calling this method. See {@link GC#getAdvanced()}.
865
 * 
854
 * @see Graphics#rotate(float)
866
 * @see Graphics#rotate(float)
855
 */
867
 */
856
public void rotate(float degrees) {
868
public void rotate(float degrees) {
857
	//Flush clipping, patter, etc., before applying transform
869
    //Flush clipping, patter, etc., before applying transform
858
	checkGC();
870
    checkGC();
859
	initTransform(true);
871
    initTransform(true);
860
	transform.rotate(degrees);
872
    transform.rotate(degrees);
861
	gc.setTransform(transform);
873
    gc.setTransform(transform);
862
	elementsNeedUpdate = true;
874
    elementsNeedUpdate = true;
863
875
864
	//Can no longer operate or maintain clipping
876
    //Can no longer operate or maintain clipping
865
	appliedState.relativeClip = currentState.relativeClip = null;
877
    appliedState.relativeClip = currentState.relativeClip = null;
866
}
878
}
867
879
868
/**
880
/**
869
 * @see Graphics#scale(double)
881
 * @see Graphics#scale(double)
870
 */
882
 */
871
public void scale(double factor) {
883
public void scale(double factor) {
872
	scale((float)factor, (float)factor);
884
    scale((float)factor, (float)factor);
873
}
885
}
874
886
875
/**
887
/**
888
 * This method requires advanced graphics support. A check should be made to
889
 * ensure advanced graphics is supported in the user's environment before
890
 * calling this method. See {@link GC#getAdvanced()}.
891
 * 
876
 * @see org.eclipse.draw2d.Graphics#scale(float, float)
892
 * @see org.eclipse.draw2d.Graphics#scale(float, float)
877
 */
893
 */
878
public void scale(float horizontal, float vertical) {
894
public void scale(float horizontal, float vertical) {
879
	//Flush any clipping before scaling
895
    //Flush any clipping before scaling
880
	checkGC();
896
    checkGC();
881
897
882
	initTransform(true);
898
    initTransform(true);
883
	transform.scale(horizontal, vertical);
899
    transform.scale(horizontal, vertical);
884
	gc.setTransform(transform);
900
    gc.setTransform(transform);
885
	elementsNeedUpdate = true;
901
    elementsNeedUpdate = true;
886
902
887
	checkSharedClipping();
903
    checkSharedClipping();
888
	if (currentState.relativeClip != null)
904
    if (currentState.relativeClip != null)
889
		currentState.relativeClip.scale(horizontal, vertical);
905
        currentState.relativeClip.scale(horizontal, vertical);
890
}
906
}
891
907
892
private void setAffineMatrix(float[] m) {
908
private void setAffineMatrix(float[] m) {
893
	if (!elementsNeedUpdate && currentState.affineMatrix == m)
909
    if (!elementsNeedUpdate && currentState.affineMatrix == m)
894
		return;
910
        return;
895
	currentState.affineMatrix = m;
911
    currentState.affineMatrix = m;
896
	if (m != null)
912
    if (m != null)
897
		transform.setElements(m[0], m[1], m[2], m[3], m[4], m[5]);
913
        transform.setElements(m[0], m[1], m[2], m[3], m[4], m[5]);
898
	else if (transform != null) {
914
    else if (transform != null) {
899
		transform.dispose();
915
        transform.dispose();
900
		transform = null;
916
        transform = null;
901
		elementsNeedUpdate = false;
917
        elementsNeedUpdate = false;
902
	}
918
    }
903
	gc.setTransform(transform);
919
    gc.setTransform(transform);
904
}
920
}
905
921
906
/**
922
/**
923
 * This method requires advanced graphics support. A check should be made to
924
 * ensure advanced graphics is supported in the user's environment before
925
 * calling this method. See {@link GC#getAdvanced()}.
926
 * 
907
 * @see Graphics#setAlpha(int)
927
 * @see Graphics#setAlpha(int)
908
 */
928
 */
909
public void setAlpha(int alpha) {
929
public void setAlpha(int alpha) {
910
	currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
930
    currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
911
	if (currentState.alpha != alpha)
931
    if (currentState.alpha != alpha)
912
		gc.setAlpha(this.currentState.alpha = alpha);
932
        gc.setAlpha(this.currentState.alpha = alpha);
913
}
933
}
914
934
915
/**
935
/**
936
 * This method requires advanced graphics support. A check should be made to
937
 * ensure advanced graphics is supported in the user's environment before
938
 * calling this method. See {@link GC#getAdvanced()}.
939
 * 
916
 * @see Graphics#setAntialias(int)
940
 * @see Graphics#setAntialias(int)
917
 */
941
 */
918
public void setAntialias(int value) {
942
public void setAntialias(int value) {
919
	currentState.graphicHints &= ~AA_MASK;
943
    currentState.graphicHints &= ~AA_MASK;
920
	currentState.graphicHints |= ADVANCED_GRAPHICS_MASK | (value + AA_WHOLE_NUMBER) << AA_SHIFT;
944
    currentState.graphicHints |= ADVANCED_GRAPHICS_MASK | (value + AA_WHOLE_NUMBER) << AA_SHIFT;
921
}
945
}
922
946
923
/**
947
/**
924
 * @see Graphics#setBackgroundColor(Color)
948
 * @see Graphics#setBackgroundColor(Color)
925
 */
949
 */
926
public void setBackgroundColor(Color color) {
950
public void setBackgroundColor(Color color) {
927
	currentState.bgColor = color;
951
    currentState.bgColor = color;
928
	if (currentState.bgPattern != null) {
952
    if (currentState.bgPattern != null) {
929
		currentState.bgPattern = null;
953
        currentState.bgPattern = null;
930
		//Force the BG color to be stale
954
        //Force the BG color to be stale
931
		appliedState.bgColor = null;
955
        appliedState.bgColor = null;
932
	}
956
    }
933
}
957
}
934
958
935
/**
959
/**
936
 * @see Graphics#setBackgroundPattern(Pattern)
960
 * @see Graphics#setBackgroundPattern(Pattern)
937
 */
961
 */
938
public void setBackgroundPattern(Pattern pattern) {
962
public void setBackgroundPattern(Pattern pattern) {
939
	currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
963
    currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
940
	if (currentState.bgPattern == pattern)
964
    if (currentState.bgPattern == pattern)
941
		return;
965
        return;
942
	currentState.bgPattern = pattern;
966
    currentState.bgPattern = pattern;
943
967
944
	if (pattern != null)
968
    if (pattern != null) {
945
		initTransform(true);
969
        initTransform(true);
946
	gc.setBackgroundPattern(pattern);
970
    }
971
    gc.setBackgroundPattern(pattern);
947
}
972
}
948
973
949
/**
974
/**
975
 * This method requires advanced graphics support. A check should be made to
976
 * ensure advanced graphics is supported in the user's environment before
977
 * calling this method. See {@link GC#getAdvanced()}.
978
 * 
950
 * @see Graphics#setClip(Path)
979
 * @see Graphics#setClip(Path)
951
 */
980
 */
952
public void setClip(Path path) {
981
public void setClip(Path path) {
953
	initTransform(false);
982
    initTransform(false);
954
	gc.setClipping(path);
983
    gc.setClipping(path);
955
	appliedState.relativeClip = currentState.relativeClip = null;
984
    appliedState.relativeClip = currentState.relativeClip = null;
956
}
985
}
957
986
958
/**
987
/**
959
 * @see Graphics#setClip(Rectangle)
988
 * @see Graphics#setClip(Rectangle)
960
 */
989
 */
961
public void setClip(Rectangle rect) {
990
public void setClip(Rectangle rect) {
962
	currentState.relativeClip = new RectangleClipping(rect);
991
    currentState.relativeClip = new RectangleClipping(rect);
963
}
992
}
964
993
965
/**
994
/**
966
 * @see Graphics#setFillRule(int)
995
 * @see Graphics#setFillRule(int)
967
 */
996
 */
968
public void setFillRule(int rule) {
997
public void setFillRule(int rule) {
969
	currentState.graphicHints &= ~FILL_RULE_MASK;
998
    currentState.graphicHints &= ~FILL_RULE_MASK;
970
	currentState.graphicHints |= (rule + FILL_RULE_WHOLE_NUMBER) << FILL_RULE_SHIFT;
999
    currentState.graphicHints |= (rule + FILL_RULE_WHOLE_NUMBER) << FILL_RULE_SHIFT;
971
}
1000
}
972
1001
973
/**
1002
/**
974
 * @see Graphics#setFont(Font)
1003
 * @see Graphics#setFont(Font)
975
 */
1004
 */
976
public void setFont(Font f) {
1005
public void setFont(Font f) {
977
	currentState.font = f;
1006
    currentState.font = f;
978
}
1007
}
979
1008
980
/**
1009
/**
981
 * @see Graphics#setForegroundColor(Color)
1010
 * @see Graphics#setForegroundColor(Color)
982
 */
1011
 */
983
public void setForegroundColor(Color color) {
1012
public void setForegroundColor(Color color) {
984
	currentState.fgColor = color;
1013
    currentState.fgColor = color;
985
	if (currentState.fgPattern != null) {
1014
    if (currentState.fgPattern != null) {
986
		currentState.fgPattern = null;
1015
        currentState.fgPattern = null;
987
		//Force fgColor to be stale
1016
        //Force fgColor to be stale
988
		appliedState.fgColor = null;
1017
        appliedState.fgColor = null;
989
	}
1018
    }
990
}
1019
}
991
1020
992
/**
1021
/**
993
 * @see Graphics#setForegroundPattern(Pattern)
1022
 * @see Graphics#setForegroundPattern(Pattern)
994
 */
1023
 */
995
public void setForegroundPattern(Pattern pattern) {
1024
public void setForegroundPattern(Pattern pattern) {
996
	currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
1025
    currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
997
	if (currentState.fgPattern == pattern)
1026
    if (currentState.fgPattern == pattern)
998
		return;
1027
        return;
999
	currentState.fgPattern = pattern;
1028
    currentState.fgPattern = pattern;
1000
1029
1001
	if (pattern != null)
1030
    if (pattern != null)
1002
		initTransform(true);
1031
        initTransform(true);
1003
	gc.setForegroundPattern(pattern);
1032
    gc.setForegroundPattern(pattern);
1004
}
1033
}
1005
1034
1006
private void setGraphicHints(int hints) {
1035
private void setGraphicHints(int hints) {
1007
	currentState.graphicHints = hints;
1036
    currentState.graphicHints = hints;
1008
}
1037
}
1009
1038
1010
/**
1039
/**
1040
 * This method requires advanced graphics support. A check should be made to
1041
 * ensure advanced graphics is supported in the user's environment before
1042
 * calling this method. See {@link GC#getAdvanced()}.
1043
 * 
1011
 * @see Graphics#setInterpolation(int)
1044
 * @see Graphics#setInterpolation(int)
1012
 */
1045
 */
1013
public void setInterpolation(int interpolation) {
1046
public void setInterpolation(int interpolation) {
1014
	//values range [-1, 3]
1047
    //values range [-1, 3]
1015
	currentState.graphicHints &= ~INTERPOLATION_MASK;
1048
    currentState.graphicHints &= ~INTERPOLATION_MASK;
1016
	currentState.graphicHints |= ADVANCED_GRAPHICS_MASK | (interpolation + INTERPOLATION_WHOLE_NUMBER) << INTERPOLATION_SHIFT; 
1049
    currentState.graphicHints |= ADVANCED_GRAPHICS_MASK | (interpolation + INTERPOLATION_WHOLE_NUMBER) << INTERPOLATION_SHIFT; 
1017
}
1050
}
1018
1051
1019
/**
1052
/**
1020
 * @see Graphics#setLineCap(int)
1053
 * @see Graphics#setLineCap(int)
1021
 */
1054
 */
1022
public void setLineCap(int cap) {
1055
public void setLineCap(int cap) {
1023
	currentState.graphicHints &= ~CAP_MASK;
1056
    currentState.graphicHints &= ~CAP_MASK;
1024
	currentState.graphicHints |= cap << CAP_SHIFT;
1057
    currentState.graphicHints |= cap << CAP_SHIFT;
1025
}
1058
}
1026
1059
1027
/**
1060
/**
1028
 * @see Graphics#setLineDash(int[])
1061
 * @see Graphics#setLineDash(int[])
1029
 */
1062
 */
1030
public void setLineDash(int[] dashes) {
1063
public void setLineDash(int[] dashes) {
1031
	if (dashes != null) {
1064
    if (dashes != null) {
1032
		int copy[] = new int[dashes.length];
1065
        int copy[] = new int[dashes.length];
1033
		for (int i = 0; i < dashes.length; i++) {
1066
        for (int i = 0; i < dashes.length; i++) {
1034
			int dash = dashes[i];
1067
            int dash = dashes[i];
1035
			if (dash <= 0)
1068
            if (dash <= 0)
1036
				SWT.error(SWT.ERROR_INVALID_ARGUMENT);
1069
                SWT.error(SWT.ERROR_INVALID_ARGUMENT);
1037
			copy[i] = dash;
1070
            copy[i] = dash;
1038
		}
1071
        }
1039
		currentState.lineDash = copy;
1072
        currentState.lineDash = copy;
1040
		setLineStyle(SWT.LINE_CUSTOM);
1073
        setLineStyle(SWT.LINE_CUSTOM);
1041
		gc.setLineDash(copy);
1074
        gc.setLineDash(copy);
1042
	} else {
1075
    } else {
1043
		currentState.lineDash = null;
1076
        currentState.lineDash = null;
1044
		setLineStyle(SWT.LINE_SOLID);
1077
        setLineStyle(SWT.LINE_SOLID);
1045
	}
1078
    }
1046
}
1079
}
1047
1080
1048
/**
1081
/**
1049
 * @see Graphics#setLineJoin(int)
1082
 * @see Graphics#setLineJoin(int)
1050
 */
1083
 */
1051
public void setLineJoin(int join) {
1084
public void setLineJoin(int join) {
1052
	currentState.graphicHints &= ~JOIN_MASK;
1085
    currentState.graphicHints &= ~JOIN_MASK;
1053
	currentState.graphicHints |= join << JOIN_SHIFT;
1086
    currentState.graphicHints |= join << JOIN_SHIFT;
1054
}
1087
}
1055
1088
1056
/**
1089
/**
1057
 * @see Graphics#setLineStyle(int)
1090
 * @see Graphics#setLineStyle(int)
1058
 */
1091
 */
1059
public void setLineStyle(int style) {
1092
public void setLineStyle(int style) {
1060
	currentState.graphicHints &= ~LINE_STYLE_MASK;
1093
    currentState.graphicHints &= ~LINE_STYLE_MASK;
1061
	currentState.graphicHints |= style;
1094
    currentState.graphicHints |= style;
1062
}
1095
}
1063
1096
1064
/**
1097
/**
1065
 * @see Graphics#setLineWidth(int)
1098
 * @see Graphics#setLineWidth(int)
1066
 */
1099
 */
1067
public void setLineWidth(int width) {
1100
public void setLineWidth(int width) {
1068
	currentState.lineWidth = width;
1101
    currentState.lineWidth = width;
1069
}
1102
}
1070
1103
1071
/**
1104
/**
1105
 * This method requires advanced graphics support. A check should be made to
1106
 * ensure advanced graphics is supported in the user's environment before
1107
 * calling this method. See {@link GC#getAdvanced()}.
1108
 * 
1072
 * @see Graphics#setTextAntialias(int)
1109
 * @see Graphics#setTextAntialias(int)
1073
 */
1110
 */
1074
public void setTextAntialias(int value) {
1111
public void setTextAntialias(int value) {
1075
	currentState.graphicHints &= ~TEXT_AA_MASK;
1112
    currentState.graphicHints &= ~TEXT_AA_MASK;
1076
	currentState.graphicHints |= ADVANCED_GRAPHICS_MASK | (value + AA_WHOLE_NUMBER) << TEXT_AA_SHIFT;
1113
    currentState.graphicHints |= ADVANCED_GRAPHICS_MASK | (value + AA_WHOLE_NUMBER) << TEXT_AA_SHIFT;
1077
}
1114
}
1078
1115
1079
/**
1116
/**
1080
 * @see Graphics#setXORMode(boolean)
1117
 * @see Graphics#setXORMode(boolean)
1081
 */
1118
 */
1082
public void setXORMode(boolean xor) {
1119
public void setXORMode(boolean xor) {
1083
	currentState.graphicHints &= ~XOR_MASK;
1120
    currentState.graphicHints &= ~XOR_MASK;
1084
	if (xor)
1121
    if (xor)
1085
		currentState.graphicHints |= XOR_MASK;
1122
        currentState.graphicHints |= XOR_MASK;
1086
}
1123
}
1087
1124
1088
/**
1125
/**
1126
 * This method requires advanced graphics support. A check should be made to
1127
 * ensure advanced graphics is supported in the user's environment before
1128
 * calling this method. See {@link GC#getAdvanced()}.
1129
 * 
1089
 * @see Graphics#shear(float, float)
1130
 * @see Graphics#shear(float, float)
1090
 */
1131
 */
1091
public void shear(float horz, float vert) {
1132
public void shear(float horz, float vert) {
1092
	//Flush any clipping changes before shearing
1133
    //Flush any clipping changes before shearing
1093
	checkGC();
1134
    checkGC();
1094
	initTransform(true);
1135
    initTransform(true);
1095
	float matrix[] = new float[6];
1136
    float matrix[] = new float[6];
1096
	transform.getElements(matrix);
1137
    transform.getElements(matrix);
1097
	transform.setElements(
1138
    transform.setElements(
1098
			matrix[0] + matrix[2] * vert,
1139
            matrix[0] + matrix[2] * vert,
1099
			matrix[1] + matrix[3] * vert,
1140
            matrix[1] + matrix[3] * vert,
1100
			matrix[0] * horz + matrix[2],
1141
            matrix[0] * horz + matrix[2],
1101
			matrix[1] * horz + matrix[3],
1142
            matrix[1] * horz + matrix[3],
1102
			matrix[4],
1143
            matrix[4],
1103
			matrix[5]);
1144
            matrix[5]);
1104
	
1145
    
1105
	gc.setTransform(transform);
1146
    gc.setTransform(transform);
1106
	elementsNeedUpdate = true;
1147
    elementsNeedUpdate = true;
1107
	//Can no longer track clipping changes
1148
    //Can no longer track clipping changes
1108
	appliedState.relativeClip = currentState.relativeClip = null;
1149
    appliedState.relativeClip = currentState.relativeClip = null;
1109
}
1150
}
1110
1151
1111
/**
1152
/**
1153
 * This method may require advanced graphics support if using a transform,
1154
 * in this case, a check should be made to ensure advanced graphics is
1155
 * supported in the user's environment before calling this method. See
1156
 * {@link GC#getAdvanced()}.
1157
 * 
1112
 * @see Graphics#translate(int, int)
1158
 * @see Graphics#translate(int, int)
1113
 */
1159
 */
1114
public void translate(int dx, int dy) {
1160
public void translate(int dx, int dy) {
1115
	if (dx == 0 && dy == 0)
1161
1116
		return;
1162
    if (dx == 0 && dy == 0)
1117
	if (transform != null) {
1163
        return;
1118
		//Flush clipping, pattern, etc. before applying transform
1164
    if (transform != null) {
1119
		checkGC();
1165
        //Flush clipping, pattern, etc. before applying transform
1120
		transform.translate(dx, dy);
1166
        checkGC();
1121
		elementsNeedUpdate = true;
1167
        transform.translate(dx, dy);
1122
		gc.setTransform(transform);
1168
        elementsNeedUpdate = true;
1123
	} else {
1169
        gc.setTransform(transform);
1124
		translateX += dx;
1170
    } else {
1125
		translateY += dy;
1171
        translateX += dx;
1126
	}
1172
        translateY += dy;
1127
	checkSharedClipping();
1173
    }
1128
	if (currentState.relativeClip != null)
1174
    checkSharedClipping();
1129
		currentState.relativeClip.translate(-dx, -dy);
1175
    if (currentState.relativeClip != null)
1176
        currentState.relativeClip.translate(-dx, -dy);
1130
}
1177
}
1131
1178
1132
/**
1179
/**
1180
 * This method requires advanced graphics support. A check should be made to
1181
 * ensure advanced graphics is supported in the user's environment before
1182
 * calling this method. See {@link GC#getAdvanced()}.
1183
 * 
1133
 * @see Graphics#translate(float, float)
1184
 * @see Graphics#translate(float, float)
1134
 */
1185
 */
1135
public void translate(float dx, float dy) {
1186
public void translate(float dx, float dy) {
1136
	initTransform(true);
1187
    initTransform(true);
1137
	checkGC();
1188
    checkGC();
1138
	transform.translate(dx, dy);
1189
    transform.translate(dx, dy);
1139
	elementsNeedUpdate = true;
1190
    elementsNeedUpdate = true;
1140
	gc.setTransform(transform);
1191
    gc.setTransform(transform);
1141
	checkSharedClipping();
1192
    checkSharedClipping();
1142
	if (currentState.relativeClip != null)
1193
    if (currentState.relativeClip != null)
1143
		currentState.relativeClip.translate(-dx, -dy);
1194
        currentState.relativeClip.translate(-dx, -dy);
1144
}
1195
}
1145
1196
1146
private void translatePointArray(int[] points, int translateX, int translateY) {
1197
private void translatePointArray(int[] points, int translateX, int translateY) {
1147
	if (translateX == 0 && translateY == 0)
1198
    if (translateX == 0 && translateY == 0)
1148
		return;
1199
        return;
1149
	for (int i = 0; (i + 1) < points.length; i += 2) {
1200
    for (int i = 0; (i + 1) < points.length; i += 2) {
1150
		points[i] += translateX;
1201
        points[i] += translateX;
1151
		points[i + 1] += translateY;
1202
        points[i + 1] += translateY;
1152
	}
1203
    }
1153
}
1204
}
1154
1205
1155
}
1206
}

Return to bug 173693