Example usage for com.badlogic.gdx.backends.lwjgl LwjglCanvas LwjglCanvas

List of usage examples for com.badlogic.gdx.backends.lwjgl LwjglCanvas LwjglCanvas

Introduction

In this page you can find the example usage for com.badlogic.gdx.backends.lwjgl LwjglCanvas LwjglCanvas.

Prototype

public LwjglCanvas(ApplicationListener listener, LwjglApplicationConfiguration config) 

Source Link

Usage

From source file:aurelienribon.texturepackergui.Main.java

License:Apache License

public static void main(String[] args) {
    Parameters params = new Parameters(args);
    Project project = params.project;//from ww w.j a  v  a  2  s .c om

    if (project == null) {
        String str = "";
        str += "input=" + params.input + "\n";
        str += "output=" + params.output + "\n";
        str += params.settings;
        project = Project.fromString(str);
    }

    if (params.silent) {
        if (project.input.equals("") || project.output.equals("")) {
            System.err.println("Input and output directories have to be set");
        } else {
            try {
                project.pack();
            } catch (GdxRuntimeException ex) {
                System.err.println("Packing unsuccessful. " + ex.getMessage());
            }
        }
        return;
    }

    final Project prj = project;
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException ex) {
            } catch (InstantiationException ex) {
            } catch (IllegalAccessException ex) {
            } catch (UnsupportedLookAndFeelException ex) {
            }

            Canvas canvas = new Canvas();
            LwjglCanvas glCanvas = new LwjglCanvas(canvas, true);

            MainWindow mw = new MainWindow(prj, canvas, glCanvas.getCanvas());
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            mw.setSize(Math.min(1100, screenSize.width - 100), Math.min(670, screenSize.height - 100));
            mw.setLocationRelativeTo(null);
            mw.setVisible(true);
        }
    });
}

From source file:com.kotcrab.vis.editor.ui.EditorFrame.java

License:Apache License

public EditorFrame(SplashController splashController, LaunchConfiguration launchConfig) {
    this.launchConfig = launchConfig;
    setTitle("VisEditor");
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override/*  www.  j  a  v  a  2s .c  o  m*/
        public void windowClosing(WindowEvent e) {
            performEditorExit();
        }
    });

    setIconImage(loadImage("/com/kotcrab/vis/editor/icon.png"));

    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.width = 1280;
    config.height = 720;
    config.backgroundFPS = 0; //default is 60, when in background it takes a lot of cpu, maybe vsync causes it?
    config.allowSoftwareMode = launchConfig.allowSoftwareMode;

    editor = new Editor(this);

    editorCanvas = new LwjglCanvas(editor, config);
    Canvas canvas = editorCanvas.getCanvas();
    canvas.setSize(1280, 720);

    getContentPane().add(canvas, BorderLayout.CENTER);

    pack();
    setLocationRelativeTo(null);
    splashController.shouldClose = true;
}

From source file:com.macbury.r0x16.utils.PowerFrame.java

License:Apache License

private void construct(ApplicationListener listener, LwjglApplicationConfiguration config) {
    lwjglCanvas = new LwjglCanvas(listener, config) {
        protected void stopped() {
            PowerFrame.this.dispose();
        }/*w  ww  . j a  v a 2 s.co m*/

        protected void setTitle(String title) {
            PowerFrame.this.setTitle(title);
        }

        protected void setDisplayMode(int width, int height) {
            PowerFrame.this.getContentPane().setPreferredSize(new Dimension(width, height));
            PowerFrame.this.getContentPane().invalidate();
            PowerFrame.this.pack();
            PowerFrame.this.setLocationRelativeTo(null);
            updateSize(width, height);
        }

        protected void resize(int width, int height) {
            updateSize(width, height);
        }

        protected void start() {
            PowerFrame.this.start();
        }

        protected void exception(Throwable t) {
            PowerFrame.this.exception(t);
        }
    };

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
        }
    });

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getContentPane().setPreferredSize(new Dimension(config.width, config.height));

    initialize();
    pack();
    Point location = getLocation();
    if (location.x == 0 && location.y == 0)
        setLocationRelativeTo(null);
    lwjglCanvas.getCanvas().setSize(getSize());

    // Finish with invokeLater so any LwjglFrame super constructor has a chance to initialize.
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            addCanvas();
            setVisible(true);
            lwjglCanvas.getCanvas().requestFocus();
        }
    });
}

From source file:com.o2d.pkayjava.editor.splash.SplashFrame.java

License:Apache License

private void construct(ApplicationListener listener, LwjglApplicationConfiguration config) {
    lwjglCanvas = new LwjglCanvas(listener, config) {
        protected void stopped() {
            SplashFrame.this.dispose();
        }//from   w w w. j  a v  a2  s  . c om

        protected void setTitle(String title) {
            SplashFrame.this.setTitle(title);
        }

        protected void setDisplayMode(int width, int height) {
            SplashFrame.this.getContentPane().setPreferredSize(new Dimension(width, height));
            SplashFrame.this.getContentPane().invalidate();
            SplashFrame.this.pack();
            SplashFrame.this.setLocationRelativeTo(null);
            updateSize(width, height);
        }

        protected void resize(int width, int height) {
            updateSize(width, height);
        }

        protected void start() {
            SplashFrame.this.start();
        }

        protected void exception(Throwable t) {
            SplashFrame.this.exception(t);
        }

        protected int getFrameRate() {
            int frameRate = SplashFrame.this.getFrameRate();
            return frameRate == 0 ? super.getFrameRate() : frameRate;
        }
    };

    setHaltOnShutdown(true);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getContentPane().setPreferredSize(new Dimension(config.width, config.height));

    initialize();
    pack();
    Point location = getLocation();
    if (location.x == 0 && location.y == 0)
        setLocationRelativeTo(null);
    lwjglCanvas.getCanvas().setSize(getSize());

    // Finish with invokeLater so any LwjglFrame super constructor has a chance to initialize.
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            addCanvas();
            setVisible(true);
            lwjglCanvas.getCanvas().requestFocus();
        }
    });
}

From source file:com.steelkiwi.patheditor.gui.LwjglPanel.java

License:Apache License

public LwjglPanel(IUIHandler handler) {
    setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));
    setLayout(new GridLayout());

    gdxApp = new GdxApp(handler);
    canvas = new LwjglCanvas(gdxApp, true);
    add(canvas.getCanvas());/*from   w w w. j  a  v  a2  s . co  m*/
}

From source file:pl.kotcrab.jdialogue.editor.EditorLogic.java

License:Open Source License

public void createRenderer() {
    // renderer/*  w w w.  jav a 2s . c  o  m*/
    renderer = new Renderer(new EditorListener() {
        @Override
        public void mouseRightClicked(int x, int y) {
            popupMenu.show(canvas.getCanvas(), x, y);
        }

        @Override
        public void showMsg(final String msg, final String title, final int msgType) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    JOptionPane.showMessageDialog(Editor.window, msg, title, msgType);
                }
            });
        }

        @Override
        public void changePropertyTableModel(ComponentTableModel tableModel) {
            if (tableModel == null) // if componet doesn't have table model set default
                table.setModel(new DefaultTableModel());
            else {
                table.setModel(tableModel);
                ColumnsAutoSizer.sizeColumnsToFit(table);
            }
        }

        @Override
        public void showSaveDialog() {
            showSaveProjectDialog();
        }
    }, xstream);

    canvas = new LwjglCanvas(renderer, true);
    canvas.getCanvas().add(popupMenu);
}

From source file:pl.kotcrab.modelviewer.ModelViewer.java

License:Apache License

/**
 * Initialize the contents of the frame.
 *///from  w ww .  j a v  a2s. c o m
private void initialize() {
    frame = new JFrame("Libgdx 3D Model Viewer");

    frame.setBounds(100, 100, 659, 451);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout(0, 0));

    JPanel renderPanel = new JPanel(new BorderLayout());
    frame.getContentPane().add(renderPanel, BorderLayout.CENTER);

    final LwjglCanvas canvas = new LwjglCanvas(new Renderer(), true); //create canvas used for rendering
    renderPanel.add(canvas.getCanvas()); //atach canvas to panel

    JMenuBar menuBar = new JMenuBar();

    frame.getContentPane().add(menuBar, BorderLayout.NORTH);

    JMenu mnFileMenu = new JMenu("File");
    menuBar.add(mnFileMenu);

    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileNameExtensionFilter("OBJ or G3DB model", "obj", "OBJ", "g3db", "G3DB"));

    JMenuItem mntmNewMenuItem = new JMenuItem("Load");
    mntmNewMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int returnVal = fc.showOpenDialog(frame);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                eventList.add(new Event(fc.getSelectedFile().getAbsolutePath().replace('\\', '/'),
                        EventType.CHANGEFILE));
            }

        }
    });
    mnFileMenu.add(mntmNewMenuItem);

    JMenu mnRenderMenu = new JMenu("Render");
    menuBar.add(mnRenderMenu);

    final JCheckBoxMenuItem chckRenderLines = new JCheckBoxMenuItem("Lines");
    chckRenderLines.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            optRenderLines = chckRenderLines.isSelected();
        }
    });

    final JCheckBoxMenuItem chckRenderLight = new JCheckBoxMenuItem("Light");
    chckRenderLight.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            optRenderLight = chckRenderLight.isSelected();
        }
    });

    final JCheckBoxMenuItem chckRenderText = new JCheckBoxMenuItem("Text");
    chckRenderText.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            optRenderText = chckRenderText.isSelected();
        }
    });

    chckRenderLight.setSelected(true);
    chckRenderLines.setSelected(true);
    chckRenderText.setSelected(true);
    mnRenderMenu.add(chckRenderLight);
    mnRenderMenu.add(chckRenderLines);
    mnRenderMenu.add(chckRenderText);

    JMenu mnAnimation = new JMenu("Animation");
    menuBar.add(mnAnimation);

    animSpinner = new JSpinner();
    mnAnimation.add(animSpinner);

    btnPlay = new JMenuItem("Play");
    btnPlay.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            eventList.add(new Event(null, EventType.PLAYANIM));
        }
    });
    mnAnimation.add(btnPlay);

    btnStop = new JMenuItem("Stop");
    btnStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            eventList.add(new Event(null, EventType.STOPANIM));

        }
    });
    mnAnimation.add(btnStop);

    JMenu mnModel = new JMenu("Model");
    menuBar.add(mnModel);

    JMenuItem btnModelScale = new JMenuItem("Scale");
    btnModelScale.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            float scale;
            try {
                scale = Float.parseFloat(JOptionPane.showInputDialog(null, "Please enter new scale: "));
            } catch (NumberFormatException e1) //if entered text is not number
            {
                JOptionPane.showMessageDialog(null, "Enter number!");
                return;
            }

            if (scale <= 0) {
                JOptionPane.showMessageDialog(null, "Wrong number!");
                return;
            }

            eventList.add(new Event("" + scale, EventType.SCALE));
        }
    });
    mnModel.add(btnModelScale);

}