Skip to content

Instantly share code, notes, and snippets.

View eonist's full-sized avatar
🎯
Focusing

André J eonist

🎯
Focusing
View GitHub Profile
import Cocoa
// Only needed until we have class variables
var __SwizzleSayHello = { (who:String) -> String in
return "Hello, \(who)"
}
class Swizzle {
//Only needed until we have class variables
class var _sayHello : (String)->String { get{ return __SwizzleSayHello } set (swizzle) {__SwizzleSayHello = swizzle} }
@eonist
eonist / CubicCurveUtils.swift
Created March 18, 2017 16:33
find y for x on a Cubic Curve segment
import Foundation
class CubicCurveUtils {
/**
* Returns Y given X on a CubicPath segment
* PARAM: p0: prev end point
* PARAM: c0: controllpoint 1 for prev end point
* PARAM: c1: control point 2 for end point
* PARAM: p1: end point
*/
//
// Point.swift
// SwiftGenericGeometry
//
// Created by Jonathan Wight on 3/29/16.
// Copyright © 2016 schwa.io. All rights reserved.
//
public protocol PointType: Equatable {
associatedtype Scalar: ScalarType
@eonist
eonist / ProtocolAssociatedType.swift
Created March 27, 2017 17:47 — forked from troystribling/ProtocolAssociatedType.swift
A swift protocol with associated type used as type parameter in generic function
protocol Thing {
typealias argType
func doit(val:argType) -> argType
}
class IntThing : Thing {
func doit(val: Int) -> Int {
return val + 1
}
}
@eonist
eonist / ElasticZoomTest.swift
Last active July 24, 2017 22:24
Test Animator
/**
*
*/
func zoomBackAndForthAnimTest(){
//Setup window 200x300,white
let winRect = CGRect(0,0,200,300)
window.size = winRect.size
window.contentView = InteractiveView2()
window.title = ""
@eonist
eonist / PressureChangeTest.swift
Created July 25, 2017 16:03
ForceTouch in macOS teating pressureChange
override func pressureChange(with event: NSEvent) {
/*A value from 0.0 through 1.0 indicating the degree of pressure applied to an appropriate input device.*/
Swift.print("event.pressure: " + "\(event.pressure)")
/*The pressure behavior and progression for an event of type pressure.*/
switch event.pressureBehavior {//<-NSPressureBehavior
case .primaryAccelerator:
Swift.print("primaryAccelerator")
case .primaryDeepClick:
@eonist
eonist / ForceTouchHandler.swift
Last active February 15, 2018 14:32
ForceTouch handler
var prevStage = 0
override func pressureChange(with event: NSEvent) {
let curStage:Int = event.stage
if event.pressureBehavior == NSPressureBehavior.primaryDeepClick,prevStage != curStage {
switch (curStage,prevStage){
case (0,1):
Swift.print("from idle to clickStage")
case (1,0):
Swift.print("from clickStage to idle")
case (1,2):
@eonist
eonist / LinearPressure.swift
Created July 26, 2017 10:57
linearPressure for forcetouch
/**
* NOTE: calculates the entire range of the stage pressures so from stage 0 to 1 the pressure goes from 0 to 0.5 and from stage 1 to 2 the linear pressure goes from 0.5 to 1 this makes it easier to scale things in a linear fashion from 0 to 1 in the entire stage range
*/
var linearPressure:CGFloat{
if event.stage == 0 {
return 0
}else if event.stage == 1{
return pressure / 2
}else /*if stage == 2*/ {
return 0.5 + (pressure / 2)
NSUserNotificationCenter.default.delegate = self//add this in the applicationDidFinishLaunching call
extension AppDelegate:NSUserNotificationCenterDelegate{
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
return true
}
}
@eonist
eonist / GestureHUD_ AppDelegate.swift
Created September 7, 2017 18:03
GestureHUD companion xcode project (AppDelegate.swift)
import Cocoa
@testable import Utils
@testable import Element
@NSApplicationMain
class AppDelegate:NSObject, NSApplicationDelegate {
weak var window:NSWindow!
var win:NSWindow?/*<--The window must be a class variable, local variables doesn't work*/
var menu:Menu?