cleanup
This commit is contained in:
parent
45962a19cd
commit
c223a2d900
11
src/image.rs
11
src/image.rs
|
@ -1,5 +1,4 @@
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
|
||||||
use crate::vec2::Vec2;
|
use crate::vec2::Vec2;
|
||||||
|
|
||||||
//todo: make dynamically different bitdepths
|
//todo: make dynamically different bitdepths
|
||||||
|
@ -48,11 +47,11 @@ impl Image {
|
||||||
|
|
||||||
pub fn draw_image(&mut self, pos: Vec2<i32>, image: &Image) {
|
pub fn draw_image(&mut self, pos: Vec2<i32>, image: &Image) {
|
||||||
//todo: write proper implementation later
|
//todo: write proper implementation later
|
||||||
for y in 0..image.size.y as i32 {
|
for y in 0..image.size.y {
|
||||||
for x in 0..image.size.x as i32 {
|
for x in 0..image.size.x {
|
||||||
//todo: implement better(very stupid to do per pixel)
|
//todo: implement better(very stupid to do per pixel)
|
||||||
if x + pos.x >= 0 && y + pos.y >= 0 && x + pos.x < self.size.x as i32 && y + pos.y < self.size.y as i32 {
|
if x + pos.x >= 0 && y + pos.y >= 0 && x + pos.x < self.size.x && y + pos.y < self.size.y {
|
||||||
let p = image.get_pixel(Vec2 { x, y: y });
|
let p = image.get_pixel(Vec2 { x, y });
|
||||||
if p > 0 {
|
if p > 0 {
|
||||||
self.set_pixel(Vec2 { x: x + pos.x, y: y + pos.y }, p);
|
self.set_pixel(Vec2 { x: x + pos.x, y: y + pos.y }, p);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +74,7 @@ impl Image {
|
||||||
};
|
};
|
||||||
let xs = xdiff / step;
|
let xs = xdiff / step;
|
||||||
let ys = ydiff / step;
|
let ys = ydiff / step;
|
||||||
for i in 1..=(step as i32) {
|
for _ in 1..=(step as i32) {
|
||||||
self.set_pixel(Vec2 { x: x as i32, y: y as i32 }, color);
|
self.set_pixel(Vec2 { x: x as i32, y: y as i32 }, color);
|
||||||
x += xs;
|
x += xs;
|
||||||
y += ys;
|
y += ys;
|
||||||
|
|
|
@ -9,9 +9,9 @@ pub struct Rect<T: Num + Copy> {
|
||||||
|
|
||||||
impl<T: Num + Copy> Rect<T> {
|
impl<T: Num + Copy> Rect<T> {
|
||||||
pub fn new(x: T, y: T, w: T, h: T) -> Rect<T> {
|
pub fn new(x: T, y: T, w: T, h: T) -> Rect<T> {
|
||||||
return Rect {
|
Rect {
|
||||||
pos: Vec2{x, y},
|
pos: Vec2{x, y},
|
||||||
size: Vec2{x: w, y: h},
|
size: Vec2{x: w, y: h},
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use pixels::{Pixels, SurfaceTexture};
|
use pixels::{Pixels, SurfaceTexture};
|
||||||
use winit::dpi::LogicalSize;
|
use winit::dpi::LogicalSize;
|
||||||
use winit::event::{ElementState, Event as WinitEvent, VirtualKeyCode, WindowEvent, MouseButton as WinitMouseButton};
|
use winit::event::{ElementState, Event as WinitEvent, WindowEvent, MouseButton as WinitMouseButton};
|
||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
use winit::window::{WindowBuilder};
|
use winit::window::{WindowBuilder};
|
||||||
use crate::image::Image;
|
use crate::image::Image;
|
||||||
|
@ -77,7 +77,7 @@ pub fn run<T : Game + 'static>(width: i32, height: i32) {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
match event {
|
match event {
|
||||||
WinitEvent::NewEvents(_) => {}
|
WinitEvent::NewEvents(_) => {}
|
||||||
WinitEvent::WindowEvent { window_id, event: window_event } => {
|
WinitEvent::WindowEvent { event: window_event, .. } => {
|
||||||
match window_event {
|
match window_event {
|
||||||
WindowEvent::Resized(_) => {}
|
WindowEvent::Resized(_) => {}
|
||||||
WindowEvent::Moved(_) => {}
|
WindowEvent::Moved(_) => {}
|
||||||
|
|
Loading…
Reference in New Issue