From 4b6a5a7a816acb03cc8f1cbb4a9571447f80eef2 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 14 Apr 2023 06:31:04 +0200 Subject: GraphUI Demo FontView01: Use full window size if grid is not otherwise defined and scale group accordingly --- .../jogamp/opengl/demos/graph/ui/FontView01.java | 38 ++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src/demos') 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 c995d1012..67c4f0ca5 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java @@ -59,9 +59,10 @@ public class FontView01 { static GraphUIDemoArgs options = new GraphUIDemoArgs(1280, 720, Region.VBAA_RENDERING_BIT); public static void main(final String[] args) throws IOException { + final int pxPerCell = 50; String fontfilename = null; - int gridWidth = 10; - int gridHeight = 10; + int gridCols = -1; + int gridRows = -1; final int startGlyphID = 0; boolean showUnderline = false; @@ -73,12 +74,12 @@ public class FontView01 { } else if(args[idx[0]].equals("-font")) { idx[0]++; fontfilename = args[idx[0]]; - } else if(args[idx[0]].equals("-gridWidth")) { + } else if(args[idx[0]].equals("-gridCols")) { idx[0]++; - gridWidth = MiscUtils.atoi(args[idx[0]], gridWidth); - } else if(args[idx[0]].equals("-gridHeight")) { + gridCols = MiscUtils.atoi(args[idx[0]], gridCols); + } else if(args[idx[0]].equals("-gridRows")) { idx[0]++; - gridHeight = MiscUtils.atoi(args[idx[0]], gridHeight); + gridRows = MiscUtils.atoi(args[idx[0]], gridRows); } else if(args[idx[0]].equals("-showUnderline")) { showUnderline = true; } @@ -94,14 +95,22 @@ public class FontView01 { font = FontFactory.get( new File( fontfilename ) ); } System.err.println("Font "+font.getFullFamilyName()); - System.err.println("Glyph Grid "+gridWidth+" x "+gridHeight); final GLProfile reqGLP = GLProfile.get(options.glProfileName); System.err.println("GLProfile: "+reqGLP); - final float gridSize = gridWidth > gridHeight ? 1f/gridWidth : 1f/gridHeight; - final Group grid = new Group(new GridLayout(gridHeight, gridSize, gridSize, new Padding(gridSize*0.1f, gridSize*0.1f))); - final int cellCount = gridWidth * gridHeight; + if( 0 >= gridCols ) { + gridCols = options.surface_width / pxPerCell; + } + if( 0 >= gridRows ) { + gridRows = options.surface_height / pxPerCell; + } + final int cellCount = gridCols * gridRows; + final float gridSize = gridCols > gridRows ? 1f/gridCols : 1f/gridRows; + System.err.println("Grid "+gridCols+" x "+gridRows+", "+cellCount+" cells, gridSize "+gridSize); + + final Group grid = new Group(new GridLayout(gridCols, gridSize, gridSize, new Padding(gridSize*0.1f, gridSize*0.1f))); + for(int i=0; i gridBox.getHeight() ? gridBox.getWidth() : gridBox.getHeight(); - final float sgxy = sxy / gxy; + final float sgxy; + if( sceneBox.getWidth() > sceneBox.getHeight() ) { + sgxy = sceneBox.getHeight() / gridBox.getHeight(); + } else { + sgxy = sceneBox.getWidth() / gridBox.getWidth(); + } grid.scale(sgxy, sgxy, 1f); grid.moveTo(sceneBox.getMinX(), sceneBox.getMinY(), 0f); scene.addShape(grid); // late add at correct position and size -- cgit v1.2.3