Moved some properties to better work with stub generator.

This commit is contained in:
Alexander Gorshenev
2017-10-30 12:28:22 +03:00
committed by alexander-gorshenev
parent 1fc7c5888f
commit 7e157c9d0d
4 changed files with 19 additions and 6 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ konanc $DIR/src/jsinterop/kotlin \
-includeBinary $DIR/src/jsinterop/js/jsinterop.js \
-p library -o $DIR/build/klib/jsinterop -target wasm32 || exit 1
konanc $DIR/src/jsinterop_tool/kotlin \
konanc $DIR/src/stubGenerator/kotlin \
-e org.jetbrains.kotlin.konan.jsinterop.tool.main \
-o $DIR/build/bin/generator || exit 1
+5 -4
View File
@@ -7,17 +7,18 @@ fun main(args: Array<String>) {
val canvas = document.getElementById("myCanvas").asCanvas
val ctx = canvas.getContext("2d")
val rect = canvas.getBoundingClientRect()
val rectLeft = rect.getInt("left")
val rectTop = rect.getInt("top")
val rectLeft = rect.left
val rectTop = rect.top
var mouseX: Int = 0
var mouseY: Int = 0
var draw: Boolean = false
document.setter("onmousemove") { args: ArrayList<JsValue> ->
val event = args[0]
val event = MouseEvent(args[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
@@ -34,7 +35,7 @@ fun main(args: Array<String>) {
setInterval(10) {
if (draw) {
ctx.setter("strokeStyle", "#222222")
ctx.strokeStyle = "#222222"
ctx.lineTo(mouseX, mouseY)
ctx.stroke()
} else {
@@ -7,6 +7,8 @@ val all = listOf(
Interface("Context",
Attribute("lineWidth", Integer, hasSetter = true),
Attribute("fillStyle", idlString, hasSetter = true),
Attribute("strokeStyle", idlString, hasSetter = true),
Operation("lineTo", Void, Arg("x", Integer), Arg("y", Integer)),
Operation("moveTo", Void, Arg("x", Integer), Arg("y", Integer)),
Operation("beginPath", Void),
@@ -16,7 +18,12 @@ val all = listOf(
Operation("fill", Void),
Operation("closePath", Void)
),
Interface("DOMRect"),
Interface("DOMRect",
Attribute("left", Integer, hasGetter = true),
Attribute("right", Integer, hasGetter = true),
Attribute("top", Integer, hasGetter = true),
Attribute("bottom", Integer, hasGetter = true)
),
Interface("Canvas",
Operation("getContext", InterfaceRef("Context"), Arg("context", idlString)),
Operation("getBoundingClientRect", InterfaceRef("DOMRect"))
@@ -24,6 +31,10 @@ val all = listOf(
Interface("Document",
Operation("getElementById", Object, Arg("id", idlString))
),
Interface("MouseEvent",
Attribute("clientX", Integer, hasGetter = true),
Attribute("clientY", Integer, hasGetter = true)
),
Interface("Response",
Operation("json", Object)
),
@@ -32,6 +43,7 @@ val all = listOf(
),
Interface("__Global",
Attribute("document", InterfaceRef("Document"), hasGetter = true),
Operation("fetch", InterfaceRef("Promise"), Arg("url", idlString)),
Operation("setInterval", Void, Arg("lambda", Function), Arg("interval", Integer))
)