11use crate :: {
22 image:: grammar:: Image ,
33 renderer:: {
4- camera:: Camera ,
54 draw_uniform:: DrawUniform ,
65 effect_pipeline:: EffectPipeline ,
76 feature_uniform:: { FeatureUniform , TransformAction } ,
@@ -12,10 +11,17 @@ use crate::{
1211 shape_uniform:: { CircleData , ShapeUniform , MAX_CIRCLES } ,
1312 } ,
1413} ;
14+
15+ #[ cfg( feature = "camera" ) ]
16+ use crate :: renderer:: camera:: Camera ;
17+
18+ #[ cfg( feature = "camera" ) ]
19+ use winit:: event:: MouseScrollDelta ;
20+
1521use anyhow:: Result ;
1622use winit:: {
1723 dpi:: PhysicalSize ,
18- event:: { ElementState , Event , KeyEvent , Modifiers , MouseButton , MouseScrollDelta , WindowEvent } ,
24+ event:: { ElementState , Event , KeyEvent , Modifiers , MouseButton , WindowEvent } ,
1925 event_loop:: EventLoop ,
2026 keyboard:: { KeyCode , PhysicalKey } ,
2127 window:: { CursorIcon , Window , WindowBuilder } ,
@@ -31,6 +37,7 @@ pub struct AppState<'a> {
3137
3238 pub feature_uniform : FeatureUniform ,
3339 pub draw_uniform : DrawUniform ,
40+ #[ cfg( feature = "camera" ) ]
3441 pub camera : Camera ,
3542 pub mouse_state : MouseState ,
3643 pub editor_state : EditorState ,
@@ -63,6 +70,7 @@ impl<'a> AppState<'a> {
6370 let draw_uniform_resource =
6471 gpu_allocator. create_uniform_resource ( "draw_uniform" , draw_uniform) ?;
6572
73+ #[ cfg( feature = "camera" ) ]
6674 let camera = Camera :: new ( ) ;
6775
6876 let shape_render_texture =
@@ -151,6 +159,7 @@ impl<'a> AppState<'a> {
151159 size,
152160 feature_uniform,
153161 draw_uniform,
162+ #[ cfg( feature = "camera" ) ]
154163 camera,
155164 mouse_state,
156165 editor_state,
@@ -188,17 +197,16 @@ impl<'a> AppState<'a> {
188197 // note to future self: we are probably due for a refactor
189198 // right now, application state, inputs, windowing are all coupled together
190199 // it would be good to be able to reuse certain commands for instance, think about cut (cmd + x)
191- let mut super_key_pressed = if cfg ! ( target_os = "macos" ) {
200+ let super_key_pressed = if cfg ! ( target_os = "macos" ) {
192201 self . modifiers . state ( ) . super_key ( )
193202 } else {
194203 self . modifiers . state ( ) . control_key ( )
195204 } ;
196205
197- let mut draw_mode = draw_uniform. crosshair ( ) ;
198-
199206 // some global rules
200207 // maybe keep a stack of actions?
201- draw_mode = if super_key_pressed { false } else { draw_mode } ;
208+
209+ let draw_mode = if super_key_pressed { false } else { draw_uniform. crosshair ( ) } ;
202210
203211 match event {
204212 WindowEvent :: MouseInput { state, button, .. } => {
@@ -208,7 +216,9 @@ impl<'a> AppState<'a> {
208216 . set_pressed ( matches ! ( state, ElementState :: Pressed ) ) ;
209217
210218 // camera panning
211- if super_key_pressed && !draw_mode {
219+ #[ cfg( feature = "camera" ) ]
220+ if super_key_pressed {
221+ dbg ! ( "pressed" ) ;
212222 self . window . set_cursor_icon ( CursorIcon :: Grab ) ;
213223
214224 match ( prev_state, self . mouse_state . pressed ( ) ) {
@@ -304,6 +314,7 @@ impl<'a> AppState<'a> {
304314 }
305315 }
306316 }
317+ #[ cfg( feature = "camera" ) ]
307318 WindowEvent :: MouseWheel { delta, .. } => {
308319 match delta {
309320 MouseScrollDelta :: LineDelta ( _, y) => {
@@ -335,6 +346,7 @@ impl<'a> AppState<'a> {
335346 WindowEvent :: CursorMoved { position, .. } => {
336347 let ( x, y) = ( position. x as f32 , position. y as f32 ) ;
337348
349+ #[ cfg( feature = "camera" ) ]
338350 if super_key_pressed && self . mouse_state . pressed ( ) {
339351 if let Some ( ( start_x, start_y) ) = self . mouse_state . camera_pan_start ( ) {
340352 let delta_x = ( x - start_x) / ( self . size . width as f32 ) * 2.0 ;
@@ -482,6 +494,7 @@ impl<'a> AppState<'a> {
482494 }
483495 }
484496 }
497+ #[ cfg( feature = "camera" ) ]
485498 ( KeyCode :: KeyR , ElementState :: Pressed ) => {
486499 self . camera . reset ( ) ;
487500 }
@@ -503,6 +516,7 @@ impl<'a> AppState<'a> {
503516 ) ;
504517
505518 // Update camera in draw uniform
519+ #[ cfg( feature = "camera" ) ]
506520 self . draw_uniform
507521 . update_camera ( self . camera . view_projection_matrix ( ) ) ;
508522
0 commit comments