Skip to content

Commit 925ff45

Browse files
authored
add 4 getters to JmeContext for screen position and frame-buffer size (jMonkeyEngine#1911)
1 parent 9a2d950 commit 925ff45

File tree

9 files changed

+394
-7
lines changed

9 files changed

+394
-7
lines changed

jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java

+60
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737
import android.content.DialogInterface;
3838
import android.content.pm.ConfigurationInfo;
3939
import android.graphics.PixelFormat;
40+
import android.graphics.Rect;
4041
import android.opengl.GLSurfaceView;
4142
import android.os.Build;
4243
import android.text.InputType;
4344
import android.view.Gravity;
45+
import android.view.SurfaceHolder;
46+
import android.view.SurfaceView;
4447
import android.view.View;
4548
import android.view.ViewGroup.LayoutParams;
4649
import android.widget.EditText;
@@ -494,4 +497,61 @@ public com.jme3.opencl.Context getOpenCLContext() {
494497
logger.warning("OpenCL is not yet supported on android");
495498
return null;
496499
}
500+
501+
/**
502+
* Returns the height of the input surface.
503+
*
504+
* @return the height (in pixels)
505+
*/
506+
@Override
507+
public int getFramebufferHeight() {
508+
Rect rect = getSurfaceFrame();
509+
int result = rect.height();
510+
return result;
511+
}
512+
513+
/**
514+
* Returns the width of the input surface.
515+
*
516+
* @return the width (in pixels)
517+
*/
518+
@Override
519+
public int getFramebufferWidth() {
520+
Rect rect = getSurfaceFrame();
521+
int result = rect.width();
522+
return result;
523+
}
524+
525+
/**
526+
* Returns the screen X coordinate of the left edge of the content area.
527+
*
528+
* @throws UnsupportedOperationException
529+
*/
530+
@Override
531+
public int getWindowXPosition() {
532+
throw new UnsupportedOperationException("not implemented yet");
533+
}
534+
535+
/**
536+
* Returns the screen Y coordinate of the top edge of the content area.
537+
*
538+
* @throws UnsupportedOperationException
539+
*/
540+
@Override
541+
public int getWindowYPosition() {
542+
throw new UnsupportedOperationException("not implemented yet");
543+
}
544+
545+
/**
546+
* Retrieves the dimensions of the input surface. Note: do not modify the
547+
* returned object.
548+
*
549+
* @return the dimensions (in pixels, left and top are 0)
550+
*/
551+
private Rect getSurfaceFrame() {
552+
SurfaceView view = (SurfaceView) androidInput.getView();
553+
SurfaceHolder holder = view.getHolder();
554+
Rect result = holder.getSurfaceFrame();
555+
return result;
556+
}
497557
}

jme3-core/src/main/java/com/jme3/system/JmeContext.java

+31
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,35 @@ public enum Type {
194194
*/
195195
public void destroy(boolean waitFor);
196196

197+
/**
198+
* Returns the height of the framebuffer.
199+
*
200+
* @return the height (in pixels)
201+
* @throws IllegalStateException for a headless or null context
202+
*/
203+
public int getFramebufferHeight();
204+
205+
/**
206+
* Returns the width of the framebuffer.
207+
*
208+
* @return the width (in pixels)
209+
* @throws IllegalStateException for a headless or null context
210+
*/
211+
public int getFramebufferWidth();
212+
213+
/**
214+
* Returns the screen X coordinate of the left edge of the content area.
215+
*
216+
* @return the screen X coordinate
217+
* @throws IllegalStateException for a headless or null context
218+
*/
219+
public int getWindowXPosition();
220+
221+
/**
222+
* Returns the screen Y coordinate of the top edge of the content area.
223+
*
224+
* @return the screen Y coordinate
225+
* @throws IllegalStateException for a headless or null context
226+
*/
227+
public int getWindowYPosition();
197228
}

jme3-core/src/main/java/com/jme3/system/NullContext.java

+40
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,44 @@ public boolean isRenderable() {
266266
public Context getOpenCLContext() {
267267
return null;
268268
}
269+
270+
/**
271+
* Returns the height of the framebuffer.
272+
*
273+
* @throws UnsupportedOperationException
274+
*/
275+
@Override
276+
public int getFramebufferHeight() {
277+
throw new UnsupportedOperationException("null context");
278+
}
279+
280+
/**
281+
* Returns the width of the framebuffer.
282+
*
283+
* @throws UnsupportedOperationException
284+
*/
285+
@Override
286+
public int getFramebufferWidth() {
287+
throw new UnsupportedOperationException("null context");
288+
}
289+
290+
/**
291+
* Returns the screen X coordinate of the left edge of the content area.
292+
*
293+
* @throws UnsupportedOperationException
294+
*/
295+
@Override
296+
public int getWindowXPosition() {
297+
throw new UnsupportedOperationException("null context");
298+
}
299+
300+
/**
301+
* Returns the screen Y coordinate of the top edge of the content area.
302+
*
303+
* @throws UnsupportedOperationException
304+
*/
305+
@Override
306+
public int getWindowYPosition() {
307+
throw new UnsupportedOperationException("null context");
308+
}
269309
}

jme3-desktop/src/main/java/com/jme3/system/AWTContext.java

+39-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
import com.jme3.input.TouchInput;
3939
import com.jme3.opencl.Context;
4040
import com.jme3.renderer.Renderer;
41-
import com.jme3.system.AppSettings;
42-
import com.jme3.system.JmeContext;
43-
import com.jme3.system.JmeSystem;
44-
import com.jme3.system.SystemListener;
45-
import com.jme3.system.Timer;
4641

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

239+
/**
240+
* Returns the height of the framebuffer.
241+
*
242+
* @return the height (in pixels)
243+
*/
244+
@Override
245+
public int getFramebufferHeight() {
246+
return height;
247+
}
248+
249+
/**
250+
* Returns the width of the framebuffer.
251+
*
252+
* @return the width (in pixels)
253+
*/
254+
@Override
255+
public int getFramebufferWidth() {
256+
return width;
257+
}
258+
259+
/**
260+
* Returns the screen X coordinate of the left edge of the content area.
261+
*
262+
* @throws UnsupportedOperationException
263+
*/
264+
@Override
265+
public int getWindowXPosition() {
266+
throw new UnsupportedOperationException("not implemented yet");
267+
}
268+
269+
/**
270+
* Returns the screen Y coordinate of the top edge of the content area.
271+
*
272+
* @throws UnsupportedOperationException
273+
*/
274+
@Override
275+
public int getWindowYPosition() {
276+
throw new UnsupportedOperationException("not implemented yet");
277+
}
244278
}

jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java

+39
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,43 @@ public void restart() {
286286
// only relevant if changing pixel format.
287287
}
288288

289+
/**
290+
* Returns the height of the input panel.
291+
*
292+
* @return the height (in pixels)
293+
*/
294+
@Override
295+
public int getFramebufferHeight() {
296+
return inputSource.getHeight();
297+
}
298+
299+
/**
300+
* Returns the width of the input panel.
301+
*
302+
* @return the width (in pixels)
303+
*/
304+
@Override
305+
public int getFramebufferWidth() {
306+
return inputSource.getWidth();
307+
}
308+
309+
/**
310+
* Returns the screen X coordinate of the left edge of the input panel.
311+
*
312+
* @return the screen X coordinate
313+
*/
314+
@Override
315+
public int getWindowXPosition() {
316+
return inputSource.getX();
317+
}
318+
319+
/**
320+
* Returns the screen Y coordinate of the top edge of the input panel.
321+
*
322+
* @return the screen Y coordinate
323+
*/
324+
@Override
325+
public int getWindowYPosition() {
326+
return inputSource.getY();
327+
}
289328
}

jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java

+40
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,44 @@ public Context getOpenCLContext() {
227227
logger.warning("OpenCL not yet supported on this platform");
228228
return null;
229229
}
230+
231+
/**
232+
* Returns the height of the framebuffer.
233+
*
234+
* @throws UnsupportedOperationException
235+
*/
236+
@Override
237+
public int getFramebufferHeight() {
238+
throw new UnsupportedOperationException("not implemented yet");
239+
}
240+
241+
/**
242+
* Returns the width of the framebuffer.
243+
*
244+
* @throws UnsupportedOperationException
245+
*/
246+
@Override
247+
public int getFramebufferWidth() {
248+
throw new UnsupportedOperationException("not implemented yet");
249+
}
250+
251+
/**
252+
* Returns the screen X coordinate of the left edge of the content area.
253+
*
254+
* @throws UnsupportedOperationException
255+
*/
256+
@Override
257+
public int getWindowXPosition() {
258+
throw new UnsupportedOperationException("not implemented yet");
259+
}
260+
261+
/**
262+
* Returns the screen Y coordinate of the top edge of the content area.
263+
*
264+
* @throws UnsupportedOperationException
265+
*/
266+
@Override
267+
public int getWindowYPosition() {
268+
throw new UnsupportedOperationException("not implemented yet");
269+
}
230270
}

jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java

+44
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,48 @@ public Timer getTimer() {
519519
public com.jme3.opencl.Context getOpenCLContext() {
520520
return clContext;
521521
}
522+
523+
/**
524+
* Returns the height of the framebuffer.
525+
*
526+
* @return the height (in pixels)
527+
*/
528+
@Override
529+
public int getFramebufferHeight() {
530+
int result = Display.getHeight();
531+
return result;
532+
}
533+
534+
/**
535+
* Returns the width of the framebuffer.
536+
*
537+
* @return the width (in pixels)
538+
*/
539+
@Override
540+
public int getFramebufferWidth() {
541+
int result = Display.getWidth();
542+
return result;
543+
}
544+
545+
/**
546+
* Returns the screen X coordinate of the left edge of the content area.
547+
*
548+
* @return the screen X coordinate
549+
*/
550+
@Override
551+
public int getWindowXPosition() {
552+
int result = Display.getX();
553+
return result;
554+
}
555+
556+
/**
557+
* Returns the screen Y coordinate of the top edge of the content area.
558+
*
559+
* @return the screen Y coordinate
560+
*/
561+
@Override
562+
public int getWindowYPosition() {
563+
int result = Display.getY();
564+
return result;
565+
}
522566
}

0 commit comments

Comments
 (0)