diff --git a/src/image.rs b/src/image.rs index 6a9749d..ba0fad5 100644 --- a/src/image.rs +++ b/src/image.rs @@ -1,4 +1,5 @@ use crate::vec2::Vec2; +use crate::Rect; use std::fs; use std::fs::File; @@ -53,9 +54,22 @@ impl Image { } pub fn draw_image(&mut self, pos: Vec2, image: &Image) { + self.draw_image_partial( + pos, + image, + Rect { + pos: Vec2::zero(), + size: image.size, + }, + ); + } + + pub fn draw_image_partial(&mut self, pos: Vec2, image: &Image, src_rect: Rect) { //todo: write proper implementation later - for y in 0..image.size.y { - for x in 0..image.size.x { + for y in 0..src_rect.size.y { + for x in 0..src_rect.size.x { + let x = x + src_rect.pos.x; + let y = y + src_rect.pos.y; //todo: implement better(very stupid to do per pixel) if x + pos.x >= 0 && y + pos.y >= 0