1extern crate gust_render as gust;
9
10use gust::prelude::*;
11use gust::spritebatch::{SpriteBatch, SpriteData};
12use std::error::Error;
13use std::rc::Rc;
14
15fn main() -> Result<(), Box<Error>> {
16 let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
17
18 let texture = Rc::new(Texture::from_path("examples/texture/Dirt.png").unwrap());
19 let mut batch = SpriteBatch::from(&texture);
20 for i in 0..1_000_000 {
21 let mut data = SpriteData::new(Vector::new(i as f32 * 1.0, i as f32 * 10.0));
22 data.set_texture_raw([Vector::new(0.0, 0.0), Vector::new(1.0, 1.0)]);
23 batch.push_sprite(data);
24 }
25
26 let event_handler = EventHandler::new(&window);
27
28 window.set_clear_color(Color::new(0.45, 0.0, 1.0));
29 window.enable_cursor();
30 window.poll(None);
31 while window.is_open() {
32 window.poll_events();
33 for event in event_handler.fetch() {
34 event_process(event, &mut window, &mut batch);
35 }
36 window.clear();
37 window.draw_mut(&mut batch);
38 window.display();
39 }
40
41 Ok(())
42}
43
44fn event_process(event: Event, window: &mut Window, batch: &mut SpriteBatch) {
45 match event.1 {
46 Events::Key(Key::Escape, _, _, _) => {
47 window.close();
48 }
49 Events::Key(Key::W, _, Action::Press, _) => {
50 batch.translate(Vector::new(10.0, 10.0));
51 }
52 Events::Key(Key::D, _, Action::Press, _) => {
53 batch
54 .get_sprite_mut(0)
55 .unwrap()
56 .translate(Vector::new(10.0, 0.0));
57 }
58 Events::MouseButton(_, _, _) => {
59 println!("Mouse button !");
60 }
61 Events::CursorPos(x, y) => {
62 println!("x: {}, y: {}", x, y);
63 }
64 _ => println!("Another event !"),
65 }
66 drop(event);
67}