added Image::draw_image_partial
This commit is contained in:
parent
10f6dc1a05
commit
cb668400f4
18
src/image.rs
18
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<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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue