Ejemplo n.º 1
0
        public virtual void Render(TargetBase target)
        {
            if (!Show)
            {
                return;
            }

            frameCount++;
            var timeElapsed = (double)clock.ElapsedTicks / Stopwatch.Frequency;;

            totalTime += timeElapsed;
            if (totalTime >= 1.0f)
            {
                measuredFPS = (double)frameCount / totalTime;
                frameCount  = 0;
                totalTime   = 0.0;
            }

            var context2D = target.DeviceManager.ContextDirect2D;

            context2D.BeginDraw();
            context2D.Transform = Matrix.Identity;
            context2D.DrawText(string.Format("{0:F2} FPS ({1:F1} ms)", measuredFPS, timeElapsed * 1000.0), textFormat, new RectangleF(8, 8, 8 + 256, 8 + 16), sceneColorBrush);
            context2D.EndDraw();

            clock.Restart();
        }
        // 繪圖主要方法
        public virtual void Render(TargetBase target)
        {
            var context2D = target.DeviceManager.ContextDirect2D;

            context2D.BeginDraw();
            context2D.Clear(Color.White);

            var sizeX = (float)target.RenderTargetBounds.Width;
            var sizeY = (float)target.RenderTargetBounds.Height;

            try
            {
                if (MainPage.pointers != null)
                {
                    for (int j = 0; j < MainPage.pointers.Count; j++)
                    {
                        // Different color for touch points
                        lineColorBrush = new SolidColorBrush(context2D, MainPage.pointers[j].color);

                        for (int i = 0; i < MainPage.pointers[j].Pointers.Count; i++)
                        {
                            if (i == MainPage.pointers[j].Pointers.Count - 1)
                            {
                                float x = (float)MainPage.pointers[j].Pointers[i].X;
                                float y = (float)MainPage.pointers[j].Pointers[i].Y;
                                // Pointers info
                                context2D.DrawText(string.Format("PointerID:{0}\nX:{1}\nY:{2}\n{3}", MainPage.pointers[j].PointerId, x, y, MainPage.pointers[j].DeviceType.ToString())
                                    , textFormat, new RectangleF(x - 150, y - 100, x - 20, y - 20), sceneColorBrush);

                                // Draw horizontal line
                                context2D.DrawLine(new DrawingPointF(0, y), new DrawingPointF(context2D.PixelSize.Width, y), lineColorBrush);
                                // Draw vertical line
                                context2D.DrawLine(new DrawingPointF(x, 0), new DrawingPointF(x, context2D.PixelSize.Height), lineColorBrush);
                                // Draw a circle (and like a Crosshair :D )
                                ellipse = new Ellipse(new DrawingPointF(x, y), 30, 30);
                                context2D.DrawEllipse(ellipse, lineColorBrush);
                                continue;
                            }

                            var beginPoint = new DrawingPointF((float)MainPage.pointers[j].Pointers[i].X, (float)MainPage.pointers[j].Pointers[i].Y);
                            var endPoint = new DrawingPointF((float)MainPage.pointers[j].Pointers[i + 1].X, (float)MainPage.pointers[j].Pointers[i + 1].Y);
                            context2D.DrawLine(beginPoint, endPoint, lineColorBrush, 10, strokeStyle);
                        }
                    }

                    // Update pointers contacts
                    context2D.DrawText(string.Format("Pointers Count:{0}/{1}", MainPage.pointers.Count, TouchCapabilities.Contacts), textFormat2, new RectangleF(8, 30, 8 + 200, 30 + 16), sceneColorBrush);
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error:" + ex);
            }

            context2D.EndDraw();
        }
Ejemplo n.º 3
0
        // 繪圖主要方法
        public virtual void Render(TargetBase target)
        {
            var context2D = target.DeviceManager.ContextDirect2D;

            context2D.BeginDraw();
            context2D.Clear(Color.White);

            var sizeX = (float)target.RenderTargetBounds.Width;
            var sizeY = (float)target.RenderTargetBounds.Height;

            try
            {
                if (MainPage.pointers != null)
                {
                    for (int j = 0; j < MainPage.pointers.Count; j++)
                    {
                        // Different color for touch points
                        lineColorBrush = new SolidColorBrush(context2D, MainPage.pointers[j].color);

                        for (int i = 0; i < MainPage.pointers[j].Pointers.Count; i++)
                        {
                            if (i == MainPage.pointers[j].Pointers.Count - 1)
                            {
                                float x = (float)MainPage.pointers[j].Pointers[i].X;
                                float y = (float)MainPage.pointers[j].Pointers[i].Y;
                                // Pointers info
                                context2D.DrawText(string.Format("PointerID:{0}\nX:{1}\nY:{2}\n{3}", MainPage.pointers[j].PointerId, x, y, MainPage.pointers[j].DeviceType.ToString())
                                                   , textFormat, new RectangleF(x - 150, y - 100, x - 20, y - 20), sceneColorBrush);

                                // Draw horizontal line
                                context2D.DrawLine(new DrawingPointF(0, y), new DrawingPointF(context2D.PixelSize.Width, y), lineColorBrush);
                                // Draw vertical line
                                context2D.DrawLine(new DrawingPointF(x, 0), new DrawingPointF(x, context2D.PixelSize.Height), lineColorBrush);
                                // Draw a circle (and like a Crosshair :D )
                                ellipse = new Ellipse(new DrawingPointF(x, y), 30, 30);
                                context2D.DrawEllipse(ellipse, lineColorBrush);
                                continue;
                            }

                            var beginPoint = new DrawingPointF((float)MainPage.pointers[j].Pointers[i].X, (float)MainPage.pointers[j].Pointers[i].Y);
                            var endPoint   = new DrawingPointF((float)MainPage.pointers[j].Pointers[i + 1].X, (float)MainPage.pointers[j].Pointers[i + 1].Y);
                            context2D.DrawLine(beginPoint, endPoint, lineColorBrush, 10, strokeStyle);
                        }
                    }

                    // Update pointers contacts
                    context2D.DrawText(string.Format("Pointers Count:{0}/{1}", MainPage.pointers.Count, TouchCapabilities.Contacts), textFormat2, new RectangleF(8, 30, 8 + 200, 30 + 16), sceneColorBrush);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error:" + ex);
            }

            context2D.EndDraw();
        }
Ejemplo n.º 4
0
        public virtual void Render(TargetBase target)
        {
            if (!Show)
                return;

            frameCount++;
            var timeElapsed = (double)clock.ElapsedTicks / Stopwatch.Frequency; ;
            totalTime += timeElapsed;
            if (totalTime >= 1.0f)
            {
                measuredFPS = (double)frameCount / totalTime;
                frameCount = 0;
                totalTime = 0.0;
            }

            var context2D = target.DeviceManager.ContextDirect2D;

            context2D.BeginDraw();
            context2D.Transform = Matrix.Identity;
            context2D.DrawText(string.Format("{0:F2} FPS ({1:F1} ms)", measuredFPS, timeElapsed * 1000.0), textFormat, new RectangleF(8, 8, 8 + 256, 8 + 16), sceneColorBrush);
            context2D.EndDraw();

            clock.Restart();
        }