/// <summary>
        /// Initializes a new instance of the <see cref="SeeingSharpCoreWindowPainter"/> class.
        /// </summary>
        /// <param name="targetWindow">The target window.</param>
        public SeeingSharpCoreWindowPainter(CoreWindow targetWindow)
        {
            // Attach to SizeChanged event (refresh view resources only after a specific time)
            m_targetWindow              = targetWindow;
            m_targetWindow.SizeChanged += OnTargetWindow_SizeChanged;
            m_observerSizeChanged       = Observable.FromEventPattern <WindowSizeChangedEventArgs>(m_targetWindow, "SizeChanged")
                                          .Throttle(TimeSpan.FromSeconds(0.5))
                                          .ObserveOn(SynchronizationContext.Current)
                                          .Subscribe((eArgs) => OnTargetWindow_ThrottledSizeChanged(eArgs.Sender as CoreWindow, eArgs.EventArgs));

            // Attach to display setting changes
            m_displayInfo                     = DisplayInformation.GetForCurrentView();
            m_displayInfo.DpiChanged         += OnDisplayInfo_DpiChanged;
            m_displayInfo.OrientationChanged += OnDisplayInfo_OrientationChanged;

            // Store current dpi setting
            m_dpiScaling = new DpiScaling(m_displayInfo.LogicalDpi, m_displayInfo.LogicalDpi);

            // Create the RenderLoop object
            GraphicsCore.Touch();
            m_renderLoop                       = new Core.RenderLoop(SynchronizationContext.Current, this);
            m_renderLoop.ClearColor            = Color4.CornflowerBlue;
            m_renderLoop.CallPresentInUIThread = true;

            m_lastRefreshTargetSize = new Size(0.0, 0.0);

            UpdateRenderLoopViewSize();

            m_renderLoop.RegisterRenderLoop();
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SeeingSharpPanelPainter" /> class.
        /// </summary>
        public SeeingSharpPanelPainter()
        {
            // Create the RenderLoop object
            GraphicsCore.Touch();
            m_renderLoop                       = new Core.RenderLoop(SynchronizationContext.Current, this);
            m_renderLoop.ClearColor            = Color4.CornflowerBlue;
            m_renderLoop.CallPresentInUIThread = false;

            m_detachOnUnload = true;
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryRenderTarget" /> class.
        /// </summary>
        /// <param name="pixelHeight">Height of the offline render target in pixels.</param>
        /// <param name="pixelWidth">Width of the offline render target in pixels.</param>
        /// <param name="syncContext">Sets the SynchronizationContext which should be used by default.</param>
        public MemoryRenderTarget(int pixelWidth, int pixelHeight, SynchronizationContext syncContext = null)
        {
            //Set confiugration
            m_pixelWidth  = pixelWidth;
            m_pixelHeight = pixelHeight;

            m_renderAwaitors = new ThreadSaveQueue <TaskCompletionSource <object> >();
            if (syncContext == null)
            {
                syncContext = new SynchronizationContext();
            }

            //Create the RenderLoop object
            GraphicsCore.Touch();
            m_renderLoop = new RenderLoop(syncContext, this);
            m_renderLoop.Camera.SetScreenSize(pixelWidth, pixelHeight);
            m_renderLoop.RegisterRenderLoop();
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FullscreenRenderTarget" /> class.
        /// </summary>
        /// <param name="outputInfo">The target output monitor.</param>
        /// <param name="initialMode">The initial view mode.</param>
        public FullscreenRenderTarget(EngineOutputInfo outputInfo, EngineOutputModeInfo initialMode = default(EngineOutputModeInfo))
        {
            outputInfo.EnsureNotNull(nameof(outputInfo));

            // Check whether we are inside a win.forms application
            System.Windows.Forms.WindowsFormsSynchronizationContext syncContext = SynchronizationContext.Current
                                                                                  as System.Windows.Forms.WindowsFormsSynchronizationContext;
            if (syncContext == null)
            {
                throw new SeeingSharpException($"{nameof(FullscreenRenderTarget)} muss be created inside a Windows.Forms application context!");
            }
            m_syncContext = syncContext;

            //Set confiugration
            m_targetOutput     = outputInfo;
            m_targetOutputMode = initialMode;
            if (m_targetOutputMode.HostOutput != outputInfo)
            {
                m_targetOutputMode = m_targetOutput.DefaultMode;
            }
            m_renderAwaitors = new ThreadSaveQueue <TaskCompletionSource <object> >();

            // Ensure that graphics is initialized
            GraphicsCore.Touch();

            // Create the dummy form
            m_dummyForm = new DummyForm();
            m_dummyForm.SetStyleCustom(ControlStyles.AllPaintingInWmPaint, true);
            m_dummyForm.SetStyleCustom(ControlStyles.ResizeRedraw, true);
            m_dummyForm.SetStyleCustom(ControlStyles.OptimizedDoubleBuffer, false);
            m_dummyForm.SetStyleCustom(ControlStyles.Opaque, true);
            m_dummyForm.SetStyleCustom(ControlStyles.Selectable, true);
            m_dummyForm.SetDoubleBuffered(false);
            m_dummyForm.MouseEnter      += (sender, eArgs) => Cursor.Hide();
            m_dummyForm.MouseLeave      += (sender, eArgs) => Cursor.Show();
            m_dummyForm.HandleDestroyed += OnDummyForm_HandleDestroyed;
            m_dummyForm.GotFocus        += OnDummyForm_GotFocus;
            m_dummyForm.CreateControl();

            // Create and start the renderloop
            m_renderLoop = new RenderLoop(syncContext, this);
            m_renderLoop.Camera.SetScreenSize(m_targetOutputMode.PixelWidth, m_targetOutputMode.PixelHeight);
            m_renderLoop.RegisterRenderLoop();
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SeeingSharpRendererElement"/> class.
        /// </summary>
        public SeeingSharpRendererElement()
        {
            this.Loaded   += OnLoaded;
            this.Unloaded += OnUnloaded;

            // Basic configuration
            this.Focusable           = true;
            this.IsHitTestVisible    = true;
            this.Stretch             = System.Windows.Media.Stretch.Fill;
            this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            this.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;

            // Load ummy bitmap
            using (System.Drawing.Bitmap dummyOrig = Properties.Resources.GfxNotInitialized)
            {
                m_dummyBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    dummyOrig.GetHbitmap(),
                    IntPtr.Zero,
                    System.Windows.Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight(500, 500));
            }
            this.Source = m_dummyBitmap;

            //Create the RenderLoop object
            GraphicsCore.Touch();
            m_renderLoop = new RenderLoop(
                SynchronizationContext.Current, this, isDesignMode: this.IsInDesignMode());

            // Break here if we are in design mode
            if (this.IsInDesignMode())
            {
                return;
            }

            m_renderLoop.ClearColor            = Color4.Transparent;
            m_renderLoop.CallPresentInUIThread = true;

            // Create new scene and camera object
            if (SeeingSharpApplication.IsInitialized)
            {
                this.Scene  = new Core.Scene();
                this.Camera = new PerspectiveCamera3D();
            }

            //Attach to SizeChanged event (refresh view resources only after a specific time)
            if (SeeingSharpApplication.IsInitialized)
            {
                // Observe events and trigger rendreing as long as the control lives
                this.Loaded += (sender, eArgs) =>
                {
                    if (m_controlObserver == null)
                    {
                        m_controlObserver = CommonTools.DisposeObject(m_controlObserver);
                        m_controlObserver = Observable.FromEventPattern <EventArgs>(this, "SizeChanged")
                                            .Merge(Observable.FromEventPattern <EventArgs>(m_renderLoop.ViewConfiguration, "ConfigurationChanged"))
                                            .Throttle(TimeSpan.FromSeconds(0.5))
                                            .ObserveOn(SynchronizationContext.Current)
                                            .Subscribe((innerEArgs) => OnThrottledSizeChanged());

                        SystemEvents.SessionSwitch += OnSystemEvents_SessionSwitch;
                    }
                };
                this.Unloaded += (sender, eArgs) =>
                {
                    if (m_controlObserver != null)
                    {
                        SystemEvents.SessionSwitch -= OnSystemEvents_SessionSwitch;

                        m_controlObserver = CommonTools.DisposeObject(m_controlObserver);
                    }
                };
            }
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SeeingSharpRendererControl"/> class.
        /// </summary>
        public SeeingSharpRendererControl()
        {
            //Set style parameters for this control
            base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            base.SetStyle(ControlStyles.ResizeRedraw, true);
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
            base.SetStyle(ControlStyles.Opaque, true);
            base.SetStyle(ControlStyles.Selectable, true);
            base.DoubleBuffered = false;

            //Create the render loop
            GraphicsCore.Touch();
            m_renderLoop = new RenderLoop(SynchronizationContext.Current, this, this.DesignMode);
            m_renderLoop.ManipulateFilterList += OnRenderLoopManipulateFilterList;
            m_renderLoop.ClearColor            = new Color4(this.BackColor);
            m_renderLoop.DiscardRendering      = true;
            this.Disposed += (sender, eArgs) =>
            {
                m_renderLoop.Dispose();
            };

            // Perform default initialization logic (if not called before)
            if (SeeingSharpApplication.IsInitialized)
            {
                m_renderLoop.SetScene(new Scene());
                m_renderLoop.Camera = new PerspectiveCamera3D();

                //Observe resize event and throttle them
                this.HandleCreateDisposeOnControl(
                    () => Observable.FromEventPattern(this, "Resize")
                    .Merge(Observable.FromEventPattern(m_renderLoop.ViewConfiguration, "ConfigurationChanged"))
                    .Throttle(TimeSpan.FromSeconds(0.5))
                    .ObserveOn(SynchronizationContext.Current)
                    .Subscribe((eArgs) => OnThrottledViewRecreation()));

                //Initialize background brush
                UpdateDrawingResourcesForFailoverRendering();

                // Observe mouse click event
                this.HandleCreateDisposeOnControl(() =>
                {
                    var mouseDownEvent = Observable.FromEventPattern <MouseEventArgs>(this, "MouseDown");
                    var mouseUpEvent   = Observable.FromEventPattern <MouseEventArgs>(this, "MouseUp");
                    var mouseClick     = from down in mouseDownEvent
                                         let timeStampDown = DateTime.UtcNow
                                                             from up in mouseUpEvent
                                                             where up.EventArgs.Button == down.EventArgs.Button
                                                             let timeStampUp = DateTime.UtcNow
                                                                               where timeStampUp - timeStampDown < TimeSpan.FromMilliseconds(200.0)
                                                                               select new { Down = down, Up = up };
                    return(mouseClick.Subscribe((givenItem) =>
                    {
                        MouseClickEx.Raise(this, givenItem.Up.EventArgs);
                    }));
                });
            }

            this.Disposed += OnDisposed;

            UpdateDrawingResourcesForFailoverRendering();
        }