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

SDL Texture support #12

Merged
merged 42 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cbf4052
refactoring
colemancda Jun 7, 2017
f989e1d
refactoring
colemancda Jun 7, 2017
40c762e
working on UIScreen
colemancda Jun 7, 2017
dd6aa58
working on view drawing and layout
colemancda Jun 7, 2017
7f69dac
working on UIView
colemancda Jun 8, 2017
dc9402e
working on UIView
colemancda Jun 8, 2017
28ad68f
Working on UIFont
colemancda Jun 8, 2017
ec3068b
working on UIViewController
colemancda Jun 8, 2017
31be8a9
working on UIView
colemancda Jun 8, 2017
bf3b33f
working on UIView rendering
colemancda Jun 8, 2017
a20fbcf
working on rendering
colemancda Jun 8, 2017
c57e626
working on Demo
colemancda Jun 8, 2017
3e4b536
working on rendering
colemancda Jun 8, 2017
9237627
working on rendering
colemancda Jun 8, 2017
62ab6ff
working on rendering
colemancda Jun 8, 2017
7aa8fa7
working on resizing
colemancda Jun 8, 2017
7ecbd8f
working on rendering
colemancda Jun 8, 2017
d3260f9
working on rendering
colemancda Jun 8, 2017
4d78a63
fixed rendering issue
colemancda Jun 8, 2017
6f0ce39
improved Cairo Surface and SDL texture interaction
colemancda Jun 8, 2017
99ef976
Fixed unit tests
colemancda Jun 8, 2017
ab969a2
fixed crash due to (0,0) sized views
colemancda Jun 8, 2017
49afcd8
[Demo] updated ContentModeViewController
colemancda Jun 8, 2017
5c4dc7b
fixed UILabel drawing
colemancda Jun 8, 2017
ca8c13f
working on demo
colemancda Jun 8, 2017
8a3e173
Added UIView.intrinsicContentSize
colemancda Jun 8, 2017
86e18a8
working on Event handling
colemancda Jun 8, 2017
cb0ad22
working on UIResponder
colemancda Jun 8, 2017
cada244
[Demo] Removed ContentView
colemancda Jun 8, 2017
ac22d32
[Demo] removed StyleKit
colemancda Jun 8, 2017
193c5d3
working on Event handling
colemancda Jun 8, 2017
d2f5d41
working on UITouch
colemancda Jun 8, 2017
0782283
[Demo] Added support for intrinsic size changing to SwiftLogoView
colemancda Jun 8, 2017
8e29046
Added UIControl
colemancda Jun 8, 2017
d763b63
working on Retina support
colemancda Jun 9, 2017
21f6fec
working on SDL support
colemancda Jun 9, 2017
889975d
implemented Retina rendering
colemancda Jun 9, 2017
bb1c947
Fixed UIScreen resizing
colemancda Jun 9, 2017
82edc3d
working on UIControl
colemancda Jun 9, 2017
2ad39ec
working on UIControl
colemancda Jun 9, 2017
b002fd7
working on UIButton
colemancda Jun 9, 2017
dacdbd3
Reset SDL texture buffer before redrawing
colemancda Jun 9, 2017
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
Prev Previous commit
Next Next commit
working on UIView
  • Loading branch information
colemancda committed Jun 8, 2017
commit 31be8a958c67651c10bf2b3aa60013fd66f9e7bd
4 changes: 2 additions & 2 deletions Sources/Cacao/NSStringDrawing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public extension String {

let font = textAttributes.font

let descender = (Double(font.silicaFont.scaledFont.descent) * font.size) / Double(font.silicaFont.scaledFont.unitsPerEm)
let descender = (Double(font.cgFont.scaledFont.descent) * font.pointSize) / Double(font.cgFont.scaledFont.unitsPerEm)

textFrame.height -= descender

Expand All @@ -57,7 +57,7 @@ public extension TextAttributes {
textAttributes.font = font
}

if let textColor = (attributes[NSForegroundColorAttributeName] as? UIColor)?.cgColor {
if let textColor = (attributes[NSForegroundColorAttributeName] as? UIColor) {

textAttributes.color = textColor
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Cacao/TextRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public extension String {

// calculate frame

let textWidth = attributes.font.cgFont.singleLineWidth(text: self, fontSize: attributes.font.size, textMatrix: textMatrix)
let textWidth = attributes.font.cgFont.singleLineWidth(text: self, fontSize: attributes.font.pointSize, textMatrix: textMatrix)

let lines = 1

Expand Down Expand Up @@ -87,8 +87,8 @@ public extension Silica.Context {

func setTextAttributes(_ attributes: TextAttributes) {

self.fontSize = attributes.font.size
self.setFont(attributes.font.silicaFont)
self.fillColor = attributes.color
self.fontSize = attributes.font.pointSize
self.setFont(attributes.font.cgFont)
self.fillColor = attributes.color.cgColor
}
}
4 changes: 2 additions & 2 deletions Sources/Cacao/UIApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ extension UIApplicationLaunchOptionsKey: Hashable {
// Default implementations
public extension UIApplicationDelegate {

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool { }
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool { return true }

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]) -> Bool { }
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]) -> Bool { return true }

func applicationDidBecomeActive(_ application: UIApplication) { }

Expand Down
File renamed without changes.
13 changes: 1 addition & 12 deletions Sources/Cacao/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Silica

public final class UIColor {
public struct UIColor {

// MARK: - Properties

Expand Down Expand Up @@ -80,14 +80,3 @@ public final class UIColor {

public static var black = UIColor(cgColor: Color.black)
}

// MARK: - CacaoConvertible

extension UIColor: CacaoConvertible {

public func toCacao() -> Silica.Color {

return cgColor
}
}

18 changes: 3 additions & 15 deletions Sources/Cacao/Label.swift → Sources/Cacao/UILabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ open class UILabel: UIView {

public final var text: String = "" { didSet { setNeedsDisplay() } }

public final var font: Font = UILabel.appearance().font { didSet { setNeedsDisplay() } }
public final var font: UIFont = UIFont(name: "Helvetica", size: 17)! { didSet { setNeedsDisplay() } }

public final var color: Color = UILabel.appearance().color { didSet { setNeedsDisplay() } }
public final var color: UIColor = UIColor.black { didSet { setNeedsDisplay() } }

public final var textAlignment: TextAlignment = .left { didSet { setNeedsDisplay() } }

Expand All @@ -43,18 +43,6 @@ extension UILabel {

public static func appearance() -> UILabel {

struct Static {
static let value = create()
static func create() -> UILabel {

let font = UIFont(name: "Helvetica", size: 17)!

let color = UIColor.black

let label = UILabel(frame: CGRect())
}
}

return Static.value
return UILabel(frame: CGRect())
}
}
2 changes: 1 addition & 1 deletion Sources/Cacao/UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ open class UIView {
UIGraphicsPushContext(CGContext(context))

// draw background color
context.fillColor = backgroundColor?.cgColor
context.fillColor = backgroundColor?.cgColor ?? CGColor.clear
context.add(rect: bounds)
try! context.fill()

Expand Down
9 changes: 3 additions & 6 deletions Sources/Cacao/UIViewContentMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ public extension UIViewContentMode {

switch self {

case .redraw:

// tiled?
fallthrough
case .redraw: fallthrough

case .scaleToFill:

return Rect(size: bounds.size)

case .aspectFit:
case .scaleAspectFit:

let widthRatio = bounds.width / size.width
let heightRatio = bounds.height / size.height
Expand All @@ -73,7 +70,7 @@ public extension UIViewContentMode {

return Rect(origin: origin, size: newSize)

case .aspectFill:
case .scaleAspectFill:

let widthRatio = (bounds.size.width / size.width)
let heightRatio = (bounds.size.height / size.height)
Expand Down
12 changes: 6 additions & 6 deletions Sources/Cacao/UIWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ open class UIWindow: UIView {
public final var rootViewController: UIViewController?

/// The screen on which the window is displayed.
public final var screen: UIScreen { return UIScreen.main }
public final var screen: UIScreen = UIScreen.main

/// The position of the window in the z-axis.
public final var windowLevel: UIWindowLevel = .normal
public final var windowLevel: UIWindowLevel = UIWindowLevelNormal

/// A Boolean value that indicates whether the window is the key window for the app.
public final var isKeyWindow: Bool { return UIScreen.main.keyWindow === self }
Expand All @@ -31,7 +31,7 @@ open class UIWindow: UIView {

makeKey()

hidden = false
isHidden = false
}

/// Makes the receiver the key window.
Expand Down Expand Up @@ -63,10 +63,10 @@ open class UIWindow: UIView {
public typealias UIWindowLevel = CGFloat

/// The default level. Use this level for the majority of your content, including for your app’s main window.
public let UIWindowLevelNormal: UIWindowLevel
public let UIWindowLevelNormal: UIWindowLevel = 0

/// The level for an alert view. Windows at this level appear on top of windows at the UIWindowLevelNormal level.
public let UIWindowLevelAlert: UIWindowLevel
public let UIWindowLevelAlert: UIWindowLevel = 2000

/// The level for a status window. Windows at this level appear on top of windows at the UIWindowLevelAlert level.
public let UIWindowLevelStatusBar: UIWindowLevel
public let UIWindowLevelStatusBar: UIWindowLevel = 1000
8 changes: 4 additions & 4 deletions Tests/CacaoTests/FontTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ final class FontTests: XCTestCase {

let expectedFullName = "Times New Roman"

XCTAssert(font.name == font.silicaFont.name)
XCTAssert(expectedFullName == font.silicaFont.scaledFont.fullName, "\(expectedFullName) == \(font.silicaFont.scaledFont.fullName)")
XCTAssert(font.name == font.cgFont.name)
XCTAssert(expectedFullName == font.cgFont.scaledFont.fullName, "\(expectedFullName) == \(font.cgFont.scaledFont.fullName)")
}

func testCreateTraitFont() {
Expand All @@ -34,7 +34,7 @@ final class FontTests: XCTestCase {

let expectedFullName = "Times New Roman"

XCTAssert(font.name == font.silicaFont.name)
XCTAssert(expectedFullName == font.silicaFont.scaledFont.fullName, "\(expectedFullName) == \(font.silicaFont.scaledFont.fullName)")
XCTAssert(font.name == font.cgFont.name)
XCTAssert(expectedFullName == font.cgFont.scaledFont.fullName, "\(expectedFullName) == \(font.cgFont.scaledFont.fullName)")
}
}