Skip to content

Commit

Permalink
Show maximum of five fingers
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev1an committed Jun 18, 2017
1 parent a8ada4d commit 5664ad9
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 13 deletions.
67 changes: 62 additions & 5 deletions Magic Drumpad/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13122.17" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13122.17"/>
<capability name="box content view" minToolsVersion="7.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Application-->
Expand Down Expand Up @@ -673,7 +676,7 @@
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Magic_Drumpad" customModuleProvider="target"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
Expand All @@ -700,11 +703,65 @@
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="Magic_Drumpad" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<box fixedFrame="YES" boxType="custom" borderType="none" cornerRadius="20" title="Box" transparent="YES" translatesAutoresizingMaskIntoConstraints="NO" id="der-H1-t4P">
<rect key="frame" x="49" y="178" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" ambiguous="YES" id="RrE-EP-fj4">
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<color key="fillColor" name="keyboardFocusIndicatorColor" catalog="System" colorSpace="catalog"/>
</box>
<box fixedFrame="YES" boxType="custom" borderType="none" cornerRadius="20" title="Box" transparent="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Gw6-IW-t3a">
<rect key="frame" x="109" y="178" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" ambiguous="YES" id="sYI-KM-RnC">
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<color key="fillColor" name="keyboardFocusIndicatorColor" catalog="System" colorSpace="catalog"/>
</box>
<box fixedFrame="YES" boxType="custom" borderType="none" cornerRadius="20" title="Box" transparent="YES" translatesAutoresizingMaskIntoConstraints="NO" id="h5L-47-BGF">
<rect key="frame" x="169" y="178" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" ambiguous="YES" id="tF9-aB-APH">
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<color key="fillColor" name="keyboardFocusIndicatorColor" catalog="System" colorSpace="catalog"/>
</box>
<box fixedFrame="YES" boxType="custom" borderType="none" cornerRadius="20" title="Box" transparent="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZIC-lB-IG1">
<rect key="frame" x="229" y="178" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" ambiguous="YES" id="1po-6S-oJV">
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<color key="fillColor" name="keyboardFocusIndicatorColor" catalog="System" colorSpace="catalog"/>
</box>
<box fixedFrame="YES" boxType="custom" borderType="none" cornerRadius="20" title="Box" transparent="YES" translatesAutoresizingMaskIntoConstraints="NO" id="q9h-Xm-FBj">
<rect key="frame" x="289" y="178" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" ambiguous="YES" id="oeV-5B-eSh">
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<color key="fillColor" name="keyboardFocusIndicatorColor" catalog="System" colorSpace="catalog"/>
</box>
</subviews>
</view>
<connections>
<outlet property="fingerView1" destination="der-H1-t4P" id="OLi-KD-3Ta"/>
<outlet property="fingerView2" destination="Gw6-IW-t3a" id="4zM-bU-BBT"/>
<outlet property="fingerView3" destination="h5L-47-BGF" id="5V5-DW-p1C"/>
<outlet property="fingerView4" destination="ZIC-lB-IG1" id="FgZ-gF-UVZ"/>
<outlet property="fingerView5" destination="q9h-Xm-FBj" id="uuy-KE-ofG"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
54 changes: 46 additions & 8 deletions Magic Drumpad/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,57 @@
import Cocoa

class ViewController: NSViewController {

@IBOutlet weak var fingerView1: NSBox!
@IBOutlet weak var fingerView2: NSBox!
@IBOutlet weak var fingerView3: NSBox!
@IBOutlet weak var fingerView4: NSBox!
@IBOutlet weak var fingerView5: NSBox!
var fingerViews: Set<NSBox>!
var visibleFingers = [Int: NSBox]()

override func viewDidLoad() {
super.viewDidLoad()

fingerViews = [fingerView1, fingerView2, fingerView3, fingerView4, fingerView5]

view.acceptsTouchEvents = true
view.pressureConfiguration = NSPressureConfiguration(pressureBehavior: .primaryClick)
// Do any additional setup after loading the view.
}

override var representedObject: Any? {
didSet {
// Update the view, if already loaded.

override func pressureChange(with event: NSEvent) {
let size = CGFloat(event.pressure) * 20 + 25
for fingerView in fingerViews {
fingerView.frame.size.width = size
fingerView.frame.size.height = size
fingerView.cornerRadius = size/2
}
}

override func touchesBegan(with event: NSEvent) {
for touch in event.touches(matching: .began, in: nil) {
if let fingerView = fingerViews.subtracting(visibleFingers.values).first {
visibleFingers[touch.identity.hash] = fingerView
fingerView.isTransparent = false

fingerView.frame.origin.x = (view.frame.width - fingerView.frame.width) * touch.normalizedPosition.x
fingerView.frame.origin.y = (view.frame.height - fingerView.frame.height) * touch.normalizedPosition.y
}
}
}

override func touchesMoved(with event: NSEvent) {
for touch in event.touches(matching: .moved, in: nil) {
if let fingerView = visibleFingers[touch.identity.hash] {
fingerView.frame.origin.x = (view.frame.width - fingerView.frame.width) * touch.normalizedPosition.x
fingerView.frame.origin.y = (view.frame.height - fingerView.frame.height) * touch.normalizedPosition.y
}
}
}

override func touchesEnded(with event: NSEvent) {
for touch in event.touches(matching: [.ended, .cancelled], in: nil) {
visibleFingers.removeValue(forKey: touch.identity.hash)?.isTransparent = true
}
}


}

0 comments on commit 5664ad9

Please sign in to comment.