Linux users should also have fewer issues with this version; some of the library setup previously required is now taken care of automatically by the JNA library.
Showing posts with label shaped window. Show all posts
Showing posts with label shaped window. Show all posts
Wednesday, June 27, 2007
Improved Window Shaping
Thanks to contributions from Olivier Chafik and Chris Deckers, the overhead for setting a window shape mask has been reduced by about two orders of magnitude. In this case, the balloon tip windows no longer have such a noticeable delay before showing.
Linux users should also have fewer issues with this version; some of the library setup previously required is now taken care of automatically by the JNA library.

Linux users should also have fewer issues with this version; some of the library setup previously required is now taken care of automatically by the JNA library.
Labels:
java,
jna,
shaped window,
swing,
transparent window
Saturday, May 12, 2007
Easier Alpha Masks
The per-pixel alpha masking in this post has been codified into a simple API.
This effectively gives the window a transparent background. The alpha levels of the window's contents are preserved.
The demo is similar to the previous one but adds a few standard components to the mix.

UPDATE If you have a linux system and this for some reason doesn't work, please post a comment to that effect, or post a message to users@jna.dev.java.net so we can ensure this works reliably across all linux systems (64-bit is in the works).
WindowUtils.setWindowTransparent(Window w, boolean transparent);
This effectively gives the window a transparent background. The alpha levels of the window's contents are preserved.
The demo is similar to the previous one but adds a few standard components to the mix.
UPDATE If you have a linux system and this for some reason doesn't work, please post a comment to that effect, or post a message to users@jna.dev.java.net so we can ensure this works reliably across all linux systems (64-bit is in the works).
Labels:
java,
jna,
shaped window,
swing,
transparent window
Wednesday, April 18, 2007
Alpha-mask Transparency for a Window
Finally got per-pixel alpha mask working on w32. The included image isn't the greatest for showing an antialiased edge (it does have one), but if you have something with a drop shadow lying about, just drop it on the demo window and that'll be used instead.
Update This demo works on Windows, OSX and Linux (Linux requires JRE1.5+).

Update Here's another image to drop on the demo window, which better demonstrates the alpha blending, in case you don't have any handy

I've got some working X11 code, too, but I need to figure out a decent API to make it happen. OSX lets you just set the window background pixel transparent and then everything you paint in the window is automatically composited with whatever alpha mask you paint with. That could probably work with Swing as well, but you have to magically drop anything with a default background. OSX does this by checking for a magic UIResource color; anything painted with that color is fully transparent.
Update Source is available on BRANCH_V2 from JNA.
I realize I may be an utter dolt, but I find it really hard to follow Microsoft APIs. I've worked with Qt, X11/Xt, and Mac, each of which has its peculiarities of architecture, but those have a consistency (might I say design) that spans more than two or three functions.
Update This demo works on Windows, OSX and Linux (Linux requires JRE1.5+).
Update Here's another image to drop on the demo window, which better demonstrates the alpha blending, in case you don't have any handy

I've got some working X11 code, too, but I need to figure out a decent API to make it happen. OSX lets you just set the window background pixel transparent and then everything you paint in the window is automatically composited with whatever alpha mask you paint with. That could probably work with Swing as well, but you have to magically drop anything with a default background. OSX does this by checking for a magic UIResource color; anything painted with that color is fully transparent.
Update Source is available on BRANCH_V2 from JNA.
I realize I may be an utter dolt, but I find it really hard to follow Microsoft APIs. I've worked with Qt, X11/Xt, and Mac, each of which has its peculiarities of architecture, but those have a consistency (might I say design) that spans more than two or three functions.
Labels:
java,
jna,
shaped window,
swing,
transparent window
Tuesday, February 27, 2007
Non-rectangular Windows Update

Updated to include support for OSX and linux.
While OSX doesn't actually use any native code to do the window mask, JNA support is there if it needed to. Source (and per-platform binaries) is available at http://jna.dev.java.net.
Update
Transparent version of the demo is available here.
Friday, February 23, 2007
Non-rectangular Windows
I've been meaning to play around with shaped windows for a while, but didn't relish the thought of walking through the tedium of JNI configurations and builds. Doing it on one platform is bad enough, but on several? No thanks.
So I thought I'd write a little scriptable shared library access stub once and be done with JNI entirely. Well, turns out it's already been done. Several times.
JNative
NLink
JNA
JNative has some interesting features not found in the others, but actually using it is only slightly better than JNI. NLink is currently w32-only, and has a bit of a COM bent. JNA fit most closely with my objectives, already had implementations for w32 and solaris, and was already platform-agnostic. So I took a couple days to hack in some more features (mostly to get an understanding of the codebase), and here is what I got. The following code is what it takes to make a frame take an arbitrary shape.
Looking up the appropriate w32 calls probably took the most time. How are the w32 libraries defined? How is this for trivial:
Now, somebody's probably going to point me to how SWT has had this functionality for years (does it?), but this is nicely abstracted and based on a very small number of classes. I'll be updating the code at jna.dev.java.net (or maybe opening a new location if I can't get the existing project moved to subversion), but for now, check out the demo by clicking on everyone's favorite orange launch button.

Permissions required, because this runs some custom native code.
Oh, BTW, this is windows-only for the moment. I'll do X11 next and anyone's free to send me some code snippets for setting window masks on other platforms. I could also use some help porting to PPC and other platforms (a very small amount of native ASM to push arguments to the stack, not too hard).
So I thought I'd write a little scriptable shared library access stub once and be done with JNI entirely. Well, turns out it's already been done. Several times.
JNative
NLink
JNA
JNative has some interesting features not found in the others, but actually using it is only slightly better than JNI. NLink is currently w32-only, and has a bit of a COM bent. JNA fit most closely with my objectives, already had implementations for w32 and solaris, and was already platform-agnostic. So I took a couple days to hack in some more features (mostly to get an understanding of the codebase), and here is what I got. The following code is what it takes to make a frame take an arbitrary shape.
User32 user32 = User32.INSTANCE;
GDI32 gdi32 = GDI32.INSTANCE;
JFrame frame = new JFrame(getName());
Pointer p = gdi32.CreateRoundRectRgn(0, -150, 300, 300, 300, 300);
int hWnd = user32.FindWindowA(null, getName());
user32.SetWindowRgn(hWnd, p, true);
Looking up the appropriate w32 calls probably took the most time. How are the w32 libraries defined? How is this for trivial:
public interface User32 extends StdCallLibarary {
User32 INSTANCE = (User32)Native.loadLibary("user32", User32.class);
int FindWindowA(String winClass, String title);
void setWindowRgn(int hWnd, Pointer p, boolean redraw);
}
public interface GDI32 extends StdCallLibrary {
GDI32 INSTANCE = (GDI32)Native.loadLibrary("gdi32", GDI32.class);
Pointer CreateRoundRectRgn(int left, int top, int right, int bottom, int w, int h);
}
Now, somebody's probably going to point me to how SWT has had this functionality for years (does it?), but this is nicely abstracted and based on a very small number of classes. I'll be updating the code at jna.dev.java.net (or maybe opening a new location if I can't get the existing project moved to subversion), but for now, check out the demo by clicking on everyone's favorite orange launch button.
Permissions required, because this runs some custom native code.
Oh, BTW, this is windows-only for the moment. I'll do X11 next and anyone's free to send me some code snippets for setting window masks on other platforms. I could also use some help porting to PPC and other platforms (a very small amount of native ASM to push arguments to the stack, not too hard).
Subscribe to:
Comments (Atom)