JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
NewtReparentingKeyAdapter.java
Go to the documentation of this file.
1/**
2 * Copyright 2011, 2019 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.newt.parenting;
29
30import com.jogamp.graph.font.FontScale;
31import com.jogamp.nativewindow.CapabilitiesImmutable;
32import com.jogamp.nativewindow.NativeWindow;
33import com.jogamp.nativewindow.NativeWindowHolder;
34import com.jogamp.newt.Window;
35import com.jogamp.newt.event.KeyEvent;
36import com.jogamp.newt.opengl.GLWindow;
37import com.jogamp.newt.opengl.util.NEWTDemoListener;
38import com.jogamp.opengl.GLAnimatorControl;
39
40/**
41 * Extending demo functionality of {@link NEWTDemoListener}
42 * <ul>
43 * <li>L: Print parent and (child) {@link GLWindow} location</li>
44 * <li>R: Toggel parenting (top-level/child)</li>
45 * </ul>
46 */
48 final NativeWindowHolder winHolder;
49
51 super(glWindow);
52 this.winHolder = winHolder;
53 }
54
55 @Override
56 public void keyPressed(final KeyEvent e) {
57 if( e.isAutoRepeat() || e.isConsumed() ) {
58 return;
59 }
60 if( 0 == e.getModifiers() ) { // all modifiers go to super class ..
61 final int keySymbol = e.getKeySymbol();
62 switch (keySymbol) {
63 case KeyEvent.VK_L:
64 e.setConsumed(true);
67 printlnState("[location]", "Parent "+p0+", NEWT "+p1);
68 break;
69 case KeyEvent.VK_R:
70 e.setConsumed(true);
72 glWindow.invokeOnNewThread(null, false, new Runnable() {
73 @Override
74 public void run() {
75 final java.lang.Thread t = glWindow.setExclusiveContextThread(null);
76 if(glWindow.getParent()==null) {
77 printlnState("[reparent pre - glWin to HOME: child pos "+winHolder.getNativeWindow().getX()+"/"+winHolder.getNativeWindow().getY()+"]");
78 glWindow.reparentWindow(winHolder.getNativeWindow(), -1, -1, 0 /* hints */);
79 } else {
82 printlnState("[reparent pre - glWin to TOP.1] frame ", p0+", glWindow "+p1);
83 glWindow.reparentWindow(null, p1.getX(), p1.getY(), 0 /* hint */);
84 }
85 printlnState("[reparent post]");
89 } } );
90 break;
91 }
92 }
93 super.keyPressed(e);
94 }
95
96 @Override
97 public void setTitle() {
98 setTitle(winHolder.getNativeWindow(), glWindow);
99 }
100 String getNativeWinTitle(final NativeWindow nw) {
101 return "["+nw.getX()+"/"+nw.getY()+" "+nw.getWidth()+"x"+nw.getHeight()+"], pix: "+nw.getSurfaceWidth()+"x"+nw.getSurfaceHeight();
102 }
103 public void setTitle(final NativeWindow nw, final Window win) {
104 final CapabilitiesImmutable chosenCaps = win.getChosenCapabilities();
106 final CapabilitiesImmutable caps = null != chosenCaps ? chosenCaps : reqCaps;
107 final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
108 final float[] sDPI = FontScale.ppmmToPPI( win.getPixelsPerMM(new float[2]) );
109 win.setTitle("GLWindow["+capsA+"], win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]);
110 }
111}
Simple static font scale methods for unit conversions.
Definition: FontScale.java:37
static float[] ppmmToPPI(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
Definition: FontScale.java:105
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final int getModifiers()
Return the modifier bits of this event, e.g.
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
static final short VK_R
See VK_A.
Definition: KeyEvent.java:629
static final short VK_L
See VK_A.
Definition: KeyEvent.java:617
final boolean isConsumed()
Returns true if this events has been consumed, otherwise false.
Definition: NEWTEvent.java:105
final void setConsumed(final boolean consumed)
If consumed is true, this event is marked as consumed, ie.
Definition: NEWTEvent.java:126
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
Point getLocationOnScreen(final Point storage)
Returns the window's top-left client-area position in the screen.
Definition: GLWindow.java:643
final NativeWindow getParent()
Definition: GLWindow.java:282
final ReparentOperation reparentWindow(final NativeWindow newParent, final int x, final int y, final int hints)
Change this window's parent window.
Definition: GLWindow.java:582
final void requestFocus()
Request focus for this native window.
Definition: GLWindow.java:416
void keyPressed(final KeyEvent e)
A key has been pressed, excluding auto-repeat modifier keys.
NewtReparentingKeyAdapter(final NativeWindowHolder winHolder, final GLWindow glWindow)
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.
int getSurfaceWidth()
Returns the width of the client area excluding insets (window decorations) in pixel units.
int getSurfaceHeight()
Returns the height of the client area excluding insets (window decorations) in pixel units.
Accessor interface for implementing classes with ownership of a NativeWindow via an is-a or has-a rel...
NativeWindow getNativeWindow()
Returns the associated NativeWindow of this NativeWindowHolder, which is identical to getNativeSurfac...
Extend the NativeSurface interface with windowing information such as window-handle,...
int getHeight()
Returns the height of the client area excluding insets (window decorations) in window units.
Point getLocationOnScreen(Point point)
Returns the window's top-left client-area position in the screen.
int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
int getX()
Returns the current x position of this window, relative to it's parent.
int getWidth()
Returns the width of the client area excluding insets (window decorations) in window units.
Specifying NEWT's Window functionality:
Definition: Window.java:115
void setTitle(String title)
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
CapabilitiesImmutable getRequestedCapabilities()
Gets an immutable set of requested capabilities.
Thread setExclusiveContextThread(Thread t)
Dedicates this instance's GLContext to the given thread.