Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic Mac implementation #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,7 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc

# Xcode
xcuserdata
6 changes: 6 additions & 0 deletions DVDScreenSaver-Cocoa/DVDScreenSaver-TestApp/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

}
276 changes: 276 additions & 0 deletions DVDScreenSaver-Cocoa/DVDScreenSaver-TestApp/Base.lproj/MainMenu.xib

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Cocoa

extension NSColor {

convenience init(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat) {
self.init(calibratedRed: r/255.0, green: g/255.0, blue: b/255.0, alpha: 1)
}

}

class DVDScreenSaverView: NSView {

@IBOutlet weak var imageView: NSImageView!

private let logoScale: CGFloat = 6
private var logo: MovingLogo?
private var timer: Timer?

override func awakeFromNib() {
guard let image = NSImage(named: "DVDVideo360"),
let superview = self.imageView.superview else {
print("Setup failed")
return
}
logo = MovingLogo(
image: image,
colors: [
NSColor(190, 0, 255),
NSColor(255, 0, 139),
NSColor(255, 131, 0),
NSColor(0, 38, 255),
NSColor(255, 250, 0),
],
onNewPosition: { rect in
self.imageView.frame = rect
},
onRedraw: { image in
self.imageView.image = image
}
)
let rescale = {
self.logo?.rescale(bounds: superview.bounds, scale: self.logoScale)
}
logo?.nextColor()
rescale()
logo?.placeInRandomSpot()
superview.postsFrameChangedNotifications = true
NotificationCenter.default.addObserver(forName: NSView.frameDidChangeNotification, object: superview, queue: nil) { _ in
rescale()
}
timer = Timer.scheduledTimer(withTimeInterval: 1/60, repeats: true) { _ in
self.logo?.animate()
}
if let timer = timer {
RunLoop.current.add(timer, forMode: .eventTracking)
}
}

override func viewDidMoveToWindow() {
if let win = window {
win.backgroundColor = .black
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
30 changes: 30 additions & 0 deletions DVDScreenSaver-Cocoa/DVDScreenSaver-TestApp/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Loading