Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4729 buffering implementation in the SWT implementation of the canvas. #4789

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ static synchronized public java.awt.BasicStroke getStrokeFor(final int style) {
return _myLineStyles.get(new Integer(style));
}

private GC buffer;

private Image bufferImage;

/**
* remember the background color - SWT has trouble remembering it
*/
Expand All @@ -293,6 +297,10 @@ static synchronized public java.awt.BasicStroke getStrokeFor(final int style) {
*/
private GC _theDest = null;

private GC _destBuffered = null;

private boolean bufferEnabled = false;

/**
* the list of registered painters for this canvas.
*/
Expand Down Expand Up @@ -793,6 +801,7 @@ public void emptyShape(final Shape shape) {

@Override
public final void endDraw(final Object theVal) {
flushBuffer();
// _theDest = null;

// and forget the line width
Expand Down Expand Up @@ -889,6 +898,20 @@ public void fillShape(final Shape shape) {
}
}

public void flushBuffer() {
if (bufferEnabled) {
_theDest.dispose();
_theDest = _destBuffered;
this.drawImage(bufferImage, 0, 1, getSize().width, getSize().height);

buffer = null;

bufferImage.dispose();

bufferEnabled = false;
}
}

/**
* get the current background colour
*/
Expand Down Expand Up @@ -1076,6 +1099,24 @@ public final boolean hasEditor() {
return true;
}

public void initializeBuffer() {
final String operSys = System.getProperty("os.name").toLowerCase();
final boolean isMacOs = operSys.contains("mac");
if (_theDest != null && !bufferEnabled && !isMacOs) {
final Color foregroundColor = _theDest.getForeground();

bufferEnabled = true;
final ImageData imageData = new ImageData(getSize().width, getSize().height, 24, new PaletteData(0, 0, 0));
bufferImage = new Image(_theDest.getDevice(), imageData);
buffer = new GC(bufferImage);
_destBuffered = _theDest;
_theDest = buffer;
setBackgroundColor(_backgroundColor);

_theDest.setForeground(foregroundColor);
}
}

@Override
public final void removePainter(final CanvasType.PaintListener listener) {
_thePainters.removeElement(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewPart;
Expand Down Expand Up @@ -439,11 +438,6 @@ private void drawHere(final GC graphics, final WorldVector newVector) {
final SWTCanvasAdapter ca = new SWTCanvasAdapter(_myCanvas.getProjection()) {
private static final long serialVersionUID = 1L;

@Override
public void drawImage(final Image image, final int x, final int y, final int width,
final int height) {
}

@Override
public void drawText(final Font theFont, final String theStr, final int x, final int y) {
}
Expand Down Expand Up @@ -472,6 +466,7 @@ protected void switchAntiAliasOn(final boolean val) {
graphics.setBackground(fc);
graphics.setLineWidth(2);
ca.startDraw(graphics);
ca.initializeBuffer();

// see if it's a painter that also wants to know the error score

Expand All @@ -486,6 +481,8 @@ protected void switchAntiAliasOn(final boolean val) {
if (errorProvider != null) {
final CoreTMASegment coreSeg = (CoreTMASegment) segment;
coreSeg.paint(ca, errorProvider);
ca.flushBuffer();
coreSeg.writeMessage(ca);
painted = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ abstract public class CoreTMASegment extends TrackSegment implements CanBePlotte
*/
protected String _dragMsg;

/**
* Position of the Draw
*/
protected WorldLocation _dragPosition;

/**
* base constructor - sorts out the obvious
*
Expand Down Expand Up @@ -160,7 +165,7 @@ public void paint(final CanvasType dest, final ITimeVariableProvider errorProvid
// ok, is this our first location?
if (tmaLastLoc == null) {
tmaLastLoc = new WorldLocation(getTrackStart());
firstEnd = new WorldLocation(tmaLastLoc);
_dragPosition = firstEnd = new WorldLocation(tmaLastLoc);
} else {
// calculate a new vector
final long timeDelta = thisTime - tmaLastDTG;
Expand Down Expand Up @@ -204,7 +209,7 @@ public void paint(final CanvasType dest, final ITimeVariableProvider errorProvid

// ok, plot the 1/2 way message
if (_dragMsg != null) {
writeMessage(dest, firstEnd);
// writeMessage(dest, firstEnd);
}
}

Expand Down Expand Up @@ -295,6 +300,12 @@ public void setSpeed(final WorldSpeed speed) {
*/
abstract public void stretch(double rngDegs, final WorldLocation origin);

public void writeMessage(final CanvasType dest) {
if (_dragMsg != null && _dragPosition != null) {
writeMessage(dest, _dragPosition);
}
}

private void writeMessage(final CanvasType dest, final WorldLocation firstEnd) {
final Point pt = dest.toScreen(firstEnd);

Expand Down