40 lines
1.1 KiB
Swift
40 lines
1.1 KiB
Swift
import CSDL3
|
|
|
|
public class Renderer {
|
|
var handle: OpaquePointer
|
|
|
|
var scale: (x: Float, y: Float) {
|
|
get {
|
|
var x: Float = 0.0
|
|
var y: Float = 0.0
|
|
SDL_GetRenderScale(handle, &x, &y)
|
|
return (x, y)
|
|
}
|
|
}
|
|
|
|
public func setScale(newScale: (x: Float, y: Float)) throws {
|
|
try SDL_SetRenderScale(handle, newScale.x, newScale.y).sdlThrow(type: type(of: self))
|
|
}
|
|
|
|
public init(_ window: Window, name: String? = nil) throws {
|
|
handle = try SDL_CreateRenderer(window.handle, name).sdlThrow(type: type(of: self))
|
|
}
|
|
|
|
deinit {
|
|
SDL_DestroyRenderer(handle)
|
|
}
|
|
|
|
|
|
public func clear() throws {
|
|
try SDL_RenderClear(handle).sdlThrow(type: type(of: self))
|
|
}
|
|
|
|
public func renderTexture(_ texture: Texture, srcRect: UnsafePointer<SDL_FRect>! = nil, dstRect: UnsafePointer<SDL_FRect>! = nil) throws {
|
|
try SDL_RenderTexture(handle, texture.handle, srcRect, dstRect).sdlThrow(type: type(of: self))
|
|
}
|
|
|
|
public func present() {
|
|
SDL_RenderPresent(handle)
|
|
}
|
|
}
|