Skip to content

Commit 1e8d3a9

Browse files
committed
Working on Renderer
1 parent 2841a12 commit 1e8d3a9

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

Sources/SDL/Renderer.swift

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public final class SDLRenderer {
4242
return (red, green, blue, alpha)
4343
}
4444

45-
public func setDrawColor(_ newValue: (red: UInt8, green: UInt8, blue: UInt8, alpha: UInt8)) throws {
45+
public func setDrawColor(red: UInt8, green: UInt8, blue: UInt8, alpha: UInt8) throws {
4646

47-
try SDL_SetRenderDrawColor(internalPointer, newValue.red, newValue.green, newValue.blue, newValue.alpha).sdlThrow()
47+
try SDL_SetRenderDrawColor(internalPointer, red, green, blue, alpha).sdlThrow()
4848
}
4949

5050
/// Current rendering target texture.
@@ -90,35 +90,21 @@ public final class SDLRenderer {
9090
}
9191

9292
/// Copy a portion of the texture to the current rendering target.
93-
public func copy(_ texture: SDLTexture, source: SDL_Rect? = nil, destination: SDL_Rect? = nil) throws {
94-
95-
let sourcePointer: UnsafeMutablePointer<SDL_Rect>?
96-
97-
defer { sourcePointer?.deallocate() }
93+
public func copy(_ texture: SDLTexture,
94+
source: SDL_Rect? = nil,
95+
destination: SDL_Rect? = nil) throws {
9896

97+
let sourcePointer: UnsafePointer<SDL_Rect>?
9998
if let rect = source {
100-
101-
sourcePointer = UnsafeMutablePointer.allocate(capacity: 1)
102-
103-
sourcePointer?.pointee = rect
104-
99+
sourcePointer = withUnsafePointer(to: rect) { $0 }
105100
} else {
106-
107101
sourcePointer = nil
108102
}
109103

110-
let destinationPointer: UnsafeMutablePointer<SDL_Rect>?
111-
112-
defer { destinationPointer?.deallocate() }
113-
104+
let destinationPointer: UnsafePointer<SDL_Rect>?
114105
if let rect = destination {
115-
116-
destinationPointer = UnsafeMutablePointer.allocate(capacity: 1)
117-
118-
destinationPointer?.pointee = rect
119-
106+
destinationPointer = withUnsafePointer(to: rect) { $0 }
120107
} else {
121-
122108
destinationPointer = nil
123109
}
124110

Sources/SDLDemo/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() throws {
4545

4646
// renderer
4747
let renderer = try SDLRenderer(window: window)
48-
try renderer.setDrawColor((0xFF, 0xFF, 0xFF, 0xFF))
48+
try renderer.setDrawColor(red: 0xFF, green: 0xFF, blue: 0xFF, alpha: 0xFF)
4949

5050
var frame = 0
5151

0 commit comments

Comments
 (0)