diff options
author | Sven Göthel <[email protected]> | 2024-02-05 12:20:44 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-05 12:20:44 +0100 |
commit | 6ec212e0348fc9028e2afc6a298c49890566bf2d (patch) | |
tree | fb991e7bc93fab31a985896355719352f4dbe1ae /src | |
parent | 347739f9589b1f846e2a0db33b554ff34b2ce984 (diff) |
Bug 805: GraphUI Demos: Adopt changes to FontView01 + UIMediaGrid01, dropping UIMediaGrid00
Diffstat (limited to 'src')
3 files changed, 43 insertions, 320 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java index 2e7d3c6e3..4839f6a83 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java @@ -56,7 +56,6 @@ import com.jogamp.graph.ui.shapes.GlyphShape; import com.jogamp.graph.ui.shapes.Label; import com.jogamp.graph.ui.shapes.Rectangle; import com.jogamp.graph.ui.widgets.RangeSlider; -import com.jogamp.graph.ui.widgets.RangeSlider.SliderListener; import com.jogamp.graph.ui.widgets.RangedGroup; import com.jogamp.graph.ui.widgets.RangedGroup.SliderParam; import com.jogamp.math.FloatUtil; @@ -219,7 +218,7 @@ public class FontView01 { System.err.println("GlyphGrid[pgsz "+glyphGridSize+", totsz "+glyphGridTotalSize+", cellSz "+glyphGridCellSize+"]"); final Group mainView; - final Shape.MouseGestureListener glyphMouseListener; + final Shape.PointerListener glyphPointerListener; { final Group glyphShapeBox = new Group( new BoxLayout( 1f, 1f, Alignment.FillCenter, new Margin(0.01f) ) ); final Group glyphShapeHolder = new Group(); @@ -233,50 +232,39 @@ public class FontView01 { glyphInfoBox.addShape(glyphInfo); glyphInfoBox.setRelayoutOnDirtyShapes(false); // avoid group re-validate on info text changes - glyphMouseListener = new Shape.MouseGestureAdapter() { - private void handleEvent(final MouseEvent e) { - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - // System.err.println("ShapeEvent "+shapeEvent); - final GlyphShape g0 = getGlyphShape(shapeEvent.shape); - - e.setConsumed(true); - - // Selected Glyph g0 - final boolean doScreenshot = e.isControlDown() && e.getButtonDownCount() > 0; - scene.invoke(false, (final GLAutoDrawable d) -> { - // Handle old one - if( 1 == glyphShapeHolder.getShapeCount() ) { - final GlyphShape old = (GlyphShape) glyphShapeHolder.getShapeByIdx(0); - if( null != old ) { - if( !doScreenshot && old.getGlyph().getCodepoint() == g0.getGlyph().getCodepoint() ) { - // System.err.println("GlyphShape Same: "+old); - return true; // abort - no change - } else { - glyphShapeHolder.removeShape(old); - } + glyphPointerListener = (final Shape s, final Vec3f pos, final MouseEvent e) -> { + // System.err.println("ShapeEvent "+shapeEvent); + final GlyphShape g0 = getGlyphShape(s); + + e.setConsumed(true); + + // Selected Glyph g0 + final boolean doScreenshot = e.isControlDown() && e.getButtonDownCount() > 0; + scene.invoke(false, (final GLAutoDrawable d) -> { + // Handle old one + if( 1 == glyphShapeHolder.getShapeCount() ) { + final GlyphShape old = (GlyphShape) glyphShapeHolder.getShapeByIdx(0); + if( null != old ) { + if( !doScreenshot && old.getGlyph().getCodepoint() == g0.getGlyph().getCodepoint() ) { + // System.err.println("GlyphShape Same: "+old); + return true; // abort - no change } else { - // System.err.println("GlyphShape Old: Null"); + glyphShapeHolder.removeShape(old); } } else { - // System.err.println("GlyphShape Old: None"); + // System.err.println("GlyphShape Old: Null"); } - // New Glyph - glyphShapeHolder.addShape(g0); - setGlyphInfo(fontStatus, glyphInfo, g0.getGlyph()); - if( doScreenshot ) { - printScreenOnGLThread(scene, window.getChosenGLCapabilities(), font, g0.getGlyph().getCodepoint()); - } - return true; - }); - } - @Override - public void mouseMoved(final MouseEvent e) { - handleEvent(e); - } - @Override - public void mousePressed(final MouseEvent e) { - handleEvent(e); - } + } else { + // System.err.println("GlyphShape Old: None"); + } + // New Glyph + glyphShapeHolder.addShape(g0); + setGlyphInfo(fontStatus, glyphInfo, g0.getGlyph()); + if( doScreenshot ) { + printScreenOnGLThread(scene, window.getChosenGLCapabilities(), font, g0.getGlyph().getCodepoint()); + } + return true; + }); }; final Group glyphInfoView = new Group(new GridLayout(2, 0f, 0f, Alignment.None)); @@ -285,7 +273,7 @@ public class FontView01 { final Group glyphGrid = new Group(new GridLayout(gridDim.columns, glyphGridCellSize*0.9f, glyphGridCellSize*0.9f, Alignment.FillCenter, new Gap(glyphGridCellSize*0.1f))); glyphGrid.setInteractive(true).setDragAndResizable(false).setToggleable(false).setName("GlyphGrid"); - addGlyphs(reqCaps.getGLProfile(), font, glyphGrid, gridDim, showUnderline, showLabel, fontStatus, fontInfo, glyphMouseListener); + addGlyphs(reqCaps.getGLProfile(), font, glyphGrid, gridDim, showUnderline, showLabel, fontStatus, fontInfo, glyphPointerListener); glyphGrid.setRelayoutOnDirtyShapes(false); // avoid group re-validate to ease load in Group.isShapeDirty() w/ thousands of glyphs if( VERBOSE_UI ) { glyphGrid.validate(reqCaps.getGLProfile()); @@ -303,15 +291,12 @@ public class FontView01 { new SliderParam( new Vec2f(glyphGridCellSize/4f, glyphGridSize.y()), glyphGridCellSize/10f, true ) ); glyphView.getVertSlider().setColor(0.3f, 0.3f, 0.3f, 0.7f).setName("GlyphView"); if( VERBOSE_UI ) { - glyphView.getVertSlider().addSliderListener(new SliderListener() { - @Override - public void dragged(final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct) { - final Vec2f minmax = w.getMinMax(); - final float row_f = val / glyphGridCellSize; - System.err.println("VertSlider: row["+row_f+".."+(row_f+gridDim.rowsPerPage-1)+"]/"+gridDim.rows+ - ", val["+old_val+" -> "+val+"]/"+minmax.y()+", pct["+(100*old_val_pct)+"% -> "+(100*val_pct)+"%], cellSz "+glyphGridCellSize); - System.err.println("VertSlider: "+w.getDescription()); - } + glyphView.getVertSlider().addSliderListener((final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct) -> { + final Vec2f minmax = w.getMinMax(); + final float row_f = val / glyphGridCellSize; + System.err.println("VertSlider: row["+row_f+".."+(row_f+gridDim.rowsPerPage-1)+"]/"+gridDim.rows+ + ", val["+old_val+" -> "+val+"]/"+minmax.y()+", pct["+(100*old_val_pct)+"% -> "+(100*val_pct)+"%], cellSz "+glyphGridCellSize); + System.err.println("VertSlider: "+w.getDescription()); }); } glyphView.getVertSlider().receiveKeyEvents(glyphGrid); @@ -505,7 +490,7 @@ public class FontView01 { */ static void addGlyphs(final GLProfile glp, final Font font, final Group sink, final GridDim gridDim, final boolean showUnderline, final boolean showLabel, - final Font fontStatus, final Font fontInfo, final Shape.MouseGestureListener glyphMouseListener) { + final Font fontStatus, final Font fontInfo, final Shape.PointerListener glyphPointerListener) { final AABBox tmpBox = new AABBox(); final long t0 = Clock.currentNanos(); @@ -532,7 +517,7 @@ public class FontView01 { } c1.addShape( c0 ); - c1.addMouseListener(glyphMouseListener); + c1.onHover(glyphPointerListener); sink.receiveKeyEvents(c1); // sink.receiveMouseEvents(c1); c1.setToolTip( new TooltipShape(new Vec4f(1, 1, 1, 1), new Vec4f(0, 0, 0, 1), 0.01f, diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIMediaGrid00.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIMediaGrid00.java deleted file mode 100644 index fec507d3c..000000000 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIMediaGrid00.java +++ /dev/null @@ -1,258 +0,0 @@ -/** - * Copyright 2010-2023 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package com.jogamp.opengl.demos.graph.ui; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.jogamp.common.net.Uri; -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.font.Font; -import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.font.FontScale; -import com.jogamp.graph.ui.Group; -import com.jogamp.graph.ui.Scene; -import com.jogamp.graph.ui.Shape; -import com.jogamp.graph.ui.layout.Alignment; -import com.jogamp.graph.ui.layout.Gap; -import com.jogamp.graph.ui.layout.GridLayout; -import com.jogamp.graph.ui.shapes.Button; -import com.jogamp.graph.ui.shapes.MediaButton; -import com.jogamp.graph.ui.shapes.Rectangle; -import com.jogamp.graph.ui.widgets.MediaPlayer; -import com.jogamp.math.Vec2i; -import com.jogamp.math.Vec3f; -import com.jogamp.math.geom.AABBox; -import com.jogamp.newt.event.KeyAdapter; -import com.jogamp.newt.event.KeyEvent; -import com.jogamp.newt.event.MouseEvent; -import com.jogamp.newt.event.WindowAdapter; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.GL; -import com.jogamp.opengl.GLCapabilities; -import com.jogamp.opengl.GLCapabilitiesImmutable; -import com.jogamp.opengl.GLProfile; -import com.jogamp.opengl.demos.util.CommandlineOptions; -import com.jogamp.opengl.demos.util.MiscUtils; -import com.jogamp.opengl.util.Animator; -import com.jogamp.opengl.util.av.GLMediaPlayer; -import com.jogamp.opengl.util.av.GLMediaPlayerFactory; - -import jogamp.graph.ui.TreeTool; - -/** - * MediaButtons in a grid, filled by media files from a directory in different aspect ratios - */ -public class UIMediaGrid00 { - static CommandlineOptions options = new CommandlineOptions(1920, 1080, Region.VBAA_RENDERING_BIT); - - public static int aid = GLMediaPlayer.STREAM_ID_AUTO; - public static boolean letterBox = true; - - public static void main(final String[] args) throws IOException { - final List<Uri> mediaFiles = new ArrayList<Uri>(); - if( 0 != args.length ) { - final int[] idx = { 0 }; - for (idx[0] = 0; idx[0] < args.length; ++idx[0]) { - if( options.parse(args, idx) ) { - continue; - } else if (args[idx[0]].equals("-file")) { - idx[0]++; - final Uri u = Uri.tryUriOrFile( args[idx[0]] ); - if( null != u ) { - mediaFiles.add(u); - } - } else if(args[idx[0]].equals("-aid")) { - idx[0]++; - aid = MiscUtils.atoi(args[idx[0]], aid); - } else if(args[idx[0]].equals("-zoom")) { - letterBox = false; - } - } - } - System.err.println(options); - System.err.println("aid "+aid); - System.err.println("letterBox "+letterBox); - - if( 0 == mediaFiles.size() ) { - System.err.println("No media files, exit."); - return; - } - for(final Uri uri : mediaFiles) { - System.err.println("- "+uri); - } - final Vec2i gridDim = new Vec2i(4, mediaFiles.size()); - - final GLCapabilities reqCaps = options.getGLCaps(); - System.out.println("Requested: " + reqCaps); - - final Animator animator = new Animator(0 /* w/o AWT */); - animator.setUpdateFPSFrames(1*60, null); // System.err); - final GLWindow window = GLWindow.create(reqCaps); - window.setSize(options.surface_width, options.surface_height); - window.setVisible(true); - System.out.println("Chosen: " + window.getChosenGLCapabilities()); - window.setTitle(UIMediaGrid00.class.getSimpleName()+": "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight()); - window.addWindowListener(new WindowAdapter() { - @Override - public void windowResized(final WindowEvent e) { - window.setTitle(UIMediaGrid00.class.getSimpleName()+": "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight()); - } - @Override - public void windowDestroyNotify(final WindowEvent e) { - animator.stop(); - } - }); - animator.add(window); - - final Scene scene = new Scene(options.graphAASamples); - scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - scene.setPMvCullingEnabled(true); - - scene.attachInputListenerTo(window); - window.addGLEventListener(scene); - - - final float[] ppmm = window.getPixelsPerMM(new float[2]); - { - final float[] dpi = FontScale.ppmmToPPI( new float[] { ppmm[0], ppmm[1] } ); - System.err.println("DPI "+dpi[0]+" x "+dpi[1]+", "+ppmm[0]+" x "+ppmm[1]+" pixel/mm"); - - final float[] hasSurfacePixelScale1 = window.getCurrentSurfaceScale(new float[2]); - System.err.println("HiDPI PixelScale: "+hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)"); - } - final Group mediaGrid; - { - final float cellWidth = 1f; - final float cellHeight = 1f; - mediaGrid = new Group(new GridLayout(gridDim.x(), cellWidth*0.9f, cellHeight*0.9f, Alignment.FillCenter, new Gap(cellHeight*0.1f, cellWidth*0.1f))); - mediaGrid.setName("MediaGrid"); - mediaGrid.setRelayoutOnDirtyShapes(false); - } - addMedia(scene, reqCaps.getGLProfile(), mediaGrid, mediaFiles); - mediaGrid.validate(reqCaps.getGLProfile()); - System.err.println("MediaGrid "+mediaGrid); - System.err.println("MediaGrid "+mediaGrid.getLayout()); - - final Group mainGrid = new Group(new GridLayout(1, 0f, 0f, Alignment.None)); - mainGrid.setName("MainGrid"); - mainGrid.addShape(mediaGrid); - scene.addShape(mainGrid); - - window.addKeyListener(new KeyAdapter() { - @Override - public void keyReleased(final KeyEvent e) { - final short keySym = e.getKeySymbol(); - if( keySym == KeyEvent.VK_S ) { - printScreenOnGLThread(scene, window.getChosenGLCapabilities()); - } else if( keySym == KeyEvent.VK_DOWN ) { - } else if( keySym == KeyEvent.VK_PAGE_DOWN ) { - } else if( keySym == KeyEvent.VK_UP ) { - } else if( keySym == KeyEvent.VK_PAGE_UP ) { - } else if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) { - MiscUtils.destroyWindow(window); - } - } - }); - - animator.start(); - scene.waitUntilDisplayed(); - { - final AABBox sceneBox = scene.getBounds(); - final AABBox mainGridBox = mainGrid.getBounds(); - final float sx = sceneBox.getWidth() / mainGridBox.getWidth(); - final float sy = sceneBox.getHeight() / mainGridBox.getHeight(); - final float sxy = Math.min(sx, sy); - System.err.println("SceneBox "+sceneBox); - System.err.println("MainGridBox "+mainGridBox); - System.err.println("scale sx "+sx+", sy "+sy+", sxy "+sxy); - // scale, moveTo origin bottom-left, then move up to top-left corner. - mainGrid.scale(sxy, sxy, 1f).moveTo(sceneBox.getLow()).move(0, sceneBox.getHeight()-mainGridBox.getHeight()*sxy, 0); - } - printScreenOnGLThread(scene, window.getChosenGLCapabilities()); - // stay open .. - } - static void printScreenOnGLThread(final Scene scene, final GLCapabilitiesImmutable caps) { - scene.screenshot(true, scene.nextScreenshotFile(null, UIMediaGrid00.class.getSimpleName(), options.renderModes, caps, "media")); - } - - - static void addMedia(final Scene scene, final GLProfile glp, final Group grid, final List<Uri> mediaFiles) { - final float zoomSize = 0.95f; - for(final Uri medium : mediaFiles) { - final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault(); - if( printNativeInfoOnce ) { - mPlayer.printNativeInfo(System.err); - printNativeInfoOnce = false; - } - // mPlayer.setTextureMinMagFilter( new int[] { GL.GL_NEAREST, GL.GL_NEAREST } ); - mPlayer.setTextureMinMagFilter( new int[] { GL.GL_LINEAR, GL.GL_LINEAR } ); - mPlayer.setTextureUnit(1); - - final List<Shape> customCtrls = new ArrayList<Shape>(); - { - final Font fontSymbols = FontFactory.getSymbolsFont(); - if( null == fontSymbols ) { - grid.addShape( new Rectangle(options.renderModes, 16f/9f, 1, 0.10f) ); - return; - } - final Button button = new Button(options.renderModes, fontSymbols, - fontSymbols.getUTF16String("reset_tv"), MediaPlayer.CtrlButtonWidth, MediaPlayer.CtrlButtonHeight, scene.getZEpsilon(16)); - button.setName("reset"); - button.setSpacing(MediaPlayer.SymSpacing, MediaPlayer.FixedSymSize).setPerp().setColor(MediaPlayer.CtrlCellCol); - button.onClicked((final Shape s0, final Vec3f pos, final MouseEvent e) -> { - TreeTool.forAll(scene, (final Shape s1) -> { - System.err.println("- "+s1.getName()); - if( s1 instanceof MediaButton ) { - final MediaButton mb = (MediaButton)s1; - final GLMediaPlayer mp = mb.getGLMediaPlayer(); - mp.seek(0); - mp.setPlaySpeed(1f); - mp.setAudioVolume( 0f ); - } - if( s1.getName().equals("muteLabel") ) { - s1.setVisible(true); - } - if( s1.getName().equals("MediaGrid") ) { - s1.markShapeDirty(); - System.err.println("Reset: "+s1); - } - return false; - }); - }); - customCtrls.add(button); - } - grid.addShape( new MediaPlayer(options.renderModes, scene, mPlayer, medium, 16f/9f, letterBox, zoomSize, customCtrls) ); - mPlayer.playStream(medium, GLMediaPlayer.STREAM_ID_AUTO, aid, GLMediaPlayer.STREAM_ID_NONE, GLMediaPlayer.TEXTURE_COUNT_DEFAULT); - } - } - private static boolean printNativeInfoOnce = true; - -} diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIMediaGrid01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIMediaGrid01.java index 9dfbca91c..dd841f3f9 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIMediaGrid01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIMediaGrid01.java @@ -54,7 +54,6 @@ import com.jogamp.graph.ui.shapes.MediaButton; import com.jogamp.graph.ui.shapes.Rectangle; import com.jogamp.graph.ui.widgets.MediaPlayer; import com.jogamp.graph.ui.widgets.RangeSlider; -import com.jogamp.graph.ui.widgets.RangeSlider.SliderListener; import com.jogamp.graph.ui.widgets.RangedGroup; import com.jogamp.graph.ui.widgets.RangedGroup.SliderParam; import com.jogamp.math.Vec2f; @@ -280,13 +279,10 @@ public class UIMediaGrid01 { mediaView.getVertSlider().setColor(0.3f, 0.3f, 0.3f, 0.7f).setName("MediaView"); // mediaView.setRelayoutOnDirtyShapes(false); // avoid group re-validate to ease load in Group.isShapeDirty() w/ thousands of glyphs if( VERBOSE_UI ) { - mediaView.getVertSlider().addSliderListener(new SliderListener() { - @Override - public void dragged(final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct) { - final Vec2f minmax = w.getMinMax(); - final float row_f = val / mediaCellHeight; - System.err.println("VertSlider: row "+row_f+", val["+old_val+" -> "+val+"], pct["+(100*old_val_pct)+"% -> "+(100*val_pct)+"%], minmax "+minmax); - } + mediaView.getVertSlider().addSliderListener((final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct) -> { + final Vec2f minmax = w.getMinMax(); + final float row_f = val / mediaCellHeight; + System.err.println("VertSlider: row "+row_f+", val["+old_val+" -> "+val+"], pct["+(100*old_val_pct)+"% -> "+(100*val_pct)+"%], minmax "+minmax); }); } if( VERBOSE_UI ) { |