Skip to content

Commit 0ea84cd

Browse files
committed
Use constructor Image(Device, ImageDataProvider) in DefaultRangeIndicator
DefaultRangeIndicator previously used Image(Device, ImageData) constructor to draw a grid to display the selected range. Previously, the grid was rendered using a 1×1 pixel checkerboard pattern (blue and white), which was mainly inteded to work at 100% zoom. However, at higher zoom levels (e.g., 150%, 200%), the visual intensity of the pattern becomes different, causing the grid to appear visually inconsistent across zooms.
1 parent 5dc925c commit 0ea84cd

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

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

Lines changed: 22 additions & 13 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;
@@ -135,20 +136,28 @@ private Image getImage(Control control, Color rangeIndicatorColor) {
135136
*/
136137
private static Image createImage(Display display, Point size, Color rangeIndicatorColor) {
137138

138-
int width= size.x;
139-
int height= size.y;
140-
141-
142-
ImageData imageData= new ImageData(width, height, 1, createPalette(display, rangeIndicatorColor));
143-
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);
147-
148-
imageData.transparentPixel= 1;
149-
139+
int width = size.x;
140+
int height = size.y;
141+
142+
ImageDataProvider imageDataProvider = zoom -> {
143+
float scaleFactor = zoom / 100.0f;
144+
int scaledWidth = Math.round(width * scaleFactor);
145+
int scaledHeight = Math.round(height * scaleFactor);
146+
ImageData imageData = new ImageData(scaledWidth, scaledHeight, 1,
147+
createPalette(display, rangeIndicatorColor));
148+
int blockSize = Math.round(scaleFactor);
149+
for (int y = 0; y < scaledHeight; y++) {
150+
for (int x = 0; x < scaledWidth; x++) {
151+
if (((x / blockSize) + (y / blockSize)) % 2 == 0) {
152+
imageData.setPixel(x, y, 1);
153+
}
154+
}
155+
}
156+
imageData.transparentPixel = 1;
157+
return imageData;
158+
};
150159

151-
return new Image(display, imageData);
160+
return new Image(display, imageDataProvider);
152161
}
153162

154163
/**

0 commit comments

Comments
 (0)