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 rendering
  • Loading branch information
colemancda committed Jun 8, 2017
commit a20fbcf67bfd9696578e7d8c3001582a94d43949
13 changes: 2 additions & 11 deletions Sources/Cacao/UIApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public func UIApplicationMain(delegate: UIApplicationDelegate, options: CacaoOpt

defer { SDL.quit() }

var windowOptions: [Window.Option] = [.allowRetina]
var windowOptions: [Window.Option] = [] // [.allowRetina]

if options.canResizeWindow {

Expand Down Expand Up @@ -69,12 +69,8 @@ public func UIApplicationMain(delegate: UIApplicationDelegate, options: CacaoOpt

var pollEventStatus = SDL_PollEvent(&event)

var needsDisplay = screen.needsDisplay // UIView sets this value

while pollEventStatus != 0 {

needsDisplay = true

let eventType = SDL_EventType(rawValue: event.type)

switch eventType {
Expand Down Expand Up @@ -104,8 +100,6 @@ public func UIApplicationMain(delegate: UIApplicationDelegate, options: CacaoOpt

case UInt8(SDL_WINDOWEVENT_SIZE_CHANGED.rawValue):

needsDisplay = true

let size = Size(width: Double(event.window.data1), height: Double(event.window.data2))

screen.size = (size, size)
Expand All @@ -123,10 +117,7 @@ public func UIApplicationMain(delegate: UIApplicationDelegate, options: CacaoOpt
// inform responder chain

// render to screen
if needsDisplay {

screen.update()
}
screen.update()

// sleep to save energy
let frameDuration = Int(SDL_GetTicks() - startTime)
Expand Down
57 changes: 47 additions & 10 deletions Sources/Cacao/UIScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
// Copyright © 2016 PureSwift. All rights reserved.
//

import Silica
import CSDL2
import SDL
import Silica

public final class UIScreen {

Expand Down Expand Up @@ -64,27 +65,63 @@ public final class UIScreen {
/// Layout (if needed) and redraw the screen
internal func update() {

// layout views
if needsLayout {
windows.forEach { $0.layoutIfNeeded() }
}

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

// render view hierarchy


// render to screen
renderer.copy(<#T##texture: Texture##Texture#>, source: <#T##SDL_Rect?#>, destination: <#T##SDL_Rect?#>)
renderer.present()
// render views
if needsLayout || needsDisplay {

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

// FIXME to support multiple windows
for window in [keyWindow!] {

// render view hierarchy
render(view: window)

// render to screen
renderer.present()
}
}

needsDisplay = false
needsLayout = false
}

private func sizeChanged() {

// update windows
keyWindow?.frame = Rect(size: size.window)

needsDisplay = true
needsLayout = true
}

private func render(view: UIView, origin: Point = Point()) {

guard view.isHidden == false
else { return }

// add translation
//context.translate(x: view.frame.x, y: view.frame.y)
var relativeOrigin = origin
relativeOrigin.x += view.frame.origin.x
relativeOrigin.y += view.frame.origin.y

// frame of view relative to SDL window
let rect = SDL_Rect(x: Int32(relativeOrigin.x),
y: Int32(relativeOrigin.y),
w: Int32(view.frame.size.width),
h: Int32(view.frame.size.height))

// render view
view.render(with: renderer, in: rect)

// render subviews
view.subviews.forEach { render(view: $0, origin: relativeOrigin) }
}
}

Expand Down
13 changes: 10 additions & 3 deletions Sources/Cacao/UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,19 @@ open class UIView {

}

internal final func render(in renderer: Renderer) {
internal final func render(with renderer: Renderer, in rect: SDL_Rect) {

guard shouldRender
else { return }

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

// create SDL texture
if texture == nil {
if texture == nil
|| texture.width != width
|| texture.height != height {

createTexture(for: renderer)
}

Expand All @@ -461,7 +467,7 @@ open class UIView {
// CoreGraphics drawing
draw(in: context)


renderer.copy(texture, destination: rect)
}

internal func draw(in context: Silica.Context) {
Expand All @@ -478,6 +484,7 @@ open class UIView {

// draw rect
draw(bounds)
surface.flush()

UIGraphicsPopContext()
}
Expand Down