Restructured the source code in the Playdate bindings target.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
extension Graphics.Bitmap {
|
||||
/// The bitmap's dimensions, row stride, and raw pixel/mask storage.
|
||||
/// The pointers are owned by the bitmap.
|
||||
public struct Data {
|
||||
public let width: Int
|
||||
public let height: Int
|
||||
public let rowBytes: Int
|
||||
public let mask: UnsafeMutablePointer<UInt8>?
|
||||
public let data: UnsafeMutablePointer<UInt8>?
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
internal import CPlaydate
|
||||
|
||||
extension Graphics {
|
||||
/// A page of glyphs within a font. Wraps `LCDFontPage`.
|
||||
/// Keep the font alive while using its pages.
|
||||
public struct FontPage {
|
||||
let pointer: OpaquePointer
|
||||
let font: Font
|
||||
|
||||
/// The glyph for `codepoint` within this page, with its bitmap and advance.
|
||||
public func glyph(for codepoint: UInt32) -> (glyph: Glyph, bitmap: Bitmap?, advance: Int)? {
|
||||
var bitmap: OpaquePointer?
|
||||
var advance: Int32 = 0
|
||||
guard let glyph = gfx.pointee.getPageGlyph.unsafelyUnwrapped(pointer, codepoint, &bitmap, &advance) else {
|
||||
return nil
|
||||
}
|
||||
return (Glyph(pointer: glyph, font: font),
|
||||
bitmap.map { Bitmap(pointer: $0, isOwned: false) },
|
||||
Int(advance))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
internal import CPlaydate
|
||||
|
||||
extension Graphics {
|
||||
/// A single glyph within a font. Wraps `LCDFontGlyph`.
|
||||
/// Keep the font alive while using its glyphs.
|
||||
public struct Glyph {
|
||||
let pointer: OpaquePointer
|
||||
let font: Font
|
||||
|
||||
/// The kerning adjustment between this glyph and the next character.
|
||||
public func kerning(glyphCode: UInt32, nextCode: UInt32) -> Int {
|
||||
Int(gfx.pointee.getGlyphKerning.unsafelyUnwrapped(pointer, glyphCode, nextCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
internal import CPlaydate
|
||||
|
||||
extension Graphics {
|
||||
/// An integer rectangle mirroring `LCDRect`. `right` and `bottom` are
|
||||
/// not inclusive.
|
||||
public struct Rect: Sendable {
|
||||
public var left: Int
|
||||
public var right: Int
|
||||
public var top: Int
|
||||
public var bottom: Int
|
||||
|
||||
public init(left: Int, right: Int, top: Int, bottom: Int) {
|
||||
self.left = left
|
||||
self.right = right
|
||||
self.top = top
|
||||
self.bottom = bottom
|
||||
}
|
||||
|
||||
public init(x: Int, y: Int, width: Int, height: Int) {
|
||||
self.init(left: x, right: x + width, top: y, bottom: y + height)
|
||||
}
|
||||
|
||||
init(_ rect: LCDRect) {
|
||||
self.init(left: Int(rect.left), right: Int(rect.right),
|
||||
top: Int(rect.top), bottom: Int(rect.bottom))
|
||||
}
|
||||
|
||||
var cValue: LCDRect {
|
||||
LCDRect(left: Int32(left), right: Int32(right),
|
||||
top: Int32(top), bottom: Int32(bottom))
|
||||
}
|
||||
|
||||
public func translated(dx: Int, dy: Int) -> Rect {
|
||||
Rect(left: left + dx, right: right + dx, top: top + dy, bottom: bottom + dy)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
extension Graphics {
|
||||
/// An 8×8 two-color pattern: 8 rows of image data followed by 8 rows of mask.
|
||||
public struct Pattern: Sendable {
|
||||
public var bytes: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
|
||||
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
|
||||
|
||||
public init(bytes: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
|
||||
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)) {
|
||||
self.bytes = bytes
|
||||
}
|
||||
|
||||
/// Creates an opaque pattern from 8 rows of image data.
|
||||
public init(rows r: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)) {
|
||||
bytes = (r.0, r.1, r.2, r.3, r.4, r.5, r.6, r.7,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user