use libc::c_float;
use sfml_types::Vector2f;
use graphics::FloatRect;
use csfml_graphics_sys as ffi;
#[repr(C)]
pub struct Transform(pub ffi::sfTransform);
impl Transform {
pub fn new(a00: f32, a01: f32, a02: f32,
b10: f32, b11: f32, b12: f32,
c20: f32, c21: f32, c22: f32) -> Transform {
unsafe {
Transform(ffi::sfTransform_fromMatrix(a00, a01, a02,
b10, b11, b12,
c20, c21, c22))
}
}
pub fn get_matrix(&mut self) -> [f32; 16] {
unsafe {
let matrix: [f32; 16] =
[0.,0.,0.,0.,
0.,0.,0.,0.,
0.,0.,0.,0.,
0.,0.,0.,0.];
ffi::sfTransform_getMatrix(&mut self.0, matrix.as_ptr() as *mut f32);
matrix
}
}
pub fn new_identity() -> Transform {
unsafe {
Transform(ffi::sfTransform_fromMatrix(1., 0., 0., 0., 1., 0., 0., 0., 1.))
}
}
pub fn get_inverse(&mut self) -> Transform {
unsafe {
Transform(ffi::sfTransform_getInverse(&mut self.0))
}
}
pub fn combine(&mut self, other: &mut Transform) {
unsafe {
ffi::sfTransform_combine(&mut self.0, &mut other.0)
}
}
pub fn translate(&mut self, x: f32, y: f32) {
unsafe {
ffi::sfTransform_translate(&mut self.0, x as c_float, y as c_float)
}
}
pub fn rotate(&mut self, angle: f32) {
unsafe {
ffi::sfTransform_rotate(&mut self.0, angle as c_float)
}
}
pub fn rotate_with_center(&mut self,
angle: f32,
center_x: f32,
center_y: f32) {
unsafe {
ffi::sfTransform_rotateWithCenter(&mut self.0,
angle as c_float,
center_x as c_float,
center_y as c_float)
}
}
pub fn scale(&mut self, scale_x: f32, scale_y: f32) {
unsafe {
ffi::sfTransform_scale(&mut self.0, scale_x as c_float, scale_y as c_float)
}
}
pub fn scale_with_center(&mut self,
scale_x: f32,
scale_y: f32,
center_x: f32,
center_y: f32) {
unsafe {
ffi::sfTransform_scaleWithCenter(&mut self.0,
scale_x,
scale_y,
center_x,
center_y)
}
}
pub fn transform_point(&mut self, point: &Vector2f) -> Vector2f {
unsafe {
ffi::sfTransform_transformPoint(&mut self.0, *point)
}
}
pub fn transform_rect(&mut self, rectangle: &FloatRect) -> FloatRect {
unsafe {
ffi::sfTransform_transformRect(&mut self.0, *rectangle)
}
}
}