From 3e5975306f1b3d0193e90074cf64a9ea3d19a744 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:09:14 +0800 Subject: [PATCH] Update stb and nfd; update generator --- buildSrc/build.gradle.kts | 10 +- buildSrc/src/main/kotlin/GenerateTask.kt | 38 +++++++ .../generator.java-conventions.gradle.kts | 20 ++++ ....java-conventions.gradle.kt => natives.kt} | 26 ++--- generators/build.gradle.kts | 50 +-------- generators/nfd/build.gradle.kts | 12 +++ .../main/java/overrungl/nfd/NFDGenerator.kt | 24 +++++ generators/opengl/build.gradle.kts | 16 +-- .../main/kotlin/overrungl/gen/constants.kt | 3 +- generators/vulkan/build.gradle.kts | 30 ++---- .../src/main/java/overrungl/OverrunGL.java | 4 +- .../src/main/java/overrungl/nfd/NFD.java | 101 ++++++++++++++++-- .../main/java/overrungl/nfd/NFDInternal.java | 14 +++ .../overrungl/nfd/NFDOpenDialogNArgs.java | 40 +++++++ .../overrungl/nfd/NFDOpenDialogU8Args.java | 40 +++++++ .../overrungl/nfd/NFDPickFolderNArgs.java | 37 +++++++ .../overrungl/nfd/NFDPickFolderU8Args.java | 37 +++++++ .../overrungl/nfd/NFDSaveDialogNArgs.java | 41 +++++++ .../overrungl/nfd/NFDSaveDialogU8Args.java | 41 +++++++ .../java/overrungl/nfd/NFDWindowHandle.java | 71 ++++++++++++ settings.gradle.kts | 6 +- 21 files changed, 548 insertions(+), 113 deletions(-) create mode 100644 buildSrc/src/main/kotlin/GenerateTask.kt create mode 100644 buildSrc/src/main/kotlin/generator.java-conventions.gradle.kts rename buildSrc/src/main/kotlin/{myproject.java-conventions.gradle.kt => natives.kt} (78%) create mode 100644 generators/nfd/build.gradle.kts create mode 100644 generators/nfd/src/main/java/overrungl/nfd/NFDGenerator.kt create mode 100644 modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogNArgs.java create mode 100644 modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogU8Args.java create mode 100644 modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderNArgs.java create mode 100644 modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderU8Args.java create mode 100644 modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogNArgs.java create mode 100644 modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogU8Args.java create mode 100644 modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDWindowHandle.java diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index e0a6190b..21126df3 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,9 @@ -plugins { - kotlin("jvm") version "2.0.0" +plugins { `kotlin-dsl` } + +dependencies { + implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:2.0.20") } -repositories { mavenCentral() } +repositories { + mavenCentral() +} diff --git a/buildSrc/src/main/kotlin/GenerateTask.kt b/buildSrc/src/main/kotlin/GenerateTask.kt new file mode 100644 index 00000000..a2fbc6d8 --- /dev/null +++ b/buildSrc/src/main/kotlin/GenerateTask.kt @@ -0,0 +1,38 @@ +import gradle.kotlin.dsl.accessors._8758bf21ec0488ee6f70886b9f0e8378.sourceSets +import org.gradle.api.tasks.JavaExec +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.provideDelegate + +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +/** + * @author squid233 + * @since 0.1.0 + */ +open class GenerateTask : JavaExec() { + private val jdkVersion: String by project + private val jdkEnablePreview: String by project + + init { + classpath(project.sourceSets["main"].runtimeClasspath) + javaLauncher.set(javaToolchainService.launcherFor { + languageVersion.set(JavaLanguageVersion.of(jdkVersion)) + }) + if (jdkEnablePreview.toBoolean()) jvmArgs("--enable-preview") + } +} diff --git a/buildSrc/src/main/kotlin/generator.java-conventions.gradle.kts b/buildSrc/src/main/kotlin/generator.java-conventions.gradle.kts new file mode 100644 index 00000000..b0e7ee4f --- /dev/null +++ b/buildSrc/src/main/kotlin/generator.java-conventions.gradle.kts @@ -0,0 +1,20 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { kotlin("jvm") } + +val jdkVersion: String by rootProject +val kotlinTargetJdkVersion: String by rootProject + +repositories { mavenCentral() } + +tasks.withType { + compilerOptions { jvmTarget.set(JvmTarget.fromTarget(kotlinTargetJdkVersion)) } +} + +tasks.withType { + javaCompiler.set(javaToolchains.compilerFor { + targetCompatibility = kotlinTargetJdkVersion + languageVersion.set(JavaLanguageVersion.of(jdkVersion)) + }) +} diff --git a/buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt b/buildSrc/src/main/kotlin/natives.kt similarity index 78% rename from buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt rename to buildSrc/src/main/kotlin/natives.kt index 33bdd136..27035943 100644 --- a/buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt +++ b/buildSrc/src/main/kotlin/natives.kt @@ -1,19 +1,3 @@ -/* - * MIT License - * - * Copyright (c) 2024 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - enum class NativePlatform( val osFamilyName: String, val osArch: String, @@ -33,6 +17,10 @@ enum class NativePlatform( WIN_ARM64("windows", "arm64", nativeLibPrefix = "", nativeLibSuffix = ".dll"); val classifier = "natives-$classifier" + + companion object { + val enumEntries = values().toList() + } } enum class NativeBinding( @@ -40,9 +28,9 @@ enum class NativeBinding( val basename: String, val platforms: List ) { - GLFW("glfw", "glfw", NativePlatform.entries), - NFD("nfd", "nfd", NativePlatform.entries), - STB("stb", "stb", NativePlatform.entries) + GLFW("glfw", "glfw", NativePlatform.enumEntries), + NFD("nfd", "nfd", NativePlatform.enumEntries), + STB("stb", "stb", NativePlatform.enumEntries), } enum class Artifact( diff --git a/generators/build.gradle.kts b/generators/build.gradle.kts index 47b94120..ee8b8ea9 100644 --- a/generators/build.gradle.kts +++ b/generators/build.gradle.kts @@ -1,49 +1,3 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -/* - * MIT License - * - * Copyright (c) 2024 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -plugins { kotlin("jvm") version "2.0.0" } - -allprojects { - apply(plugin = "org.jetbrains.kotlin.jvm") - - val javaToolchains: JavaToolchainService by extensions - val jdkVersion: String by rootProject - val kotlinTargetJdkVersion: String by rootProject - - repositories { mavenCentral() } - - tasks.withType { - compilerOptions { jvmTarget.set(JvmTarget.fromTarget(kotlinTargetJdkVersion)) } - } - - tasks.withType { - javaCompiler.set(javaToolchains.compilerFor { - targetCompatibility = kotlinTargetJdkVersion - languageVersion.set(JavaLanguageVersion.of(jdkVersion)) - }) - } -} - -subprojects { - val implementation by configurations - - dependencies { - implementation(project(":generators")) - } +plugins { + id("generator.java-conventions") } diff --git a/generators/nfd/build.gradle.kts b/generators/nfd/build.gradle.kts new file mode 100644 index 00000000..f29846ad --- /dev/null +++ b/generators/nfd/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + id("generator.java-conventions") +} + +dependencies { + implementation(project(":generators")) +} + +tasks.register("generate") { + mainClass = "overrungl.nfd.NFDGeneratorKt" + workingDir = project(":nfd").projectDir.resolve("src/main/java/overrungl/nfd") +} diff --git a/generators/nfd/src/main/java/overrungl/nfd/NFDGenerator.kt b/generators/nfd/src/main/java/overrungl/nfd/NFDGenerator.kt new file mode 100644 index 00000000..d55a777a --- /dev/null +++ b/generators/nfd/src/main/java/overrungl/nfd/NFDGenerator.kt @@ -0,0 +1,24 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd + +/** + * @author squid233 + * @since 0.1.0 + */ +fun main() { +} diff --git a/generators/opengl/build.gradle.kts b/generators/opengl/build.gradle.kts index e03062db..03acdcdb 100644 --- a/generators/opengl/build.gradle.kts +++ b/generators/opengl/build.gradle.kts @@ -1,12 +1,12 @@ -val jdkVersion: String by rootProject -val jdkEnablePreview: String by rootProject +plugins { + id("generator.java-conventions") +} + +dependencies { + implementation(project(":generators")) +} -tasks.register("generate") { - classpath(sourceSets["main"].runtimeClasspath) - javaLauncher.set(javaToolchains.launcherFor { - languageVersion.set(JavaLanguageVersion.of(jdkVersion)) - }) - if (jdkEnablePreview.toBoolean()) jvmArgs("--enable-preview") +tasks.register("generate") { mainClass.set("overrungl.opengl.OpenGLGeneratorKt") workingDir = project(":opengl").projectDir.resolve("src/main/java/overrungl/opengl") } diff --git a/generators/src/main/kotlin/overrungl/gen/constants.kt b/generators/src/main/kotlin/overrungl/gen/constants.kt index 7c0b4c50..8a8cb86e 100644 --- a/generators/src/main/kotlin/overrungl/gen/constants.kt +++ b/generators/src/main/kotlin/overrungl/gen/constants.kt @@ -1,4 +1,4 @@ -package overrungl.gen/* +/* * MIT License * * Copyright (c) 2024 Overrun Organization @@ -13,6 +13,7 @@ package overrungl.gen/* * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. */ +package overrungl.gen const val fileHeader = """/* * MIT License diff --git a/generators/vulkan/build.gradle.kts b/generators/vulkan/build.gradle.kts index 946f8e19..7a87ec35 100644 --- a/generators/vulkan/build.gradle.kts +++ b/generators/vulkan/build.gradle.kts @@ -1,28 +1,12 @@ -/* - * MIT License - * - * Copyright (c) 2024 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ +plugins { + id("generator.java-conventions") +} -val jdkVersion: String by rootProject -val jdkEnablePreview: String by rootProject +dependencies { + implementation(project(":generators")) +} -tasks.register("generate") { - classpath(sourceSets["main"].runtimeClasspath) - javaLauncher.set(javaToolchains.launcherFor { - languageVersion.set(JavaLanguageVersion.of(jdkVersion)) - }) - if (jdkEnablePreview.toBoolean()) jvmArgs("--enable-preview") +tasks.register("generate") { mainClass.set("overrungl.vulkan.VulkanGeneratorKt") workingDir = project(":vulkan").projectDir.resolve("src/main/java/overrungl/vulkan") } diff --git a/modules/overrungl.core/src/main/java/overrungl/OverrunGL.java b/modules/overrungl.core/src/main/java/overrungl/OverrunGL.java index dbdefdf4..78da6b30 100644 --- a/modules/overrungl.core/src/main/java/overrungl/OverrunGL.java +++ b/modules/overrungl.core/src/main/java/overrungl/OverrunGL.java @@ -41,11 +41,11 @@ public final class OverrunGL { /** * The version of NFD native libraries. */ - public static final String NFD_VERSION = "1.1.1.0"; + public static final String NFD_VERSION = "1.2.1.0"; /** * The version of STB native libraries. */ - public static final String STB_VERSION = "0.1.0.4"; + public static final String STB_VERSION = "0.1.0.5"; private static final Consumer DEFAULT_LOGGER = System.err::println; private static Consumer apiLogger = DEFAULT_LOGGER; diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java index d49ed078..34ddf5c2 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java @@ -16,7 +16,10 @@ package overrungl.nfd; -import overrun.marshal.*; +import overrun.marshal.DirectAccess; +import overrun.marshal.Marshal; +import overrun.marshal.MemoryStack; +import overrun.marshal.Unmarshal; import overrun.marshal.gen.Entrypoint; import overrun.marshal.gen.SizedSeg; import overrun.marshal.gen.Skip; @@ -24,12 +27,9 @@ import overrungl.internal.RuntimeHelper; import overrungl.util.value.Tuple2; -import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; import java.lang.foreign.ValueLayout; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.util.Map; import static java.lang.foreign.ValueLayout.*; @@ -123,6 +123,28 @@ * @since 0.1.0 */ public interface NFD extends DirectAccess { + /** + * The native window handle type. + */ + int WINDOW_HANDLE_TYPE_UNSET = 0, + /** + * Windows: handle is HWND (the Windows API typedefs this to void*) + */ + WINDOW_HANDLE_TYPE_WINDOWS = 1, + /** + * Cocoa: handle is NSWindow* + */ + WINDOW_HANDLE_TYPE_COCOA = 2, + /** + * X11: handle is Window + */ + WINDOW_HANDLE_TYPE_X11 = 3; + /** + * This is a unique identifier tagged to all the NFD_*With() function calls, for backward + * compatibility purposes. There is usually no need to use this directly, unless you want to use + * NFD differently depending on the version you're building with. + */ + long INTERFACE_VERSION = 1; /** * The type of the path-set size ({@code unsigned long} for Windows and Mac OS X, * {@code unsigned int} for others). @@ -131,10 +153,7 @@ public interface NFD extends DirectAccess { /** * The instance of NFD. */ - NFD INSTANCE = Downcall.load(MethodHandles.lookup(), NFDInternal.LOOKUP, DowncallOption.descriptors(Map.of( - "NFD_PathSet_GetPathN", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS), - "NFD_PathSet_GetPathU8", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS) - ))); + NFD INSTANCE = NFDInternal.instance; /** * {@return NFD_PathSet_GetPathN} @@ -259,6 +278,18 @@ default NFDResult openDialogU8(String[] outPath, NFDU8FilterItem filterList, } } + @Entrypoint("NFD_OpenDialogN_With_Impl") + int openDialogNWithImpl(long version, MemorySegment outPath, MemorySegment args); + + @Entrypoint("NFD_OpenDialogN_With") + int openDialogNWith(MemorySegment outPath, MemorySegment args); + + @Entrypoint("NFD_OpenDialogU8_With_Impl") + int openDialogU8WithImpl(long version, MemorySegment outPath, MemorySegment args); + + @Entrypoint("NFD_OpenDialogU8_With") + int openDialogU8With(MemorySegment outPath, MemorySegment args); + /** * Multiple file open dialog * @@ -325,6 +356,18 @@ default NFDResult openDialogMultipleU8(@NativeType("const nfdpathset_t**") Memor } } + @Entrypoint("NFD_OpenDialogMultipleN_With_Impl") + int openDialogMultipleNWithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_OpenDialogMultipleN_With") + int openDialogMultipleNWith(MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_OpenDialogMultipleU8_With_Impl") + int openDialogMultipleU8WithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_OpenDialogMultipleU8_With") + int openDialogMultipleU8With(MemorySegment outPaths, MemorySegment args); + /** * Save dialog * @@ -409,6 +452,18 @@ default NFDResult saveDialogU8(String[] outPath, NFDU8FilterItem filterList, } } + @Entrypoint("NFD_SaveDialogN_With_Impl") + int saveDialogNWithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_SaveDialogN_With") + int saveDialogNWith(MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_SaveDialogU8_With_Impl") + int saveDialogU8WithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_SaveDialogU8_With") + int saveDialogU8With(MemorySegment outPaths, MemorySegment args); + /** * Select folder dialog * @@ -475,6 +530,36 @@ default NFDResult pickFolderU8(String[] outPath, String defaultPath) { } } + @Entrypoint("NFD_PickFolderN_With_Impl") + int pickFolderNWithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_PickFolderN_With") + int pickFolderNWith(MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_PickFolderU8_With_Impl") + int pickFolderU8WithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_PickFolderU8_With") + int pickFolderU8With(MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_PickFolderMultipleN") + int pickFolderMultipleN(MemorySegment outPaths, MemorySegment defaultPath); + + @Entrypoint("NFD_PickFolderMultipleU8") + int pickFolderMultipleU8(MemorySegment outPaths, MemorySegment defaultPath); + + @Entrypoint("NFD_PickFolderMultipleN_With_Impl") + int pickFolderMultipleNWithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_PickFolderMultipleN_With") + int pickFolderMultipleNWith(MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_PickFolderMultipleU8_With_Impl") + int pickFolderMultipleU8WithImpl(long version, MemorySegment outPaths, MemorySegment args); + + @Entrypoint("NFD_PickFolderMultipleU8_With") + int pickFolderMultipleU8With(MemorySegment outPaths, MemorySegment args); + /** * Get the last error *

diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDInternal.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDInternal.java index 4cbdf2be..ac07a9a8 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDInternal.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDInternal.java @@ -17,15 +17,24 @@ package overrungl.nfd; import io.github.overrun.platform.Platform; +import overrun.marshal.Downcall; +import overrun.marshal.DowncallOption; import overrungl.Configurations; import overrungl.OverrunGL; import overrungl.internal.RuntimeHelper; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.SymbolLookup; +import java.lang.invoke.MethodHandles; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.Map; import java.util.function.Supplier; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static overrungl.nfd.NFD.PATH_SET_SIZE; + /** * internal * @@ -34,11 +43,16 @@ */ final class NFDInternal { static final SymbolLookup LOOKUP; + static final NFD instance; static { final Supplier lib = () -> RuntimeHelper.load("nfd", "nfd", OverrunGL.NFD_VERSION); final var function = Configurations.NFD_SYMBOL_LOOKUP.get(); LOOKUP = function != null ? function.apply(lib) : lib.get(); + instance = Downcall.load(MethodHandles.lookup(), NFDInternal.LOOKUP, DowncallOption.descriptors(Map.of( + "NFD_PathSet_GetPathN", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS), + "NFD_PathSet_GetPathU8", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS) + ))); } static final Platform os = Platform.current(); diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogNArgs.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogNArgs.java new file mode 100644 index 00000000..7f15cf65 --- /dev/null +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogNArgs.java @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd; + +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Unmarshal; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; +import overrungl.internal.RuntimeHelper; + +/** + * {@code NFDOpenDialogNArgs} + */ +public interface NFDOpenDialogNArgs extends Struct { + /** + * The struct allocator. + */ + StructAllocator OF = new StructAllocator<>(java.lang.invoke.MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("filterList") + .add(RuntimeHelper.SIZE_T, "filterCount") + .add(Unmarshal.STR_LAYOUT, "defaultPath") + .cAddress("parentWindow", NFDWindowHandle.OF.layout()) + .build() + ); +} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogU8Args.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogU8Args.java new file mode 100644 index 00000000..9f4d39d1 --- /dev/null +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDOpenDialogU8Args.java @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd; + +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Unmarshal; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; +import overrungl.internal.RuntimeHelper; + +/** + * {@code NFDOpenDialogU8Args} + */ +public interface NFDOpenDialogU8Args extends Struct { + /** + * The struct allocator. + */ + StructAllocator OF = new StructAllocator<>(java.lang.invoke.MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("filterList") + .add(RuntimeHelper.SIZE_T, "filterCount") + .add(Unmarshal.STR_LAYOUT, "defaultPath") + .cAddress("parentWindow", NFDWindowHandle.OF.layout()) + .build() + ); +} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderNArgs.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderNArgs.java new file mode 100644 index 00000000..7b06e9ba --- /dev/null +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderNArgs.java @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd; + +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Unmarshal; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; + +/** + * {@code NFDPickFolderNArgs} + */ +public interface NFDPickFolderNArgs extends Struct { + /** + * The struct allocator. + */ + StructAllocator OF = new StructAllocator<>(java.lang.invoke.MethodHandles.lookup(), + LayoutBuilder.struct() + .add(Unmarshal.STR_LAYOUT, "defaultPath") + .cStruct("parentWindow", NFDWindowHandle.OF.layout()) + .build() + ); +} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderU8Args.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderU8Args.java new file mode 100644 index 00000000..4814fa65 --- /dev/null +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDPickFolderU8Args.java @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd; + +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Unmarshal; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; + +/** + * {@code NFDPickFolderU8Args} + */ +public interface NFDPickFolderU8Args extends Struct { + /** + * The struct allocator. + */ + StructAllocator OF = new StructAllocator<>(java.lang.invoke.MethodHandles.lookup(), + LayoutBuilder.struct() + .add(Unmarshal.STR_LAYOUT, "defaultPath") + .cStruct("parentWindow", NFDWindowHandle.OF.layout()) + .build() + ); +} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogNArgs.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogNArgs.java new file mode 100644 index 00000000..537aa477 --- /dev/null +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogNArgs.java @@ -0,0 +1,41 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd; + +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Unmarshal; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; +import overrungl.internal.RuntimeHelper; + +/** + * {@code NFDSaveDialogNArgs} + */ +public interface NFDSaveDialogNArgs extends Struct { + /** + * The struct allocator. + */ + StructAllocator OF = new StructAllocator<>(java.lang.invoke.MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("filterList") + .add(RuntimeHelper.SIZE_T, "filterCount") + .add(Unmarshal.STR_LAYOUT, "defaultPath") + .add(Unmarshal.STR_LAYOUT, "defaultName") + .cAddress("parentWindow", NFDWindowHandle.OF.layout()) + .build() + ); +} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogU8Args.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogU8Args.java new file mode 100644 index 00000000..1ba684d1 --- /dev/null +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDSaveDialogU8Args.java @@ -0,0 +1,41 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd; + +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Unmarshal; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; +import overrungl.internal.RuntimeHelper; + +/** + * {@code NFDSaveDialogU8Args} + */ +public interface NFDSaveDialogU8Args extends Struct { + /** + * The struct allocator. + */ + StructAllocator OF = new StructAllocator<>(java.lang.invoke.MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("filterList") + .add(RuntimeHelper.SIZE_T, "filterCount") + .add(Unmarshal.STR_LAYOUT, "defaultPath") + .add(Unmarshal.STR_LAYOUT, "defaultName") + .cAddress("parentWindow", NFDWindowHandle.OF.layout()) + .build() + ); +} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDWindowHandle.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDWindowHandle.java new file mode 100644 index 00000000..4206a7c9 --- /dev/null +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDWindowHandle.java @@ -0,0 +1,71 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.nfd; + +import overrun.marshal.LayoutBuilder; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; +import overrungl.internal.RuntimeHelper; + +import java.lang.foreign.MemorySegment; +import java.lang.invoke.MethodHandles; + +/** + * The native window handle. + *

+ * If using a platform abstraction framework (e.g. SDL2), this should be + * obtained using the corresponding NFD glue header (e.g. nfd_sdl2.h). + * + * @author squid233 + * @since 0.1.0 + */ +public interface NFDWindowHandle extends Struct { + /** + * The struct allocator. + */ + StructAllocator OF = new StructAllocator<>(MethodHandles.lookup(), + LayoutBuilder.struct() + .add(RuntimeHelper.SIZE_T, "type") + .cAddress("handle") + .build()); + + /** + * {@return type} + */ + long type(); + + /** + * Sets {@code type}. + * + * @param type type + * @return {@code this} + */ + NFDWindowHandle type(long type); + + /** + * {@return handle} + */ + MemorySegment handle(); + + /** + * Sets {@code handle} + * + * @param handle handle + * @return {@code this} + */ + NFDWindowHandle handle(MemorySegment handle); +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 429e8e5a..de97c3d0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,4 +17,8 @@ file("modules").listFiles().forEach { project(":$s").projectDir = it } -include("generators:opengl", "generators:vulkan") +include( + "generators:nfd", + "generators:opengl", + "generators:vulkan" +)