Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package sample.html5canvas
|
||||
|
||||
import kotlinx.interop.wasm.dom.*
|
||||
import kotlinx.wasm.jsinterop.*
|
||||
|
||||
fun main() {
|
||||
|
||||
val canvas = document.getElementById("myCanvas").asCanvas
|
||||
val ctx = canvas.getContext("2d")
|
||||
val rect = canvas.getBoundingClientRect()
|
||||
val rectLeft = rect.left
|
||||
val rectTop = rect.top
|
||||
|
||||
var mouseX: Int = 0
|
||||
var mouseY: Int = 0
|
||||
var draw: Boolean = false
|
||||
|
||||
document.setter("onmousemove") { arguments: ArrayList<JsValue> ->
|
||||
val event = MouseEvent(arguments[0])
|
||||
mouseX = event.getInt("clientX") - rectLeft
|
||||
mouseY = event.getInt("clientY") - rectTop
|
||||
|
||||
if (mouseX < 0) mouseX = 0
|
||||
if (mouseX > 639) mouseX = 639
|
||||
if (mouseY < 0) mouseY = 0
|
||||
if (mouseY > 479) mouseY = 479
|
||||
}
|
||||
|
||||
document.setter("onmousedown") {
|
||||
draw = true
|
||||
}
|
||||
|
||||
document.setter("onmouseup") {
|
||||
draw = false
|
||||
}
|
||||
|
||||
setInterval(10) {
|
||||
if (draw) {
|
||||
ctx.strokeStyle = "#222222"
|
||||
ctx.lineTo(mouseX, mouseY)
|
||||
ctx.stroke()
|
||||
} else {
|
||||
ctx.moveTo(mouseX, mouseY)
|
||||
ctx.stroke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:JvmName("HttpServer")
|
||||
|
||||
package sample.html5canvas.httpserver
|
||||
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.content.LocalFileContent
|
||||
import io.ktor.http.content.default
|
||||
import io.ktor.http.content.files
|
||||
import io.ktor.http.content.static
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.get
|
||||
import io.ktor.routing.routing
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.netty.Netty
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
check(args.size == 1) { "Invalid number of arguments: $args.\nExpected one argument with content root." }
|
||||
|
||||
val contentRoot = File(args[0])
|
||||
check(contentRoot.isDirectory) { "Invalid content root: $contentRoot." }
|
||||
|
||||
println(
|
||||
"""
|
||||
|
||||
IMPORTANT: Please open http://localhost:8080/ in your browser!
|
||||
|
||||
To stop embedded HTTP server use Ctrl+C (Cmd+C for Mac OS X).
|
||||
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
val server = embeddedServer(Netty, 8080) {
|
||||
routing {
|
||||
val wasm = "build/bin/html5Canvas/releaseExecutable/html5Canvas.wasm"
|
||||
get(wasm) {
|
||||
// TODO: ktor as of now doesn't know about 'application/wasm'.
|
||||
// The newer browsers (firefox and chrome at least) don't allow
|
||||
// 'application/octet-stream' for wasm anymore.
|
||||
// We provide the proper content type here and,
|
||||
// at the same time, put it into the ktor database.
|
||||
// Remove this whole get() clause when ktor fix is available.
|
||||
call.respond(LocalFileContent(File(wasm), ContentType("application", "wasm")))
|
||||
}
|
||||
static("/") {
|
||||
files(contentRoot)
|
||||
default("index.html")
|
||||
}
|
||||
}
|
||||
}
|
||||
server.start(wait = true)
|
||||
}
|
||||
Reference in New Issue
Block a user