Fixed bugs found for the bitmap mask, JSON reader and wifi wrappers in the library.
This commit is contained in:
@@ -2,15 +2,18 @@ internal import CPlaydate
|
||||
|
||||
extension Graphics {
|
||||
/// A drawable image and drawing target. Wraps `LCDBitmap`. Bitmaps borrowed from
|
||||
/// tables, fonts, masks, video players, or the system live only as long as their owner.
|
||||
/// tables, fonts, video players, or the system live only as long as their owner.
|
||||
public final class Bitmap {
|
||||
let pointer: OpaquePointer
|
||||
/// Whether deinit frees the `LCDBitmap`.
|
||||
let isOwned: Bool
|
||||
/// Kept alive because this bitmap shares its pixels.
|
||||
private let owner: Bitmap?
|
||||
|
||||
init(pointer: OpaquePointer, isOwned: Bool) {
|
||||
init(pointer: OpaquePointer, isOwned: Bool, owner: Bitmap? = nil) {
|
||||
self.pointer = pointer
|
||||
self.isOwned = isOwned
|
||||
self.owner = owner
|
||||
}
|
||||
|
||||
public convenience init(width: Int, height: Int, backgroundColor: Color = .clear) {
|
||||
@@ -126,10 +129,11 @@ extension Graphics {
|
||||
gfx.pointee.setBitmapMask.unsafelyUnwrapped(pointer, mask?.pointer) != 0
|
||||
}
|
||||
|
||||
/// Shares this bitmap's mask data: drawing into it edits the mask.
|
||||
/// Shares this bitmap's mask data, and keeps this bitmap alive.
|
||||
public var mask: Bitmap? {
|
||||
// Owned by the caller; pixels are shared with `self`.
|
||||
guard let mask = gfx.pointee.getBitmapMask.unsafelyUnwrapped(pointer) else { return nil }
|
||||
return Bitmap(pointer: mask, isOwned: false)
|
||||
return Bitmap(pointer: mask, isOwned: true, owner: self)
|
||||
}
|
||||
|
||||
/// Whether opaque pixels of both bitmaps overlap within the non-empty `rect`.
|
||||
|
||||
Reference in New Issue
Block a user