@@ -6,8 +6,8 @@ use crate::components::source::{Source, SourceType};
6
6
use crate :: components:: states:: { Drag , Selected } ;
7
7
use crate :: components:: wall:: { CircWall , RectWall , WResize , Wall } ;
8
8
use crate :: events:: { Load , Reset , Save , UpdateWalls } ;
9
- use crate :: simulation:: plugin:: ComponentIDs ;
10
9
use crate :: math:: transformations:: { screen_to_grid, screen_to_nearest_grid} ;
10
+ use crate :: simulation:: plugin:: ComponentIDs ;
11
11
use crate :: ui:: state:: { ClipboardBuffer , ToolType , UiState , WallType } ;
12
12
13
13
/// This system handles the copy and paste functionality
@@ -132,13 +132,9 @@ pub fn button_input(
132
132
}
133
133
ToolType :: DrawWall => match ui_state. wall_type {
134
134
WallType :: Rectangle => {
135
- if let Some ( ( mut x , mut y) ) =
135
+ if let Some ( ( x , y) ) =
136
136
screen_to_nearest_grid ( position. x , position. y , ui_state. image_rect )
137
137
{
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
- }
142
138
commands. spawn ( (
143
139
RectWall :: new (
144
140
x,
@@ -294,14 +290,9 @@ pub fn button_input(
294
290
}
295
291
}
296
292
ToolType :: DrawWall | ToolType :: ResizeWall => {
297
- if let Some ( ( mut x , mut y) ) =
293
+ if let Some ( ( x , y) ) =
298
294
screen_to_nearest_grid ( position. x , position. y , ui_state. image_rect )
299
295
{
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
-
305
296
rect_wall_set
306
297
. p2 ( )
307
298
. iter_mut ( )
@@ -310,22 +301,67 @@ pub fn button_input(
310
301
. p2 ( )
311
302
. iter_mut ( )
312
303
. 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
+ }
313
328
}
314
329
}
315
330
ToolType :: MoveWall => {
316
- if let Some ( ( mut x , mut y) ) =
331
+ if let Some ( ( x , y) ) =
317
332
screen_to_nearest_grid ( position. x , position. y , ui_state. image_rect )
318
333
{
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
- }
323
334
rect_wall_set. p1 ( ) . iter_mut ( ) . for_each ( |( _, mut wall) | {
324
335
wall. set_center ( x, y) ;
325
336
} ) ;
326
337
circ_wall_set. p1 ( ) . iter_mut ( ) . for_each ( |( _, mut wall) | {
327
338
wall. set_center ( x, y) ;
328
339
} ) ;
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
+ }
329
365
}
330
366
}
331
367
ToolType :: MoveMic => {
0 commit comments