forked from iina/iina
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCropSettingsViewController.swift
More file actions
70 lines (57 loc) · 2.08 KB
/
CropSettingsViewController.swift
File metadata and controls
70 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// CropSettingsViewController.swift
// iina
//
// Created by lhc on 22/12/2016.
// Copyright © 2016 lhc. All rights reserved.
//
import Cocoa
class CropSettingsViewController: CropBoxViewController {
@IBOutlet weak var cropRectLabel: NSTextField!
@IBOutlet weak var predefinedAspectSegment: NSSegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear() {
predefinedAspectSegment.selectedSegment = -1
}
override func selectedRectUpdated() {
super.selectedRectUpdated()
cropRectLabel.stringValue = readableCropString
}
@IBAction func doneBtnAction(_ sender: AnyObject) {
let player = mainWindow.player
mainWindow.exitInteractiveMode {
if self.cropx == 0 && self.cropy == 0 &&
self.cropw == player.info.videoWidth &&
self.croph == player.info.videoHeight {
// if no crop, remove the crop filter
if let vf = player.info.cropFilter {
let _ = player.removeVideoFilter(vf)
player.info.unsureCrop = "None"
return
}
}
// else, set the filter
let filter = MPVFilter.crop(w: self.cropw, h: self.croph, x: self.cropx, y: self.cropy)
player.setCrop(fromFilter: filter)
// custom crop has no corresponding menu entry
player.info.unsureCrop = ""
player.sendOSD(.crop(self.readableCropString))
}
}
@IBAction func cancelBtnAction(_ sender: AnyObject) {
mainWindow.exitInteractiveMode()
}
@IBAction func predefinedAspectValueAction(_ sender: NSSegmentedControl) {
guard let str = sender.label(forSegment: sender.selectedSegment) else { return }
guard let aspect = Aspect(string: str) else { return }
let actualSize = cropBoxView.actualSize
let croppedSize = actualSize.crop(withAspect: aspect)
let cropped = NSMakeRect((actualSize.width - croppedSize.width) / 2,
(actualSize.height - croppedSize.height) / 2,
croppedSize.width,
croppedSize.height)
cropBoxView.setSelectedRect(to: cropped)
}
}