Skip to content

Commit

Permalink
add 4 getters to JmeContext for screen position and frame-buffer size (
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold authored Jan 15, 2023
1 parent 9a2d950 commit 925ff45
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
import android.content.DialogInterface;
import android.content.pm.ConfigurationInfo;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.text.InputType;
import android.view.Gravity;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
Expand Down Expand Up @@ -494,4 +497,61 @@ public com.jme3.opencl.Context getOpenCLContext() {
logger.warning("OpenCL is not yet supported on android");
return null;
}

/**
* Returns the height of the input surface.
*
* @return the height (in pixels)
*/
@Override
public int getFramebufferHeight() {
Rect rect = getSurfaceFrame();
int result = rect.height();
return result;
}

/**
* Returns the width of the input surface.
*
* @return the width (in pixels)
*/
@Override
public int getFramebufferWidth() {
Rect rect = getSurfaceFrame();
int result = rect.width();
return result;
}

/**
* Returns the screen X coordinate of the left edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowXPosition() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Returns the screen Y coordinate of the top edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowYPosition() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Retrieves the dimensions of the input surface. Note: do not modify the
* returned object.
*
* @return the dimensions (in pixels, left and top are 0)
*/
private Rect getSurfaceFrame() {
SurfaceView view = (SurfaceView) androidInput.getView();
SurfaceHolder holder = view.getHolder();
Rect result = holder.getSurfaceFrame();
return result;
}
}
31 changes: 31 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/JmeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,35 @@ public enum Type {
*/
public void destroy(boolean waitFor);

/**
* Returns the height of the framebuffer.
*
* @return the height (in pixels)
* @throws IllegalStateException for a headless or null context
*/
public int getFramebufferHeight();

/**
* Returns the width of the framebuffer.
*
* @return the width (in pixels)
* @throws IllegalStateException for a headless or null context
*/
public int getFramebufferWidth();

/**
* Returns the screen X coordinate of the left edge of the content area.
*
* @return the screen X coordinate
* @throws IllegalStateException for a headless or null context
*/
public int getWindowXPosition();

/**
* Returns the screen Y coordinate of the top edge of the content area.
*
* @return the screen Y coordinate
* @throws IllegalStateException for a headless or null context
*/
public int getWindowYPosition();
}
40 changes: 40 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/NullContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,44 @@ public boolean isRenderable() {
public Context getOpenCLContext() {
return null;
}

/**
* Returns the height of the framebuffer.
*
* @throws UnsupportedOperationException
*/
@Override
public int getFramebufferHeight() {
throw new UnsupportedOperationException("null context");
}

/**
* Returns the width of the framebuffer.
*
* @throws UnsupportedOperationException
*/
@Override
public int getFramebufferWidth() {
throw new UnsupportedOperationException("null context");
}

/**
* Returns the screen X coordinate of the left edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowXPosition() {
throw new UnsupportedOperationException("null context");
}

/**
* Returns the screen Y coordinate of the top edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowYPosition() {
throw new UnsupportedOperationException("null context");
}
}
44 changes: 39 additions & 5 deletions jme3-desktop/src/main/java/com/jme3/system/AWTContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
import com.jme3.input.TouchInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext;
import com.jme3.system.JmeSystem;
import com.jme3.system.SystemListener;
import com.jme3.system.Timer;

/**
* A JMonkey {@link JmeContext context} that is dedicated to AWT component rendering.
Expand Down Expand Up @@ -241,4 +236,43 @@ public void destroy(final boolean waitFor) {
backgroundContext.destroy(waitFor);
}

/**
* Returns the height of the framebuffer.
*
* @return the height (in pixels)
*/
@Override
public int getFramebufferHeight() {
return height;
}

/**
* Returns the width of the framebuffer.
*
* @return the width (in pixels)
*/
@Override
public int getFramebufferWidth() {
return width;
}

/**
* Returns the screen X coordinate of the left edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowXPosition() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Returns the screen Y coordinate of the top edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowYPosition() {
throw new UnsupportedOperationException("not implemented yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,43 @@ public void restart() {
// only relevant if changing pixel format.
}

/**
* Returns the height of the input panel.
*
* @return the height (in pixels)
*/
@Override
public int getFramebufferHeight() {
return inputSource.getHeight();
}

/**
* Returns the width of the input panel.
*
* @return the width (in pixels)
*/
@Override
public int getFramebufferWidth() {
return inputSource.getWidth();
}

/**
* Returns the screen X coordinate of the left edge of the input panel.
*
* @return the screen X coordinate
*/
@Override
public int getWindowXPosition() {
return inputSource.getX();
}

/**
* Returns the screen Y coordinate of the top edge of the input panel.
*
* @return the screen Y coordinate
*/
@Override
public int getWindowYPosition() {
return inputSource.getY();
}
}
40 changes: 40 additions & 0 deletions jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,44 @@ public Context getOpenCLContext() {
logger.warning("OpenCL not yet supported on this platform");
return null;
}

/**
* Returns the height of the framebuffer.
*
* @throws UnsupportedOperationException
*/
@Override
public int getFramebufferHeight() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Returns the width of the framebuffer.
*
* @throws UnsupportedOperationException
*/
@Override
public int getFramebufferWidth() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Returns the screen X coordinate of the left edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowXPosition() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Returns the screen Y coordinate of the top edge of the content area.
*
* @throws UnsupportedOperationException
*/
@Override
public int getWindowYPosition() {
throw new UnsupportedOperationException("not implemented yet");
}
}
44 changes: 44 additions & 0 deletions jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,48 @@ public Timer getTimer() {
public com.jme3.opencl.Context getOpenCLContext() {
return clContext;
}

/**
* Returns the height of the framebuffer.
*
* @return the height (in pixels)
*/
@Override
public int getFramebufferHeight() {
int result = Display.getHeight();
return result;
}

/**
* Returns the width of the framebuffer.
*
* @return the width (in pixels)
*/
@Override
public int getFramebufferWidth() {
int result = Display.getWidth();
return result;
}

/**
* Returns the screen X coordinate of the left edge of the content area.
*
* @return the screen X coordinate
*/
@Override
public int getWindowXPosition() {
int result = Display.getX();
return result;
}

/**
* Returns the screen Y coordinate of the top edge of the content area.
*
* @return the screen Y coordinate
*/
@Override
public int getWindowYPosition() {
int result = Display.getY();
return result;
}
}
Loading

0 comments on commit 925ff45

Please sign in to comment.