-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NSFont, NSLevelIndicator, AlertSheetReturnCodeMapper, NSEvent cla…
…sses in Kotlin Added NSFont, NSLevelIndicator, AlertSheetReturnCodeMapper, and NSEvent class implementations to the Darwin package in Kotlin. These new classes provide more support for handling fonts, level indicators, alert sheets, and events, extending the range of functionalities in the Darwin package. The new classes also contain several methods for respective class functions.
- Loading branch information
1 parent
70c70c0
commit 738c301
Showing
134 changed files
with
29,077 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@file:OptIn(ExperimentalWasmDsl::class) | ||
|
||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl | ||
|
||
plugins { | ||
alias(libs.plugins.kotlinMultiplatform) | ||
} | ||
|
||
kotlin { | ||
js { | ||
browser() | ||
} | ||
jvm() | ||
|
||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
api(project(":wgpu4k")) | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0") | ||
|
||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
bindings/wgpu/examples/common/src/commonMain/kotlin/io.ygdrasil.wgpu.examples/Application.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@file:OptIn(ExperimentalStdlibApi::class) | ||
|
||
package io.ygdrasil.wgpu.examples | ||
|
||
import io.ygdrasil.wgpu.Adapter | ||
import io.ygdrasil.wgpu.Device | ||
import io.ygdrasil.wgpu.RenderingContext | ||
|
||
abstract class Application( | ||
val renderingContext: RenderingContext, | ||
val device: Device, | ||
val adapter: Adapter | ||
) : AutoCloseable { | ||
|
||
private lateinit var currentScene: Scene | ||
|
||
init { | ||
changeScene(scenes.first()) | ||
} | ||
|
||
abstract class Scene { | ||
|
||
abstract fun Application.initialiaze() | ||
|
||
abstract fun Application.render() | ||
|
||
} | ||
|
||
fun changeScene(nextScene: Scene) { | ||
with(nextScene) { | ||
try { | ||
initialiaze() | ||
} catch (e: Throwable) { | ||
e.printStackTrace() | ||
} | ||
} | ||
currentScene = nextScene | ||
} | ||
|
||
fun renderFrame() { | ||
with(currentScene) { | ||
try { | ||
render() | ||
} catch (e: Throwable) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
|
||
override fun close() { | ||
renderingContext.close() | ||
device.close() | ||
adapter.close() | ||
} | ||
|
||
abstract suspend fun run() | ||
} | ||
|
||
val scenes = listOf( | ||
BlueTitlingScene(), | ||
SimpleTriangleScene(), | ||
) |
18 changes: 18 additions & 0 deletions
18
...pu/examples/common/src/commonMain/kotlin/io.ygdrasil.wgpu.examples/AutoClosableContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@file:OptIn(ExperimentalStdlibApi::class) | ||
|
||
package io.ygdrasil.wgpu.examples | ||
|
||
fun <T> autoClosableContext(block: AutoClosableContext.() -> T): T = AutoClosableContext() | ||
.use { it.block() } | ||
|
||
class AutoClosableContext : AutoCloseable { | ||
|
||
private val subjects: MutableList<AutoCloseable> = mutableListOf() | ||
|
||
fun <T : AutoCloseable> T.bind(): T = also { subjects.add(it) } | ||
|
||
override fun close() { | ||
subjects.reversed() | ||
.forEach { it.close() } | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../wgpu/examples/common/src/commonMain/kotlin/io.ygdrasil.wgpu.examples/BlueTitlingScene.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.ygdrasil.wgpu.examples | ||
|
||
import io.ygdrasil.wgpu.RenderPassDescriptor | ||
|
||
class TitlingManager() { | ||
fun nextFrame() { | ||
if (value > 255.0) { | ||
delta = -5.0 | ||
} else if (value < 0) { | ||
delta = 5.0 | ||
} | ||
|
||
value += delta | ||
} | ||
|
||
fun reset() { | ||
delta = 5.0 | ||
value = 0.0 | ||
} | ||
|
||
private var delta = 5.0 | ||
var value = 0.0 | ||
private set | ||
} | ||
|
||
class BlueTitlingScene : Application.Scene() { | ||
|
||
private val titlingManager = TitlingManager() | ||
|
||
override fun Application.initialiaze() { | ||
titlingManager.reset() | ||
} | ||
|
||
override fun Application.render() = autoClosableContext { | ||
titlingManager.nextFrame() | ||
|
||
// Clear the canvas with a render pass | ||
val encoder = device.createCommandEncoder() | ||
.bind() | ||
|
||
val texture = renderingContext.getCurrentTexture() | ||
.bind() | ||
val view = texture.createView() | ||
.bind() | ||
|
||
val renderPassEncoder = encoder.beginRenderPass( | ||
RenderPassDescriptor( | ||
colorAttachments = arrayOf( | ||
RenderPassDescriptor.ColorAttachment( | ||
view = view, | ||
loadOp = "clear", | ||
clearValue = arrayOf(0, 0, titlingManager.value / 255.0, 1.0), | ||
storeOp = "store" | ||
) | ||
) | ||
) | ||
).bind() | ||
renderPassEncoder.end() | ||
|
||
val commandBuffer = encoder.finish() | ||
.bind() | ||
|
||
device.queue.submit(arrayOf(commandBuffer)) | ||
|
||
renderingContext.present() | ||
|
||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
...pu/examples/common/src/commonMain/kotlin/io.ygdrasil.wgpu.examples/SimpleTriangleScene.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package io.ygdrasil.wgpu.examples | ||
|
||
import io.ygdrasil.wgpu.* | ||
|
||
class SimpleTriangleScene : Application.Scene() { | ||
|
||
lateinit var renderPipeline: RenderPipeline | ||
|
||
override fun Application.initialiaze() { | ||
val shaderModule = device.createShaderModule( | ||
ShaderModuleDescriptor( | ||
code = shader | ||
) | ||
) | ||
|
||
val pipelineLayout = device.createPipelineLayout(PipelineLayoutDescriptor()) | ||
|
||
renderPipeline = device.createRenderPipeline( | ||
RenderPipelineDescriptor( | ||
layout = pipelineLayout, | ||
vertex = RenderPipelineDescriptor.VertexState( | ||
module = shaderModule, | ||
entryPoint = "vs_main" | ||
), | ||
fragment = RenderPipelineDescriptor.FragmentState( | ||
module = shaderModule, | ||
entryPoint = "fs_main", | ||
targets = arrayOf( | ||
RenderPipelineDescriptor.FragmentState.ColorTargetState( | ||
format = renderingContext.textureFormat, | ||
writeMask = ColorWriteMask.all | ||
) | ||
) | ||
), | ||
primitive = RenderPipelineDescriptor.PrimitiveState( | ||
topology = PrimitiveTopology.trianglelist | ||
), | ||
multisample = RenderPipelineDescriptor.MultisampleState( | ||
count = 1, | ||
mask = 0xFFFFFFF | ||
) | ||
) | ||
) | ||
} | ||
|
||
override fun Application.render() = autoClosableContext { | ||
|
||
// Clear the canvas with a render pass | ||
val encoder = device.createCommandEncoder() | ||
.bind() | ||
|
||
val texture = renderingContext.getCurrentTexture() | ||
.bind() | ||
val view = texture.createView() | ||
.bind() | ||
|
||
val renderPassEncoder = encoder.beginRenderPass( | ||
RenderPassDescriptor( | ||
colorAttachments = arrayOf( | ||
RenderPassDescriptor.ColorAttachment( | ||
view = view, | ||
loadOp = "clear", | ||
clearValue = arrayOf(0, 1.0, 0, 1.0), | ||
storeOp = "store" | ||
) | ||
) | ||
) | ||
) | ||
.bind() | ||
|
||
renderPassEncoder.setPipeline(renderPipeline) | ||
renderPassEncoder.draw(3, 1, 0, 0) | ||
renderPassEncoder.end() | ||
|
||
val commandBuffer = encoder.finish() | ||
.bind() | ||
|
||
device.queue.submit(arrayOf(commandBuffer)) | ||
|
||
renderingContext.present() | ||
|
||
} | ||
} | ||
|
||
private val shader = """ | ||
@vertex | ||
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> { | ||
let x = f32(i32(in_vertex_index) - 1); | ||
let y = f32(i32(in_vertex_index & 1u) * 2 - 1); | ||
return vec4<f32>(x, y, 0.0, 1.0); | ||
} | ||
@fragment | ||
fn fs_main() -> @location(0) vec4<f32> { | ||
return vec4<f32>(1.0, 0.0, 0.0, 1.0); | ||
} | ||
""".trimIndent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat | ||
|
||
plugins { | ||
alias(libs.plugins.kotlinMultiplatform) | ||
alias(libs.plugins.compose) | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
google() | ||
maven { | ||
url = uri("http://repo.maven.cyberduck.io.s3.amazonaws.com/releases") | ||
isAllowInsecureProtocol = true | ||
} | ||
} | ||
|
||
kotlin { | ||
jvm() | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(project(":examples:common")) | ||
} | ||
} | ||
|
||
val jvmMain by getting { | ||
//configurations["jvmMainCompileOnly"].isCanBeResolved = true | ||
dependencies { | ||
implementation(compose.desktop.currentOs) | ||
implementation("net.java.dev.jna:jna:5.14.0") | ||
implementation("net.java.dev.jna:jna-platform:5.14.0") | ||
implementation("org.rococoa:rococoa-core:0.9.1") | ||
implementation("org.rococoa:librococoa:0.9.1") | ||
implementation("org.apache.logging.log4j:log4j-api:2.20.0") | ||
implementation("org.apache.logging.log4j:log4j-core:2.20.0") | ||
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.20.0") | ||
|
||
} | ||
/* | ||
tasks.register<Copy>("copyFileFromDependency") { | ||
val dependencyFile = configurations.runtimeClasspath.get() | ||
.filter { it.name.contains("librococoa-0.9.1.dylib") } | ||
.singleFile | ||
from(dependencyFile) | ||
into("src/main/resources/darwin/") | ||
rename { "librococoa.dylib" } | ||
} | ||
*/ | ||
} | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "MainKt" | ||
|
||
jvmArgs += "--add-opens=java.base/java.lang=ALL-UNNAMED" | ||
|
||
nativeDistributions { | ||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) | ||
packageName = "compose" | ||
packageVersion = "1.0.0" | ||
} | ||
} | ||
} | ||
|
||
|
||
/* | ||
configurations | ||
.filter { it.name.contains("jvmMainCompileOnly") } | ||
.first() | ||
.let { it.asPath } | ||
.let { zipTree(it) } | ||
.forEach { println(it) } | ||
val smokeTest by configurations.creating { | ||
} | ||
dependencies { | ||
smokeTest("org.rococoa:librococoa:0.9.1") | ||
} | ||
smokeTest | ||
.forEach { println(it) } | ||
//.let(::zipTree) | ||
//.files | ||
//.filter { it.name.contains("librococoa-0.9.1.dylib") } | ||
//.let { println(it.) } | ||
smokeTest.forEach { println(it.name) }*/ | ||
|
||
/*tasks.register<Copy>("copyFileFromDependency") { | ||
val runtimeClasspath = configurations["kotlinJvmRuntimeClasspath"] | ||
val dependencyFile = runtimeClasspath.get() | ||
.filter { it.name.contains("librococoa-0.9.1.dylib") } | ||
.singleFile | ||
from(dependencyFile) | ||
into("src/jvmMain/resources/darwin/") | ||
rename { "librococoa.dylib" } | ||
}*/ |
Oops, something went wrong.