Skip to content

Commit

Permalink
Updated for Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 18, 2018
1 parent 8c0cbe1 commit 9cda4a1
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 198 deletions.
1 change: 0 additions & 1 deletion Cartfile

This file was deleted.

60 changes: 0 additions & 60 deletions Package.pins

This file was deleted.

40 changes: 11 additions & 29 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"package": "Cairo",
"repositoryURL": "https://github.com/PureSwift/Cairo.git",
"state": {
"branch": null,
"branch": "master",
"revision": "bc207ab2e367fbafef51a47b85a7e1eb2821ce57",
"version": "1.2.3"
"version": null
}
},
{
Expand Down Expand Up @@ -37,49 +37,31 @@
"version": "1.0.4"
}
},
{
"package": "CLCMS",
"repositoryURL": "https://github.com/PureSwift/CLCMS.git",
"state": {
"branch": null,
"revision": "20d18d62ebc642e52758512cab59af06f2d3655e",
"version": "1.0.0"
}
},
{
"package": "CSDL2",
"repositoryURL": "https://github.com/PureSwift/CSDL2.git",
"state": {
"branch": null,
"revision": "a4798aa0174f6661404b9df4ccaf2ba1dc9cc92c",
"version": "1.0.1"
}
},
{
"package": "LittleCMS",
"repositoryURL": "https://github.com/PureSwift/LittleCMS.git",
"state": {
"branch": null,
"revision": "4143dfd3916be5b1ccd3cc46c27d939e9b63c0dd",
"version": "1.0.2"
"branch": "master",
"revision": "7cfe34d9d12cf7fe958c42c2f37577bd01c703e4",
"version": null
}
},
{
"package": "SDL",
"repositoryURL": "https://github.com/PureSwift/SDL.git",
"state": {
"branch": null,
"revision": "7d73084635022234e399385ae2724ca03d47d2a5",
"version": "1.0.1"
"branch": "master",
"revision": "fe4cdf67266afd5dc285dd6ebf54fb417b44a2a5",
"version": null
}
},
{
"package": "Silica",
"repositoryURL": "https://github.com/PureSwift/Silica.git",
"state": {
"branch": null,
"revision": "6239656493fba609a11bef46efd495fca2379090",
"version": "1.3.2"
"branch": "master",
"revision": "7aeb8673927d2b69a0bab1679fcb8147426651cb",
"version": null
}
}
]
Expand Down
49 changes: 33 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
// swift-tools-version:3.0.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

// swift-tools-version:4.1
import PackageDescription

let package = Package(
name: "Cacao",
targets: [
Target(
name: "CacaoDemo",
dependencies: [.Target(name: "Cacao")]),
Target(
name: "Cacao"
)
],
products: [
.library(name: "Cacao", targets: ["Cacao"]),
.executable(name: "CacaoDemo", targets: ["CacaoDemo"]),
],
dependencies: [
.Package(url: "https://github.com/PureSwift/Silica.git", majorVersion: 1),
.Package(url: "https://github.com/PureSwift/Cairo.git", majorVersion: 1),
.Package(url: "https://github.com/PureSwift/SDL.git", majorVersion: 1),
.Package(url: "https://github.com/PureSwift/CSDL2.git", majorVersion: 1)
.package(
url: "https://github.com/PureSwift/Silica.git",
.branch("master")
),
.package(
url: "https://github.com/PureSwift/Cairo.git",
.branch("master")
),
.package(
url: "https://github.com/PureSwift/SDL.git",
.branch("master")
)
],
exclude: ["iOS", "Resources"]
targets: [
.target(
name: "Cacao",
dependencies: [
"Silica",
"Cairo",
"SDL"
]
),
.target(
name: "CacaoDemo",
dependencies: [
"Cacao"
]
),
]
)
2 changes: 1 addition & 1 deletion Sources/Cacao/NSIndexPath+UITableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public extension IndexPath {
}

@inline(__always)
init(row: Int, in section: Int) {
init(row: Int, section: Int) {

self.init(indexes: [section, row])
}
Expand Down
52 changes: 11 additions & 41 deletions Sources/Cacao/SDL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ internal func SDLEventRun() {
assert(Thread.current.isMainThread, "Should only be called from main thread")
#endif

SDL.initialize(subSystems: [.video]).sdlAssert()
do { try SDL.initialize(subSystems: [.video]) }
catch { fatalError("Could not initialize SDL: \(error)") }

defer { SDL.quit() }

let options = UIApplication.shared.options

let delegate = UIApplication.shared.delegate!

var windowOptions: Set<Window.Option> = [.allowRetina, .opengl]
var windowOptions: BitMaskOptionSet<SDLWindow.Option> = [.allowRetina, .opengl]

if options.canResizeWindow {

Expand All @@ -37,10 +38,14 @@ internal func SDLEventRun() {

let initialWindowSize = preferredSize // can we query for screen resolution?

let window = Window(title: options.windowName, frame: (x: .centered, y: .centered, width: Int(initialWindowSize.width), height: Int(initialWindowSize.height)), options: windowOptions).sdlAssert()
let window = try! SDLWindow(title: options.windowName,
frame: (x: .centered, y: .centered,
width: Int(initialWindowSize.width),
height: Int(initialWindowSize.height)),
options: windowOptions)

// create main UIScreen
let screen = UIScreen(window: window, size: initialWindowSize)
let screen = try! UIScreen(window: window, size: initialWindowSize)
UIScreen._main = screen

let framesPerSecond = screen.maximumFramesPerSecond
Expand Down Expand Up @@ -84,7 +89,8 @@ internal func SDLEventRun() {
if eventCount > 0 { print("Runloop took (\(SDL_GetTicks() - runLoopStartTime)ms)") }

// render to screen
screen.update()
do { try screen.update() }
catch { fatalError("Could not render: \(error)") }

// sleep to save energy
let frameDuration = SDL_GetTicks() - startTime
Expand All @@ -95,39 +101,3 @@ internal func SDLEventRun() {
}
}
}

// MARK: - Assertions

internal extension Bool {

@inline(__always)
func sdlAssert(function: String = #function, file: StaticString = #file, line: UInt = #line) {

guard self else { sdlFatalError(function: function, file: file, line: line) }
}
}

internal extension Optional {

@inline(__always)
func sdlAssert(function: String = #function, file: StaticString = #file, line: UInt = #line) -> Wrapped {

guard let value = self
else { sdlFatalError(function: function, file: file, line: line) }

return value
}
}

@_silgen_name("_cacao_sdl_fatal_error")
internal func sdlFatalError(function: String = #function, file: StaticString = #file, line: UInt = #line) -> Never {

if let error = SDL.errorDescription {

fatalError("SDL error: \(error)", file: file, line: line)

} else {

fatalError("An SDL error occurred", file: file, line: line)
}
}
4 changes: 2 additions & 2 deletions Sources/Cacao/UIFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public final class UIFont: Equatable {

public extension UIFont {

static func systemFontOfSize(_ size: CGFloat) -> UIFont {
static func systemFont(ofSize size: CGFloat) -> UIFont {

return UIFont(name: "HelveticaNeu", size: size)!
}

static func boldSystemFontOfSize(_ size: CGFloat) -> UIFont {
static func boldSystemFont(ofSize size: CGFloat) -> UIFont {

return UIFont(name: "HelveticaNeu-Bold", size: size)!
}
Expand Down
12 changes: 4 additions & 8 deletions Sources/Cacao/UILabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
// Copyright © 2016 PureSwift. All rights reserved.
//

import struct Foundation.CGFloat
import struct Foundation.CGPoint
import struct Foundation.CGSize
import struct Foundation.CGRect
import Foundation
import Silica

open class UILabel: UIView {
Expand All @@ -25,7 +22,7 @@ open class UILabel: UIView {

// MARK: - Properties

open var text: String = "" { didSet { setNeedsDisplay() } }
open var text: String? { didSet { setNeedsDisplay() } }

open var font: UIFont = UIFont(name: "Helvetica", size: 17)! { didSet { setNeedsDisplay() } }

Expand All @@ -35,8 +32,7 @@ open class UILabel: UIView {

// MARK: - Draw

@nonobjc
open override func draw(_ rect: CGRect?) {
open override func draw(_ rect: CGRect) {

guard let context = UIGraphicsGetCurrentContext()
else { return }
Expand All @@ -46,7 +42,7 @@ open class UILabel: UIView {
attributes.color = textColor
attributes.paragraphStyle.alignment = textAlignment

text.draw(in: self.bounds, context: context, attributes: attributes)
text?.draw(in: self.bounds, context: context, attributes: attributes)
}
}

Expand Down
Loading

0 comments on commit 9cda4a1

Please sign in to comment.