Files
playdate-kit/Sources/PlaydateKit/Display/Display.swift
T
javier c5037dd716 Swift 6.4 migration and exhancements (#1)
This PR contains the work done to update the library and the attached example project to use the Swift 6.4 computer as a minimum supported version and also, to use the latest features introduced in it.

Reviewed-on: #1
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
2026-09-18 13:15:08 +00:00

48 lines
1.7 KiB
Swift

internal import CPlaydate
/// Display size, refresh rate, scale, and effects. Wraps `playdate_display`.
public enum Display {}
extension Display {
private static var api: UnsafePointer<playdate_display> { Playdate.displayAPI.unsafelyUnwrapped }
/// Pixels at the current scale (200 at scale 2).
public static var width: Int { Int(api.pointee.getWidth.unsafelyUnwrapped()) }
/// Pixels at the current scale (120 at scale 2).
public static var height: Int { Int(api.pointee.getHeight.unsafelyUnwrapped()) }
/// Target frames per second; default 30, max 50. 0 updates as fast as possible.
public static var refreshRate: Float {
get { api.pointee.getRefreshRate.unsafelyUnwrapped() }
set { api.pointee.setRefreshRate.unsafelyUnwrapped(newValue) }
}
/// Measured frames per second; can fall below `refreshRate` on slow frames.
public static var fps: Float { api.pointee.getFPS.unsafelyUnwrapped() }
/// `true` swaps black and white.
public static func setInverted(_ inverted: Bool) {
api.pointee.setInverted.unsafelyUnwrapped(inverted ? 1 : 0)
}
/// Valid values: 1, 2, 4, 8.
public static func setScale(_ scale: UInt32) {
api.pointee.setScale.unsafelyUnwrapped(scale)
}
/// Mosaic effect; `x` and `y` in 0...3.
public static func setMosaic(x: UInt32, y: UInt32) {
api.pointee.setMosaic.unsafelyUnwrapped(x, y)
}
public static func setFlipped(x: Bool, y: Bool) {
api.pointee.setFlipped.unsafelyUnwrapped(x ? 1 : 0, y ? 1 : 0)
}
/// Offset in pixels; uncovered areas show the current background color.
public static func setOffset(x: Int, y: Int) {
api.pointee.setOffset.unsafelyUnwrapped(Int32(x), Int32(y))
}
}