Skip to content

Commit 080a1c7

Browse files
arunjose696fedejeanne
authored andcommitted
Use constructor Image(Device, ImageDataProvider) for Radial gradients
This PR does not cause a visual impact but is meant for completeness to Replace Image(Device, ImageData) with Imagde(Device, ImageDataProvider) making sure the earlier behaviour is preserved
1 parent 875996f commit 080a1c7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/GradientBackgroundListener.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.eclipse.swt.graphics.GC;
3838
import org.eclipse.swt.graphics.Image;
3939
import org.eclipse.swt.graphics.ImageData;
40+
import org.eclipse.swt.graphics.ImageDataProvider;
4041
import org.eclipse.swt.graphics.ImageGcDrawer;
4142
import org.eclipse.swt.graphics.PaletteData;
4243
import org.eclipse.swt.graphics.Point;
@@ -133,13 +134,17 @@ public void handleEvent(Event event) {
133134
}
134135
}
135136

136-
BufferedImage image = getBufferedImage(size.x, size.y, colors,
137-
CSSSWTColorHelper.getPercents(grad));
138-
// long startTime = System.currentTimeMillis();
139-
ImageData imagedata = convertToSWT(image);
140-
// System.out.println("Conversion took "
141-
// + (System.currentTimeMillis() - startTime) + " ms");
142-
gradientImage = new Image(control.getDisplay(), imagedata);
137+
ImageDataProvider imageDataProvider = zoom -> {
138+
float scaleFactor = zoom / 100f;
139+
int scaledWidth = Math.round(size.x * scaleFactor);
140+
int scaledHeight = Math.round(size.y * scaleFactor);
141+
BufferedImage image = getBufferedImage(scaledWidth, scaledHeight, colors,
142+
CSSSWTColorHelper.getPercents(grad));
143+
ImageData imagedata = convertToSWT(image);
144+
return imagedata;
145+
};
146+
147+
gradientImage = new Image(control.getDisplay(), imageDataProvider);
143148
radialGradient = true;
144149
} else if (oldImage == null || oldImage.isDisposed()
145150
|| oldImage.getBounds().height != size.y || radialGradient

0 commit comments

Comments
 (0)