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 rendering
  • Loading branch information
colemancda committed Jun 8, 2017
commit bf3b33f9b29673f9b4e438fcddd7110b1a69798f
1 change: 0 additions & 1 deletion Sources/Cacao/UIApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public func UIApplicationMain(delegate: UIApplicationDelegate, options: CacaoOpt

// inform responder chain


// render to screen
if needsDisplay {

Expand Down
10 changes: 2 additions & 8 deletions Sources/Cacao/UIScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,17 @@ public final class UIScreen {
internal func update() {

if needsLayout {

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

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()

let texture = Texture(renderer: renderer, surface: imageSurface).sdlAssert()
renderer.clear()

// render view hierarchy


// render to screen
renderer.copy(texture)
renderer.clear()
renderer.copy(<#T##texture: Texture##Texture#>, source: <#T##SDL_Rect?#>, destination: <#T##SDL_Rect?#>)
renderer.present()

needsDisplay = false
Expand Down
46 changes: 32 additions & 14 deletions Sources/Cacao/UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// Copyright © 2016 PureSwift. All rights reserved.
//

import Silica
import CSDL2
import SDL
import Silica
import Cairo

/// An object that represents a rectangular area on the screen and manages the content in that area.
///
Expand Down Expand Up @@ -415,34 +417,50 @@ open class UIView {
return nil
}







// MARK: - Drawing

/// The backing rendering node / texture.
///
/// Cacao's equivalent of `UIView.layer` / `CALayer`.
/// Instead of the CoreGraphics API you could draw directly to the texture's pixel data.
public private(set) var texture: Texture!


private var texture: Texture!
private var surface: Cairo.Surface.Image!

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



// MARK: - Drawing

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

private func createTexture(for renderer: Renderer) {

let width = Int(bounds.size.width)
let height = Int(bounds.size.height)

texture = Texture(renderer: renderer,
format: PixelFormat.RawValue(SDL_PIXELFORMAT_ARGB8888),
access: .streaming,
width: width,
height: height)!

surface = texture.withUnsafeMutableBytes { try! Cairo.Surface.Image.init(mutableBytes: $0.assumingMemoryBound(to: UInt8.self), format: .argb32, width: width, height: height, stride: $1) }


}

internal final func render(in renderer: Renderer) {

guard shouldRender
else { return }

// create SDL texture
if texture == nil {
createTexture(for: renderer)
}

let context = try! Silica.Context(surface: surface, size: bounds.size)

// CoreGraphics drawing
draw(in: context)


}

Expand Down