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 UIViewController
  • Loading branch information
colemancda committed Jun 8, 2017
commit ec3068b4ddff66581630fc80837fd6fa0c9b9f91
2 changes: 1 addition & 1 deletion Sources/Cacao/NSStringDrawing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)?.cgColor {

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,11 +31,11 @@ public extension String {

// calculate frame

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

let lines = 1

let textHeight = attributes.font.size * Double(lines)
let textHeight = attributes.font.pointSize * Double(lines)

var textRect = Rect(x: bounds.x, y: bounds.y, width: textWidth, height: textHeight) // height == font.size

Expand All @@ -58,9 +58,9 @@ public struct TextAttributes {

public init() { }

public var font = Font(name: "Helvetica", size: 17)!
public var font = UIFont(name: "Helvetica", size: 17)!

public var color = Color.black
public var color = UIColor.black

public var paragraphStyle = ParagraphStyle()
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Cacao/UIApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public func UIApplicationMain(delegate: UIApplicationDelegate, options: CacaoOpt
guard event.button.which != SDL_TOUCH_MOUSEID
else { return }*/

break
//screen.handle(event: PointerEvent(event.button))

case SDL_FINGERDOWN, SDL_FINGERUP: break
Expand Down
22 changes: 11 additions & 11 deletions Sources/Cacao/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public final class UIColor {

// MARK: - Properties

public let CGColor: Color
public let cgColor: CGColor

// MARK: - Initialization

public init(cgColor color: Color) {
public init(cgColor color: CGColor) {

self.CGColor = color
self.cgColor = color
}

/// An initialized color object. The color information represented by this object is in the device RGB colorspace.
Expand All @@ -27,7 +27,7 @@ public final class UIColor {
blue: Double,
alpha: Double = 1.0) {

self.CGColor = Color(red: red, green: green, blue: blue, alpha: alpha)
self.cgColor = Color(red: red, green: green, blue: blue, alpha: alpha)
}

// MARK: - Methods
Expand All @@ -39,10 +39,10 @@ public final class UIColor {
blue: inout Double,
alpha: inout Double) -> Bool {

red = CGColor.red
green = CGColor.green
blue = CGColor.blue
alpha = CGColor.alpha
red = cgColor.red
green = cgColor.green
blue = cgColor.blue
alpha = cgColor.alpha

return true
}
Expand All @@ -59,13 +59,13 @@ public final class UIColor {
/// Sets the color of subsequent fill operations to the color that the receiver represents.
public func setFill() {

UIGraphicsGetCurrentContext()?.silicaContext.fillColor = CGColor
UIGraphicsGetCurrentContext()?.silicaContext.fillColor = cgColor
}

/// Sets the color of subsequent stroke operations to the color that the receiver represents.
public func setStroke() {

UIGraphicsGetCurrentContext()?.silicaContext.strokeColor = CGColor
UIGraphicsGetCurrentContext()?.silicaContext.strokeColor = cgColor
}

// MARK: - Singletons
Expand All @@ -87,7 +87,7 @@ extension UIColor: CacaoConvertible {

public func toCacao() -> Silica.Color {

return CGColor
return cgColor
}
}

13 changes: 9 additions & 4 deletions Sources/Cacao/UIScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class UIScreen {

public static internal(set) var main: UIScreen!

public static let screens: [UIScreen] = [UIScreen.main]()
public static var screens: [UIScreen] { return [UIScreen.main] }

// MARK: - Properties

Expand All @@ -38,7 +38,7 @@ public final class UIScreen {

internal let window: Window

internal var size: (window: Size, native: Size)
internal var size: (window: Size, native: Size) { didSet { sizeChanged() } }

internal lazy var renderer: Renderer = Renderer(window: self.window).sdlAssert()

Expand Down Expand Up @@ -66,10 +66,10 @@ public final class UIScreen {

if needsLayout {


windows.forEach { $0.layoutIfNeeded() }
}

renderer.drawColor = (0xFF, 0xFF, 0xFF, 0xFF)
renderer.drawColor = (0x00, 0x00, 0x00, 0xFF)

// get data for surface
let imageSurface = Surface(rgb: (Int(size.window.width), Int(size.window.height)), depth: 32).sdlAssert()
Expand All @@ -87,6 +87,11 @@ public final class UIScreen {
needsDisplay = false
needsLayout = false
}

private func sizeChanged() {


}
}

/*
Expand Down
9 changes: 5 additions & 4 deletions Sources/Cacao/UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,18 @@ open class UIView {



internal final var shouldDrawContent: Bool { return isHidden == false && alpha > 0 }
internal final var shouldRender: Bool { return isHidden == false && alpha > 0 }



// MARK: - Drawing

open func draw(_ rect: CGRect) { /* implemented by subclasses */ }

internal final func render(in renderer) {
internal final func render(in renderer: Renderer) {

let shouldDrawContent = hidden == false && alpha > 0
guard shouldRender
else { return }


}
Expand All @@ -450,7 +451,7 @@ open class UIView {
UIGraphicsPushContext(CGContext(context))

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

Expand Down
6 changes: 6 additions & 0 deletions Sources/Cacao/UIViewContentMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
// Copyright © 2016 PureSwift. All rights reserved.
//

#if os(macOS)
import Darwin.C.math
#elseif os(Linux)
import Glibc
#endif

import Silica

public enum UIViewContentMode: Int {
Expand Down
157 changes: 157 additions & 0 deletions Sources/Cacao/UIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,166 @@
// Created by Alsey Coleman Miller on 6/7/17.
//

import class Foundation.NSCoder
import class Foundation.Bundle
import Silica

open class UIViewController {

// MARK: - Configuring a View Controller Using Nib Files

public init?(coder: NSCoder) {

return nil
}

/// Returns a newly initialized view controller with the nib file in the specified bundle.
public init(nibName: String? = nil, bundle: Bundle? = nil) {

self.nibName = nibName
self.nibBundle = bundle
}

public final var nibName: String?

public final var nibBundle: Bundle?

// MARK: - Managing the View

/// The view that the controller manages.
///
/// The view stored in this property represents the root view for the view controller'€™s view hierarchy.
/// The default value of this property is nil.
///
/// If you access this property and its value is currently nil,
/// the view controller automatically calls the loadView() method and returns the resulting view.
///
/// Each view controller object is the sole owner of its view.
/// You must not associate the same view object with multiple view controller objects.
/// The only exception to this rule is that a container view controller implementation may
/// add this view as a subview in its own view hierarchy. Before adding the subview,
/// the container must first call its `addChildViewController(_:)` method
/// to create a parent-child relationship between the two view controller objects.
///
/// Because accessing this property can cause the view to be loaded automatically,
/// you can use the isViewLoaded() method to determine if the view is currently in memory.
/// Unlike this property, the isViewLoaded() property does not force the loading of the
/// view if it is not currently in memory.
public final var view: UIView! {
get { loadViewIfNeeded(); return _view }
set { _view = newValue }
}
private var _view: UIView?
public final var isViewLoaded: Bool { return _view != nil }

/// You should never call this method directly.
/// The view controller calls this method when its view property is requested but is currently nil.
/// This method loads or creates a view and assigns it to the view property.
///
/// If the view controller has an associated nib file, this method loads the view from the nib file.
/// A view controller has an associated nib file if the nibName property returns a non-nil value,
/// which occurs if the view controller was instantiated from a storyboard,
/// if you explicitly assigned it a nib file using the `init(nibName:bundle:)` method,
/// or if the app finds a nib file in the app bundle with a name based on the view controller'€™s class name.
/// If the view controller does not have an associated nib file, this method creates a plain `UIView` object instead.
///
/// If you use Interface Builder to create your views and initialize the view controller, you must not override this method.
///
/// You can override this method in order to create your views manually.
/// If you choose to do so, assign the root view of your view hierarchy to the view property.
/// The views you create should be unique instances and should not be shared with any other view controller object.
/// Your custom implementation of this method should not call super.
///
/// If you want to perform any additional initialization of your views, do so in the `viewDidLoad()` method.
open func loadView() {

self.view = UIView(frame: CGRect())
}

/// Called after the controller'€™s view is loaded into memory.
open func viewDidLoad() { /* Subclasses should override */ }

/// Loads the view controller’s view if it has not yet been loaded.
public final func loadViewIfNeeded() {

if isViewLoaded == false {
loadView()
viewDidLoad()
}
}

/// The view controller’s view, or nil if the view is not yet loaded.
public final var viewIfLoaded: UIView? { return _view }

/// A localized string that represents the view this controller manages.
public final var title: String?

/// The preferred size for the view controller’s view.
///
/// The value in this property is used primarily when displaying the view controller’s
/// content in a popover but may also be used in other situations.
public final var preferredContentSize: CGSize = CGSize()

// MARK: - Presenting View Controllers

// MARK: - Responding to View Events

// MARK: - Configuring the View’s Layout Behavior

// MARK: - Configuring the View Rotation Settings

// MARK: - Managing Child View Controllers in a Custom Container

public final private(set) var childViewControllers = [UIViewController]()

public final func addChildViewController(_ viewController: UIViewController) {

childViewControllers.append(viewController)

viewController.parent = self
}

public final func removeFromParentViewController() {

guard let index = parent?.childViewControllers.index(where: { $0 === self })
else { return }

parent?.childViewControllers.remove(at: index)
}

// MARK: - Responding to Containment Events

// MARK: - Getting Other Related View Controllers

/// The view controller that presented this view controller.
public private(set) weak var presentingViewController: UIViewController?

/// The view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy.
public var presentedViewController: UIViewController? {

return nil
}

public final private(set) weak var parent: UIViewController?

//public final var navigationController: UINavigationController?

//var splitViewController: UISplitViewController?
//var tabBarController: UITabBarController?

// MARK: - Handling Memory Warnings

/// Sent to the view controller when the app receives a memory warning.
///
/// Your app never calls this method directly.
/// Instead, this method is called when the system determines that the amount of available memory is low.
///
/// You can override this method to release any additional memory used by your view controller.
/// If you do, your implementation of this method must call the super implementation at some point.
open func didReceiveMemoryWarning() {

childViewControllers.forEach { $0.didReceiveMemoryWarning() }
}


}
28 changes: 0 additions & 28 deletions Sources/Cacao/ViewController.swift

This file was deleted.