OSDN Git Service

ran gdx-tools HeaderFixer tool
[mikumikustudio/libgdx-mikumikustudio.git] / backends / gdx-backend-jglfw / src / com / badlogic / gdx / backends / jglfw / JglfwGraphics.java
index 358f7c7..56117e3 100644 (file)
@@ -1,3 +1,18 @@
+/*******************************************************************************\r
+ * Copyright 2011 See AUTHORS file.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *   http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************************/
 
 package com.badlogic.gdx.backends.jglfw;
 
@@ -33,8 +48,8 @@ public class JglfwGraphics implements Graphics {
        private int x, y, width, height;
        private boolean visible;
        private Color initialBackgroundColor;
-       private volatile boolean isContinuous = true;
-       private volatile boolean renderRequested;
+       private volatile boolean isContinuous = true, renderRequested;
+       volatile boolean foreground, minimized;
 
        private float deltaTime;
        private long frameStart, lastTime = -1;
@@ -112,8 +127,8 @@ public class JglfwGraphics implements Graphics {
                if (newWindow == 0) return false;
                if (oldWindow != 0) glfwDestroyWindow(oldWindow);
                window = newWindow;
-               this.width = width;
-               this.height = height;
+               this.width = Math.max(1, width);
+               this.height = Math.max(1, height);
 
                this.fullscreen = fullscreen;
                if (!fullscreen) {
@@ -134,8 +149,7 @@ public class JglfwGraphics implements Graphics {
                return true;
        }
 
-       void frameStart () {
-               long time = System.nanoTime();
+       void frameStart (long time) {
                if (lastTime == -1) lastTime = time;
                deltaTime = (time - lastTime) / 1000000000.0f;
                lastTime = time;
@@ -149,6 +163,9 @@ public class JglfwGraphics implements Graphics {
        }
 
        void sizeChanged (int width, int height) {
+               glfwShowWindow(window); // This is required to refresh the NSOpenGLContext on OSX!
+               width = Math.max(1, width);
+               height = Math.max(1, height);
                this.width = width;
                this.height = height;
                Gdx.gl.glViewport(0, 0, width, height);
@@ -187,11 +204,11 @@ public class JglfwGraphics implements Graphics {
        }
 
        public int getWidth () {
-               return glfwGetWindowWidth(window);
+               return width;
        }
 
        public int getHeight () {
-               return glfwGetWindowHeight(window);
+               return height;
        }
 
        public float getDeltaTime () {
@@ -211,35 +228,36 @@ public class JglfwGraphics implements Graphics {
        }
 
        public float getPpiX () {
-               // return getWidth() / (glfwGetMonitorPhysicalWidth(getWindowMonitor()) * 0.03937f);
+               // return getWidth() / (glfwGetMonitorPhysicalWidth(getWindowMonitor()) * 0.03937f); // mm to inches
                return Toolkit.getDefaultToolkit().getScreenResolution();
        }
 
        public float getPpiY () {
-               // return getHeight() / (glfwGetMonitorPhysicalHeight(getWindowMonitor()) * 0.03937f);
+               // return getHeight() / (glfwGetMonitorPhysicalHeight(getWindowMonitor()) * 0.03937f); // mm to inches
                return Toolkit.getDefaultToolkit().getScreenResolution();
        }
 
        public float getPpcX () {
-               // return getWidth() / (glfwGetMonitorPhysicalWidth(getWindowMonitor()) / 10);
+               // return getWidth() / (glfwGetMonitorPhysicalWidth(getWindowMonitor()) / 10); // mm to cm
                return Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f;
        }
 
        public float getPpcY () {
-               // return getHeight() / (glfwGetMonitorPhysicalHeight(getWindowMonitor()) / 10);
+               // return getHeight() / (glfwGetMonitorPhysicalHeight(getWindowMonitor()) / 10); // mm to cm
                return Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f;
        }
 
        public float getDensity () {
-               long monitor = getWindowMonitor();
-               float mmWidth = glfwGetMonitorPhysicalWidth(monitor);
-               float mmHeight = glfwGetMonitorPhysicalHeight(monitor);
-               float inches = (float)Math.sqrt(mmWidth * mmWidth + mmHeight * mmHeight) * 0.03937f;
-               float pixelWidth = getWidth();
-               float pixelHeight = getHeight();
-               float pixels = (float)Math.sqrt(pixelWidth * pixelWidth + pixelHeight * pixelHeight);
-               float diagonalPpi = pixels / inches;
-               return diagonalPpi / 160f;
+               // long monitor = getWindowMonitor();
+               // float mmWidth = glfwGetMonitorPhysicalWidth(monitor);
+               // float mmHeight = glfwGetMonitorPhysicalHeight(monitor);
+               // float inches = (float)Math.sqrt(mmWidth * mmWidth + mmHeight * mmHeight) * 0.03937f; // mm to inches
+               // float pixelWidth = getWidth();
+               // float pixelHeight = getHeight();
+               // float pixels = (float)Math.sqrt(pixelWidth * pixelWidth + pixelHeight * pixelHeight);
+               // float diagonalPpi = pixels / inches;
+               // return diagonalPpi / 160f;
+               return Toolkit.getDefaultToolkit().getScreenResolution() / 160f;
        }
 
        public boolean supportsDisplayModeChange () {
@@ -355,8 +373,16 @@ public class JglfwGraphics implements Graphics {
                glfwSwapBuffers(window);
        }
 
+       public boolean isHidden () {
+               return !visible;
+       }
+
        public boolean isMinimized () {
-               return glfwGetWindowParam(window, GLFW_ICONIFIED) == 1;
+               return minimized;
+       }
+
+       public boolean isForeground () {
+               return foreground;
        }
 
        public void minimize () {
@@ -380,4 +406,4 @@ public class JglfwGraphics implements Graphics {
                        super(width, height, refreshRate, bitsPerPixel);
                }
        }
-}
+}
\ No newline at end of file