private void RestoreSettings() { if (settings.WindowLocation.X != 0 && settings.WindowSize.Width != 0 && settings.WindowSize.Height != 0) { // make sure it is visible on the user's current screen configuration. var bounds = new System.Drawing.Rectangle( XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.X), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.Y), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Width), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Height)); var screen = System.Windows.Forms.Screen.FromRectangle(bounds); bounds.Intersect(screen.WorkingArea); this.Left = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.X); this.Top = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Y); this.Width = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Width); this.Height = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Height); } if (string.IsNullOrEmpty(this.SrtFileName.Text)) { this.SrtFileName.Text = this.settings.SrtFile; UpdateSrt(); } if (string.IsNullOrEmpty(this.VideoFileName.Text)) { this.VideoFileName.Text = this.settings.VideoFile; UpdateVideoLocation(this.settings.Position); } this.Visibility = Visibility.Visible; }
Rect?GetSavedWindowSettings() { var savedBounds = settings.Bounds; if (savedBounds == Rect.Empty) { return(null); } const int MIN_WIDTH = 50, MIN_HEIGHT = 50; foreach (var screen in System.Windows.Forms.Screen.AllScreens) { var rect = new System.Drawing.Rectangle((int)savedBounds.X, (int)savedBounds.Y, (int)savedBounds.Width, (int)savedBounds.Height); rect.Intersect(screen.Bounds); if (rect.Height >= MIN_HEIGHT && rect.Width >= MIN_WIDTH) { var t = savedBounds; t = Rect.Transform(savedBounds, PresentationSource.FromVisual(window).CompositionTarget.TransformFromDevice); return(new Rect(t.TopLeft, savedBounds.Size)); } } return(null); }
private void RestorePosition() { this.SizeChanged -= OnWindowSizeChanged; this.LocationChanged -= OnWindowLocationChanged; this.settings = App.Instance.LoadSettings(); if (settings.WindowLocation.X != 0 && settings.WindowSize.Width != 0 && settings.WindowSize.Height != 0) { // make sure it is visible on the user's current screen configuration. var bounds = new System.Drawing.Rectangle( XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.X), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.Y), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Width), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Height)); var screen = System.Windows.Forms.Screen.FromRectangle(bounds); bounds.Intersect(screen.WorkingArea); this.Left = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.X); this.Top = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Y); this.Width = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Width); this.Height = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Height); } this.Visibility = Visibility.Visible; this.SizeChanged += OnWindowSizeChanged; this.LocationChanged += OnWindowLocationChanged; }
private void AddIsotopesToPlots() { if (CurrentFeature == null) { return; } var precursor = new Feature(CurrentFeature.Statistics); var precursorBoundary = precursor.GetBoundary(); foreach (var isotopeEntry in IsotopeFeaturesDictionary) { var isotopeName = isotopeEntry.Key; foreach (var featureBlob in isotopeEntry.Value) { var feature = new Feature(featureBlob.Statistics); var boundary = feature.GetBoundary(); var intersection = Rectangle.Intersect(precursorBoundary, boundary); // Ignore features that do not intersect at all if (intersection.IsEmpty) { continue; } AddToLcPlot(featureBlob, isotopeName, OxyColors.DeepSkyBlue); AddToImsPlot(featureBlob, isotopeName, OxyColors.DeepSkyBlue); } } }
/// When given multiple windows, this function will return the window *most likely* to be the one of eye gaze/fixation public static List <string> getWindowOfFixation(List <Tuple <HWND, Tuple <string, WINDOWPLACEMENT> > > windows) { //Check how many windows are in fixation overlap area. If there are more than 2, narrow it down to the top 2 windows int indexWindow1 = 0; int indexWindow2 = 1; if (windows.Count() > 2) { int j = 0; //This loop compares 3 indices and keeps the top 2 windows for each set for (int i = 1; i < windows.Count(); i++) { //top window of pair takes place of index 1 if (topWindow(windows[j].Item1, windows[i].Item1)) //if window-j is above window-i -> true { indexWindow1 = j; //see if i is higher than indexWindow2 if ((i != indexWindow2) && (topWindow(windows[i].Item1, windows[indexWindow2].Item1))) { indexWindow2 = i; } } else { indexWindow1 = i; //see if j is higher than indexWindow2 if ((j != indexWindow2) && (topWindow(windows[j].Item1, windows[indexWindow2].Item1))) { indexWindow2 = j; } } j = indexWindow1; } } System.Drawing.Rectangle window1 = windows[indexWindow1].Item2.Item2.rcNormalPosition; System.Drawing.Rectangle window2 = windows[indexWindow2].Item2.Item2.rcNormalPosition; //Check the overlap percentage: (Area of overlap)/(Area of bottom window) var bottomArea = (window2.Height * window2.Width); window1.Intersect(window2); //replaces window1 with rectangle of size/location of intersection var overlapX = window1.Height * window1.Width; overlapX = 100 * overlapX / bottomArea; //Console.WriteLine("Overlap: {0}", overlapX); //If the percentage is big (>50% - see GlobalVals in Program.CS), assume the top window is the one being looked at List <string> returnList = new List <string>(); returnList.Add(windows[indexWindow1].Item2.Item1); //if the overlap area is >= 50%, return only window1. Otherwise return window2 as well (unless I get to TO-DO below) if (overlapX < GlobalVals.areaPercent) { returnList.Add(windows[indexWindow2].Item2.Item1); } //TO-DO: If it's not >50%, use data from recent fixations to determine it. May not have time to implement this. return(returnList); }
/// <inheritdoc /> /// <summary> /// Class constructor /// </summary> /// <param name="rect">Screen region</param> /// <param name="windowHandle">Attached window handle (unused)</param> /// <exception cref="NotSupportedException">Thrown when no video adapters were found</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the capture region is empty</exception> internal DxVideoProvider(Rectangle rect, IntPtr?windowHandle = null) : base(rect, windowHandle) { throw new NotImplementedException(); Log.WriteLine(LogLevel.Debug, "creating DirectX video provider"); this.direct3d = new Direct3D(); // enumerate adapters List <(AdapterInformation Adapter, Rectangle Rectangle, Rectangle Bounds)> intersections = ( from adapter in this.direct3d.Adapters let info = new MONITORINFO() where User32.GetMonitorInfo(adapter.Monitor, info) let outputRect = Rectangle.FromLTRB(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom) let intersection = Rectangle.Intersect(rect, outputRect) where intersection != Rectangle.Empty select(adapter, intersection, outputRect)).ToList(); // make sure we do not capture out of bounds CaptureBounds = rect; if (CaptureBounds.IsEmpty) { throw new ArgumentOutOfRangeException(nameof(rect)); } // set rectangles for each output this.rects = intersections.Select(t => t.Rectangle).ToArray(); this.regions = intersections.Select(t => t.Bounds).ToArray(); // create devices for each adapter this.devices = intersections.Select(i => new Device(this.direct3d, i.Adapter.Adapter, DeviceType.Hardware, User32.GetDesktopWindow(), CreateFlags.HardwareVertexProcessing, new PresentParameters(i.Bounds.Width, i.Bounds.Height))) .ToArray(); // create adapter and surface arrays this.adapters = intersections.Select(t => t.Adapter).ToArray(); Surfaces = new Surface[this.devices.Length]; }
/// <summary> /// Method generates actual image for specified viewport. /// </summary> private void BuildUpViewportImage(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle invalidatedRect) { if (canvas.Width != viewport.Width || canvas.Height != viewport.Height) { throw new System.ArgumentException(StringResources.GetString("ExStrCanvasAndViewportDimsShouldBeEqual")); } // We should take into account 2 issues here // 1) Shift or resize of the viewport. // 2) Invalidated areas. // // Note: Current implementation may draw twice invalidatedRect in some case. Taking this case // into account would cause code complication. I think that it is a rather rare case, because invalidatedRect // is usually empty during scrolling. On the other hand, it is not empty during // object editing, but in such case viewportOrigin is not changed. In both of these most regular cases // invalidatedRect will be drawn once. // Drawing actual cached region of the viewportOrigin. System.Drawing.Rectangle cachedRegion = _viewportCache.GetActualRegion(zoom, viewport); System.Drawing.Rectangle[] cachedActualRegions = VObjectsUtils.SubstractRectangle(cachedRegion, invalidatedRect); for (int i = 0; i < cachedActualRegions.Length; i++) { if (cachedActualRegions[i].Width < 1 || cachedActualRegions[i].Height < 1) { continue; } using (var canvasGdiGraphics = canvas.GetGraphics()) { _viewportCache.DrawCached(canvasGdiGraphics, zoom, viewport, cachedActualRegions[i]); } } // Drawing non-cached parts of the viewportOrigin image. invalidatedRect.Intersect(viewport); if (invalidatedRect.Width > 0 && invalidatedRect.Height > 0) { DrawNoncachedArea(canvas, zoom, viewport, invalidatedRect); } System.Drawing.Rectangle[] newRegions = VObjectsUtils.SubstractRectangle(viewport, cachedRegion); for (int i = 0; i < newRegions.Length; i++) { newRegions[i].Intersect(viewport); if (newRegions[i].Width < 1 || newRegions[i].Height < 1) { continue; } DrawNoncachedArea(canvas, zoom, viewport, newRegions[i]); } }
private static void setMaskingInfo(MaskingInfo maskingInfo, bool overwritePreviousScissor) { FlushCurrentBatch(); Shader.SetGlobalProperty(@"g_MaskingRect", new Vector4( maskingInfo.MaskingRect.Left, maskingInfo.MaskingRect.Top, maskingInfo.MaskingRect.Right, maskingInfo.MaskingRect.Bottom)); Shader.SetGlobalProperty(@"g_ToMaskingSpace", maskingInfo.ToMaskingSpace); Shader.SetGlobalProperty(@"g_CornerRadius", maskingInfo.CornerRadius); Shader.SetGlobalProperty(@"g_BorderThickness", maskingInfo.BorderThickness / maskingInfo.BlendRange); Color4 linearBorderColour = maskingInfo.BorderColour.toLinear(); Shader.SetGlobalProperty(@"g_BorderColour", new Vector4( linearBorderColour.R, linearBorderColour.G, linearBorderColour.B, linearBorderColour.A)); Shader.SetGlobalProperty(@"g_MaskingBlendRange", maskingInfo.BlendRange); Rectangle actualRect = maskingInfo.ScreenSpaceAABB; actualRect.X += Viewport.X; actualRect.Y += Viewport.Y; // Ensure the rectangle only has positive width and height. (Required by OGL) if (actualRect.Width < 0) { actualRect.X += actualRect.Width; actualRect.Width = -actualRect.Width; } if (actualRect.Height < 0) { actualRect.Y += actualRect.Height; actualRect.Height = -actualRect.Height; } if (overwritePreviousScissor) { currentScissorRect = actualRect; } else { currentScissorRect.Intersect(actualRect); } UpdateScissorToCurrentViewportAndOrtho(); }
private bool IsFrameOnScreens(System.Drawing.Rectangle frameArea, float minCoverage = 0.2f) { var coveredPixels = 0; foreach (var screen in Screen.AllScreens) { var screenArea = screen.WorkingArea; if (screenArea.IntersectsWith(frameArea)) { var intersection = new System.Drawing.Rectangle(frameArea.Location, frameArea.Size); intersection.Intersect(screenArea); coveredPixels += intersection.Width * intersection.Height; } } var coverage = coveredPixels / (frameArea.Width * frameArea.Height * 1f); return(coverage >= minCoverage); }
private void MatchPrecursorToFragments() { if (CurrentFeature == null) { return; } var precursor = new Feature(CurrentFeature.Statistics); var precursorBoundary = precursor.GetBoundary(); foreach (var kvp in FragmentFeaturesDictionary) { var ionTypeTuple = kvp.Key; // Skip any fragments that do not meet the UI filter criteria if (!ShouldShowFragment(ionTypeTuple)) { continue; } var residueNumber = ionTypeTuple.Item2; var fragmentName = ionTypeTuple.Item1.GetName(residueNumber); var fragmentFeatureList = kvp.Value; foreach (var fragmentFeature in fragmentFeatureList) { var feature = new Feature(fragmentFeature.Statistics); var fragmentBoundary = feature.GetBoundary(); var intersection = Rectangle.Intersect(precursorBoundary, fragmentBoundary); // Ignore fragment features that do not intersect at all if (intersection.IsEmpty) { continue; } AddToLcPlot(fragmentFeature, fragmentName, OxyColors.Red); AddToImsPlot(fragmentFeature, fragmentName, OxyColors.Red); } } }
public static Bitmap TakeScreenshot(this OpenQA.Selenium.IWebElement element) { RemoteWebDriver driver = (RemoteWebDriver)((RemoteWebElement)element).WrappedDriver; if (((IHasCapabilities)driver).Capabilities.HasCapability("takesElementScreenshot")) { byte[] bytes = ((RemoteWebElement)element).GetScreenshot().AsByteArray; return((Bitmap)Bitmap.FromStream(new MemoryStream(bytes, 0, bytes.Length, false, true), false, false)); } else { var dict = (Dictionary <String, Object>)driver.ExecuteScript(@" arguments[0].scrollIntoView(true); var r = arguments[0].getBoundingClientRect(), scrollX = 0, scrollY = 0; for(var e = arguments[0]; e; e=e.parentNode) { scrollX += e.scrollLeft || 0; scrollY += e.scrollTop || 0; } return {left: r.left|0, top: r.top|0, width: r.width|0, height: r.height|0 , scrollX: scrollX, scrollY: scrollY, innerHeight: window.innerHeight}; " , element); var rect = new System.Drawing.Rectangle( Convert.ToInt32(dict["left"]), Convert.ToInt32(dict["top"]), Convert.ToInt32(dict["width"]), Convert.ToInt32(dict["height"])); byte[] bytes = driver.GetScreenshot().AsByteArray; using (Bitmap bitmap = (Bitmap)Bitmap.FromStream(new MemoryStream(bytes, 0, bytes.Length, false, true), false, false)) { if (bitmap.Height > Convert.ToInt32(dict["innerHeight"])) { rect.Offset(Convert.ToInt32(dict["scrollX"]), Convert.ToInt32(dict["scrollY"])); } rect.Intersect(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height)); if (rect.Height == 0 || rect.Width == 0) { throw new WebDriverException("WebElement is outside of the screenshot."); } return(bitmap.Clone(rect, bitmap.PixelFormat)); } } }
private async void RestoreSettings() { Settings settings = await ((App)App.Current).LoadSettings(); if (settings.WindowLocation.X != 0 && settings.WindowSize.Width != 0 && settings.WindowSize.Height != 0) { // make sure it is visible on the user's current screen configuration. var bounds = new System.Drawing.Rectangle( XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.X), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.Y), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Width), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Height)); var screen = System.Windows.Forms.Screen.FromRectangle(bounds); bounds.Intersect(screen.WorkingArea); this.Left = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.X); this.Top = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Y); this.Width = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Width); this.Height = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Height); } ConnectionPanel.DefaultUdpPort = settings.Port; this.Visibility = Visibility.Visible; }
private async void RestoreSettings() { Settings settings = await((App)App.Current).LoadSettings(); if (settings.WindowLocation.X != 0 && settings.WindowSize.Width != 0 && settings.WindowSize.Height != 0) { // make sure it is visible on the user's current screen configuration. var bounds = new System.Drawing.Rectangle( XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.X), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowLocation.Y), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Width), XamlExtensions.ConvertFromDeviceIndependentPixels(settings.WindowSize.Height)); var screen = System.Windows.Forms.Screen.FromRectangle(bounds); bounds.Intersect(screen.WorkingArea); this.Left = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.X); this.Top = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Y); this.Width = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Width); this.Height = XamlExtensions.ConvertToDeviceIndependentPixels(bounds.Height); } ConnectionPanel.DefaultUdpPort = settings.Port; this.Visibility = Visibility.Visible; }
public MainWindow() { InitializeComponent(); LoadNotebooks(); this.WindowState = (System.Windows.WindowState)Enum.Parse(typeof(System.Windows.WindowState), Properties.Settings.Default.MainWindow_State); if (this.WindowState == System.Windows.WindowState.Normal) { if (Properties.Settings.Default.MainWindow_Bounds != System.Drawing.Rectangle.Empty) { // restore position only if the position overlaps available screen var virtScreen = new System.Drawing.Rectangle( x: (int)SystemParameters.VirtualScreenLeft, y: (int)SystemParameters.VirtualScreenTop, width: (int)SystemParameters.VirtualScreenWidth, height: (int)SystemParameters.VirtualScreenHeight); virtScreen.Intersect(Properties.Settings.Default.MainWindow_Bounds); if (virtScreen.Width > 50 && virtScreen.Height > 50) { this.Left = Properties.Settings.Default.MainWindow_Bounds.Left; this.Top = Properties.Settings.Default.MainWindow_Bounds.Top; this.Width = Properties.Settings.Default.MainWindow_Bounds.Width; this.Height = Properties.Settings.Default.MainWindow_Bounds.Height; } } } toggleAutosave.IsChecked = Properties.Settings.Default.AutoSave; toggleWrap.IsChecked = Properties.Settings.Default.WordWrap; toggleOnTop.IsChecked = Properties.Settings.Default.OnTop; toggleTags.IsChecked = Properties.Settings.Default.ShowTags; toggleTagsOnTop.IsChecked = Properties.Settings.Default.TagsOnTop; DetermineWindowIcons(); _timer = new DispatcherTimer(TimeSpan.FromSeconds(10), DispatcherPriority.ApplicationIdle, OnSaveTimer, Dispatcher.CurrentDispatcher); this.Title = this.Title + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
/// <summary>Render the control</summary> public override void Render(Device device, float elapsedTime) { if (!IsVisible) { return; // Nothing to render } // Render the control graphics for (int i = 0; i <= LowerRightBorder; ++i) { Element e = elementList[i] as Element; e.TextureColor.Blend(ControlState.Normal, elapsedTime); parentDialog.DrawSprite(e, elementRects[i]); } // // Compute the X coordinates of the first visible character. // int xFirst = textData.GetPositionFromCharIndex(firstVisible).X; int xCaret = textData.GetPositionFromCharIndex(caretPosition).X; int xSel; if (caretPosition != textData.SelectionStart) { xSel = textData.GetPositionFromCharIndex(textData.SelectionStart).X; } else { xSel = xCaret; } // Render the selection rectangle System.Drawing.Rectangle selRect = System.Drawing.Rectangle.Empty; if (caretPosition != textData.SelectionStart) { int selLeft = xCaret, selRight = xSel; // Swap if left is beigger than right if (selLeft > selRight) { int temp = selLeft; selLeft = selRight; selRight = temp; } selRect = System.Drawing.Rectangle.FromLTRB( selLeft, textRect.Top, selRight, textRect.Bottom); selRect.Offset(textRect.Left - xFirst, 0); selRect.Intersect(textRect); Parent.DrawRectangle(selRect, selectedBackColor); } // Render the text Element textElement = elementList[TextLayer] as Element; textElement.FontColor.Current = textColor; parentDialog.DrawText(textData.Text.Substring(firstVisible), textElement, textRect); // Render the selected text if (caretPosition != textData.SelectionStart) { int firstToRender = Math.Max(firstVisible, Math.Min(textData.SelectionStart, caretPosition)); int numToRender = Math.Max(textData.SelectionStart, caretPosition) - firstToRender; textElement.FontColor.Current = selectedTextColor; parentDialog.DrawText(textData.Text.Substring(firstToRender, numToRender), textElement, selRect); } // // Blink the caret // if (FrameworkTimer.GetAbsoluteTime() - lastBlink >= blinkTime) { isCaretOn = !isCaretOn; lastBlink = FrameworkTimer.GetAbsoluteTime(); } // // Render the caret if this control has the focus // if (hasFocus && isCaretOn && !isHidingCaret) { // Start the rectangle with insert mode caret System.Drawing.Rectangle caretRect = textRect; caretRect.Width = 2; caretRect.Location = new System.Drawing.Point( caretRect.Left - xFirst + xCaret - 1, caretRect.Top); // If we are in overwrite mode, adjust the caret rectangle // to fill the entire character. if (!isInsertMode) { // Obtain the X coord of the current character caretRect.Width = 4; } parentDialog.DrawRectangle(caretRect, caretColor); } }
Rect? GetSavedWindowSettings() { var savedBounds = settings.Bounds; if (savedBounds == Rect.Empty) return null; var bounds = Rect.Transform(savedBounds, PresentationSource.FromVisual(window).CompositionTarget.TransformToDevice); const int MIN_WIDTH = 50, MIN_HEIGHT = 50; foreach (var screen in System.Windows.Forms.Screen.AllScreens) { var rect = new System.Drawing.Rectangle((int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)bounds.Height); rect.Intersect(screen.Bounds); if (rect.Height >= MIN_HEIGHT && rect.Width >= MIN_WIDTH) return bounds; } return null; }
/// <inheritdoc /> /// <summary> /// Class constructor /// </summary> /// <param name="rect">Screen region</param> /// <exception cref="NotSupportedException">Thrown when no video adapters were found</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the capture region is empty</exception> internal DxgiVideoProvider(Rectangle rect) { Log.WriteLine(LogLevel.Debug, "creating DXGI video provider"); var factory = new Factory1(); var intersections = new List <(Adapter Adapter, Output Output, Rectangle Rectangle, Rectangle Bounds)>(); // enumerate outputs if (factory.GetAdapterCount1() == 0) { throw new NotSupportedException("No suitable video adapters found"); } foreach (Adapter adapter in factory.Adapters) { intersections.AddRange(from output in adapter.Outputs let outputRect = new Rectangle(output.Description.DesktopBounds.Left, output.Description.DesktopBounds.Top, output.Description.DesktopBounds.Right - output.Description.DesktopBounds.Left, output.Description.DesktopBounds.Bottom - output.Description.DesktopBounds.Top) let intersection = Rectangle.Intersect(rect, outputRect) where intersection.Width > 0 && intersection.Height > 0 select(adapter, output, intersection, outputRect)); } // make sure we do not capture out of bounds //this.rect = triples.Select(t => Rectangle.Union(this.rect, t.Rectangle)).Last(); CaptureBounds = rect; if (CaptureBounds.IsEmpty) { throw new ArgumentOutOfRangeException(nameof(rect)); } // create adapter, output arrays this.adapters = intersections.Select(t => t.Adapter).ToArray(); this.outputs = intersections.Select(t => t.Output).ToArray(); // set rectangles for each output this.rects = intersections.Select(t => t.Rectangle).ToArray(); this.regions = intersections.Select(t => { var region = new ResourceRegion(t.Rectangle.X - t.Bounds.X, t.Rectangle.Y - t.Bounds.Y, 0, t.Rectangle.Width, t.Rectangle.Height, 1); region.Right += region.Left; region.Bottom += region.Top; return(region); }) .ToArray(); // create devices for each adapter this.devices = this.adapters.Select((a, i) => { var flags = DeviceCreationFlags.VideoSupport; #if DEBUG flags |= DeviceCreationFlags.Debug; #endif var device = new Device(a, flags, FeatureLevel.Level_12_1, FeatureLevel.Level_12_0, FeatureLevel.Level_11_0) { #if DEBUG DebugName = $"[#{i}] {a.Description.Description}" #endif }; device.QueryInterface <Multithread>().SetMultithreadProtected(new RawBool(true)); return(device); }) .ToArray(); // create the shared texture in this device StagingTextures = this.devices.Select((d, i) => new Texture2D(d, new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = intersections[i].Rectangle.Width, Height = intersections[i].Rectangle.Height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging })) .ToArray(); // let video encoders use the screen texture if a single monitor is being captured // TODO: implement D3D12 multi-adapter support /*if (...) { * // create full capture texture * SharedTexture = new Texture2D(this.devices[0], * new Texture2DDescription { * CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write, * BindFlags = BindFlags.None, * Format = Format.B8G8R8A8_UNorm, * Width = CaptureBounds.Width, * Height = CaptureBounds.Height, * OptionFlags = ResourceOptionFlags.None, * MipLevels = 1, * ArraySize = 1, * SampleDescription = {Count = 1, Quality = 0}, * Usage = ResourceUsage.Staging * }); * } else*/ if (StagingTextures.Length == 1) { SharedTexture = StagingTextures[0]; } // duplicate desktops this.duplications = this.outputs.Select((o, i) => { try { // attempt to use DuplicateOutput1 for improved performance and SRGB support Format[] formats = { Format.B8G8R8A8_UNorm }; return(o.QueryInterface <Output6>().DuplicateOutput1(this.devices[i], 0, formats.Length, formats)); } catch (SharpDXException exception1) when(exception1.HResult == ResultCode.Unsupported.Result) { try { return(o.QueryInterface <Output1>().DuplicateOutput(this.devices[i])); } catch (SharpDXException exception) when(exception.HResult == ResultCode.Unsupported.Result || exception.HResult == NotImplementedHResult) { throw new NotSupportedException("Platform is not supported"); } } }) .ToArray(); }
/// <summary> /// 获得和指定矩形对象的相交区域对象 /// </summary> /// <param name="vRect">矩形对象</param> /// <returns>相交的区域对象</returns> public System.Drawing.Rectangle Intersect(System.Drawing.Rectangle vRect) { System.Drawing.Rectangle myRect = new System.Drawing.Rectangle(intLeft, intTop, intWidth, intHeight); myRect.Intersect(vRect); return(myRect); }