1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2005, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
|
12
|
package org.eclipse.draw2d;
|
13
|
|
14
|
|
15
|
import org.eclipse.draw2d.geometry.Rectangle;
|
16
|
import org.eclipse.swt.widgets.Control;
|
17
|
|
18
|
/**
|
19
|
* A graphics source that posts a paint request to the control rather than
|
20
|
* constructing GC on it directly. This allows the OS's native painting
|
21
|
* mechanism to be used directly, including any double-buffering that the OS may
|
22
|
* provide for free.
|
23
|
*
|
24
|
* @since 3.2
|
25
|
*/
|
26
|
public final class NativeGraphicsSource implements GraphicsSource {
|
27
|
|
28
|
private final Control canvas;
|
29
|
|
30
|
/**
|
31
|
* Constructs a new graphics source on the given control.
|
32
|
*
|
33
|
* @param canvas
|
34
|
* the control
|
35
|
* @since 3.2
|
36
|
*/
|
37
|
public NativeGraphicsSource(Control canvas) {
|
38
|
this.canvas = canvas;
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* Always returns <code>null</code>, because
|
43
|
*
|
44
|
* @see GraphicsSource#getGraphics(Rectangle)
|
45
|
*/
|
46
|
public Graphics getGraphics(Rectangle r) {
|
47
|
canvas.redraw(r.x, r.y, r.width, r.height, false);
|
48
|
canvas.update();
|
49
|
return null;
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Does nothing.
|
54
|
*
|
55
|
* @see GraphicsSource#flushGraphics(Rectangle)
|
56
|
*/
|
57
|
public void flushGraphics(Rectangle region) {
|
58
|
}
|
59
|
|
60
|
}
|