28package com.jogamp.newt.opengl.util;
30import java.net.URLConnection;
31import java.util.ArrayList;
34import com.jogamp.common.util.IOUtil;
35import com.jogamp.graph.font.FontScale;
36import com.jogamp.nativewindow.CapabilitiesImmutable;
37import com.jogamp.nativewindow.ScalableSurface;
38import com.jogamp.newt.Window;
39import com.jogamp.newt.Display;
40import com.jogamp.newt.Display.PointerIcon;
41import com.jogamp.newt.event.KeyEvent;
42import com.jogamp.newt.event.KeyListener;
43import com.jogamp.newt.event.MouseEvent;
44import com.jogamp.newt.event.MouseListener;
45import com.jogamp.newt.event.WindowAdapter;
46import com.jogamp.newt.event.WindowEvent;
47import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.FPSCounter;
49import com.jogamp.opengl.GL;
50import com.jogamp.opengl.GLAnimatorControl;
51import com.jogamp.opengl.GLAutoDrawable;
52import com.jogamp.opengl.GLDrawable;
53import com.jogamp.opengl.GLRunnable;
54import com.jogamp.opengl.util.Gamma;
55import com.jogamp.opengl.util.PNGPixelRect;
57import jogamp.newt.driver.PNGIcon;
86 int pointerIconIdx = 0;
88 float brightness = 0f;
90 boolean confinedFixedCenter =
false;
98 this.glWindow = glWin;
99 this.pointerIcons = pointerIcons;
129 glWindow.invokeOnCurrentThread(
new Runnable() {
144 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
154 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
164 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
167 if(
null != pointerIcons ) {
171 if( pointerIconIdx >= pointerIcons.length ) {
175 newPI=pointerIcons[pointerIconIdx++];
184 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
195 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
214 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
217 final float newGamma = gamma + ( e.
isShiftDown() ? -0.1f : 0.1f );
218 System.err.println(
"[set gamma]: "+gamma+
" -> "+newGamma);
226 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
236 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
245 }
else if( !confine ) {
252 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
259 final boolean horz, vert;
277 printlnState(
"[set maximize pre]",
"max[vert "+vert+
", horz "+horz+
"]");
279 printlnState(
"[set maximize post]",
"max[vert "+vert+
", horz "+horz+
"]");
284 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
294 System.err.println(
"QUIT Key "+Thread.currentThread());
295 quitAdapterShouldQuit =
true;
300 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
310 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
324 final GL gl = drawable.
getGL();
328 case 0: i = -1;
break;
329 case -1: i = 1;
break;
330 case 1: i = 0;
break;
331 default: i = 1;
break;
342 System.err.println(
"Swap Interval: "+_i+
" -> "+i+
" -> "+gl.
getSwapInterval());
347 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
358 java.lang.Thread.sleep(5000);
359 }
catch (
final InterruptedException e) {
371 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
382 final float[] reqSurfacePixelScale;
388 System.err.println(
"[set PixelScale pre]: had "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" -> req "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]);
392 System.err.println(
"[set PixelScale post]: "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" (had) -> "+
393 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
394 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
395 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
403 confinedFixedCenter = v;
424 private void mouseCenterWarp(
final MouseEvent e) {
444 private boolean quitAdapterShouldQuit =
false;
445 private boolean quitAdapterEnabled =
false;
446 private boolean quitAdapterEnabled2 =
true;
449 quitAdapterEnabled2 =
false;
453 quitAdapterEnabled2 =
true;
457 public boolean shouldQuit() {
return quitAdapterShouldQuit; }
458 public void doQuit() { quitAdapterShouldQuit=
true; }
462 if( quitAdapterEnabled && quitAdapterEnabled2 ) {
463 System.err.println(
"QUIT Window "+Thread.currentThread());
464 quitAdapterShouldQuit =
true;
484 ", scale[min "+minSurfacePixelScale[0]+
"x"+minSurfacePixelScale[1]+
", max "+
485 maxSurfacePixelScale[0]+
"x"+maxSurfacePixelScale[1]+
", req "+
486 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" -> has "+
487 hasSurfacePixelScale[0]+
"x"+hasSurfacePixelScale[1]+
"]");
491 final List<PointerIcon> pointerIcons =
new ArrayList<PointerIcon>();
496 final IOUtil.ClassResources res =
new IOUtil.ClassResources(
new String[] {
"jogamp/newt/assets/cross-grey-alpha-16x16.png" }, disp.getClass().getClassLoader(),
null);
499 pointerIcons.add(_pointerIcon);
500 System.err.printf(
"Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.
toString());
501 }
catch (
final Exception e) {
502 System.err.println(e.getMessage());
507 final IOUtil.ClassResources res =
new IOUtil.ClassResources(
new String[] {
"jogamp/newt/assets/pointer-grey-alpha-16x24.png" }, disp.getClass().getClassLoader(),
null);
510 pointerIcons.add(_pointerIcon);
511 System.err.printf(
"Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.
toString());
512 }
catch (
final Exception e) {
513 System.err.println(e.getMessage());
518 final IOUtil.ClassResources res =
new IOUtil.ClassResources(
new String[] {
"arrow-red-alpha-64x64.png" }, disp.getClass().getClassLoader(),
null);
521 pointerIcons.add(_pointerIcon);
522 System.err.printf(
"Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.
toString());
523 }
catch (
final Exception e) {
524 System.err.println(e.getMessage());
529 final IOUtil.ClassResources res =
new IOUtil.ClassResources(
new String[] {
"arrow-blue-alpha-64x64.png" }, disp.getClass().getClassLoader(),
null);
532 pointerIcons.add(_pointerIcon);
533 System.err.printf(
"Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.
toString());
534 }
catch (
final Exception e) {
535 System.err.println(e.getMessage());
538 if( PNGIcon.isAvailable() ) {
540 final IOUtil.ClassResources res =
new IOUtil.ClassResources(
new String[] {
"jogamp-pointer-64x64.png" }, disp.getClass().getClassLoader(),
null);
542 final URLConnection urlConn = res.resolve(0);
543 if(
null != urlConn ) {
545 System.err.printf(
"Create PointerIcon #%02d: %s%n", pointerIcons.size()+1, image.
toString());
547 pointerIcons.add(_pointerIcon);
548 System.err.printf(
"Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.
toString());
550 }
catch (
final Exception e) {
551 System.err.println(e.getMessage());
555 return pointerIcons.toArray(
new PointerIcon[pointerIcons.size()]);
Simple static font scale methods for unit conversions.
static float[] ppmmToPPI(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
abstract void createNative()
Manual trigger the native creation, if it is not done yet.
abstract PointerIcon createPointerIcon(final IOUtil.ClassResources pngResource, final int hotX, final int hotY)
Returns the newly created PointerIcon or null if not implemented on platform.
abstract Display getDisplay()
static final short VK_W
See VK_A.
static final short VK_A
VK_A thru VK_Z are the same as Capital UTF16/ASCII 'A' thru 'Z' (0x41 - 0x5A)
static final short VK_C
See VK_A.
static final short VK_M
See VK_A.
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
static final short VK_P
See VK_A.
static final short VK_SPACE
Constant for the SPACE function key.
static final short VK_D
See VK_A.
static final short VK_S
See VK_A.
static final short VK_R
See VK_A.
static final short VK_Q
See VK_A.
static final short VK_V
See VK_A.
static final short VK_J
See VK_A.
static final short VK_F
See VK_A.
static final short VK_I
See VK_A.
static final short VK_X
See VK_A.
static final short VK_G
See VK_A.
static final short VK_B
See VK_A.
Pointer event of type PointerType.
final int getPointerCount()
See details for multiple-pointer events.
final short getClickCount()
final boolean isConsumed()
Returns true if this events has been consumed, otherwise false.
final void setConsumed(final boolean consumed)
If consumed is true, this event is marked as consumed, ie.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final float[] getMaximumSurfaceScale(final float[] result)
Returns the maximum pixel scale of the associated NativeSurface.
final void warpPointer(final int x, final int y)
Moves the pointer to x/y relative to this window's origin in pixel units.
final void setPointerIcon(final PointerIcon pi)
final String getStateMaskString()
Returns a string representation of the current state mask.
final boolean isFullscreen()
final CapabilitiesImmutable getRequestedCapabilities()
Gets an immutable set of requested capabilities.
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setPointerVisible(final boolean mouseVisible)
Makes the pointer visible or invisible.
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setTitle(final String title)
final boolean isAlwaysOnBottom()
final float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
final boolean isResizable()
final void setAlwaysOnTop(final boolean value)
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.
final void setMaximized(final boolean horz, final boolean vert)
final int getX()
Returns the current x position of this window, relative to it's parent.
final boolean isAlwaysOnTop()
final boolean isUndecorated()
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
final void setAlwaysOnBottom(final boolean value)
final boolean isVisible()
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final PointerIcon getPointerIcon()
Returns the current PointerIcon, which maybe null for the default.
final Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
final boolean isPointerConfined()
final boolean isMaximizedHorz()
final void setSticky(final boolean value)
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final void setResizable(final boolean value)
final boolean isPointerVisible()
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void setUndecorated(final boolean value)
final boolean isMaximizedVert()
final boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
final float[] getMinimumSurfaceScale(final float[] result)
Returns the minimum pixel scale of the associated NativeSurface.
final void confinePointer(final boolean grab)
Confine the pointer to this window, ie.
NEWT GLWindow Demo functionality.
void printlnState(final String prelude)
void keyReleased(final KeyEvent e)
A key has been released, excluding auto-repeat modifier keys.
void mouseEntered(final MouseEvent e)
Only generated for PointerType#Mouse.
static void setTitle(final GLWindow win)
static PointerIcon[] createPointerIcons(final Display disp)
void mouseExited(final MouseEvent e)
Only generated for PointerType#Mouse.
void mousePressed(final MouseEvent e)
void quitAdapterEnable(final boolean v)
void printlnState(final String prelude, final String post)
void mouseMoved(final MouseEvent e)
void mouseReleased(final MouseEvent e)
void keyPressed(final KeyEvent e)
A key has been pressed, excluding auto-repeat modifier keys.
NEWTDemoListener(final GLWindow glWin)
Creates a new instance with createPointerIcons(Display) default pointer icons.
void windowDestroyNotify(final WindowEvent e)
Window destruction has been requested.
void mouseDragged(final MouseEvent e)
void mouseWheelMoved(final MouseEvent e)
Traditional event name originally produced by a mouse pointer type.
NEWTDemoListener(final GLWindow glWin, final PointerIcon[] pointerIcons)
Creates a new instance with given pointer icons, which are not used if null.
void mouseClicked(final MouseEvent e)
void setConfinedFixedCenter(final boolean v)
Provides convenient wrapper for GLDrawableFactory control over individual display's gamma,...
static boolean setDisplayGamma(final GLDrawable drawable, final float gamma, final float brightness, final float contrast)
Convenient wrapper for GLDrawableFactory#setDisplayGamma(com.jogamp.nativewindow.NativeSurface,...
static PNGPixelRect read(final InputStream in, final PixelFormat ddestFmt, final boolean destDirectBuffer, final int destMinStrideInBytes, final boolean destIsGLOriented)
Reads a PNG image from the specified InputStream.
Specifies an immutable set of capabilities that a window's rendering context must support,...
boolean isBackgroundOpaque()
Returns whether an opaque or translucent surface is requested, supported or chosen.
Adding mutable surface pixel scale property to implementing class, usually to a NativeSurface impleme...
static final float IDENTITY_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in same pixel- and window-units.
static final float AUTOMAX_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in maximum platform dependent pixel-scale,...
Native PointerIcon handle.
Listener for MouseEvents.
void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...
boolean resume()
Resumes animation if paused.
boolean pause()
Pauses this animator.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
GLAnimatorControl getAnimator()
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
int getSwapInterval()
Return the current swap interval.