1extern crate minilibx;
2
3use minilibx::{Endian, Mlx, MlxError};
4use std::process;
5
6fn main() {
7 let mlx = Mlx::new().unwrap();
8
9 let width = 1080;
10 let height = 720;
11 let window = mlx.new_window(width, height, "Mlx example").unwrap();
12
13 let image = match mlx.new_image(width, height) {
14 Ok(img) => img,
15 Err(e) => match e {
16 MlxError::Any(s) => return println!("{}", s),
17 _ => return,
18 },
19 };
20
21 let _bytes_per_pixel = image.bits_per_pixel / 8;
22 let offset = image.size_line / 2 + image.size_line * height / 2;
23 for i in 1..100 {
24 let offset = offset + i * 4;
27 match image.endian {
28 Endian::Little => {
29 image.write_to(offset + 2, 0xff); image.write_to(offset + 1, 0x0); image.write_to(offset, 0x0); }
33 Endian::Big => {
34 image.write_to(offset, 0xff); image.write_to(offset + 1, 0x0); image.write_to(offset + 2, 0x0); }
38 }
39 }
40
41 window.key_hook(
42 move |keycode, _| {
43 println!("{}", keycode);
45
46 if keycode == 113 {
48 process::exit(0);
49 } else if keycode == 97 {
51 let x = width / 2;
52 let y = height / 2;
53 let color = 0xffffff;
54 for i in 0..50 {
55 mlx.pixel_put(&window, x + i, y + i, color);
56 }
57 } else if keycode == 98 {
58 mlx.put_image_to_window(&window, &image, 0, 0);
59 }
60 },
61 &(),
62 );
63
64 mlx.event_loop();
66}