mirror of
https://github.com/jlengrand/korge-samples.git
synced 2026-03-10 08:31:18 +00:00
Added mask sample showing how to use MaskedView
This commit is contained in:
1
mask/.gitignore
vendored
Normal file
1
mask/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
8
mask/build.gradle.kts
Normal file
8
mask/build.gradle.kts
Normal file
@@ -0,0 +1,8 @@
|
||||
import com.soywiz.korge.gradle.*
|
||||
|
||||
apply<KorgeGradlePlugin>()
|
||||
|
||||
korge {
|
||||
id = "com.soywiz.samples.mask"
|
||||
targetDefault()
|
||||
}
|
||||
26
mask/src/commonMain/kotlin/main.kt
Normal file
26
mask/src/commonMain/kotlin/main.kt
Normal 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")
|
||||
BIN
mask/src/commonMain/resources/korge.png
Normal file
BIN
mask/src/commonMain/resources/korge.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Reference in New Issue
Block a user