Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java、swt、Shell透明性+;抗锯齿_Java_Swt - Fatal编程技术网

Java、swt、Shell透明性+;抗锯齿

Java、swt、Shell透明性+;抗锯齿,java,swt,Java,Swt,这是一个例子: import org.eclipse.swt.swt; 导入org.eclipse.swt.graphics.Point; 导入org.eclipse.swt.graphics.Rectangle; 导入org.eclipse.swt.graphics.Region; 导入org.eclipse.swt.widgets.Button; 导入org.eclipse.swt.widgets.Display; 导入org.eclipse.swt.widgets.Event; 导入org

这是一个例子:

import org.eclipse.swt.swt;
导入org.eclipse.swt.graphics.Point;
导入org.eclipse.swt.graphics.Rectangle;
导入org.eclipse.swt.graphics.Region;
导入org.eclipse.swt.widgets.Button;
导入org.eclipse.swt.widgets.Display;
导入org.eclipse.swt.widgets.Event;
导入org.eclipse.swt.widgets.Listener;
导入org.eclipse.swt.widgets.Shell;
公共类代码段134{
静态int[]圆(int r,int offsetX,int offsetY){
int[]多边形=新的int[8*r+4];
//x^2+y^2=r^2
对于(int i=0;i<2*r+1;i++){
int x=i-r;
inty=(int)Math.sqrt(r*r-x*x);
多边形[2*i]=偏移量x+x;
多边形[2*i+1]=offsetY+y;
多边形[8*r-2*i-2]=偏移量x+x;
多边形[8*r-2*i-1]=偏移量-y;
}
返回多边形;
}
公共静态void main(字符串[]args){
最终显示=新显示();
//外壳必须使用SWT.NO_修剪样式创建
最终外壳=新外壳(显示器,SWT.NO|U装饰| SWT.ON|U顶部);
shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
//定义一个看起来像钥匙孔的区域
区域=新区域();
添加(圆圈(67,67,67));
减法(圆(20,67,50));
减法(新的int[]{67,50,55,105,79,105});
//使用setRegion定义外壳的形状
壳.setRegion(region);
矩形大小=region.getBounds();
外壳尺寸(尺寸、宽度、尺寸、高度);
//添加移动shell的能力
侦听器l=新侦听器(){
点源;
公共无效handleEvent(事件e){
开关(e型){
案例SWT.MouseDown:
原点=新点(e.x,e.y);
打破
案例SWT.MouseUp:
原点=空;
打破
case SWT.MouseMove:
如果(原点!=null){
点p=display.map(shell,null,e.x,e.y);
外壳设置位置(p.x-原点.x,p.y-原点.y);
}
打破
}
}
};
shell.addListener(SWT.MouseDown,l);
shell.addListener(SWT.MouseUp,l);
shell.addListener(SWT.MouseMove,l);
//添加关闭shell的功能
按钮b=新按钮(外壳,SWT.按钮);
b、 setBackground(shell.getBackground());
b、 setText(“关闭”);
b、 包装();
b、 设定位置(10,68);
b、 addListener(SWT.Selection,newlistener()){
公共无效handleEvent(事件e){
shell.close();
}
});
shell.open();
而(!shell.isDisposed()){
如果(!display.readAndDispatch())
display.sleep();
}
region.dispose();
display.dispose();
}
}
我想让它成为antialias-ed。我知道它可以通过
gc.setAntialias(SWT.ON)来实现但不知道写在哪里。

类似。看来这是不可能的。
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class Snippet134 {

  static int[] circle(int r, int offsetX, int offsetY) {
    int[] polygon = new int[8 * r + 4];
    // x^2 + y^2 = r^2
    for (int i = 0; i < 2 * r + 1; i++) {
      int x = i - r;
      int y = (int) Math.sqrt(r * r - x * x);
      polygon[2 * i] = offsetX + x;
      polygon[2 * i + 1] = offsetY + y;
      polygon[8 * r - 2 * i - 2] = offsetX + x;
      polygon[8 * r - 2 * i - 1] = offsetY - y;
    }
    return polygon;
  }

  public static void main(String[] args) {
    final Display display = new Display();
    // Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    // define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] { 67, 50, 55, 105, 79, 105 });
    // define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    // add ability to move shell around
    Listener l = new Listener() {
      Point origin;

      public void handleEvent(Event e) {
        switch (e.type) {
        case SWT.MouseDown:
          origin = new Point(e.x, e.y);
          break;
        case SWT.MouseUp:
          origin = null;
          break;
        case SWT.MouseMove:
          if (origin != null) {
            Point p = display.map(shell, null, e.x, e.y);
            shell.setLocation(p.x - origin.x, p.y - origin.y);
          }
          break;
        }
      }
    };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    // add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        shell.close();
      }
    });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    region.dispose();
    display.dispose();
  }
}