Skip to content

Commit dcb675a

Browse files
committed
Support clearing of drawings in library (lispkit draw).
1 parent 23d27cf commit dcb675a

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

Sources/LispKit/Graphics/Drawing.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public final class Drawing: NativeObject {
5454
/// Appends a new drawing instruction.
5555
@discardableResult public func append(_ instruction: DrawingInstruction) -> Bool {
5656
switch instruction {
57+
// Do not allow recursive dependencies
5758
case .inline(let drawing), .include(let drawing, _):
5859
if drawing.includes(self) {
5960
return false
@@ -65,6 +66,11 @@ public final class Drawing: NativeObject {
6566
return true
6667
}
6768

69+
/// Clears all drawing instructions
70+
public func clear() {
71+
self.instructions.removeAll()
72+
}
73+
6874
/// Draws the drawing to the current graphics context clipped to a given shape. The drawing is
6975
/// put into a new transparency layer. Upon exit, the previous graphics state is being
7076
/// restored.

Sources/LispKit/Graphics/Drawing_iOS.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public final class Drawing: NativeObject {
5656
/// Appends a new drawing instruction.
5757
@discardableResult public func append(_ instruction: DrawingInstruction) -> Bool {
5858
switch instruction {
59+
// Do not allow recursive dependencies
5960
case .inline(let drawing), .include(let drawing, _):
6061
if drawing.includes(self) {
6162
return false
@@ -67,6 +68,11 @@ public final class Drawing: NativeObject {
6768
return true
6869
}
6970

71+
/// Clears all drawing instructions
72+
public func clear() {
73+
self.instructions.removeAll()
74+
}
75+
7076
/// Draws the drawing to the current graphics context clipped to a given shape. The drawing is
7177
/// put into a new transparency layer. Upon exit, the previous graphics state is being
7278
/// restored.

Sources/LispKit/Graphics/Shape.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public final class Shape: NativeObject {
143143
@discardableResult public func append(_ constructor: ShapeConstructor) -> Bool {
144144
if case .include(let other) = constructor {
145145
other.owners.compact()
146+
// Do not allow recursive dependencies
146147
if other.includes(self) {
147148
return false
148149
}

Sources/LispKit/Primitives/DrawingLibrary.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public final class DrawingLibrary: NativeLibrary {
119119
self.define(Procedure("drawing?", isDrawing))
120120
self.define(Procedure("make-drawing", makeDrawing))
121121
self.define(Procedure("copy-drawing", copyDrawing))
122+
self.define(Procedure("clear-drawing", clearDrawing))
122123
self.define(Procedure("set-color", setColor))
123124
self.define(Procedure("set-fill-color", setFillColor))
124125
self.define(Procedure("set-line-width", setLineWidth))
@@ -406,6 +407,11 @@ public final class DrawingLibrary: NativeLibrary {
406407
return .object(Drawing(copy: try self.drawing(from: drawing)))
407408
}
408409

410+
private func clearDrawing(drawing: Expr) throws -> Expr {
411+
try self.drawing(from: drawing).clear()
412+
return .void
413+
}
414+
409415
private func setColor(color: Expr, drawing: Expr?) throws -> Expr {
410416
try self.drawing(from: drawing).append(.setStrokeColor(try self.color(from: color)))
411417
return .void

Sources/LispKit/Primitives/DrawingLibrary_iOS.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public final class DrawingLibrary: NativeLibrary {
115115
self.define(Procedure("drawing?", isDrawing))
116116
self.define(Procedure("make-drawing", makeDrawing))
117117
self.define(Procedure("copy-drawing", copyDrawing))
118+
self.define(Procedure("clear-drawing", clearDrawing))
118119
self.define(Procedure("set-color", setColor))
119120
self.define(Procedure("set-fill-color", setFillColor))
120121
self.define(Procedure("set-line-width", setLineWidth))
@@ -385,6 +386,11 @@ public final class DrawingLibrary: NativeLibrary {
385386
return .object(Drawing(copy: try self.drawing(from: drawing)))
386387
}
387388

389+
private func clearDrawing(drawing: Expr) throws -> Expr {
390+
try self.drawing(from: drawing).clear()
391+
return .void
392+
}
393+
388394
private func setColor(color: Expr, drawing: Expr?) throws -> Expr {
389395
try self.drawing(from: drawing).append(.setStrokeColor(try self.color(from: color)))
390396
return .void

Sources/LispKitRepl/AppInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public struct AppInfo {
4545
public static let buildDate = { () -> String in
4646
let dateFormatter = DateFormatter()
4747
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
48-
return dateFormatter.string(from: Date(timeIntervalSince1970: 1699655433))
48+
return dateFormatter.string(from: Date(timeIntervalSince1970: 1700948712))
4949
}()
5050
public static let buildAnnotation = " (\(AppInfo.buildDate))"
5151
}

0 commit comments

Comments
 (0)