Add orx-image-fit

This commit is contained in:
Edwin Jakobs
2020-02-10 23:37:05 +01:00
parent ac9d0bb4f9
commit 77dee0c6af
2 changed files with 44 additions and 17 deletions

View File

@@ -2,11 +2,12 @@
Fits images in frames with two options, contain and cover. Similar to CSS object-fit (https://www.w3schools.com/css/css3_object-fit.asp)
## usage
`orx-image-fit` provides an extension function`imageFit` for `Drawer`.
## Usage
`imageFit(img: ColorBuffer, x: Double, y: Double, w: Double, h: Double, fitMethod, horizontalPosition:Double, verticalPosition:Double)`
fitMethod
- `contain`
- `cover`
@@ -17,4 +18,21 @@ horizontal values
vertical values
- top ... bottom
- `-1.0` ... `1.0`
- `-1.0` ... `1.0`
## Example
A quick example that fits an image to the window rectangle with a 10 pixel margin. By default
`imageFit` uses the cover mode, which fills the target rectangle with an image.
```kotlin
fun main() = application {
program {
val image = loadImage("data/images/pm5544.png")
extend {
drawer.imageFit(10.0, 10.0, width - 20.0, height - 20.0)
}
}
}
```