Skip to content

Commit 81acf47

Browse files
arunjose696HeikoKlare
authored andcommitted
Replace Image(Device, ImageData) with Imagde(Device, ImageDataProvider)
Refactoring to use conmstructor which scales ImageData according to monitor zoom
1 parent 93acda3 commit 81acf47

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

  • bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets

bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormUtil.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.swt.graphics.GC;
2626
import org.eclipse.swt.graphics.Image;
2727
import org.eclipse.swt.graphics.ImageData;
28+
import org.eclipse.swt.graphics.ImageDataProvider;
2829
import org.eclipse.swt.graphics.Point;
2930
import org.eclipse.swt.graphics.Rectangle;
3031
import org.eclipse.swt.layout.GridData;
@@ -485,25 +486,29 @@ public static Form getForm(Control c) {
485486
}
486487

487488
public static Image createAlphaMashImage(Device device, Image srcImage) {
488-
Rectangle bounds = srcImage.getBounds();
489-
int alpha = 0;
490-
int calpha = 0;
491-
ImageData data = srcImage.getImageData();
492-
// Create a new image with alpha values alternating
493-
// between fully transparent (0) and fully opaque (255).
494-
// This image will show the background through the
495-
// transparent pixels.
496-
for (int i = 0; i < bounds.height; i++) {
497-
// scan line
498-
alpha = calpha;
499-
for (int j = 0; j < bounds.width; j++) {
500-
// column
501-
data.setAlpha(j, i, alpha);
502-
alpha = alpha == 255 ? 0 : 255;
489+
490+
ImageDataProvider imageDataProvider = zoom -> {
491+
int alpha = 0;
492+
int calpha = 0;
493+
ImageData data = srcImage.getImageData(zoom);
494+
// Create a new image with alpha values alternating
495+
// between fully transparent (0) and fully opaque (255).
496+
// This image will show the background through the
497+
// transparent pixels.
498+
for (int i = 0; i < data.height; i++) {
499+
// scan line
500+
alpha = calpha;
501+
for (int j = 0; j < data.width; j++) {
502+
// column
503+
data.setAlpha(j, i, alpha);
504+
alpha = alpha == 255 ? 0 : 255;
505+
}
506+
calpha = calpha == 255 ? 0 : 255;
503507
}
504-
calpha = calpha == 255 ? 0 : 255;
505-
}
506-
return new Image(device, data);
508+
509+
return data;
510+
};
511+
return new Image(device, imageDataProvider);
507512
}
508513

509514
public static boolean mnemonicMatch(String text, char key) {

0 commit comments

Comments
 (0)