Implement DisplayNode drawing
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import SwiftUI
|
||||
|
||||
extension GraphicsContext {
|
||||
func draw(_ displayNode: Math.DisplayNode, size: CGSize, foregroundColor: Color) {
|
||||
var context = self
|
||||
|
||||
context.translateBy(x: 0, y: size.height)
|
||||
context.scaleBy(x: 1, y: -1)
|
||||
|
||||
let foregroundColor = foregroundColor.resolve(in: environment).cgColor
|
||||
|
||||
context.withCGContext { cgContext in
|
||||
cgContext.draw(displayNode, foregroundColor: foregroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
func draw(_ displayNode: Math.DisplayNode, size: CGSize, with shading: GraphicsContext.Shading) {
|
||||
var context = self
|
||||
|
||||
context.fill(Path(CGRect(origin: .zero, size: size)), with: shading)
|
||||
context.blendMode = .destinationIn
|
||||
|
||||
context.drawLayer {
|
||||
$0.draw(displayNode, size: size, foregroundColor: .black)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user