X-Git-Url: https://git.r.bdr.sh/rbdr/captura/blobdiff_plain/533cd932281300fb444c07e80f81fc683a410b60..8e9321304ca80e9ada7ac01058a5f4603cb37fab:/Captura/Presentation/Windows/RecordingWindow.swift?ds=inline diff --git a/Captura/Presentation/Windows/RecordingWindow.swift b/Captura/Presentation/Windows/RecordingWindow.swift index 3395c54..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 @@ -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 }