Skip to content

Commit

Permalink
Made splash-screen higher resolution.
Browse files Browse the repository at this point in the history
Small Gradle improvements.
  • Loading branch information
renatoathaydes committed Sep 11, 2021
1 parent fb6bf28 commit adcbe1f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
16 changes: 6 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ tasks.withType( JavaCompile ) {

def libs = "${buildDir}/libs"
def image = "${buildDir}/image"
ext.splashImage = "${image}/bin/logfx-logo.png"
ext.splashImage = "${image}/bin/logfx-logo"

task deps {
doLast {
copy {
from configurations.runtimeClasspath
into libs
}
}
task deps( type: Copy ) {
from configurations.runtimeClasspath
into libs
}

task copyShellScriptToImage( type: Copy ) {
Expand All @@ -53,7 +49,7 @@ task jlink( type: Exec ) {
'--module-path', libs,
'--vm=server', // options: client|server|minimal|all
'--add-modules', 'java.base,java.desktop,javafx.controls,jdk.unsupported,jdk.crypto.ec,org.slf4j,' +
'com.athaydes.keepup.core,com.athaydes.keepup.bintray,com.athaydes.logfx',
'com.athaydes.logfx',
'--output', image,
'--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages' ]
def jlink = System.getProperty( 'java.home' ) + '/bin/jlink'
Expand All @@ -63,7 +59,7 @@ task jlink( type: Exec ) {

task packageImage( type: Zip ) {
outputs.upToDateWhen { false }
dependsOn jlink
dependsOn jlink, copyShellScriptToImage
from image
into "logfx"
include '**/*'
Expand Down
2 changes: 1 addition & 1 deletion splash-maker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ dependencies {
task createSplashScreen( type: JavaExec ) {
classpath = sourceSets.main.runtimeClasspath
systemProperty( "java.awt.headless", "true" )
main = 'com.athaydes.logfx.splash.SplashMaker'
mainClass.set( 'com.athaydes.logfx.splash.SplashMaker' )
args rootProject.file( rootProject.splashImage ).absolutePath
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.athaydes.logfx.splash;

import com.athaydes.logfx.ui.AboutLogFXView;
import com.athaydes.logfx.ui.Dialog;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.transform.Transform;
import javafx.stage.Stage;

import javax.imageio.ImageIO;
Expand All @@ -21,27 +26,59 @@ public void start( Stage primaryStage ) {
throw new IllegalStateException( "Wrong number of arguments provided, expected 1, got " + args.size() );
}

var filePrefix = args.get( 0 );
var view = new AboutLogFXView();
var dialog = view.createDialog();

var scales = new double[]{ 1.25, 2.0 };
var suffixes = new String[]{ ".png", "@2x.png" };

Platform.runLater( () -> {
var image = dialog.getBox().snapshot( new SnapshotParameters(), null );
var file = new File( args.get( 0 ) );
if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {
throw new RuntimeException("Not a directory (and cannot be created): " + file.getParentFile());
}
System.out.println( "Writing splash image to " + file.getAbsolutePath() );
try {
ImageIO.write( SwingFXUtils.fromFXImage( image, null ), "png", file );
System.out.println( "Image written to " + file.getAbsolutePath() );
} catch ( IOException e ) {
e.printStackTrace();
System.exit( 1 );
for ( int i = 0; i < scales.length; i++ ) {
var image = createScaledView( dialog, scales[ i ] );
var file = new File( filePrefix + suffixes[ i ] );
if ( !file.getParentFile().mkdirs() && !file.getParentFile().isDirectory() ) {
System.err.println( "Not a directory (and cannot be created): " + file.getParentFile() );
System.exit( 1 );
}
System.out.println( "Writing splash image to " + file.getAbsolutePath() );
try {
ImageIO.write( SwingFXUtils.fromFXImage( image, null ), "png", file );
System.out.println( "Image written to " + file.getAbsolutePath() );
} catch ( IOException e ) {
e.printStackTrace();
System.exit( 1 );
}
}

System.exit( 0 );
} );
}

/**
* Source: https://news.kynosarges.org/2017/02/01/javafx-snapshot-scaling/
*
* @return scaled image
*/
private static Image createScaledView( Dialog dialog, double scale ) {
var node = dialog.getBox();

var image = new WritableImage(
( int ) ( AboutLogFXView.WIDTH * scale ),
( int ) ( AboutLogFXView.HEIGHT * scale ) );

var snapshotParameters = new SnapshotParameters();
snapshotParameters.setTransform( Transform.scale( scale, scale ) );

var result = node.snapshot( snapshotParameters, image );

var view = new ImageView( result );
view.setFitWidth( AboutLogFXView.WIDTH );
view.setFitHeight( AboutLogFXView.HEIGHT );

return view.getImage();
}

public static void main( String[] args ) {
launch( args );
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/athaydes/logfx/ui/AboutLogFXView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
public class AboutLogFXView {

public static final int WIDTH = 500;
public static final int HEIGHT = 350;

VBox createNode() {
VBox contents = new VBox( 25 );
contents.setPrefSize( 500, 300 );
contents.setPrefSize( WIDTH, HEIGHT );
contents.setAlignment( Pos.CENTER );
contents.getStylesheets().add( resourcePath( "css/about.css" ) );

Expand Down

0 comments on commit adcbe1f

Please sign in to comment.
-