Skip to content

Commit 41ee8c1

Browse files
committed
Merge branch 'main' of github.com:nichilum/wavefront
2 parents d25dc2c + ca07ef7 commit 41ee8c1

File tree

1 file changed

+53
-17
lines changed

1 file changed

+53
-17
lines changed

src/input/systems.rs

+53-17
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::components::source::{Source, SourceType};
66
use crate::components::states::{Drag, Selected};
77
use crate::components::wall::{CircWall, RectWall, WResize, Wall};
88
use crate::events::{Load, Reset, Save, UpdateWalls};
9-
use crate::simulation::plugin::ComponentIDs;
109
use crate::math::transformations::{screen_to_grid, screen_to_nearest_grid};
10+
use crate::simulation::plugin::ComponentIDs;
1111
use crate::ui::state::{ClipboardBuffer, ToolType, UiState, WallType};
1212

1313
/// This system handles the copy and paste functionality
@@ -132,13 +132,9 @@ pub fn button_input(
132132
}
133133
ToolType::DrawWall => match ui_state.wall_type {
134134
WallType::Rectangle => {
135-
if let Some((mut x, mut y)) =
135+
if let Some((x, y)) =
136136
screen_to_nearest_grid(position.x, position.y, ui_state.image_rect)
137137
{
138-
if keys.pressed(KeyCode::ControlLeft) {
139-
x = (x as f32 / 10.).round() as u32 * 10;
140-
y = (y as f32 / 10.).round() as u32 * 10;
141-
}
142138
commands.spawn((
143139
RectWall::new(
144140
x,
@@ -294,14 +290,9 @@ pub fn button_input(
294290
}
295291
}
296292
ToolType::DrawWall | ToolType::ResizeWall => {
297-
if let Some((mut x, mut y)) =
293+
if let Some((x, y)) =
298294
screen_to_nearest_grid(position.x, position.y, ui_state.image_rect)
299295
{
300-
if keys.pressed(KeyCode::ControlLeft) {
301-
x = (x as f32 / 10.).round() as u32 * 10;
302-
y = (y as f32 / 10.).round() as u32 * 10;
303-
}
304-
305296
rect_wall_set
306297
.p2()
307298
.iter_mut()
@@ -310,22 +301,67 @@ pub fn button_input(
310301
.p2()
311302
.iter_mut()
312303
.for_each(|(_, wall_resize, mut wall)| wall.resize(wall_resize, x, y));
304+
305+
#[cfg(not(target_os = "macos"))]
306+
let ctrl = keys.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
307+
308+
#[cfg(target_os = "macos")]
309+
let ctrl = keys.any_pressed([KeyCode::SuperLeft, KeyCode::SuperRight]);
310+
311+
if ctrl {
312+
// snap all four corners to grid
313+
rect_wall_set.p2().iter_mut().for_each(|(_, _, mut wall)| {
314+
let min = UVec2 {
315+
x: (wall.rect.min.x as f32 / 10.).round() as u32 * 10,
316+
y: (wall.rect.min.y as f32 / 10.).round() as u32 * 10,
317+
};
318+
let max = UVec2 {
319+
x: (wall.rect.max.x as f32 / 10.).round() as u32 * 10,
320+
y: (wall.rect.max.y as f32 / 10.).round() as u32 * 10,
321+
};
322+
wall.resize(&WResize::TopLeft, min.x, min.y);
323+
wall.resize(&WResize::TopRight, max.x, min.y);
324+
wall.resize(&WResize::BottomLeft, min.x, max.y);
325+
wall.resize(&WResize::BottomRight, max.x, max.y);
326+
});
327+
}
313328
}
314329
}
315330
ToolType::MoveWall => {
316-
if let Some((mut x, mut y)) =
331+
if let Some((x, y)) =
317332
screen_to_nearest_grid(position.x, position.y, ui_state.image_rect)
318333
{
319-
if keys.pressed(KeyCode::ControlLeft) {
320-
x = (x as f32 / 10.).round() as u32 * 10;
321-
y = (y as f32 / 10.).round() as u32 * 10;
322-
}
323334
rect_wall_set.p1().iter_mut().for_each(|(_, mut wall)| {
324335
wall.set_center(x, y);
325336
});
326337
circ_wall_set.p1().iter_mut().for_each(|(_, mut wall)| {
327338
wall.set_center(x, y);
328339
});
340+
341+
#[cfg(not(target_os = "macos"))]
342+
let ctrl = keys.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
343+
344+
#[cfg(target_os = "macos")]
345+
let ctrl = keys.any_pressed([KeyCode::SuperLeft, KeyCode::SuperRight]);
346+
347+
if ctrl {
348+
// snap all four corners to grid
349+
rect_wall_set.p1().iter_mut().for_each(|(_, mut wall)| {
350+
let min = UVec2 {
351+
x: (wall.rect.min.x as f32 / 10.).round() as u32 * 10,
352+
y: (wall.rect.min.y as f32 / 10.).round() as u32 * 10,
353+
};
354+
let max = UVec2 {
355+
x: (wall.rect.max.x as f32 / 10.).round() as u32 * 10,
356+
y: (wall.rect.max.y as f32 / 10.).round() as u32 * 10,
357+
};
358+
359+
wall.resize(&WResize::TopLeft, min.x, min.y);
360+
wall.resize(&WResize::TopRight, max.x, min.y);
361+
wall.resize(&WResize::BottomLeft, min.x, max.y);
362+
wall.resize(&WResize::BottomRight, max.x, max.y);
363+
});
364+
}
329365
}
330366
}
331367
ToolType::MoveMic => {

0 commit comments

Comments
 (0)