blob: 3f36123f319d9f11e9b8a45d09de28a6f2dd9c6f (
plain) (
blame)
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
|
pub mod grid;
pub mod math;
pub mod tool;
pub mod transform;
pub use transform::Transform;
use raylib::prelude::*;
use tool::{RoomTool, Tool};
fn main() {
let (mut rl, thread) = raylib::init().resizable().title("Hello there!").build();
let mut current_tool = RoomTool::new();
let mut transform = Transform::new();
let mut last_mouse_pos = rl.get_mouse_position();
while !rl.window_should_close() {
let screen_width = rl.get_screen_width();
let screen_height = rl.get_screen_height();
// Move the canvas together with the mouse
if rl.is_mouse_button_down(MouseButton::MOUSE_MIDDLE_BUTTON) {
transform.move_by_px(rl.get_mouse_position() - last_mouse_pos);
}
// Handle scrolling of the canvas
if rl.get_mouse_wheel_move() > 0 {
transform.try_zoom_in();
} else if rl.get_mouse_wheel_move() < 0 {
transform.try_zoom_out();
}
current_tool.update(&rl, &transform);
// Update the last mouse position
last_mouse_pos = rl.get_mouse_position();
// Drawing section
{
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::BLACK);
grid::draw_grid(&mut d, screen_width, screen_height, &transform);
current_tool.draw(&mut d, &transform);
}
}
}
|