Skip to content

Commit

Permalink
Add hover sound effect for blender buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
balazs630 committed Jul 11, 2017
1 parent f53581c commit 1e7caab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
8 changes: 6 additions & 2 deletions FrogBlender.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
AC1B9D571F07BA3A00D4A1C9 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC1B9D561F07BA3A00D4A1C9 /* MainViewController.swift */; };
AC1B9D591F07BA3A00D4A1C9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AC1B9D581F07BA3A00D4A1C9 /* Assets.xcassets */; };
AC1B9D5C1F07BA3A00D4A1C9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AC1B9D5A1F07BA3A00D4A1C9 /* Main.storyboard */; };
AC847A101F14DEDB0091F2B1 /* AVPlayerViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC847A0F1F14DEDB0091F2B1 /* AVPlayerViewExtensions.swift */; };
ACCA81A21F0AD7F400C53288 /* intro.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = ACCA81951F0AD7F400C53288 /* intro.mp4 */; };
ACCA81A31F0AD7F400C53288 /* outro.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = ACCA81961F0AD7F400C53288 /* outro.mp4 */; };
ACCA81A41F0AD7F400C53288 /* speed-0.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = ACCA81971F0AD7F400C53288 /* speed-0.mp4 */; };
Expand Down Expand Up @@ -40,6 +41,7 @@
AC1B9D581F07BA3A00D4A1C9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
AC1B9D5B1F07BA3A00D4A1C9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
AC1B9D5D1F07BA3A00D4A1C9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
AC847A0F1F14DEDB0091F2B1 /* AVPlayerViewExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AVPlayerViewExtensions.swift; sourceTree = "<group>"; };
ACCA81951F0AD7F400C53288 /* intro.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = intro.mp4; path = FrogBlender/Videos/intro.mp4; sourceTree = "<group>"; };
ACCA81961F0AD7F400C53288 /* outro.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = outro.mp4; path = FrogBlender/Videos/outro.mp4; sourceTree = "<group>"; };
ACCA81971F0AD7F400C53288 /* speed-0.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = "speed-0.mp4"; path = "FrogBlender/Videos/speed-0.mp4"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,9 +94,10 @@
AC1B9D531F07BA3A00D4A1C9 /* FrogBlender */ = {
isa = PBXGroup;
children = (
AC1B9D541F07BA3A00D4A1C9 /* AppDelegate.swift */,
ACCA81D01F0D274100C53288 /* ButtonViewController.swift */,
AC1B9D561F07BA3A00D4A1C9 /* MainViewController.swift */,
ACCA81D01F0D274100C53288 /* ButtonViewController.swift */,
AC847A0F1F14DEDB0091F2B1 /* AVPlayerViewExtensions.swift */,
AC1B9D541F07BA3A00D4A1C9 /* AppDelegate.swift */,
AC1B9D5A1F07BA3A00D4A1C9 /* Main.storyboard */,
AC1B9D581F07BA3A00D4A1C9 /* Assets.xcassets */,
AC1B9D5D1F07BA3A00D4A1C9 /* Info.plist */,
Expand Down Expand Up @@ -229,6 +232,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AC847A101F14DEDB0091F2B1 /* AVPlayerViewExtensions.swift in Sources */,
AC1B9D571F07BA3A00D4A1C9 /* MainViewController.swift in Sources */,
ACCA81D11F0D274100C53288 /* ButtonViewController.swift in Sources */,
AC1B9D551F07BA3A00D4A1C9 /* AppDelegate.swift in Sources */,
Expand Down
41 changes: 21 additions & 20 deletions FrogBlender/ButtonViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Button.swift
// ButtonViewController.swift
// FrogBlender
//
// Created by Horváth Balázs on 2017. 07. 05..
Expand All @@ -21,38 +21,39 @@ class ButtonViewController: NSViewController {
NSButton(),
NSButton()]

static var blenderButtonPos = [CGPoint(x: 307, y: 58),
CGPoint(x: 335, y: 62),
CGPoint(x: 363, y: 68),
CGPoint(x: 391, y: 76),
CGPoint(x: 421, y: 84),
CGPoint(x: 450, y: 91),
CGPoint(x: 479, y: 99),
CGPoint(x: 508, y: 108),
CGPoint(x: 534, y: 118),
CGPoint(x: 561, y: 130)]
static var blenderButtonsPos = [CGPoint(x: 309, y: 57),
CGPoint(x: 336, y: 61),
CGPoint(x: 364, y: 67),
CGPoint(x: 392, y: 75),
CGPoint(x: 422, y: 83),
CGPoint(x: 452, y: 90),
CGPoint(x: 481, y: 98),
CGPoint(x: 510, y: 107),
CGPoint(x: 536, y: 117),
CGPoint(x: 563, y: 129)]

static var blenderButtonSize = CGSize(width: 20, height: 20)

static var btnPlay = NSButton()
static var btnReplay = NSButton()
static var btnTurnOff = NSButton()

class func initBlenderButtons() {
class func initBlenderButtons(to view: NSViewController) {
for i in 0...blenderButtons.count - 1 {
blenderButtons[i] = NSButton(frame: NSRect(origin: blenderButtonPos[i],
blenderButtons[i] = NSButton(frame: NSRect(origin: blenderButtonsPos[i],
size: blenderButtonSize))
blenderButtons[i].title = ""
blenderButtons[i].tag = i + 1 // tag for which button is pressed (1-10)
blenderButtons[i].tag = i + 1 // tag for which blender speed button was pressed (1-10)
blenderButtons[i].isTransparent = true
blenderButtons[i].action = #selector(MainViewController.speedButtonClicked(sender:))
let area = NSTrackingArea.init(rect: blenderButtons[i].bounds,
options: [.mouseEnteredAndExited, .activeAlways],
owner: view,
userInfo: ["btnName": "btnBlender"])
blenderButtons[i].addTrackingArea(area)
}
}

class func getBlenderButtons() -> [NSButton] {
return blenderButtons
}

class func removeBlenderButtons() {
for i in 0...blenderButtons.count - 1 {
blenderButtons[i].removeFromSuperview()
Expand Down Expand Up @@ -84,7 +85,7 @@ class ButtonViewController: NSViewController {
let imageWidth = btnReplayImage.size.width
let imageHeight = btnReplayImage.size.height

btnReplay = NSButton(frame: NSRect(origin: CGPoint(x: 754, y: 23),
btnReplay = NSButton(frame: NSRect(origin: CGPoint(x: 756, y: 23),
size: CGSize(width: imageWidth, height: imageHeight)))
btnReplay.image = btnReplayImage
btnReplay.imagePosition = .imageOnly
Expand All @@ -100,7 +101,7 @@ class ButtonViewController: NSViewController {
}

class func addTurnOffButton() -> NSButton {
btnTurnOff = NSButton(frame: NSRect(origin: CGPoint(x: 422, y: 125),
btnTurnOff = NSButton(frame: NSRect(origin: CGPoint(x: 423, y: 124),
size: CGSize(width: 50, height: 15)))
btnTurnOff.title = ""
btnTurnOff.rotate(byDegrees: CGFloat(-15))
Expand Down
16 changes: 10 additions & 6 deletions FrogBlender/MainViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ViewController.swift
// MainViewController.swift
// FrogBlender
//
// Created by Horváth Balázs on 2017. 07. 01..
Expand Down Expand Up @@ -31,7 +31,7 @@ class MainViewController: NSViewController {
// Action when the actual video is over
switch(self.currentlyPlayedVideoName) {
case "intro":
ButtonViewController.initBlenderButtons()
ButtonViewController.initBlenderButtons(to: self)
self.playVideo(fileNamed: "speed-0", type: "mp4")
self.playerView!.player?.pause()
self.playerView.contentOverlayView?.addSubview(ButtonViewController.addPlayButton(to: self))
Expand All @@ -40,7 +40,7 @@ class MainViewController: NSViewController {
self.playerView.contentOverlayView?.addSubview(ButtonViewController.addReplayButton(to: self))
self.playSound(fileNamed: "replay-button-appears", type: "aac")
default:
//Loop the actual video, waiting for user interaction (buttonpress)
//Loop the actual video, waiting for user interaction (button press)
self.videoPlayer.seek(to: kCMTimeZero)
self.playerView!.player?.play()
}
Expand Down Expand Up @@ -89,7 +89,7 @@ class MainViewController: NSViewController {
func startPlaying() {
playVideo(fileNamed: "speed-0", type: "mp4")

for button in ButtonViewController.getBlenderButtons() {
for button in ButtonViewController.blenderButtons {
playerView.contentOverlayView?.addSubview(button)
}

Expand Down Expand Up @@ -132,8 +132,10 @@ class MainViewController: NSViewController {
case "btnReplay":
ButtonViewController.btnReplay.image = NSImage(named: "replay-hover")
playSound(fileNamed: "replay-button-hover", type: "aac")
case "btnBlender":
playSound(fileNamed: "blender-button-hover", type: "aac")
default:
print("The given button name is unknown!")
print("The given button name: \"\(buttonName)\" is unknown!")
}
}
}
Expand All @@ -147,8 +149,10 @@ class MainViewController: NSViewController {
ButtonViewController.btnPlay.image = NSImage(named: "play-standard")
case "btnReplay":
ButtonViewController.btnReplay.image = NSImage(named: "replay-standard")
case "btnBlender":
break
default:
print("The given button name is unknown!")
print("The given button name: \"\(buttonName)\" is unknown!")
}
}
}
Expand Down

0 comments on commit 1e7caab

Please sign in to comment.