Skip to content

Commit

Permalink
桌面端摄像头完成
Browse files Browse the repository at this point in the history
  • Loading branch information
xfqwdsj committed May 1, 2024
1 parent fef8c93 commit fe0ce49
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
19 changes: 8 additions & 11 deletions compose-app/src/commonMain/kotlin/ui/composables/CameraPreview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import xyz.xfqlittlefan.fhraise.platform.Camera

Expand All @@ -54,16 +53,14 @@ fun CameraPreview(
camera = camera, onStateChange = { ready = it }, onDispose = onDispose,
frame = { bitmap ->
Box {
with(LocalDensity.current) {
bitmap?.let {
Image(
bitmap = it,
contentDescription = "相机预览",
modifier = Modifier.graphicsLayer {
if (flipHorizontally) scaleX = -1f
}.blur(blurRadius).then(modifier),
)
}
bitmap?.let {
Image(
bitmap = it,
contentDescription = "相机预览",
modifier = Modifier.graphicsLayer {
if (flipHorizontally) scaleX = -1f
}.blur(blurRadius).then(modifier),
)
}
AnimatedVisibility(
visible = !ready, modifier = Modifier.matchParentSize(), enter = fadeIn(), exit = fadeOut()
Expand Down
44 changes: 20 additions & 24 deletions compose-app/src/commonMain/kotlin/ui/pages/root/SignIn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,23 @@ import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.onFocusEvent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Outline
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.layout.SubcomposeLayout
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalAutofill
import androidx.compose.ui.platform.LocalAutofillTree
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.*
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import fhraise.compose_app.generated.resources.Res
import fhraise.compose_app.generated.resources.fhraise_logo
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -853,25 +852,22 @@ private fun SignInComponent.Face() {
}

selectedCamera?.let {
CameraPreview(
camera = it, onDispose = { componentScope.launch { it.close() } },
modifier = Modifier.clip(object : Shape {
override fun createOutline(
size: Size, layoutDirection: LayoutDirection, density: Density
): Outline {
val squareSize = min(size.width, size.height)
return Outline.Rectangle(
Rect(
offset = Offset(
(size.width - squareSize) / 2, (size.height - squareSize) / 2
),
size = Size(squareSize, squareSize),
Box(modifier = Modifier.clip(CircleShape)) {
CameraPreview(
camera = it, onDispose = { componentScope.launch { it.close() } },
modifier = Modifier.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
val size = min(placeable.width, placeable.height)
layout(size, size) {
placeable.placeRelative(
x = (size - placeable.width) / 2,
y = (size - placeable.height) / 2,
)
)
}
}).clip(CircleShape),
flipHorizontally = true,
)
}
},
flipHorizontally = true,
)
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions shared/src/commonMain/kotlin/xyz/xfqlittlefan/fhraise/Logger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package xyz.xfqlittlefan.fhraise

expect class Logger(name: String) {
val name: String

fun trace(message: Any, throwable: Throwable? = null)
fun debug(message: Any, throwable: Throwable? = null)
fun info(message: Any, throwable: Throwable? = null)
fun warn(message: Any, throwable: Throwable? = null)
fun error(message: Any, throwable: Throwable? = null)
}

val Any.logger: Logger get() = Logger(this::class.let { it.qualifiedName ?: it.toString() })

0 comments on commit fe0ce49

Please sign in to comment.