use Alignment;
use Draw;
use DrawContext;
use Matrix;
use widgets::image;
#[inline]
pub fn draw<D: ?Sized + Draw>(draw: &DrawContext<D>, empty: &D::ImageResource,
full: &D::ImageResource, progress: f32, alignment: &Alignment)
{
let draw = draw.animation_stop();
let ratio = draw.draw().get_image_width_per_height(empty);
stretch(&draw.enforce_aspect_ratio_downscale(ratio, alignment), empty, full, progress)
}
pub fn stretch<D: ?Sized + Draw>(draw: &DrawContext<D>, empty: &D::ImageResource,
full: &D::ImageResource, progress: f32)
{
assert!(progress >= 0.0);
assert!(progress <= 1.0);
image::stretch(draw, empty);
for num in 0 .. 4 {
let local_percent = (progress - 0.25 * num as f32) / 0.125;
if local_percent <= 0.0 { continue; }
let local_percent = if local_percent >= 1.0 { 1.0 } else { local_percent };
let local_matrix = Matrix::translate(1.0, 1.0);
let local_matrix = Matrix::scale_wh(0.5 * local_percent, 0.5) * local_matrix;
let local_matrix = Matrix::rotate(num as f32 * -3.141592 * 0.5) * local_matrix;
let (uv1, uv3) = match num {
0 => ([0.5, 1.0], [0.5 + 0.5 * local_percent, 1.0]),
1 => ([1.0, 0.5], [1.0, 0.5 - 0.5 * local_percent]),
2 => ([0.5, 0.0], [0.5 - 0.5 * local_percent, 0.0]),
3 => ([0.0, 0.5], [0.0, 0.5 + 0.5 * local_percent]),
_ => unreachable!()
};
draw.draw().draw_triangle(full, &(draw.matrix() * local_matrix), [uv1, [0.5, 0.5], uv3]);
}
for num in 0 .. 4 {
let local_percent = (progress - 0.125 - 0.25 * num as f32) / 0.125;
if local_percent <= 0.0 { continue; }
let local_percent = if local_percent >= 1.0 { 1.0 } else { local_percent };
let local_matrix = Matrix::translate(1.0, 1.0);
let local_matrix = Matrix::scale_wh(0.5 * local_percent, 0.5) * local_matrix;
let local_matrix = Matrix::skew_x(-3.141592 / 4.0) * local_matrix;
let local_matrix = Matrix::rotate((num + 1) as f32 * -3.141592 * 0.5) * local_matrix;
let (uv1, uv3) = match num {
0 => ([1.0, 1.0], [1.0, 1.0 - 0.5 * local_percent]),
1 => ([1.0, 0.0], [1.0 - 0.5 * local_percent, 0.0]),
2 => ([0.0, 0.0], [0.0, 0.0 + 0.5 * local_percent]),
3 => ([0.0, 1.0], [0.0 + 0.5 * local_percent, 1.0]),
_ => unreachable!()
};
draw.draw().draw_triangle(full, &(draw.matrix() * local_matrix), [uv1, [0.5, 0.5], uv3]);
}
}