Files
Picross/Sources/SDL/Renderer.swift
T
2024-10-24 14:38:04 -04:00

40 lines
1.1 KiB
Swift

import CSDL2
public class Renderer {
var handle: OpaquePointer
var scale: (x: Float, y: Float) {
get {
var x: Float = 0.0
var y: Float = 0.0
SDL_RenderGetScale(handle, &x, &y)
return (x, y)
}
}
public func setScale(newScale: (x: Float, y: Float)) throws {
try SDL_RenderSetScale(handle, newScale.x, newScale.y).sdlThrow(type: type(of: self))
}
public init(_ window: Window) throws {
handle = try SDL_CreateRenderer(window.handle, -1, SDL_RENDERER_ACCELERATED.rawValue).sdlThrow(type: type(of: self))
}
deinit {
SDL_DestroyRenderer(handle)
}
public func clear() throws {
try SDL_RenderClear(handle).sdlThrow(type: type(of: self))
}
public func copy(_ texture: Texture, srcRect: UnsafePointer<SDL_Rect>! = nil, dstRect: UnsafePointer<SDL_Rect>! = nil) throws {
try SDL_RenderCopy(handle, texture.handle, srcRect, dstRect).sdlThrow(type: type(of: self))
}
public func present() {
SDL_RenderPresent(handle)
}
}