Search in sources :

Example 1 with ModernUI

use of icyllis.modernui.ModernUI in project ModernUI by BloCamLimb.

the class TestMain method main.

public static void main(String[] args) {
    if (!CREATE_WINDOW) {
        try (ModernUI modernUI = new ModernUI()) {
            modernUI.run(new TestFragment());
        }
        return;
    }
    /*String s = "\u0641\u0647\u0648\u064a\u062a\u062d\u062f\u0651\u062b\u0020\u0628\u0644\u063a\u0629\u0020";
        Font font = ALL_FONTS.stream().filter(f -> f.canDisplayUpTo("\u0641\u0647\u0648") == -1).findFirst().get();
        GlyphVector vector = font.layoutGlyphVector(GRAPHICS.getFontRenderContext(),
                s.toCharArray(), 0, s.length(), Font.LAYOUT_RIGHT_TO_LEFT);
        ModernUI.LOGGER.info(MARKER, "GlyphNum: {}", vector.getNumGlyphs());
        for (int i = 0; i < vector.getNumGlyphs(); i++) {
            ModernUI.LOGGER.info(MARKER, "GlyphCode: {}", vector.getGlyphCode(i));
        }
        breakWords(s);
        breakGraphemes(s);
        ModernUI.LOGGER.info(Integer.toHexString(MuiHooks.C.calcGuiScales(3840, 2160)));*/
    /*System.setProperty("org.lwjgl.librarypath", nativesDir);*/
    /*ModernUI.LOGGER.info("Module: {}", TestMain.class.getModule());
        ModernUI.LOGGER.info("Main class loader: {}", TestMain.class.getClassLoader());
        ModernUI.LOGGER.info("System class loader: {}", ClassLoader.getSystemClassLoader());
        ModernUI.LOGGER.info("Bootstrap class loader: {}", Object.class.getClassLoader());

        ArrayList<Object> acc_r = new ArrayList<>();
        acc_r.add("c");
        List<String> acc_f = (List<String>) (Object) acc_r;

        ArrayList<String> acc_c = new ArrayList<>();
        acc_c.add("d");
        List<Object> acc_g = (List<Object>) (Object) acc_c;*/
    /*IMAGE = new BufferedImage(1024, 1024, BufferedImage.TYPE_INT_ARGB);
        GRAPHICS = IMAGE.createGraphics();

        GraphicsEnvironment.getLocalGraphicsEnvironment().preferLocaleFonts();
        ALL_FONTS = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts());
        GRAPHICS.setColor(Color.BLACK);
        GRAPHICS.fillRect(0, 0, 1024, 1024);
        GRAPHICS.setColor(Color.WHITE);
        GRAPHICS.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        GRAPHICS.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        GRAPHICS.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        GRAPHICS.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        GRAPHICS.draw(new RoundRectangle2D.Float(20, 20, 600, 600, 20, 20));
        try {
            ImageIO.write(IMAGE, "png", new File("F:/trrr.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    /*try {
            DataSet dataSet = DataSet.inflate(new FileInputStream("F:/ftestdata.dat"));
            ModernUI.LOGGER.info(dataSet);
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    // (sec23°)²+(sec22°)²-2sec23°sec22°cos45°=a²
    // θ=arccos((a²+(sec22°)²-(sec23°)²)/(2asec22°))
    /*double sec22 = 1 / Math.cos(Math.toRadians(22));
        double sec23 = 1 / Math.cos(Math.toRadians(23));
        double sec22_2 = sec22 * sec22;
        double sec23_2 = sec23 * sec23;
        double a_2 = sec23_2 + sec22_2 - 2 * sec22 * sec23 * Math.cos(Math.toRadians(45));
        double a = Math.sqrt(a_2);
        double theta = Math.acos((a_2 + sec22_2 - sec23_2) / (2 * a * sec22));
        ModernUI.LOGGER.info(Math.toDegrees(theta));

        ModernUI.LOGGER.info(Integer.toHexString(ColorEvaluator.evaluate(0.5f, 0xF0AADCF0, 0xF0FFC3F7)).toUpperCase
        (Locale.ROOT));*/
    /*float[] av = new float[]{1, 3, 2, 4.1f, 6, 0, 6, 0.5f, 5, 7, 11.3f, 9, 9.1f, 15, 8, 10};
        float[] bv = new float[]{9.1f, 2, 7, 5, 3.3f, 6.1f, 5.5f, 4, 0, 8, 3, 1, 2.7f, 3, 9, 2};
        int[] intervals = new int[]{0, 4, 9, 15, 17};*/
    /*float[] re = new float[256];
        float[] im = new float[256];

        for (int i = 0; i < 256; i++) {
            re[i] = MathUtil.cos(2 * MathUtil.PI * i / 256f);
            im[i] = 0;
        }

        ModernUI.LOGGER.info("Before \n{}\n{}", Arrays.toString(re), Arrays.toString(im));
        FFT.fft(re, im);

        float[] ff = new float[256];
        for (int i = 0; i < 256; i++) {
            ff[i] = MathUtil.sqrt(re[i] * re[i] + im[i] * im[i]);
        }

        ModernUI.LOGGER.info("After \n{}", Arrays.toString(ff));*/
    // Quaternion q = Quaternion.fromAxisAngle(0.40824829f, 0.81649658f, 0.40824829f, MathUtil.PI_DIV_3);
    /*Vector3 vec1 = new Vector3(5, 2, 2);
        Vector3 vec2 = vec1.copy();
        Vector3 vec3 = vec2.copy();
        Quaternion q = Quaternion.makeAxisAngle(1.0f, 0, 0, MathUtil.PI_DIV_4);
        vec1.transform(q.toMatrix4());
        vec2.transform(q);
        Matrix4 mat = Matrix4.identity();
        mat.rotateX(MathUtil.PI_DIV_4);
        vec3.transform(mat);
        ModernUI.LOGGER.info("\n{}\n{}\n{}\nEq: {}, {}", vec1, vec2, vec3, vec1.equivalent(vec2), vec2.equivalent
        (vec3));*/
    /*Matrix4 mat = Matrix4.identity();
        Vector3 pos = new Vector3(3, 0, 0);
        mat.translate(2, 0, 0);
        mat.rotateZ(MathUtil.PI_DIV_2);
        mat.translate(-2, 0, 0);
        pos.transform(mat);*/
    /*Bidi bidi = new Bidi(text.toCharArray(), 0, null, 0, text.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
        int runCount = bidi.getRunCount();
        byte[] levels = new byte[runCount];
        Integer[] ranges = new Integer[runCount];

        */
    /* Reorder contiguous runs of text into their display order from left to right */
    /*
        for (int index = 0; index < runCount; index++) {
            levels[index] = (byte) bidi.getRunLevel(index);
            ranges[index] = index;
        }
        Bidi.reorderVisually(levels, 0, ranges, 0, runCount);
        ModernUI.LOGGER.info("Reorder: {}", Arrays.toString(Bidi.reorderVisual(levels)));


        for (int logicalIndex = 0; logicalIndex < runCount; logicalIndex++) {
            int visualIndex = ranges[logicalIndex];

            ModernUI.LOGGER.info("Bidi: {}, RTL {}, {} to {}", logicalIndex, (bidi.getRunLevel(visualIndex) & 1) != 0,
                    bidi.getRunStart(visualIndex), bidi.getRunLimit(visualIndex));
        }*/
    // ModernUI.LOGGER.info(MathUtil.atan2(-1, -1));
    // ModernUI.LOGGER.info(pos);
    /*try {
            new Runner(new OptionsBuilder().include(TestCompare.class.getSimpleName()).build()).run();
        } catch (RunnerException e) {
            e.printStackTrace();
        }*/
    // ModernUI.LOGGER.info(Gravity.TOP & Gravity.BOTTOM);
    new ModernUI();
    ShaderManager.getInstance().addListener(mgr -> mgr.getShard(ModernUI.ID, "a.vert"));
    try {
        Thread.currentThread().setName("Main-Thread");
        ArchCore.initialize();
        sWindow = MainWindow.initialize("Modern UI Layout Editor", 1600, 900);
        try (var c1 = ModernUI.getInstance().getResourceChannel(ModernUI.ID, "AppLogo16x.png");
            var bitmap1 = NativeImage.decode(null, c1);
            var c2 = ModernUI.getInstance().getResourceChannel(ModernUI.ID, "AppLogo32x.png");
            var bitmap2 = NativeImage.decode(null, c2);
            var c3 = ModernUI.getInstance().getResourceChannel(ModernUI.ID, "AppLogo48x.png");
            var bitmap3 = NativeImage.decode(null, c3)) {
            sWindow.setIcon(bitmap1, bitmap2, bitmap3);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Thread renderThread = new Thread(TestMain::runRenderThread, "Render-Thread");
        renderThread.start();
        /*new Thread(() -> {
                // convert to png format with alpha channel
                try (Bitmap b = Bitmap.openDialog(Bitmap.Format.RGBA)) {
                    if (b != null) {
                        b.saveDialog(Bitmap.SaveFormat.PNG, 0);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }, "Open-File").start();*/
        /*new Thread(() -> {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                try (MemoryStack stack = MemoryStack.stackPush()) {
                    ByteBuffer buffer = stack.malloc(3);
                    String c = TinyFileDialogs.tinyfd_colorChooser((ByteBuffer) null, null, buffer, buffer);
                    if (c != null) {
                        ModernUI.LOGGER.info("Choose color {}", c);
                    }
                }
            }, "Choose-Color").start();*/
        Looper.prepare(sWindow);
        Looper.loop();
        renderThread.interrupt();
    } finally {
        if (sWindow != null) {
            sWindow.close();
        }
        AudioManager.getInstance().close();
        Stream.of(glfwSetMonitorCallback(null), glfwSetErrorCallback(null)).filter(Objects::nonNull).forEach(Callback::free);
        glfwTerminate();
        LOGGER.info(MARKER, "Stopped");
    }
}
Also used : Callback(org.lwjgl.system.Callback) ModernUI(icyllis.modernui.ModernUI) IOException(java.io.IOException)

Aggregations

ModernUI (icyllis.modernui.ModernUI)1 IOException (java.io.IOException)1 Callback (org.lwjgl.system.Callback)1