Move separated Position when the composition frame is resized or cropped.
Those edits offset the combined Position property, which a separated layer does not render. X and Y Position, including their keys, now move by the same amount.
This commit is contained in:
@@ -36,19 +36,8 @@ fn apply_settings(c: &mut Comp, p: &Value) {
|
||||
let dy = (c.height as f64 - oh as f64) * (a / 3) as f64 / 2.0;
|
||||
if dx != 0.0 || dy != 0.0 {
|
||||
for l in c.layers.iter_mut().filter(|l| l.parent.is_none()) {
|
||||
let Some(pr) = l.props.prop_mut("transform/position") else { continue };
|
||||
let shift = |v: &mut effectcraft_keyframe::Value| {
|
||||
if let effectcraft_keyframe::Value::Vec2(x) = v {
|
||||
x[0] += dx;
|
||||
x[1] += dy;
|
||||
} else if let effectcraft_keyframe::Value::Vec3(x) = v {
|
||||
x[0] += dx;
|
||||
x[1] += dy;
|
||||
}
|
||||
};
|
||||
shift(&mut pr.value);
|
||||
for k in &mut pr.keys {
|
||||
shift(&mut k.value);
|
||||
if let Some(tr) = l.transform_mut() {
|
||||
super::layer::offset_position(tr, dx, dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Composition menu, part two: crop to region of interest / layer bounds, Save Frame As ▸ File,
|
||||
//! Responsive Design — Time.
|
||||
|
||||
use effectcraft_keyframe::Value as KV;
|
||||
use effectcraft_project::Marker;
|
||||
use effectcraft_time::Tick;
|
||||
use serde_json::{Value, json};
|
||||
@@ -24,14 +23,8 @@ fn crop(s: &mut Session, cid: effectcraft_project::ItemId, r: [f64; 4], label: &
|
||||
c.width = w;
|
||||
c.height = h;
|
||||
for l in c.layers.iter_mut().filter(|l| l.parent.is_none()) {
|
||||
let Some(pos) = l.transform_mut().and_then(|tr| tr.get_mut("position")) else { continue };
|
||||
let mv = |v: &KV| {
|
||||
let a = v.as_vec3();
|
||||
KV::Vec3([a[0] - x, a[1] - y, a[2]])
|
||||
};
|
||||
pos.value = mv(&pos.value);
|
||||
for k in &mut pos.keys {
|
||||
k.value = mv(&k.value);
|
||||
if let Some(tr) = l.transform_mut() {
|
||||
super::layer::offset_position(tr, -x, -y);
|
||||
}
|
||||
}
|
||||
for g in &mut c.guides {
|
||||
|
||||
@@ -1124,6 +1124,37 @@ fn set_text(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
/// Move Position by `(dx, dy)`, including every key. Separated dimensions move X and Y as well
|
||||
/// as the combined property the channels were split from.
|
||||
pub(crate) fn offset_position(tr: &mut PropGroup, dx: f64, dy: f64) {
|
||||
if dx == 0.0 && dy == 0.0 {
|
||||
return;
|
||||
}
|
||||
if tr.get("positionX").is_some() {
|
||||
for (name, d) in [("positionX", dx), ("positionY", dy)] {
|
||||
if let Some(pr) = tr.get_mut(name) {
|
||||
pr.value = KV::Scalar(pr.value.as_f64() + d);
|
||||
for k in &mut pr.keys {
|
||||
k.value = KV::Scalar(k.value.as_f64() + d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(pr) = tr.get_mut("position") {
|
||||
let shift = |v: &KV| match v {
|
||||
KV::Vec2(a) => KV::Vec2([a[0] + dx, a[1] + dy]),
|
||||
other => {
|
||||
let a = other.as_vec3();
|
||||
KV::Vec3([a[0] + dx, a[1] + dy, a[2]])
|
||||
}
|
||||
};
|
||||
pr.value = shift(&pr.value);
|
||||
for k in &mut pr.keys {
|
||||
k.value = shift(&k.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set a layer's Position at layer time `lt` to `f(current)`: X/Y/Z Position when its dimensions
|
||||
/// are separated.
|
||||
pub(crate) fn update_position(tr: &mut PropGroup, lt: Tick, f: impl Fn([f64; 3]) -> [f64; 3]) {
|
||||
|
||||
Reference in New Issue
Block a user