Exemple #1
0
        public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false, bool recalculateLayout = false, bool processEvents = false)
        {
            if (!isDesignerMode)
            {
                if (recalculateLayout)
                {
                    plt.TightenLayout();
                }

                if (equalAxes)
                {
                    plt.AxisEqual();
                }

                if (!(skipIfCurrentlyRendering && currentlyRendering))
                {
                    currentlyRendering = true;
                    imagePlot.Source   = BmpImageFromBmp(plt.GetBitmap(true, lowQuality || lowQualityAlways));
                    if (isPanningOrZooming || isMovingDraggable || processEvents)
                    {
                        DoEvents();
                    }
                    currentlyRendering = false;
                    Rendered?.Invoke(null, null);
                }
            }
        }
Exemple #2
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            Rendering?.Invoke(this, new CanvasRenderingEventArgs(e.Surface.Canvas));

            base.OnPaintSurface(e);

            Rendered?.Invoke(this, new CanvasRenderingEventArgs(e.Surface.Canvas));
        }
Exemple #3
0
        private void Render()
        {
            gui.form.renderWindow.Clear();
            gui.form.renderWindow.Draw(world);
            gui.form.renderWindow.Display();

            Rendered?.Invoke(this, new RenderEventArgs());
        }
        /// <summary>
        /// Process the image and render the output.
        /// </summary>
        /// <param name="drawRectangles">Specifies whether to draw the discovered rectangles on the output image.</param>
        /// <remarks></remarks>
        public Bitmap RenderImage(bool drawRectangles = true)
        {
            if (_img is null)
            {
                return(null);
            }
            CalcDims();
            if (_Regions is null || _Regions.Count == 0)
            {
                Calculate();
            }

            var rc = _Regions.ToArray();

            if (_rendered is object)
            {
                _rendered.Dispose();
            }

            var    p = new Pen(Brushes.Black, 2f);
            double x;
            double y;
            var    img2 = new Bitmap(_img.Width, _img.Height, PixelFormat.Format32bppArgb);

            System.Drawing.Graphics g;
            var g2 = System.Drawing.Graphics.FromImage(img2);

            g2.DrawImage(_img, 0, 0, _img.Width, _img.Height);
            if (drawRectangles)
            {
                foreach (var r in rc)
                {
                    g2.DrawRectangle(p, (Rectangle)r);
                }
            }

            p.Dispose();
            g2.Dispose();
            if (_img.Height > _img.Width)
            {
                y = MaxY;
                x = _img.Width * (MaxY / (double)_img.Height);
            }
            else
            {
                x = MaxX;
                y = _img.Height * (MaxX / (double)_img.Width);
            }

            _rendered = new Bitmap((int)x, (int)y, PixelFormat.Format32bppArgb);
            g         = System.Drawing.Graphics.FromImage(_rendered);
            g.DrawImage(img2, 0f, 0f, (float)x, (float)y);
            img2.Dispose();
            g.Dispose();
            OnPropertyChanged("RenderedImage");
            Rendered?.Invoke(this, new EventArgs());
            return(_rendered);
        }
Exemple #5
0
 public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false, bool recalculateLayout = false)
 {
     if (!isDesignerMode)
     {
         if (!(skipIfCurrentlyRendering && currentlyRendering))
         {
             currentlyRendering = true;
             SetImagePlot(lowQuality);
             currentlyRendering = false;
             Rendered?.Invoke(null, null);
         }
     }
 }
        public void Render()
        {
            var now       = DateTime.Now;
            var timeDiff  = now - _lastRenderTime;
            var deltaTime = (float)timeDiff.TotalMilliseconds / 1000;

            var rect = GUILayoutUtility.GetRect(Width, Height);

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            _cachedRect = rect;

            PreviewRenderUtility.BeginPreview(_cachedRect, _backgroundStyle);
            var cam = PreviewRenderUtility.camera;

            if (RenderTarget != null)
            {
                if (RotateSpeed != 0 && AutoRotate)
                {
                    Rotation += deltaTime * RotateSpeed;
                }


                var rot = _renderTarget.transform.localEulerAngles;
                rot.y = Rotation * Mathf.Rad2Deg;
                _renderTarget.transform.localEulerAngles = rot;

                if (EditorWindow.focusedWindow != null)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            cam.transform.localPosition = new Vector3(
                0,
                Mathf.Sin(_cameraAngle) * _cameraDistance,
                Mathf.Cos(_cameraAngle) * _cameraDistance
                );

            if (CameraLookAt)
            {
                cam.transform.LookAt(Vector3.zero);
            }

            cam.Render();
            PreviewRenderUtility.EndAndDrawPreview(rect);
            _lastRenderTime = now;
            Rendered?.Invoke(this);
        }
Exemple #7
0
        private static void PreRender(FrameEventArgs e)
        {
            GL.Viewport((int)renderOffset.x, (int)renderOffset.y, Width, Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearColor(Background.r / 255f, Background.g / 255f, Background.b / 255f, 1);

            // Checks the Current Framerate
            if ((lastFPSCheck += (float)e.Time) >= 1)
            {
                Framerate    = (float)(1f / e.Time);
                lastFPSCheck = 0;
            }

            Rendered?.Invoke((float)e.Time);
            window?.SwapBuffers();
        }
Exemple #8
0
        public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false)
        {
            if (!isDesignerMode)
            {
                if (equalAxes)
                {
                    plt.AxisEqual();
                }

                if (!(skipIfCurrentlyRendering && currentlyRendering))
                {
                    currentlyRendering = true;
                    imagePlot.Source   = BmpImageFromBmp(plt.GetBitmap(true, lowQuality));
                    currentlyRendering = false;
                    Rendered?.Invoke(null, null);
                }
            }
        }
Exemple #9
0
        public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false, bool recalculateLayout = false, bool processEvents = false)
        {
            if (isDesignerMode || plt is null || imagePlot.Width < 1 || imagePlot.Height < 1)
            {
                return;
            }

            if (!(skipIfCurrentlyRendering && currentlyRendering))
            {
                currentlyRendering = true;
                imagePlot.Source   = BmpImageFromBmp(plt.Render(lowQuality || lowQualityAlways));
                if (isPanningOrZooming || isMovingDraggable || processEvents)
                {
                    DoEvents();
                }
                currentlyRendering = false;
                Rendered?.Invoke(null, null);
            }
        }
Exemple #10
0
        public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false, bool recalculateLayout = false)
        {
            if (!isDesignerMode)
            {
                if (recalculateLayout)
                {
                    plt.TightenLayout();
                }

                if (equalAxes)
                {
                    plt.AxisEqual();
                }

                if (!(skipIfCurrentlyRendering && currentlyRendering))
                {
                    currentlyRendering = true;
                    SetImagePlot(lowQuality);
                    currentlyRendering = false;
                    Rendered?.Invoke(null, null);
                }
            }
        }
Exemple #11
0
        public async Task GameLoop(CancellationToken cancellationToken)
        {
            //Console.WriteLine("Start Game Loop");

            var lastTicks = DateTime.UtcNow.Ticks;

            while (IsRunning)
            {
                var deltaMs = (DateTime.UtcNow.Ticks - lastTicks) / 10000;
                var delta   = 2 * deltaMs / 16;
                if (!IsPaused)
                {
                    //Console.WriteLine($"Loop {delta} {deltaMs} {stopwatch.ElapsedMilliseconds}");

                    Bird.Move(delta);

                    Pipes.Move(delta);

                    CheckCollisions();

                    CheckPassedPipes();


                    Rendered?.Invoke();
                }

                lastTicks = DateTime.UtcNow.Ticks;

                await Task.Delay(16);

                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }
        }
Exemple #12
0
 /// <summary>
 ///     Raises the <see cref="E:Rendered" /> event.
 /// </summary>
 /// <param name="e">The <see cref="LogiFrame.RenderedEventArgs" /> instance containing the event data.</param>
 protected virtual void OnRendered(RenderedEventArgs e)
 {
     Rendered?.Invoke(this, e);
 }
Exemple #13
0
        /// <summary>
        /// Renders the chart graph to a Visual. The graphic gets scaled to the available height and width displaying only
        /// values between minValueDisplayX and minValueDisplayX. The actual values get cropped between minDisplayValueY
        /// and maxDisplayValueY.
        /// </summary>
        public Visual CreateVisual(double width, double height)
        {
            DrawingVisual drawingVisual = new DrawingVisual();

            bool areMinMaxDefined = !double.IsNaN(MinDisplayValues[0]) && !double.IsNaN(MaxDisplayValues[0]);

            if (MinDisplayValues.Length > 1)
            {
                areMinMaxDefined = areMinMaxDefined && !double.IsNaN(MinDisplayValues[0]) && !double.IsNaN(MaxDisplayValues[0]);
            }
            if (!areMinMaxDefined || double.IsNaN(width) || double.IsNaN(height) || width <= 0 || height <= 0)
            {
                string message = "Renderer" + RendererId + "(): empty Visual returned";
                if (DimensionX < MinDisplayValues.Length)
                {
                    message += ", MinDisplayValueX: " + MinDisplayValues[DimensionX] + ", MaxDisplayValueX: " + MaxDisplayValues[DimensionX];
                }
                if (DimensionY < MinDisplayValues.Length)
                {
                    message += ", MinDisplayValueY: " + MinDisplayValues[DimensionY] + ", MaxDisplayValueY: " + MaxDisplayValues[DimensionY] + "";
                }
                TraceWpf.Line(message);
                return(drawingVisual); //return an empty Visual, not null
            }

            if (DimensionMap[0] == DimensionX)
            {
                //if there is a DimensionX in DimensionMap, it must be the first entry per convention
                dimensionXIndex = 0;
                double differenceX = MaxDisplayValues[DimensionX] - MinDisplayValues[DimensionX];
                if (differenceX == 0)
                {
                    ScaleX = width;
                }
                else
                {
                    ScaleX = width / differenceX;
                }
            }
            else
            {
                //DimensionX not used
                dimensionXIndex = int.MinValue;
                ScaleX          = double.NaN;
            }

            if (DimensionMap[0] == DimensionY)
            {
                //if the DimensionMap has only 1 entry, only this one has to be checked
                dimensionYIndex = 0;
            }
            else if (DimensionMap.Length > 1 && DimensionMap[1] == DimensionY)
            {
                //if the DimensionMap has more than 1 entry, DimensionY is by convention the second entry in DimensionMap
                dimensionYIndex = 1;
            }
            if (dimensionYIndex > int.MinValue)
            {
                double differenceY = MaxDisplayValues[dimensionYIndex] - MinDisplayValues[dimensionYIndex];
                if (differenceY == 0)
                {
                    ScaleY = height;
                }
                else
                {
                    ScaleY = height / differenceY;
                }
            }
            else
            {
                //DimensionY not used
                dimensionYIndex = int.MinValue;
                ScaleY          = double.NaN;
            }

            using (DrawingContext drawingContext = drawingVisual.RenderOpen()) {
                OnCreateVisual(drawingContext, width, height, drawingVisual);
            }

            Rendered?.Invoke(this);
            return(drawingVisual);
        }
Exemple #14
0
 public void OnRendered()
 {
     Rendered?.Invoke(this, new EventArgs());
 }
Exemple #15
0
 public event EventHandler Rendered = delegate { }; // thread safe assigment (always not null)
 public void Render()
 {
     //... some code, then
     Rendered.Invoke(this, EventArgs.Empty);
 }
Exemple #16
0
 /// <summary>
 /// Updates the and render.
 /// </summary>
 public void UpdateAndRender()
 {
     if (CanRender())
     {
         if (EnableSharingModelMode && SharedModelContainer != null)
         {
             SharedModelContainer.CurrentRenderHost = this;
         }
         IsBusy = true;
         var t0 = TimeSpan.FromSeconds((double)Stopwatch.GetTimestamp() / Stopwatch.Frequency);
         renderStatistics.FPSStatistics.Push((t0 - lastRenderTime).TotalMilliseconds);
         renderStatistics.Camera = viewport.CameraCore;
         lastRenderTime          = t0;
         UpdateRequested         = false;
         ++updateCounter;
         renderContext.AutoUpdateOctree      = RenderConfiguration.AutoUpdateOctree;
         renderContext.EnableBoundingFrustum = EnableRenderFrustum;
         if (RenderConfiguration.UpdatePerFrameData)
         {
             viewport.Update(t0);
             renderContext.TimeStamp           = t0;
             renderContext.Camera              = viewport.CameraCore;
             renderContext.OITWeightPower      = RenderConfiguration.OITWeightPower;
             renderContext.OITWeightDepthSlope = RenderConfiguration.OITWeightDepthSlope;
             renderContext.OITWeightMode       = RenderConfiguration.OITWeightMode;
         }
         renderBuffer.VSyncInterval = RenderConfiguration.EnableVSync ? 1 : 0;
         bool updateSceneGraph         = UpdateSceneGraphRequested;
         bool updatePerFrameRenderable = UpdatePerFrameRenderableRequested;
         renderContext.UpdateSceneGraphRequested         = UpdateSceneGraphRequested;
         renderContext.UpdatePerFrameRenderableRequested = UpdatePerFrameRenderableRequested;
         UpdateSceneGraphRequested         = false;
         UpdatePerFrameRenderableRequested = false;
         PreRender(updateSceneGraph, updatePerFrameRenderable);
         try
         {
             if (renderBuffer.BeginDraw())
             {
                 OnRender(t0);
                 renderBuffer.EndDraw();
                 renderStatistics.NumDrawCalls = renderer.ImmediateContext.ResetDrawCalls() + EffectsManager.DeviceContextPool.ResetDrawCalls();
             }
             if (RenderConfiguration.RenderD2D && D2DTarget.D2DTarget != null)
             {
                 OnRender2D(t0);
             }
             renderBuffer.Present();
         }
         catch (SharpDXException ex)
         {
             var desc = ResultDescriptor.Find(ex.ResultCode);
             if (desc == global::SharpDX.DXGI.ResultCode.DeviceRemoved || desc == global::SharpDX.DXGI.ResultCode.DeviceReset ||
                 desc == global::SharpDX.DXGI.ResultCode.DeviceHung || desc == global::SharpDX.Direct2D1.ResultCode.RecreateTarget ||
                 desc == global::SharpDX.DXGI.ResultCode.AccessLost)
             {
                 Log(LogLevel.Warning, $"Device Lost, code = {desc.Code}");
                 RenderBuffer_OnDeviceLost(RenderBuffer, EventArgs.Empty);
             }
             else
             {
                 Log(LogLevel.Error, ex);
                 EndD3D();
                 ExceptionOccurred?.Invoke(this, new RelayExceptionEventArgs(ex));
             }
         }
         catch (Exception ex)
         {
             Log(LogLevel.Error, ex);
             EndD3D();
             ExceptionOccurred?.Invoke(this, new RelayExceptionEventArgs(ex));
         }
         finally
         {
             PostRender();
             IsBusy = false;
         }
         lastRenderingDuration = TimeSpan.FromSeconds((double)Stopwatch.GetTimestamp() / Stopwatch.Frequency) - t0;
         RenderStatistics.LatencyStatistics.Push(lastRenderingDuration.TotalMilliseconds);
         Rendered?.Invoke(this, EventArgs.Empty);
     }
 }