]> git.r.bdr.sh - rbdr/captura/blobdiff - Captura/Presentation/Windows/RecordingWindow.swift
Adds configure support for URLs
[rbdr/captura] / Captura / Presentation / Windows / RecordingWindow.swift
index 3395c549c65ba6a7734772354de906da45442f1e..f5941dc82bdbde22970439157d5088a2572eef23 100644 (file)
@@ -11,7 +11,7 @@ class RecordingWindow: NSWindow {
     self.contentView as! RecordingContentView
   }
   
-  init(_ button: NSRect?) {
+  init(_ configuration: CaptureSessionConfiguration, _ button: NSRect?) {
     
     let screens = NSScreen.screens
     var boundingBox = NSZeroRect
@@ -33,7 +33,7 @@ class RecordingWindow: NSWindow {
     self.titlebarAppearsTransparent = true
     self.setFrame(boundingBox, display: true)
     self.titleVisibility = .hidden
-    let recordingView = RecordingContentView()
+    let recordingView = RecordingContentView(configuration, frame: boundingBox)
     recordingView.frame = boundingBox
     recordingView.button = button
     self.contentView = recordingView
@@ -80,12 +80,41 @@ enum RecordingWindowState {
 
 class RecordingContentView: NSView {
   
+  init(_ configuration: CaptureSessionConfiguration, frame: NSRect) {
+    super.init(frame: frame)
+    preventResize = configuration.preventResize
+    preventMove = configuration.preventMove
+    autoStart = configuration.autoStart
+    
+    if configuration.x != nil || configuration.y != nil || configuration.width != nil || configuration.height != nil {
+      box = NSRect(
+        x: configuration.x ?? Int(frame.width / 2.0),
+        y: configuration.y ?? Int(frame.height / 2.0),
+        width: configuration.width ?? 400,
+        height: configuration.height ?? 400
+      )
+    }
+    
+    if autoStart {
+      DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
+        NotificationCenter.default.post(name: .startRecording, object: nil, userInfo: nil)
+      }
+    }
+  }
+  
+  required init?(coder: NSCoder) {
+    fatalError("init(coder:) has not been implemented")
+  }
+  
   public var button: NSRect? = nil
   @Published public var box: NSRect? = nil
   public var state: RecordingWindowState = .idle
   private var mouseLocation: NSPoint = NSPoint()
   private var origin: NSPoint = NSPoint()
   private var boxOrigin: NSPoint = NSPoint()
+  private var preventResize = false
+  private var preventMove = false
+  private var autoStart = false
   
   private var resizeBox: NSRect? {
     if let box {
@@ -222,18 +251,22 @@ class RecordingContentView: NSView {
         }
       }
       
-      if resizeBox!.contains(origin) {
+      if resizeBox!.contains(origin) && !preventResize {
         self.origin = NSPoint(x: box.minX, y: box.maxY)
         state = .resizing
         return
       }
-      if box.contains(origin) {
+      if box.contains(origin) && !preventMove {
         state = .moving
         self.boxOrigin = NSPoint(x: box.origin.x, y: box.origin.y)
         return
       }
     }
     
+    if preventResize || preventMove {
+      return
+    }
+    
     state = .drawing
   }