Permalink
Browse files

Update indentation

  • Loading branch information...
wddwycc committed Jun 17, 2017
1 parent 58d591f commit f23adb8d64cbfd9d9cf010da63301b0c0a81677c
@@ -16,8 +16,6 @@
84713B881CA6B9ED001F4A4B /* FreehandTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84713B871CA6B9ED001F4A4B /* FreehandTests.swift */; };
84713B941CA6BA32001F4A4B /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84713B921CA6BA31001F4A4B /* MainViewController.swift */; };
84713B951CA6BA32001F4A4B /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84713B931CA6BA32001F4A4B /* MainViewController.xib */; };
849586741CE59C1B00906A4C /* ChangePathWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849586721CE59C1B00906A4C /* ChangePathWindowController.swift */; };
849586751CE59C1B00906A4C /* ChangePathWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 849586731CE59C1B00906A4C /* ChangePathWindowController.xib */; };
84FD34341CA7B9A000A05890 /* LineWidthPlate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FD34331CA7B9A000A05890 /* LineWidthPlate.swift */; };
C3B00C9F1CAEC5400040E77C /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B00C9E1CAEC5400040E77C /* EventMonitor.swift */; };
/* End PBXBuildFile section */
@@ -46,8 +44,6 @@
84713B891CA6B9ED001F4A4B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
84713B921CA6BA31001F4A4B /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
84713B931CA6BA32001F4A4B /* MainViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainViewController.xib; sourceTree = "<group>"; };
849586721CE59C1B00906A4C /* ChangePathWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangePathWindowController.swift; sourceTree = "<group>"; };
849586731CE59C1B00906A4C /* ChangePathWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ChangePathWindowController.xib; sourceTree = "<group>"; };
84FD34331CA7B9A000A05890 /* LineWidthPlate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineWidthPlate.swift; sourceTree = "<group>"; };
C3B00C9E1CAEC5400040E77C /* EventMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -99,7 +95,6 @@
842E156A1CA77FAA002851D8 /* Stroke.swift */,
842E156E1CA7A027002851D8 /* ColorPlate.swift */,
84FD34331CA7B9A000A05890 /* LineWidthPlate.swift */,
849586761CE59C2900906A4C /* Legacy */,
84713B791CA6B9ED001F4A4B /* Assets.xcassets */,
84713B7B1CA6B9ED001F4A4B /* MainMenu.xib */,
84713B7E1CA6B9ED001F4A4B /* Info.plist */,
@@ -116,15 +111,6 @@
path = FreehandTests;
sourceTree = "<group>";
};
849586761CE59C2900906A4C /* Legacy */ = {
isa = PBXGroup;
children = (
849586721CE59C1B00906A4C /* ChangePathWindowController.swift */,
849586731CE59C1B00906A4C /* ChangePathWindowController.xib */,
);
name = Legacy;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -211,7 +197,6 @@
files = (
84713B7A1CA6B9ED001F4A4B /* Assets.xcassets in Resources */,
84713B951CA6BA32001F4A4B /* MainViewController.xib in Resources */,
849586751CE59C1B00906A4C /* ChangePathWindowController.xib in Resources */,
84713B7D1CA6B9ED001F4A4B /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -234,7 +219,6 @@
84713B941CA6BA32001F4A4B /* MainViewController.swift in Sources */,
842E156D1CA78493002851D8 /* Board.swift in Sources */,
842E156F1CA7A027002851D8 /* ColorPlate.swift in Sources */,
849586741CE59C1B00906A4C /* ChangePathWindowController.swift in Sources */,
C3B00C9F1CAEC5400040E77C /* EventMonitor.swift in Sources */,
842E156B1CA77FAA002851D8 /* Stroke.swift in Sources */,
84FD34341CA7B9A000A05890 /* LineWidthPlate.swift in Sources */,
@@ -13,17 +13,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
lazy var changePathWindowController: ChangePathWindowController = ChangePathWindowController(windowNibName: "ChangePathWindowController")
let statusItem = NSStatusBar.system().statusItem(withLength: -2)
let popover = NSPopover()
var eventMonitor: EventMonitor?
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
if let button = statusItem.button {
button.image = NSImage(named: "StatusBarButtonImage")
button.action = #selector(AppDelegate.togglePopover(_:))
@@ -40,24 +36,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
eventMonitor?.start()
// set default saving path
if(self.savingPath == nil){
self.savingPath = "/Users/\(NSUserName())/Desktop"
}
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func showPopover(_ sender: AnyObject?) {
if let button = statusItem.button {
popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
@@ -78,24 +61,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}
//global
func terminateApp(_ sender:AnyObject){
NSApplication.shared().terminate(nil)
}
// TODO: change path
func presentPathChangerWindow(){
// self.changePathWindowController.showWindow(self)
// NSApp.activateIgnoringOtherApps(true)
// self.changePathWindowController.window!.makeKeyAndOrderFront(nil)
self.togglePopover(nil)
let panel = NSOpenPanel()
panel.canChooseFiles = false
@@ -13,5 +13,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
@@ -9,105 +9,98 @@
import Cocoa
class Board: NSView {
var currentStroke:Stroke?
var currentStrokeWidth:CGFloat = 1
var currentStrokeColor:NSColor = NSColor.black
var strokeStack = [Stroke]()
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
setup()
}
init(){
super.init(frame: NSRect())
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setup(){
self.layer = CALayer()
self.layer?.backgroundColor = NSColor.white.cgColor
//gesture
let drawGesture = NSPanGestureRecognizer(target: self, action: #selector(Board.handlePan(_:)))
self.addGestureRecognizer(drawGesture)
self.layer!.masksToBounds = true
}
func handlePan(_ gesture:NSPanGestureRecognizer){
switch gesture.state{
case .began:
let stroke = Stroke(strokeWidth: self.currentStrokeWidth, strokeColor: self.currentStrokeColor)
self.currentStroke = stroke
stroke.beginAt(gesture.location(in: self), stickedLayer: self.layer!)
case .changed:
self.currentStroke?.moveTo(gesture.location(in: self))
case .ended, .cancelled:
self.strokeStack.append(self.currentStroke!)
self.undoManager!.registerUndo(withTarget: self, selector: #selector(Board.executeUndo), object: nil)
self.currentStroke = nil
default:
break
}
}
func executeUndo(){
self.strokeStack.last?.removeFromSuperlayer()
self.strokeStack.removeLast()
}
internal func produceImage()->NSImage{
let size = self.bounds.size
let im = NSImage.init(size: size)
let rep = NSBitmapImageRep.init(bitmapDataPlanes: nil,
pixelsWide: Int(size.width),
pixelsHigh: Int(size.height),
bitsPerSample: 8,
samplesPerPixel: 4,
hasAlpha: true,
isPlanar: false,
colorSpaceName: NSCalibratedRGBColorSpace,
bytesPerRow: 0,
bitsPerPixel: 0)
im.addRepresentation(rep!)
im.lockFocus()
let rect = NSMakeRect(0, 0, size.width, size.height)
let ctx = NSGraphicsContext.current()?.cgContext
ctx?.clear(rect)
ctx?.setFillColor(NSColor.clear.cgColor)
self.layer!.render(in: ctx!)
ctx?.fill(rect)
im.unlockFocus()
return im
var currentStroke:Stroke?
var currentStrokeWidth:CGFloat = 1
var currentStrokeColor:NSColor = NSColor.black
var strokeStack = [Stroke]()
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
setup()
}
init(){
super.init(frame: NSRect())
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setup(){
self.layer = CALayer()
self.layer?.backgroundColor = NSColor.white.cgColor
//gesture
let drawGesture = NSPanGestureRecognizer(target: self, action: #selector(Board.handlePan(_:)))
self.addGestureRecognizer(drawGesture)
self.layer!.masksToBounds = true
}
func handlePan(_ gesture:NSPanGestureRecognizer){
switch gesture.state{
case .began:
let stroke = Stroke(strokeWidth: self.currentStrokeWidth, strokeColor: self.currentStrokeColor)
self.currentStroke = stroke
stroke.beginAt(gesture.location(in: self), stickedLayer: self.layer!)
case .changed:
self.currentStroke?.moveTo(gesture.location(in: self))
case .ended, .cancelled:
self.strokeStack.append(self.currentStroke!)
self.undoManager!.registerUndo(withTarget: self, selector: #selector(Board.executeUndo), object: nil)
self.currentStroke = nil
default:
break
}
internal func clearboard(){
if(self.layer!.sublayers == nil){return}
for member in self.layer!.sublayers!{
member.removeFromSuperlayer()
}
self.strokeStack.removeAll()
}
func executeUndo(){
self.strokeStack.last?.removeFromSuperlayer()
self.strokeStack.removeLast()
}
internal func produceImage()->NSImage{
let size = self.bounds.size
let im = NSImage.init(size: size)
let rep = NSBitmapImageRep.init(bitmapDataPlanes: nil,
pixelsWide: Int(size.width),
pixelsHigh: Int(size.height),
bitsPerSample: 8,
samplesPerPixel: 4,
hasAlpha: true,
isPlanar: false,
colorSpaceName: NSCalibratedRGBColorSpace,
bytesPerRow: 0,
bitsPerPixel: 0)
im.addRepresentation(rep!)
im.lockFocus()
let rect = NSMakeRect(0, 0, size.width, size.height)
let ctx = NSGraphicsContext.current()?.cgContext
ctx?.clear(rect)
ctx?.setFillColor(NSColor.clear.cgColor)
self.layer!.render(in: ctx!)
ctx?.fill(rect)
im.unlockFocus()
return im
}
internal func clearboard(){
if(self.layer!.sublayers == nil){return}
for member in self.layer!.sublayers!{
member.removeFromSuperlayer()
}
// override func drawRect(dirtyRect: NSRect) {
// super.drawRect(dirtyRect)
//
// // Drawing code here.
// }
self.strokeStack.removeAll()
}
}

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit f23adb8

Please sign in to comment.