[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.gef3d] Problem getting Draw3d to draw something
|
Hi,
I tried to wrap my head around Draw3d a bit and play around with it but
didn't managed to get a simple example working (I simply wanted to draw
a rectangle).
Could someone please correct the code from below for me?
Tom
package test3d;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw3d.Draw3DCanvas;
import org.eclipse.draw3d.Figure3D;
import org.eclipse.draw3d.LightweightSystem3D;
import org.eclipse.draw3d.RenderContext;
import org.eclipse.draw3d.XYZLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
public class View extends ViewPart {
public static final String ID = "Test3D.view";
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
Composite c = new Composite(parent,SWT.NONE);
c.setLayout(new FillLayout());
draw2d(c);
draw3d(c);
}
private void draw2d(Composite parent) {
Canvas cvs = new Canvas(parent,SWT.DOUBLE_BUFFERED);
cvs.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
LightweightSystem lws = new LightweightSystem(cvs);
Figure rootFigure = new Figure();
rootFigure.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN));
Figure rect = new Figure() {
@Override
protected void paintFigure(Graphics graphics) {
graphics.setBackgroundColor(getBackgroundColor());
graphics.fillRectangle(getBounds());
}
};
rect.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
rect.setLocation(new Point(20,20));
rect.setSize(100, 100);
rootFigure.add(rect);
rootFigure.setLayoutManager(new XYLayout());
lws.setContents(rootFigure);
}
private void draw3d(Composite parent) {
LightweightSystem3D lws = new LightweightSystem3D();
Figure3D rootFigure = new Figure3D() {
@Override
protected void paintFigure(Graphics iGraphics) {
super.paintFigure(iGraphics);
System.err.println("Root Paint is called");
}
@Override
public void render(RenderContext renderContext) {
super.render(renderContext);
System.err.println("Root Render is called");
}
};
rootFigure.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN));
Figure3D rect = new Figure3D() {
@Override
protected void paintFigure(Graphics iGraphics) {
super.paintFigure(iGraphics);
System.err.println("Rect Paint is called");
}
@Override
public void render(RenderContext renderContext) {
super.render(renderContext);
System.err.println("Rect Render is called");
}
};
rect.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
rect.setLocation(new Point(20,20));
rect.setSize(100, 100);
rootFigure.add(rect);
rootFigure.setLayoutManager(new XYZLayout());
lws.setContents(rootFigure);
Draw3DCanvas cvs = Draw3DCanvas.createCanvas(parent, SWT.NONE, lws);
cvs.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}