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

HostResourceProvider.cs « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7beea59f630d27bc7cc3cdd622cac3fff0baf084 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.IO;
using AppKit;
using Foundation;
using ObjCRuntime;

namespace Xamarin.PropertyEditing.Mac
{
	public class HostResourceProvider
		: IHostResourceProvider
	{
		public NSAppearance CurrentAppearance
		{
			get;
			set;
		}

		public HostResourceProvider ()
		{
			var bundlePath = NSBundle.MainBundle.PathForResource ("PropertyEditingResource", "bundle");
			if (!Directory.Exists (bundlePath))
			{
				//if the bundle resource directory is not in place we fallback into the assembly location
				var containingDir = Path.GetDirectoryName (typeof (HostResourceProvider).Assembly.Location);
				bundlePath = Path.Combine (containingDir, "PropertyEditingResource.bundle");
			}
			
			this.resourceBundle = new NSBundle (bundlePath);
		}

		public virtual NSAppearance GetVibrantAppearance (NSAppearance appearance)
		{
			if (appearance == null)
				throw new ArgumentNullException (nameof (appearance));

			if (appearance.Name == NSAppearance.NameDarkAqua || appearance.Name == NSAppearance.NameVibrantDark)
				return NSAppearance.GetAppearance (NSAppearance.NameVibrantDark);

			return NSAppearance.GetAppearance (NSAppearance.NameVibrantLight);
		}

		public virtual NSColor GetNamedColor (string name)
		{
			return NSColor.FromName (name);
		}

		public virtual NSImage GetNamedImage (string name)
		{
			NSAppearance currentAppearance = CurrentAppearance ?? NSAppearance.CurrentAppearance;
			if (currentAppearance != null && currentAppearance.Name.ToLower ().Contains ("dark")) {
				bool sel = name.EndsWith ("~sel");
				if (sel)
					name = name.Substring (0, name.Length - 4);

				name += "~dark";

				if (sel)
					name += "~sel";
			}

			return this.resourceBundle.ImageForResource (name);
		}

		public virtual NSFont GetNamedFont (string name, nfloat fontSize)
		{
			return NSFont.FromFontName (name, fontSize);
		}

		private readonly NSBundle resourceBundle;
	}

	public static class NamedResources
	{
		public const string Checkerboard0Color = "Checkerboard0";
		public const string Checkerboard1Color = "Checkerboard1";
		public const string ForegroundColor = "ForegroundColor";
		public const string PadBackgroundColor = "PadBackgroundColor";
		public const string DescriptionLabelColor = "DescriptionLabelColor";
		public const string ValueBlockBackgroundColor = "ValueBlockBackgroundColor";
		public const string TabBorderColor = "TabBorderColor";
		public const string FrameBoxBorderColor = "FrameBoxBorderColor";
		public const string FrameBoxBackgroundColor = "FrameBoxBackgroundColor";
		public const string FrameBoxButtonBorderColor = "FrameBoxButtonBorderColor";
		public const string FrameBoxButtonBackgroundColor = "FrameBoxButtonBackgroundColor";
		public const string ListHeaderSeparatorColor = "ListHeaderSeparatorColor";
		public const string PanelTabBackground = "PanelTabBackground";
		public const string ControlBackground = "ControlBackground";
	}
}