Esempio n. 1
0
        private async void OnCmdCopy_Click(object sender, EventArgs e)
        {
            SeeingSharpRendererControl renderControl = m_ctrlRenderer;

            if (renderControl == null)
            {
                return;
            }

            using (Bitmap screenshot = await renderControl.RenderLoop.GetScreenshotGdiAsync())
                using (Bitmap rescaledScreenshot = new Bitmap(screenshot, new Size(300, 225)))
                {
                    Clipboard.SetImage(rescaledScreenshot);
                }
        }
Esempio n. 2
0
        /// <summary>
        /// Changes the render resolution to given width and height.
        /// </summary>
        /// <param name="width">The width in pixels.</param>
        /// <param name="height">The height in pixels.</param>
        private void ChangeRenderResolution(int width, int height)
        {
            SeeingSharpRendererControl renderControl = m_ctrlRenderer;

            if (renderControl == null)
            {
                return;
            }

            Size2 currentViewSize   = renderControl.RenderLoop.CurrentViewSize;
            Size2 currentWindowSize = new Size2(this.Width, this.Height);
            Size2 difference        = new Size2(
                currentWindowSize.Width - currentViewSize.Width,
                currentWindowSize.Height - currentViewSize.Height);
            Size2 newWindowSize = new Size2(width + difference.Width, height + difference.Height);

            this.WindowState = FormWindowState.Normal;
            this.Width       = newWindowSize.Width;
            this.Height      = newWindowSize.Height;
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the current control state.
        /// </summary>
        private void UpdateControlState()
        {
            SeeingSharpRendererControl actRenderControl = m_ctrlRenderer;

            // Update state values
            m_lblRenderResolutionValue.Text = actRenderControl != null ?
                                              actRenderControl.RenderLoop.CurrentViewSize.Width + " x " + actRenderControl.RenderLoop.CurrentViewSize.Height :
                                              "-";
            m_lblCountObjectsValue.Text = actRenderControl != null?
                                          actRenderControl.RenderLoop.VisibleObjectCount.ToString() :
                                              "-";

            // Update progress bar
            m_lblWorking.Visible  = m_isChangingSample;
            m_barProgress.Visible = m_isChangingSample;

            // Update sample tab
            m_tabControlSamples.Enabled = !m_isChangingSample;

            // Update enabled states
            m_cmdShowPerformance.Enabled = actRenderControl != null;
        }
        public async Task WinForms_Parent_Child_Switch()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            Panel hostPanel1 = null;
            Panel hostPanel2 = null;
            SeeingSharpRendererControl renderControl = null;
            int       stepID = 0;
            Exception fakeUIThreadException = null;

            ObjectThread fakeUIThread = new ObjectThread("Fake-UI", 100);

            fakeUIThread.ThreadException += (sender, eArgs) =>
            {
                fakeUIThreadException = eArgs.Exception;
            };
            fakeUIThread.Starting += (sender, eArgs) =>
            {
                hostPanel1      = new System.Windows.Forms.Panel();
                hostPanel1.Size = new Size(500, 500);
                hostPanel2      = new System.Windows.Forms.Panel();
                hostPanel2.Size = new Size(500, 500);

                renderControl      = new SeeingSharpRendererControl();
                renderControl.Dock = System.Windows.Forms.DockStyle.Fill;

                hostPanel1.CreateControl();
                hostPanel2.CreateControl();
                hostPanel1.Controls.Add(renderControl);
            };
            fakeUIThread.Tick += (sender, eArgs) =>
            {
                Application.DoEvents();
                stepID++;

                switch (stepID)
                {
                case 2:
                    hostPanel1.Controls.Remove(renderControl);
                    break;

                case 4:
                    hostPanel2.Controls.Add(renderControl);
                    break;

                case 8:
                    hostPanel2.Controls.Remove(renderControl);
                    break;

                case 10:
                    renderControl.Dispose();
                    hostPanel2.Dispose();
                    hostPanel1.Dispose();
                    break;

                case 11:
                    fakeUIThread.Stop();
                    break;
                }
            };
            fakeUIThread.Start();

            // Wait until the Fake-UI thread stopped
            await fakeUIThread.WaitUntilSoppedAsync();

            // Some checks after rendering
            Assert.True(GraphicsCore.Current.MainLoop.IsRunning);
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0);
            Assert.Null(fakeUIThreadException);
            Assert.True(renderControl.IsDisposed);
        }
Esempio n. 5
0
        public async Task WinForms_Parent_Child_Switch()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            // Ensure that any async disposal is  done before we create a new GraphicsCore
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();

            Panel?hostPanel1 = null;
            Panel?hostPanel2 = null;
            SeeingSharpRendererControl?renderControl = null;
            var       stepId = 0;
            Exception?fakeUIThreadException = null;

            var fakeUIThread = new ObjectThread("Fake-UI", 100);

            fakeUIThread.ThreadException += (_, eArgs) =>
            {
                fakeUIThreadException = eArgs.Exception;
            };
            fakeUIThread.Starting += (_, _) =>
            {
                hostPanel1 = new Panel
                {
                    Size = new GDI.Size(500, 500)
                };

                hostPanel2 = new Panel
                {
                    Size = new GDI.Size(500, 500)
                };

                renderControl = new SeeingSharpRendererControl
                {
                    Dock = DockStyle.Fill
                };

                hostPanel1.CreateControl();
                hostPanel2.CreateControl();
                hostPanel1.Controls.Add(renderControl);
            };
            fakeUIThread.Tick += (_, _) =>
            {
                Application.DoEvents();
                stepId++;

                switch (stepId)
                {
                case 2:
                    hostPanel1 !.Controls.Remove(renderControl !);
                    break;

                case 4:
                    hostPanel2 !.Controls.Add(renderControl !);
                    break;

                case 8:
                    hostPanel2 !.Controls.Remove(renderControl !);
                    break;

                case 10:
                    renderControl !.Dispose();
                    hostPanel2 !.Dispose();
                    hostPanel1 !.Dispose();
                    break;

                case 20:
                    fakeUIThread.Stop();
                    break;
                }
            };
            fakeUIThread.Start();

            // Wait until the Fake-UI thread stopped
            await fakeUIThread.WaitUntilSoppedAsync();

            // Some checks after rendering
            Assert.IsTrue(GraphicsCore.Current.MainLoop.IsRunning);
            Assert.IsTrue(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0);
            Assert.IsNull(fakeUIThreadException);
            Assert.IsTrue(renderControl !.IsDisposed);
        }