Some tweaks in canvas api.

This commit is contained in:
Pavel V. Talanov
2012-03-30 20:02:27 +04:00
parent 8ed9a89d9e
commit fc843eca8f
5 changed files with 86 additions and 79 deletions
+2 -2
View File
@@ -2,8 +2,8 @@
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/src/html5/fancyLines"> <content url="file://$MODULE_DIR$/src/html5/creatures">
<sourceFolder url="file://$MODULE_DIR$/src/html5/fancyLines" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/html5/creatures" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
+1 -1
View File
@@ -61,7 +61,7 @@ class Logo(override var pos : Vector) : Shape()
fun drawLogo(state : CanvasState) { fun drawLogo(state : CanvasState) {
size = imageSize * (state.size.x / imageSize.x) * relSize size = imageSize * (state.size.x / imageSize.x) * relSize
// getKotlinLogo() is a 'magic' function here defined only for purposes of demonstration but in fact it just find an element containing the logo // getKotlinLogo() is a 'magic' function here defined only for purposes of demonstration but in fact it just find an element containing the logo
state.context.drawImage(getKotlinLogo(), 0.0, 0.0, imageSize.x, imageSize.y, position.x, position.y, size.x, size.y) state.context.drawImage(getKotlinLogo(), 0, 0, imageSize.x.toInt(), imageSize.y.toInt(), position.x.toInt(), position.y.toInt(), size.x.toInt(), size.y.toInt())
} }
override fun draw(state : CanvasState) { override fun draw(state : CanvasState) {
+64 -60
View File
@@ -5,24 +5,24 @@ import js.DomElement
native native
class Context() { class Context() {
fun save() { fun save() : Unit = js.noImpl
}
fun restore() {
}
fun scale(x : Double, y : Double) { fun restore() : Unit = js.noImpl
}
fun rotate(angle : Double) {
} fun scale(x : Double, y : Double) : Unit = js.noImpl
fun translate(x : Double, y : Double) {
} fun rotate(angle : Double) : Unit = js.noImpl
fun translate(x : Double, y : Double) : Unit = js.noImpl
fun clearRect(x : Double, y : Double, w : Double, h : Double) : Unit = js.noImpl
fun fillRect(x : Double, y : Double, w : Double, h : Double) : Unit = js.noImpl
fun strokeRect(x : Double, y : Double, w : Double, h : Double) : Unit = js.noImpl
fun clearRect(x : Double, y : Double, w : Double, h : Double) {
}
fun fillRect(x : Double, y : Double, w : Double, h : Double) {
}
fun strokeRect(x : Double, y : Double, w : Double, h : Double) {
}
var globalAlpha : Double = 1.0; var globalAlpha : Double = 1.0;
var strokeStyle : Any = "" var strokeStyle : Any = ""
@@ -34,49 +34,47 @@ class Context() {
var shadowColor : String = "" var shadowColor : String = ""
var font : String = "" var font : String = ""
fun beginPath() { fun beginPath() : Unit = js.noImpl
}
fun moveTo(x : Double, y : Double) {
}
fun closePath() {
}
fun lineTo(x : Double, y : Double) { fun moveTo(x : Double, y : Double) : Unit = js.noImpl
}
fun quadraticCurveTo(cpx : Double, cpy : Double, x : Double, y : Double) {
}
fun bezierCurveTo(cp1x : Double, cp1y : Double, cp2x : Double, cp2y : Double, x : Double, y : Double) {
}
fun arcTo(x1 : Double, y1 : Double, x2 : Double, y2 : Double, radius : Double) {
}
fun arc(x : Double, y : Double, radius : Double, startAngle : Double, endAngle : Double, anticlockwise : Boolean) {
}
fun rect(x : Double, y : Double, w : Double, h : Double) { fun closePath() : Unit = js.noImpl
}
fun fill() {
} fun lineTo(x : Double, y : Double) : Unit = js.noImpl
fun stroke() {
} fun quadraticCurveTo(cpx : Double, cpy : Double, x : Double, y : Double) : Unit = js.noImpl
fun bezierCurveTo(cp1x : Double, cp1y : Double, cp2x : Double, cp2y : Double, x : Double, y : Double) : Unit = js.noImpl
fun arcTo(x1 : Double, y1 : Double, x2 : Double, y2 : Double, radius : Double) : Unit = js.noImpl
fun arc(x : Double, y : Double, radius : Double, startAngle : Double, endAngle : Double, anticlockwise : Boolean) : Unit = js.noImpl
fun rect(x : Double, y : Double, w : Double, h : Double) : Unit = js.noImpl
fun fill() : Unit = js.noImpl
fun stroke() : Unit = js.noImpl
fun fillText(text : String, x : Double, y : Double) : Unit = js.noImpl
fun fillText(text : String, x : Double, y : Double, maxWidth : Double) : Unit = js.noImpl
fun strokeText(text : String, x : Double, y : Double) : Unit = js.noImpl
fun strokeText(text : String, x : Double, y : Double, maxWidth : Double) : Unit = js.noImpl
fun fillText(text : String, x : Double, y : Double) {
}
fun fillText(text : String, x : Double, y : Double, maxWidth : Double) {
}
fun strokeText(text : String, x : Double, y : Double) {
}
fun strokeText(text : String, x : Double, y : Double, maxWidth : Double) {
}
fun measureText(text : String) : TextMetrics = TextMetrics(); fun measureText(text : String) : TextMetrics = TextMetrics();
fun drawImage(image : HTMLImageElement, dx : Double, dy : Double) { fun drawImage(image : HTMLImageElement, dx : Int, dy : Int) : Unit = js.noImpl
} fun drawImage(image : HTMLImageElement, dx : Int, dy : Int, dw : Int, dh : Int) : Unit = js.noImpl
fun drawImage(image : HTMLImageElement, dx: Double, dy: Double, dw: Double, dh: Double) { fun drawImage(image : HTMLImageElement, sx : Int, sy : Int,
} sw : Int, sh : Int, dx : Int, dy : Int, dw : Int, dh : Int) : Unit = js.noImpl
fun drawImage(image : HTMLImageElement, sx: Double, sy: Double,
sw: Double, sh: Double, dx: Double, dy: Double, dw: Double, dh: Double) {
}
fun createLinearGradient(x0 : Double, y0 : Double, x1 : Double, y1 : Double) : CanvasGradient = CanvasGradient() fun createLinearGradient(x0 : Double, y0 : Double, x1 : Double, y1 : Double) : CanvasGradient = CanvasGradient()
fun createRadialGradient(x0 : Double, y0 : Double, r0 : Double, x1 : Double, y1 : Double, r1 : Double) : CanvasGradient = CanvasGradient(); fun createRadialGradient(x0 : Double, y0 : Double, r0 : Double, x1 : Double, y1 : Double, r1 : Double) : CanvasGradient = CanvasGradient();
@@ -85,16 +83,19 @@ class Context() {
fun putImageData(data : ImageData, dx : Int, dy : Int) : Unit = js.noImpl fun putImageData(data : ImageData, dx : Int, dy : Int) : Unit = js.noImpl
} }
native native
open class HTMLImageElement() : DomElement() { open class HTMLImageElement() : DomElement() {
} }
native native
class CanvasGradient() { class CanvasGradient() {
fun addColorStop(offset : Double, color : String) { fun addColorStop(offset : Double, color : String) : Unit = js.noImpl
}
} }
native native
class ImageData() { class ImageData() {
// readonly attribute unsigned long width; // readonly attribute unsigned long width;
@@ -106,6 +107,7 @@ class ImageData() {
} }
native native
class Canvas() : DomElement() { class Canvas() : DomElement() {
var width : Int = js.noImpl; var width : Int = js.noImpl;
@@ -116,17 +118,19 @@ class Canvas() : DomElement() {
fun toDataURL(typ : String) : String = js.noImpl fun toDataURL(typ : String) : String = js.noImpl
} }
native native
class TextMetrics() { class TextMetrics() {
val width : Int = 0 val width : Int = js.noImpl
} }
/*custom helpers*/ /*custom helpers*/
native native
fun getContext() : Context = Context(); fun getContext() : Context = js.noImpl
native native
fun getCanvas() : Canvas = Canvas(); fun getCanvas() : Canvas = js.noImpl
native native
fun getKotlinLogo() : HTMLImageElement = HTMLImageElement(); fun getKotlinLogo() : HTMLImageElement = js.noImpl
native native
fun getImage(src: String) : HTMLImageElement = HTMLImageElement(); fun getImage(src : String) : HTMLImageElement = js.noImpl
@@ -84,6 +84,8 @@ public final class Intrinsics {
declareBooleanIntrinsics(); declareBooleanIntrinsics();
FunctionDescriptor intToDouble = getFunctionByName(library.getInt().getDefaultType().getMemberScope(), "toDouble"); FunctionDescriptor intToDouble = getFunctionByName(library.getInt().getDefaultType().getMemberScope(), "toDouble");
functionIntrinsics.put(intToDouble, ReturnReceiverIntrinsic.INSTANCE); functionIntrinsics.put(intToDouble, ReturnReceiverIntrinsic.INSTANCE);
FunctionDescriptor doubleToInt = getFunctionByName(library.getDouble().getDefaultType().getMemberScope(), "toInt");
functionIntrinsics.put(doubleToInt, new CallStandardMethodIntrinsic("Math.floor", true, 0));
FunctionDescriptor toStringFunction = getFunctionByName(library.getLibraryScope(), "toString"); FunctionDescriptor toStringFunction = getFunctionByName(library.getLibraryScope(), "toString");
functionIntrinsics.put(toStringFunction, new BuiltInFunctionIntrinsic("toString")); functionIntrinsics.put(toStringFunction, new BuiltInFunctionIntrinsic("toString"));
} }
@@ -144,7 +146,7 @@ public final class Intrinsics {
FunctionDescriptor iteratorFunction = getFunctionByName(arrayMemberScope, "iterator"); FunctionDescriptor iteratorFunction = getFunctionByName(arrayMemberScope, "iterator");
functionIntrinsics.put(iteratorFunction, new CallStandardMethodIntrinsic("Kotlin.arrayIterator", true, 0)); functionIntrinsics.put(iteratorFunction, new CallStandardMethodIntrinsic("Kotlin.arrayIterator", true, 0));
ConstructorDescriptor arrayConstructor = ConstructorDescriptor arrayConstructor =
((ClassDescriptor) arrayMemberScope.getContainingDeclaration()).getConstructors().iterator().next(); ((ClassDescriptor)arrayMemberScope.getContainingDeclaration()).getConstructors().iterator().next();
functionIntrinsics.put(arrayConstructor, new CallStandardMethodIntrinsic("Kotlin.arrayFromFun", false, 2)); functionIntrinsics.put(arrayConstructor, new CallStandardMethodIntrinsic("Kotlin.arrayFromFun", false, 2));
} }
@@ -199,7 +201,7 @@ public final class Intrinsics {
public boolean isIntrinsic(@NotNull DeclarationDescriptor descriptor) { public boolean isIntrinsic(@NotNull DeclarationDescriptor descriptor) {
//NOTE: that if we want to add other intrinsics we have to modify this method //NOTE: that if we want to add other intrinsics we have to modify this method
if (descriptor instanceof FunctionDescriptor) { if (descriptor instanceof FunctionDescriptor) {
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor.getOriginal(); FunctionDescriptor functionDescriptor = (FunctionDescriptor)descriptor.getOriginal();
return (equalsIntrinsics.containsKey(functionDescriptor) || return (equalsIntrinsics.containsKey(functionDescriptor) ||
compareToIntrinsics.containsKey(functionDescriptor) || compareToIntrinsics.containsKey(functionDescriptor) ||
functionIntrinsics.containsKey(functionDescriptor)); functionIntrinsics.containsKey(functionDescriptor));
@@ -289,5 +291,4 @@ public final class Intrinsics {
return !DescriptorUtils.hasParameters(descriptor); return !DescriptorUtils.hasParameters(descriptor);
} }
} }
} }
@@ -152,11 +152,13 @@ public final class DescriptorUtils {
@NotNull @NotNull
public static String getNameForNamespace(@NotNull NamespaceDescriptor descriptor) { public static String getNameForNamespace(@NotNull NamespaceDescriptor descriptor) {
if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) { //if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) {
// return Namer.getAnonymousNamespaceName();
//} else
if (descriptor.getName().isEmpty()) {
return Namer.getAnonymousNamespaceName(); return Namer.getAnonymousNamespaceName();
} else if (descriptor.getName().equals("")) { }
return Namer.getAnonymousNamespaceName(); else {
} else {
return descriptor.getName(); return descriptor.getName();
} }
} }