Skip to content

Commit 4723e32

Browse files
committed
Replacing Image(Device, ImageData) constructor in DefaultRangeIndicator with Image(Device, ImageDataProvider)
1 parent a9ec6c9 commit 4723e32

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultRangeIndicator.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.swt.graphics.GC;
2121
import org.eclipse.swt.graphics.Image;
2222
import org.eclipse.swt.graphics.ImageData;
23+
import org.eclipse.swt.graphics.ImageDataProvider;
2324
import org.eclipse.swt.graphics.PaletteData;
2425
import org.eclipse.swt.graphics.Point;
2526
import org.eclipse.swt.graphics.RGB;
@@ -139,16 +140,31 @@ private static Image createImage(Display display, Point size, Color rangeIndicat
139140
int height= size.y;
140141

141142

142-
ImageData imageData= new ImageData(width, height, 1, createPalette(display, rangeIndicatorColor));
143+
ImageDataProvider imageDataProvider = zoom -> {
144+
145+
float scaleFactor = (float) ((zoom) / 100.0);
146+
int scaled_width = Math.round(width * scaleFactor);
147+
int scaled_height = Math.round(height * scaleFactor);
148+
ImageData imageData = new ImageData(scaled_width, scaled_height,
149+
1,
150+
createPalette(display, rangeIndicatorColor));
151+
int blockSize = Math.round(scaleFactor);
152+
for (int y = 0; y < scaled_height; y++)
153+
for (int x = 0; x < scaled_width; x++) {
154+
if (((x / blockSize) + (y / blockSize)) % 2 == 0) {
155+
imageData.setPixel(x, y, 1);
156+
}
157+
158+
}
159+
imageData.transparentPixel = 1;
160+
return imageData;
161+
162+
};
143163

144-
for (int y= 0, offset= 1; y < height; y++, offset= (offset + 1) % 2)
145-
for (int x= offset; x < width; x += 2)
146-
imageData.setPixel(x, y, 1);
147164

148-
imageData.transparentPixel= 1;
149165

150166

151-
return new Image(display, imageData);
167+
return new Image(display, imageDataProvider);
152168
}
153169

154170
/**

0 commit comments

Comments
 (0)