123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // KMGuideTargetView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2024/6/25.
- //
- import Cocoa
- class KMGuideTargetView: NSView {
- var lineWidth: CGFloat = 2 {
- didSet {
- self.needsDisplay = true
- }
- }
- var strokeColor: NSColor = .black {
- didSet {
- self.needsDisplay = true
- }
- }
-
- var insets: NSEdgeInsets = .init(top: 0, left: 0, bottom: 0, right: 0) {
- didSet {
- self.needsDisplay = true
- }
- }
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
-
- let rect = self.bounds
- let left = self.insets.left
- let top = self.insets.top
- let drawW = max(NSWidth(rect)-left-self.insets.right, 0)
- let drawH = max(NSHeight(rect)-top-self.insets.bottom, 0)
- let drawRect = NSMakeRect(left, top, drawW, drawH)
-
- let context = NSGraphicsContext.current?.cgContext
- context?.saveGState()
- context?.setLineWidth(self.lineWidth)
- context?.setStrokeColor(self.strokeColor.cgColor)
- let dxy = self.lineWidth * 0.5
- let outRect = drawRect.insetBy(dx: dxy, dy: dxy)
- context?.addEllipse(in: outRect)
- let offset: CGFloat = 4
- let inRect = outRect.insetBy(dx: dxy+offset, dy: dxy+offset)
- context?.addEllipse(in: inRect)
- context?.strokePath()
- context?.restoreGState()
- }
- }
|