Merge branch 'drag'

This commit is contained in:
A. Vatsaev 2016-12-05 23:28:00 +01:00
commit 582ee53e18
16 changed files with 92 additions and 43 deletions

View file

@ -1,11 +1,18 @@
# Touchbar Nyancat # Touchbar Nyancat
Stupid Nyan Cat animation on your +$2k MacBook Pro's Touchbar. Enjoy. Stupid Nyan Cat animation on your +$2k MacBook Pro's Touchbar. Enjoy.
[DEMO VIDEO 📼](https://www.youtube.com/watch?v=E7Or2M7XUb4) [Download ⬇️](https://www.dropbox.com/s/3j18z84jctsecjf/touchbar_nyancat.app.zip?dl=0)
![](http://i.imgur.com/mHYg4vE.jpeg) ![](http://i.imgur.com/mHYg4vE.jpeg)
## Other awesome TouchBar apps
* [TouchFart][touchfart] - by @hungtruong
* [KnightTouchBar2000][KnightTouchBar2000] - by @AkdM
[touchfart]: <https://github.com/hungtruong/TouchFart>
[KnightTouchBar2000]: <https://github.com/AkdM/KnightTouchBar2000>

Binary file not shown.

View file

@ -15,9 +15,6 @@
A362A10D1DCE6D6B00737197 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A362A10B1DCE6D6B00737197 /* Main.storyboard */; }; A362A10D1DCE6D6B00737197 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A362A10B1DCE6D6B00737197 /* Main.storyboard */; };
A3826CDA1DCE79B900B7C41E /* NyanCatCanvas.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3826CD91DCE79B900B7C41E /* NyanCatCanvas.swift */; }; A3826CDA1DCE79B900B7C41E /* NyanCatCanvas.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3826CD91DCE79B900B7C41E /* NyanCatCanvas.swift */; };
A3826CDC1DCE7B5000B7C41E /* NyanCatCanvas.xib in Resources */ = {isa = PBXBuildFile; fileRef = A3826CDB1DCE7B5000B7C41E /* NyanCatCanvas.xib */; }; A3826CDC1DCE7B5000B7C41E /* NyanCatCanvas.xib in Resources */ = {isa = PBXBuildFile; fileRef = A3826CDB1DCE7B5000B7C41E /* NyanCatCanvas.xib */; };
A3A050DC1DCE96BD009D9775 /* nyan_music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = A3A050DB1DCE96BD009D9775 /* nyan_music.mp3 */; };
A3A050E01DCE9E03009D9775 /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = A3A050DF1DCE9E03009D9775 /* icon.png */; };
A3A050E41DCEAB08009D9775 /* nyan_long@2x.gif in Resources */ = {isa = PBXBuildFile; fileRef = A3A050E31DCEAB08009D9775 /* nyan_long@2x.gif */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -31,9 +28,6 @@
A362A10E1DCE6D6B00737197 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; A362A10E1DCE6D6B00737197 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A3826CD91DCE79B900B7C41E /* NyanCatCanvas.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NyanCatCanvas.swift; sourceTree = "<group>"; }; A3826CD91DCE79B900B7C41E /* NyanCatCanvas.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NyanCatCanvas.swift; sourceTree = "<group>"; };
A3826CDB1DCE7B5000B7C41E /* NyanCatCanvas.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NyanCatCanvas.xib; sourceTree = "<group>"; }; A3826CDB1DCE7B5000B7C41E /* NyanCatCanvas.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NyanCatCanvas.xib; sourceTree = "<group>"; };
A3A050DB1DCE96BD009D9775 /* nyan_music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = nyan_music.mp3; sourceTree = "<group>"; };
A3A050DF1DCE9E03009D9775 /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = "<group>"; };
A3A050E31DCEAB08009D9775 /* nyan_long@2x.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = "nyan_long@2x.gif"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -84,8 +78,6 @@
children = ( children = (
A34053A11DCF56600081ABF1 /* ic_volume_off_3x.png */, A34053A11DCF56600081ABF1 /* ic_volume_off_3x.png */,
A34053A31DCF56640081ABF1 /* ic_volume_up_3x.png */, A34053A31DCF56640081ABF1 /* ic_volume_up_3x.png */,
A3A050E31DCEAB08009D9775 /* nyan_long@2x.gif */,
A3A050DF1DCE9E03009D9775 /* icon.png */,
); );
name = img; name = img;
sourceTree = "<group>"; sourceTree = "<group>";
@ -93,7 +85,6 @@
A3A050DA1DCE96B2009D9775 /* sound */ = { A3A050DA1DCE96B2009D9775 /* sound */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
A3A050DB1DCE96BD009D9775 /* nyan_music.mp3 */,
); );
name = sound; name = sound;
sourceTree = "<group>"; sourceTree = "<group>";
@ -159,12 +150,9 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
A3826CDC1DCE7B5000B7C41E /* NyanCatCanvas.xib in Resources */, A3826CDC1DCE7B5000B7C41E /* NyanCatCanvas.xib in Resources */,
A3A050E01DCE9E03009D9775 /* icon.png in Resources */,
A3A050DC1DCE96BD009D9775 /* nyan_music.mp3 in Resources */,
A362A10A1DCE6D6B00737197 /* Assets.xcassets in Resources */, A362A10A1DCE6D6B00737197 /* Assets.xcassets in Resources */,
A362A10D1DCE6D6B00737197 /* Main.storyboard in Resources */, A362A10D1DCE6D6B00737197 /* Main.storyboard in Resources */,
A34053A21DCF56600081ABF1 /* ic_volume_off_3x.png in Resources */, A34053A21DCF56600081ABF1 /* ic_volume_off_3x.png in Resources */,
A3A050E41DCEAB08009D9775 /* nyan_long@2x.gif in Resources */,
A34053A41DCF56640081ABF1 /* ic_volume_up_3x.png in Resources */, A34053A41DCF56640081ABF1 /* ic_volume_up_3x.png in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View file

@ -21,39 +21,33 @@
"scale" : "2x" "scale" : "2x"
}, },
{ {
"size" : "128x128",
"idiom" : "mac", "idiom" : "mac",
"filename" : "touchbar_nyancat_icon_128@2x.png", "size" : "128x128",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"size" : "128x128",
"idiom" : "mac", "idiom" : "mac",
"filename" : "touchbar_nyancat_icon_256@2x-2.png", "size" : "128x128",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"size" : "256x256",
"idiom" : "mac", "idiom" : "mac",
"filename" : "touchbar_nyancat_icon_256@2x-1.png", "size" : "256x256",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"size" : "256x256",
"idiom" : "mac", "idiom" : "mac",
"filename" : "touchbar_nyancat_icon_512@2x-2.png", "size" : "256x256",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"size" : "512x512",
"idiom" : "mac", "idiom" : "mac",
"filename" : "touchbar_nyancat_icon_512@2x-1.png", "size" : "512x512",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"size" : "512x512",
"idiom" : "mac", "idiom" : "mac",
"filename" : "touchbar_nyancat_icon@2x 2.png", "size" : "512x512",
"scale" : "2x" "scale" : "2x"
} }
], ],

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2657" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS"> <document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2659" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaDFRPlugin" version="7104"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaDFRPlugin" version="7104"/>
@ -16,7 +16,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/> <rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="878"/> <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1028"/>
<value key="minSize" type="size" width="480" height="270"/> <value key="minSize" type="size" width="480" height="270"/>
<value key="maxSize" type="size" width="480" height="270"/> <value key="maxSize" type="size" width="480" height="270"/>
</window> </window>
@ -113,6 +113,7 @@
</view> </view>
<connections> <connections>
<outlet property="bkg" destination="iUM-SV-UtP" id="Y8L-Wa-nPi"/> <outlet property="bkg" destination="iUM-SV-UtP" id="Y8L-Wa-nPi"/>
<outlet property="muteBtn" destination="uCH-1A-AJh" id="AdG-ie-hNs"/>
<outlet property="sound_btn" destination="Uwj-zc-KXn" id="jky-Ou-f9G"/> <outlet property="sound_btn" destination="Uwj-zc-KXn" id="jky-Ou-f9G"/>
</connections> </connections>
</viewController> </viewController>

View file

@ -10,16 +10,74 @@ import Cocoa
class NyanCatCanvas: NSImageView { class NyanCatCanvas: NSImageView {
var imageLoaded:Bool = false;
var xPosition: CGFloat = 0 {
didSet {
self.frame = CGRect(x: xPosition, y: 0, width: 685, height: 30)
}
}
override func draw(_ dirtyRect: NSRect) { override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect) super.draw(dirtyRect)
// Drawing code here. // Drawing code here.
self.frame = CGRect(x: 0, y: 0, width: 685, height: 30)
self.animates = true self.animates = true
self.image = NSImage(named: "nyan_long@2x.gif")!
if(!self.imageLoaded){
self.downloadImage()
}
self.canDrawSubviewsIntoLayer = true self.canDrawSubviewsIntoLayer = true
self.frame = CGRect(x: xPosition, y: 0, width: 685, height: 30)
}
override func touchesBegan(with event: NSEvent) {
// Calling super causes the cat to jump back to its original position 🤔
//super.touchesBegan(with: event)
}
override func didAddSubview(_ subview: NSView) {
}
func downloadImage() {
let url = URL(string: "https://i.imgur.com/7pgdK28.gif")
getDataFromUrl(url: url!) { (data, response, error) in
guard let data = data, error == nil else { return }
DispatchQueue.main.async() { () -> Void in
self.image = NSImage(data: data)
self.imageLoaded = true;
}
}
}
func getDataFromUrl(url: URL, completion: @escaping (_ data: Data?, _ response: URLResponse?, _ error: Error?) -> Void) {
URLSession.shared.dataTask(with: url) {
(data, response, error) in
completion(data, response, error)
}.resume()
}
override func touchesMoved(with event: NSEvent) {
if #available(OSX 10.12.1, *) {
let current = event.allTouches().first?.location(in: self).x ?? 0
let previous = event.allTouches().first?.previousLocation(in: self).x ?? 0
let dX = (current - previous)
xPosition += dX
} else {
// Fallback on earlier versions
}
} }
} }

View file

@ -15,6 +15,7 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{
var audio_player: AVAudioPlayer? var audio_player: AVAudioPlayer?
@IBOutlet weak var muteBtn: NSButton!
//NOTE: I fucking love Swift's computed properties! //NOTE: I fucking love Swift's computed properties!
var sound: Bool = true { var sound: Bool = true {
@ -35,7 +36,6 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{
var sound_btn_image_on: NSImage? var sound_btn_image_on: NSImage?
var sound_btn_image_off: NSImage? var sound_btn_image_off: NSImage?
@IBOutlet weak var sound_btn: NSButtonCell! @IBOutlet weak var sound_btn: NSButtonCell!
@IBOutlet weak var bkg: NSView! @IBOutlet weak var bkg: NSView!
@ -44,6 +44,7 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{
super.viewDidLoad() super.viewDidLoad()
self.view.wantsLayer = true self.view.wantsLayer = true
self.muteBtn.isHidden = true
} }
@ -62,17 +63,17 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{
sound_btn_image_off = NSImage(named: "ic_volume_off_3x.png") sound_btn_image_off = NSImage(named: "ic_volume_off_3x.png")
let nyan_music = URL(fileURLWithPath: Bundle.main.path(forResource: "nyan_music", ofType: "mp3")!) // let nyan_music = URL(fileURLWithPath: Bundle.main.path(forResource: "nyan_music", ofType: "mp3")!)
//
// do {
//
// try audio_player = AVAudioPlayer(contentsOf: nyan_music)
// audio_player?.numberOfLoops = -1
// audio_player?.prepareToPlay()
//
// }catch{}
do { //sound = true
try audio_player = AVAudioPlayer(contentsOf: nyan_music)
audio_player?.numberOfLoops = -1
audio_player?.prepareToPlay()
}catch{}
sound = true
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.