|
@@ -35,6 +35,76 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
open var keyEquivalentModifierMask: NSEvent.ModifierFlags = NSEvent.ModifierFlags()
|
|
|
|
|
|
// MARK: - 初始化
|
|
|
+ public override func draw(_ dirtyRect: NSRect) {
|
|
|
+ super.draw(dirtyRect)
|
|
|
+
|
|
|
+ var fillColor = properties.propertyInfo.color_nor
|
|
|
+ var borderWidth = properties.propertyInfo.borderWidth
|
|
|
+ var borderColor = properties.propertyInfo.borderColor_nor
|
|
|
+
|
|
|
+ if properties.state == .normal {
|
|
|
+
|
|
|
+ } else if properties.state == .hover {
|
|
|
+ fillColor = properties.propertyInfo.color_hov
|
|
|
+ borderWidth = properties.propertyInfo.borderWidth_hov
|
|
|
+ borderColor = properties.propertyInfo.borderColor_hov
|
|
|
+ } else if properties.state == .pressed {
|
|
|
+ fillColor = properties.propertyInfo.color_active
|
|
|
+ borderWidth = properties.propertyInfo.borderWidth_active
|
|
|
+ borderColor = properties.propertyInfo.borderColor_active
|
|
|
+ }
|
|
|
+ if properties.isDisabled == true {
|
|
|
+ fillColor = properties.propertyInfo.color_dis
|
|
|
+ borderWidth = properties.propertyInfo.borderWidth
|
|
|
+ borderColor = properties.propertyInfo.borderColor_dis
|
|
|
+ }
|
|
|
+
|
|
|
+ let cornerRadius_topLeft: CGFloat = properties.propertyInfo.cornerRadius_topLeft
|
|
|
+ let cornerRadius_topRight: CGFloat = properties.propertyInfo.cornerRadius_topRight
|
|
|
+ let cornerRadius_bottomLeft: CGFloat = properties.propertyInfo.cornerRadius_bottomLeft
|
|
|
+ let cornerRadius_bottomRight: CGFloat = properties.propertyInfo.cornerRadius_bottomRight
|
|
|
+
|
|
|
+ let drawBounds = bounds.insetBy(dx: 1, dy: 1)
|
|
|
+
|
|
|
+ let path = NSBezierPath()
|
|
|
+ path.lineWidth = borderWidth + 1
|
|
|
+
|
|
|
+ path.move(to: NSPoint(x: drawBounds.minX + cornerRadius_bottomLeft, y: drawBounds.minY))
|
|
|
+ if cornerRadius_bottomLeft > 0 {
|
|
|
+ path.appendArc(from: NSPoint(x: drawBounds.minX + cornerRadius_bottomLeft, y: drawBounds.minY), to: NSPoint(x: drawBounds.minX + cornerRadius_bottomLeft, y: drawBounds.minY), radius: cornerRadius_bottomLeft) //左下角
|
|
|
+ }
|
|
|
+
|
|
|
+ if cornerRadius_bottomRight > 0 {
|
|
|
+ path.appendArc(from: NSPoint(x: drawBounds.maxX, y: drawBounds.minY), to: NSPoint(x: drawBounds.maxX, y: drawBounds.minY + cornerRadius_bottomRight), radius: cornerRadius_bottomRight) //右下角
|
|
|
+ } else {
|
|
|
+ path.line(to: NSPoint(x: drawBounds.maxX, y: drawBounds.minY))
|
|
|
+ }
|
|
|
+
|
|
|
+ if cornerRadius_topRight > 0 {
|
|
|
+ path.appendArc(from: NSPoint(x: drawBounds.maxX, y: drawBounds.maxY), to: NSPoint(x: drawBounds.maxX - cornerRadius_topRight, y: drawBounds.maxY), radius: cornerRadius_topRight) // 右上角
|
|
|
+ } else {
|
|
|
+ path.line(to: NSPoint(x: drawBounds.maxX, y: drawBounds.maxY))
|
|
|
+ }
|
|
|
+
|
|
|
+ if cornerRadius_topLeft > 0 {
|
|
|
+ path.appendArc(from: NSPoint(x: drawBounds.minX, y: drawBounds.maxY), to: NSPoint(x: drawBounds.minX, y: drawBounds.maxY - cornerRadius_topLeft), radius: cornerRadius_topLeft) //左上角
|
|
|
+ } else {
|
|
|
+ path.line(to: NSPoint(x: drawBounds.minX, y: drawBounds.maxY))
|
|
|
+ }
|
|
|
+
|
|
|
+ if cornerRadius_bottomLeft > 0 {
|
|
|
+ path.appendArc(from: NSPoint(x: drawBounds.minX, y: drawBounds.minY), to: NSPoint(x: drawBounds.minX + cornerRadius_bottomLeft, y: drawBounds.minY), radius: cornerRadius_bottomLeft) //左下角
|
|
|
+ } else {
|
|
|
+ path.line(to: NSPoint(x: drawBounds.minX, y: drawBounds.minY))
|
|
|
+ }
|
|
|
+
|
|
|
+ borderColor.setStroke()
|
|
|
+ path.stroke()
|
|
|
+ path.close()
|
|
|
+ fillColor.setFill()
|
|
|
+ path.fill()
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
public required init?(coder decoder: NSCoder) {
|
|
|
super.init(coder: decoder)
|
|
@@ -47,8 +117,14 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
|
|
|
public override func awakeFromNib() {
|
|
|
super.awakeFromNib()
|
|
|
-
|
|
|
+
|
|
|
label.wantsLayer = true
|
|
|
+
|
|
|
+ contendBox.fillColor = NSColor.clear
|
|
|
+ contendBox.borderColor = NSColor.clear
|
|
|
+ contendBox.cornerRadius = 0
|
|
|
+ contendBox.borderWidth = 0
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -66,49 +142,39 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
reloadData()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
|
|
|
//MARK: - setupUI
|
|
|
|
|
|
func setupUI() {
|
|
|
- leftIcon.isHidden = true
|
|
|
- label.isHidden = true
|
|
|
- rightIcon.isHidden = true
|
|
|
+ leftIcon.isHidden = true
|
|
|
+ label.isHidden = true
|
|
|
+ rightIcon.isHidden = true
|
|
|
|
|
|
if properties.onlyIcon == true {
|
|
|
leftIcon.isHidden = false
|
|
|
} else {
|
|
|
- label.isHidden = false
|
|
|
+ label.isHidden = false
|
|
|
if properties.showLeftIcon == true &&
|
|
|
properties.showRightIcon == true {
|
|
|
-
|
|
|
- leftIcon.isHidden = false
|
|
|
- rightIcon.isHidden = false
|
|
|
-
|
|
|
+ leftIcon.isHidden = false
|
|
|
+ rightIcon.isHidden = false
|
|
|
} else if properties.showLeftIcon == true &&
|
|
|
properties.showRightIcon == false {
|
|
|
- leftIcon.isHidden = false
|
|
|
-
|
|
|
- } else if properties.showLeftIcon == false &&
|
|
|
+ leftIcon.isHidden = false
|
|
|
+ } else if properties.showLeftIcon == false &&
|
|
|
properties.showRightIcon == true {
|
|
|
rightIcon.isHidden = false
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func refreshUI() {
|
|
|
- var fillColor = properties.propertyInfo.color_nor
|
|
|
- var borderWidth = properties.propertyInfo.borderWidth
|
|
|
- var borderColor = properties.propertyInfo.borderColor_nor
|
|
|
|
|
|
var textColor = properties.propertyInfo.textColor
|
|
|
|
|
|
var leftImage = properties.icon
|
|
|
var rightImage = properties.icon
|
|
|
-
|
|
|
+
|
|
|
if properties.state == .normal {
|
|
|
if let image = properties.propertyInfo.leftIcon_nor {
|
|
|
leftImage = image
|
|
@@ -117,38 +183,49 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
rightImage = image
|
|
|
}
|
|
|
} else if properties.state == .hover {
|
|
|
- fillColor = properties.propertyInfo.color_hov
|
|
|
- borderWidth = properties.propertyInfo.borderWidth_hov
|
|
|
- borderColor = properties.propertyInfo.borderColor_hov
|
|
|
textColor = properties.propertyInfo.textColor_hov
|
|
|
-
|
|
|
if let image = properties.propertyInfo.leftIcon_hov {
|
|
|
leftImage = image
|
|
|
+ } else {
|
|
|
+ if let image = properties.propertyInfo.leftIcon_nor?.filled(with: textColor) {
|
|
|
+ leftImage = image
|
|
|
+ } else if let image = properties.icon?.filled(with: textColor) {
|
|
|
+ leftImage = image
|
|
|
+ }
|
|
|
}
|
|
|
if let image = properties.propertyInfo.rightIcon_hov {
|
|
|
rightImage = image
|
|
|
+ } else {
|
|
|
+ if let image = properties.propertyInfo.rightIcon_nor?.filled(with: textColor) {
|
|
|
+ rightImage = image
|
|
|
+ } else if let image = properties.icon?.filled(with: textColor) {
|
|
|
+ rightImage = image
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
} else if properties.state == .pressed {
|
|
|
- fillColor = properties.propertyInfo.color_active
|
|
|
- borderWidth = properties.propertyInfo.borderWidth_active
|
|
|
- borderColor = properties.propertyInfo.borderColor_active
|
|
|
textColor = properties.propertyInfo.textColor_Active
|
|
|
-
|
|
|
if let image = properties.propertyInfo.leftIcon_press {
|
|
|
leftImage = image
|
|
|
+ } else {
|
|
|
+ if let image = properties.propertyInfo.leftIcon_nor?.filled(with: textColor) {
|
|
|
+ leftImage = image
|
|
|
+ } else if let image = properties.icon?.filled(with: textColor) {
|
|
|
+ leftImage = image
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if let image = properties.propertyInfo.rightIcon_press {
|
|
|
rightImage = image
|
|
|
+ } else {
|
|
|
+ if let image = properties.propertyInfo.rightIcon_nor?.filled(with: textColor) {
|
|
|
+ rightImage = image
|
|
|
+ } else if let image = properties.icon?.filled(with: textColor) {
|
|
|
+ rightImage = image
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if properties.isDisabled == true {
|
|
|
- fillColor = properties.propertyInfo.color_dis
|
|
|
- borderWidth = properties.propertyInfo.borderWidth
|
|
|
- borderColor = properties.propertyInfo.borderColor_dis
|
|
|
textColor = properties.propertyInfo.textColor_dis
|
|
|
-
|
|
|
if let image = properties.propertyInfo.leftIcon_dis {
|
|
|
leftImage = image
|
|
|
} else {
|
|
@@ -160,18 +237,17 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
}
|
|
|
if let image = properties.propertyInfo.rightIcon_dis {
|
|
|
rightImage = image
|
|
|
+ } else {
|
|
|
+ if let image = properties.propertyInfo.rightIcon_nor?.filled(with: textColor) {
|
|
|
+ rightImage = image
|
|
|
+ } else if let image = properties.icon?.filled(with: textColor) {
|
|
|
+ rightImage = image
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- contendBox.fillColor = fillColor
|
|
|
- contendBox.borderColor = borderColor
|
|
|
- contendBox.cornerRadius = properties.propertyInfo.cornerRadius
|
|
|
- contendBox.borderWidth = borderWidth
|
|
|
-
|
|
|
label.textColor = textColor
|
|
|
-
|
|
|
label.font = properties.propertyInfo.textFont
|
|
|
-
|
|
|
+
|
|
|
if let image = leftImage {
|
|
|
leftIcon.image = image
|
|
|
}
|
|
@@ -238,17 +314,16 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
}
|
|
|
leftIcon.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
|
|
|
|
|
|
+ display()
|
|
|
}
|
|
|
|
|
|
public func reloadData() {
|
|
|
DispatchQueue.main.async {
|
|
|
-
|
|
|
self.setupUI()
|
|
|
|
|
|
self.refreshUI()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
|
|
|
//MARK: - Public Method
|
|
|
|
|
@@ -285,8 +360,7 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
|
|
|
public override func mouseMoved(with event: NSEvent) {
|
|
|
super.mouseMoved(with: event)
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public override func mouseExited(with event: NSEvent) {
|
|
@@ -315,7 +389,6 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
if properties.isDisabled == false {
|
|
|
if properties.keepPressState == false {
|
|
|
properties.state = .hover
|
|
|
-
|
|
|
refreshUI()
|
|
|
}
|
|
|
window?.makeFirstResponder(self)
|