Skip to content

Commit 6339ccd

Browse files
hageldavehttpdigest
authored andcommitted
Let AWTGLCanvas.getGraphics() return Graphics which ignores clearRect()
to prevent clearing through the Canvas' Graphics object
1 parent 9ed0978 commit 6339ccd

File tree

5 files changed

+732
-1
lines changed

5 files changed

+732
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.lwjglx</groupId>
55
<artifactId>lwjgl3-awt</artifactId>
6-
<version>0.1.4</version>
6+
<version>0.1.5-SNAPSHOT</version>
77
<name>LWJGLX/lwjgl3-awt</name>
88
<description>LWJGLX/lwjgl3-awt</description>
99
<inceptionYear>2016</inceptionYear>
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
package org.lwjgl.awthacks;
2+
3+
import java.awt.Color;
4+
import java.awt.Font;
5+
import java.awt.FontMetrics;
6+
import java.awt.Graphics;
7+
import java.awt.Image;
8+
import java.awt.Polygon;
9+
import java.awt.Rectangle;
10+
import java.awt.Shape;
11+
import java.awt.image.ImageObserver;
12+
import java.text.AttributedCharacterIterator;
13+
14+
/**
15+
* Wrapper for a {@link Graphics} object that delegates to it.
16+
* Only {@link NonClearGraphics#clearRect(int, int, int, int)} does
17+
* not delegate in order to prevent clearing the Canvas after
18+
* it was rendered.
19+
*
20+
* @author hageldave
21+
* @see NonClearGraphics2D
22+
*/
23+
public class NonClearGraphics extends Graphics {
24+
25+
protected Graphics delegate;
26+
27+
public NonClearGraphics(Graphics delegate) {
28+
this.delegate = delegate;
29+
}
30+
31+
/**
32+
* Does nothing. This is to prevent a clearRect call from
33+
* clearing the already rendered Canvas.
34+
*/
35+
public void clearRect(int x, int y, int width, int height) {
36+
// NOOP
37+
}
38+
39+
@Deprecated
40+
public Rectangle getClipRect() {
41+
return delegate.getClipRect();
42+
}
43+
44+
public NonClearGraphics create() {
45+
return new NonClearGraphics(delegate.create());
46+
}
47+
48+
public NonClearGraphics create(int x, int y, int width, int height) {
49+
return new NonClearGraphics(delegate.create(x, y, width, height));
50+
}
51+
52+
public void translate(int x, int y) {
53+
delegate.translate(x, y);
54+
}
55+
56+
public Color getColor() {
57+
return delegate.getColor();
58+
}
59+
60+
public void setColor(Color c) {
61+
delegate.setColor(c);
62+
}
63+
64+
public void setPaintMode() {
65+
delegate.setPaintMode();
66+
}
67+
68+
public void setXORMode(Color c1) {
69+
delegate.setXORMode(c1);
70+
}
71+
72+
public Font getFont() {
73+
return delegate.getFont();
74+
}
75+
76+
public void setFont(Font font) {
77+
delegate.setFont(font);
78+
}
79+
80+
public FontMetrics getFontMetrics() {
81+
return delegate.getFontMetrics();
82+
}
83+
84+
public FontMetrics getFontMetrics(Font f) {
85+
return delegate.getFontMetrics(f);
86+
}
87+
88+
public Rectangle getClipBounds() {
89+
return delegate.getClipBounds();
90+
}
91+
92+
public void clipRect(int x, int y, int width, int height) {
93+
delegate.clipRect(x, y, width, height);
94+
}
95+
96+
public void setClip(int x, int y, int width, int height) {
97+
delegate.setClip(x, y, width, height);
98+
}
99+
100+
public Shape getClip() {
101+
return delegate.getClip();
102+
}
103+
104+
public void setClip(Shape clip) {
105+
delegate.setClip(clip);
106+
}
107+
108+
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
109+
delegate.copyArea(x, y, width, height, dx, dy);
110+
}
111+
112+
public void drawLine(int x1, int y1, int x2, int y2) {
113+
delegate.drawLine(x1, y1, x2, y2);
114+
}
115+
116+
public void fillRect(int x, int y, int width, int height) {
117+
delegate.fillRect(x, y, width, height);
118+
}
119+
120+
public void drawRect(int x, int y, int width, int height) {
121+
delegate.drawRect(x, y, width, height);
122+
}
123+
124+
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
125+
delegate.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
126+
}
127+
128+
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
129+
delegate.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
130+
}
131+
132+
public void draw3DRect(int x, int y, int width, int height, boolean raised) {
133+
delegate.draw3DRect(x, y, width, height, raised);
134+
}
135+
136+
public void fill3DRect(int x, int y, int width, int height, boolean raised) {
137+
delegate.fill3DRect(x, y, width, height, raised);
138+
}
139+
140+
public void drawOval(int x, int y, int width, int height) {
141+
delegate.drawOval(x, y, width, height);
142+
}
143+
144+
public void fillOval(int x, int y, int width, int height) {
145+
delegate.fillOval(x, y, width, height);
146+
}
147+
148+
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
149+
delegate.drawArc(x, y, width, height, startAngle, arcAngle);
150+
}
151+
152+
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
153+
delegate.fillArc(x, y, width, height, startAngle, arcAngle);
154+
}
155+
156+
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
157+
delegate.drawPolyline(xPoints, yPoints, nPoints);
158+
}
159+
160+
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
161+
delegate.drawPolygon(xPoints, yPoints, nPoints);
162+
}
163+
164+
public void drawPolygon(Polygon p) {
165+
delegate.drawPolygon(p);
166+
}
167+
168+
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
169+
delegate.fillPolygon(xPoints, yPoints, nPoints);
170+
}
171+
172+
public void fillPolygon(Polygon p) {
173+
delegate.fillPolygon(p);
174+
}
175+
176+
public void drawString(String str, int x, int y) {
177+
delegate.drawString(str, x, y);
178+
}
179+
180+
public void drawString(AttributedCharacterIterator iterator, int x, int y) {
181+
delegate.drawString(iterator, x, y);
182+
}
183+
184+
public void drawChars(char[] data, int offset, int length, int x, int y) {
185+
delegate.drawChars(data, offset, length, x, y);
186+
}
187+
188+
public void drawBytes(byte[] data, int offset, int length, int x, int y) {
189+
delegate.drawBytes(data, offset, length, x, y);
190+
}
191+
192+
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
193+
return delegate.drawImage(img, x, y, observer);
194+
}
195+
196+
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
197+
return delegate.drawImage(img, x, y, width, height, observer);
198+
}
199+
200+
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
201+
return delegate.drawImage(img, x, y, bgcolor, observer);
202+
}
203+
204+
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
205+
return delegate.drawImage(img, x, y, width, height, bgcolor, observer);
206+
}
207+
208+
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
209+
ImageObserver observer) {
210+
return delegate.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
211+
}
212+
213+
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
214+
Color bgcolor, ImageObserver observer) {
215+
return delegate.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
216+
}
217+
218+
public void dispose() {
219+
delegate.dispose();
220+
}
221+
222+
public void finalize() {
223+
delegate.finalize();
224+
}
225+
226+
public String toString() {
227+
return delegate.toString();
228+
}
229+
230+
public boolean hitClip(int x, int y, int width, int height) {
231+
return delegate.hitClip(x, y, width, height);
232+
}
233+
234+
public Rectangle getClipBounds(Rectangle r) {
235+
return delegate.getClipBounds(r);
236+
}
237+
238+
}

0 commit comments

Comments
 (0)