//////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2007-2020 , Inc. All Rights Reserved. // //////////////////////////////////////////////////////////////////////////////// using System; using GCSeries.Core.Interop; namespace GCSeries.Core.Sdk { public class ZDisplayManager : ZNativeResourceCache { public ZDisplayManager(ZContext context) { this._context = context; } //////////////////////////////////////////////////////////////////////// // Public Methods //////////////////////////////////////////////////////////////////////// /// /// Refreshes the internal cache of information corresponding to /// all active displays. /// /// /// /// This method is expensive performance-wise and should be called /// sparingly (if at all). /// public void RefreshDisplays() { this.ClearCache(); ZPlugin.LogOnError( ZPlugin.RefreshDisplays(this._context.NativePtr), "RefreshDisplays"); } /// /// Gets the number of displays that are currently active. /// /// /// /// The number of displays that are currently active. /// public int GetNumDisplays() { int numDisplays = 0; ZPlugin.LogOnError( ZPlugin.GetNumDisplays(this._context.NativePtr, out numDisplays), "GetNumDisplays"); return numDisplays; } /// /// Gets the number of displays of a specified type that are /// currently active. /// /// /// /// The display type. /// /// /// /// The number of displays of a specified type that are currently /// active. /// public int GetNumDisplays(ZDisplayType displayType) { int numDisplays = 0; ZPlugin.LogOnError(ZPlugin.GetNumDisplaysByType( this._context.NativePtr, displayType, out numDisplays), "GetNumDisplaysByType"); return numDisplays; } /// /// Gets a display based on a specified index. /// /// /// /// The index to retrieve the display for. /// /// /// /// The display at the specified index. /// public ZDisplay GetDisplay(int index) { IntPtr displayNativePtr = IntPtr.Zero; ZPlugin.LogOnError(ZPlugin.GetDisplayByIndex( this._context.NativePtr, index, out displayNativePtr), "GetDisplayByIndex"); return this.GetOrCreateCachedResource(displayNativePtr); } /// /// Gets a display that contains the specified (x, y) virtual desktop /// position in pixels. /// /// /// /// The virtual desktop x-position in pixels. /// /// /// The virtual desktop y-position in pixels. /// /// /// /// The display that contains the specified position. /// public ZDisplay GetDisplay(int x, int y) { IntPtr displayNativePtr = IntPtr.Zero; ZPlugin.LogOnError(ZPlugin.GetDisplay( this._context.NativePtr, x, y, out displayNativePtr), "GetDisplay"); return this.GetOrCreateCachedResource(displayNativePtr); } /// /// Gets a display of a specified type at a specified index. /// /// /// /// The type of display. /// /// /// The index of the display. /// /// /// /// The display of a specified type at a specified index. /// public ZDisplay GetDisplay(ZDisplayType displayType, int index = 0) { IntPtr displayNativePtr = IntPtr.Zero; ZPlugin.LogOnError(ZPlugin.GetDisplayByType( this._context.NativePtr, displayType, index, out displayNativePtr), "GetDisplayByType"); return this.GetOrCreateCachedResource(displayNativePtr); } //////////////////////////////////////////////////////////////////////// // Private Methods //////////////////////////////////////////////////////////////////////// private ZDisplay GetOrCreateCachedResource(IntPtr displayNativePtr) { return this.GetOrCreateCachedResource( displayNativePtr, d => new ZDisplay(d)); } //////////////////////////////////////////////////////////////////////// // Private Members //////////////////////////////////////////////////////////////////////// private ZContext _context = null; } }