mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +01:00
Layers: a height-combination mask makes the layer's height blend Normal
Where the mask shows the layer, its height now replaces the height below instead of mixing with it, in the same undo step as the mask.
This commit is contained in:
1 parent
53c501e488
commit
f7795c349b
2 files changed
+30
-5
No files matched your search
@@ -1,10 +1,10 @@
|
||||
//! The layer toolbar's Add mask items that add a mask with an effect in it (a bitmap, a height combination) and Add effect's colour selection
|
||||
|
||||
use serde_json::Value;
|
||||
use texturecraft_core::{BlendMode, EffectKind, Sampling, Source};
|
||||
use texturecraft_core::{BlendMode, Channel, EffectKind, Sampling, Source};
|
||||
use texturecraft_paint::alphas;
|
||||
|
||||
use crate::commands::{CommandSpec, bad, has_layer, strp};
|
||||
use crate::commands::{CommandSpec, bad, has_layer, layer_param, strp};
|
||||
use crate::mask_cmds::{color_selection, mask_target, new_compare, push_effect_as, push_own_mask_effect};
|
||||
use crate::{Result, Session, cmd};
|
||||
|
||||
@@ -24,9 +24,9 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Add mask with height combination",
|
||||
["Layers", "Mask"],
|
||||
None,
|
||||
"{layer?} → {effect} — a compare mask (this layer's height greater than the layers below it, hardness 0.9) in the layer's mask (a new one if it has none); selected",
|
||||
"{layer?} → {effect} — a compare mask (this layer's height greater than the layers below it, hardness 0.9) in the layer's mask (a new one if it has none); selected. The layer's height channel, if it has one, blends Normal",
|
||||
has_layer,
|
||||
|s, p| push_own_mask_effect(s, p, new_compare(), "Add mask with height combination", |_| Ok(()))
|
||||
|s, p| push_own_mask_effect(s, p, new_compare(), "Add mask with height combination", |s| height_blends_normal(s, p))
|
||||
),
|
||||
cmd!(
|
||||
"effect.add.colorSelection",
|
||||
@@ -40,6 +40,16 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
]
|
||||
}
|
||||
|
||||
/// Where a height-combination mask shows the layer, the layer's height replaces the height below instead of mixing with it
|
||||
fn height_blends_normal(s: &mut Session, p: &Value) -> Result<()> {
|
||||
let id = layer_param(s, "mask.add.heightCombination", p)?;
|
||||
if let Some(blend) = s.doc.project.layers.get_mut(&id).and_then(|layer| layer.channels.get_mut(&Channel::Height)) {
|
||||
blend.mode = BlendMode::Normal;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A mask fill reading an image resource or a library alpha, in one undo step with the alpha's resource
|
||||
fn add_bitmap(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const CMD: &str = "mask.add.bitmap";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The layer toolbar's Add mask items that add a mask with an effect in it, and Add effect's colour selection: one undo step each, the new effect selected
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_engine::core::{Channel, CompareSource, EffectKind, LayerId, MaskBackground, Source};
|
||||
use texturecraft_engine::core::{BlendMode, Channel, CompareSource, EffectKind, LayerId, MaskBackground, Source};
|
||||
use texturecraft_engine::fill_alpha::resource_name;
|
||||
use texturecraft_engine::geom::primitives;
|
||||
use texturecraft_engine::paint::alphas;
|
||||
@@ -75,6 +75,21 @@ fn a_height_combination_is_a_mask_comparing_this_layers_height_with_the_layers_b
|
||||
assert_eq!(s.history_labels().last().map(String::as_str), Some("Add mask with height combination"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_height_combination_makes_the_layers_height_blend_normal_in_the_same_step() {
|
||||
let (mut s, layer) = fill();
|
||||
execute(&mut s, "layer.blend", &json!({"layer": layer.0, "channel": "height", "enabled": true, "mode": "linearDodge"})).unwrap();
|
||||
let height_mode = |s: &Session| s.doc.project.layer(layer).unwrap().channels.get(&Channel::Height).map(|blend| blend.mode);
|
||||
let before = height_mode(&s);
|
||||
assert!(before.is_some_and(|mode| mode != BlendMode::Normal), "the height starts out blending another way");
|
||||
|
||||
execute(&mut s, "mask.add.heightCombination", &json!({"layer": layer.0})).unwrap();
|
||||
assert_eq!(height_mode(&s), Some(BlendMode::Normal));
|
||||
|
||||
execute(&mut s, "edit.undo", &Value::Null).unwrap();
|
||||
assert_eq!(height_mode(&s), before, "one undo takes the mask and the blend back");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn color_selections_go_in_the_mask_and_are_selected() {
|
||||
let (mut s, layer) = fill();
|
||||
|
||||
Reference in new issue
Block a user