Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #77 from natmark/natmark/fix-import-setting
Browse files Browse the repository at this point in the history
Fix import setting
  • Loading branch information
natmark authored Jan 4, 2018
2 parents 1e32f9b + 963090c commit fb3e74e
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 40 deletions.
4 changes: 2 additions & 2 deletions ProcessingKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ProcessingKit"
s.version = "0.5.1"
s.version = "0.6.0"
s.summary = "Visual Designing library for iOS."
s.description = <<-DESC
ProcessingKit is a Visual Designing library for iOS.
Expand All @@ -12,9 +12,9 @@ Pod::Spec.new do |s|
s.author = { "Atsuya Sato" => "[email protected]" }
s.osx.deployment_target = "10.11"
s.ios.deployment_target = "10.0"
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/*"
s.ios.exclude_files = "ProcessingKit/Extensions/NSImage.swift", "ProcessingKit/Extensions/NSView.swift"
s.requires_arc = true
end
2 changes: 2 additions & 0 deletions ProcessingKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -583,6 +584,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
6 changes: 6 additions & 0 deletions ProcessingKit/Color/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

class ColorComponents {
var fill: UIColor = UIColor.white
var stroke: UIColor = UIColor.clear
Expand Down
6 changes: 6 additions & 0 deletions ProcessingKit/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

public protocol Constants {
var HALF_PI: CGFloat { get }
var PI: CGFloat { get }
Expand Down
6 changes: 6 additions & 0 deletions ProcessingKit/Environment/Frame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

class FrameComponents {
var bounds: CGRect = CGRect.zero
var frame: CGRect = CGRect.zero
Expand Down
8 changes: 5 additions & 3 deletions ProcessingKit/Extensions/CGPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if !os(iOS)
import Cocoa
typealias CGPoint = NSPoint
#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
typealias CGPoint = NSPoint
#endif

extension CGPoint {
Expand Down
3 changes: 3 additions & 0 deletions ProcessingKit/Extensions/NSImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//

import Foundation

#if os(OSX)
import Cocoa
#endif

extension NSImage {
var cgImage: CGImage? {
Expand Down
2 changes: 2 additions & 0 deletions ProcessingKit/Extensions/NSView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if os(OSX)
import Cocoa
#endif

extension NSView {
var backgroundColor: NSColor? {
Expand Down
8 changes: 5 additions & 3 deletions ProcessingKit/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if !os(iOS)
import Cocoa
#if os(iOS)
import UIKit
#else
import Cocoa
#endif

extension String {
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
#if os(iOS)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
#else
#elseif os(OSX)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
#endif

Expand Down
6 changes: 4 additions & 2 deletions ProcessingKit/Extensions/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if !os(iOS)
import Cocoa
#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

extension UIColor {
Expand Down
10 changes: 6 additions & 4 deletions ProcessingKit/Image/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if !os(iOS)
#if os(iOS)
import UIKit
#elseif os(OSX)
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
#elseif os(OSX)
func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat)
func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat)
#endif
Expand Down Expand Up @@ -43,7 +45,7 @@ struct ImageModel: ImageModelContract {
}
g?.restoreGState()
}
#else
#elseif os(OSX)
func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat) {
let g = MultiplatformCommon.getCurrentContext()
g?.saveGState()
Expand Down Expand Up @@ -78,7 +80,7 @@ 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
#elseif os(OSX)
public func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat) {
self.imageModel.drawImage(img, x, y)
}
Expand Down
20 changes: 11 additions & 9 deletions ProcessingKit/Input/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if !os(iOS)
import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

import Foundation

class EventComponents {
#if os(iOS)
var fingerTapped = false
Expand All @@ -22,7 +24,7 @@ class EventComponents {
var touchY: CGFloat = 0.0
var touchesX: Set<CGFloat> = []
var touchesY: Set<CGFloat> = []
#else
#elseif os(OSX)
var mouseClicked = false
var mouseDragged = false
var mouseMoved = false
Expand All @@ -43,7 +45,7 @@ protocol EventModelContract {
mutating func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
mutating func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
mutating func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
#else
#elseif os(OSX)
var mousePressed: Bool { get }
var mouseX: CGFloat { get }
var mouseY: CGFloat { get }
Expand Down Expand Up @@ -86,7 +88,7 @@ struct EventModel: EventModelContract {
var touchesY: Set<CGFloat> {
return self.eventComponents.touchesY
}
#else
#elseif os(OSX)
var mousePressed: Bool {
return self.eventComponents.mousePressed
}
Expand Down Expand Up @@ -132,7 +134,7 @@ struct EventModel: EventModelContract {
}
}
}
#else
#elseif os(OSX)
mutating func mouseDown(with event: NSEvent) {
self.eventComponents.mouseX = event.locationInWindow.x
self.eventComponents.mouseY = event.locationInWindow.y
Expand Down Expand Up @@ -190,7 +192,7 @@ extension ProcessingView: EventModelContract {
public var touchesY: Set<CGFloat> {
return self.eventModel.touchesY
}
#else
#elseif os(OSX)
public var mousePressed: Bool {
return self.eventModel.mousePressed
}
Expand All @@ -217,7 +219,7 @@ extension ProcessingView: EventModelContract {
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
self.eventModel.touchesEnded(touches, with: event)
}
#else
#elseif os(OSX)
open override func mouseDown(with event: NSEvent) {
self.eventModel.mouseDown(with: event)
}
Expand Down
10 changes: 6 additions & 4 deletions ProcessingKit/MultiplatformCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if !os(iOS)
import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
public typealias UIColor = NSColor
public typealias UIImageView = NSImageView
Expand All @@ -19,13 +23,11 @@ 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
#elseif os(OSX)
return NSGraphicsContext.current()?.cgContext
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion ProcessingKit/ProcessingKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

//! Project version number for ProcessingKit.
FOUNDATION_EXPORT double ProcessingKitVersionNumber;
Expand Down
18 changes: 10 additions & 8 deletions ProcessingKit/ProcessingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//

#if !os(iOS)
import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

import Foundation

@objc public protocol ProcessingViewDelegate {
@objc optional func setup()
@objc optional func draw()
Expand All @@ -20,7 +22,7 @@ import Foundation
@objc optional func fingerTapped()
@objc optional func fingerDragged()
@objc optional func fingerReleased()
#else
#elseif os(OSX)
@objc optional func mouseClicked()
@objc optional func mouseDragged()
@objc optional func mouseMoved()
Expand Down Expand Up @@ -116,7 +118,7 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate {
private func configuration() {
#if os(iOS)
self.isUserInteractionEnabled = true
#else
#elseif os(OSX)
if let window = self.window {
self.bounds = CGRect(x: 0, y: 0, width: window.frame.size.width, height: window.frame.size.height)
} else {
Expand Down Expand Up @@ -159,7 +161,7 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate {
#if os(iOS)
UIGraphicsBeginImageContext(rect.size)
self.image?.draw(at: CGPoint(x: 0, y: 0))
#else
#elseif os(OSX)
self.image?.draw(at: NSPoint.zero, from: NSRect.zero, operation: .copy, fraction: 1.0)

// MARK: Coordinate systems are different between iOS and OS X
Expand All @@ -186,7 +188,7 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate {
let drawnImage = UIGraphicsGetImageFromCurrentImageContext()
self.image = drawnImage
UIGraphicsEndImageContext()
#else
#elseif os(OSX)
if let cgImage = NSGraphicsContext.current()?.cgContext.makeImage() {
DispatchQueue.main.async {
self.image = NSImage(cgImage: cgImage, size: self.frame.size)
Expand Down Expand Up @@ -224,7 +226,7 @@ open class ProcessingView: UIImageView, ProcessingViewDelegate {
self.eventComponents.fingerReleased = false
self.delegate?.fingerReleased?()
}
#else
#elseif os(OSX)
if self.eventComponents.mouseClicked {
self.eventComponents.mouseClicked = false
self.delegate?.mouseClicked?()
Expand Down
6 changes: 6 additions & 0 deletions ProcessingKit/Shape/Shape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

protocol ShapeModelContract {
func point(_ x: CGFloat, _ y: CGFloat)
func line(_ x1: CGFloat, _ y1: CGFloat, _ x2: CGFloat, _ y2: CGFloat)
Expand Down
6 changes: 6 additions & 0 deletions ProcessingKit/Shape/Vertex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

public enum BeginShapeKind {
case points
case lines
Expand Down
6 changes: 6 additions & 0 deletions ProcessingKit/Transform/Transform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

#if os(iOS)
import UIKit
#elseif os(OSX)
import Cocoa
#endif

protocol TransformModelContract {
func pushMatrix()
func popMatrix()
Expand Down
Loading

0 comments on commit fb3e74e

Please sign in to comment.