private void OnMouseHover(bool isHover) { NSColor requiredColor = (isHover) ? __PauseLeftTimeText.TextColor = __PauseLeftTimeTextOrigColor.ColorWithAlphaComponent(0.5f) : __PauseLeftTimeTextOrigColor; if (!__PauseLeftTimeText.TextColor.Equals(requiredColor)) { __PauseLeftTimeText.TextColor = requiredColor; NeedsDisplay = true; } }
public override void UpdateLayer() { base.UpdateLayer(); if (image != null && imageLayer == null) { Layer.MasksToBounds = false; if (maskLayer == null) { maskLayer = CAShapeLayer.Create() as CAShapeLayer; Layer.AddSublayer(maskLayer); maskLayer.Path = CGPath.FromRoundedRect(Bounds, cornerRadius, cornerRadius); } imageLayer = CALayer.Create(); imageLayer.Mask = maskLayer; imageLayer.MasksToBounds = true; image.LockFocus(); imageLayer.Contents = image.CGImage; imageLayer.ContentsGravity = CALayer.GravityResizeAspectFill; image.UnlockFocus(); Layer.AddSublayer(imageLayer); } if (image == null) { imageLayer?.RemoveFromSuperLayer(); } if (overlayAlpha > 0 && overlayLayer == null) { overlayLayer = new CALayer(); overlayLayer.BackgroundColor = overlayColor.ColorWithAlphaComponent(overlayAlpha).CGColor; Layer.AddSublayer(overlayLayer); } if (overlayAlpha == 0 && overlayLayer != null) { overlayLayer.RemoveFromSuperLayer(); overlayLayer = null; } CATransaction.Begin(); CATransaction.DisableActions = true; if (imageLayer != null) { if (imageLayer.Bounds.Width != Bounds.Width) { imageLayer.Frame = Bounds; maskLayer.Path = CGPath.FromRoundedRect(Bounds, cornerRadius, cornerRadius); } } if (overlayLayer != null && overlayLayer.SuperLayer != null && overlayLayer.Frame != Bounds) { overlayLayer.Frame = Bounds; } CATransaction.Commit(); }