-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.rs
More file actions
68 lines (53 loc) · 1.47 KB
/
screen.rs
File metadata and controls
68 lines (53 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use super::sdl2::pixels::Color;
use super::sdl2;
use super::sdl2::render;
use super::sdl2::rect::Point;
const WIDTH: usize = 64;
const HEIGHT: usize = 32;
pub struct screen {
renderer: render::Renderer<'static>,
}
impl screen {
pub fn new(sdl_context: &sdl2::Sdl) -> screen {
let video_subsystem = sdl_context.video().unwrap();
let window = video_subsystem.window("CHIP8RUST", WIDTH as u32 * 10, HEIGHT as u32 * 10)
.position_centered()
.build()
.unwrap();
let mut renderer = window.renderer().build().unwrap();
renderer.set_scale(10.0, 10.0);
renderer.set_draw_color(Color::RGB(0, 0, 0));
renderer.clear();
renderer.present();
renderer.set_draw_color(Color::RGB(255, 255, 255));
screen {
renderer: renderer,
}
}
pub fn draw(&mut self, x: i32, y: i32){
self.put(x, y);
self.present();
}
fn present(&mut self){
self.renderer.present();
}
fn put(&mut self, x: i32, y: i32){
self.renderer.draw_point(Point::new(x, y));
}
pub fn draw_array(&mut self, arrays: &Box<[u8;8* 4]>){
for row in 0..4 {
for col in 0..8{
for bit in 0..8 {
if (arrays[row * col + ] & (0b1 << bit)) > 0{
if (x * y + x)
self.put(bit as i32, y as i32);
}else {
self.put((x + bit) as i32, y as i32);
}
}
}
}
}
self.present();
}
}