Browse Source

Move image viewer to 0.0.0-master-build413

pull/1281/head
Nikolay Igotti 3 years ago
parent
commit
c3e3fa30e2
  1. 2
      examples/imageviewer/build.gradle.kts
  2. 12
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/utils/GraphicsMath.kt
  3. 2
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MouseHover.kt

2
examples/imageviewer/build.gradle.kts

@ -7,7 +7,7 @@ buildscript {
dependencies { dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha4-build361") classpath("org.jetbrains.compose:compose-gradle-plugin:0.0.0-master-build413")
classpath("com.android.tools.build:gradle:4.1.0") classpath("com.android.tools.build:gradle:4.1.0")
classpath(kotlin("gradle-plugin", version = "1.5.31")) classpath(kotlin("gradle-plugin", version = "1.5.31"))
} }

12
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/utils/GraphicsMath.kt

@ -1,6 +1,6 @@
package example.imageviewer.utils package example.imageviewer.utils
import androidx.compose.ui.window.WindowSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import java.awt.Dimension import java.awt.Dimension
import java.awt.Graphics2D import java.awt.Graphics2D
@ -41,7 +41,7 @@ fun scaleBitmapAspectRatio(
return result return result
} }
fun getDisplayBounds(bitmap: BufferedImage, windowSize: WindowSize): Rectangle { fun getDisplayBounds(bitmap: BufferedImage, windowSize: DpSize): Rectangle {
val boundW: Float = windowSize.width.value.toFloat() val boundW: Float = windowSize.width.value.toFloat()
val boundH: Float = windowSize.height.value.toFloat() val boundH: Float = windowSize.height.value.toFloat()
@ -123,7 +123,7 @@ fun cropImage(bitmap: BufferedImage, crop: Rectangle) : BufferedImage {
fun cropBitmapByScale( fun cropBitmapByScale(
bitmap: BufferedImage, bitmap: BufferedImage,
size: WindowSize, size: DpSize,
scale: Float, scale: Float,
drag: DragHandler drag: DragHandler
): BufferedImage { ): BufferedImage {
@ -143,7 +143,7 @@ fun cropBitmapByScale(
fun cropBitmapByBounds( fun cropBitmapByBounds(
bitmap: BufferedImage, bitmap: BufferedImage,
bounds: Rectangle, bounds: Rectangle,
size: WindowSize, size: DpSize,
scaleFactor: Float, scaleFactor: Float,
drag: DragHandler drag: DragHandler
): Rectangle { ): Rectangle {
@ -196,11 +196,11 @@ fun cropBitmapByBounds(
return Rectangle(leftOffset, topOffset, leftOffset + boundW, topOffset + boundH) return Rectangle(leftOffset, topOffset, leftOffset + boundW, topOffset + boundH)
} }
fun getPreferredWindowSize(desiredWidth: Int, desiredHeight: Int): WindowSize { fun getPreferredWindowSize(desiredWidth: Int, desiredHeight: Int): DpSize {
val screenSize: Dimension = Toolkit.getDefaultToolkit().screenSize val screenSize: Dimension = Toolkit.getDefaultToolkit().screenSize
val preferredWidth: Int = (screenSize.width * 0.8f).toInt() val preferredWidth: Int = (screenSize.width * 0.8f).toInt()
val preferredHeight: Int = (screenSize.height * 0.8f).toInt() val preferredHeight: Int = (screenSize.height * 0.8f).toInt()
val width: Int = if (desiredWidth < preferredWidth) desiredWidth else preferredWidth val width: Int = if (desiredWidth < preferredWidth) desiredWidth else preferredWidth
val height: Int = if (desiredHeight < preferredHeight) desiredHeight else preferredHeight val height: Int = if (desiredHeight < preferredHeight) desiredHeight else preferredHeight
return WindowSize(width.dp, height.dp) return DpSize(width.dp, height.dp)
} }

2
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MouseHover.kt

@ -1,9 +1,11 @@
package example.imageviewer.view package example.imageviewer.view
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.input.pointer.pointerMoveFilter
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.hover( actual fun Modifier.hover(
onEnter: () -> Boolean, onEnter: () -> Boolean,
onExit: () -> Boolean, onExit: () -> Boolean,

Loading…
Cancel
Save