Added missing documentation to the source code in the Playdate bindings target.
This commit is contained in:
@@ -39,6 +39,7 @@ extension Graphics {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// The bitmap's dimensions, row stride, and raw storage.
|
||||
public var data: Data {
|
||||
var width: Int32 = 0, height: Int32 = 0, rowBytes: Int32 = 0
|
||||
var mask: UnsafeMutablePointer<UInt8>?
|
||||
@@ -61,7 +62,9 @@ extension Graphics {
|
||||
return size
|
||||
}
|
||||
|
||||
/// The bitmap's width, in pixels.
|
||||
public var width: Int { size.width }
|
||||
/// The bitmap's height, in pixels.
|
||||
public var height: Int { size.height }
|
||||
|
||||
/// The color of the pixel at (x, y).
|
||||
@@ -84,6 +87,7 @@ extension Graphics {
|
||||
color.withLCDColor { gfx.pointee.clearBitmap.unsafelyUnwrapped(pointer, $0) }
|
||||
}
|
||||
|
||||
/// Returns a new copy of the bitmap.
|
||||
public func copy() -> Bitmap {
|
||||
Bitmap(pointer: gfx.pointee.copyBitmap.unsafelyUnwrapped(pointer).unsafelyUnwrapped, isOwned: true)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ extension Graphics {
|
||||
return (Int(count), Int(width))
|
||||
}
|
||||
|
||||
/// The number of bitmaps in the table.
|
||||
public var count: Int { info.count }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
internal import CPlaydate
|
||||
|
||||
/// The cached `playdate->graphics->videostream` C API table.
|
||||
private var streamAPI: UnsafePointer<playdate_videostream> { Playdate.videoStreamAPI.unsafelyUnwrapped }
|
||||
|
||||
extension Graphics {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
internal import CPlaydate
|
||||
|
||||
/// The cached `playdate->graphics->tilemap` C API table.
|
||||
private var tilemapAPI: UnsafePointer<playdate_tilemap> { Playdate.tilemapAPI.unsafelyUnwrapped }
|
||||
|
||||
extension Graphics {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
internal import CPlaydate
|
||||
|
||||
/// The cached `playdate->graphics->video` C API table.
|
||||
private var videoAPI: UnsafePointer<playdate_video> { Playdate.videoAPI.unsafelyUnwrapped }
|
||||
|
||||
extension Graphics {
|
||||
|
||||
@@ -3,10 +3,15 @@ internal import CPlaydate
|
||||
extension Graphics {
|
||||
/// A drawing color: solid or an 8×8 pattern.
|
||||
public enum Color: Sendable {
|
||||
/// Solid black.
|
||||
case black
|
||||
/// Solid white.
|
||||
case white
|
||||
/// Transparent; leaves the destination unchanged.
|
||||
case clear
|
||||
/// Inverts the destination pixels.
|
||||
case xor
|
||||
/// An 8×8 two-color pattern.
|
||||
case pattern(Pattern)
|
||||
|
||||
/// Materializes the `LCDColor` for the duration of `body`. Pattern
|
||||
|
||||
@@ -3,13 +3,21 @@ internal import CPlaydate
|
||||
extension Graphics {
|
||||
/// How source pixels combine with the destination when drawing.
|
||||
public enum DrawMode: UInt32, Sendable {
|
||||
/// Source pixels replace the destination.
|
||||
case copy = 0
|
||||
/// White source pixels are treated as transparent.
|
||||
case whiteTransparent = 1
|
||||
/// Black source pixels are treated as transparent.
|
||||
case blackTransparent = 2
|
||||
/// Opaque source pixels draw white.
|
||||
case fillWhite = 3
|
||||
/// Opaque source pixels draw black.
|
||||
case fillBlack = 4
|
||||
/// Source pixels are XORed with the destination.
|
||||
case xor = 5
|
||||
/// The inverse of `xor`.
|
||||
case nxor = 6
|
||||
/// Source pixels draw inverted.
|
||||
case inverted = 7
|
||||
|
||||
init(_ mode: LCDBitmapDrawMode) { self = DrawMode(rawValue: UInt32(mode.rawValue)) ?? .copy }
|
||||
|
||||
@@ -3,6 +3,7 @@ internal import CPlaydate
|
||||
/// The graphics API: drawing, bitmaps, fonts, tilemaps, and video.
|
||||
public enum Graphics {}
|
||||
|
||||
/// The cached `playdate->graphics` C API table.
|
||||
var gfx: UnsafePointer<playdate_graphics> { Playdate.graphicsAPI.unsafelyUnwrapped }
|
||||
|
||||
extension Graphics {
|
||||
@@ -50,10 +51,12 @@ extension Graphics {
|
||||
gfx.pointee.setScreenClipRect.unsafelyUnwrapped(Int32(x), Int32(y), Int32(width), Int32(height))
|
||||
}
|
||||
|
||||
/// Clears the current clip rect.
|
||||
public static func clearClipRect() {
|
||||
gfx.pointee.clearClipRect.unsafelyUnwrapped()
|
||||
}
|
||||
|
||||
/// Sets the end cap style used by subsequent line drawing.
|
||||
public static func setLineCapStyle(_ style: LineCapStyle) {
|
||||
gfx.pointee.setLineCapStyle.unsafelyUnwrapped(style.cValue)
|
||||
}
|
||||
@@ -71,18 +74,21 @@ extension Graphics {
|
||||
gfx.pointee.pushContext.unsafelyUnwrapped(target?.pointer)
|
||||
}
|
||||
|
||||
/// Pops the top drawing context off the stack.
|
||||
public static func popContext() {
|
||||
gfx.pointee.popContext.unsafelyUnwrapped()
|
||||
}
|
||||
|
||||
// MARK: - Shapes
|
||||
|
||||
/// Draws a line from (x1, y1) to (x2, y2) with the given stroke width.
|
||||
public static func drawLine(x1: Int, y1: Int, x2: Int, y2: Int, width: Int, color: Color) {
|
||||
color.withLCDColor {
|
||||
gfx.pointee.drawLine.unsafelyUnwrapped(Int32(x1), Int32(y1), Int32(x2), Int32(y2), Int32(width), $0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Fills the triangle with vertices (x1, y1), (x2, y2), and (x3, y3).
|
||||
public static func fillTriangle(x1: Int, y1: Int, x2: Int, y2: Int, x3: Int, y3: Int, color: Color) {
|
||||
color.withLCDColor {
|
||||
gfx.pointee.fillTriangle.unsafelyUnwrapped(Int32(x1), Int32(y1), Int32(x2), Int32(y2),
|
||||
@@ -90,18 +96,22 @@ extension Graphics {
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws the outline of a rectangle, stroked inside its frame.
|
||||
public static func drawRect(x: Int, y: Int, width: Int, height: Int, color: Color) {
|
||||
color.withLCDColor {
|
||||
gfx.pointee.drawRect.unsafelyUnwrapped(Int32(x), Int32(y), Int32(width), Int32(height), $0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Fills the rectangle with `color`.
|
||||
public static func fillRect(x: Int, y: Int, width: Int, height: Int, color: Color) {
|
||||
color.withLCDColor {
|
||||
gfx.pointee.fillRect.unsafelyUnwrapped(Int32(x), Int32(y), Int32(width), Int32(height), $0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws the outline of a rectangle with rounded corners, stroked with
|
||||
/// `lineWidth`.
|
||||
public static func drawRoundRect(x: Int, y: Int, width: Int, height: Int, radius: Int,
|
||||
lineWidth: Int, color: Color) {
|
||||
color.withLCDColor {
|
||||
@@ -110,6 +120,7 @@ extension Graphics {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fills a rectangle with rounded corners.
|
||||
public static func fillRoundRect(x: Int, y: Int, width: Int, height: Int, radius: Int, color: Color) {
|
||||
color.withLCDColor {
|
||||
gfx.pointee.fillRoundRect.unsafelyUnwrapped(Int32(x), Int32(y), Int32(width), Int32(height),
|
||||
@@ -127,6 +138,8 @@ extension Graphics {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fills an ellipse inside the rect. If the angles differ, fills the
|
||||
/// wedge from `startAngle` to `endAngle` (clockwise degrees, 0 at top).
|
||||
public static func fillEllipse(x: Int, y: Int, width: Int, height: Int,
|
||||
startAngle: Float = 0, endAngle: Float = 0, color: Color) {
|
||||
color.withLCDColor {
|
||||
@@ -202,6 +215,7 @@ extension Graphics {
|
||||
gfx.pointee.setTextTracking.unsafelyUnwrapped(Int32(tracking))
|
||||
}
|
||||
|
||||
/// The extra space currently added between letters, in pixels.
|
||||
public static var textTracking: Int {
|
||||
Int(gfx.pointee.getTextTracking.unsafelyUnwrapped())
|
||||
}
|
||||
|
||||
@@ -2,10 +2,17 @@ extension Graphics.Bitmap {
|
||||
/// The bitmap's dimensions, row stride, and raw pixel/mask storage.
|
||||
/// The pointers are owned by the bitmap.
|
||||
public struct Data {
|
||||
/// The bitmap's width, in pixels.
|
||||
public let width: Int
|
||||
/// The bitmap's height, in pixels.
|
||||
public let height: Int
|
||||
/// The stride of one row of pixel data, in bytes.
|
||||
public let rowBytes: Int
|
||||
/// The bitmap's mask data, or `nil` if it has no mask. One bit per
|
||||
/// pixel; rows are `rowBytes` wide.
|
||||
public let mask: UnsafeMutablePointer<UInt8>?
|
||||
/// The bitmap's pixel data. One bit per pixel; rows are `rowBytes`
|
||||
/// wide.
|
||||
public let data: UnsafeMutablePointer<UInt8>?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ extension Graphics {
|
||||
public var top: Int
|
||||
public var bottom: Int
|
||||
|
||||
/// Creates a rect from its edges. `right` and `bottom` are not
|
||||
/// inclusive.
|
||||
public init(left: Int, right: Int, top: Int, bottom: Int) {
|
||||
self.left = left
|
||||
self.right = right
|
||||
@@ -16,6 +18,7 @@ extension Graphics {
|
||||
self.bottom = bottom
|
||||
}
|
||||
|
||||
/// Creates a rect from an origin and size.
|
||||
public init(x: Int, y: Int, width: Int, height: Int) {
|
||||
self.init(left: x, right: x + width, top: y, bottom: y + height)
|
||||
}
|
||||
@@ -30,6 +33,7 @@ extension Graphics {
|
||||
top: Int32(top), bottom: Int32(bottom))
|
||||
}
|
||||
|
||||
/// Returns the rect offset by (dx, dy).
|
||||
public func translated(dx: Int, dy: Int) -> Rect {
|
||||
Rect(left: left + dx, right: right + dx, top: top + dy, bottom: bottom + dy)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
extension Graphics {
|
||||
/// An 8×8 two-color pattern: 8 rows of image data followed by 8 rows of mask.
|
||||
public struct Pattern: Sendable {
|
||||
/// The pattern's 8 rows of image data followed by 8 rows of mask,
|
||||
/// one byte per row.
|
||||
public var bytes: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
|
||||
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
|
||||
|
||||
/// Creates a pattern from 8 rows of image data and 8 rows of mask.
|
||||
public init(bytes: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
|
||||
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)) {
|
||||
self.bytes = bytes
|
||||
|
||||
Reference in New Issue
Block a user