tags:

views:

546

answers:

0

I have an SWT app that has been developed on win32 and is now being ported to OSX. Everything works smoothly except for some visual quirks and one annoying problem.

The shell for this app is an image with rounded corners, so I'm using some code taken from one of the SWT snippets to create a shell with rounded corners. For some reason, when I'm adding a button with a background image to a composite that's attached to this shell, the button appears as a 'hole' in the shell (you can see the desktop through the shell). If I disable the transparency fix for the shell, the button appears. I've tried using GIF, PNG and JPG images without success for either. Needless to say, I did not have this issue on win32.

Any ideas will be appreciated.

The code creating the shell:

    final Shell shell = new Shell (display, SWT.NO_TRIM);

 final Region region = new Region();
 final ImageData imageData = image.getImageData();
 if (imageData.alphaData != null) {
  Rectangle pixel = new Rectangle(0, 0, 1, 1);
  for (int y = 0; y < imageData.height; y++) {
   for (int x = 0; x < imageData.width; x++) {
    if (imageData.getAlpha(x, y) == 255) {
     pixel.x = x;
     pixel.y = y;
     region.add(pixel);
    } 
   }
  }
 } else {
  ImageData mask = imageData.getTransparencyMask();
  Rectangle pixel = new Rectangle(0, 0, 1, 1);
  for (int y = 0; y < mask.height; y++) {
   for (int x = 0; x < mask.width; x++) {
    if (mask.getPixel(x, y) != 0) {
     pixel.x = x;

     pixel.y = y;

     region.add(pixel);      
    }
   }
  }   

 }

 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.drawImage(image, 0, 0);
   }
  }
 };
 shell.addListener(SWT.KeyDown, l);
 shell.addListener(SWT.MouseDown, l);
 shell.addListener(SWT.MouseMove, l);
 shell.addListener(SWT.Paint, l);

 shell.setSize(imageData.width, imageData.height);

 shell.addDisposeListener(new DisposeListener()
 {
  public void widgetDisposed(DisposeEvent event)
  {
   region.dispose();    
  }

 });