2019-04-27 17:54:37 +00:00
|
|
|
use crate::backend::render::common::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};
|
|
|
|
|
|
|
|
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-04-27 17:54:37 +00:00
|
|
|
pub fn new(shape_handle: ShapeHandle, x_min: f32, y_min: f32) -> Graphic {
|
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-04-26 03:27:44 +00:00
|
|
|
x_min,
|
|
|
|
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-04-29 05:55:44 +00:00
|
|
|
context.matrix_stack.push(self.get_matrix());
|
|
|
|
context
|
|
|
|
.color_transform_stack
|
|
|
|
.push(self.get_color_transform());
|
2019-04-26 21:11:29 +00:00
|
|
|
|
2019-04-25 17:52:22 +00:00
|
|
|
let world_matrix = context.matrix_stack.matrix();
|
2019-04-26 21:11:29 +00:00
|
|
|
let color_transform = context.color_transform_stack.color_transform();
|
|
|
|
|
2019-04-27 17:54:37 +00:00
|
|
|
context
|
|
|
|
.renderer
|
|
|
|
.render_shape(self.shape_handle, &world_matrix);
|
|
|
|
|
2019-04-29 05:55:44 +00:00
|
|
|
context.color_transform_stack.pop();
|
|
|
|
context.matrix_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
|
|
|
|
}
|
|
|
|
}
|