@@ -306,128 +306,107 @@ impl<'a> AppState<'a> {
306306 ..
307307 } ,
308308 ..
309- } => match ( keycode, state) {
310- ( KeyCode :: KeyA , ElementState :: Pressed ) => {
311- draw_uniform. toggle_crosshair ( ) ;
309+ } => {
310+ let super_key_pressed = if cfg ! ( target_os = "macos" ) {
311+ self . modifiers . state ( ) . super_key ( )
312+ } else {
313+ self . modifiers . state ( ) . control_key ( )
314+ } ;
312315
313- if draw_uniform. crosshair ( ) {
314- self . window . set_cursor_icon ( CursorIcon :: Crosshair ) ;
315- } else {
316- self . window . set_cursor_icon ( CursorIcon :: Default ) ;
316+ match ( keycode, state) {
317+ ( KeyCode :: KeyA , ElementState :: Pressed ) => {
318+ draw_uniform. toggle_crosshair ( ) ;
319+
320+ if draw_uniform. crosshair ( ) {
321+ self . window . set_cursor_icon ( CursorIcon :: Crosshair ) ;
322+ } else {
323+ self . window . set_cursor_icon ( CursorIcon :: Default ) ;
324+ }
317325 }
318- }
319- // (KeyCode::KeyC, ElementState::Pressed) => {
320- // feature_uniform.reset_features();
321- // }
322- ( KeyCode :: KeyB , ElementState :: Pressed ) => {
323- feature_uniform. toggle_blur ( ) ;
324- }
325- ( KeyCode :: ArrowUp , ElementState :: Pressed ) => {
326- if feature_uniform. blur ( ) {
327- feature_uniform. increase_blur_radius ( ) ;
326+ // (KeyCode::KeyC, ElementState::Pressed) => {
327+ // feature_uniform.reset_features();
328+ // }
329+ ( KeyCode :: KeyB , ElementState :: Pressed ) => {
330+ feature_uniform. toggle_blur ( ) ;
328331 }
332+ ( KeyCode :: ArrowUp , ElementState :: Pressed ) => {
333+ if feature_uniform. blur ( ) {
334+ feature_uniform. increase_blur_radius ( ) ;
335+ }
329336
330- if feature_uniform. sharpen ( ) {
331- feature_uniform. increase_sharpen_factor ( ) ;
332- }
333- }
334- ( KeyCode :: ArrowDown , ElementState :: Pressed ) => {
335- if feature_uniform. blur ( ) {
336- feature_uniform. decrease_blur_radius ( ) ;
337+ if feature_uniform. sharpen ( ) {
338+ feature_uniform. increase_sharpen_factor ( ) ;
339+ }
337340 }
341+ ( KeyCode :: ArrowDown , ElementState :: Pressed ) => {
342+ if feature_uniform. blur ( ) {
343+ feature_uniform. decrease_blur_radius ( ) ;
344+ }
338345
339- if feature_uniform. sharpen ( ) {
340- feature_uniform. decrease_sharpen_factor ( ) ;
346+ if feature_uniform. sharpen ( ) {
347+ feature_uniform. decrease_sharpen_factor ( ) ;
348+ }
341349 }
342- }
343- ( KeyCode :: KeyG , ElementState :: Pressed ) => {
344- feature_uniform. toggle_grayscale ( ) ;
345- }
346- ( KeyCode :: KeyS , ElementState :: Pressed ) => {
347- feature_uniform. toggle_sharpen ( ) ;
348- }
349- ( KeyCode :: KeyI , ElementState :: Pressed ) => {
350- feature_uniform. toggle_invert ( ) ;
351- }
352- ( KeyCode :: KeyE , ElementState :: Pressed ) => {
353- feature_uniform. toggle_edge_detect ( ) ;
354- }
355- ( KeyCode :: KeyX , ElementState :: Pressed ) => {
356- feature_uniform. apply_transform ( TransformAction :: FlipX ) ;
357- }
358- ( KeyCode :: KeyY , ElementState :: Pressed ) => {
359- feature_uniform. apply_transform ( TransformAction :: FlipY ) ;
360- }
361- ( KeyCode :: Delete , ElementState :: Pressed )
362- | ( KeyCode :: Backspace , ElementState :: Pressed ) => {
363- // Delete the selected circle
364- if let Some ( selected_element_id) = self . mouse_state . selected_shape ( ) {
365- self . editor_state . remove_shape_by_id ( selected_element_id) ;
366- self . mouse_state . set_selected_shape ( None ) ;
367- self . mouse_state . set_dragging_shape ( false ) ;
350+ ( KeyCode :: KeyG , ElementState :: Pressed ) => {
351+ feature_uniform. toggle_grayscale ( ) ;
368352 }
369- }
370- ( KeyCode :: KeyZ , ElementState :: Pressed ) => {
371- #[ cfg( target_os = "macos" ) ]
372- if self . modifiers . state ( ) . super_key ( ) {
373- self . editor_state . undo ( ) ;
353+ ( KeyCode :: KeyS , ElementState :: Pressed ) => {
354+ feature_uniform. toggle_sharpen ( ) ;
374355 }
375-
376- #[ cfg( not( target_os = "macos" ) ) ]
377- if self . modifiers . state ( ) . control_key ( ) {
378- self . editor_state . undo ( ) ;
356+ ( KeyCode :: KeyI , ElementState :: Pressed ) => {
357+ feature_uniform. toggle_invert ( ) ;
379358 }
380- }
381- ( KeyCode :: KeyC , ElementState :: Pressed ) => {
382- #[ cfg( target_os = "macos" ) ]
383- if self . modifiers . state ( ) . super_key ( ) {
384- let circle = self . mouse_state . selected_shape ( ) . map ( |i| {
385- * self
386- . editor_state
387- . get_element_by_id ( i)
388- . expect ( "selected id must be valid" )
389- . inner ( )
390- } ) ;
391-
392- self . mouse_state . set_clipboard_shape ( circle) ;
359+ ( KeyCode :: KeyE , ElementState :: Pressed ) => {
360+ feature_uniform. toggle_edge_detect ( ) ;
393361 }
394-
395- #[ cfg( not( target_os = "macos" ) ) ]
396- if self . modifiers . state ( ) . control_key ( ) {
397- let circle = self . mouse_state . selected_shape ( ) . map ( |i| {
398- self . editor_state
399- . get_element_by_id ( i)
400- . expect ( "selected id must be valid" )
401- . inner ( )
402- . clone ( )
403- } ) ;
404-
405- self . mouse_state . set_clipboard_shape ( circle) ;
362+ ( KeyCode :: KeyX , ElementState :: Pressed ) => {
363+ feature_uniform. apply_transform ( TransformAction :: FlipX ) ;
406364 }
407- }
408- ( KeyCode :: KeyV , ElementState :: Pressed ) => {
409- let window_dimensions = ( self . size . width as f32 , self . size . height as f32 ) ;
410-
411- # [ cfg ( target_os = "macos" ) ]
412- if self . modifiers . state ( ) . super_key ( ) {
413- if let Some ( circle ) = self . mouse_state . clipboard_shape ( ) {
414- let copied_element_id =
415- self . editor_state . copy_shape ( circle , window_dimensions ) ;
416- self . mouse_state . set_selected_shape ( Some ( copied_element_id ) ) ;
365+ ( KeyCode :: KeyY , ElementState :: Pressed ) => {
366+ feature_uniform . apply_transform ( TransformAction :: FlipY ) ;
367+ }
368+ ( KeyCode :: Delete , ElementState :: Pressed )
369+ | ( KeyCode :: Backspace , ElementState :: Pressed ) => {
370+ // Delete the selected circle
371+ if let Some ( selected_element_id ) = self . mouse_state . selected_shape ( ) {
372+ self . editor_state . remove_shape_by_id ( selected_element_id ) ;
373+ self . mouse_state . set_selected_shape ( None ) ;
374+ self . mouse_state . set_dragging_shape ( false ) ;
417375 }
418376 }
377+ ( KeyCode :: KeyZ , ElementState :: Pressed ) => {
378+ if super_key_pressed {
379+ self . editor_state . undo ( ) ;
380+ }
381+ }
382+ ( KeyCode :: KeyC , ElementState :: Pressed ) => {
383+ if super_key_pressed {
384+ let circle = self . mouse_state . selected_shape ( ) . map ( |i| {
385+ * self
386+ . editor_state
387+ . get_element_by_id ( i)
388+ . expect ( "selected id must be valid" )
389+ . inner ( )
390+ } ) ;
391+
392+ self . mouse_state . set_clipboard_shape ( circle) ;
393+ }
394+ }
395+
396+ ( KeyCode :: KeyV , ElementState :: Pressed ) => {
397+ let window_dimensions = ( self . size . width as f32 , self . size . height as f32 ) ;
419398
420- # [ cfg ( not ( target_os = "macos" ) ) ]
421- if self . modifiers . state ( ) . control_key ( ) {
422- if let Some ( circle ) = self . mouse_state . clipboard_shape ( ) {
423- let copied_element_id =
424- self . editor_state . copy_shape ( circle , window_dimensions ) ;
425- self . mouse_state . set_selected_shape ( Some ( copied_element_id ) ) ;
399+ if super_key_pressed {
400+ if let Some ( circle ) = self . mouse_state . clipboard_shape ( ) {
401+ let copied_element_id =
402+ self . editor_state . copy_shape ( circle , window_dimensions ) ;
403+ self . mouse_state . set_selected_shape ( Some ( copied_element_id ) ) ;
404+ }
426405 }
427406 }
407+ _ => return false ,
428408 }
429- _ => return false ,
430- } ,
409+ }
431410 _ => return false ,
432411 }
433412
0 commit comments