/// <inheritdoc/> public override Boolean Refresh() { var oldDeviceScale = deviceScale; var oldDensityX = densityX; var oldDensityY = densityY; var oldDensityScale = densityScale; var oldDensityBucket = densityBucket; 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().Properties.SupportsHighDensityDisplayModes; if (displayIsScaled) { densityX /= deviceScale; densityY /= deviceScale; } densityScale = densityX / 96f; densityBucket = GuessBucketFromDensityScale(densityScale); return (oldDeviceScale != deviceScale || oldDensityX != densityX || oldDensityY != densityY || oldDensityScale != densityScale || oldDensityBucket != densityBucket); }
/// <summary> /// Creates a new instance of the <see cref="Surface2D"/> class. /// </summary> /// <param name="source">The <see cref="SurfaceSource"/> from which to create the surface.</param> /// <returns>The instance of <see cref="Surface2D"/> that was created.</returns> public static Surface2D Create(SurfaceSource source) { Contract.Require(source, nameof(source)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <Surface2DFromSourceFactory>()(uv, source)); }
/// <summary> /// Creates a new instance of the <see cref="IndexBuffer"/> class. /// </summary> /// <param name="itype">The index element type.</param> /// <param name="icount">The index element count.</param> /// <returns>The instance of <see cref="IndexBuffer"/> that was created.</returns> public static IndexBuffer Create(IndexBufferElementType itype, Int32 icount) { Contract.EnsureRange(icount > 0, nameof(icount)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <IndexBufferFactory>()(uv, itype, icount)); }
/// <summary> /// Creates a new instance of the <see cref="Cursor"/> class. /// </summary> /// <param name="surface">The <see cref="Surface2D"/> that contains the cursor image.</param> /// <param name="hx">The x-coordinate of the cursor's hotspot.</param> /// <param name="hy">The y-coordinate of the cursor's hotspot.</param> /// <returns>The instance of <see cref="Cursor"/> that was created.</returns> public static Cursor Create(Surface2D surface, Int32 hx, Int32 hy) { Contract.Require(surface, nameof(surface)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <CursorFactory>()(uv, surface, hx, hy)); }
public static Boolean TryParse(String s, out SpriteAnimationID value) { Contract.Require(s, nameof(s)); var uv = UltravioletContext.DemandCurrent(); return(TryParseInternal(uv.GetContent().Manifests, s, out value)); }
/// <summary> /// Converts the string representation of a <see cref="SpriteAnimationID"/> to an object instance. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="s">The string to convert.</param> /// <param name="style">A set of <see cref="NumberStyles"/> values indicating which elements are present in <paramref name="s"/>.</param> /// <param name="provider">A format provider that provides culture-specific formatting information.</param> /// <param name="v">The converted value.</param> /// <returns><see langword="true"/> if the conversion succeeded; otherwise, <see langword="false"/>.</returns> public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out SpriteAnimationID v) { Contract.Require(s, nameof(s)); var uv = UltravioletContext.DemandCurrent(); return(TryParseInternal(uv.GetContent().Manifests, s, out v)); }
/// <summary> /// Creates a new instance of the <see cref="Surface2D"/> class. /// </summary> /// <param name="surface">The <see cref="PlatformNativeSurface"/> from which to create the surface.</param> /// <param name="options">The surface's configuration options.</param> /// <returns>The instance of <see cref="Surface2D"/> that was created.</returns> public static Surface2D Create(PlatformNativeSurface surface, SurfaceOptions options = SurfaceOptions.Default) { Contract.Require(surface, nameof(surface)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <Surface2DFromNativeSurfaceFactory>()(uv, surface, options)); }
/// <summary> /// Creates a new instance of the <see cref="RenderTarget2D"/> class. /// </summary> /// <param name="width">The render target's width in pixels.</param> /// <param name="height">The render target's height in pixels.</param> /// <param name="usage">A <see cref="RenderTargetUsage"/> value specifying whether the /// render target's data is discarded or preserved when it is bound to the graphics device.</param> /// <returns>The instance of <see cref="RenderTarget2D"/> that was created.</returns> public static RenderTarget2D Create(Int32 width, Int32 height, RenderTargetUsage usage = RenderTargetUsage.DiscardContents) { Contract.EnsureRange(width > 0, nameof(width)); Contract.EnsureRange(height > 0, nameof(height)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <RenderTarget2DFactory>()(uv, width, height, usage)); }
/// <summary> /// Creates a new instance of the <see cref="Surface2D"/> class. /// </summary> /// <param name="width">The surface's width in pixels.</param> /// <param name="height">The surface's height in pixels.</param> /// <returns>The instance of <see cref="Surface2D"/> that was created.</returns> public static Surface2D Create(Int32 width, Int32 height) { Contract.EnsureRange(width > 0, nameof(width)); Contract.EnsureRange(height > 0, nameof(height)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <Surface2DFactory>()(uv, width, height)); }
/// <summary> /// Creates a new instance of the <see cref="Texture2D"/> class. /// </summary> /// <param name="width">The texture's width in pixels.</param> /// <param name="height">The texture's height in pixels.</param> /// <param name="options">The texture's configuration options.</param> /// <returns>The instance of <see cref="Texture2D"/> that was created.</returns> public static Texture2D CreateTexture(Int32 width, Int32 height, TextureOptions options = TextureOptions.Default) { Contract.EnsureRange(width > 0, nameof(width)); Contract.EnsureRange(height > 0, nameof(height)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <Texture2DFactory>()(uv, width, height, options)); }
/// <summary> /// Creates a new instance of the <see cref="RenderBuffer2D"/> class. /// </summary> /// <param name="format">A <see cref="RenderBufferFormat"/> value specifying the render buffer's data format.</param> /// <param name="width">The render buffer's width in pixels.</param> /// <param name="height">The render buffer's height in pixels.</param> /// <param name="options">The render buffer's configuration options.</param> /// <returns>The instance of <see cref="RenderBuffer2D"/> that was created.</returns> public static RenderBuffer2D CreateRenderBuffer(RenderBufferFormat format, Int32 width, Int32 height, RenderBufferOptions options = RenderBufferOptions.Default) { Contract.EnsureRange(width > 0, nameof(width)); Contract.EnsureRange(height > 0, nameof(height)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <RenderBuffer2DFactory>()(uv, format, width, height, options)); }
/// <summary> /// Creates a new instance of the <see cref="VertexBuffer"/> class. /// </summary> /// <param name="vdecl">The vertex declaration for the buffer.</param> /// <param name="vcount">The number of vertices in the buffer.</param> /// <returns>The instance of <see cref="VertexBuffer"/> that was created.</returns> public static VertexBuffer Create(VertexDeclaration vdecl, Int32 vcount) { Contract.Require(vdecl, nameof(vdecl)); Contract.EnsureRange(vcount > 0, nameof(vcount)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <VertexBufferFactory>()(uv, vdecl, vcount)); }
/// <summary> /// Initializes a new instance of the <see cref="RoslynExpressionCompilerState"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> public RoslynExpressionCompilerState(ICrossThreadUltravioletContext uv) { this.uv = uv; this.knownTypes = new Dictionary <String, Type>(); this.knownDefaultProperties = new Dictionary <Type, String>(); this.componentTemplateManager = uv?.QueueWorkItem(state => UltravioletContext.DemandCurrent().GetUI().GetPresentationFoundation().ComponentTemplates).Result; LoadKnownTypes(); }
/// <summary> /// Creates a new instance of the <see cref="Texture2D"/> class which is designed to be /// dynamically updated from data on the CPU. /// </summary> /// <param name="width">The texture's width in pixels.</param> /// <param name="height">The texture's height in pixels.</param> /// <param name="options">The texture's configuration options.</param> /// <param name="state">An arbitrary state object which will be passed to the flush handler.</param> /// <param name="flushed">The handler to invoke when the texture is flushed.</param> /// <returns>The instance of <see cref="Texture2D"/> that was created.</returns> public static Texture2D CreateDynamicTexture(Int32 width, Int32 height, TextureOptions options, Object state, Action <Texture2D, Object> flushed) { Contract.EnsureRange(width > 0, nameof(width)); Contract.EnsureRange(height > 0, nameof(height)); Contract.Require(flushed, nameof(flushed)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <DynamicTexture2DFactory>()(uv, width, height, options, state, flushed)); }
/// <summary> /// Creates a new instance of the <see cref="Surface3D"/> class. /// </summary> /// <param name="width">The surface's width in pixels.</param> /// <param name="height">The surface's height in pixels.</param> /// <param name="depth">The number of layers in the surface.</param> /// <param name="bytesPerPixel">The number of bytes used to represent a pixel on the surface.</param> /// <param name="options">The surface's configuration options.</param> /// <returns>The instance of <see cref="Surface3D"/> which was created.</returns> public static Surface3D Create(Int32 width, Int32 height, Int32 depth, Int32 bytesPerPixel, SurfaceOptions options = SurfaceOptions.Default) { Contract.Ensure(width > 0, nameof(width)); Contract.Ensure(height > 0, nameof(height)); Contract.Ensure(depth > 0, nameof(depth)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <Surface3DFactory>()(uv, width, height, depth, bytesPerPixel, options)); }
/// <summary> /// Creates a new instance of the <see cref="VertexBuffer"/> class. /// </summary> /// <typeparam name="T">The vertex type that defines the layout of the buffer's vertices.</typeparam> /// <param name="vcount">The number of vertices in the buffer.</param> /// <returns>The instance of <see cref="VertexBuffer"/> that was created.</returns> public static VertexBuffer Create <T>(Int32 vcount) where T : struct, IVertexType { Contract.EnsureRange(vcount > 0, nameof(vcount)); var vdecl = new T().VertexDeclaration; var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <VertexBufferFactory>()(uv, vdecl, vcount)); }
/// <summary> /// Gets the registered content processor for loading <see cref="FreeTypeFont"/> instances from <see cref="FreeTypeFontInfo"/> objects. /// </summary> private static ContentProcessor <FreeTypeFontInfo, FreeTypeFont> GetFreeTypeFontProcessor() { var impl = UltravioletContext.DemandCurrent().GetContent().Processors.FindProcessor(typeof(FreeTypeFontInfo), typeof(FreeTypeFont)); if (impl == null) { throw new InvalidOperationException(FreeTypeStrings.ContentRedirectionError.Format(typeof(FreeTypeFontInfo).Name, typeof(FreeTypeFont).Name)); } return((ContentProcessor <FreeTypeFontInfo, FreeTypeFont>)impl); }
/// <summary> /// Initializes a new instance of the <see cref="UIPanel"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="rootDirectory">The root directory of the panel's local content manager.</param> /// <param name="globalContent">The content manager with which to load globally-available assets.</param> internal UIPanel(UltravioletContext uv, String rootDirectory, ContentManager globalContent) : base(uv ?? UltravioletContext.DemandCurrent()) { Contract.RequireNotEmpty(rootDirectory, nameof(rootDirectory)); Contract.Require(globalContent, nameof(globalContent)); this.vmfactory = new UIViewModelFactory(CreateViewModel); this.localContent = ContentManager.Create(rootDirectory); this.globalContent = globalContent; }
/// <summary> /// Creates a new instance of the <see cref="Texture3D"/> class. /// </summary> /// <param name="layers">A pointer to the raw pixel data for each of the texture's layers.</param> /// <param name="width">The texture's width in pixels.</param> /// <param name="height">The texture's height in pixels.</param> /// <param name="bytesPerPixel">The number of bytes which represent each pixel in the raw data.</param> /// <param name="options">The texture's configuration options.</param> /// <returns>The instance of <see cref="Texture3D"/> that was created.</returns> public static Texture3D CreateTexture(IList <IntPtr> layers, Int32 width, Int32 height, Int32 bytesPerPixel, TextureOptions options = TextureOptions.Default) { Contract.Require(layers, nameof(layers)); Contract.EnsureRange(width > 0, nameof(width)); Contract.EnsureRange(height > 0, nameof(height)); Contract.EnsureRange(bytesPerPixel == 3 || bytesPerPixel == 4, nameof(bytesPerPixel)); var uv = UltravioletContext.DemandCurrent(); return(uv.GetFactoryMethod <Texture3DFromRawDataFactory>()(uv, layers, width, height, bytesPerPixel, options)); }
/// <summary> /// Creates a new instance of the <see cref="FMODPlatformSpecificImplementationDetails"/> class. /// </summary> /// <returns>The instance of <see cref="FMODPlatformSpecificImplementationDetails"/> that was created.</returns> public static FMODPlatformSpecificImplementationDetails Create() { var uv = UltravioletContext.DemandCurrent(); var factory = uv.TryGetFactoryMethod <FMODPlatformSpecificImplementationDetailsFactory>(); if (factory == null) { return(new FMODGenericPlatformImplementationDetails()); } return(factory(uv)); }
public static SpriteAnimationID Parse(String s) { Contract.Require(s, nameof(s)); SpriteAnimationID value; if (!TryParseInternal(UltravioletContext.DemandCurrent().GetContent().Manifests, s, out value)) { throw new FormatException(); } return(value); }
/// <summary> /// Creates a new instance of the <see cref="FileSystemService"/> class. /// </summary> /// <returns>The instance of <see cref="FileSystemService"/> that was created.</returns> public static AssemblyLoaderService Create() { var uv = UltravioletContext.DemandCurrent(); var factory = uv.TryGetFactoryMethod <AssemblyLoaderServiceFactory>(); if (factory != null) { return(factory()); } return(new PlatformAgnosticAssemblyLoaderService()); }
/// <summary> /// Gets a <see cref="System.ComponentModel.TypeConverter.StandardValuesCollection"/> containing the asset identifiers defined by the specified content manifest group. /// </summary> /// <param name="manifestName">The name of the manifest from which to retrieve values.</param> /// <param name="manifestGroupName">The name of the manifest group from which to retrieve values.</param> /// <returns>The <see cref="System.ComponentModel.TypeConverter.StandardValuesCollection"/> which was created.</returns> private static StandardValuesCollection GetStandardValuesForManifestGroup(String manifestName, String manifestGroupName) { var uv = UltravioletContext.DemandCurrent(); var manifestGroup = uv.GetContent().Manifests[manifestName][manifestGroupName]; var ids = (from asset in manifestGroup select asset.CreateAssetID()).ToList(); ids.Insert(0, AssetID.Invalid); var values = new StandardValuesCollection(ids.ToList()); return(values); }
/// <summary> /// When overridden in a derived class, creates a data source wrapper which implements /// the template's binding expressions. /// </summary> /// <param name="dataSource">The object's data source.</param> /// <param name="namescope">The template's namescope.</param> /// <returns>The wrapped data source.</returns> private Object CreateDataSourceWrapper(Object dataSource, out Namescope namescope) { namescope = new Namescope(); if (String.IsNullOrEmpty(dataSourceWrapperName)) { return(dataSource); } var uv = UltravioletContext.DemandCurrent(); var wrapper = uv.GetUI().GetPresentationFoundation().CreateDataSourceWrapperForView(dataSource, namescope); return(wrapper); }
/// <summary> /// Creates a new instance of the <see cref="PlatformNativeSurface"/> class. /// </summary> /// <param name="stream">The stream from which to load the surface.</param> /// <returns>The instance of <see cref="PlatformNativeSurface"/> that was created.</returns> public static PlatformNativeSurface Create(Stream stream) { var uv = UltravioletContext.DemandCurrent(); var factory = uv.GetFactoryMethod <PlatformNativeSurfaceFactory>(); var data = new Byte[stream.Length]; stream.Read(data, 0, data.Length); using (var mstream = new MemoryStream(data)) using (var src = SurfaceSource.Create(mstream)) { return(factory(src)); } }
/// <summary> /// Creates a new instance of the <see cref="UIView"/> class. /// </summary> /// <param name="uiPanel">The <see cref="UIPanel"/> which is creating the view.</param> /// <param name="uiPanelDefinition">The <see cref="UIPanelDefinition"/> that defines the view's containing panel.</param> /// <param name="vmfactory">A view model factory which is used to create the view's initial view model, or <see langword="null"/> to skip view model creation.</param> /// <returns>The instance of <see cref="UIView"/> that was created.</returns> public static UIView Create(UIPanel uiPanel, UIPanelDefinition uiPanelDefinition, UIViewModelFactory vmfactory) { Contract.Require(uiPanel, nameof(uiPanel)); Contract.Require(uiPanelDefinition, nameof(uiPanelDefinition)); var uv = UltravioletContext.DemandCurrent(); var factory = uv.TryGetFactoryMethod <UIViewFactory>(); if (factory != null) { return(factory(uv, uiPanel, uiPanelDefinition, vmfactory)); } return(null); }
/// <summary> /// Loads the set of known types which are available to the compiler. /// </summary> private void LoadKnownTypes() { if (uv != null) { var upf = uv.QueueWorkItem(state => UltravioletContext.DemandCurrent().GetUI().GetPresentationFoundation()).Result; foreach (var kvp in upf.GetKnownTypes()) { knownTypes[kvp.Key] = kvp.Value; } foreach (var kvp in knownTypes) { if (upf.GetElementDefaultProperty(kvp.Value, out var property)) { knownDefaultProperties[kvp.Value] = property; } } } else { var types = from type in typeof(PresentationFoundation).Assembly.GetTypes() let attrKnownType = type.GetCustomAttributes(typeof(UvmlKnownTypeAttribute), false).Cast <UvmlKnownTypeAttribute>().SingleOrDefault() let attrDefaultProp = type.GetCustomAttributes(typeof(DefaultPropertyAttribute), true).Cast <DefaultPropertyAttribute>().SingleOrDefault() where attrKnownType != null select new { Type = type, AttrKnownType = attrKnownType, AttrDefaultProp = attrDefaultProp }; foreach (var type in types) { var name = type.AttrKnownType.Name ?? type.Type.Name; knownTypes[name] = type.Type; System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.Type.TypeHandle); if (type.AttrDefaultProp != null) { knownDefaultProperties[type.Type] = type.AttrDefaultProp.Name; } } } }
/// <summary> /// Loads the content of the template as an instance of an object and returns the root element of the content. /// </summary> /// <param name="dataSource">The object's data source.</param> /// <param name="dataSourceType">The object's data source type.</param> /// <returns>The root element of the content.</returns> public DependencyObject LoadContent(Object dataSource, Type dataSourceType) { var uv = UltravioletContext.DemandCurrent(); var namescope = default(Namescope); var wrapper = CreateDataSourceWrapper(dataSource, out namescope); var context = new UvmlInstantiationContext(uv, null, wrapper, wrapper?.GetType(), namescope); var dobj = (DependencyObject)((UvmlTemplateInstance)template.Instantiate(uv, context)).Finalize(); var element = dobj as FrameworkElement; if (element != null) { element.TemplatedNamescope = namescope; } if (dataSource != null) { namescope.PopulateFieldsFromRegisteredElements(dataSource); } return(dobj); }
/// <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); }
/// <summary> /// Creates a new instance of the <see cref="DynamicTextureAtlas"/> class. /// </summary> /// <param name="width">The texture's width in pixels.</param> /// <param name="height">The texture's height in pixels.</param> /// <param name="spacing">The number of pixels between cells on the texture atlas.</param> /// <param name="options">The texture's configuration options.</param> /// <returns>The instance of <see cref="DynamicTextureAtlas"/> that was created.</returns> public static DynamicTextureAtlas Create(Int32 width, Int32 height, Int32 spacing, TextureOptions options = TextureOptions.Default) { var uv = UltravioletContext.DemandCurrent(); return(new DynamicTextureAtlas(uv, width, height, spacing, options)); }