ruffle/src/graphic.rs

64 lines
1.6 KiB
Rust
Raw Normal View History

2019-04-25 17:52:22 +00:00
use crate::display_object::DisplayObject;
use crate::library::Library;
use crate::Matrix;
2019-04-26 03:27:44 +00:00
use crate::{RenderContext, UpdateContext};
2019-04-25 17:52:22 +00:00
use bacon_rajan_cc::{Trace, Tracer};
2019-04-26 03:27:44 +00:00
use log::{info, trace, warn};
2019-04-25 17:52:22 +00:00
use web_sys::HtmlImageElement;
pub struct Graphic {
matrix: Matrix,
2019-04-26 03:27:44 +00:00
x_min: f32,
y_min: f32,
2019-04-25 17:52:22 +00:00
image: HtmlImageElement,
}
impl Graphic {
2019-04-26 03:27:44 +00:00
pub fn new(image: HtmlImageElement, x_min: f32, y_min: f32) -> Graphic {
2019-04-25 17:52:22 +00:00
Graphic {
image,
2019-04-26 03:27:44 +00:00
x_min,
y_min,
2019-04-25 17:52:22 +00:00
matrix: std::default::Default::default(),
}
}
}
impl DisplayObject 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) {
context.matrix_stack.push(&self.matrix);
let world_matrix = context.matrix_stack.matrix();
context
.context_2d
2019-04-26 03:27:44 +00:00
.set_transform(
2019-04-25 17:52:22 +00:00
world_matrix.a.into(),
world_matrix.b.into(),
world_matrix.c.into(),
world_matrix.d.into(),
world_matrix.tx.into(),
world_matrix.ty.into(),
)
.unwrap();
context
.context_2d
2019-04-26 03:27:44 +00:00
.draw_image_with_html_image_element(&self.image, self.x_min.into(), self.y_min.into())
.expect("Couldn't render image");
2019-04-25 17:52:22 +00:00
context.matrix_stack.pop();
}
2019-04-26 03:27:44 +00:00
fn set_matrix(&mut self, matrix: Matrix) {
self.matrix = matrix;
}
2019-04-25 17:52:22 +00:00
}
impl Trace for Graphic {
fn trace(&mut self, _tracer: &mut Tracer) {
// Noop
}
}