/* * Called when the application is alt-tabbed to or from */ private void appActivate(boolean active) { if (inAppActivate) { return; } inAppActivate = true; isFocused = active; if (active) { if (Display.isFullscreen()) { restoreDisplayMode(); } if (parent == null) { setForegroundWindow(getHwnd()); } setFocus(getHwnd()); redoMakeContextCurrent = true; if (Display.isFullscreen()) updateClipping(); if (keyboard != null) keyboard.fireLostKeyEvents(); } else if (Display.isFullscreen()) { showWindow(getHwnd(), SW_SHOWMINNOACTIVE); resetDisplayMode(); } else updateClipping(); updateCursor(); inAppActivate = false; }
public void setResizable(boolean resizable) { if (this.resizable != resizable) { int style = (int) getWindowLongPtr(hwnd, GWL_STYLE); int styleex = (int) getWindowLongPtr(hwnd, GWL_EXSTYLE); // update frame style if (resizable && !Display.isFullscreen()) { setWindowLongPtr(hwnd, GWL_STYLE, style |= (WS_THICKFRAME | WS_MAXIMIZEBOX)); } else { setWindowLongPtr(hwnd, GWL_STYLE, style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX)); } // from the existing client rect, determine the new window rect // based on the style changes - using AdjustWindowRectEx. getClientRect(hwnd, rect_buffer); rect.copyFromBuffer(rect_buffer); adjustWindowRectEx(rect_buffer, style, false, styleex); rect.copyFromBuffer(rect_buffer); // force a frame update and resize accordingly setWindowPos( hwnd, HWND_TOP, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); updateWidthAndHeight(); resized = false; } this.resizable = resizable; }
public void update(int delta) { // rotate quad rotation += 0.15f * delta; if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) x -= 0.35f * delta; if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) x += 0.35f * delta; if (Keyboard.isKeyDown(Keyboard.KEY_UP)) y -= 0.35f * delta; if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) y += 0.35f * delta; while (Keyboard.next()) { if (Keyboard.getEventKeyState()) { if (Keyboard.getEventKey() == Keyboard.KEY_F) { setDisplayMode(800, 600, !Display.isFullscreen()); } else if (Keyboard.getEventKey() == Keyboard.KEY_V) { vsync = !vsync; Display.setVSyncEnabled(vsync); } } } // keep quad on the screen if (x < 0) x = 0; if (x > 800) x = 800; if (y < 0) y = 0; if (y > 600) y = 600; updateFPS(); // update FPS Counter }
public void update() { Display.update(); Display.sync(fps); detectKonami(); if (Constants.allowFullScr) { if ((fullScr && !Display.isFullscreen()) || (!fullScr && Display.isFullscreen())) { System.out.println("Performing Display.destroy()/create() cycle"); sM = Display.getDisplayMode(); Display.destroy(); try { // DisplayMode[] d = Display.getAvailableDisplayModes(); // int value = 0; // int index = 0; // for(int i = 0; i < d.length; i++){ // if(d[i].getWidth() > value){ // value = d[i].getWidth(); // index = i; // } // } Display.setDisplayMode(sM); Display.setTitle("Music Dots"); Display.setFullscreen(fullScr); Display.create(); Display.setVSyncEnabled(true); Constants.VIEW_HEIGHT = sM.getHeight(); Constants.VIEW_WIDTH = sM.getWidth(); setupOpenGl(); Fonts.initialize(); } catch (LWJGLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Theme.setClearColor(); // TODO: we should be calling a "recreateView" function and call this in there. Not sure why // we're recreating the view in an update function. if (!bPlayerModelInitialized) { StaticDrawer.initializeTextures(); bPlayerModelInitialized = true; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
/** * Set the display mode to be used * * @param width The width of the display required * @param height The height of the display required * @param fullscreen True if we want fullscreen mode */ public void setDisplayMode(int width, int height, boolean fullscreen) { // return if requested DisplayMode is already set if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) && (Display.isFullscreen() == fullscreen)) { return; } try { DisplayMode targetDisplayMode = null; if (fullscreen) { DisplayMode[] modes = Display.getAvailableDisplayModes(); int freq = 0; for (int i = 0; i < modes.length; i++) { DisplayMode current = modes[i]; if ((current.getWidth() == width) && (current.getHeight() == height)) { if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) { if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) { targetDisplayMode = current; freq = targetDisplayMode.getFrequency(); } } // if we've found a match for bpp and frequence against the // original display mode then it's probably best to go for this one // since it's most likely compatible with the monitor if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) { targetDisplayMode = current; break; } } } } else { targetDisplayMode = new DisplayMode(width, height); } if (targetDisplayMode == null) { System.out.println( "Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen); return; } Display.setDisplayMode(targetDisplayMode); Display.setFullscreen(fullscreen); } catch (LWJGLException e) { System.out.println( "Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e); } }
/** * @return this method will return the height of the Display window. * <p>If running in fullscreen mode it will return the height of the current set DisplayMode. * If Display.setParent(Canvas parent) is being used, the height of the parent will be * returned. * <p>This value will be updated after a call to Display.update(). */ public static int getHeight() { if (Display.isFullscreen()) { return Display.getDisplayMode().getHeight(); } if (parent != null) { return parent.getHeight(); } return height; }
/** * @return this method will return the width of the Display window. * <p>If running in fullscreen mode it will return the width of the current set DisplayMode. * If Display.setParent(Canvas parent) is being used, the width of the parent will be * returned. * <p>This value will be updated after a call to Display.update(). */ public static int getWidth() { if (Display.isFullscreen()) { return Display.getDisplayMode().getWidth(); } if (parent != null) { return parent.getWidth(); } return width; }
/** * @return this method will return the y position (top-left) of the Display window. * <p>If running in fullscreen mode it will return 0. If Display.setParent(Canvas parent) is * being used, the y position of the parent will be returned. */ public static int getY() { if (Display.isFullscreen()) { return 0; } if (parent != null) { return parent.getY(); } return display_impl.getY(); }
private void updateClipping() { if ((Display.isFullscreen() || (mouse != null && mouse.isGrabbed())) && !isMinimized && isFocused && (getForegroundWindow() == getHwnd() || hasParent)) { try { setupCursorClipping(getHwnd()); } catch (LWJGLException e) { LWJGLUtil.log("setupCursorClipping failed: " + e.getMessage()); } } else { resetCursorClipping(); } }
public void setDisplayMode(int width, int height, boolean fullscreen) { if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) && (Display.isFullscreen() == fullscreen)) { return; } try { DisplayMode targetDisplayMode = null; if (fullscreen) { DisplayMode[] modes = Display.getAvailableDisplayModes(); int freq = 0; for (int i = 0; i < modes.length; i++) { DisplayMode current = modes[i]; if ((current.getWidth() == width) && (current.getHeight() == height)) { if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) { if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) { targetDisplayMode = current; freq = targetDisplayMode.getFrequency(); } } if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) { targetDisplayMode = current; break; } } } } else targetDisplayMode = new DisplayMode(width, height); if (targetDisplayMode == null) { System.out.println( "Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen); return; } Display.setDisplayMode(targetDisplayMode); Display.setFullscreen(fullscreen); } catch (LWJGLException e) { System.out.println( "Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e); } }
@Override public boolean isFullscreen() { return Display.isFullscreen(); }
public void reshape(int x, int y, int width, int height) { nReshape( getHwnd(), x, y, width, height, Display.isFullscreen() || isUndecorated(), parent != null); }
public void createWindow(DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException { close_requested = false; is_dirty = false; isMinimized = false; isFocused = false; redoMakeContextCurrent = false; maximized = false; this.parent = parent; hasParent = parent != null; parent_hwnd = parent != null ? getHwnd(parent) : 0; this.hwnd = nCreateWindow( x, y, mode.getWidth(), mode.getHeight(), Display.isFullscreen() || isUndecorated(), parent != null, parent_hwnd); this.resizable = false; if (hwnd == 0) { throw new LWJGLException("Failed to create window"); } this.hdc = getDC(hwnd); if (hdc == 0) { nDestroyWindow(hwnd); throw new LWJGLException("Failed to get dc"); } try { if (drawable instanceof DrawableGL) { int format = WindowsPeerInfo.choosePixelFormat( getHdc(), 0, 0, (PixelFormat) drawable.getPixelFormat(), null, true, true, false, true); WindowsPeerInfo.setPixelFormat(getHdc(), format); } else { peer_info = new WindowsDisplayPeerInfo(true); ((DrawableGLES) drawable) .initialize( hwnd, hdc, EGL.EGL_WINDOW_BIT, (org.lwjgl.opengles.PixelFormat) drawable.getPixelFormat()); } peer_info.initDC(getHwnd(), getHdc()); showWindow(getHwnd(), SW_SHOWDEFAULT); updateWidthAndHeight(); if (parent == null) { if (Display.isResizable()) { setResizable(true); } setForegroundWindow(getHwnd()); } else { parent_focused = new AtomicBoolean(false); parent.addFocusListener( parent_focus_tracker = new FocusAdapter() { public void focusGained(FocusEvent e) { parent_focused.set(true); clearAWTFocus(); } }); SwingUtilities.invokeLater( new Runnable() { public void run() { clearAWTFocus(); } }); } grabFocus(); } catch (LWJGLException e) { nReleaseDC(hwnd, hdc); nDestroyWindow(hwnd); throw e; } }
public static boolean isFullscreen() { return Display.isFullscreen(); }