Shell: setRegion(Region reg) : Shell « org.eclipse.swt.widgets « Java by API






Shell: setRegion(Region reg)

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainClass {

  public static void main(String[] a) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    Region region = new Region();
    region.add(createCircle(50, 50, 50));
    region.subtract(createCircle(50, 50, 20));
    shell.setRegion(region);
    shell.setSize(region.getBounds().width, region.getBounds().height);
    shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
    

    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
  static int[] createCircle(int xOffset, int yOffset, int radius) {
    int[] circlePoints = new int[10 * radius];
    for (int loopIndex = 0; loopIndex < 2 * radius + 1; loopIndex++) {
      int xCurrent = loopIndex - radius;
      int yCurrent = (int) Math.sqrt(radius * radius - xCurrent * xCurrent);
      int doubleLoopIndex = 2 * loopIndex;
      
      circlePoints[doubleLoopIndex] = xCurrent + xOffset;
      circlePoints[doubleLoopIndex + 1] = yCurrent + yOffset;
      circlePoints[10 * radius - doubleLoopIndex - 2] = xCurrent + xOffset;
      circlePoints[10 * radius - doubleLoopIndex - 1] = -yCurrent + yOffset;
    }
    
    return circlePoints;
  }  
}

           
       








Related examples in the same category

1.new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM) (Make shell a dialog)
2.new Shell(Display arg0)
3.new Shell(Display display, int style)
4.new Shell(Shell parent)
5.Shell: getClientArea()
6.Shell: getDisplay()
7.Shell: open()
8.Shell: setImage(Image img)
9.Shell: setMenuBar(Menu menu)
10.Shell: setSize(int width, int height)