|
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; |
@@ -6722,31 +6723,28 @@ private Caret createInsertCaret(StyledText styledText) { |
6722 | 6723 | } |
6723 | 6724 |
|
6724 | 6725 | private Image createRawInsertModeCaretImage(StyledText styledText) { |
6725 | | - |
6726 | 6726 | PaletteData caretPalette= new PaletteData(new RGB (0,0,0), new RGB (255,255,255)); |
6727 | 6727 | int width= getCaretWidthPreference(); |
6728 | | - int widthOffset= width - 1; |
6729 | | - |
6730 | 6728 | // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612 |
6731 | | - ImageData imageData= new ImageData(4 + widthOffset, styledText.getLineHeight(), 1, caretPalette); |
6732 | | - |
6733 | | - Display display= styledText.getDisplay(); |
6734 | | - Image bracketImage= new Image(display, imageData); |
6735 | | - GC gc= new GC (bracketImage); |
6736 | | - gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); |
6737 | | - gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance |
6738 | | - int height= imageData.height / 3; |
6739 | | - // gap between two bars of one third of the height |
6740 | | - // draw boxes using lines as drawing a line of a certain width produces |
6741 | | - // rounded corners. |
6742 | | - for (int i= 0; i < width ; i++) { |
6743 | | - gc.drawLine(i, 0, i, height - 1); |
6744 | | - gc.drawLine(i, imageData.height - height, i, imageData.height - 1); |
6745 | | - } |
6746 | | - |
6747 | | - gc.dispose(); |
6748 | | - |
6749 | | - return bracketImage; |
| 6729 | + int height= styledText.getLineHeight(); |
| 6730 | + return new Image(styledText.getDisplay(), new ImageDataProvider() { |
| 6731 | + @Override |
| 6732 | + public ImageData getImageData(int zoom) { |
| 6733 | + double scaleFactor = zoom / 100.0; |
| 6734 | + int w= (int)(width * scaleFactor + 0.5); |
| 6735 | + int h= (int)(height * scaleFactor + 0.5); |
| 6736 | + ImageData imageData= new ImageData(w, h, 1, caretPalette); |
| 6737 | + // gap between two bars of one third of the height |
| 6738 | + int h3= h / 3; |
| 6739 | + for (int x= 0; x < w; x++) { |
| 6740 | + for (int y= 0; y < h3; y++) { |
| 6741 | + imageData.setPixel(x, y, 1); |
| 6742 | + imageData.setPixel(x, h - y - 1, 1); |
| 6743 | + } |
| 6744 | + } |
| 6745 | + return imageData; |
| 6746 | + } |
| 6747 | + }); |
6750 | 6748 | } |
6751 | 6749 |
|
6752 | 6750 | private Caret createRawInsertModeCaret(StyledText styledText) { |
|
0 commit comments