Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageDataProvider;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
Expand Down Expand Up @@ -6537,31 +6538,28 @@ private Caret createInsertCaret(StyledText styledText) {
}

private Image createRawInsertModeCaretImage(StyledText styledText) {

// XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
PaletteData caretPalette= new PaletteData(new RGB[] {new RGB (0,0,0), new RGB (255,255,255)});
int width= getCaretWidthPreference();
int widthOffset= width - 1;

// XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
ImageData imageData= new ImageData(4 + widthOffset, styledText.getLineHeight(), 1, caretPalette);

Display display= styledText.getDisplay();
Image bracketImage= new Image(display, imageData);
GC gc= new GC (bracketImage);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance
int height= imageData.height / 3;
// gap between two bars of one third of the height
// draw boxes using lines as drawing a line of a certain width produces
// rounded corners.
for (int i= 0; i < width ; i++) {
gc.drawLine(i, 0, i, height - 1);
gc.drawLine(i, imageData.height - height, i, imageData.height - 1);
}

gc.dispose();

return bracketImage;
int height= styledText.getLineHeight();
return new Image(styledText.getDisplay(), new ImageDataProvider() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to use an ImageDataProvider rather than an ImageGcDrawer?
This requires to manually implement proper line width calculation and line rendering instead of just using gc.drawLine() like in the original code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a 1-bit image as before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with "1-bit image"? Do you mean that the line is 1 pixel wide? That's the intended behavior of setLineWidth(0). Changing that to setLineWidth(1) should resolve it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1-bit image = image with 1-bit color palette = a pixels uses 1-bit = colloquially called black-and-white image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. But is it really necessary/beneficial to keep it like that?

@Override
public ImageData getImageData(int zoom) {
double scaleFactor = zoom / 100.0;
int w= (int)(width * scaleFactor + 0.5);
int h= (int)(height * scaleFactor + 0.5);
ImageData imageData= new ImageData(w, h, 1, caretPalette);
// gap between two bars of one third of the height
int h3= h / 3;
for (int x= 0; x < w; x++) {
for (int y= 0; y < h3; y++) {
imageData.setPixel(x, y, 1);
imageData.setPixel(x, h - y - 1, 1);
}
}
return imageData;
}
});
}

private Caret createRawInsertModeCaret(StyledText styledText) {
Expand Down
Loading