34 lines
897 B
Swift
34 lines
897 B
Swift
//
|
|
// ImageBackgroundView.swift
|
|
// PrivadoVPN
|
|
//
|
|
// Created by Murad Shabanov on 01.03.2022.
|
|
// Copyright © 2022 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
final class ImageBackgroundView: View {
|
|
|
|
public var hoverColor: NSColor?
|
|
|
|
override func onMouseHover(_ hover: Bool) {
|
|
guard let color = self.hoverColor else {
|
|
return
|
|
}
|
|
self.viewBackgroundColor = hover ? color : .clear
|
|
}
|
|
|
|
override func updateTrackingAreas() {
|
|
super.updateTrackingAreas()
|
|
|
|
for trackingArea in self.trackingAreas {
|
|
self.removeTrackingArea(trackingArea)
|
|
}
|
|
|
|
let options: NSTrackingArea.Options = [.mouseEnteredAndExited, .activeAlways]
|
|
let trackingArea = NSTrackingArea(rect: self.bounds, options: options, owner: self, userInfo: nil)
|
|
self.addTrackingArea(trackingArea)
|
|
}
|
|
}
|