[
(NSPoint(x: 3, y: height), NSPoint(x: bounds.maxX, y: height)),
(NSPoint(x: width, y: 0), NSPoint(x: width, y: height))
- ]
- )
+ ])
.stroke()
}
}
return nil
case .slightly:
- return polygon {
- [NSPoint]()
- .appended { NSPoint(x: 35.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 35.0) }
- }
+ return polygon(points:
+ [
+ NSPoint(x: 35.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 35.0)
+ ])
case .modest:
- return polygon {
- [NSPoint]()
- .appended { NSPoint(x: 50.0, y: height - 2.0) }
- .appended { NSPoint(x: 25.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 25.0) }
- .appended { NSPoint(x: 0.0, y: height - 50.0) }
- }
+ return polygon(points:
+ [
+ NSPoint(x: 50.0, y: height - 2.0),
+ NSPoint(x: 25.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 25.0),
+ NSPoint(x: 0.0, y: height - 50.0)
+ ])
case .badly:
- let p = polygon {
- [NSPoint]()
- .appended { NSPoint(x: 60.0, y: height - 2.0) }
- .appended { NSPoint(x: 53.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 53.0) }
- .appended { NSPoint(x: 0.0, y: height - 60.0) }
- }
- polygon {
- [NSPoint]()
- .appended { NSPoint(x: 47.0, y: height - 2.0) }
- .appended { NSPoint(x: 23.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 23.0) }
- .appended { NSPoint(x: 0.0, y: height - 47.0) }
- }
+ let p = polygon(points:
+ [
+ NSPoint(x: 60.0, y: height - 2.0),
+ NSPoint(x: 53.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 53.0),
+ NSPoint(x: 0.0, y: height - 60.0)
+ ])
+ polygon(points:
+ [
+ NSPoint(x: 47.0, y: height - 2.0),
+ NSPoint(x: 23.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 23.0),
+ NSPoint(x: 0.0, y: height - 47.0)
+ ])
.map { p?.append($0) }
return p
}
return nil
case .slightly:
- return polygon {
- [NSPoint]()
- .appended { NSPoint(x: 35.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 35.0) }
- }
+ return polygon(points:
+ [
+ NSPoint(x: 35.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 35.0)
+ ])
case .modest:
- return polygon {
- [NSPoint]()
- .appended { NSPoint(x: 50.0, y: height - 2.0) }
- .appended { NSPoint(x: 25.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 25.0) }
- .appended { NSPoint(x: 0.0, y: height - 50.0) }
- }
+ return polygon(points:
+ [
+ NSPoint(x: 50.0, y: height - 2.0),
+ NSPoint(x: 25.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 25.0),
+ NSPoint(x: 0.0, y: height - 50.0)
+ ])
case .badly:
- let p = polygon {
- [NSPoint]()
- .appended { NSPoint(x: 55.0, y: height - 2.0) }
- .appended { NSPoint(x: 48.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 48.0) }
- .appended { NSPoint(x: 0.0, y: height - 55.0) }
- }
- polygon {
- [NSPoint]()
- .appended { NSPoint(x: 42.0, y: height - 2.0) }
- .appended { NSPoint(x: 20.0, y: height - 2.0) }
- .appended { NSPoint(x: 0.0, y: height - 20.0) }
- .appended { NSPoint(x: 0.0, y: height - 42.0) }
- }
+ let p = polygon(points:
+ [
+ NSPoint(x: 55.0, y: height - 2.0),
+ NSPoint(x: 48.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 48.0),
+ NSPoint(x: 0.0, y: height - 55.0)
+ ])
+ polygon(points:
+ [
+ NSPoint(x: 42.0, y: height - 2.0),
+ NSPoint(x: 20.0, y: height - 2.0),
+ NSPoint(x: 0.0, y: height - 20.0),
+ NSPoint(x: 0.0, y: height - 42.0)
+ ])
.map { p?.append($0) }
return p
}
let taihiString = try? String(contentsOf: url, encoding: .utf8)
else { fatalError("Can not load Taihi.txt") }
- guard (taihiString as NSString).length == 2 else { fatalError("Taihi string is not 2 charactor") }
+ guard (taihiString as NSString).length == 2
+ else { fatalError("Taihi string is not 2 charactor") }
return taihiString
}()
fileprivate func customPredicate() -> NSPredicate? {
switch (shipTypePredicte, omitPredicate) {
+
case let (s?, o?): return NSCompoundPredicate(type: .and, subpredicates: [o, s])
case let (s?, nil): return s
case let (nil, o?): return o
return
}
- DispatchQueue(label: "makeTrimedImage queue")
- .async {
+ DispatchQueue(label: "makeTrimedImage queue").async {
+
+ let images: [NSImage] = self.editedImages.flatMap {
- let images: [NSImage] = self.editedImages.flatMap {
-
- guard let originalImage = NSImage(contentsOf: $0.url) else { return nil }
-
- let trimedImage = NSImage(size: self.currentTrimInfo.rect.size)
-
- trimedImage.lockFocus()
- originalImage.draw(at: .zero,
- from: self.currentTrimInfo.rect,
- operation: NSCompositeCopy,
- fraction: 1.0)
- trimedImage.unlockFocus()
-
- return trimedImage
- }
+ guard let originalImage = NSImage(contentsOf: $0.url)
+ else { return nil }
- DispatchQueue.main.async {
-
- self.tiledImageView.images = images
- }
+ let trimedImage = NSImage(size: self.currentTrimInfo.rect.size)
+
+ trimedImage.lockFocus()
+ originalImage.draw(at: .zero,
+ from: self.currentTrimInfo.rect,
+ operation: NSCompositeCopy,
+ fraction: 1.0)
+ trimedImage.unlockFocus()
+
+ return trimedImage
+ }
+
+ DispatchQueue.main.async {
+
+ self.tiledImageView.images = images
+ }
}
}
struct CodingKey {
static let url = "Url"
- static let version = "Version"
}
required convenience init?(coder aDecoder: NSCoder) {
func registerScreenshot(_ image: NSBitmapImageRep, fromOnScreen: NSRect) {
- DispatchQueue(label: "Screenshot queue")
- .async {
+ DispatchQueue(label: "Screenshot queue").async {
+
+ guard let data = image.representation(using: .JPEG, properties: [:])
+ else { return }
+
+ let url = self.screenshotSaveDirectoryURL
+ .appendingPathComponent(self.dirName)
+ .appendingPathExtension("jpg")
+ let pathURL = FileManager.default.uniqueFileURL(url)
+
+ do {
- guard let data = image.representation(using: .JPEG, properties: [:])
- else { return }
+ try data.write(to: pathURL)
- let url = self.screenshotSaveDirectoryURL
- .appendingPathComponent(self.dirName)
- .appendingPathExtension("jpg")
- let pathURL = FileManager.default.uniqueFileURL(url)
+ } catch {
- do {
-
- try data.write(to: pathURL)
-
- } catch {
-
- print("Can not write image")
- return
- }
+ print("Can not write image")
+ return
+ }
+
+ DispatchQueue.main.async {
- DispatchQueue.main.async {
-
- let info = ScreenshotInformation(url: pathURL, version: self.cacheVersion(forUrl: pathURL))
-
- self.screenshotsController.insert(info, atArrangedObjectIndex: 0)
- let set: Set<IndexPath> = [NSIndexPath(forItem: 0, inSection: 0) as IndexPath]
- self.collectionView.selectionIndexPaths = set
-
- self.collectionView.scrollToItems(at: set, scrollPosition: .nearestHorizontalEdge)
- if UserDefaults.standard[.showsListWindowAtScreenshot] {
-
- self.view.window?.makeKeyAndOrderFront(nil)
- }
+ let info = ScreenshotInformation(url: pathURL, version: self.cacheVersion(forUrl: pathURL))
+
+ self.screenshotsController.insert(info, atArrangedObjectIndex: 0)
+ let set: Set<IndexPath> = [NSIndexPath(forItem: 0, inSection: 0) as IndexPath]
+ self.collectionView.selectionIndexPaths = set
+
+ self.collectionView.scrollToItems(at: set, scrollPosition: .nearestHorizontalEdge)
+ if UserDefaults.standard[.showsListWindowAtScreenshot] {
- self.saveCache()
+ self.view.window?.makeKeyAndOrderFront(nil)
}
+
+ self.saveCache()
+ }
}
}
fileprivate func reloadData() {
- guard let f = try? FileManager
- .default
- .contentsOfDirectory(at: screenshotSaveDirectoryURL, includingPropertiesForKeys: nil) else {
- print("can not read list of screenshot directory")
- return
+ guard let f = try? FileManager.default.contentsOfDirectory(at: screenshotSaveDirectoryURL, includingPropertiesForKeys: nil)
+ else {
+ print("can not read list of screenshot directory")
+ return
}
let imageTypes = NSImage.imageTypes()
private func tag(_ sender: AnyObject?) -> Int {
- guard let sender = sender
- else { return -1 }
-
- if let control = sender as? NSSegmentedControl,
- let cell = sender.cell as? NSSegmentedCell {
+ switch sender {
- return cell.tag(forSegment: control.selectedSegment)
- }
-
- if let control = sender as? NSControl {
+ case let segmented as NSSegmentedControl:
+ let cell = segmented.cell as? NSSegmentedCell
+ return cell?.tag(forSegment: segmented.selectedSegment) ?? -1
+
+ case let control as NSControl:
return control.tag
+
+ default:
+ return -1
}
-
- return -1
}
@IBAction func changeView(_ sender: AnyObject?) {
- ViewType(rawValue: tag(sender)).map { showView(with: $0) }
+ ViewType(rawValue: tag(sender)).map(showView)
}
}
NSColor.gridColor.set()
NSBezierPath.setDefaultLineWidth(1.0)
- multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: 40.5, y: 0), NSPoint(x: 40.5, y: height)) }
- .appended { (NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)) }
- .appended { (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5)) }
- .appended { (NSPoint(x: 0, y: 51.5), NSPoint(x: width, y: 51.5)) }
- }
+ multiline(lines:
+ [
+ (
+ NSPoint(x: 40.5, y: 0),
+ NSPoint(x: 40.5, y: height)
+ ),
+ (
+ NSPoint(x: 0, y: 17.5),
+ NSPoint(x: width, y: 17.5)
+ ),
+ (
+ NSPoint(x: 0, y: 34.5),
+ NSPoint(x: width, y: 34.5)
+ ),
+ (
+ NSPoint(x: 0, y: 51.5),
+ NSPoint(x: width, y: 51.5)
+ )
+ ])
.stroke()
}
}
let width = bounds.width
let height = bounds.height
- let path = multiline { [(NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height))] }
+ let path = multiline(lines: [
+ (
+ NSPoint(x: width - offset, y: 0),
+ NSPoint(x: width - offset, y: height)
+ )
+ ])
path.lineWidth = 1.0
return path
let width = bounds.width
let height = bounds.height
- let path = multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height)) }
- .appended {
- (NSPoint(x: width - offset - padding, y: 0), NSPoint(x: width - offset - padding, y: height))
- }
- }
+ let path = multiline(lines:
+ [
+ (
+ NSPoint(x: width - offset, y: 0),
+ NSPoint(x: width - offset, y: height)
+ ),
+ (
+ NSPoint(x: width - offset - padding, y: 0),
+ NSPoint(x: width - offset - padding, y: height)
+ )
+ ])
path.lineWidth = 1.0
return path
let width = bounds.width
let height = bounds.height
- let path = multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height)) }
- .appended {
- (NSPoint(x: width - offset - padding, y: 0), NSPoint(x: width - offset - padding, y: height))
- }
- .appended {
- (NSPoint(x: width - offset - padding * 2, y: 0),
- NSPoint(x: width - offset - padding * 2, y: height))
- }
- }
+ let path = multiline(lines:
+ [
+ (
+ NSPoint(x: width - offset, y: 0),
+ NSPoint(x: width - offset, y: height)
+ ),
+ (
+ NSPoint(x: width - offset - padding, y: 0),
+ NSPoint(x: width - offset - padding, y: height)
+ ),
+ (
+ NSPoint(x: width - offset - padding * 2, y: 0),
+ NSPoint(x: width - offset - padding * 2, y: height)
+ )
+ ])
path.lineWidth = 1.0
return path
let width = bounds.width
let height = bounds.height
- let path = multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
- }
+ let path = multiline(lines:
+ [
+ (
+ NSPoint(x: width - offset - slideOffset, y: 0),
+ NSPoint(x: width - offset, y: height)
+ )
+ ])
path.lineWidth = 2.0
return path
let width = bounds.width
let height = bounds.height
- let path = multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
- .appended {
- (NSPoint(x: width - offset - padding - slideOffset, y: 0),
- NSPoint(x: width - offset - padding, y: height))
- }
- }
+ let path = multiline(lines:
+ [
+ (
+ NSPoint(x: width - offset - slideOffset, y: 0),
+ NSPoint(x: width - offset, y: height)
+ ),
+ (
+ NSPoint(x: width - offset - padding - slideOffset, y: 0),
+ NSPoint(x: width - offset - padding, y: height)
+ )
+ ])
path.lineWidth = 2.0
return path
let width = bounds.width
let height = bounds.height
- let path = multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
- .appended {
- (NSPoint(x: width - offset - padding - slideOffset, y: 0),
- NSPoint(x: width - offset - padding, y: height))
- }
- .appended {
- (NSPoint(x: width - offset - padding * 2 - slideOffset, y: 0),
- NSPoint(x: width - offset - padding * 2, y: height))
- }
- }
+ let path = multiline(lines:
+ [
+ (
+ NSPoint(x: width - offset - slideOffset, y: 0),
+ NSPoint(x: width - offset, y: height)
+ ),
+ (
+ NSPoint(x: width - offset - padding - slideOffset, y: 0),
+ NSPoint(x: width - offset - padding, y: height)
+ ),
+ (
+ NSPoint(x: width - offset - padding * 2 - slideOffset, y: 0),
+ NSPoint(x: width - offset - padding * 2, y: height)
+ )
+ ])
path.lineWidth = 2.0
return path
let width = bounds.width
let height = bounds.height
- let path = polyline {
- [NSPoint]()
- .appended { NSPoint(x: width - offset - slideOffset, y: 0) }
- .appended { NSPoint(x: width - offset, y: height * 0.5) }
- .appended { NSPoint(x: width - offset - anglePoint, y: height) }
- }
- polyline {
- [NSPoint]()
- .appended { NSPoint(x: width - offset - padding - slideOffset, y: 0) }
- .appended { NSPoint(x: width - offset - padding, y: height * 0.5) }
- .appended { NSPoint(x: width - offset - padding - anglePoint, y: height) }
- }
+ let path = polyline(points:
+ [
+ NSPoint(x: width - offset - slideOffset, y: 0),
+ NSPoint(x: width - offset, y: height * 0.5),
+ NSPoint(x: width - offset - anglePoint, y: height)
+ ])
+ polyline(points:
+ [
+ NSPoint(x: width - offset - padding - slideOffset, y: 0),
+ NSPoint(x: width - offset - padding, y: height * 0.5),
+ NSPoint(x: width - offset - padding - anglePoint, y: height)
+ ])
.map { path?.append($0) }
path?.lineWidth = 2.0
(NSPoint(x: 209.5, y: 0), NSPoint(x: 209.5, y: height)),
(NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)),
(NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5))
- ]
- )
+ ])
.stroke()
}
}
fileprivate func removeAllTrackingAreas() {
- trackingAreas.forEach { removeTrackingArea($0) }
+ trackingAreas.forEach(removeTrackingArea)
}
fileprivate func setTrackingArea() {
extension TiledImageView: NSDraggingSource {
- func draggingSession(_ session: NSDraggingSession,
- sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {
+ func draggingSession(_ session: NSDraggingSession, sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {
return context == .withinApplication ? .move : []
}