X-Git-Url: https://git.r.bdr.sh/rbdr/captura/blobdiff_plain/c9b9e1d654ea697afad9f6427d94623bfdf55cce..e42019cd38b59e757f6036b132614a471d4cf6fe:/Captura/Presentation/Windows/RecordingWindow.swift?ds=inline diff --git a/Captura/Presentation/Windows/RecordingWindow.swift b/Captura/Presentation/Windows/RecordingWindow.swift index b9f212c..f5941dc 100644 --- a/Captura/Presentation/Windows/RecordingWindow.swift +++ b/Captura/Presentation/Windows/RecordingWindow.swift @@ -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 @@ -27,13 +27,13 @@ class RecordingWindow: NSWindow { self.isReleasedWhenClosed = false self.collectionBehavior = [.canJoinAllSpaces] - self.center() self.isMovableByWindowBackground = false self.isMovable = false + self.canHide = false 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 @@ -41,7 +41,6 @@ class RecordingWindow: NSWindow { self.level = .screenSaver self.isOpaque = false self.hasShadow = false - self.makeKeyAndOrderFront(nil) } // MARK: - Window Behavior Overrides @@ -81,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 { @@ -223,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 }