Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SpinnerButton.cs « Custom « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2b82a62e535023e5be15b0b8b00aad41a2c3f3b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using AppKit;
using CoreGraphics;
using ObjCRuntime;

namespace Xamarin.PropertyEditing.Mac
{
	internal class SpinnerButton
		: UnfocusableButton
	{
		public bool AcceptsUserInteraction { get; set; } = true;

		public override NSView HitTest (CGPoint aPoint)
		{
			if (!AcceptsUserInteraction) {
				return null;
			}

			return base.HitTest (aPoint);
		}

		public SpinnerButton (IHostResourceProvider hostResource, bool isUp)
		{
			if (hostResource == null)
				throw new ArgumentNullException (nameof (hostResource));

			this.hostResources = hostResource;
			this.imageBase += (isUp) ? "up" : "down";

			AppearanceChanged ();
		}

		public override void MouseExited (NSEvent theEvent)
		{
			this.isMouseOver = false;
			UpdateImage ();
		}

		public override void MouseEntered (NSEvent theEvent)
		{
			this.isMouseOver = true;
			UpdateImage ();
		}

		public sealed override void ViewDidChangeEffectiveAppearance ()
		{
			base.ViewDidChangeEffectiveAppearance ();

			AppearanceChanged ();
		}

		private void AppearanceChanged ()
		{
			this.image = this.hostResources.GetNamedImage (this.imageBase);
			this.mouseOverImage = this.hostResources.GetNamedImage (this.imageBase + "-focus-blue");

			UpdateImage ();
		}

		private readonly IHostResourceProvider hostResources;
		private bool isMouseOver;
		private string imageBase = "pe-stepper-";

		private NSImage image;
		private NSImage mouseOverImage;

		private void UpdateImage ()
		{
			Image = Enabled ? (this.isMouseOver) ? this.mouseOverImage : this.image : this.image;
		}
	}
}