Skip to content

Commit 693032c

Browse files
arunjose696akoch-yatta
authored andcommitted
Adapt Snippets to use new GC#drawImage API wherever a full image is drawn
This change replaces the old drawImage API call in Snippets with the newer, simplified drawImage overload that takes fewer parameters
1 parent 229e093 commit 693032c

File tree

6 files changed

+9
-42
lines changed

6 files changed

+9
-42
lines changed

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet10.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void main(String[] args) {
4343
Transform tr = new Transform(display);
4444
tr.translate(50, 120);
4545
tr.rotate(-30);
46-
gc1.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
46+
gc1.drawImage(image, 0, 0, rect.width / 2, rect.height / 2);
4747
gc1.setAlpha(100);
4848
gc1.setTransform(tr);
4949
Path path = new Path(display);

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet141.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ public void run() {
7272
image = new Image(display, imageData);
7373
offScreenImageGC.drawImage(
7474
image,
75-
0,
76-
0,
77-
imageData.width,
78-
imageData.height,
7975
imageData.x,
8076
imageData.y,
8177
imageData.width,
@@ -97,33 +93,17 @@ public void run() {
9793
break;
9894
case SWT.DM_FILL_PREVIOUS:
9995
/* Restore the previous image before drawing. */
100-
offScreenImageGC.drawImage(
101-
image,
102-
0,
103-
0,
104-
imageData.width,
105-
imageData.height,
106-
imageData.x,
107-
imageData.y,
108-
imageData.width,
109-
imageData.height);
96+
offScreenImageGC.drawImage(image, imageData.x, imageData.y, imageData.width,
97+
imageData.height);
11098
break;
11199
}
112100

113101
imageDataIndex = (imageDataIndex + 1) % imageDataArray.length;
114102
imageData = imageDataArray[imageDataIndex];
115103
image.dispose();
116104
image = new Image(display, imageData);
117-
offScreenImageGC.drawImage(
118-
image,
119-
0,
120-
0,
121-
imageData.width,
122-
imageData.height,
123-
imageData.x,
124-
imageData.y,
125-
imageData.width,
126-
imageData.height);
105+
offScreenImageGC.drawImage(image, imageData.x, imageData.y, imageData.width,
106+
imageData.height);
127107

128108
/* Draw the off-screen image to the shell. */
129109
shellGC.drawImage(offScreenImage, 0, 0);

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet180.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ public static void main(String[] args) {
4747
//define the shape of the shell using setRegion
4848
shell.setRegion(region);
4949
shell.addPaintListener(e -> {
50-
Rectangle bounds = image.getBounds();
5150
Point size = shell.getSize();
52-
e.gc.drawImage(image, 0, 0, bounds.width, bounds.height, 10, 10, size.x-20, size.y-20);
51+
e.gc.drawImage(image, 10, 10, size.x-20, size.y-20);
5352
});
5453
shell.addListener(SWT.KeyDown, e -> {
5554
if (e.character == SWT.ESC) {

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,11 @@ private static void loadAllImages(String directory, String[] filenames) throws S
124124
0,
125125
0,
126126
fullWidth,
127-
fullHeight,
128-
0,
129-
0,
130-
fullWidth,
131127
fullHeight);
132128
break;
133129
}
134130
Image newFrame = new Image(display, imageData);
135131
gc.drawImage(newFrame,
136-
0,
137-
0,
138-
imageData.width,
139-
imageData.height,
140132
imageData.x,
141133
imageData.y,
142134
imageData.width,

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet355.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public static void main (String [] args) {
3333
int height = rect.height;
3434
GC gc = e.gc;
3535
int x = 10, y = 10;
36-
gc.drawImage (image, 0, 0, width, height, x, y, width, height);
37-
gc.drawImage (image, 0, 0, width, height, x+width, y, (int)Math.round(width * 0.5), (int)Math.round(height * 0.5));
38-
gc.drawImage (image, 0, 0, width, height, x+width+(int)Math.round(width * 0.5), y, width * 2, height * 2);
36+
gc.drawImage (image, x, y, width, height);
37+
gc.drawImage (image, x+width, y, (int)Math.round(width * 0.5), (int)Math.round(height * 0.5));
38+
gc.drawImage (image, x+width+(int)Math.round(width * 0.5), y, width * 2, height * 2);
3939
});
4040
shell.setSize (600, 400);
4141
shell.open ();

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ private static void performPrintAction(final Display display, final Shell shell)
171171
if (printer.startPage()) {
172172
printerGC.drawImage(
173173
printerImage,
174-
0,
175-
0,
176-
imageData.width,
177-
imageData.height,
178174
-trim.x,
179175
-trim.y,
180176
scaleFactor * imageData.width,

0 commit comments

Comments
 (0)