Skip to content

Commit 2cfd95c

Browse files
wahlbrinkHeikoKlare
authored andcommitted
Fix caret of raw insert mode of text editor on HiDPI screens
Fixes: #3010
1 parent 62f3974 commit 2cfd95c

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.eclipse.swt.graphics.GC;
6868
import org.eclipse.swt.graphics.Image;
6969
import org.eclipse.swt.graphics.ImageData;
70+
import org.eclipse.swt.graphics.ImageDataProvider;
7071
import org.eclipse.swt.graphics.PaletteData;
7172
import org.eclipse.swt.graphics.Point;
7273
import org.eclipse.swt.graphics.RGB;
@@ -6961,32 +6962,27 @@ private Caret createInsertCaret(StyledText styledText) {
69616962
}
69626963

69636964
private Image createRawInsertModeCaretImage(StyledText styledText) {
6964-
69656965
PaletteData caretPalette = new PaletteData(new RGB(0, 0, 0), new RGB(255, 255, 255));
69666966
int width = getCaretWidthPreference();
6967-
int widthOffset = width - 1;
6968-
69696967
// XXX: Filed request to get a caret with auto-height:
69706968
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
6971-
ImageData imageData = new ImageData(4 + widthOffset, styledText.getLineHeight(), 1, caretPalette);
6972-
6973-
Display display = styledText.getDisplay();
6974-
Image bracketImage = new Image(display, imageData);
6975-
GC gc = new GC(bracketImage);
6976-
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
6977-
gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance
6978-
int height = imageData.height / 3;
6979-
// gap between two bars of one third of the height
6980-
// draw boxes using lines as drawing a line of a certain width produces
6981-
// rounded corners.
6982-
for (int i = 0; i < width; i++) {
6983-
gc.drawLine(i, 0, i, height - 1);
6984-
gc.drawLine(i, imageData.height - height, i, imageData.height - 1);
6985-
}
6986-
6987-
gc.dispose();
6988-
6989-
return bracketImage;
6969+
int height = styledText.getLineHeight();
6970+
ImageDataProvider imageDataProvider = zoom -> {
6971+
double scaleFactor = zoom / 100.0;
6972+
int w = (int) (width * scaleFactor + 0.5);
6973+
int h = (int) (height * scaleFactor + 0.5);
6974+
ImageData imageData = new ImageData(w, h, 1, caretPalette);
6975+
// gap between two bars of one third of the height
6976+
int h3 = h / 3;
6977+
for (int x = 0; x < w; x++) {
6978+
for (int y = 0; y < h3; y++) {
6979+
imageData.setPixel(x, y, 1);
6980+
imageData.setPixel(x, h - y - 1, 1);
6981+
}
6982+
}
6983+
return imageData;
6984+
};
6985+
return new Image(styledText.getDisplay(), imageDataProvider);
69906986
}
69916987

69926988
private Caret createRawInsertModeCaret(StyledText styledText) {

0 commit comments

Comments
 (0)