From 5d7a4a5dd55e48faf199af8d6c02c9c84842f04e Mon Sep 17 00:00:00 2001 From: natmark Date: Sun, 31 Dec 2017 01:23:21 +0900 Subject: [PATCH 01/13] :sparkles: Supports OSX --- ProcessingKit.xcodeproj/project.pbxproj | 175 +++++++++++++++++- .../xcschemes/ProcessingKit OSX.xcscheme | 101 ++++++++++ ProcessingKit/Color/Color.swift | 5 +- ProcessingKit/Extensions/CGPoint.swift | 5 + ProcessingKit/Extensions/NSImage.swift | 26 +++ ProcessingKit/Extensions/NSView.swift | 22 +++ ProcessingKit/Extensions/String.swift | 10 +- ProcessingKit/Extensions/UIColor.swift | 4 + ProcessingKit/Image/Image.swift | 8 +- ProcessingKit/Input/Event.swift | 39 ++++ ProcessingKit/MultiplatformCommon.swift | 32 ++++ ProcessingKit/ProcessingView.swift | 34 +++- ProcessingKit/Shape/Shape.swift | 18 +- ProcessingKit/Shape/Vertex.swift | 4 +- ProcessingKit/Transform/Transform.swift | 14 +- ProcessingKit/Typography/Text.swift | 12 +- 16 files changed, 478 insertions(+), 31 deletions(-) create mode 100644 ProcessingKit.xcodeproj/xcshareddata/xcschemes/ProcessingKit OSX.xcscheme create mode 100644 ProcessingKit/Extensions/NSImage.swift create mode 100644 ProcessingKit/Extensions/NSView.swift create mode 100644 ProcessingKit/MultiplatformCommon.swift diff --git a/ProcessingKit.xcodeproj/project.pbxproj b/ProcessingKit.xcodeproj/project.pbxproj index 927fe5a..11f057d 100644 --- a/ProcessingKit.xcodeproj/project.pbxproj +++ b/ProcessingKit.xcodeproj/project.pbxproj @@ -27,6 +27,25 @@ E76820211F7B6446009E8FD2 /* Vertex.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76820201F7B6446009E8FD2 /* Vertex.swift */; }; E76820241F7B647A009E8FD2 /* Transform.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76820231F7B647A009E8FD2 /* Transform.swift */; }; E7B77DCD1FF7D30500CE691A /* CGPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B77DCC1FF7D30500CE691A /* CGPoint.swift */; }; + E7B77E141FF7E1B300CE691A /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = E70BB68B1F40902A00E0372D /* Color.swift */; }; + E7B77E151FF7E1B300CE691A /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76046C01F408B2E00921B1A /* Constants.swift */; }; + E7B77E161FF7E1B300CE691A /* Frame.swift in Sources */ = {isa = PBXBuildFile; fileRef = E70BB68F1F40937100E0372D /* Frame.swift */; }; + E7B77E171FF7E1B300CE691A /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7387A481F44828F00C3B35C /* String.swift */; }; + E7B77E181FF7E1B300CE691A /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E713695F1F44945900267715 /* UIColor.swift */; }; + E7B77E191FF7E1B300CE691A /* CGPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B77DCC1FF7D30500CE691A /* CGPoint.swift */; }; + E7B77E1A1FF7E1B300CE691A /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = E747DDA81F44656E006BAC6A /* Image.swift */; }; + E7B77E1B1FF7E1B300CE691A /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76820181F7B32B8009E8FD2 /* Date.swift */; }; + E7B77E1C1FF7E1B300CE691A /* Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7054AE11F3A0C8800EA0C0F /* Event.swift */; }; + E7B77E1D1FF7E1B300CE691A /* Shape.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7054ADF1F3A0A7E00EA0C0F /* Shape.swift */; }; + E7B77E1E1FF7E1B300CE691A /* Vertex.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76820201F7B6446009E8FD2 /* Vertex.swift */; }; + E7B77E1F1FF7E1B300CE691A /* Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76046B71F4088FB00921B1A /* Loop.swift */; }; + E7B77E201FF7E1B300CE691A /* Transform.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76820231F7B647A009E8FD2 /* Transform.swift */; }; + E7B77E211FF7E1B300CE691A /* Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = E70BB6881F408FAB00E0372D /* Text.swift */; }; + E7B77E221FF7E1B300CE691A /* ProcessingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7054AD31F34CCB200EA0C0F /* ProcessingView.swift */; }; + E7B77E241FF7E30C00CE691A /* MultiplatformCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B77E231FF7E30C00CE691A /* MultiplatformCommon.swift */; }; + E7B77E251FF7E36F00CE691A /* MultiplatformCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B77E231FF7E30C00CE691A /* MultiplatformCommon.swift */; }; + E7B77E2B1FF7EC6600CE691A /* NSImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B77E291FF7EBFF00CE691A /* NSImage.swift */; }; + E7B77E2E1FF7F19D00CE691A /* NSView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B77E2C1FF7F19700CE691A /* NSView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -64,6 +83,10 @@ E76820231F7B647A009E8FD2 /* Transform.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transform.swift; sourceTree = ""; }; E76820351F7E49B1009E8FD2 /* Demo.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = Demo.playground; path = ProcessingKit/Demo.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; E7B77DCC1FF7D30500CE691A /* CGPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGPoint.swift; sourceTree = ""; }; + E7B77DD31FF7E02900CE691A /* ProcessingKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ProcessingKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + E7B77E231FF7E30C00CE691A /* MultiplatformCommon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiplatformCommon.swift; sourceTree = ""; }; + E7B77E291FF7EBFF00CE691A /* NSImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSImage.swift; sourceTree = ""; }; + E7B77E2C1FF7F19700CE691A /* NSView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -82,6 +105,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E7B77DCF1FF7E02900CE691A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -108,6 +138,7 @@ children = ( E7212F401F34B5A600173CD8 /* ProcessingKit.framework */, E7212F491F34B5A600173CD8 /* ProcessingKitTests.xctest */, + E7B77DD31FF7E02900CE691A /* ProcessingKit.framework */, ); name = Products; sourceTree = ""; @@ -128,6 +159,7 @@ E7212F441F34B5A600173CD8 /* Info.plist */, E7212F431F34B5A600173CD8 /* ProcessingKit.h */, E7054AD31F34CCB200EA0C0F /* ProcessingView.swift */, + E7B77E231FF7E30C00CE691A /* MultiplatformCommon.swift */, ); path = ProcessingKit; sourceTree = ""; @@ -149,6 +181,8 @@ E7387A481F44828F00C3B35C /* String.swift */, E713695F1F44945900267715 /* UIColor.swift */, E7B77DCC1FF7D30500CE691A /* CGPoint.swift */, + E7B77E291FF7EBFF00CE691A /* NSImage.swift */, + E7B77E2C1FF7F19700CE691A /* NSView.swift */, ); path = Extensions; sourceTree = ""; @@ -238,6 +272,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E7B77DD01FF7E02900CE691A /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -278,13 +319,31 @@ productReference = E7212F491F34B5A600173CD8 /* ProcessingKitTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + E7B77DD21FF7E02900CE691A /* ProcessingKit OSX */ = { + isa = PBXNativeTarget; + buildConfigurationList = E7B77DE81FF7E02A00CE691A /* Build configuration list for PBXNativeTarget "ProcessingKit OSX" */; + buildPhases = ( + E7B77DCE1FF7E02900CE691A /* Sources */, + E7B77DCF1FF7E02900CE691A /* Frameworks */, + E7B77DD01FF7E02900CE691A /* Headers */, + E7B77DD11FF7E02900CE691A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "ProcessingKit OSX"; + productName = "ProcessingKit OSX"; + productReference = E7B77DD31FF7E02900CE691A /* ProcessingKit.framework */; + productType = "com.apple.product-type.framework"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ E7212F371F34B5A600173CD8 /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0830; + LastSwiftUpdateCheck = 0910; LastUpgradeCheck = 0830; ORGANIZATIONNAME = "Atsuya Sato"; TargetAttributes = { @@ -297,6 +356,11 @@ CreatedOnToolsVersion = 8.3.3; ProvisioningStyle = Automatic; }; + E7B77DD21FF7E02900CE691A = { + CreatedOnToolsVersion = 9.1; + DevelopmentTeam = DEQGLB9PU4; + ProvisioningStyle = Automatic; + }; }; }; buildConfigurationList = E7212F3A1F34B5A600173CD8 /* Build configuration list for PBXProject "ProcessingKit" */; @@ -313,6 +377,7 @@ targets = ( E7212F3F1F34B5A600173CD8 /* ProcessingKit */, E7212F481F34B5A600173CD8 /* ProcessingKitTests */, + E7B77DD21FF7E02900CE691A /* ProcessingKit OSX */, ); }; /* End PBXProject section */ @@ -332,6 +397,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E7B77DD11FF7E02900CE691A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -369,6 +441,7 @@ E76820241F7B647A009E8FD2 /* Transform.swift in Sources */, E70BB6891F408FB000E0372D /* Text.swift in Sources */, E76820191F7B32B8009E8FD2 /* Date.swift in Sources */, + E7B77E241FF7E30C00CE691A /* MultiplatformCommon.swift in Sources */, E7B77DCD1FF7D30500CE691A /* CGPoint.swift in Sources */, E76046C11F408B2E00921B1A /* Constants.swift in Sources */, ); @@ -384,6 +457,31 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E7B77DCE1FF7E02900CE691A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E7B77E141FF7E1B300CE691A /* Color.swift in Sources */, + E7B77E151FF7E1B300CE691A /* Constants.swift in Sources */, + E7B77E161FF7E1B300CE691A /* Frame.swift in Sources */, + E7B77E171FF7E1B300CE691A /* String.swift in Sources */, + E7B77E181FF7E1B300CE691A /* UIColor.swift in Sources */, + E7B77E191FF7E1B300CE691A /* CGPoint.swift in Sources */, + E7B77E1A1FF7E1B300CE691A /* Image.swift in Sources */, + E7B77E2E1FF7F19D00CE691A /* NSView.swift in Sources */, + E7B77E1B1FF7E1B300CE691A /* Date.swift in Sources */, + E7B77E1C1FF7E1B300CE691A /* Event.swift in Sources */, + E7B77E1D1FF7E1B300CE691A /* Shape.swift in Sources */, + E7B77E1E1FF7E1B300CE691A /* Vertex.swift in Sources */, + E7B77E1F1FF7E1B300CE691A /* Loop.swift in Sources */, + E7B77E2B1FF7EC6600CE691A /* NSImage.swift in Sources */, + E7B77E201FF7E1B300CE691A /* Transform.swift in Sources */, + E7B77E251FF7E36F00CE691A /* MultiplatformCommon.swift in Sources */, + E7B77E211FF7E1B300CE691A /* Text.swift in Sources */, + E7B77E221FF7E1B300CE691A /* ProcessingView.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -565,6 +663,72 @@ }; name = Release; }; + E7B77DE41FF7E02A00CE691A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = DEQGLB9PU4; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = ProcessingKit/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = "io.github.natmark.ProcessingKit-OSX"; + PRODUCT_NAME = ProcessingKit; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + E7B77DE51FF7E02A00CE691A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = DEQGLB9PU4; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = ProcessingKit/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = "io.github.natmark.ProcessingKit-OSX"; + PRODUCT_NAME = ProcessingKit; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -595,6 +759,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + E7B77DE81FF7E02A00CE691A /* Build configuration list for PBXNativeTarget "ProcessingKit OSX" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E7B77DE41FF7E02A00CE691A /* Debug */, + E7B77DE51FF7E02A00CE691A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = E7212F371F34B5A600173CD8 /* Project object */; diff --git a/ProcessingKit.xcodeproj/xcshareddata/xcschemes/ProcessingKit OSX.xcscheme b/ProcessingKit.xcodeproj/xcshareddata/xcschemes/ProcessingKit OSX.xcscheme new file mode 100644 index 0000000..9f52eaa --- /dev/null +++ b/ProcessingKit.xcodeproj/xcshareddata/xcschemes/ProcessingKit OSX.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProcessingKit/Color/Color.swift b/ProcessingKit/Color/Color.swift index 75fbfad..dc9ce41 100644 --- a/ProcessingKit/Color/Color.swift +++ b/ProcessingKit/Color/Color.swift @@ -37,7 +37,7 @@ struct ColorModel: ColorModelContract { } func background(_ color: UIColor) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g!.clear(self.frameComponents.bounds) } @@ -46,7 +46,7 @@ struct ColorModel: ColorModelContract { } func clear() { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g!.clear(self.frameComponents.bounds) } @@ -89,6 +89,7 @@ extension ProcessingView: ColorModelContract { public func background(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat = 255) { self.colorModel.background(r, g, b, a) self.backgroundColor = UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a / 255.0) + } public func clear() { diff --git a/ProcessingKit/Extensions/CGPoint.swift b/ProcessingKit/Extensions/CGPoint.swift index bfacad6..fdc1750 100644 --- a/ProcessingKit/Extensions/CGPoint.swift +++ b/ProcessingKit/Extensions/CGPoint.swift @@ -6,6 +6,11 @@ // Copyright © 2017年 Atsuya Sato. All rights reserved. // +#if !os(iOS) + import Cocoa + typealias CGPoint = NSPoint +#endif + extension CGPoint { func addTo(_ a: CGPoint) -> CGPoint { return CGPoint(x: self.x + a.x, y: self.y + a.y) diff --git a/ProcessingKit/Extensions/NSImage.swift b/ProcessingKit/Extensions/NSImage.swift new file mode 100644 index 0000000..1d517c7 --- /dev/null +++ b/ProcessingKit/Extensions/NSImage.swift @@ -0,0 +1,26 @@ +// +// NSImage.swift +// ProcessingKit +// +// Created by AtsuyaSato on 2017/12/31. +// Copyright © 2017年 Atsuya Sato. All rights reserved. +// + +import Foundation +import Cocoa + +extension NSImage { + var cgImage: CGImage? { + var imageRect = NSRect(x: 0, y: 0, width: size.width, height: size.height) + #if swift(>=3.0) + guard let image = cgImage(forProposedRect: &imageRect, context: nil, hints: nil) else { + return nil + } + #else + guard let image = CGImageForProposedRect(&imageRect, context: nil, hints: nil) else { + return nil + } + #endif + return image + } +} diff --git a/ProcessingKit/Extensions/NSView.swift b/ProcessingKit/Extensions/NSView.swift new file mode 100644 index 0000000..c447b44 --- /dev/null +++ b/ProcessingKit/Extensions/NSView.swift @@ -0,0 +1,22 @@ +// +// NSView.swift +// ProcessingKit +// +// Created by AtsuyaSato on 2017/12/31. +// Copyright © 2017年 Atsuya Sato. All rights reserved. +// + +import Cocoa + +extension NSView { + var backgroundColor: NSColor? { + get { + guard let layer = layer, let backgroundColor = layer.backgroundColor else {return nil} + return NSColor(cgColor: backgroundColor) + } + set { + wantsLayer = true + layer?.backgroundColor = newValue?.cgColor + } + } +} diff --git a/ProcessingKit/Extensions/String.swift b/ProcessingKit/Extensions/String.swift index 9628033..a167020 100644 --- a/ProcessingKit/Extensions/String.swift +++ b/ProcessingKit/Extensions/String.swift @@ -6,10 +6,18 @@ // Copyright © 2017年 Atsuya Sato. All rights reserved. // +#if !os(iOS) + import Cocoa +#endif + extension String { func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat { let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude) - let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) + #if os(iOS) + let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) + #else + let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) + #endif return ceil(boundingBox.height) } diff --git a/ProcessingKit/Extensions/UIColor.swift b/ProcessingKit/Extensions/UIColor.swift index bd0d8c6..b713752 100644 --- a/ProcessingKit/Extensions/UIColor.swift +++ b/ProcessingKit/Extensions/UIColor.swift @@ -6,6 +6,10 @@ // Copyright © 2017年 Atsuya Sato. All rights reserved. // +#if !os(iOS) + import Cocoa +#endif + extension UIColor { open class func hexStr (hexStr: NSString, alpha: CGFloat) -> UIColor { let alpha = alpha diff --git a/ProcessingKit/Image/Image.swift b/ProcessingKit/Image/Image.swift index df83a1f..b75b057 100644 --- a/ProcessingKit/Image/Image.swift +++ b/ProcessingKit/Image/Image.swift @@ -6,6 +6,10 @@ // Copyright © 2017年 Atsuya Sato. All rights reserved. // +#if !os(iOS) +import Cocoa +#endif + public protocol ImageModelContract { func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) @@ -14,7 +18,7 @@ public protocol ImageModelContract { struct ImageModel: ImageModelContract { func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.saveGState() g?.translateBy(x: 0.0, y: img.size.height) g?.scaleBy(x: 1.0, y: -1.0) @@ -25,7 +29,7 @@ struct ImageModel: ImageModelContract { } func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.saveGState() g?.translateBy(x: 0.0, y: height) g?.scaleBy(x: 1.0, y: -1.0) diff --git a/ProcessingKit/Input/Event.swift b/ProcessingKit/Input/Event.swift index 28b3f3a..bbcb77e 100644 --- a/ProcessingKit/Input/Event.swift +++ b/ProcessingKit/Input/Event.swift @@ -6,6 +6,10 @@ // Copyright © 2017年 Atsuya Sato. All rights reserved. // +#if !os(iOS) +import Cocoa +#endif + import Foundation class EventComponents { @@ -25,9 +29,15 @@ protocol EventModelContract { var touchY: CGFloat { get } var touchesX: Set { get } var touchesY: Set { get } + #if os(iOS) mutating func touchesBegan(_ touches: Set, with event: UIEvent?) mutating func touchesMoved(_ touches: Set, with event: UIEvent?) mutating func touchesEnded(_ touches: Set, with event: UIEvent?) + #else + mutating func touchesBegan(with event: NSEvent) + mutating func touchesMoved(with event: NSEvent) + mutating func touchesEnded(with event: NSEvent) + #endif } struct EventModel: EventModelContract { @@ -62,6 +72,7 @@ struct EventModel: EventModelContract { return self.eventComponents.touchesY } + #if os(iOS) mutating func touchesBegan(_ touches: Set, with event: UIEvent?) { self.storeTouches(touches) self.eventComponents.fingerPressed = true @@ -78,6 +89,22 @@ struct EventModel: EventModelContract { self.eventComponents.fingerTapped = false self.eventComponents.fingerReleased = true } + #else + mutating func touchesBegan(with event: NSEvent) { + self.storeTouches(event.touches(matching: .any, in: nil)) + self.eventComponents.fingerPressed = true + self.eventComponents.fingerTapped = true + } + mutating func touchesMoved(with event: NSEvent) { + self.storeTouches(event.touches(matching: .any, in: nil)) + self.eventComponents.fingerMoved = true + } + mutating func touchesEnded(with event: NSEvent) { + self.storeTouches(event.touches(matching: .any, in: nil)) + self.eventComponents.fingerTapped = false + self.eventComponents.fingerReleased = true + } + #endif private mutating func storeTouches(_ touches: Set) { self.eventComponents.touchesX.removeAll() @@ -117,6 +144,7 @@ extension ProcessingView: EventModelContract { return self.eventModel.touchesY } + #if os(iOS) open override func touchesBegan(_ touches: Set, with event: UIEvent?) { self.eventModel.touchesBegan(touches, with: event) } @@ -128,4 +156,15 @@ extension ProcessingView: EventModelContract { open override func touchesEnded(_ touches: Set, with event: UIEvent?) { self.eventModel.touchesEnded(touches, with: event) } + #else + open override func touchesBegan(with event: NSEvent) { + self.eventModel.touchesBegan(with: event) + } + open override func touchesMoved(with event: NSEvent) { + self.eventModel.touchesMoved(with: event) + } + open override func touchesEnded(with event: NSEvent) { + self.eventModel.touchesEnded(with: event) + } + #endif } diff --git a/ProcessingKit/MultiplatformCommon.swift b/ProcessingKit/MultiplatformCommon.swift new file mode 100644 index 0000000..049b79a --- /dev/null +++ b/ProcessingKit/MultiplatformCommon.swift @@ -0,0 +1,32 @@ +// +// MultiplatformCommon.swift +// ProcessingKit +// +// Created by AtsuyaSato on 2017/12/31. +// Copyright © 2017年 Atsuya Sato. All rights reserved. +// + +#if !os(iOS) +import Cocoa +public typealias UIColor = NSColor +public typealias UIImageView = NSImageView +public typealias UIImage = NSImage +public typealias UIViewController = NSViewController +public typealias UITouch = NSTouch +public typealias UIFont = NSFont +public typealias UIEvent = NSEvent +public typealias UIView = NSView +public typealias UIResponder = NSResponder +#endif + +import Foundation + +public class MultiplatformCommon { + public class func getCurrentContext() -> CGContext? { + #if os(iOS) + return UIGraphicsGetCurrentContext() + #else + return NSGraphicsContext.current()?.cgContext + #endif + } +} diff --git a/ProcessingKit/ProcessingView.swift b/ProcessingKit/ProcessingView.swift index fd222ba..0eb2750 100644 --- a/ProcessingKit/ProcessingView.swift +++ b/ProcessingKit/ProcessingView.swift @@ -6,6 +6,12 @@ // Copyright © 2017年 Atsuya Sato. All rights reserved. // +#if !os(iOS) +import Cocoa +#endif + +import Foundation + @objc public protocol ProcessingViewDelegate { @objc optional func setup() @objc optional func draw() @@ -101,7 +107,9 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { } private func configuration() { + #if os(iOS) self.isUserInteractionEnabled = true + #endif self.delegate = self } @@ -112,7 +120,11 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { private func parentViewController() -> UIViewController? { var parentResponder: UIResponder? = self while true { + #if os(iOS) guard let nextResponder = parentResponder?.next else { return nil } + #else + guard let nextResponder = parentResponder?.nextResponder else { return nil } + #endif if let viewController = nextResponder as? UIViewController { return viewController } @@ -131,8 +143,13 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { // MARK: - Override Methods open override func draw(_ rect: CGRect) { - UIGraphicsBeginImageContext(rect.size) - self.image?.draw(at: CGPoint(x: 0, y: 0)) + #if os(iOS) + UIGraphicsBeginImageContext(rect.size) + self.image?.draw(at: CGPoint(x: 0, y: 0)) + #else + self.image?.lockFocus() + #endif + // Setup if firstcall { self.firstcall = false @@ -156,9 +173,16 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { // Draw self.frameComponents.frameCount += 1 self.delegate?.draw?() - let drawnImage = UIGraphicsGetImageFromCurrentImageContext() - self.image = drawnImage - UIGraphicsEndImageContext() + + #if os(iOS) + let drawnImage = UIGraphicsGetImageFromCurrentImageContext() + self.image = drawnImage + UIGraphicsEndImageContext() + #else + guard let cgImage = NSGraphicsContext.current()?.cgContext.makeImage() else { return } + self.image = NSImage(cgImage: cgImage, size: self.frame.size) + self.image?.unlockFocus() + #endif if self.delegate?.draw == nil { self.noLoop() diff --git a/ProcessingKit/Shape/Shape.swift b/ProcessingKit/Shape/Shape.swift index abb2ee9..f8a2a52 100644 --- a/ProcessingKit/Shape/Shape.swift +++ b/ProcessingKit/Shape/Shape.swift @@ -29,14 +29,14 @@ struct ShapeModel: ShapeModelContract { } func point(_ x: CGFloat, _ y: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.setFillColor(self.colorComponents.stroke.cgColor) g?.fill(CGRect(x: x, y: y, width: 1.0, height: 1.0)) } func line(_ x1: CGFloat, _ y1: CGFloat, _ x2: CGFloat, _ y2: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.saveGState() @@ -49,7 +49,7 @@ struct ShapeModel: ShapeModelContract { } func rect(_ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.stroke(CGRect(x: x, y: y, width: width, height: height)) @@ -57,14 +57,14 @@ struct ShapeModel: ShapeModelContract { } func ellipse(_ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.strokeEllipse(in: CGRect(x: x - width / 2, y: y - height / 2, width: width, height: height)) g?.fillEllipse(in: CGRect(x: x - width / 2, y: y - height / 2, width: width, height: height)) } func arc(_ x: CGFloat, _ y: CGFloat, _ radius: CGFloat, _ start: CGFloat, _ stop: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.saveGState() @@ -74,7 +74,7 @@ struct ShapeModel: ShapeModelContract { } func triangle(_ x1: CGFloat, _ y1: CGFloat, _ x2: CGFloat, _ y2: CGFloat, _ x3: CGFloat, _ y3: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.saveGState() @@ -88,7 +88,7 @@ struct ShapeModel: ShapeModelContract { } func quad(_ x1: CGFloat, _ y1: CGFloat, _ x2: CGFloat, _ y2: CGFloat, _ x3: CGFloat, _ y3: CGFloat, _ x4: CGFloat, _ y4: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.saveGState() @@ -124,7 +124,7 @@ struct ShapeModel: ShapeModelContract { b2 = b2.addTo(p2.multiplyBy(2 * pow(d3, 2 * alpha) + 3 * pow(d3, alpha) * pow(d2, alpha) + pow(d2, 2 * alpha))) b2 = b2.multiplyBy(1.0 / (3 * pow(d3, alpha) * (pow(d3, alpha) + pow(d2, alpha)))) - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.saveGState() @@ -135,7 +135,7 @@ struct ShapeModel: ShapeModelContract { } func bezier(_ x1: CGFloat, _ y1: CGFloat, _ cpx1: CGFloat, _ cpy1: CGFloat, _ cpx2: CGFloat, _ cpy2: CGFloat, _ x2: CGFloat, _ y2: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) g?.saveGState() diff --git a/ProcessingKit/Shape/Vertex.swift b/ProcessingKit/Shape/Vertex.swift index 4a613a2..8195b09 100644 --- a/ProcessingKit/Shape/Vertex.swift +++ b/ProcessingKit/Shape/Vertex.swift @@ -53,7 +53,7 @@ struct VertexModel: VertexModelContract { switch self.vertexComponents.kind { case .points: - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.setFillColor(self.colorComponents.stroke.cgColor) for vertex in self.vertexComponents.vertexes { g?.fill(CGRect(x: vertex.x, y: vertex.y, width: self.colorComponents.strokeWeight, height: self.colorComponents.strokeWeight)) @@ -91,7 +91,7 @@ struct VertexModel: VertexModelContract { } private func addLineToPoints(vertexes: [CGPoint], isClosed: Bool) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() setGraphicsConfiguration(context: g) for (index, vertex) in vertexes.enumerated() { diff --git a/ProcessingKit/Transform/Transform.swift b/ProcessingKit/Transform/Transform.swift index 117a123..aba2d8f 100644 --- a/ProcessingKit/Transform/Transform.swift +++ b/ProcessingKit/Transform/Transform.swift @@ -20,38 +20,38 @@ protocol TransformModelContract { struct TransformModel: TransformModelContract { func pushMatrix() { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.saveGState() } func popMatrix() { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.restoreGState() } func scale(_ s: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.scaleBy(x: s, y: s) } func scale(_ x: CGFloat, _ y: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.scaleBy(x: x, y: y) } func shere(_ angleX: CGFloat, _ angleY: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.concatenate(CGAffineTransform(a: 1, b: angleY, c: angleX, d: 1, tx: 0, ty: 0)) } func rotate(_ angle: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.rotate(by: angle) } func translate(_ x: CGFloat, _ y: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.translateBy(x: x, y: y) } } diff --git a/ProcessingKit/Typography/Text.swift b/ProcessingKit/Typography/Text.swift index 338cf92..1ee30fa 100644 --- a/ProcessingKit/Typography/Text.swift +++ b/ProcessingKit/Typography/Text.swift @@ -6,6 +6,10 @@ // Copyright © 2017年 Atsuya Sato. All rights reserved. // +#if !os(iOS) + import Cocoa +#endif + import Foundation class TextComponents { @@ -45,7 +49,7 @@ struct TextModel: TextModelContract { } func text(_ str: String, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) { - let g = UIGraphicsGetCurrentContext() + let g = MultiplatformCommon.getCurrentContext() g?.saveGState() @@ -80,7 +84,11 @@ struct TextModel: TextModelContract { } func textWidth(_ str: String) -> CGFloat { - let size = str.size(attributes: [NSFontAttributeName: self.textComponents.textFont]) + #if os(iOS) + let size = str.size(attributes: [NSFontAttributeName: self.textComponents.textFont]) + #else + let size = str.size(withAttributes: [NSFontAttributeName: self.textComponents.textFont]) + #endif return size.width } From d2f8fa4a9e9a85ad3b1bdefa121fa12959f756c9 Mon Sep 17 00:00:00 2001 From: natmark Date: Mon, 1 Jan 2018 00:22:24 +0900 Subject: [PATCH 02/13] :construction: Add OSX Example --- ProcessingKit/ProcessingView.swift | 2 +- .../project.pbxproj | 540 +++++++++++++ .../contents.xcworkspacedata | 7 + .../ProcessingKitOSXExample/AppDelegate.swift | 26 + .../AppIcon.appiconset/Contents.json | 58 ++ .../Base.lproj/Main.storyboard | 733 ++++++++++++++++++ .../ProcessingKitOSXExample/CustomView.swift | 32 + .../ProcessingKitOSXExample/Info.plist | 32 + .../ProcessingKitOSXExample.entitlements | 10 + .../ViewController.swift | 27 + .../ProcessingKitOSXExampleTests/Info.plist | 22 + .../ProcessingKitOSXExampleTests.swift | 36 + 12 files changed, 1524 insertions(+), 1 deletion(-) create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample/AppDelegate.swift create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample/Base.lproj/Main.storyboard create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample/Info.plist create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExample/ViewController.swift create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExampleTests/Info.plist create mode 100644 ProcessingKitOSXExample/ProcessingKitOSXExampleTests/ProcessingKitOSXExampleTests.swift diff --git a/ProcessingKit/ProcessingView.swift b/ProcessingKit/ProcessingView.swift index 0eb2750..c1b6da3 100644 --- a/ProcessingKit/ProcessingView.swift +++ b/ProcessingKit/ProcessingView.swift @@ -181,7 +181,7 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { #else guard let cgImage = NSGraphicsContext.current()?.cgContext.makeImage() else { return } self.image = NSImage(cgImage: cgImage, size: self.frame.size) - self.image?.unlockFocus() + //self.image?.unlockFocus() #endif if self.delegate?.draw == nil { diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj b/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj new file mode 100644 index 0000000..6230c67 --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj @@ -0,0 +1,540 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 48; + objects = { + +/* Begin PBXBuildFile section */ + E72410561FF89A2200FBF78D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72410551FF89A2200FBF78D /* AppDelegate.swift */; }; + E72410581FF89A2200FBF78D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72410571FF89A2200FBF78D /* ViewController.swift */; }; + E724105A1FF89A2200FBF78D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E72410591FF89A2200FBF78D /* Assets.xcassets */; }; + E724105D1FF89A2200FBF78D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E724105B1FF89A2200FBF78D /* Main.storyboard */; }; + E72410691FF89A2200FBF78D /* ProcessingKitOSXExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72410681FF89A2200FBF78D /* ProcessingKitOSXExampleTests.swift */; }; + E72410801FF89A5000FBF78D /* ProcessingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E724107E1FF89A3400FBF78D /* ProcessingKit.framework */; }; + E72410811FF89A5000FBF78D /* ProcessingKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E724107E1FF89A3400FBF78D /* ProcessingKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + E72410861FF89AD100FBF78D /* CustomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72410851FF89AD100FBF78D /* CustomView.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + E72410651FF89A2200FBF78D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = E724104A1FF89A2200FBF78D /* Project object */; + proxyType = 1; + remoteGlobalIDString = E72410511FF89A2200FBF78D; + remoteInfo = ProcessingKitOSXExample; + }; + E72410791FF89A3400FBF78D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = E72410731FF89A3300FBF78D /* ProcessingKit.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E7212F401F34B5A600173CD8; + remoteInfo = ProcessingKit; + }; + E724107B1FF89A3400FBF78D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = E72410731FF89A3300FBF78D /* ProcessingKit.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E7212F491F34B5A600173CD8; + remoteInfo = ProcessingKitTests; + }; + E724107D1FF89A3400FBF78D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = E72410731FF89A3300FBF78D /* ProcessingKit.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E7B77DD31FF7E02900CE691A; + remoteInfo = "ProcessingKit OSX"; + }; + E72410821FF89A5000FBF78D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = E72410731FF89A3300FBF78D /* ProcessingKit.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = E7B77DD21FF7E02900CE691A; + remoteInfo = "ProcessingKit OSX"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + E72410841FF89A5000FBF78D /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + E72410811FF89A5000FBF78D /* ProcessingKit.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + E72410521FF89A2200FBF78D /* ProcessingKitOSXExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ProcessingKitOSXExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + E72410551FF89A2200FBF78D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + E72410571FF89A2200FBF78D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + E72410591FF89A2200FBF78D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + E724105C1FF89A2200FBF78D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + E724105E1FF89A2200FBF78D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E724105F1FF89A2200FBF78D /* ProcessingKitOSXExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ProcessingKitOSXExample.entitlements; sourceTree = ""; }; + E72410641FF89A2200FBF78D /* ProcessingKitOSXExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ProcessingKitOSXExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + E72410681FF89A2200FBF78D /* ProcessingKitOSXExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcessingKitOSXExampleTests.swift; sourceTree = ""; }; + E724106A1FF89A2200FBF78D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E72410731FF89A3300FBF78D /* ProcessingKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ProcessingKit.xcodeproj; path = ../ProcessingKit.xcodeproj; sourceTree = ""; }; + E72410851FF89AD100FBF78D /* CustomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomView.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E724104F1FF89A2200FBF78D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + E72410801FF89A5000FBF78D /* ProcessingKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E72410611FF89A2200FBF78D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E72410491FF89A2200FBF78D = { + isa = PBXGroup; + children = ( + E72410541FF89A2200FBF78D /* ProcessingKitOSXExample */, + E72410671FF89A2200FBF78D /* ProcessingKitOSXExampleTests */, + E72410531FF89A2200FBF78D /* Products */, + E72410731FF89A3300FBF78D /* ProcessingKit.xcodeproj */, + ); + sourceTree = ""; + }; + E72410531FF89A2200FBF78D /* Products */ = { + isa = PBXGroup; + children = ( + E72410521FF89A2200FBF78D /* ProcessingKitOSXExample.app */, + E72410641FF89A2200FBF78D /* ProcessingKitOSXExampleTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + E72410541FF89A2200FBF78D /* ProcessingKitOSXExample */ = { + isa = PBXGroup; + children = ( + E72410551FF89A2200FBF78D /* AppDelegate.swift */, + E72410571FF89A2200FBF78D /* ViewController.swift */, + E72410851FF89AD100FBF78D /* CustomView.swift */, + E72410591FF89A2200FBF78D /* Assets.xcassets */, + E724105B1FF89A2200FBF78D /* Main.storyboard */, + E724105E1FF89A2200FBF78D /* Info.plist */, + E724105F1FF89A2200FBF78D /* ProcessingKitOSXExample.entitlements */, + ); + path = ProcessingKitOSXExample; + sourceTree = ""; + }; + E72410671FF89A2200FBF78D /* ProcessingKitOSXExampleTests */ = { + isa = PBXGroup; + children = ( + E72410681FF89A2200FBF78D /* ProcessingKitOSXExampleTests.swift */, + E724106A1FF89A2200FBF78D /* Info.plist */, + ); + path = ProcessingKitOSXExampleTests; + sourceTree = ""; + }; + E72410741FF89A3300FBF78D /* Products */ = { + isa = PBXGroup; + children = ( + E724107A1FF89A3400FBF78D /* ProcessingKit.framework */, + E724107C1FF89A3400FBF78D /* ProcessingKitTests.xctest */, + E724107E1FF89A3400FBF78D /* ProcessingKit.framework */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E72410511FF89A2200FBF78D /* ProcessingKitOSXExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = E724106D1FF89A2200FBF78D /* Build configuration list for PBXNativeTarget "ProcessingKitOSXExample" */; + buildPhases = ( + E724104E1FF89A2200FBF78D /* Sources */, + E724104F1FF89A2200FBF78D /* Frameworks */, + E72410501FF89A2200FBF78D /* Resources */, + E72410841FF89A5000FBF78D /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + E72410831FF89A5000FBF78D /* PBXTargetDependency */, + ); + name = ProcessingKitOSXExample; + productName = ProcessingKitOSXExample; + productReference = E72410521FF89A2200FBF78D /* ProcessingKitOSXExample.app */; + productType = "com.apple.product-type.application"; + }; + E72410631FF89A2200FBF78D /* ProcessingKitOSXExampleTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = E72410701FF89A2200FBF78D /* Build configuration list for PBXNativeTarget "ProcessingKitOSXExampleTests" */; + buildPhases = ( + E72410601FF89A2200FBF78D /* Sources */, + E72410611FF89A2200FBF78D /* Frameworks */, + E72410621FF89A2200FBF78D /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + E72410661FF89A2200FBF78D /* PBXTargetDependency */, + ); + name = ProcessingKitOSXExampleTests; + productName = ProcessingKitOSXExampleTests; + productReference = E72410641FF89A2200FBF78D /* ProcessingKitOSXExampleTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E724104A1FF89A2200FBF78D /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0910; + LastUpgradeCheck = 0910; + ORGANIZATIONNAME = "Atsuya Sato"; + TargetAttributes = { + E72410511FF89A2200FBF78D = { + CreatedOnToolsVersion = 9.1; + ProvisioningStyle = Automatic; + }; + E72410631FF89A2200FBF78D = { + CreatedOnToolsVersion = 9.1; + ProvisioningStyle = Automatic; + TestTargetID = E72410511FF89A2200FBF78D; + }; + }; + }; + buildConfigurationList = E724104D1FF89A2200FBF78D /* Build configuration list for PBXProject "ProcessingKitOSXExample" */; + compatibilityVersion = "Xcode 8.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = E72410491FF89A2200FBF78D; + productRefGroup = E72410531FF89A2200FBF78D /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = E72410741FF89A3300FBF78D /* Products */; + ProjectRef = E72410731FF89A3300FBF78D /* ProcessingKit.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + E72410511FF89A2200FBF78D /* ProcessingKitOSXExample */, + E72410631FF89A2200FBF78D /* ProcessingKitOSXExampleTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + E724107A1FF89A3400FBF78D /* ProcessingKit.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = ProcessingKit.framework; + remoteRef = E72410791FF89A3400FBF78D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + E724107C1FF89A3400FBF78D /* ProcessingKitTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = ProcessingKitTests.xctest; + remoteRef = E724107B1FF89A3400FBF78D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + E724107E1FF89A3400FBF78D /* ProcessingKit.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = ProcessingKit.framework; + remoteRef = E724107D1FF89A3400FBF78D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXResourcesBuildPhase section */ + E72410501FF89A2200FBF78D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E724105A1FF89A2200FBF78D /* Assets.xcassets in Resources */, + E724105D1FF89A2200FBF78D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E72410621FF89A2200FBF78D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + E724104E1FF89A2200FBF78D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E72410861FF89AD100FBF78D /* CustomView.swift in Sources */, + E72410581FF89A2200FBF78D /* ViewController.swift in Sources */, + E72410561FF89A2200FBF78D /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E72410601FF89A2200FBF78D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E72410691FF89A2200FBF78D /* ProcessingKitOSXExampleTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + E72410661FF89A2200FBF78D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = E72410511FF89A2200FBF78D /* ProcessingKitOSXExample */; + targetProxy = E72410651FF89A2200FBF78D /* PBXContainerItemProxy */; + }; + E72410831FF89A5000FBF78D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = "ProcessingKit OSX"; + targetProxy = E72410821FF89A5000FBF78D /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + E724105B1FF89A2200FBF78D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + E724105C1FF89A2200FBF78D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + E724106B1FF89A2200FBF78D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "Mac Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.13; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + E724106C1FF89A2200FBF78D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "Mac Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.13; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + }; + name = Release; + }; + E724106E1FF89A2200FBF78D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = DEQGLB9PU4; + INFOPLIST_FILE = ProcessingKitOSXExample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = io.github.natmark.ProcessingKitOSXExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; + }; + name = Debug; + }; + E724106F1FF89A2200FBF78D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = DEQGLB9PU4; + INFOPLIST_FILE = ProcessingKitOSXExample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = io.github.natmark.ProcessingKitOSXExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; + }; + name = Release; + }; + E72410711FF89A2200FBF78D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = DEQGLB9PU4; + INFOPLIST_FILE = ProcessingKitOSXExampleTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = io.github.natmark.ProcessingKitOSXExampleTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ProcessingKitOSXExample.app/Contents/MacOS/ProcessingKitOSXExample"; + }; + name = Debug; + }; + E72410721FF89A2200FBF78D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = DEQGLB9PU4; + INFOPLIST_FILE = ProcessingKitOSXExampleTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = io.github.natmark.ProcessingKitOSXExampleTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ProcessingKitOSXExample.app/Contents/MacOS/ProcessingKitOSXExample"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E724104D1FF89A2200FBF78D /* Build configuration list for PBXProject "ProcessingKitOSXExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E724106B1FF89A2200FBF78D /* Debug */, + E724106C1FF89A2200FBF78D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E724106D1FF89A2200FBF78D /* Build configuration list for PBXNativeTarget "ProcessingKitOSXExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E724106E1FF89A2200FBF78D /* Debug */, + E724106F1FF89A2200FBF78D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E72410701FF89A2200FBF78D /* Build configuration list for PBXNativeTarget "ProcessingKitOSXExampleTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E72410711FF89A2200FBF78D /* Debug */, + E72410721FF89A2200FBF78D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = E724104A1FF89A2200FBF78D /* Project object */; +} diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..81fcbbf --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/AppDelegate.swift b/ProcessingKitOSXExample/ProcessingKitOSXExample/AppDelegate.swift new file mode 100644 index 0000000..2e4b61d --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/AppDelegate.swift @@ -0,0 +1,26 @@ +// +// AppDelegate.swift +// ProcessingKitOSXExample +// +// Created by AtsuyaSato on 2017/12/31. +// Copyright © 2017年 Atsuya Sato. All rights reserved. +// + +import Cocoa + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + + + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application + } + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } + + +} + diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/Assets.xcassets/AppIcon.appiconset/Contents.json b/ProcessingKitOSXExample/ProcessingKitOSXExample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..2db2b1c --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/Base.lproj/Main.storyboard b/ProcessingKitOSXExample/ProcessingKitOSXExample/Base.lproj/Main.storyboard new file mode 100644 index 0000000..a108512 --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/Base.lproj/Main.storyboard @@ -0,0 +1,733 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift b/ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift new file mode 100644 index 0000000..f5a6f6f --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift @@ -0,0 +1,32 @@ +// +// CustomView.swift +// ProcessingKitOSXExample +// +// Created by AtsuyaSato on 2017/12/31. +// Copyright © 2017年 Atsuya Sato. All rights reserved. +// + +import Foundation +import ProcessingKit +import Cocoa + +class CustomView: ProcessingView { + func setup() { + background(NSColor.white) + fill(NSColor.blue) + ellipse(50, 50, 100, 100) + } +// var x: CGFloat = 0 +// func draw() { +// background(NSColor.white) +// print(x) +// if x < 300 { +// x += 1 +// }else{ +// x = 0 +// } +// +// fill(NSColor.blue) +// ellipse(x, 50, 100, 100) +// } +} diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/Info.plist b/ProcessingKitOSXExample/ProcessingKitOSXExample/Info.plist new file mode 100644 index 0000000..e6173f8 --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2017年 Atsuya Sato. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + + diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements b/ProcessingKitOSXExample/ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/ViewController.swift b/ProcessingKitOSXExample/ProcessingKitOSXExample/ViewController.swift new file mode 100644 index 0000000..3fe945c --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/ViewController.swift @@ -0,0 +1,27 @@ +// +// ViewController.swift +// ProcessingKitOSXExample +// +// Created by AtsuyaSato on 2017/12/31. +// Copyright © 2017年 Atsuya Sato. All rights reserved. +// + +import Cocoa + +class ViewController: NSViewController { + + @IBOutlet weak var customView: CustomView! + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + } + + override var representedObject: Any? { + didSet { + // Update the view, if already loaded. + } + } + + +} + diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExampleTests/Info.plist b/ProcessingKitOSXExample/ProcessingKitOSXExampleTests/Info.plist new file mode 100644 index 0000000..6c40a6c --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExampleTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExampleTests/ProcessingKitOSXExampleTests.swift b/ProcessingKitOSXExample/ProcessingKitOSXExampleTests/ProcessingKitOSXExampleTests.swift new file mode 100644 index 0000000..6d597f0 --- /dev/null +++ b/ProcessingKitOSXExample/ProcessingKitOSXExampleTests/ProcessingKitOSXExampleTests.swift @@ -0,0 +1,36 @@ +// +// ProcessingKitOSXExampleTests.swift +// ProcessingKitOSXExampleTests +// +// Created by AtsuyaSato on 2017/12/31. +// Copyright © 2017年 Atsuya Sato. All rights reserved. +// + +import XCTest +@testable import ProcessingKitOSXExample + +class ProcessingKitOSXExampleTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} From 67ef04fe3a9cbc8196b1dd1a22c77ae69b48b522 Mon Sep 17 00:00:00 2001 From: natmark Date: Wed, 3 Jan 2018 23:31:06 +0900 Subject: [PATCH 03/13] :fire: Remove Signing --- ProcessingKit.xcodeproj/project.pbxproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ProcessingKit.xcodeproj/project.pbxproj b/ProcessingKit.xcodeproj/project.pbxproj index 11f057d..38fd7c7 100644 --- a/ProcessingKit.xcodeproj/project.pbxproj +++ b/ProcessingKit.xcodeproj/project.pbxproj @@ -358,7 +358,6 @@ }; E7B77DD21FF7E02900CE691A = { CreatedOnToolsVersion = 9.1; - DevelopmentTeam = DEQGLB9PU4; ProvisioningStyle = Automatic; }; }; @@ -678,7 +677,7 @@ CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = DEQGLB9PU4; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -711,7 +710,7 @@ CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = DEQGLB9PU4; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; From 98c3b71e4cbae1ab940bdacc21b3129980d127e2 Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 01:04:25 +0900 Subject: [PATCH 04/13] :ok: Fix example view --- .../project.pbxproj | 4 +++ .../ProcessingKitOSXExample/CustomView.swift | 25 ++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj b/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj index 6230c67..26e6571 100644 --- a/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample.xcodeproj/project.pbxproj @@ -442,6 +442,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = DEQGLB9PU4; @@ -449,6 +450,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = io.github.natmark.ProcessingKitOSXExample; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; }; name = Debug; @@ -459,6 +461,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = ProcessingKitOSXExample/ProcessingKitOSXExample.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = DEQGLB9PU4; @@ -466,6 +469,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = io.github.natmark.ProcessingKitOSXExample; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; }; name = Release; diff --git a/ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift b/ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift index f5a6f6f..ac595f9 100644 --- a/ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift +++ b/ProcessingKitOSXExample/ProcessingKitOSXExample/CustomView.swift @@ -13,20 +13,17 @@ import Cocoa class CustomView: ProcessingView { func setup() { background(NSColor.white) + } + + var x: CGFloat = 0 + + func draw() { + background(NSColor.white) + x += 2 + if x > width { + x = 0 + } fill(NSColor.blue) - ellipse(50, 50, 100, 100) + ellipse(x, 0, 100, 100) } -// var x: CGFloat = 0 -// func draw() { -// background(NSColor.white) -// print(x) -// if x < 300 { -// x += 1 -// }else{ -// x = 0 -// } -// -// fill(NSColor.blue) -// ellipse(x, 50, 100, 100) -// } } From e650d6a9849022ba272d661e4a7038d30fb8ab7f Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 01:04:54 +0900 Subject: [PATCH 05/13] :fire: Remove force unwrap --- ProcessingKit/Color/Color.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProcessingKit/Color/Color.swift b/ProcessingKit/Color/Color.swift index dc9ce41..eb39934 100644 --- a/ProcessingKit/Color/Color.swift +++ b/ProcessingKit/Color/Color.swift @@ -38,7 +38,7 @@ struct ColorModel: ColorModelContract { func background(_ color: UIColor) { let g = MultiplatformCommon.getCurrentContext() - g!.clear(self.frameComponents.bounds) + g?.clear(self.frameComponents.bounds) } func background(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat) { @@ -47,7 +47,7 @@ struct ColorModel: ColorModelContract { func clear() { let g = MultiplatformCommon.getCurrentContext() - g!.clear(self.frameComponents.bounds) + g?.clear(self.frameComponents.bounds) } func fill(_ color: UIColor) { From d29d8c1165c5accdf28dd9cffd92df3c3e839c1c Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 01:05:42 +0900 Subject: [PATCH 06/13] :bug: Fix GraphicsContext --- ProcessingKit/ProcessingView.swift | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ProcessingKit/ProcessingView.swift b/ProcessingKit/ProcessingView.swift index c1b6da3..39be035 100644 --- a/ProcessingKit/ProcessingView.swift +++ b/ProcessingKit/ProcessingView.swift @@ -109,6 +109,12 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { private func configuration() { #if os(iOS) self.isUserInteractionEnabled = true + #else + if let window = self.window { + self.bounds = CGRect(x: 0, y: 0, width: window.frame.size.width, height: window.frame.size.height) + } else { + self.bounds = CGRect.zero + } #endif self.delegate = self } @@ -144,10 +150,10 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { // MARK: - Override Methods open override func draw(_ rect: CGRect) { #if os(iOS) - UIGraphicsBeginImageContext(rect.size) - self.image?.draw(at: CGPoint(x: 0, y: 0)) + UIGraphicsBeginImageContext(rect.size) + self.image?.draw(at: CGPoint(x: 0, y: 0)) #else - self.image?.lockFocus() + self.image?.draw(at: NSZeroPoint, from: NSZeroRect, operation: .copy, fraction: 1.0) #endif // Setup @@ -175,13 +181,16 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { self.delegate?.draw?() #if os(iOS) - let drawnImage = UIGraphicsGetImageFromCurrentImageContext() - self.image = drawnImage - UIGraphicsEndImageContext() + let drawnImage = UIGraphicsGetImageFromCurrentImageContext() + self.image = drawnImage + UIGraphicsEndImageContext() #else - guard let cgImage = NSGraphicsContext.current()?.cgContext.makeImage() else { return } - self.image = NSImage(cgImage: cgImage, size: self.frame.size) - //self.image?.unlockFocus() + if let cgImage = NSGraphicsContext.current()?.cgContext.makeImage() { + DispatchQueue.main.async { + self.image = NSImage(cgImage: cgImage, size: self.frame.size) + self.setNeedsDisplay() + } + } #endif if self.delegate?.draw == nil { From c620c95fd1c51ffb55900f2b945d911616a68b6d Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 01:20:23 +0900 Subject: [PATCH 07/13] :bug: Fix coordinate systems --- ProcessingKit/ProcessingView.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ProcessingKit/ProcessingView.swift b/ProcessingKit/ProcessingView.swift index 39be035..0b33cf6 100644 --- a/ProcessingKit/ProcessingView.swift +++ b/ProcessingKit/ProcessingView.swift @@ -154,6 +154,12 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { self.image?.draw(at: CGPoint(x: 0, y: 0)) #else self.image?.draw(at: NSZeroPoint, from: NSZeroRect, operation: .copy, fraction: 1.0) + + // MARK: Coordinate systems are different between iOS and OS X + let g = MultiplatformCommon.getCurrentContext() + g?.saveGState() + g?.translateBy(x: 0.0, y: height) + g?.scaleBy(x: 1.0, y: -1.0) #endif // Setup @@ -191,6 +197,7 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { self.setNeedsDisplay() } } + g?.restoreGState() #endif if self.delegate?.draw == nil { From 502ff48980b870103f1934d111cd36a0c01ba079 Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 02:10:34 +0900 Subject: [PATCH 08/13] :bug: Support mouse events --- ProcessingKit/Input/Event.swift | 129 ++++++++++++++++++++++------- ProcessingKit/ProcessingView.swift | 34 +++++++- 2 files changed, 128 insertions(+), 35 deletions(-) diff --git a/ProcessingKit/Input/Event.swift b/ProcessingKit/Input/Event.swift index bbcb77e..51349a4 100644 --- a/ProcessingKit/Input/Event.swift +++ b/ProcessingKit/Input/Event.swift @@ -13,30 +13,44 @@ import Cocoa import Foundation class EventComponents { + #if os(iOS) var fingerTapped = false - var fingerMoved = false - var fingerReleased = false + var fingerDragged = false var fingerPressed = false + var fingerReleased = false var touchX: CGFloat = 0.0 var touchY: CGFloat = 0.0 var touchesX: Set = [] var touchesY: Set = [] + #else + var mouseClicked = false + var mouseDragged = false + var mouseMoved = false + var mousePressed = false + var mouseReleased = false + var mouseX: CGFloat = 0.0 + var mouseY: CGFloat = 0.0 + #endif } protocol EventModelContract { + #if os(iOS) var fingerPressed: Bool { get } var touchX: CGFloat { get } var touchY: CGFloat { get } var touchesX: Set { get } var touchesY: Set { get } - #if os(iOS) mutating func touchesBegan(_ touches: Set, with event: UIEvent?) mutating func touchesMoved(_ touches: Set, with event: UIEvent?) mutating func touchesEnded(_ touches: Set, with event: UIEvent?) #else - mutating func touchesBegan(with event: NSEvent) - mutating func touchesMoved(with event: NSEvent) - mutating func touchesEnded(with event: NSEvent) + var mousePressed: Bool { get } + var mouseX: CGFloat { get } + var mouseY: CGFloat { get } + mutating func mouseDown(with event: NSEvent) + mutating func mouseDragged(with event: NSEvent) + mutating func mouseUp(with event: NSEvent) + mutating func mouseMoved(with event: NSEvent) #endif } @@ -52,6 +66,7 @@ struct EventModel: EventModelContract { self.eventComponents = eventComponents } + #if os(iOS) var fingerPressed: Bool { return self.eventComponents.fingerPressed } @@ -71,6 +86,19 @@ struct EventModel: EventModelContract { var touchesY: Set { return self.eventComponents.touchesY } + #else + var mousePressed: Bool { + return self.eventComponents.mousePressed + } + + var mouseX: CGFloat { + return self.eventComponents.mouseX + } + + var mouseY: CGFloat { + return self.eventComponents.mouseY + } + #endif #if os(iOS) mutating func touchesBegan(_ touches: Set, with event: UIEvent?) { @@ -81,7 +109,7 @@ struct EventModel: EventModelContract { mutating func touchesMoved(_ touches: Set, with event: UIEvent?) { self.storeTouches(touches) - self.eventComponents.fingerMoved = true + self.eventComponents.fingerDragged = true } mutating func touchesEnded(_ touches: Set, with event: UIEvent?) { @@ -89,22 +117,6 @@ struct EventModel: EventModelContract { self.eventComponents.fingerTapped = false self.eventComponents.fingerReleased = true } - #else - mutating func touchesBegan(with event: NSEvent) { - self.storeTouches(event.touches(matching: .any, in: nil)) - self.eventComponents.fingerPressed = true - self.eventComponents.fingerTapped = true - } - mutating func touchesMoved(with event: NSEvent) { - self.storeTouches(event.touches(matching: .any, in: nil)) - self.eventComponents.fingerMoved = true - } - mutating func touchesEnded(with event: NSEvent) { - self.storeTouches(event.touches(matching: .any, in: nil)) - self.eventComponents.fingerTapped = false - self.eventComponents.fingerReleased = true - } - #endif private mutating func storeTouches(_ touches: Set) { self.eventComponents.touchesX.removeAll() @@ -120,10 +132,45 @@ struct EventModel: EventModelContract { } } } + #else + mutating func mouseDown(with event: NSEvent) { + self.eventComponents.mouseX = event.locationInWindow.x + self.eventComponents.mouseY = event.locationInWindow.y + + self.eventComponents.mousePressed = true + self.eventComponents.mouseClicked = true + } + + mutating func mouseDragged(with event: NSEvent) { + self.storeTouch(event.locationInWindow) + + self.eventComponents.mouseDragged = true + } + + mutating func mouseUp(with event: NSEvent) { + self.storeTouch(event.locationInWindow) + + self.eventComponents.mousePressed = false + self.eventComponents.mouseReleased = true + } + + mutating func mouseMoved(with event: NSEvent) { + self.storeTouch(event.locationInWindow) + + self.eventComponents.mouseMoved = true + } + + private mutating func storeTouch(_ point: NSPoint) { + self.eventComponents.mouseX = point.x + // MARK: Coordinate systems are different between iOS and OS X + self.eventComponents.mouseY = self.frameComponents.bounds.height - point.y + } + #endif } // MARK: - ProcessingView Public APIs extension ProcessingView: EventModelContract { + #if os(iOS) public var fingerPressed: Bool { return self.eventModel.fingerPressed } @@ -136,13 +183,27 @@ extension ProcessingView: EventModelContract { return self.eventModel.touchY } - var touchesX: Set { + public var touchesX: Set { return self.eventModel.touchesX } - var touchesY: Set { + public var touchesY: Set { return self.eventModel.touchesY } + #else + public var mousePressed: Bool { + return self.eventModel.mousePressed + } + + public var mouseX: CGFloat { + return self.eventModel.mouseX + } + + public var mouseY: CGFloat { + return self.eventModel.mouseY + } + + #endif #if os(iOS) open override func touchesBegan(_ touches: Set, with event: UIEvent?) { @@ -157,14 +218,20 @@ extension ProcessingView: EventModelContract { self.eventModel.touchesEnded(touches, with: event) } #else - open override func touchesBegan(with event: NSEvent) { - self.eventModel.touchesBegan(with: event) + open override func mouseDown(with event: NSEvent) { + self.eventModel.mouseDown(with: event) + } + + open override func mouseDragged(with event: NSEvent) { + self.eventModel.mouseDragged(with: event) } - open override func touchesMoved(with event: NSEvent) { - self.eventModel.touchesMoved(with: event) + + open override func mouseUp(with event: NSEvent) { + self.eventModel.mouseUp(with: event) } - open override func touchesEnded(with event: NSEvent) { - self.eventModel.touchesEnded(with: event) + + open override func mouseMoved(with event: NSEvent) { + self.eventModel.mouseMoved(with: event) } #endif } diff --git a/ProcessingKit/ProcessingView.swift b/ProcessingKit/ProcessingView.swift index 0b33cf6..8146914 100644 --- a/ProcessingKit/ProcessingView.swift +++ b/ProcessingKit/ProcessingView.swift @@ -16,9 +16,16 @@ import Foundation @objc optional func setup() @objc optional func draw() + #if os(iOS) @objc optional func fingerTapped() - @objc optional func fingerMoved() + @objc optional func fingerDragged() @objc optional func fingerReleased() + #else + @objc optional func mouseClicked() + @objc optional func mouseDragged() + @objc optional func mouseMoved() + @objc optional func mouseReleased() + #endif } open class ProcessingView: UIImageView, ProcessingViewDelegate { @@ -169,18 +176,37 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { } // Touch events + #if os(iOS) if self.eventComponents.fingerTapped { self.eventComponents.fingerTapped = false self.delegate?.fingerTapped?() } - if self.eventComponents.fingerMoved { - self.eventComponents.fingerMoved = false - self.delegate?.fingerMoved?() + if self.eventComponents.fingerDragged { + self.eventComponents.fingerDragged = false + self.delegate?.fingerDragged?() } if self.eventComponents.fingerReleased { self.eventComponents.fingerReleased = false self.delegate?.fingerReleased?() } + #else + if self.eventComponents.mouseClicked { + self.eventComponents.mouseClicked = false + self.delegate?.mouseClicked?() + } + if self.eventComponents.mouseDragged { + self.eventComponents.mouseDragged = false + self.delegate?.mouseDragged?() + } + if self.eventComponents.mouseMoved { + self.eventComponents.mouseMoved = false + self.delegate?.mouseMoved?() + } + if self.eventComponents.mouseReleased { + self.eventComponents.mouseReleased = false + self.delegate?.mouseReleased?() + } + #endif // Draw self.frameComponents.frameCount += 1 From c3dd6f2a62d85ced3966081d7cc6b198c3a66b3d Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 02:19:52 +0900 Subject: [PATCH 09/13] :bug: Fix image function --- ProcessingKit/Image/Image.swift | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/ProcessingKit/Image/Image.swift b/ProcessingKit/Image/Image.swift index b75b057..ae75d96 100644 --- a/ProcessingKit/Image/Image.swift +++ b/ProcessingKit/Image/Image.swift @@ -11,12 +11,17 @@ import Cocoa #endif public protocol ImageModelContract { + #if os(iOS) func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) + #else + func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat) + func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) + #endif } struct ImageModel: ImageModelContract { - + #if os(iOS) func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) { let g = MultiplatformCommon.getCurrentContext() g?.saveGState() @@ -38,10 +43,34 @@ struct ImageModel: ImageModelContract { } g?.restoreGState() } + #else + func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat) { + let g = MultiplatformCommon.getCurrentContext() + g?.saveGState() + g?.translateBy(x: 0.0, y: img.size.height) + g?.scaleBy(x: 1.0, y: -1.0) + if let cgImg = img.cgImage { + g?.draw(cgImg, in: CGRect(x: x, y: y, width: img.size.width, height: img.size.height)) + } + g?.restoreGState() + } + + func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) { + let g = MultiplatformCommon.getCurrentContext() + g?.saveGState() + g?.translateBy(x: 0.0, y: height) + g?.scaleBy(x: 1.0, y: -1.0) + if let cgImg = img.cgImage { + g?.draw(cgImg, in: CGRect(x: x, y: -y, width: width, height: height)) + } + g?.restoreGState() + } + #endif } // MARK: - ProcessingView Public APIs extension ProcessingView: ImageModelContract { + #if os(iOS) public func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) { self.imageModel.image(img, x, y) } @@ -49,4 +78,13 @@ extension ProcessingView: ImageModelContract { public func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) { self.imageModel.image(img, x, y, width, height) } + #else + public func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat) { + self.imageModel.drawImage(img, x, y) + } + + public func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) { + self.imageModel.drawImage(img, x, y, width, height) + } + #endif } From f5e3eb4ceac39e7d91a59d63aa4daf91ec2dd265 Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 02:26:42 +0900 Subject: [PATCH 10/13] :rotating_light: Remove linter warning --- ProcessingKit/ProcessingView.swift | 67 ++++++++++++++++-------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/ProcessingKit/ProcessingView.swift b/ProcessingKit/ProcessingView.swift index 8146914..3d3097b 100644 --- a/ProcessingKit/ProcessingView.swift +++ b/ProcessingKit/ProcessingView.swift @@ -160,7 +160,7 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { UIGraphicsBeginImageContext(rect.size) self.image?.draw(at: CGPoint(x: 0, y: 0)) #else - self.image?.draw(at: NSZeroPoint, from: NSZeroRect, operation: .copy, fraction: 1.0) + self.image?.draw(at: NSPoint.zero, from: NSRect.zero, operation: .copy, fraction: 1.0) // MARK: Coordinate systems are different between iOS and OS X let g = MultiplatformCommon.getCurrentContext() @@ -176,6 +176,41 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { } // Touch events + self.callDelegatesIfNeeded() + + // Draw + self.frameComponents.frameCount += 1 + self.delegate?.draw?() + + #if os(iOS) + let drawnImage = UIGraphicsGetImageFromCurrentImageContext() + self.image = drawnImage + UIGraphicsEndImageContext() + #else + if let cgImage = NSGraphicsContext.current()?.cgContext.makeImage() { + DispatchQueue.main.async { + self.image = NSImage(cgImage: cgImage, size: self.frame.size) + self.setNeedsDisplay() + } + } + g?.restoreGState() + #endif + + // Only setup + if self.delegate?.draw == nil { + self.noLoop() + return + } + + // Deallocate timer + if self.parentViewController() == nil { + if autoRelease == true && isPlayground == false { + self.noLoop() + } + } + } + + private func callDelegatesIfNeeded() { #if os(iOS) if self.eventComponents.fingerTapped { self.eventComponents.fingerTapped = false @@ -207,36 +242,6 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate { self.delegate?.mouseReleased?() } #endif - - // Draw - self.frameComponents.frameCount += 1 - self.delegate?.draw?() - - #if os(iOS) - let drawnImage = UIGraphicsGetImageFromCurrentImageContext() - self.image = drawnImage - UIGraphicsEndImageContext() - #else - if let cgImage = NSGraphicsContext.current()?.cgContext.makeImage() { - DispatchQueue.main.async { - self.image = NSImage(cgImage: cgImage, size: self.frame.size) - self.setNeedsDisplay() - } - } - g?.restoreGState() - #endif - - if self.delegate?.draw == nil { - self.noLoop() - return - } - - // Deallocate timer - if self.parentViewController() == nil { - if autoRelease == true && isPlayground == false { - self.noLoop() - } - } } // MARK: - Update view bounds From b59ed5acf9957c8ccfcbfb4a49d4d25e849fe074 Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 15:08:11 +0900 Subject: [PATCH 11/13] :construction_worker: Add Travis script for OSX --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1035371..3522e47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,3 +9,4 @@ before_script: - set -o pipefail script: - xcodebuild test -project ./ProcessingKit.xcodeproj -scheme ProcessingKitTests -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,id=ABBD7191-486B-462F-80B4-AE08C5820DA1' | xcpretty -c + - xcodebuild -project ./ProcessingKit.xcodeproj -scheme 'ProcessingKit OSX' -configuration Debug | xcpretty -c From 061d9bac0b0269050cd74b0764c0e85c068d7f96 Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 15:09:20 +0900 Subject: [PATCH 12/13] :pencil2: Update podspec --- ProcessingKit.podspec | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ProcessingKit.podspec b/ProcessingKit.podspec index d3f8a35..eb8f7cf 100644 --- a/ProcessingKit.podspec +++ b/ProcessingKit.podspec @@ -1,17 +1,18 @@ Pod::Spec.new do |s| s.name = "ProcessingKit" s.version = "0.5.1" - s.summary = "Visual Programming library for iOS." + s.summary = "Visual Designing library for iOS." s.description = <<-DESC - ProcessingKit is a Visual Programming library for iOS. + ProcessingKit is a Visual Designing library for iOS. ProcessingKit written in Swift🐧 and you can write like processing. DESC s.homepage = "https://github.com/natmark/ProcessingKit" - s.screenshots = "https://github.com/natmark/ProcessingKit/blob/master/Resources/demo.gif?raw=true" + s.screenshots = "https://github.com/natmark/ProcessingKit/raw/master/Resources/ProcessingKit-Header.png?raw=true" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "Atsuya Sato" => "natmark0918@gmail.com" } - s.osx.deployment_target = "10.0" - s.platform = :ios, "10.0" + s.osx.deployment_target = "10.10" + s.ios.deployment_target = "10.0" + s.platforms = { :ios => "10.0", :osx => "10.10" } s.source = { :git => "https://github.com/natmark/ProcessingKit.git", :tag => "#{s.version}" } s.source_files = "ProcessingKit/**/*.swift" s.exclude_files = "ProcessingKit/Demo.playground/*" From cf4f77b95d5ba15019e04d48b3f72de396543858 Mon Sep 17 00:00:00 2001 From: natmark Date: Thu, 4 Jan 2018 15:18:55 +0900 Subject: [PATCH 13/13] :bug: Fix deployment target --- ProcessingKit.podspec | 4 ++-- ProcessingKit.xcodeproj/project.pbxproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ProcessingKit.podspec b/ProcessingKit.podspec index eb8f7cf..a0eb89e 100644 --- a/ProcessingKit.podspec +++ b/ProcessingKit.podspec @@ -10,9 +10,9 @@ Pod::Spec.new do |s| s.screenshots = "https://github.com/natmark/ProcessingKit/raw/master/Resources/ProcessingKit-Header.png?raw=true" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "Atsuya Sato" => "natmark0918@gmail.com" } - s.osx.deployment_target = "10.10" + s.osx.deployment_target = "10.11" s.ios.deployment_target = "10.0" - s.platforms = { :ios => "10.0", :osx => "10.10" } + s.platforms = { :ios => "10.0", :osx => "10.11" } s.source = { :git => "https://github.com/natmark/ProcessingKit.git", :tag => "#{s.version}" } s.source_files = "ProcessingKit/**/*.swift" s.exclude_files = "ProcessingKit/Demo.playground/*" diff --git a/ProcessingKit.xcodeproj/project.pbxproj b/ProcessingKit.xcodeproj/project.pbxproj index 38fd7c7..e4cd55c 100644 --- a/ProcessingKit.xcodeproj/project.pbxproj +++ b/ProcessingKit.xcodeproj/project.pbxproj @@ -686,7 +686,7 @@ INFOPLIST_FILE = ProcessingKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "io.github.natmark.ProcessingKit-OSX"; PRODUCT_NAME = ProcessingKit; SDKROOT = macosx; @@ -719,7 +719,7 @@ INFOPLIST_FILE = ProcessingKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "io.github.natmark.ProcessingKit-OSX"; PRODUCT_NAME = ProcessingKit; SDKROOT = macosx;