|
67 | 67 | import org.eclipse.swt.graphics.GC; |
68 | 68 | import org.eclipse.swt.graphics.Image; |
69 | 69 | import org.eclipse.swt.graphics.ImageData; |
| 70 | +import org.eclipse.swt.graphics.ImageDataProvider; |
70 | 71 | import org.eclipse.swt.graphics.PaletteData; |
71 | 72 | import org.eclipse.swt.graphics.Point; |
72 | 73 | import org.eclipse.swt.graphics.RGB; |
@@ -6537,31 +6538,30 @@ private Caret createInsertCaret(StyledText styledText) { |
6537 | 6538 | } |
6538 | 6539 |
|
6539 | 6540 | private Image createRawInsertModeCaretImage(StyledText styledText) { |
6540 | | - |
| 6541 | + // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612 |
6541 | 6542 | PaletteData caretPalette= new PaletteData(new RGB[] {new RGB (0,0,0), new RGB (255,255,255)}); |
6542 | 6543 | int width= getCaretWidthPreference(); |
6543 | | - int widthOffset= width - 1; |
6544 | | - |
6545 | | - // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612 |
6546 | | - ImageData imageData= new ImageData(4 + widthOffset, styledText.getLineHeight(), 1, caretPalette); |
6547 | | - |
6548 | | - Display display= styledText.getDisplay(); |
6549 | | - Image bracketImage= new Image(display, imageData); |
6550 | | - GC gc= new GC (bracketImage); |
6551 | | - gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); |
6552 | | - gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance |
6553 | | - int height= imageData.height / 3; |
6554 | | - // gap between two bars of one third of the height |
6555 | | - // draw boxes using lines as drawing a line of a certain width produces |
6556 | | - // rounded corners. |
6557 | | - for (int i= 0; i < width ; i++) { |
6558 | | - gc.drawLine(i, 0, i, height - 1); |
6559 | | - gc.drawLine(i, imageData.height - height, i, imageData.height - 1); |
6560 | | - } |
6561 | | - |
6562 | | - gc.dispose(); |
6563 | | - |
6564 | | - return bracketImage; |
| 6544 | + int height= styledText.getLineHeight(); |
| 6545 | + return new Image(styledText.getDisplay(), new ImageDataProvider() { |
| 6546 | + @Override |
| 6547 | + public ImageData getImageData(int zoom) { |
| 6548 | + double scaleFactor = zoom / 100.0; |
| 6549 | + int w= (int)(width * scaleFactor + 0.5); |
| 6550 | + int h= (int)(height * scaleFactor + 0.5); |
| 6551 | + ImageData imageData= new ImageData(w, h, 1, caretPalette); |
| 6552 | + // gap between two bars of one third of the height |
| 6553 | + // draw boxes using lines as drawing a line of a certain width produces |
| 6554 | + // rounded corners. |
| 6555 | + int h3= h / 3; |
| 6556 | + for (int x= 0; x < w; x++) { |
| 6557 | + for (int y= 0; y < h3; y++) { |
| 6558 | + imageData.setPixel(x, y, 1); |
| 6559 | + imageData.setPixel(x, h - y - 1, 1); |
| 6560 | + } |
| 6561 | + } |
| 6562 | + return imageData; |
| 6563 | + } |
| 6564 | + }); |
6565 | 6565 | } |
6566 | 6566 |
|
6567 | 6567 | private Caret createRawInsertModeCaret(StyledText styledText) { |
|
0 commit comments