[Editor] Add working opacity parameter to Image Layer

This commit is contained in:
2021-02-20 10:33:42 +01:00
parent f2fe303e31
commit 53c24c9b99
4 changed files with 46 additions and 23 deletions

View File

@@ -133,7 +133,7 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr
private fun renderImageLayer(gc: GraphicsContext, imageLayer: ImageLayer) {
imageLayer.image?.let {
val alpha = gc.globalAlpha
gc.globalAlpha = imageLayer.alpha / 100.0
gc.globalAlpha = imageLayer.opacity / 100.0
gc.drawImage(it, 0.0, 0.0)

View File

@@ -8,7 +8,7 @@ import javafx.scene.image.Image
import tornadofx.getValue
import tornadofx.setValue
class ImageLayer(name: String, imageAsset: ImageAsset, alpha: Int) : Layer {
class ImageLayer(name: String, imageAsset: ImageAsset, opacity: Int) : Layer {
override val nameProperty = SimpleStringProperty(name)
override var name by nameProperty
@@ -22,8 +22,8 @@ class ImageLayer(name: String, imageAsset: ImageAsset, alpha: Int) : Layer {
val image by imageProperty
val alphaProperty = SimpleObjectProperty(alpha)
var alpha by alphaProperty
val opacityProperty = SimpleObjectProperty(opacity)
var opacity by opacityProperty
override fun resize(rows: Int, columns: Int) {
// We essentially need to do nothing

View File

@@ -9,24 +9,36 @@ import org.springframework.stereotype.Component
@Component
class ColorLayerParametersBinder : LayerParametersBinder<ColorLayer> {
override fun bind(layer: ColorLayer, parameters: ObservableList<Parameter<*>>, project: Project, onCommit: () -> Unit) {
val red = IntegerParameter("red", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
val green = IntegerParameter("green", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
val blue = IntegerParameter("blue", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
val alpha = IntegerParameter("alpha", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
private var red: IntegerParameter? = null
private var green: IntegerParameter? = null
private var blue: IntegerParameter? = null
private var alpha: IntegerParameter? = null
red.valueProperty.bindBidirectional(layer.redProperty)
green.valueProperty.bindBidirectional(layer.greenProperty)
blue.valueProperty.bindBidirectional(layer.blueProperty)
alpha.valueProperty.bindBidirectional(layer.alphaProperty)
override fun bind(
layer: ColorLayer,
parameters: ObservableList<Parameter<*>>,
project: Project,
onCommit: () -> Unit
) {
val red = IntegerParameter("red", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
.apply { valueProperty.bindBidirectional(layer.redProperty) }
val green = IntegerParameter("green", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
.apply { valueProperty.bindBidirectional(layer.greenProperty) }
val blue = IntegerParameter("blue", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
.apply { valueProperty.bindBidirectional(layer.blueProperty) }
val alpha = IntegerParameter("alpha", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
.apply { valueProperty.bindBidirectional(layer.alphaProperty) }
parameters.addAll(red, green, blue, alpha)
}
override fun unbind(layer: ColorLayer, parameters: ObservableList<Parameter<*>>) {
(parameters[0] as IntegerParameter).valueProperty.unbindBidirectional(layer.redProperty)
(parameters[1] as IntegerParameter).valueProperty.unbindBidirectional(layer.greenProperty)
(parameters[2] as IntegerParameter).valueProperty.unbindBidirectional(layer.blueProperty)
(parameters[3] as IntegerParameter).valueProperty.unbindBidirectional(layer.alphaProperty)
red?.valueProperty?.unbindBidirectional(layer.redProperty)
green?.valueProperty?.unbindBidirectional(layer.greenProperty)
blue?.valueProperty?.unbindBidirectional(layer.blueProperty)
alpha?.valueProperty?.unbindBidirectional(layer.alphaProperty)
}
}

View File

@@ -1,6 +1,7 @@
package com.bartlomiejpluta.base.editor.map.parameter.layer
import com.bartlomiejpluta.base.editor.common.parameter.model.GraphicAssetParameter
import com.bartlomiejpluta.base.editor.common.parameter.model.IntegerParameter
import com.bartlomiejpluta.base.editor.common.parameter.model.Parameter
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer
@@ -10,19 +11,29 @@ import org.springframework.stereotype.Component
@Component
class ImageLayerParametersBinder : LayerParametersBinder<ImageLayer> {
private var image: GraphicAssetParameter<ImageAsset>? = null
private var opacity: IntegerParameter? = null
override fun bind(layer: ImageLayer, parameters: ObservableList<Parameter<*>>, project: Project, onCommit: () -> Unit) {
val image = GraphicAssetParameter("image", layer.imageAsset, true, project.images) { _, _, submit ->
override fun bind(
layer: ImageLayer,
parameters: ObservableList<Parameter<*>>,
project: Project,
onCommit: () -> Unit
) {
image = GraphicAssetParameter("image", layer.imageAsset, true, project.images) { _, _, submit ->
onCommit()
submit()
}
}.apply { valueProperty.bindBidirectional(layer.imageAssetProperty) }
image.valueProperty.bindBidirectional(layer.imageAssetProperty)
opacity = IntegerParameter("opacity", 100, 0, 100, autocommit = true) { _, _, _ ->
onCommit()
}.apply { valueProperty.bindBidirectional(layer.opacityProperty) }
parameters.addAll(image)
parameters.addAll(image, opacity)
}
override fun unbind(layer: ImageLayer, parameters: ObservableList<Parameter<*>>) {
(parameters[0] as GraphicAssetParameter<ImageAsset>).valueProperty.unbindBidirectional(layer.imageAssetProperty)
image?.valueProperty?.unbindBidirectional(layer.imageAssetProperty)
opacity?.valueProperty?.unbindBidirectional(layer.opacityProperty)
}
}