Skip to content

Commit

Permalink
Working on UIEventFetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 21, 2017
1 parent 105030d commit 890d280
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sources/Cacao/SDL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ internal func SDLEventRun() {
eventFetcher.pollEvents()

// run loop
//runloop.run(mode: <#T##RunLoopMode#>, before: <#T##Date#>)
runloop.run(mode: .defaultRunLoopMode, before: Date() + 0.1)

// render to screen
screen.update()
Expand Down
2 changes: 2 additions & 0 deletions Sources/Cacao/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ public struct UIColor {
public static var white = UIColor(cgColor: CGColor.white)

public static var black = UIColor(cgColor: CGColor.black)

public static let clear = UIColor(red: 0, green: 0, blue: 0, alpha: 0)
}
4 changes: 3 additions & 1 deletion Sources/Cacao/UIEventFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ internal final class UIEventFetcher {

self.receiveHIDEvent(sdlEvent)
}

self.eventFetcherSink?.eventFetcherDidReceiveEvents(self)
}

private func receiveHIDEvent(_ event: SDL_Event) {

// access safely and add to queue of incoming events
// add to queue of incoming events
self.incomingHIDEvents.append(event)

/*
Expand Down
2 changes: 1 addition & 1 deletion Sources/CacaoDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {

self.window = UIWindow(frame: UIScreen.main.bounds)

self.window?.rootViewController = TableViewController()
self.window?.rootViewController = SwitchViewController()

self.window?.makeKeyAndVisible()

Expand Down
21 changes: 13 additions & 8 deletions Sources/CacaoDemo/ContentModeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ final class ContentModeViewController: UIViewController {

// MARK: - Views

private(set) var label: UILabel!
private(set) weak var label: UILabel!

private(set) var logoView: SwiftLogoView!
private(set) weak var logoView: SwiftLogoView!

private(set) var button: UIButton!
private(set) weak var button: UIButton!

// MARK: - Properties

Expand All @@ -39,27 +39,28 @@ final class ContentModeViewController: UIViewController {

override func loadView() {

logoView = SwiftLogoView(frame: CGRect()) // since we dont use autoresizing, initial size doesnt matter
let logoView = SwiftLogoView(frame: CGRect()) // since we dont use autoresizing, initial size doesnt matter

self.view = logoView

logoView.contentMode = modes[0]

logoView.pointSize = 150

label = UILabel() // layoutSubviews will set size
let label = UILabel() // layoutSubviews will set size

label.text = "\(modes[0])"

label.textColor = UIColor.white

button = UIButton()
let button = UIButton()

button.isOpaque = true

#if os(iOS)
button.addTarget(self, action: #selector(_changeMode), for: .touchUpInside)
button.addTarget(self, action: #selector(_changeMode), for: .touchUpInside)
#else
let selector = Selector(name: "changeMode", action: { (_, sender, _) in self.changeMode(sender as! UIButton) })

button.addTarget(self, action: selector, for: .touchUpInside)
#endif

Expand All @@ -70,6 +71,10 @@ final class ContentModeViewController: UIViewController {
view.addSubview(label)

view.backgroundColor = UIColor.blue

self.button = button
self.label = label
self.logoView = logoView
}

override func viewWillLayoutSubviews() {
Expand Down
1 change: 1 addition & 0 deletions Sources/CacaoDemo/SwiftLogoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class SwiftLogoView: UIView {

// disable user interaction
self.isUserInteractionEnabled = false
self.backgroundColor = .clear
}

@available(iOS, unavailable)
Expand Down
7 changes: 4 additions & 3 deletions Sources/CacaoDemo/SwitchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ final class SwitchViewController: UIViewController {

// MARK: - Views

private(set) var switchView: UISwitch!
private(set) weak var switchView: UISwitch!

// MARK: - Loading

override func loadView() {

view = UIView(frame: CGRect())
view = UIView()

switchView = UISwitch(frame: CGRect())
let switchView = UISwitch()
self.switchView = switchView

view.backgroundColor = UIColor.white

Expand Down

0 comments on commit 890d280

Please sign in to comment.