added Image::draw_image_partial

This commit is contained in:
dani 2023-07-01 21:18:28 +00:00
parent 10f6dc1a05
commit cb668400f4
1 changed files with 16 additions and 2 deletions

View File

@ -1,4 +1,5 @@
use crate::vec2::Vec2; use crate::vec2::Vec2;
use crate::Rect;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
@ -53,9 +54,22 @@ impl Image {
} }
pub fn draw_image(&mut self, pos: Vec2<i32>, image: &Image) { pub fn draw_image(&mut self, pos: Vec2<i32>, image: &Image) {
self.draw_image_partial(
pos,
image,
Rect {
pos: Vec2::zero(),
size: image.size,
},
);
}
pub fn draw_image_partial(&mut self, pos: Vec2<i32>, image: &Image, src_rect: Rect<i32>) {
//todo: write proper implementation later //todo: write proper implementation later
for y in 0..image.size.y { for y in 0..src_rect.size.y {
for x in 0..image.size.x { 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) //todo: implement better(very stupid to do per pixel)
if x + pos.x >= 0 if x + pos.x >= 0
&& y + pos.y >= 0 && y + pos.y >= 0