Commit 0fb09bef authored by David's avatar David

Working on the camera view

parent 3750cbc7
package `is`.kow.deskscreen
import `is`.kow.deskscreen.views.DefaultView
import `is`.kow.deskscreen.camera.CameraView
import `is`.kow.deskscreen.system.SystemView
import `is`.kow.deskscreen.views.DefaultView
import `is`.kow.deskscreen.wx.LoadingView
import `is`.kow.deskscreen.wx.RadarView
import mu.KotlinLogging
......@@ -20,6 +21,7 @@ class TransitionsController : Controller() {
private val loadingView: LoadingView by inject()
private val radarView: RadarView by inject()
private val infoView: SystemView by inject()
private val cameraView: CameraView by inject()
private val currentView = AtomicReference<View>()
......@@ -46,6 +48,11 @@ class TransitionsController : Controller() {
setView(infoView)
}
fun showCameraView() {
logger.debug("Switching to camera view")
setView(cameraView)
}
private fun setView(thing: View) {
//TODO: there's something wrong here, I haven't done it right...
currentView.getAndSet(thing).replaceWith(thing)
......
package `is`.kow.deskscreen.camera
import javafx.beans.binding.Bindings
import javafx.beans.property.SimpleObjectProperty
import javafx.geometry.Pos
import javafx.scene.control.ProgressBar
import javafx.scene.layout.Priority
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import org.kordamp.ikonli.javafx.FontIcon
import tornadofx.*
import java.awt.image.BufferedImage
enum class PictureTakingState {
READY, TAKING, PREVIEWING, GOOD
}
class CameraState {
val imageProperty = SimpleObjectProperty<BufferedImage>(this, "image", null)
var image by imageProperty
val stateProperty = SimpleObjectProperty<PictureTakingState>(this, "state", PictureTakingState.READY)
var state by stateProperty
}
class CameraStateModel : ItemViewModel<CameraState>() {
val image: SimpleObjectProperty<BufferedImage> = bind(CameraState::imageProperty)
val state: SimpleObjectProperty<PictureTakingState> = bind(CameraState::stateProperty)
val previewing = Bindings.equal(PictureTakingState.PREVIEWING, state)
val readyToTake = Bindings.equal(PictureTakingState.READY, state) //Huh, why isn't that true to start with....
}
class CameraView : View() {
private val cameraLoadingView: CameraLoadingView by inject()
private val cameraStateModel: CameraStateModel by inject()
class CameraView: View() {
override val root = borderpane {
center = label("LOADING SPINNER UNTIL I SWAP IT")
left = label("Figure out the left size")
right = label("Figure out the right size")
//Left and right can be 160px max
center = cameraLoadingView.root
right = vbox {
prefWidth = 160.0
hbox {
alignment = Pos.CENTER
button("", FontIcon.of(FontAwesomeSolid.CHECK_SQUARE, 60)) {
enableWhen {
cameraStateModel.previewing
}
//Picture is good, enabled only after a capture
//Make it green
}
}
//Kinda want a space in-between these two
button("Take Picture!") {
//Call the controller action that updates the model and starts the count down
enableWhen {
//this should start off enabled, but it's not... that's weird.
cameraStateModel.readyToTake
}
}
hbox {
label("Delay to take picture")
progressbar {
//countdown timer for photo taking
//Set max width to the same as something?
}
}
}
left = vbox {
prefWidth = 160.0
hbox {
alignment = Pos.CENTER
button("", FontIcon.of(FontAwesomeSolid.WINDOW_CLOSE, 60)) {
//Picture is no good, don't keep it
enableWhen {
cameraStateModel.previewing
}
}
}
}
}
}
class CameraLoadingView : View() {
override val root = hbox {
vgrow = Priority.ALWAYS
hgrow = Priority.ALWAYS
alignment = Pos.CENTER
progressindicator {
progress = ProgressBar.INDETERMINATE_PROGRESS
}
}
}
\ No newline at end of file
}
package `is`.kow.deskscreen.views
import `is`.kow.deskscreen.Styles
import `is`.kow.deskscreen.camera.CameraController
import `is`.kow.deskscreen.TransitionsController
import `is`.kow.deskscreen.temperature.TemperatureView
import com.github.thomasnield.rxkotlinfx.actionEvents
import io.reactivex.schedulers.Schedulers
import javafx.geometry.Pos
import javafx.scene.paint.CycleMethod
import javafx.scene.paint.LinearGradient
......@@ -13,14 +11,13 @@ import mu.KotlinLogging
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import org.kordamp.ikonli.javafx.FontIcon
import tornadofx.*
import java.util.*
//TODO: need to ensure a max width
class NamePlateView : View() {
private val logger = KotlinLogging.logger {}
private val temperatureView: TemperatureView by inject()
private val cameraController: CameraController by inject()
private val transitionsController: TransitionsController by inject()
override val root = borderpane {
style {
......@@ -62,18 +59,9 @@ class NamePlateView : View() {
style {
baseColor = c("black")
}
//TODO: switch to a view that uses the sides to display a countdown, and then displays the rendered image after taking
//And allows for a retake....
//TODO: then figure out what to do with the image?
actionEvents()
.observeOn(Schedulers.io())
.map {
Optional.ofNullable(cameraController.takePicture()) //TODO: Need to wrap in optional for desktop
}
.doOnNext {
logger.error("PICTURE TAKEN!")
}
.subscribe()
action {
transitionsController.showCameraView()
}
}
right = temperatureView.root
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment