Skip to content
Draft
Show file tree
Hide file tree
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 @@ -45,6 +45,7 @@ public GridCanvas(Composite parent, int style) {
*/
@Override
protected void paint(GC gc) {
gc.setAdvanced(true);
Rectangle clipping = gc.getClipping();
if (clipping.width == 0 || clipping.height == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private enum SelectionMode {
* (SWT.H_SCROLL and SWT.V_SCROLL are automatically added).
*/
public TextCanvas(Composite parent, ITextCanvasModel model, int style, ILinelRenderer cellRenderer) {
super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL);
super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED);
fCellRenderer = cellRenderer;
setCellWidth(fCellRenderer.getCellWidth());
setCellHeight(fCellRenderer.getCellHeight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.terminal.connector.Logger;
Expand Down Expand Up @@ -61,21 +60,19 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
if (width <= 0 || height <= 0) {
return;
}
Image buffer = new Image(gc.getDevice(), width, height);
GC doubleBufferGC = new GC(buffer);
if (line < 0 || line >= getTerminalText().getHeight() || colFirst >= getTerminalText().getWidth()
|| colFirst - colLast == 0) {
fillBackground(doubleBufferGC, 0, 0, width, height);
fillBackground(gc, x, y, width, height);
} else {
colLast = Math.min(colLast, getTerminalText().getWidth());
LineSegment[] segments = getTerminalText().getLineSegments(line, colFirst, colLast - colFirst);
for (int i = 0; i < segments.length; i++) {
LineSegment segment = segments[i];
TerminalStyle style = segment.getStyle();
setupGC(doubleBufferGC, style);
setupGC(gc, style);
String text = segment.getText();
drawText(doubleBufferGC, 0, 0, colFirst, segment.getColumn(), text);
drawCursor(model, doubleBufferGC, line, 0, 0, colFirst);
drawText(gc, x, y, colFirst, segment.getColumn(), text);
drawCursor(model, gc, line, x, y, colFirst);
}
if (fModel.hasHoverSelection(line)) {
if (DEBUG_HOVER) {
Expand All @@ -87,14 +84,14 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
int colEnd = line == hsEnd.y ? hsEnd.x : getTerminalText().getWidth();
if (colStart < colEnd) {
RGB defaultFg = fStyleMap.getForegrondRGB(null);
doubleBufferGC.setForeground(new Color(doubleBufferGC.getDevice(), defaultFg));
drawUnderline(doubleBufferGC, colStart, colEnd);
gc.setForeground(new Color(gc.getDevice(), defaultFg));
drawUnderline(gc, x, y, colStart, colEnd);
}
}
if (fModel.hasLineSelection(line)) {
TerminalStyle style = TerminalStyle.getStyle(TerminalColor.SELECTION_FOREGROUND,
TerminalColor.SELECTION_BACKGROUND);
setupGC(doubleBufferGC, style);
setupGC(gc, style);
Point start = model.getSelectionStart();
Point end = model.getSelectionEnd();
char[] chars = model.getTerminalText().getChars(line);
Expand All @@ -113,14 +110,11 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
len = Math.min(len, chars.length - offset);
if (len > 0) {
String text = new String(chars, offset, len);
drawText(doubleBufferGC, 0, 0, colFirst, offset, text);
drawText(gc, x, y, colFirst, offset, text);
}
}
}
}
gc.drawImage(buffer, x, y);
doubleBufferGC.dispose();
buffer.dispose();
}

private void fillBackground(GC gc, int x, int y, int width, int height) {
Expand Down Expand Up @@ -186,9 +180,9 @@ private void drawText(GC gc, int x, int y, int colFirst, int col, String text) {
* @param colStart Starting text column to underline (inclusive)
* @param colEnd Ending text column to underline (inclusive)
*/
private void drawUnderline(GC gc, int colStart, int colEnd) {
int y = getCellHeight() - 1;
int x = getCellWidth() * colStart;
private void drawUnderline(GC gc, int xOffset, int yOffset, int colStart, int colEnd) {
int y = yOffset + getCellHeight() - 1;
int x = xOffset + getCellWidth() * colStart;

// x2 is the right side of last column being underlined.
int x2 = (colEnd + 1) * getCellWidth() - 1;
Expand Down
Loading