Skip to content

Commit 8e5b700

Browse files
committed
Make Text widget use SkijaGC if enabled
Currently, the Text widget based on CSimpleText uses the original (native) GC. With this change, it performs rendering based on a SkijaGC if enabled.
1 parent 76ccf9f commit 8e5b700

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/CSimpleText.java

+31-35
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ protected void widgetDisposed(Event e) {
367367
caret.dispose();
368368
}
369369

370+
@Override
370371
public Color getBackground() {
371372
return backgroundColor != null ? backgroundColor : BACKGROUND_COLOR;
372373
}
@@ -390,25 +391,27 @@ public void setForeground(Color color) {
390391

391392
private void paintControl(Event e) {
392393
Rectangle visibleArea = getVisibleArea();
393-
e.gc.setFont(getFont());
394-
e.gc.setForeground(getForeground());
395-
e.gc.setBackground(getBackground());
396-
if (!isEnabled()) {
397-
e.gc.setForeground(DISABLED_COLOR);
398-
}
399-
if (backgroundColor != null) {
400-
if (!isEnabled() || ((style & SWT.BORDER) == 1 && !getEditable())) {
401-
e.gc.setBackground(READONLY_BACKGROUND_COLOR);
394+
Drawing.drawWithGC(this, e.gc, gc -> {
395+
gc.setFont(getFont());
396+
gc.setForeground(getForeground());
397+
gc.setBackground(getBackground());
398+
if (!isEnabled()) {
399+
gc.setForeground(DISABLED_COLOR);
402400
}
403-
if ((style & SWT.BORDER) == 0 && !getEditable()) {
404-
e.gc.setBackground(getParent().getBackground());
401+
if (backgroundColor != null) {
402+
if (!isEnabled() || ((style & SWT.BORDER) == 1 && !getEditable())) {
403+
gc.setBackground(READONLY_BACKGROUND_COLOR);
404+
}
405+
if ((style & SWT.BORDER) == 0 && !getEditable()) {
406+
gc.setBackground(getParent().getBackground());
407+
}
405408
}
406-
}
407409

408-
drawBackground(e, getClientArea());
409-
drawText(e, visibleArea);
410-
drawSelection(e, visibleArea);
411-
drawCaret(e, visibleArea);
410+
drawBackground(gc, getClientArea());
411+
drawText(gc, visibleArea);
412+
drawSelection(gc, visibleArea);
413+
drawCaret(gc, visibleArea);
414+
});
412415
}
413416

414417
@Override
@@ -417,8 +420,7 @@ public void setEnabled(boolean enabled) {
417420
redraw();
418421
}
419422

420-
private void drawSelection(Event e, Rectangle visibleArea) {
421-
GC gc = e.gc;
423+
private void drawSelection(GC gc, Rectangle visibleArea) {
422424
int textLength = model.getText().length();
423425
int start = Math.min(Math.max(model.getSelectionStart(), 0), textLength);
424426
int end = Math.min(Math.max(model.getSelectionEnd(), 0), textLength);
@@ -450,53 +452,47 @@ private void drawSelection(Event e, Rectangle visibleArea) {
450452
}
451453
}
452454

453-
private void drawCaret(Event e, Rectangle visibleArea) {
454-
GC gc = e.gc;
455-
455+
private void drawCaret(GC gc, Rectangle visibleArea) {
456456
int caretOffset = model.getCaretOffset();
457-
458457
if (caretOffset >= 0) {
459-
Point caretLocation = getLocationByOffset(model.getCaretOffset(), e.gc);
460-
int x = e.x + caretLocation.x - visibleArea.x;
461-
int y = e.y + caretLocation.y - visibleArea.y;
458+
Point caretLocation = getLocationByOffset(model.getCaretOffset(), gc);
459+
int x = caretLocation.x - visibleArea.x;
460+
int y = caretLocation.y - visibleArea.y;
462461
getCaret().setBounds(x, y, 1, getLineHeight(gc));
463462
}
464463

465-
caret.paint(e);
464+
caret.paint(gc);
466465
}
467466

468-
private void drawText(Event e, Rectangle visibleArea) {
467+
private void drawText(GC gc, Rectangle visibleArea) {
469468
String[] lines = model.getLines();
470469
for (int i = 0; i < lines.length; i++) {
471470
String line = lines[i];
472-
drawTextLine(line, i, e.x, e.y, visibleArea, e.gc);
471+
drawTextLine(line, i, visibleArea, gc);
473472
}
474473
}
475474

476475

477-
private void drawTextLine(String text, int lineNumber, int x, int y, Rectangle visibleArea,
476+
private void drawTextLine(String text, int lineNumber, Rectangle visibleArea,
478477
GC gc) {
479478
Point completeTextExtent = gc.textExtent(text);
480479
Rectangle clientArea = getClientArea();
481-
int _x;
480+
int _x = 0;
482481
if ((style & SWT.CENTER) != 0) {
483482
_x = (clientArea.width - completeTextExtent.x) / 2;
484483
} else if ((style & SWT.RIGHT) != 0) {
485484
_x = clientArea.width - completeTextExtent.x;
486-
} else { // ((style & SWT.LEFT) != 0)
487-
_x = x;
488485
}
489486
_x -= visibleArea.x;
490-
int _y = y + lineNumber * completeTextExtent.y - visibleArea.y;
487+
int _y = lineNumber * completeTextExtent.y - visibleArea.y;
491488
if ((style & SWT.BORDER) != 0) {
492489
_x += getBorderWidth();
493490
_y += getBorderWidth();
494491
}
495492
gc.drawText(text, _x, _y, true);
496493
}
497494

498-
private void drawBackground(Event e, Rectangle clientArea) {
499-
GC gc = e.gc;
495+
private void drawBackground(GC gc, Rectangle clientArea) {
500496
int height = clientArea.height;
501497
final boolean drawLine = (style & SWT.BORDER) != 0 && getEditable() && isEnabled();
502498
if (drawLine) {

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/CTextCaret.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,8 @@ boolean showCaret() {
633633
return drawCaret();
634634
}
635635

636-
public void paint(Event e) {
636+
public void paint(GC gc) {
637637
if (isShowing) {
638-
GC gc = e.gc;
639638
Color oldBackground = gc.getBackground();
640639
gc.setBackground(parent.getForeground());
641640
gc.fillRectangle(getBounds());

0 commit comments

Comments
 (0)