123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- //
- // KMCustomTableRowView.swift
- // PDF Reader Pro
- //
- // Created by lxy on 2022/11/7.
- //
- import Cocoa
- class KMCustomTableRowView: NSTableRowView {
- var highlightColor : NSColor!
- var selectionColor : NSColor!
- var isHaveRadius = false
- var color : NSColor!
-
- // MARK - Draw
- override func drawBackground(in dirtyRect: NSRect) {
- if(self.color != nil) {
- self.color.setFill()
- if self.isHaveRadius == true {
- let selectionPath = NSBezierPath.init(roundedRect: dirtyRect, xRadius: 6.0, yRadius: 6.0)
- selectionPath.fill()
- } else {
- __NSRectFill(dirtyRect)
- }
- } else {
- super.drawBackground(in: dirtyRect)
- }
- }
-
- override func drawSelection(in dirtyRect: NSRect) {
- if self.selectionHighlightStyle == NSTableView.SelectionHighlightStyle.none {
- super.drawSelection(in: dirtyRect)
- } else {
- if(self.selectionColor != nil) {
- self.selectionColor.setFill()
- if self.isHaveRadius == true {
- let selectionPath = NSBezierPath.init(roundedRect: dirtyRect, xRadius: 6.0, yRadius: 6.0)
- selectionPath.fill()
- } else {
- __NSRectFill(dirtyRect)
- }
- } else {
- super.drawSelection(in: dirtyRect)
- }
- }
- }
-
- // MARK - Event
- private func addTrackingArea() {
- let opt = (NSTrackingArea.Options.mouseEnteredAndExited.rawValue | NSTrackingArea.Options.inVisibleRect.rawValue | NSTrackingArea.Options.activeInKeyWindow.rawValue)
- let trackingArea = NSTrackingArea.init(rect: self.bounds,options:NSTrackingArea.Options(rawValue: opt), owner: self, userInfo:nil)
- self.addTrackingArea(trackingArea)
- }
-
- override func mouseEntered(with event: NSEvent) {
- super.mouseEntered(with: event)
- self.color = self.highlightColor
- self.needsDisplay = false
- }
-
- override func mouseExited(with event: NSEvent) {
- super.mouseExited(with: event)
- self.color = NSColor()
- }
- }
|