src/inventory/InventoryDemo.java
author Matthias Mann
Sat Feb 11 13:27:12 2012 +0100 (3 months ago)
changeset 262 f896aec65113
parent 253 25120c47f789
permissions -rw-r--r--
allow mouse input for scrolling, don't update text area model when nothing has changed
Matthias@233
     1
/*
Matthias@259
     2
 * Copyright (c) 2008-2012, Matthias Mann
Matthias@233
     3
 *
Matthias@233
     4
 * All rights reserved.
Matthias@233
     5
 *
Matthias@233
     6
 * Redistribution and use in source and binary forms, with or without
Matthias@233
     7
 * modification, are permitted provided that the following conditions are met:
Matthias@233
     8
 *
Matthias@233
     9
 *     * Redistributions of source code must retain the above copyright notice,
Matthias@233
    10
 *       this list of conditions and the following disclaimer.
Matthias@233
    11
 *     * Redistributions in binary form must reproduce the above copyright
Matthias@233
    12
 *       notice, this list of conditions and the following disclaimer in the
Matthias@233
    13
 *       documentation and/or other materials provided with the distribution.
Matthias@233
    14
 *     * Neither the name of Matthias Mann nor the names of its contributors may
Matthias@233
    15
 *       be used to endorse or promote products derived from this software
Matthias@233
    16
 *       without specific prior written permission.
Matthias@233
    17
 *
Matthias@233
    18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Matthias@233
    19
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Matthias@233
    20
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Matthias@233
    21
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
Matthias@233
    22
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Matthias@233
    23
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Matthias@233
    24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Matthias@233
    25
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Matthias@233
    26
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Matthias@233
    27
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Matthias@233
    28
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Matthias@233
    29
 */
Matthias@248
    30
package inventory;
Matthias@233
    31
Matthias@248
    32
import de.matthiasmann.twl.DesktopArea;
Matthias@233
    33
import de.matthiasmann.twl.FPSCounter;
Matthias@233
    34
import de.matthiasmann.twl.GUI;
Matthias@248
    35
import de.matthiasmann.twl.ResizableFrame;
Matthias@233
    36
import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer;
Matthias@233
    37
import de.matthiasmann.twl.theme.ThemeManager;
Matthias@259
    38
import org.lwjgl.input.Mouse;
Matthias@233
    39
import org.lwjgl.opengl.Display;
Matthias@233
    40
import org.lwjgl.opengl.DisplayMode;
Matthias@233
    41
import org.lwjgl.opengl.GL11;
Matthias@253
    42
import test.TestUtils;
Matthias@233
    43
Matthias@233
    44
/**
Matthias@233
    45
 * A simple login panel
Matthias@233
    46
 * 
Matthias@233
    47
 * @author Matthias Mann
Matthias@233
    48
 */
Matthias@248
    49
public class InventoryDemo extends DesktopArea {
Matthias@233
    50
    
Matthias@233
    51
    public static void main(String[] args) {
Matthias@233
    52
        try {
Matthias@233
    53
            Display.setDisplayMode(new DisplayMode(800, 600));
Matthias@233
    54
            Display.create();
Matthias@235
    55
            Display.setTitle("TWL Login Panel Demo");
Matthias@233
    56
            Display.setVSyncEnabled(true);
Matthias@233
    57
Matthias@259
    58
            Mouse.setClipMouseCoordinatesToWindow(false);
Matthias@259
    59
            
Matthias@248
    60
            InventoryDemo demo = new InventoryDemo();
Matthias@233
    61
            
Matthias@233
    62
            LWJGLRenderer renderer = new LWJGLRenderer();
Matthias@233
    63
            GUI gui = new GUI(demo, renderer);
Matthias@233
    64
Matthias@233
    65
            ThemeManager theme = ThemeManager.createThemeManager(
Matthias@248
    66
                    InventoryDemo.class.getResource("inventory.xml"), renderer);
Matthias@233
    67
            gui.applyTheme(theme);
Matthias@233
    68
Matthias@248
    69
            gui.validateLayout();
Matthias@248
    70
            demo.positionFrame();
Matthias@248
    71
            
Matthias@233
    72
            while(!Display.isCloseRequested() && !demo.quit) {
Matthias@233
    73
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
Matthias@233
    74
Matthias@233
    75
                gui.update();
Matthias@233
    76
                Display.update();
Matthias@233
    77
            }
Matthias@233
    78
Matthias@233
    79
            gui.destroy();
Matthias@233
    80
            theme.destroy();
Matthias@233
    81
        } catch (Exception ex) {
Matthias@253
    82
            TestUtils.showErrMsg(ex);
Matthias@233
    83
        }
Matthias@233
    84
        Display.destroy();
Matthias@233
    85
    }
Matthias@233
    86
Matthias@233
    87
    final FPSCounter fpsCounter;
Matthias@248
    88
    final ResizableFrame frame;
Matthias@248
    89
    final InventoryPanel inventoryPanel;
Matthias@233
    90
    
Matthias@233
    91
    boolean quit;
Matthias@233
    92
Matthias@248
    93
    public InventoryDemo() {
Matthias@233
    94
        fpsCounter = new FPSCounter();
Matthias@233
    95
        
Matthias@248
    96
        inventoryPanel = new InventoryPanel(10, 5);
Matthias@233
    97
        
Matthias@248
    98
        frame = new ResizableFrame();
Matthias@248
    99
        frame.setTitle("Inventory");
Matthias@248
   100
        frame.setResizableAxis(ResizableFrame.ResizableAxis.NONE);
Matthias@248
   101
        frame.add(inventoryPanel);
Matthias@233
   102
        
Matthias@233
   103
        add(fpsCounter);
Matthias@248
   104
        add(frame);
Matthias@233
   105
    }
Matthias@233
   106
Matthias@248
   107
    void positionFrame() {
Matthias@248
   108
        frame.adjustSize();
Matthias@248
   109
        frame.setPosition(
Matthias@248
   110
                getInnerX() + (getInnerWidth() - frame.getWidth())/2,
Matthias@248
   111
                getInnerY() + (getInnerHeight() - frame.getHeight())/2);
Matthias@248
   112
    }
Matthias@248
   113
    
Matthias@233
   114
    @Override
Matthias@233
   115
    protected void layout() {
Matthias@248
   116
        super.layout();
Matthias@248
   117
        
Matthias@233
   118
        // fpsCounter is bottom right
Matthias@233
   119
        fpsCounter.adjustSize();
Matthias@233
   120
        fpsCounter.setPosition(
Matthias@233
   121
                getInnerRight() - fpsCounter.getWidth(),
Matthias@233
   122
                getInnerBottom() - fpsCounter.getHeight());
Matthias@233
   123
    }
Matthias@233
   124
    
Matthias@233
   125
}