2019-04-27 01:55:06 +00:00
|
|
|
use crate::player::{RenderContext, UpdateContext};
|
2019-04-29 05:55:44 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
use crate::transform::Transform;
|
2019-05-24 17:25:03 +00:00
|
|
|
use gc_arena::{Collect, GcCell};
|
2019-04-25 17:52:22 +00:00
|
|
|
|
2019-05-24 17:25:03 +00:00
|
|
|
#[derive(Clone, Collect)]
|
|
|
|
#[collect(empty_drop)]
|
2019-04-29 05:55:44 +00:00
|
|
|
pub struct DisplayObjectBase {
|
|
|
|
depth: Depth,
|
|
|
|
transform: Transform,
|
2019-05-06 18:15:52 +00:00
|
|
|
name: String,
|
2019-05-12 17:48:00 +00:00
|
|
|
clip_depth: Depth,
|
2019-04-25 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 05:55:44 +00:00
|
|
|
impl Default for DisplayObjectBase {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
depth: Default::default(),
|
|
|
|
transform: Default::default(),
|
2019-05-06 18:15:52 +00:00
|
|
|
name: Default::default(),
|
2019-05-12 17:48:00 +00:00
|
|
|
clip_depth: Default::default(),
|
2019-04-26 03:27:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-29 05:55:44 +00:00
|
|
|
}
|
2019-04-26 03:27:44 +00:00
|
|
|
|
2019-05-24 17:25:03 +00:00
|
|
|
impl<'gc> DisplayObject<'gc> for DisplayObjectBase {
|
2019-05-01 16:55:54 +00:00
|
|
|
fn transform(&self) -> &Transform {
|
|
|
|
&self.transform
|
|
|
|
}
|
|
|
|
|
2019-04-29 05:55:44 +00:00
|
|
|
fn get_matrix(&self) -> &Matrix {
|
|
|
|
&self.transform.matrix
|
2019-04-25 17:52:22 +00:00
|
|
|
}
|
2019-04-29 05:55:44 +00:00
|
|
|
fn set_matrix(&mut self, matrix: &Matrix) {
|
2019-05-03 18:44:12 +00:00
|
|
|
self.transform.matrix = *matrix;
|
2019-04-26 03:27:44 +00:00
|
|
|
}
|
2019-04-29 05:55:44 +00:00
|
|
|
fn get_color_transform(&self) -> &ColorTransform {
|
|
|
|
&self.transform.color_transform
|
|
|
|
}
|
|
|
|
fn set_color_transform(&mut self, color_transform: &ColorTransform) {
|
2019-05-03 18:44:12 +00:00
|
|
|
self.transform.color_transform = *color_transform;
|
2019-04-25 17:52:22 +00:00
|
|
|
}
|
2019-05-06 18:15:52 +00:00
|
|
|
fn name(&self) -> &str {
|
|
|
|
&self.name
|
|
|
|
}
|
|
|
|
fn set_name(&mut self, name: &str) {
|
|
|
|
self.name = name.to_string();
|
|
|
|
}
|
2019-05-12 17:48:00 +00:00
|
|
|
fn clip_depth(&self) -> Depth {
|
|
|
|
self.clip_depth
|
|
|
|
}
|
|
|
|
fn set_clip_depth(&mut self, depth: Depth) {
|
|
|
|
self.clip_depth = depth;
|
|
|
|
}
|
2019-05-24 17:25:03 +00:00
|
|
|
fn box_clone(&self) -> Box<DisplayObject<'gc>> {
|
2019-05-09 01:10:43 +00:00
|
|
|
Box::new(self.clone())
|
|
|
|
}
|
2019-04-29 05:55:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 17:25:03 +00:00
|
|
|
pub trait DisplayObject<'gc>: 'gc + Collect {
|
2019-05-01 16:55:54 +00:00
|
|
|
fn transform(&self) -> &Transform;
|
2019-04-29 05:55:44 +00:00
|
|
|
fn get_matrix(&self) -> &Matrix;
|
|
|
|
fn set_matrix(&mut self, matrix: &Matrix);
|
|
|
|
fn get_color_transform(&self) -> &ColorTransform;
|
|
|
|
fn set_color_transform(&mut self, color_transform: &ColorTransform);
|
2019-05-06 18:15:52 +00:00
|
|
|
fn name(&self) -> &str;
|
|
|
|
fn set_name(&mut self, name: &str);
|
2019-05-12 17:48:00 +00:00
|
|
|
fn clip_depth(&self) -> Depth;
|
|
|
|
fn set_clip_depth(&mut self, depth: Depth);
|
2019-04-26 21:11:29 +00:00
|
|
|
|
2019-05-24 17:25:03 +00:00
|
|
|
fn preload(&mut self, _context: &mut UpdateContext<'_, 'gc, '_>) {}
|
|
|
|
fn run_frame(&mut self, _context: &mut UpdateContext<'_, 'gc, '_>) {}
|
|
|
|
fn run_post_frame(&mut self, _context: &mut UpdateContext<'_, 'gc, '_>) {}
|
|
|
|
fn render(&self, _context: &mut RenderContext<'_, 'gc>) {}
|
2019-05-03 18:44:12 +00:00
|
|
|
|
|
|
|
fn handle_click(&mut self, _pos: (f32, f32)) {}
|
2019-05-24 17:25:03 +00:00
|
|
|
fn as_movie_clip(&self) -> Option<&crate::movie_clip::MovieClip<'gc>> {
|
2019-05-07 06:31:34 +00:00
|
|
|
None
|
|
|
|
}
|
2019-05-24 17:25:03 +00:00
|
|
|
fn as_movie_clip_mut(&mut self) -> Option<&mut crate::movie_clip::MovieClip<'gc>> {
|
2019-05-07 06:31:34 +00:00
|
|
|
None
|
|
|
|
}
|
2019-05-12 16:55:48 +00:00
|
|
|
fn as_morph_shape(&self) -> Option<&crate::morph_shape::MorphShape> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn as_morph_shape_mut(&mut self) -> Option<&mut crate::morph_shape::MorphShape> {
|
|
|
|
None
|
|
|
|
}
|
2019-05-24 17:25:03 +00:00
|
|
|
fn box_clone(&self) -> Box<DisplayObject<'gc>>;
|
2019-05-09 01:10:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 17:25:03 +00:00
|
|
|
impl<'gc> Clone for Box<DisplayObject<'gc>> {
|
|
|
|
fn clone(&self) -> Box<DisplayObject<'gc>> {
|
2019-05-09 01:10:43 +00:00
|
|
|
self.box_clone()
|
|
|
|
}
|
2019-04-29 05:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_display_object {
|
2019-05-07 10:34:17 +00:00
|
|
|
($field:ident) => {
|
2019-05-09 01:10:43 +00:00
|
|
|
fn transform(&self) -> &crate::transform::Transform {
|
|
|
|
self.$field.transform()
|
|
|
|
}
|
|
|
|
fn get_matrix(&self) -> &Matrix {
|
|
|
|
self.$field.get_matrix()
|
|
|
|
}
|
|
|
|
fn set_matrix(&mut self, matrix: &Matrix) {
|
|
|
|
self.$field.set_matrix(matrix)
|
|
|
|
}
|
|
|
|
fn get_color_transform(&self) -> &ColorTransform {
|
|
|
|
self.$field.get_color_transform()
|
|
|
|
}
|
|
|
|
fn set_color_transform(&mut self, color_transform: &ColorTransform) {
|
|
|
|
self.$field.set_color_transform(color_transform)
|
|
|
|
}
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
self.$field.name()
|
|
|
|
}
|
|
|
|
fn set_name(&mut self, name: &str) {
|
|
|
|
self.$field.set_name(name)
|
|
|
|
}
|
2019-05-12 17:48:00 +00:00
|
|
|
fn clip_depth(&self) -> $crate::prelude::Depth {
|
|
|
|
self.$field.clip_depth()
|
|
|
|
}
|
|
|
|
fn set_clip_depth(&mut self, depth: $crate::prelude::Depth) {
|
|
|
|
self.$field.set_clip_depth(depth)
|
|
|
|
}
|
2019-05-24 17:25:03 +00:00
|
|
|
fn box_clone(&self) -> Box<$crate::display_object::DisplayObject<'gc>> {
|
2019-05-09 01:10:43 +00:00
|
|
|
Box::new(self.clone())
|
|
|
|
}
|
2019-04-29 05:55:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-24 17:25:03 +00:00
|
|
|
/// `DisplayNode` is the garbage-collected pointer between display objects.
|
|
|
|
/// TODO(Herschel): The extra Box here is necessary to hold the trait object inside a GC pointer,
|
|
|
|
/// but this is an extra allocation... Can we avoid this, maybe with a DST?
|
|
|
|
pub type DisplayNode<'gc> = GcCell<'gc, Box<dyn DisplayObject<'gc>>>;
|