ruffle/render/src/transform.rs

44 lines
1.1 KiB
Rust
Raw Normal View History

use crate::color_transform::ColorTransform;
use crate::matrix::Matrix;
2019-04-29 05:55:44 +00:00
/// Represents the transform for a DisplayObject.
/// This includes both the transformation matrix and the color transform.
#[derive(Clone, Debug, Default)]
2019-04-29 05:55:44 +00:00
pub struct Transform {
pub matrix: Matrix,
pub color_transform: ColorTransform,
}
2019-05-01 16:55:54 +00:00
pub struct TransformStack(Vec<Transform>);
impl TransformStack {
pub fn new() -> Self {
Self(vec![Transform::default()])
}
pub fn push(&mut self, transform: &Transform) {
let cur_transform = self.transform();
2019-05-24 17:25:03 +00:00
let matrix = cur_transform.matrix * transform.matrix;
let color_transform = cur_transform.color_transform * transform.color_transform;
self.0.push(Transform {
matrix,
color_transform,
});
2019-05-01 16:55:54 +00:00
}
pub fn pop(&mut self) {
assert!(self.0.len() > 1, "Transform stack underflow");
2019-05-01 16:55:54 +00:00
self.0.pop();
}
pub fn transform(&self) -> &Transform {
&self.0[self.0.len() - 1]
}
}
2019-05-24 17:25:03 +00:00
impl Default for TransformStack {
fn default() -> Self {
TransformStack::new()
}
}