mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Do not cache the GC
This commit is contained in:
parent
8266f8929e
commit
494e3e0027
1 changed files with 12 additions and 20 deletions
|
@ -14,8 +14,6 @@ package org.eclipse.tm.internal.terminal.textcanvas;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.events.DisposeEvent;
|
|
||||||
import org.eclipse.swt.events.DisposeListener;
|
|
||||||
import org.eclipse.swt.graphics.Color;
|
import org.eclipse.swt.graphics.Color;
|
||||||
import org.eclipse.swt.graphics.GC;
|
import org.eclipse.swt.graphics.GC;
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.swt.graphics.Point;
|
||||||
|
@ -34,9 +32,8 @@ import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;
|
||||||
*/
|
*/
|
||||||
public abstract class VirtualCanvas extends Canvas {
|
public abstract class VirtualCanvas extends Canvas {
|
||||||
|
|
||||||
private Rectangle fVirtualBounds = new Rectangle(0,0,0,0);
|
private final Rectangle fVirtualBounds = new Rectangle(0,0,0,0);
|
||||||
private Rectangle fClientArea;
|
private Rectangle fClientArea;
|
||||||
private GC fPaintGC=null;
|
|
||||||
/**
|
/**
|
||||||
* prevent infinite loop in {@link #updateScrollbars()}
|
* prevent infinite loop in {@link #updateScrollbars()}
|
||||||
*/
|
*/
|
||||||
|
@ -45,7 +42,6 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
|
|
||||||
public VirtualCanvas(Composite parent, int style) {
|
public VirtualCanvas(Composite parent, int style) {
|
||||||
super(parent, style|SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE);
|
super(parent, style|SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE);
|
||||||
fPaintGC= new GC(this);
|
|
||||||
fClientArea=getClientArea();
|
fClientArea=getClientArea();
|
||||||
addListener(SWT.Paint, new Listener() {
|
addListener(SWT.Paint, new Listener() {
|
||||||
public void handleEvent(Event event) {
|
public void handleEvent(Event event) {
|
||||||
|
@ -71,16 +67,7 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addDisposeListener(new DisposeListener(){
|
}
|
||||||
public void widgetDisposed(DisposeEvent e) {
|
|
||||||
if(fPaintGC!=null){
|
|
||||||
fPaintGC.dispose();
|
|
||||||
fPaintGC=null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
protected void onResize() {
|
protected void onResize() {
|
||||||
updateViewRectangle();
|
updateViewRectangle();
|
||||||
}
|
}
|
||||||
|
@ -149,10 +136,15 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void repaint(Rectangle r) {
|
protected void repaint(Rectangle r) {
|
||||||
if (fPaintGC!=null) {
|
if(isDisposed())
|
||||||
if(inClipping(r,fClientArea)) {
|
return;
|
||||||
fPaintGC.setClipping(r);
|
if(inClipping(r,fClientArea)) {
|
||||||
paint(fPaintGC);
|
GC gc=new GC(this);
|
||||||
|
try {
|
||||||
|
gc.setClipping(r);
|
||||||
|
paint(gc);
|
||||||
|
} finally {
|
||||||
|
gc.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +253,7 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
return y-fVirtualBounds.y;
|
return y-fVirtualBounds.y;
|
||||||
}
|
}
|
||||||
/** called when the viewed part is changing */
|
/** called when the viewed part is changing */
|
||||||
private Rectangle fViewRectangle=new Rectangle(0,0,0,0);
|
private final Rectangle fViewRectangle=new Rectangle(0,0,0,0);
|
||||||
protected void updateViewRectangle() {
|
protected void updateViewRectangle() {
|
||||||
if(
|
if(
|
||||||
fViewRectangle.x==-fVirtualBounds.x
|
fViewRectangle.x==-fVirtualBounds.x
|
||||||
|
|
Loading…
Add table
Reference in a new issue