Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [draw2D] transparent Figures always have a white background on windows
[draw2D] transparent Figures always have a white background on windows [message #240280] Thu, 13 December 2007 17:10 Go to next message
Eclipse UserFriend
Originally posted by: Gerhard.Hinterndorfer.pedrics.at

Hallo,

I have a problem implementing transparent draw2D labels on top of a swt
canvas under Windows. On the canvas I draw some other stuff: lines an
text using swt.eclipse.swt.graphics.GC.

On Linux everthing is fine: the draw2D labels are transparent :-)

But on Windows platforms (I tested it already on Win200 XP and Vista)
there I always get a white background after redraw. The size of the
white rectangle encloses exactly all the new drawn draw2D Labels.
After moving the whole Application Window out of the Desktop and moving
it in again the white rectangle disappeared.
When I switch to another application in maximized mode it disappears as
well after switching back to my RCP Application.

Does anybody have an idea?
Re: [draw2D] transparent Figures always have a white background on windows [message #240286 is a reply to message #240280] Fri, 14 December 2007 19:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Gerhard.Hinterndorfer.pedrics.at

Hallo again,

Now I prepared a Demo which shows exactly my issue explained below:

--------- Code starts here: --------------
package at.testDraw2D;

import org.eclipse.draw2d.*;
import org.eclipse.draw2d.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class CanvasDraw2DTest {

private static int canvasX=10;
private static int canvasY=10;
private static int canvasWidth=460;
private static int canvasHeight=300;

Canvas plotArea;
IFigure topLevelFigure;
IFigure labelFigures;

public static void main(String[] args) {
new CanvasDraw2DTest().startApplication();
}

private void startApplication(){
Shell shell = new Shell();
shell.setText("CanvasDraw2DTest");
shell.setSize(500, 500);
shell.open();

plotArea = new Canvas(shell, SWT.NO_REDRAW_RESIZE);

plotArea.setBounds(canvasX,canvasY,
canvasWidth,canvasHeight);
plotArea.setBackground(new
Color(org.eclipse.swt.widgets.Display.getDefault(),
180, 228, 187));
plotArea.addPaintListener
(new org.eclipse.swt.events.PaintListener() {
public void paintControl(
org.eclipse.swt.events.PaintEvent e) {
plotOnCanvas(e.gc);
}
});

LightweightSystem lws = new LightweightSystem(plotArea);
//set Draw2D Layer into transparent mode
lws.getRootFigure().setOpaque(false);

topLevelFigure = new Figure();
topLevelFigure.setForegroundColor(ColorConstants.red);
labelFigures = new Figure();
topLevelFigure.add(labelFigures);
labelFigures.setBounds(new
org.eclipse.draw2d.geometry.Rectangle(
0,0,canvasWidth,canvasHeight));
labelFigures.add(new
extLabel(canvasWidth/2,canvasHeight/2,
"Draw2D Text."));

lws.setContents(topLevelFigure);

Display display = Display.getDefault();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()){
display.sleep();
}
}
}

private void plotOnCanvas(GC gc){
gc.setForeground(Display.getDefault().getSystemColor(
SWT.COLOR_BLACK));
gc.drawRectangle(10,10,canvasWidth-20,canvasHeight-20);
gc.drawText ("Canvas Text.",20,20,SWT.DRAW_TRANSPARENT);
gc.drawLine(10, 10, canvasWidth-20,canvasHeight-20);
gc.drawLine(10, canvasHeight-20, canvasWidth-20,10);
}
}

class extLabel extends Label{
Label toolTip;

public extLabel(int xPos, int yPos, String text){
super();

this.setText(text);
this.setLocation(new org.eclipse.draw2d.geometry.Point(
xPos, yPos));
this.setSize(this.calculateTextSize());

toolTip = new Label("Tool Tip: "+text);
setToolTip(toolTip);
}
}

---------Code ends here -----------------

Thanks
Gerhard


Gerhard H. schrieb:
> Hallo,
>
> I have a problem implementing transparent draw2D labels on top of a swt
> canvas under Windows. On the canvas I draw some other stuff: lines an
> text using swt.eclipse.swt.graphics.GC.
>
> On Linux everthing is fine: the draw2D labels are transparent :-)
>
> But on Windows platforms (I tested it already on Win200 XP and Vista)
> there I always get a white background after redraw. The size of the
> white rectangle encloses exactly all the new drawn draw2D Labels.
> After moving the whole Application Window out of the Desktop and moving
> it in again the white rectangle disappeared.
> When I switch to another application in maximized mode it disappears as
> well after switching back to my RCP Application.
>
> Does anybody have an idea?
Re: [draw2D] transparent Figures always have a white background on windows [message #240288 is a reply to message #240286] Fri, 14 December 2007 20:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: irbull.cs.uvic.ca

I tired SWT.DOUBLE_BUFFERED on your canvas and it seems to fix things.
When using a doubled buffered canvas Draw2D doesn't try and do its own
double buffering, so therefore it is not trying to copy an image (which
must have a background) overtop of your canvas.

I don't know what will happen on MAC.

cheers,
ian

Gerhard H. wrote:
> Hallo again,
>
> Now I prepared a Demo which shows exactly my issue explained below:
>
> --------- Code starts here: --------------
> package at.testDraw2D;
>
> import org.eclipse.draw2d.*;
> import org.eclipse.draw2d.Label;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.*;
> import org.eclipse.swt.widgets.*;
>
> public class CanvasDraw2DTest {
>
> private static int canvasX=10;
> private static int canvasY=10;
> private static int canvasWidth=460;
> private static int canvasHeight=300;
>
> Canvas plotArea;
> IFigure topLevelFigure;
> IFigure labelFigures;
>
> public static void main(String[] args) {
> new CanvasDraw2DTest().startApplication();
> }
>
> private void startApplication(){
> Shell shell = new Shell();
> shell.setText("CanvasDraw2DTest");
> shell.setSize(500, 500);
> shell.open();
>
> plotArea = new Canvas(shell, SWT.NO_REDRAW_RESIZE);
>
> plotArea.setBounds(canvasX,canvasY,
> canvasWidth,canvasHeight);
> plotArea.setBackground(new
> Color(org.eclipse.swt.widgets.Display.getDefault(),
> 180, 228, 187));
> plotArea.addPaintListener
> (new org.eclipse.swt.events.PaintListener() {
> public void paintControl(
> org.eclipse.swt.events.PaintEvent e) {
> plotOnCanvas(e.gc);
> }
> });
>
> LightweightSystem lws = new LightweightSystem(plotArea);
> //set Draw2D Layer into transparent mode
> lws.getRootFigure().setOpaque(false);
>
> topLevelFigure = new Figure();
> topLevelFigure.setForegroundColor(ColorConstants.red);
> labelFigures = new Figure();
> topLevelFigure.add(labelFigures);
> labelFigures.setBounds(new
> org.eclipse.draw2d.geometry.Rectangle(
> 0,0,canvasWidth,canvasHeight));
> labelFigures.add(new
> extLabel(canvasWidth/2,canvasHeight/2,
> "Draw2D Text."));
>
> lws.setContents(topLevelFigure);
>
> Display display = Display.getDefault();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()){
> display.sleep();
> }
> }
> }
>
> private void plotOnCanvas(GC gc){
> gc.setForeground(Display.getDefault().getSystemColor(
> SWT.COLOR_BLACK));
> gc.drawRectangle(10,10,canvasWidth-20,canvasHeight-20);
> gc.drawText ("Canvas Text.",20,20,SWT.DRAW_TRANSPARENT);
> gc.drawLine(10, 10, canvasWidth-20,canvasHeight-20);
> gc.drawLine(10, canvasHeight-20, canvasWidth-20,10);
> }
> }
>
> class extLabel extends Label{
> Label toolTip;
>
> public extLabel(int xPos, int yPos, String text){
> super();
>
> this.setText(text);
> this.setLocation(new org.eclipse.draw2d.geometry.Point(
> xPos, yPos));
> this.setSize(this.calculateTextSize());
>
> toolTip = new Label("Tool Tip: "+text);
> setToolTip(toolTip);
> }
> }
>
> ---------Code ends here -----------------
>
> Thanks
> Gerhard
>
>
> Gerhard H. schrieb:
>> Hallo,
>>
>> I have a problem implementing transparent draw2D labels on top of a swt
>> canvas under Windows. On the canvas I draw some other stuff: lines an
>> text using swt.eclipse.swt.graphics.GC.
>>
>> On Linux everthing is fine: the draw2D labels are transparent :-)
>>
>> But on Windows platforms (I tested it already on Win200 XP and Vista)
>> there I always get a white background after redraw. The size of the
>> white rectangle encloses exactly all the new drawn draw2D Labels.
>> After moving the whole Application Window out of the Desktop and moving
>> it in again the white rectangle disappeared.
>> When I switch to another application in maximized mode it disappears as
>> well after switching back to my RCP Application.
>>
>> Does anybody have an idea?
Re: [draw2D] transparent Figures always have a white background on windows [message #240290 is a reply to message #240288] Fri, 14 December 2007 21:11 Go to previous message
Eclipse UserFriend
Originally posted by: Gerhard.Hinterndorfer.pedrics.at

Thanks a lot Ian, it also works in my RCP Application :-).

I already invested one day, and the solution is, as quite often, that
easy and also quite clear when I look back now

cheers,
Gerhard

Ian Bull schrieb:
> I tired SWT.DOUBLE_BUFFERED on your canvas and it seems to fix things.
> When using a doubled buffered canvas Draw2D doesn't try and do its own
> double buffering, so therefore it is not trying to copy an image (which
> must have a background) overtop of your canvas.
>
> I don't know what will happen on MAC.
>
> cheers,
> ian
>
> Gerhard H. wrote:
>> Hallo again,
>>
>> Now I prepared a Demo which shows exactly my issue explained below:
>>
>> --------- Code starts here: --------------
>> package at.testDraw2D;
>>
>> import org.eclipse.draw2d.*;
>> import org.eclipse.draw2d.Label;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.graphics.*;
>> import org.eclipse.swt.widgets.*;
>>
>> public class CanvasDraw2DTest {
>>
>> private static int canvasX=10;
>> private static int canvasY=10;
>> private static int canvasWidth=460;
>> private static int canvasHeight=300;
>>
>> Canvas plotArea;
>> IFigure topLevelFigure;
>> IFigure labelFigures;
>>
>> public static void main(String[] args) {
>> new CanvasDraw2DTest().startApplication();
>> }
>>
>> private void startApplication(){
>> Shell shell = new Shell();
>> shell.setText("CanvasDraw2DTest");
>> shell.setSize(500, 500);
>> shell.open();
>>
>> plotArea = new Canvas(shell, SWT.NO_REDRAW_RESIZE);
>>
>> plotArea.setBounds(canvasX,canvasY,
>> canvasWidth,canvasHeight);
>> plotArea.setBackground(new
>> Color(org.eclipse.swt.widgets.Display.getDefault(),
>> 180, 228, 187));
>> plotArea.addPaintListener
>> (new org.eclipse.swt.events.PaintListener() {
>> public void paintControl(
>> org.eclipse.swt.events.PaintEvent e) {
>> plotOnCanvas(e.gc);
>> }
>> });
>>
>> LightweightSystem lws = new LightweightSystem(plotArea);
>> //set Draw2D Layer into transparent mode
>> lws.getRootFigure().setOpaque(false);
>>
>> topLevelFigure = new Figure();
>> topLevelFigure.setForegroundColor(ColorConstants.red);
>> labelFigures = new Figure();
>> topLevelFigure.add(labelFigures);
>> labelFigures.setBounds(new
>> org.eclipse.draw2d.geometry.Rectangle(
>> 0,0,canvasWidth,canvasHeight));
>> labelFigures.add(new
>> extLabel(canvasWidth/2,canvasHeight/2,
>> "Draw2D Text."));
>>
>> lws.setContents(topLevelFigure);
>>
>> Display display = Display.getDefault();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch()){
>> display.sleep();
>> }
>> }
>> }
>>
>> private void plotOnCanvas(GC gc){
>> gc.setForeground(Display.getDefault().getSystemColor(
>> SWT.COLOR_BLACK));
>> gc.drawRectangle(10,10,canvasWidth-20,canvasHeight-20);
>> gc.drawText ("Canvas Text.",20,20,SWT.DRAW_TRANSPARENT);
>> gc.drawLine(10, 10, canvasWidth-20,canvasHeight-20);
>> gc.drawLine(10, canvasHeight-20, canvasWidth-20,10);
>> }
>> }
>>
>> class extLabel extends Label{
>> Label toolTip;
>>
>> public extLabel(int xPos, int yPos, String text){
>> super();
>>
>> this.setText(text);
>> this.setLocation(new org.eclipse.draw2d.geometry.Point(
>> xPos, yPos));
>> this.setSize(this.calculateTextSize());
>>
>> toolTip = new Label("Tool Tip: "+text);
>> setToolTip(toolTip);
>> }
>> }
>>
>> ---------Code ends here -----------------
>>
>> Thanks
>> Gerhard
>>
>>
>> Gerhard H. schrieb:
>>> Hallo,
>>>
>>> I have a problem implementing transparent draw2D labels on top of a swt
>>> canvas under Windows. On the canvas I draw some other stuff: lines an
>>> text using swt.eclipse.swt.graphics.GC.
>>>
>>> On Linux everthing is fine: the draw2D labels are transparent :-)
>>>
>>> But on Windows platforms (I tested it already on Win200 XP and Vista)
>>> there I always get a white background after redraw. The size of the
>>> white rectangle encloses exactly all the new drawn draw2D Labels.
>>> After moving the whole Application Window out of the Desktop and moving
>>> it in again the white rectangle disappeared.
>>> When I switch to another application in maximized mode it disappears as
>>> well after switching back to my RCP Application.
>>>
>>> Does anybody have an idea?
Previous Topic:Autolayout algorithm ?
Next Topic:Forcing outlying views (palette, properties, outline, etc) to update?
Goto Forum:
  


Current Time: Fri Apr 19 10:21:23 GMT 2024

Powered by FUDForum. Page generated in 0.02091 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top