zoukankan      html  css  js  c++  java
  • 用SWT做圆形控件

    public static void main(String[] args) {

            final Display display = new Display();

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

            Region region = new Region();

            region.add(circle(20, 500, 300));

            shell.setRegion(region);

            // shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY));

           shell.setBackgroundImage(new Image(shell.getDisplay(),"C://Program Files//Movie Maker//Shared//Sample2.jpg"));

            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);

                    }

                }

            };

            shell.addListener(SWT.KeyDown, l);

            shell.addListener(SWT.MouseDown, l);

            shell.addListener(SWT.MouseMove, l);

            shell.addListener(SWT.Paint, l);

            shell.open();

            while (!shell.isDisposed()) {

                if (!display.readAndDispatch())

                    display.sleep();

            }

            region.dispose();

            display.dispose();

        }

        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;

        }

  • 相关阅读:
    DIJ最短路
    快速输入/输出
    Codeforces Round #610 (Div. 2).K for the Price of One (Hard Version)
    Codeforces Round #625 (Div. 1, based on Technocup 2020 Final Round).B. Navigation System
    Codeforces Round #612 (Div. 2)C. Garland
    Codeforces Round #621 (Div. 1 + Div. 2).D. Cow and Fields
    73.Python中ORM聚合函数详解:Count
    72.Python中ORM聚合函数详解:Avg,aggregate,annotate
    17. Getting to the essence of things
    55.ORM外键:引用同app下的不同模型,引用不同app下的模型,引用模型自身使用详解
  • 原文地址:https://www.cnblogs.com/okuc/p/4111598.html
Copyright © 2011-2022 走看看