| 1 | use calling::CallCommand; |
| 2 | use gpui_kit::*; |
| 3 | |
| 4 | use super::share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY}; |
| 5 | use crate::app_state::{AppEvent, AppState}; |
| 6 | |
| 7 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 8 | pub enum ZoomStep { |
| 9 | In, |
| 10 | Out, |
| 11 | Reset, |
| 12 | } |
| 13 | |
| 14 | fn flag_text(on: bool) -> &'static str { |
| 15 | if on { "1" } else { "0" } |
| 16 | } |
| 17 | |
| 18 | impl AppState { |
| 19 | fn change_share_stage( |
| 20 | &mut self, |
| 21 | cx: &mut Context<Self>, |
| 22 | change: impl FnOnce(&mut super::share_view::ShareStage), |
| 23 | ) { |
| 24 | let Some(call) = self |
| 25 | .call |
| 26 | .as_mut() |
| 27 | .filter(|call| call.model.screen_sharer.is_some()) |
| 28 | else { |
| 29 | return; |
| 30 | }; |
| 31 | change(&mut call.share_stage); |
| 32 | cx.emit(AppEvent::Call); |
| 33 | cx.notify(); |
| 34 | } |
| 35 | |
| 36 | pub fn zoom_share_wheel( |
| 37 | &mut self, |
| 38 | scroll_pixels: f32, |
| 39 | position: (f32, f32), |
| 40 | cx: &mut Context<Self>, |
| 41 | ) { |
| 42 | self.change_share_stage(cx, |stage| { |
| 43 | let (pointer, size) = (stage.pointer(position), stage.size()); |
| 44 | stage.view.zoom_wheel(scroll_pixels, pointer, size); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | pub fn zoom_share(&mut self, step: ZoomStep, cx: &mut Context<Self>) { |
| 49 | self.change_share_stage(cx, |stage| { |
| 50 | let size = stage.size(); |
| 51 | match step { |
| 52 | ZoomStep::In => stage.view.step_in(size), |
| 53 | ZoomStep::Out => stage.view.step_out(size), |
| 54 | ZoomStep::Reset => stage.view.reset(), |
| 55 | } |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | pub fn begin_share_pan(&mut self, position: (f32, f32), cx: &mut Context<Self>) { |
| 60 | self.change_share_stage(cx, |stage| stage.pan_from = Some(position)); |
| 61 | } |
| 62 | |
| 63 | pub fn pan_share_to(&mut self, position: (f32, f32), cx: &mut Context<Self>) { |
| 64 | self.change_share_stage(cx, |stage| { |
| 65 | let Some(from) = stage.pan_from.replace(position) else { |
| 66 | return; |
| 67 | }; |
| 68 | let size = stage.size(); |
| 69 | stage |
| 70 | .view |
| 71 | .pan_by((position.0 - from.0, position.1 - from.1), size); |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | pub fn end_share_pan(&mut self, cx: &mut Context<Self>) { |
| 76 | self.change_share_stage(cx, |stage| stage.pan_from = None); |
| 77 | } |
| 78 | |
| 79 | pub fn pop_out_stage(&mut self, cx: &mut Context<Self>) { |
| 80 | self.change_share_stage(cx, |stage| stage.popped = true); |
| 81 | } |
| 82 | |
| 83 | pub fn return_stage_from_pop_out(&mut self, cx: &mut Context<Self>) { |
| 84 | self.change_share_stage(cx, |stage| stage.popped = false); |
| 85 | } |
| 86 | |
| 87 | pub fn set_call_share_motion(&mut self, on: bool, cx: &mut Context<Self>) { |
| 88 | self.call_share_motion = on; |
| 89 | let _ = self.store.set_meta(SHARE_MOTION_META_KEY, flag_text(on)); |
| 90 | self.send_call_command(CallCommand::SetShareMotion(on)); |
| 91 | cx.notify(); |
| 92 | } |
| 93 | |
| 94 | pub fn set_call_share_standout(&mut self, on: bool, cx: &mut Context<Self>) { |
| 95 | self.call_share_standout = on; |
| 96 | let _ = self.store.set_meta(SHARE_STANDOUT_META_KEY, flag_text(on)); |
| 97 | self.send_call_command(CallCommand::SetShareStandout(on)); |
| 98 | cx.notify(); |
| 99 | } |
| 100 | } |