2019-05-03 02:11:47 +00:00
|
|
|
use crate::backend::render::ShapeHandle;
|
2019-04-26 21:11:29 +00:00
|
|
|
use crate::color_transform::ColorTransform;
|
2019-04-29 05:55:44 +00:00
|
|
|
use crate::display_object::{DisplayObjectBase, DisplayObjectImpl, DisplayObjectUpdate};
|
2019-04-27 01:55:06 +00:00
|
|
|
use crate::matrix::Matrix;
|
|
|
|
use crate::player::{RenderContext, UpdateContext};
|
2019-04-25 17:52:22 +00:00
|
|
|
use bacon_rajan_cc::{Trace, Tracer};
|
|
|
|
|
2019-05-07 10:22:58 +00:00
|
|
|
#[derive(Clone)]
|
2019-04-25 17:52:22 +00:00
|
|
|
pub struct Graphic {
|
2019-04-29 05:55:44 +00:00
|
|
|
base: DisplayObjectBase,
|
2019-04-27 17:54:37 +00:00
|
|
|
shape_handle: ShapeHandle,
|
2019-04-26 03:27:44 +00:00
|
|
|
x_min: f32,
|
|
|
|
y_min: f32,
|
2019-04-25 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Graphic {
|
2019-05-07 10:22:58 +00:00
|
|
|
pub fn from_swf_tag(swf_shape: &swf::Shape, context: &mut UpdateContext) -> Graphic {
|
|
|
|
let shape_handle = context.renderer.register_shape(swf_shape);
|
2019-04-25 17:52:22 +00:00
|
|
|
Graphic {
|
2019-04-29 05:55:44 +00:00
|
|
|
base: Default::default(),
|
2019-04-27 17:54:37 +00:00
|
|
|
shape_handle,
|
2019-05-07 10:22:58 +00:00
|
|
|
x_min: swf_shape.shape_bounds.x_min,
|
|
|
|
y_min: swf_shape.shape_bounds.y_min,
|
2019-04-25 17:52:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-29 05:55:44 +00:00
|
|
|
impl_display_object!(Graphic, base);
|
|
|
|
|
|
|
|
impl DisplayObjectUpdate for Graphic {
|
2019-04-26 03:27:44 +00:00
|
|
|
fn run_frame(&mut self, _context: &mut UpdateContext) {
|
2019-04-25 17:52:22 +00:00
|
|
|
// Noop
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render(&self, context: &mut RenderContext) {
|
2019-05-01 16:55:54 +00:00
|
|
|
context.transform_stack.push(self.transform());
|
2019-04-26 21:11:29 +00:00
|
|
|
|
2019-04-27 17:54:37 +00:00
|
|
|
context
|
|
|
|
.renderer
|
2019-05-01 16:55:54 +00:00
|
|
|
.render_shape(self.shape_handle, context.transform_stack.transform());
|
2019-04-27 17:54:37 +00:00
|
|
|
|
2019-05-01 16:55:54 +00:00
|
|
|
context.transform_stack.pop();
|
2019-04-26 21:11:29 +00:00
|
|
|
}
|
2019-04-25 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Trace for Graphic {
|
|
|
|
fn trace(&mut self, _tracer: &mut Tracer) {
|
|
|
|
// Noop
|
|
|
|
}
|
|
|
|
}
|