Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » "Transparent" splash screen
"Transparent" splash screen [message #450773] Fri, 18 February 2005 11:11 Go to next message
Eclipse UserFriend
Originally posted by: e3oginosX.hotmail.com

hi
i am trying to make a splash screen with an image and no background so as
to look 'transparent'. This was quite easily done by setting the shell to
SWT.NO_BACKGROUND and adding a paintlistener on the shell to repaint the
image when nessesary.
However, when another window is on top of it and you move it so the
'splash' (or part of it) becomes visible, the 'transparent' part of the
splah gets screwed up. I tried many things (that are commented out in the
following code) to make it repaint itself but nothing seems to work
HELP!

heres the code (try it with a transparent gif/png/whatever picture):



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.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;




public class test {

public test() {

Display display = new Display();
Shell shell = new Shell(display , SWT.NO_BACKGROUND | SWT.NO_TRIM);
shell.setSize(140,100);

final Image img = new Image(display, "splash.GIF");
shell.setBounds(img.getBounds());
shell.open();

shell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {



e.gc.drawImage(img, 0, 0);

// splash.setRedraw(true);
// splash.setVisible(true);
//splash.redraw();
//splash.setVisible(false);
//splash.setVisible(true);
//splash.setMinimized(false);
//splash.open();
// splash.setActive();
// splash.forceActive();
//splash.update();
//splash.setSize(500,500);
//splash.setMaximized(false);

}
});



GC gc = new GC(shell);
gc.drawImage(img,0,0);

shell.open();
while(!display.isDisposed()) {
try {
if (!display.readAndDispatch())
display.sleep();
}
catch (Exception e) {
e.printStackTrace();
}
}


}
public static void main(String args[]) {
new test();
}
}
Re: "Transparent" splash screen [message #450840 is a reply to message #450773] Fri, 18 February 2005 14:44 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
SWT.NO_BACKGROUND just means that the operating system will not fill in the
background colour on paint events. As a result, the background is garbage.
People are often fooled into thinking this is transparent because the
garbage is initially whatever was behind when the widget was created. The
style SWT.NO_BACKGROUND is meant for people writing custom widgets who do
not want the flash of having the OS paint the background and then the custom
widget immediately paints the background to something else.

Transparency is not supported by GTK and Motif and therefore is not included
in SWT. However, here is a snippet that approximates the effect for a
shell:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet180.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup

"Kiriakou Andonis" <e3oginosX@hotmail.com> wrote in message
news:cv4ih5$vn1$1@www.eclipse.org...
> hi
> i am trying to make a splash screen with an image and no background so as
> to look 'transparent'. This was quite easily done by setting the shell to
> SWT.NO_BACKGROUND and adding a paintlistener on the shell to repaint the
> image when nessesary. However, when another window is on top of it and
> you move it so the 'splash' (or part of it) becomes visible, the
> 'transparent' part of the splah gets screwed up. I tried many things (that
> are commented out in the following code) to make it repaint itself but
> nothing seems to work
> HELP!
>
> heres the code (try it with a transparent gif/png/whatever picture):
>
>
>
> 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.Image;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
>
>
>
> public class test {
>
> public test() {
> Display display = new Display();
> Shell shell = new Shell(display , SWT.NO_BACKGROUND | SWT.NO_TRIM);
> shell.setSize(140,100);
>
> final Image img = new Image(display, "splash.GIF");
> shell.setBounds(img.getBounds());
> shell.open();
> shell.addPaintListener(new PaintListener() {
> public void paintControl(PaintEvent e) {
>
> e.gc.drawImage(img, 0, 0);
> // splash.setRedraw(true); //
> splash.setVisible(true);
> //splash.redraw();
> //splash.setVisible(false);
> //splash.setVisible(true);
> //splash.setMinimized(false);
> //splash.open();
> // splash.setActive();
> // splash.forceActive();
> //splash.update();
> //splash.setSize(500,500);
> //splash.setMaximized(false);
> }
> });
>
>
> GC gc = new GC(shell);
> gc.drawImage(img,0,0);
> shell.open();
> while(!display.isDisposed()) {
> try {
> if (!display.readAndDispatch())
> display.sleep();
> }
> catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> public static void main(String args[]) {
> new test();
> }
> }
>
>
Re: "Transparent" splash screen [message #450863 is a reply to message #450840] Fri, 18 February 2005 18:02 Go to previous message
Eclipse UserFriend
Originally posted by: e3oginosX.hotmail.com

ah, works fine this way, thanks alot

Veronika Irvine wrote:

> SWT.NO_BACKGROUND just means that the operating system will not fill in the
> background colour on paint events. As a result, the background is garbage.
> People are often fooled into thinking this is transparent because the
> garbage is initially whatever was behind when the widget was created. The
> style SWT.NO_BACKGROUND is meant for people writing custom widgets who do
> not want the flash of having the OS paint the background and then the custom
> widget immediately paints the background to something else.

> Transparency is not supported by GTK and Motif and therefore is not included
> in SWT. However, here is a snippet that approximates the effect for a
> shell:

>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet180.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup

> "Kiriakou Andonis" <e3oginosX@hotmail.com> wrote in message
> news:cv4ih5$vn1$1@www.eclipse.org...
>> hi
>> i am trying to make a splash screen with an image and no background so as
>> to look 'transparent'. This was quite easily done by setting the shell to
>> SWT.NO_BACKGROUND and adding a paintlistener on the shell to repaint the
>> image when nessesary. However, when another window is on top of it and
>> you move it so the 'splash' (or part of it) becomes visible, the
>> 'transparent' part of the splah gets screwed up. I tried many things (that
>> are commented out in the following code) to make it repaint itself but
>> nothing seems to work
>> HELP!
>>
>> heres the code (try it with a transparent gif/png/whatever picture):
>>
>>
>>
>> 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.Image;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>>
>>
>>
>>
>> public class test {
>>
>> public test() {
>> Display display = new Display();
>> Shell shell = new Shell(display , SWT.NO_BACKGROUND | SWT.NO_TRIM);
>> shell.setSize(140,100);
>>
>> final Image img = new Image(display, "splash.GIF");
>> shell.setBounds(img.getBounds());
>> shell.open();
>> shell.addPaintListener(new PaintListener() {
>> public void paintControl(PaintEvent e) {
>>
>> e.gc.drawImage(img, 0, 0);
>> // splash.setRedraw(true); //
>> splash.setVisible(true);
>> //splash.redraw();
>> //splash.setVisible(false);
>> //splash.setVisible(true);
>> //splash.setMinimized(false);
>> //splash.open();
>> // splash.setActive();
>> // splash.forceActive();
>> //splash.update();
>> //splash.setSize(500,500);
>> //splash.setMaximized(false);
>> }
>> });
>>
>>
>> GC gc = new GC(shell);
>> gc.drawImage(img,0,0);
>> shell.open();
>> while(!display.isDisposed()) {
>> try {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>> }
>> public static void main(String args[]) {
>> new test();
>> }
>> }
>>
>>
Previous Topic:SWT counterpart to Swings TreeCellRenderer
Next Topic:GridLayout not using all columns on every row
Goto Forum:
  


Current Time: Fri Apr 26 18:59:36 GMT 2024

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

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

Back to the top