From b9d4bf0ca7aaa5529d86fde06e2d99161b4f2d64 Mon Sep 17 00:00:00 2001 From: workinghard Date: Mon, 13 Apr 2015 23:59:32 -0700 Subject: [PATCH] a --- Cube4Fun/Animations.swift | 14 ++++ Cube4Fun/AnimationsController.swift | 40 ++++++++++ Cube4Fun/AppDelegate.swift | 39 ++++++++++ Cube4Fun/Base.lproj/MainMenu.xib | 110 ++++++++++++++++++++++++--- Cube4Fun/CubeNetwork.cpp | 113 ++++++++++++++++++++++++---- Cube4Fun/CubeNetwork.h | 1 + Cube4Fun/ObjCtoCPlusPlus.h | 1 + Cube4Fun/ObjCtoCPlusPlus.mm | 4 + 8 files changed, 298 insertions(+), 24 deletions(-) diff --git a/Cube4Fun/Animations.swift b/Cube4Fun/Animations.swift index 28bcbef..21a32de 100644 --- a/Cube4Fun/Animations.swift +++ b/Cube4Fun/Animations.swift @@ -60,10 +60,24 @@ class Animations: NSObject { return _animationArray.count } + func loadAnimations(animArray: NSArray) { + // clear the array first + _animationArray.removeAll(keepCapacity: true) + for ( var i=0; i (NSDictionary) { let myAnimation = _animationArray[id] as NSDictionary return myAnimation } + func getAnimations() -> ([NSDictionary]) { + return _animationArray as [NSDictionary]; + } func getAnimationName(id: Int) -> (String) { let value = (self.getAnimation(id)).objectForKey(AnimName) as! String diff --git a/Cube4Fun/AnimationsController.swift b/Cube4Fun/AnimationsController.swift index 5797b32..7617560 100644 --- a/Cube4Fun/AnimationsController.swift +++ b/Cube4Fun/AnimationsController.swift @@ -23,11 +23,17 @@ var dataArray: [NSMutableDictionary] = [["AnimName": "Animation1", "AnimKey": "1 //var _animationArray: [NSMutableDictionary] = [NSMutableDictionary](); //var _selectedAnimation: Int = 0; +var __tableView: NSTableView = NSTableView() class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate { @IBOutlet weak var myTableView: NSTableView! + override func awakeFromNib() { + super.awakeFromNib() + __tableView = myTableView + } + func numberOfRowsInTableView(tableView: NSTableView) -> Int { let numberOfRows:Int = __animations.count() // _animationArray.count return numberOfRows @@ -136,6 +142,40 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate } } + func convertInt16(value: UInt16) -> ([UInt8]) { + var array: [UInt8] = [0,0] + array[0] = UInt8(value & 0x000000ff); + array[1] = UInt8((value & 0x0000ff00) >> 8); + return array; + } + + func convertInt32(value: UInt32) -> ([UInt8]) { + var array: [UInt8] = [0,0,0,0] + array[0] = UInt8(value & 0x000000ff); + array[1] = UInt8((value & 0x0000ff00) >> 8); + array[2] = UInt8((value & 0x00ff0000) >> 16); + array[3] = UInt8((value & 0xff000000) >> 24); + return array; + } + + @IBAction func exportAnimations(send: AnyObject) { + let testdata: [UInt8] = [254, 1, 128, 255] + println("Import button pressed") + + // for each animation + + // Create header line per animation + + // Append frame, separated by new-Line + + // Calculate overall data to send + + + // Send data + CubeNetworkObj.sendBytes(testdata, count: UInt32(testdata.count)) + + } + /* @IBAction func closeButtonClicked(sender: AnyObject ) { animationsWindow.close() diff --git a/Cube4Fun/AppDelegate.swift b/Cube4Fun/AppDelegate.swift index c9064e9..ec4203d 100644 --- a/Cube4Fun/AppDelegate.swift +++ b/Cube4Fun/AppDelegate.swift @@ -17,6 +17,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! @IBOutlet weak var animationsWindow: NSWindow! + @IBOutlet weak var preferencesWindow: NSWindow! + @IBOutlet weak var myMenu: NSMenu! + func applicationDidFinishLaunching(aNotification: NSNotification) { // Insert code here to initialize your application @@ -30,5 +33,41 @@ class AppDelegate: NSObject, NSApplicationDelegate { return NSApplicationTerminateReply.TerminateNow } + @IBAction func saveDocument(sender: AnyObject) { + let mySavePanel: NSSavePanel = NSSavePanel() + mySavePanel.allowedFileTypes = ["plist"] + mySavePanel.beginWithCompletionHandler { (result: Int) -> Void in + if result == NSFileHandlingPanelOKButton { + let exportedFileURL = mySavePanel.URL + // Save the data. What you do depends on your app. + let myAnimArray: NSMutableArray = NSMutableArray() + myAnimArray.addObjectsFromArray(__animations.getAnimations()) + myAnimArray.writeToURL(exportedFileURL!, atomically: true) + //let myAnimation: NSDictionary = NSDictionary(dictionary: __animations.getAnimations()) + + + // Don't just paste this code in your app as your app + // probably doesn't have a createPDF() method. self.createPDF(exportedFileURL) + } + } // End block + println("save pressed") + } + + @IBAction func openDocument(sender: AnyObject) { + let myOpenPanel: NSOpenPanel = NSOpenPanel() + myOpenPanel.allowedFileTypes = ["plist"] + myOpenPanel.beginWithCompletionHandler { (result: Int) -> Void in + if result == NSFileHandlingPanelOKButton { + let importedFileURL = myOpenPanel.URL + //let myAnimationsDict: NSMutableDictionary = NSMutableDictionary(contentsOfURL: importedFileURL!)! + let myAnimArray: NSMutableArray = NSMutableArray(contentsOfURL: importedFileURL!)! + __animations.loadAnimations(myAnimArray) + } + } // End block + } + + @IBAction func openPreferences(send: AnyObject) { + preferencesWindow.setIsVisible(true) + } } diff --git a/Cube4Fun/Base.lproj/MainMenu.xib b/Cube4Fun/Base.lproj/MainMenu.xib index 847f09a..e8a5d2f 100644 --- a/Cube4Fun/Base.lproj/MainMenu.xib +++ b/Cube4Fun/Base.lproj/MainMenu.xib @@ -14,10 +14,10 @@ - - + + - + @@ -26,7 +26,11 @@ - + + + + + @@ -76,10 +80,10 @@ - +