Esempio n. 1
0
 private void Mv_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintGLSurfaceEventArgs e)
 {
     e.Surface.Canvas.DrawRect(100, 100, 500, 500, new SKPaint {
         Color = SKColors.Pink
     });
     Debug.WriteLine($"GRContext: {mv.GRContext}");
 }
Esempio n. 2
0
 // the native view tells the user to repaint
 protected virtual void OnPaintSurface(SKPaintGLSurfaceEventArgs e)
 {
     PaintSurface?.Invoke(this, e);
 }
Esempio n. 3
0
 void ISKGLViewController.OnPaintSurface(SKPaintGLSurfaceEventArgs e)
 {
     OnPaintSurface(e);
 }
Esempio n. 4
0
        private void SkCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintGLSurfaceEventArgs e) // .SKPaintSurfaceEventArgs // SKPaintGLSurfaceEventArgs
        {
            try
            {
                var surface = e.Surface;

                e.Surface.Canvas.Clear(SKColors.Gray);

                surface.Canvas.DrawCircle(0, 0, 50, new SKPaint()
                {
                    Color = SKColor.Parse("ff0000")
                });

                e.Surface.Canvas.Scale((float)scale.Width, (float)scale.Height);

                Func <IntPtr, bool> func = null;
                func = (handle) =>
                {
                    var hwnd = Hwnd.ObjectFromHandle(handle);

                    var x = 0;
                    var y = 0;

                    XplatUI.driver.ClientToScreen(hwnd.client_window, ref x, ref y);

                    var width         = 0;
                    var height        = 0;
                    var client_width  = 0;
                    var client_height = 0;


                    if (hwnd.hwndbmp != null && hwnd.Mapped && hwnd.Visible && !hwnd.zombie)
                    {
                        // setup clip
                        var parent = hwnd;
                        surface.Canvas.ClipRect(
                            SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width,
                                          Screen.PrimaryScreen.Bounds.Height), (SKClipOperation)5);

                        while (parent != null)
                        {
                            var xp = 0;
                            var yp = 0;
                            XplatUI.driver.ClientToScreen(parent.client_window, ref xp, ref yp);

                            surface.Canvas.ClipRect(SKRect.Create(xp, yp, parent.Width, parent.Height),
                                                    SKClipOperation.Intersect);

                            /*
                             * surface.Canvas.DrawRect(xp, yp, parent.Width, parent.Height,
                             *  new SKPaint()
                             *  {
                             *
                             *      Color = new SKColor(255, 0, 0),
                             *      Style = SKPaintStyle.Stroke
                             *
                             *
                             *  });
                             */
                            parent = parent.parent;
                        }

                        Monitor.Enter(XplatUIMine.paintlock);

                        if (hwnd.ClientWindow != hwnd.WholeWindow)
                        {
                            var frm = Control.FromHandle(hwnd.ClientWindow) as Form;

                            Hwnd.Borders borders = new Hwnd.Borders();

                            if (frm != null)
                            {
                                borders = Hwnd.GetBorders(frm.GetCreateParams(), null);

                                surface.Canvas.ClipRect(
                                    SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width,
                                                  Screen.PrimaryScreen.Bounds.Height), (SKClipOperation)5);
                            }

                            if (surface.Canvas.DeviceClipBounds.Width > 0 &&
                                surface.Canvas.DeviceClipBounds.Height > 0)
                            {
                                surface.Canvas.DrawImage(hwnd.hwndbmpNC,
                                                         new SKPoint(x - borders.left, y - borders.top),
                                                         new SKPaint()
                                {
                                    FilterQuality = SKFilterQuality.Low
                                });

                                surface.Canvas.ClipRect(
                                    SKRect.Create(x, y, hwnd.width - borders.right - borders.left,
                                                  hwnd.height - borders.top - borders.bottom), SKClipOperation.Intersect);

                                surface.Canvas.DrawImage(hwnd.hwndbmp,
                                                         new SKPoint(x, y),
                                                         new SKPaint()
                                {
                                    FilterQuality = SKFilterQuality.Low
                                });
                            }
                            else
                            {
                                Monitor.Exit(XplatUIMine.paintlock);
                                return(true);
                            }
                        }
                        else
                        {
                            if (surface.Canvas.DeviceClipBounds.Width > 0 &&
                                surface.Canvas.DeviceClipBounds.Height > 0)
                            {
                                surface.Canvas.DrawImage(hwnd.hwndbmp,
                                                         new SKPoint(x + 0, y + 0),
                                                         new SKPaint()
                                {
                                    FilterQuality = SKFilterQuality.Low
                                });
                            }
                            else
                            {
                                Monitor.Exit(XplatUIMine.paintlock);
                                return(true);
                            }
                        }

                        Monitor.Exit(XplatUIMine.paintlock);
                    }

                    //surface.Canvas.DrawText(x + " " + y, x, y+10, new SKPaint() { Color =  SKColors.Red});

                    if (hwnd.Mapped && hwnd.Visible)
                    {
                        IEnumerable <Hwnd> children;
                        lock (Hwnd.windows)
                            children = Hwnd.windows.OfType <System.Collections.DictionaryEntry>()
                                       .Where(hwnd2 =>
                            {
                                var Key   = (IntPtr)hwnd2.Key;
                                var Value = (Hwnd)hwnd2.Value;
                                if (Value.ClientWindow == Key && Value.Parent == hwnd && Value.Visible &&
                                    Value.Mapped && !Value.zombie)
                                {
                                    return(true);
                                }
                                return(false);
                            }).Select(a => (Hwnd)a.Value).ToArray();

                        foreach (var child in children)
                        {
                            func(child.ClientWindow);
                        }
                    }

                    return(true);
                };

                foreach (Form form in Application.OpenForms.Select(a => a).ToArray())
                {
                    if (form.IsHandleCreated)
                    {
                        if (form is MainV2 && form.WindowState != FormWindowState.Maximized)
                        {
                            form.WindowState = FormWindowState.Maximized;
                        }

                        if (form.WindowState == FormWindowState.Maximized)
                        {
                            var border = Hwnd.GetBorders(form.GetCreateParams(), null);

                            //XplatUI.driver.SetWindowPos(form.Handle, 0, 0, (int) Screen.PrimaryScreen.Bounds.Width + border.right + border.left,                            (int) Screen.PrimaryScreen.Bounds.Height + border.top + border.bottom);
                        }
                        else
                        {
                            if (form.Location.X < 0 || form.Location.Y < 0)
                            {
                                form.Location = new Point(Math.Max(form.Location.X, 0), Math.Max(form.Location.Y, 0));
                            }

                            var border = Hwnd.GetBorders(form.GetCreateParams(), null);

                            if (form.Size.Width > Screen.PrimaryScreen.Bounds.Width ||
                                form.Size.Height > Screen.PrimaryScreen.Bounds.Height)
                            {
                                //form.Size = new System.Drawing.Size((int) Screen.PrimaryScreen.Bounds.Width, (int) Screen.PrimaryScreen.Bounds.Height);
                                XplatUI.driver.SetWindowPos(form.Handle, 0, 0, (int)Screen.PrimaryScreen.Bounds.Width,
                                                            (int)Screen.PrimaryScreen.Bounds.Height);
                            }
                        }

                        try
                        {
                            func(form.Handle);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                }

                IEnumerable <Hwnd> menu;
                lock (Hwnd.windows)
                    menu = Hwnd.windows.Values.OfType <Hwnd>()
                           .Where(hw => hw.topmost && hw.Mapped && hw.Visible).ToArray();
                foreach (Hwnd hw in menu)
                {
                    if (hw.topmost && hw.Mapped && hw.Visible)
                    {
                        var ctlmenu = Control.FromHandle(hw.ClientWindow);
                        if (ctlmenu != null)
                        {
                            func(hw.ClientWindow);
                        }
                    }
                }

                {
                    surface.Canvas.ClipRect(
                        SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width,
                                      Screen.PrimaryScreen.Bounds.Height), (SKClipOperation)5);

                    var path = new SKPath();

                    path.MoveTo(cursorPoints.First());
                    cursorPoints.ForEach(a => path.LineTo(a));
                    path.Transform(new SKMatrix(1, 0, XplatUI.driver.MousePosition.X, 0, 1,
                                                XplatUI.driver.MousePosition.Y, 0, 0, 1));

                    surface.Canvas.DrawPath(path,
                                            new SKPaint()
                    {
                        Color = SKColors.White, Style = SKPaintStyle.Fill, StrokeJoin = SKStrokeJoin.Miter
                    });
                    surface.Canvas.DrawPath(path,
                                            new SKPaint()
                    {
                        Color = SKColors.Black, Style = SKPaintStyle.Stroke, StrokeJoin = SKStrokeJoin.Miter, IsAntialias = true
                    });
                }

                surface.Canvas.Flush();

                return;

                surface.Canvas.ClipRect(new SKRect(0, 0, Screen.PrimaryScreen.Bounds.Right,
                                                   Screen.PrimaryScreen.Bounds.Bottom), (SKClipOperation)5);

                surface.Canvas.DrawText("PixelScreenSize " + Device.Info.PixelScreenSize.ToString(),
                                        new SKPoint(50, 10), new SKPaint()
                {
                    Color = SKColor.Parse("ffff00")
                });


                surface.Canvas.DrawText("screen " + Screen.PrimaryScreen.ToString(), new SKPoint(50, 30),
                                        new SKPaint()
                {
                    Color = SKColor.Parse("ffff00")
                });

                int mx = 0, my = 0;
                XplatUI.driver.GetCursorPos(IntPtr.Zero, out mx, out my);

                surface.Canvas.DrawText("mouse " + XplatUI.driver.MousePosition.ToString(), new SKPoint(50, 50),
                                        new SKPaint()
                {
                    Color = SKColor.Parse("ffff00")
                });
                surface.Canvas.DrawText(mx + " " + my, new SKPoint(50, 70),
                                        new SKPaint()
                {
                    Color = SKColor.Parse("ffff00")
                });


                if (Application.OpenForms.Count > 0 &&
                    Application.OpenForms[Application.OpenForms.Count - 1].IsHandleCreated)
                {
                    var x = XplatUI.driver.MousePosition.X;
                    var y = XplatUI.driver.MousePosition.Y;

                    XplatUI.driver.ScreenToClient(Application.OpenForms[Application.OpenForms.Count - 1].Handle, ref x,
                                                  ref y);

                    var ctl = XplatUIMine.FindControlAtPoint(Application.OpenForms[Application.OpenForms.Count - 1],
                                                             new Point(x, y));
                    if (ctl != null)
                    {
                        XplatUI.driver.ScreenToClient(ctl.Handle, ref mx, ref my);
                        surface.Canvas.DrawText("client " + mx + " " + my, new SKPoint(50, 90),
                                                new SKPaint()
                        {
                            Color = SKColor.Parse("ffff00")
                        });

                        surface.Canvas.DrawText(ctl?.ToString(), new SKPoint(50, 130),
                                                new SKPaint()
                        {
                            Color = SKColor.Parse("ffff00")
                        });

                        var hwnd = Hwnd.ObjectFromHandle(ctl.Handle);

                        surface.Canvas.DrawText(ctl.Location.ToString(), new SKPoint(50, 150),
                                                new SKPaint()
                        {
                            Color = SKColor.Parse("ffff00")
                        });
                    }
                }

                surface.Canvas.DrawText("!", new SKPoint(XplatUI.driver.MousePosition.X,
                                                         XplatUI.driver.MousePosition.Y),
                                        new SKPaint()
                {
                    Color = SKColor.Parse("ffff00")
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
            }
        }