/// <summary>
        /// Gets a <see cref="WatchedAsset{T}"/> which watches the specified asset. The <see cref="WatchedAsset{T}"/> which is returned
        /// is owned by the content manager and shared between all callers of this method. If the watched asset has not already been
        /// loaded, it will be loaded and added to the content manager's internal cache.
        /// </summary>
        /// <typeparam name="TOutput">The type of object being loaded.</typeparam>
        /// <param name="asset">The path to the asset to load.</param>
        /// <param name="density">The screen density for which to retrieve an asset watcher.</param>
        /// <returns>The <see cref="WatchedAsset{T}"/> instance which this content manager uses to watch the specified asset.</returns>
        public WatchedAsset <TOutput> GetSharedWatchedAsset <TOutput>(String asset, ScreenDensityBucket density)
        {
            Contract.RequireNotEmpty(asset, nameof(asset));
            Contract.EnsureNotDisposed(this, Disposed);

            return(GetSharedWatchedAssetInternal <TOutput>(asset, density));
        }
Exemple #2
0
        /// <summary>
        /// Adds the specified dependency to an asset. If the asset is being watched for changes, then any
        /// changes to the specified dependency will also cause the main asset to be reloaded.
        /// </summary>
        private Boolean AddAssetDependencyInternal(String asset, String dependency, ScreenDensityBucket density)
        {
            if (IsDependencyTrackingSuppressed)
            {
                return(false);
            }

            var dependencyAssetPath         = dependency;
            var dependencyAssetResolvedPath = ContentManager.ResolveAssetFilePath(dependencyAssetPath, density, true);
            var dependencyAssetFilePath     = Path.GetFullPath(dependencyAssetResolvedPath);

            lock (ContentManager.AssetCache.SyncObject)
            {
                if (assetDependencies == null)
                {
                    assetDependencies = new Dictionary <String, IAssetDependencyCollection>();
                }

                assetDependencies.TryGetValue(dependencyAssetFilePath, out var dependents);

                if (dependents == null)
                {
                    dependents = new AssetDependencyCollection(ContentManager, dependencyAssetPath, dependencyAssetFilePath);
                    assetDependencies[dependencyAssetFilePath] = dependents;
                }

                dependents.DependentAssets.Add(asset);
            }

            return(true);
        }
        /// <summary>
        /// Adds a watcher for the specified asset.
        /// </summary>
        /// <param name="asset">The asset path of the asset for which to add a watcher.</param>
        /// <param name="density">The density bucket corresponding to the version of the asset to watch.</param>
        /// <param name="watcher">The watcher to add for the specified asset.</param>
        /// <returns><see langword="true"/> if the watcher was added; otherwise, <see langword="false"/>.</returns>
        public Boolean AddWatcher <TOutput>(String asset, ScreenDensityBucket density, AssetWatcher <TOutput> watcher)
        {
            Contract.Require(asset, nameof(asset));
            Contract.Require(watcher, nameof(watcher));

            return(AddWatcherInternal(asset, density, watcher));
        }
        /// <summary>
        /// Gets the short name of the specified density bucket.
        /// </summary>
        /// <param name="bucket">The <see cref="ScreenDensityBucket"/> value for which to retrieve a short name.</param>
        /// <returns>The short name of the specified density bucket.</returns>
        public static String GetDensityBucketName(ScreenDensityBucket bucket)
        {
            switch (bucket)
            {
            case ScreenDensityBucket.Desktop:
                return("pcdpi");

            case ScreenDensityBucket.Low:
                return("ldpi");

            case ScreenDensityBucket.Retina:
                return("retina");

            case ScreenDensityBucket.Medium:
                return("mdpi");

            case ScreenDensityBucket.RetinaHD:
                return("retinahd");

            case ScreenDensityBucket.High:
                return("hdpi");

            case ScreenDensityBucket.ExtraHigh:
                return("xhdpi");

            case ScreenDensityBucket.ExtraExtraHigh:
                return("xxhdpi");

            case ScreenDensityBucket.ExtraExtraExtraHigh:
                return("xxxhdpi");
            }
            throw new ArgumentException("bucket");
        }
Exemple #5
0
        /// <summary>
        /// Finds the best set of DPI values to use when loading the font for the specified density bucket.
        /// </summary>
        private static void GetBestScreenDensityMatch(UltravioletContext uv, ScreenDensityBucket bucket, out Single dpiX, out Single dpiY)
        {
            dpiX = 96f;
            dpiY = 96f;

            var bestMatchFound = false;
            var bestMatchScale = Single.MaxValue;

            foreach (var display in uv.GetPlatform().Displays)
            {
                if (display.DensityBucket == bucket)
                {
                    if (display.DensityScale < bestMatchScale)
                    {
                        bestMatchFound = true;
                        bestMatchScale = display.DensityScale;
                        dpiX           = display.DpiX;
                        dpiY           = display.DpiY;
                    }
                }
            }

            if (bestMatchFound)
            {
                return;
            }

            dpiX = dpiY = ScreenDensityService.GuessDensityFromBucket(bucket);
        }
        /// <summary>
        /// Adds a watcher to the specified asset.
        /// </summary>
        private Boolean AddWatcherInternal <TOutput>(String asset, ScreenDensityBucket density, AssetWatcher <TOutput> watcher)
        {
            lock (ContentManager.AssetCache.SyncObject)
            {
                if (CreateFileSystemWatchers())
                {
                    if (assetWatchers == null)
                    {
                        assetWatchers = new Dictionary <String, IAssetWatcherCollection>();
                    }

                    var assetPath         = asset;
                    var assetResolvedPath = ContentManager.ResolveAssetFilePath(assetPath, density, true);
                    var assetFilePath     = Path.GetFullPath(assetResolvedPath);

                    if (!assetWatchers.TryGetValue(assetFilePath, out var list))
                    {
                        list = new AssetWatcherCollection <TOutput>(ContentManager, assetPath, assetFilePath);
                        assetWatchers[assetFilePath] = list;
                    }

                    list.Add(watcher);

                    return(true);
                }

                return(false);
            }
        }
Exemple #7
0
        /// <summary>
        /// Returns a probable DPI value which matches the specified density bucket.
        /// </summary>
        /// <param name="bucket">The density bucket to evaluate.</param>
        /// <returns>A probable DPI value which matches the specified density bucket.</returns>
        public static Single GuessDensityFromBucket(ScreenDensityBucket bucket)
        {
            switch (bucket)
            {
            case ScreenDensityBucket.Low:
                return(120f);

            case ScreenDensityBucket.Retina:
                return(220f);

            case ScreenDensityBucket.Medium:
                return(144f);

            case ScreenDensityBucket.RetinaHD:
                return(330f);

            case ScreenDensityBucket.High:
                return(240f);

            case ScreenDensityBucket.ExtraHigh:
                return(288f);

            case ScreenDensityBucket.ExtraExtraHigh:
                return(480f);

            case ScreenDensityBucket.ExtraExtraExtraHigh:
                return(576f);

            default:
                return(96f);
            }
        }
 /// <summary>
 /// Gets the short name of the specified density bucket.
 /// </summary>
 /// <param name="bucket">The <see cref="ScreenDensityBucket"/> value for which to retrieve a short name.</param>
 /// <returns>The short name of the specified density bucket.</returns>
 public static String GetDensityBucketName(ScreenDensityBucket bucket)
 {
     switch (bucket)
     {
         case ScreenDensityBucket.Desktop:
             return "pcdpi";
         case ScreenDensityBucket.Low:
             return "ldpi";
         case ScreenDensityBucket.Retina:
             return "retina";
         case ScreenDensityBucket.Medium:
             return "mdpi";
         case ScreenDensityBucket.RetinaHD:
             return "retinahd";
         case ScreenDensityBucket.High:
             return "hdpi";
         case ScreenDensityBucket.ExtraHigh:
             return "xhdpi";
         case ScreenDensityBucket.ExtraExtraHigh:
             return "xxhdpi";
         case ScreenDensityBucket.ExtraExtraExtraHigh:
             return "xxxhdpi";
     }
     throw new ArgumentException("bucket");
 }
Exemple #9
0
        /// <summary>
        /// Gets the version of the asset associated with the specified <see cref="ScreenDensityBucket"/> value,
        /// if there is an asset version for that value.
        /// </summary>
        /// <param name="assetDensityBucket">The <see cref="ScreenDensityBucket"/> value for which to retrieve an asset instance.</param>
        /// <param name="asset">The asset version associated with the specified <see cref="ScreenDensityBucket"/> value.</param>
        /// <returns><see langword="true"/> if an asset was retrieved; otherwise, <see langword="false"/>.</returns>
        public Boolean GetVersion(ScreenDensityBucket assetDensityBucket, out Object asset)
        {
            if (obj is AssetCacheVersion acv)
            {
                if (acv.AssetDensityBucket == assetDensityBucket)
                {
                    asset = acv.AssetInstance;
                    return(true);
                }

                asset = null;
                return(false);
            }
            else
            {
                var dictionary = (Dictionary <Byte, AssetCacheVersion>)obj;

                if (dictionary.TryGetValue((Byte)assetDensityBucket, out var version))
                {
                    asset = version.AssetInstance;
                    return(true);
                }

                asset = null;
                return(false);
            }
        }
Exemple #10
0
        /// <summary>
        /// Sets the version of the asset associated with the specified <see cref="ScreenDensityBucket"/> value.
        /// </summary>
        /// <param name="assetDensityBucket">The density bucket associated with this asset.</param>
        /// <param name="assetOrigin">The origin path of the asset.</param>
        /// <param name="assetInstance">The asset instance.</param>
        /// <returns><see langword="true"/> if the asset was set; otherwise, <see langword="false"/>.</returns>
        public Boolean SetVersion(ScreenDensityBucket assetDensityBucket, String assetOrigin, Object assetInstance)
        {
            var dictionary = default(Dictionary <Byte, AssetCacheVersion>);

            if (obj is AssetCacheVersion acv)
            {
                if (acv.AssetDensityBucket == assetDensityBucket)
                {
                    return(false);
                }

                dictionary = new Dictionary <Byte, AssetCacheVersion>();
                dictionary[(Byte)acv.AssetDensityBucket] = acv;
                obj = dictionary;
            }
            else
            {
                dictionary = (Dictionary <Byte, AssetCacheVersion>)obj;
            }

            if (dictionary.ContainsKey((Byte)assetDensityBucket))
            {
                return(false);
            }

            dictionary[(Byte)assetDensityBucket] = new AssetCacheVersion(assetDensityBucket, assetOrigin, assetInstance);
            return(true);
        }
Exemple #11
0
        /// <summary>
        /// Gets a value indicating whether the specified asset is registered as a dependency of another asset.
        /// </summary>
        /// <param name="asset">The asset identifier of the main asset to evaluate.</param>
        /// <param name="dependency">The file path of the dependency asset to evaluate.</param>
        /// <param name="density">The screen density for which to query dependency relationships.</param>
        /// <returns><see langword="true"/> if <paramref name="dependency"/> is a dependency of <paramref name="asset"/>; otherwise, <see langword="false"/>.</returns>
        public Boolean IsAssetDependencyPath(AssetID asset, String dependency, ScreenDensityBucket density)
        {
            Contract.Ensure <ArgumentException>(asset.IsValid, nameof(asset));
            Contract.Require(dependency, nameof(dependency));
            Contract.EnsureNotDisposed(this, Disposed);

            return(IsAssetDependencyPathInternal(AssetID.GetAssetPath(asset), dependency, density));
        }
Exemple #12
0
        /// <summary>
        /// Gets a value indicating whether the specified file path is registered as a dependency of another asset.
        /// </summary>
        /// <param name="asset">The asset path of the main asset to evaluate.</param>
        /// <param name="dependency">The file path of the dependency asset to evaluate.</param>
        /// <param name="density">The screen density for which to query dependency relationships.</param>
        /// <returns><see langword="true"/> if <paramref name="dependency"/> is a dependency of <paramref name="asset"/>; otherwise, <see langword="false"/>.</returns>
        public Boolean IsAssetDependencyPath(String asset, String dependency, ScreenDensityBucket density)
        {
            Contract.Require(asset, nameof(asset));
            Contract.Require(dependency, nameof(dependency));
            Contract.EnsureNotDisposed(this, Disposed);

            return(IsAssetDependencyPathInternal(asset, dependency, density));
        }
Exemple #13
0
        /// <summary>
        /// Adds the specified dependency to an asset. If the asset is being watched for changes, then any
        /// changes to the specified dependency will also cause the main asset to be reloaded.
        /// </summary>
        /// <param name="asset">The asset identifier of the asset for which to add a dependency.</param>
        /// <param name="dependency">The asset identifier of the dependency to add to the specified asset.</param>
        /// <param name="density">The screen density of the assets for which to add a dependency.</param>
        public void AddAssetDependency(AssetID asset, AssetID dependency, ScreenDensityBucket density)
        {
            Contract.Ensure <ArgumentException>(asset.IsValid, nameof(asset));
            Contract.Ensure <ArgumentException>(dependency.IsValid, nameof(dependency));
            Contract.EnsureNotDisposed(this, Disposed);

            AddAssetDependencyInternal(AssetID.GetAssetPath(asset), AssetID.GetAssetPath(dependency), density);
        }
Exemple #14
0
        /// <summary>
        /// Adds the specified dependency to an asset. If the asset is being watched for changes, then any
        /// changes to the specified dependency will also cause the main asset to be reloaded.
        /// </summary>
        /// <param name="asset">The asset path of the asset for which to add a dependency.</param>
        /// <param name="dependency">The asset path of the dependency to add to the specified asset.</param>
        /// <param name="density">The screen density of the assets for which to add a dependency.</param>
        public void AddAssetDependency(String asset, String dependency, ScreenDensityBucket density)
        {
            Contract.Require(asset, nameof(asset));
            Contract.Require(dependency, nameof(dependency));
            Contract.EnsureNotDisposed(this, Disposed);

            AddAssetDependencyInternal(asset, dependency, density);
        }
        /// <summary>
        /// Loads the resource from the specified content manager.
        /// </summary>
        /// <param name="content">The <see cref="ContentManager"/> with which to load the resource.</param>
        /// <param name="asset">The asset identifier that identifies the resource to load.</param>
        /// <param name="density">The screen density for which to load the resource.</param>
        public void Load(ContentManager content, AssetID asset, ScreenDensityBucket density)
        {
            Contract.Require(content, nameof(content));

            var watch = content.Ultraviolet.GetUI().WatchingViewFilesForChanges;

            value = watch ? content.GetSharedWatchedAsset <TResource>(asset, density) :
                    (WatchableAssetReference <TResource>)content.Load <TResource>(asset, density);
        }
        /// <summary>
        /// Converts the composite document to a <see cref="UvssDocument"/> instance appropriate
        /// for the specified creen density.
        /// </summary>
        private UvssDocument ToUvssDocumentInternal(ScreenDensityBucket density)
        {
            var document = new UvssDocument(Ultraviolet);

            foreach (var child in children)
            {
                document.Append(child.Get(density));
            }

            return(document);
        }
Exemple #17
0
 /// <summary>
 /// Gets a value indicating whether this asset has a version for the specified <see cref="ScreenDensityBucket"/> value.
 /// </summary>
 /// <param name="assetDensityBucket">The <see cref="ScreenDensityBucket"/> value to evaluate.</param>
 /// <returns><see langword="true"/> if the asset has a version for the specified <see cref="ScreenDensityBucket"/> value; otherwise, <see langword="false"/>.</returns>
 public Boolean HasVersion(ScreenDensityBucket assetDensityBucket)
 {
     if (obj is AssetCacheVersion acv)
     {
         return(acv.AssetDensityBucket == assetDensityBucket);
     }
     else
     {
         var dictionary = (Dictionary <Byte, AssetCacheVersion>)obj;
         return(dictionary.ContainsKey((Byte)assetDensityBucket));
     }
 }
        /// <summary>
        /// Loads the image's texture resource from the specified content manager.
        /// </summary>
        /// <param name="content">The content manager with which to load the image's texture resource.</param>
        /// <param name="density">The screen density for which to load the resource.</param>
        public void Load(ContentManager content, ScreenDensityBucket density)
        {
            Contract.Require(content, nameof(content));

            if (!cursorCollectionID.IsValid || String.IsNullOrEmpty(cursorName))
            {
                return;
            }

            var watch = content.Ultraviolet.GetUI().WatchingViewFilesForChanges;

            cursorCollection = watch ? content.GetSharedWatchedAsset <CursorCollection>(CursorCollectionID, density) :
                               (WatchableAssetReference <CursorCollection>)content.Load <CursorCollection>(CursorCollectionID, density);
        }
        /// <summary>
        /// Resolves the current global style sheet to a <see cref="UvssDocument"/> instance which
        /// is appropriate for the specified screen density.
        /// </summary>
        /// <param name="density">The screen density for which to resolve the style sheet.</param>
        /// <returns>The <see cref="UvssDocument"/> instance that was created.</returns>
        public UvssDocument ResolveGlobalStyleSheet(ScreenDensityBucket density)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            if (globalStyleSheet == null)
            {
                return(null);
            }

            if (globalStyleSheet is UvssDocument doc)
            {
                return(doc);
            }

            return(((GlobalStyleSheet)globalStyleSheet).ToUvssDocument(density));
        }
Exemple #20
0
        /// <summary>
        /// Loads the image's texture resource from the specified content manager.
        /// </summary>
        /// <param name="content">The content manager with which to load the image's texture resource.</param>
        /// <param name="density"></param>
        /// <param name="watch">A value indicating whether the <see cref="TextureImage"/> should watch the file
        /// system for changes to its underlying resources.</param>
        public void Load(ContentManager content, ScreenDensityBucket density, Boolean watch = false)
        {
            Contract.Require(content, nameof(content));

            if (!TextureID.IsValid)
            {
                return;
            }

            texture = watch ? content.GetSharedWatchedAsset <Texture2D>(TextureID, density) :
                      (WatchableAssetReference <Texture2D>)content.Load <Texture2D>(TextureID, density);

            if (TextureRegion.IsEmpty && !texture.IsNullReference)
            {
                TextureRegion = new Rectangle(0, 0, texture.Value.Width, texture.Value.Height);
            }
        }
        /// <summary>
        /// Removes a watcher from the specified asset.
        /// </summary>
        private Boolean RemoveWatcherInternal <TOutput>(String asset, ScreenDensityBucket density, AssetWatcher <TOutput> watcher)
        {
            lock (ContentManager.AssetCache.SyncObject)
            {
                if (assetWatchers == null)
                {
                    return(false);
                }

                if (assetWatchers.TryGetValue(asset, out var list))
                {
                    return(list.Remove(watcher));
                }

                return(false);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OSXScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public OSXScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            var screen = NSScreen.Screens[display.Index];
            deviceScale = (Single)screen.BackingScaleFactor;

            var density = ((NSValue)screen.DeviceDescription["NSDeviceResolution"]).CGSizeValue;
            densityX = (Single)density.Width * (96f / 72f);
            densityY = (Single)density.Height * (96f / 72f);

            var displayIsScaled = !UltravioletContext.DemandCurrent().SupportsHighDensityDisplayModes;
            if (displayIsScaled)
            {
                densityX /= deviceScale;
                densityY /= deviceScale;
            }

            densityScale = densityX / 96f;
            densityBucket = GuessBucketFromDensityScale(densityScale);
        }
Exemple #23
0
        /// <summary>
        /// Gets a value indicating whether the specified asset is registered as a dependency of another asset.
        /// </summary>
        private Boolean IsAssetDependencyInternal(String asset, String dependency, ScreenDensityBucket density)
        {
            var dependencyAssetResolvedPath = ContentManager.ResolveAssetFilePath(dependency, density, true);
            var dependencyAssetFilePath     = Path.GetFullPath(dependencyAssetResolvedPath);

            lock (ContentManager.AssetCache.SyncObject)
            {
                if (assetDependencies == null)
                {
                    return(false);
                }

                if (assetDependencies.TryGetValue(dependencyAssetFilePath, out var dependents))
                {
                    return(dependents.DependentAssets.Contains(asset));
                }
            }

            return(false);
        }
        /// <summary>
        /// Gets the version of this document which has been loaded for the specified density bucket.
        /// </summary>
        /// <param name="density">The density bucket for which to retrieve a document.</param>
        /// <returns>The version of this document which has been loaded for the specified density bucket.</returns>
        public UvssDocument Get(ScreenDensityBucket density)
        {
            Contract.EnsureNotDisposed(this, disposed);

            if (!assetVersions.TryGetValue((Byte)density, out var document))
            {
                var watching = contentManager.Ultraviolet.GetUI().WatchingViewFilesForChanges;
                if (watching)
                {
                    document = new WatchedAsset <UvssDocument>(contentManager, assetPath, density,
                                                               (p, a) => validating?.Invoke(p, a) ?? true,
                                                               (p, a, v) => validationComplete?.Invoke(p, a, v));
                }
                else
                {
                    document = new WatchedAsset <UvssDocument>(contentManager, assetPath, density);
                }
                assetVersions[(Byte)density] = document;
            }

            return(document.ValidatingValue ?? document.Value);
        }
Exemple #25
0
 /// <summary>
 /// Loads the resource using the specified content manager.
 /// </summary>
 /// <param name="contentManager">The <see cref="ContentManager"/> with which to load the resource.</param>
 /// <param name="density">The screen density for which to load the resource.</param>
 public void Load(ContentManager contentManager, ScreenDensityBucket density)
 {
     resource.Load(contentManager, density);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetCacheVersion"/> structure.
 /// </summary>
 /// <param name="assetDensityBucket">The density bucket associated with this asset.</param>
 /// <param name="assetOrigin">The origin path of the asset.</param>
 /// <param name="assetInstance">The asset instance.</param>
 public AssetCacheVersion(ScreenDensityBucket assetDensityBucket, String assetOrigin, Object assetInstance)
 {
     this.AssetDensityBucket = assetDensityBucket;
     this.AssetOrigin        = assetOrigin;
     this.AssetInstance      = assetInstance;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="iOSScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public unsafe iOSScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            var buf = IntPtr.Zero;
            try
            {
                buf = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UltravioletNative.utsname_darwin)));
                if (UltravioletNative.uname(buf) < 0)
                    throw new InvalidOperationException(UltravioletStrings.UnableToRetrieveDeviceName);

                var deviceInfo = Marshal.PtrToStructure<UltravioletNative.utsname_darwin>(buf);
                var deviceID = deviceInfo.machine;

                deviceScale = (Single)UIScreen.MainScreen.Scale;

                switch (deviceID)
                {
                    // Simulator
                    case "i386":
                    case "x86_64":
                        densityX = densityY = (Int32)(72 * deviceScale);
                        break;

                    // iPod Touch 1st-3rd Gen
                    case "iPod1,1":
                    case "iPod2,1":
                    case "iPod3,1":
                        densityX = densityY = 163;
                        break;

                    // iPod Touch 4th-6th Gen
                    case "iPod4,1":
                    case "iPod5,1":
                    case "iPod7,1":
                        densityX = densityY = 326;
                        break;

                    // iPhone, 3G, 3GS
                    case "iPhone1,1":
                    case "iPhone1,2":
                    case "iPhone2,1":
                        densityX = densityY = 163;
                        break;

                    // iPhone 4-6, SE
                    case "iPhone3,3":
                    case "iPhone3,1":
                    case "iPhone4,1":
                    case "iPhone5,1":
                    case "iPhone5,2":
                    case "iPhone5,3":
                    case "iPhone5,4":
                    case "iPhone6,1":
                    case "iPhone6,2":
                    case "iPhone7,2":
                    case "iPhone8,1":
                    case "iPhone8,4":
                        densityX = densityY = 326;
                        break;

                    // iPhone 6 Plus, 6S Plus
                    case "iPhone7,1":
                    case "iPhone8,2":
                        densityX = densityY = 401;
                        break;

                    // iPad
                    case "iPad1,1":
                    case "iPad2,1":
                        densityX = densityY = 132;
                        break;

                    // iPad 3rd Gen, iPad Air
                    case "iPad3,1":
                    case "iPad3,4":
                    case "iPad4,1":
                    case "iPad4,2":
                        densityX = densityY = 264;
                        break;

                    // iPad Mini
                    case "iPad2,5":
                        densityX = densityY = 163;
                        break;

                    // iPad Mini 2, Mini 3, Mini 4
                    case "iPad4,4":
                    case "iPad4,5":
                    case "iPad4,7":
                    case "iPad5,1":
                    case "iPad5,2":
                        densityX = densityY = 326;
                        break;

                    // iPad Pro
                    case "iPad6,3":
                    case "iPad6,8":
                        densityX = densityY = 264;
                        break;

                    // We don't know what this is so just blindly assume 326ppi
                    default:
                        densityX = densityY = 326;
                        break;
                }

                densityX *= 96f / 72f;
                densityY *= 96f / 72f;

                var displayIsScaled = !UltravioletContext.DemandCurrent().SupportsHighDensityDisplayModes;
                if (displayIsScaled)
                {
                    densityX /= deviceScale;
                    densityY /= deviceScale;
                }

                densityScale = densityX / 96f;
                densityBucket = GuessBucketFromDensityScale(densityScale);
            }
            finally
            {
                if (buf != IntPtr.Zero)
                    Marshal.FreeHGlobal(buf);
            }
        }
        /// <summary>
        /// Gets a <see cref="WatchedAsset{T}"/> which watches the specified asset. The <see cref="WatchedAsset{T}"/> which is returned
        /// is owned by the content manager and shared between all callers of this method. If the watched asset has not already been
        /// loaded, it will be loaded and added to the content manager's internal cache.
        /// </summary>
        /// <typeparam name="TOutput">The type of object being loaded.</typeparam>
        /// <param name="asset">The identifier of the asset to load.</param>
        /// <param name="density">The screen density for which to retrieve an asset watcher.</param>
        /// <returns>The <see cref="WatchedAsset{T}"/> instance which this content manager uses to watch the specified asset.</returns>
        public WatchedAsset <TOutput> GetSharedWatchedAsset <TOutput>(AssetID asset, ScreenDensityBucket density)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            return(GetSharedWatchedAssetInternal <TOutput>(AssetID.GetAssetPath(asset), density));
        }
Exemple #29
0
 /// <summary>
 /// Creates an empty asset metadata object for assets loaded in-memory.
 /// </summary>
 /// <param name="density">The density bucket for which the asset is being loaded.</param>
 /// <param name="importerMetadata">The content importer metadata object.</param>
 /// <param name="processorMetadata">The content processor metadata object.</param>
 /// <returns>The <see cref="AssetMetadata"/> which was created.</returns>
 public static AssetMetadata CreateInMemoryMetadata(ScreenDensityBucket density, Object importerMetadata = null, Object processorMetadata = null) =>
 new AssetMetadata(null, null, null, importerMetadata, processorMetadata, false, false, false, false, density);
Exemple #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetMetadata"/> class.
 /// </summary>
 /// <param name="overrideDirectory">The override directory from which the asset was loaded.</param>
 /// <param name="assetPath">The asset path of the asset being loaded.</param>
 /// <param name="assetFilePath">The path to the file that contains the asset being loaded.</param>
 /// <param name="importerMetadata">The asset's importer metadata.</param>
 /// <param name="processorMetadata">The asset's processor metadata.</param>
 /// <param name="isFile">A value indicating whether the asset was loaded from a file.</param>
 /// <param name="isStream">A value indicating whether the asset was loaded from a stream.</param>
 /// <param name="isJson">A value indicating whether the asset metadata is JSON.</param>
 /// <param name="isLoadedFromSln">A value indicating whether the asset is being loaded from the
 /// application's solution rather than the binaries folder.</param>
 /// <param name="assetDensity">The screen density for which the asset is being loaded.</param>
 public AssetMetadata(String overrideDirectory, String assetPath, String assetFilePath,
                      Object importerMetadata, Object processorMetadata, Boolean isFile, Boolean isStream, Boolean isJson, Boolean isLoadedFromSln, ScreenDensityBucket assetDensity)
 {
     this.OverrideDirectory    = overrideDirectory;
     this.AssetPath            = assetPath;
     this.AssetFilePath        = assetFilePath;
     this.AssetFileName        = (assetFilePath == null) ? null : System.IO.Path.GetFileName(assetFilePath);
     this.Extension            = (assetFilePath == null) ? null : System.IO.Path.GetExtension(assetFilePath);
     this.ImporterMetadata     = importerMetadata;
     this.ProcessorMetadata    = processorMetadata;
     this.IsFile               = isFile;
     this.IsStream             = isStream;
     this.IsJson               = isJson;
     this.IsLoadedFromSolution = isLoadedFromSln;
     this.AssetDensity         = assetDensity;
 }
        /// <summary>
        /// Adds a watcher for the specified asset.
        /// </summary>
        /// <param name="asset">The asset identifier of the asset for which to add a watcher.</param>
        /// <param name="density">The density bucket corresponding to the version of the asset to watch.</param>
        /// <param name="watcher">The watcher to add for the specified asset.</param>
        /// <returns><see langword="true"/> if the watcher was added; otherwise, <see langword="false"/>.</returns>
        public Boolean AddWatcher <TOutput>(AssetID asset, ScreenDensityBucket density, AssetWatcher <TOutput> watcher)
        {
            Contract.Require(watcher, nameof(watcher));

            return(AddWatcherInternal(AssetID.GetAssetPath(asset), density, watcher));
        }
        /// <summary>
        /// Retrieves DPI information when running on Windows 8.1 and higher.
        /// </summary>
        private Boolean InitWindows8_1(UltravioletContext uv, IUltravioletDisplay display)
        {
            if (uv.Platform != UltravioletPlatform.Windows || Environment.OSVersion.Version < new Version(6, 3))
                return false;

            var rect = new Win32.RECT
            {
                left = display.Bounds.Left,
                top = display.Bounds.Top,
                right = display.Bounds.Right,
                bottom = display.Bounds.Bottom
            };

            var hmonitor = IntPtr.Zero;

            unsafe
            {
                Win32.EnumDisplayMonitors(IntPtr.Zero, &rect, (hdc, lprcClip, lprcMonitor, dwData) =>
                {
                    hmonitor = hdc;
                    return false;
                }, IntPtr.Zero);
            }

            if (hmonitor == IntPtr.Zero)
                return false;

            UInt32 x, y;
            Win32.GetDpiForMonitor(hmonitor, 0, out x, out y);

            this.densityX = x;
            this.densityY = y;
            this.densityScale = x / 96f;
            this.densityBucket = GuessBucketFromDensityScale(densityScale);

            return true;
        }
 /// <summary>
 /// Retrieves DPI information in the general case.
 /// </summary>
 private Boolean InitFallback(UltravioletContext uv, IUltravioletDisplay display)
 {
     using (var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
     {
         this.densityX = graphics.DpiX;
         this.densityY = graphics.DpiY;
         this.densityScale = graphics.DpiX / 96f;
         this.densityBucket = GuessBucketFromDensityScale(densityScale);
     }
     return true;
 }
        /// <summary>
        /// Converts the composite document to a <see cref="UvssDocument"/> instance appropriate
        /// for the specified creen density.
        /// </summary>
        /// <returns>The <see cref="UvssDocument"/> which was created.</returns>
        public UvssDocument ToUvssDocument(ScreenDensityBucket density)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            return(ToUvssDocumentInternal(density));
        }
        /// <summary>
        /// Gets a <see cref="WatchedAsset{T}"/> which watches the specified asset.
        /// </summary>
        private WatchedAsset <TOutput> GetSharedWatchedAssetInternal <TOutput>(String asset, ScreenDensityBucket density)
        {
            lock (ContentManager.AssetCache.SyncObject)
            {
                if (CreateFileSystemWatchers())
                {
                    if (sharedWatchedAssets == null)
                    {
                        sharedWatchedAssets = new Dictionary <String, Dictionary <Byte, Object> >();
                    }

                    if (!sharedWatchedAssets.TryGetValue(asset, out var watchersForAsset))
                    {
                        watchersForAsset           = new Dictionary <Byte, Object>();
                        sharedWatchedAssets[asset] = watchersForAsset;
                    }

                    if (!watchersForAsset.TryGetValue((Byte)density, out var watcherForDensity))
                    {
                        watcherForDensity = new WatchedAsset <TOutput>(ContentManager, asset, density);
                        watchersForAsset[(Byte)density] = watcherForDensity;
                    }

                    return((WatchedAsset <TOutput>)watcherForDensity);
                }
            }

            return(null);
        }