|
Re: Widget transparency [message #525714 is a reply to message #525480] |
Wed, 07 April 2010 14:35 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
(If you have any follow-up questions from here then the eclipse.platform.swt
newsgroup is a more appropriate place than here).
The following snippets provide examples of creating non-standard Shells, and
some should be helpful with what you want to do. If the approach of a
transparent window+buttons proves to be difficult then you may instead want
to try creating multiple Shells with one Button each.
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet219.java?view=co
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet134.java?view=co
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet180.java?view=co
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet285.java?view=co
For controls != Shell (such as Button) true transparency is not supported.
It can be somewhat faked by inheiriting the parent Control's background
color or image, as demonstrated in
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet237.java?view=co .
However I think it will be difficult to implement the case of having the
button show the content underneath it that's coming from a different parent
Shell. If you really need the buttons to be transparent then you may need
to not use real Button controls, and instead just draw fake ones on the
transparent Shell, listen for mouse down events, etc. This would look
something like the snippet below.
public class ModifiedSnippet219 {
static final String STRING = "Fake Button";
public static void main(String[] args) {
final Display display = new Display ();
final Shell shell = new Shell (display, SWT.NO_TRIM);
shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE)) ;
GC gc = new GC(shell);
Point stringExtent = gc.stringExtent(STRING);
final Point size = new Point(stringExtent.x, stringExtent.y);
size.x += 20; size.y += 20;
gc.dispose();
Region region = new Region();
Rectangle rect = new Rectangle(0,0,1,1);
for (int i = 0; i < size.x; i++) {
rect.x = i; rect.y = 0;
region.add(rect);
rect.y = size.y - 1;
region.add(rect);
}
for (int i = 0; i < size.y; i++) {
rect.y = i; rect.x = 0;
region.add(rect);
rect.x = size.x - 1;
region.add(rect);
}
region.add(10,10,stringExtent.x, stringExtent.y);
shell.setRegion(region);
Listener l = new Listener() {
int startX, startY;
public void handleEvent(Event e) {
if (e.type == SWT.KeyDown && e.character == SWT.ESC) {
shell.dispose();
}
if (e.type == SWT.MouseDown && e.button == 1) {
startX = e.x;
startY = e.y;
}
if (e.type == SWT.MouseMove && (e.stateMask & SWT.BUTTON1)
!= 0) {
Point p = shell.toDisplay(e.x, e.y);
p.x -= startX;
p.y -= startY;
shell.setLocation(p);
}
if (e.type == SWT.Paint) {
e.gc.drawRectangle(0,0,size.x-1,size.y-1);
e.gc.drawString(STRING, 10, 10, true);
}
}
};
shell.addListener(SWT.KeyDown, l);
shell.addListener(SWT.MouseDown, l);
shell.addListener(SWT.MouseMove, l);
shell.addListener(SWT.Paint, l);
shell.setSize(size.x, size.y);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
region.dispose();
display.dispose ();
}
}
HTH,
Grant
"Herb Miller" <herbmiller7@gmail.com> wrote in message
news:hpfou6$6h1$1@build.eclipse.org...
> Does eclipse support transparency for SWT and JFace? I am especially
interested in making a small transparent window with transparent buttons
that can be popped up over my existing application (which is an RCP app).
>
> If I need to post this in other forums please let me know.
>
> Thanks.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03637 seconds