Added mask sample showing how to use MaskedView

This commit is contained in:
soywiz
2020-11-23 22:29:13 +01:00
parent 153ee97d99
commit fcdce537b0
4 changed files with 35 additions and 0 deletions

1
mask/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

8
mask/build.gradle.kts Normal file
View File

@@ -0,0 +1,8 @@
import com.soywiz.korge.gradle.*
apply<KorgeGradlePlugin>()
korge {
id = "com.soywiz.samples.mask"
targetDefault()
}

View File

@@ -0,0 +1,26 @@
import com.soywiz.korge.*
import com.soywiz.korge.input.*
import com.soywiz.korge.resources.*
import com.soywiz.korge.view.*
import com.soywiz.korim.bitmap.effect.*
import com.soywiz.korim.color.*
import com.soywiz.korio.resources.*
suspend fun main() = Korge(width = 512, height = 512) {
val bitmap = korgePng.get().extract().toBMP32()
val bitmap2 = bitmap.applyEffect(BitmapEffect(dropShadowColor = Colors.BLUE, dropShadowX = 10, dropShadowY = 0, dropShadowRadius = 6))
val maskedView = MaskedView()
addChild(maskedView)
maskedView.text("HELLO WORLD!", textSize = 64.0)
val img = maskedView.image(bitmap2).scale(3, 3)
val mask = Circle(256.0).centered
maskedView.mask = mask
maskedView.mask!!.position(0, 0)
mouse {
onMoveAnywhere {
maskedView.mask!!.position(localMouseX(views).coerceIn(0.0, 512.0), localMouseY(views).coerceIn(0.0, 512.0))
}
}
}
val ResourcesContainer.korgePng by resourceBitmap("korge.png")

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB