いくつかのデータを表現するためにカスタム フィギュアで GEF (Draw2d 3.9、Zest 1.5.0) を使用して、新しい Eclipse プラグインを開発しています。私は現在、調整可能なレンズ ビューを開発しようとしています。望ましい機能は、マウスがメイン ウィンドウ上でドラッグされることであり、「レンズ ビュー ウィンドウ」が選択された領域を表します。
そのために、レンズ ビュー用の SWT キャンバスを含むウィンドウを使用します。メイン ウィンドウ (グラフ) の内容は、レンズ キャンバスに描画されます。次に、レンズ キャンバスの別の領域 (可視領域の外側にある可能性があります) をポイント 0,0 (レンズ キャンバスの) にコピーします。問題は、レンズ キャンバスがその可視領域の外側にペイントされているものをすべて無視し、上記の領域をコピーすると内容ではなく黒くなることです。
グラフの内容を画像にコピーし、その後画像の一部を描画することは解決策ではありません。私のグラフは巨大 (> 200000 x 200000) かもしれないからです。
以下に、私のコードの一部を示します。
import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
public class LensView {
private final Shell shell;
private final Canvas canvas;
private final Point focalPoint;
private float lensScaleFactor;
private float mainScaleFactor;
public LensView(final Graph graph, Display d) {
this.visualizer = visualizer;
focalPoint = new Point(0, 0);
lensScaleFactor = 1.0f;
mainScaleFactor = 1.0f;
shell = new Shell(d, SWT.SHELL_TRIM);
shell.setSize(640, 480);
shell.setLayout(new FillLayout());
canvas = new Canvas(shell, SWT.NO_REDRAW_RESIZE);
canvas.setLayout(new FillLayout());
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Rectangle area = canvas.getClientArea();
//Scale the origin to 1.0 and apply our scale factor
float scale = lensScaleFactor/mainScaleFactor;
Point viewLocation = graph.getViewport().getViewLocation();
int tmpx = normaliseDec(Math.round((focalPoint.x + viewLocation.x) * scale) - Math.round(area.width/2.0f));
int tmpy = normaliseDec(Math.round((focalPoint.y + viewLocation.y) * scale) - Math.round(area.height/2.0f));
GC gc = new GC(canvas);
SWTGraphics graphics = new SWTGraphics(gc);
graphics.scale(scale);
graph.getContents().paint(graphics);
e.gc.copyArea(tmpx, tmpy, area.width, area.height, 0, 0);
graphics.dispose();
gc.dispose();
}
});
}
public void redraw (int x, int y) {
focalPoint.x = normaliseDec(x);
focalPoint.y = normaliseDec(y);
canvas.redraw();
canvas.update();
}
private int normaliseDec (int i) {
return i < 0 ? 0 : i;
}
}