Exemplo n.º 1
0
        private void StartThreads()
        {
            size = Device.Info.ScaledScreenSize;
            size = Device.Info.PixelScreenSize;

            size  = new Forms.Size(885, 500); // 1.77
            scale = new Forms.Size((Device.Info.PixelScreenSize.Width / size.Width),
                                   (Device.Info.PixelScreenSize.Height / size.Height));

            XplatUIMine.GetInstance()._virtualScreen = new Rectangle(0, 0, (int)size.Width, (int)size.Height);
            XplatUIMine.GetInstance()._workingArea   = new Rectangle(0, 0, (int)size.Width, (int)size.Height);

            new Thread(() =>
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                MissionPlanner.Program.Main(new string[0]);
            }).Start();

            Forms.Device.StartTimer(TimeSpan.FromMilliseconds(1000 / 30), () =>
            {
                Monitor.Enter(XplatUIMine.paintlock);
                if (XplatUIMine.PaintPending)
                {
                    this.SkCanvasView.InvalidateSurface();
                    XplatUIMine.PaintPending = false;
                }
                Monitor.Exit(XplatUIMine.paintlock);

                return(true);
            });
        }
Exemplo n.º 2
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            SkCanvasView.IgnorePixelScaling = false;
            StartThreads();

            XplatUIMine.GetInstance().Keyboard = new Keyboard(Entry);
        }
Exemplo n.º 3
0
        protected override void OnAppearing()
        {
            if (!start)
            {
                StartThreads();

                XplatUIMine.GetInstance().Keyboard = new Keyboard(Entry);
                start = true;
            }

            SkCanvasView.InvalidateSurface();

            base.OnAppearing();
        }
Exemplo n.º 4
0
        private void StartThreads()
        {
            size = Device.Info.ScaledScreenSize;
            size = Device.Info.PixelScreenSize;

            size  = new Forms.Size(900, 540); // 1.66 - remove back and home pane
            scale = new Forms.Size((Device.Info.PixelScreenSize.Width / size.Width),
                                   (Device.Info.PixelScreenSize.Height / size.Height));

            XplatUIMine.GetInstance()._virtualScreen = new Rectangle(0, 0, (int)size.Width, (int)size.Height);
            XplatUIMine.GetInstance()._workingArea   = new Rectangle(0, 0, (int)size.Width, (int)size.Height);

            winforms = new Thread(() =>
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                Application.Idle += (sender, args) => Thread.Sleep(0);

                MissionPlanner.Program.Main(new string[0]);
            });
            winforms.Start();

            Forms.Device.StartTimer(TimeSpan.FromMilliseconds(1000 / 30), () =>
            {
                Monitor.Enter(XplatUIMine.paintlock);
                if (XplatUIMine.PaintPending)
                {
                    if (SkCanvasView != null)
                    {
                        scale = new Forms.Size((Instance.SkCanvasView.CanvasSize.Width / size.Width),
                                               (Instance.SkCanvasView.CanvasSize.Height / size.Height));

                        XplatUIMine.GetInstance()._virtualScreen =
                            new Rectangle(0, 0, (int)size.Width, (int)size.Height);
                        XplatUIMine.GetInstance()._workingArea =
                            new Rectangle(0, 0, (int)size.Width, (int)size.Height);

                        Device.BeginInvokeOnMainThread(() => { Instance.SkCanvasView.InvalidateSurface(); });
                        XplatUIMine.PaintPending = false;
                    }
                }
                Monitor.Exit(XplatUIMine.paintlock);

                return(true);
            });
        }
Exemplo n.º 5
0
        private static void OnMouseButton(object sender, MouseButtonEventArgs e)
        {
            if (e.Button == MouseButton.Left)
            {
                if (e.Action == InputState.Press)
                {
                    XplatUIMine.GetInstance()
                    .SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, IntPtr.Zero,
                                 new IntPtr(Program.lastMousePosition.Value.X + (Program.lastMousePosition.Value.Y << 16)));
                    XplatUIMine.GetInstance()
                    .SendMessage(IntPtr.Zero, Msg.WM_LBUTTONDOWN, new IntPtr((int)MsgButtons.MK_LBUTTON),
                                 new IntPtr(Program.lastMousePosition.Value.X + (Program.lastMousePosition.Value.Y << 16)));
                }

                if (e.Action == InputState.Release)
                {
                    XplatUIMine.GetInstance()
                    .SendMessage(IntPtr.Zero, Msg.WM_LBUTTONUP, new IntPtr((int)MsgButtons.MK_LBUTTON),
                                 new IntPtr(Program.lastMousePosition.Value.X + (Program.lastMousePosition.Value.Y << 16)));
                }
            }
            if (e.Button == MouseButton.Right)
            {
                if (e.Action == InputState.Press)
                {
                    XplatUIMine.GetInstance()
                    .SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, IntPtr.Zero,
                                 new IntPtr(Program.lastMousePosition.Value.X + (Program.lastMousePosition.Value.Y << 16)));
                    XplatUIMine.GetInstance()
                    .SendMessage(IntPtr.Zero, Msg.WM_RBUTTONDOWN, new IntPtr((int)MsgButtons.MK_RBUTTON),
                                 new IntPtr(Program.lastMousePosition.Value.X + (Program.lastMousePosition.Value.Y << 16)));
                }

                if (e.Action == InputState.Release)
                {
                    XplatUIMine.GetInstance()
                    .SendMessage(IntPtr.Zero, Msg.WM_RBUTTONUP, new IntPtr((int)MsgButtons.MK_RBUTTON),
                                 new IntPtr(Program.lastMousePosition.Value.X + (Program.lastMousePosition.Value.Y << 16)));
                }
            }
        }
Exemplo n.º 6
0
        private void SkCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            try
            {
                var surface = e.Surface;

                e.Surface.Canvas.Clear();

                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;

                    Monitor.Enter(XplatUIMine.paintlock);
                    if (hwnd.hwndbmp != null && hwnd.Mapped && hwnd.Visible)
                    {
                        if (hwnd.ClientWindow != hwnd.WholeWindow)
                        {
                            surface.Canvas.DrawImage(hwnd.hwndbmpNC.ToSKImage(), new SKPoint(hwnd.X, hwnd.Y - XplatUI.CaptionHeight), new SKPaint()
                            {
                                FilterQuality = SKFilterQuality.Low
                            });
                        }
                        surface.Canvas.DrawImage(hwnd.hwndbmp.ToSKImage(), new SKPoint(x + hwnd.ClientRect.X, y + hwnd.ClientRect.Y), new SKPaint()
                        {
                            FilterQuality = SKFilterQuality.Low
                        });
                    }
                    Monitor.Exit(XplatUIMine.paintlock);

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

                    if (hwnd.Mapped && hwnd.Visible)
                    {
                        var enumer = Hwnd.windows.GetEnumerator();
                        while (enumer.MoveNext())
                        {
                            var hwnd2 = (System.Collections.DictionaryEntry)enumer.Current;
                            var Key   = (IntPtr)hwnd2.Key;
                            var Value = (Hwnd)hwnd2.Value;
                            if (Value.ClientWindow == Key && Value.Parent == hwnd && Value.Visible && Value.Mapped)
                            {
                                func(Value.ClientWindow);
                            }
                        }
                    }

                    return(true);
                };

                foreach (Form form in Application.OpenForms)
                {
                    if (form.IsHandleCreated)
                    {
                        if (form.Location.X < 0 || form.Location.Y < 0)
                        {
                            form.Location = Point.Empty;
                        }

                        if (form.Size.Width > size.Width || form.Size.Height > size.Height)
                        {
                            form.Size = new System.Drawing.Size((int)size.Width, (int)size.Height);
                        }

                        try
                        {
                            func(form.Handle);
                        }
                        finally
                        {
                        }
                    }
                }

                foreach (Hwnd hw in Hwnd.windows.Values)
                {
                    if (hw.topmost && hw.Mapped && hw.Visible)
                    {
                        var ctlmenu = Control.FromHandle(hw.ClientWindow);
                        if (ctlmenu != null)
                        {
                            func(hw.ClientWindow);
                        }
                    }
                }


                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 { }
        }
Exemplo n.º 7
0
        private void StartThreads()
        {
            size = Device.Info.ScaledScreenSize;
            size = Device.Info.PixelScreenSize;

            size  = new Forms.Size(1280, 720);
            scale = new Forms.Size((Device.Info.PixelScreenSize.Width / size.Width),
                                   (Device.Info.PixelScreenSize.Height / size.Height));

            XplatUIMine.GetInstance()._virtualScreen = new Rectangle(0, 0, (int)size.Width, (int)size.Height);
            XplatUIMine.GetInstance()._workingArea   = new Rectangle(0, 0, (int)size.Width, (int)size.Height);

            new Thread(() =>
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                MissionPlanner.Program.Main(new string[0]);

                MessageBox.Show("Application Exit");

                return;

                var frm = new Form()
                {
                    Width    = (int)Forms.Application.Current.MainPage.Width,
                    Height   = (int)Forms.Application.Current.MainPage.Height,
                    Location = new System.Drawing.Point(0, 0)
                };

                frm.Controls.Add(new Label()
                {
                    Text = "this is a test", Location = new System.Drawing.Point(frm.Width / 2, frm.Height / 2)
                });

                /*
                 * frm.Controls.Add(new RadioButton());
                 * frm.Controls.Add(new CheckBox());
                 * frm.Controls.Add(new ComboBox());
                 * frm.Controls.Add(new DomainUpDown());
                 * frm.Controls.Add(new DataGridView());
                 * frm.Controls.Add(new TextBox());
                 */
                var param = new ConfigRawParams()
                {
                    Location = new System.Drawing.Point(0, 0), Size = new System.Drawing.Size(frm.Width, frm.Height)
                };
                frm.Controls.Add(param);

                frm.Shown += (sender, args) => { param.Activate(); };

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                Application.Run(frm);
            }).Start();

            Forms.Device.StartTimer(TimeSpan.FromMilliseconds(100), () =>
            {
                this.SkCanvasView.InvalidateSurface();
                return(true);
            });

            this.SkCanvasView.PaintSurface += SkCanvasView_PaintSurface;

            this.SkCanvasView.EnableTouchEvents = true;
            this.SkCanvasView.Touch            += SkCanvasView_Touch;
        }
Exemplo n.º 8
0
            private bool DrawOntoCanvas(IntPtr handle, SKCanvas Canvas, bool forcerender = false)
            {
                var hwnd = Hwnd.ObjectFromHandle(handle);

                var x        = 0;
                var y        = 0;
                var wasdrawn = false;

                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;
                    Canvas.ClipRect(
                        SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width * 2,
                                      Screen.PrimaryScreen.Bounds.Height * 2), (SKClipOperation)5);

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

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

                        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);

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

                        if (Canvas.DeviceClipBounds.Width > 0 &&
                            Canvas.DeviceClipBounds.Height > 0)
                        {
                            if (hwnd.DrawNeeded || forcerender)
                            {
                                if (hwnd.hwndbmpNC != null)
                                {
                                    Canvas.DrawImage(hwnd.hwndbmpNC,
                                                     new SKPoint(x - borders.left, y - borders.top), paint);
                                }

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

                                Canvas.DrawImage(hwnd.hwndbmp,
                                                 new SKPoint(x, y), paint);

                                wasdrawn = true;
                            }

                            hwnd.DrawNeeded = false;
                        }
                        else
                        {
                            Monitor.Exit(XplatUIMine.paintlock);
                            return(true);
                        }
                    }
                    else
                    {
                        if (Canvas.DeviceClipBounds.Width > 0 &&
                            Canvas.DeviceClipBounds.Height > 0)
                        {
                            if (hwnd.DrawNeeded || forcerender)
                            {
                                Canvas.DrawImage(hwnd.hwndbmp,
                                                 new SKPoint(x + 0, y + 0), paint);

                                wasdrawn = true;
                            }

                            hwnd.DrawNeeded = false;

/*
 *                      surface.Canvas.DrawText(Control.FromHandle(hwnd.ClientWindow).Name,
 *                          new SKPoint(x, y + 15),
 *                          new SKPaint() {Color = SKColor.Parse("55ffff00")});
 *                      /*surface.Canvas.DrawText(hwnd.ClientWindow.ToString(), new SKPoint(x,y+15),
 *                          new SKPaint() {Color = SKColor.Parse("ffff00")});*/
                        }
                        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();

                    children = children.OrderBy((hwnd2) =>
                    {
                        var info = XplatUIMine.GetInstance().GetZOrder(hwnd2.client_window);
                        if (info.top)
                        {
                            return(1000);
                        }
                        if (info.bottom)
                        {
                            return(0);
                        }
                        return(500);
                    });

                    foreach (var child in children)
                    {
                        DrawOntoCanvas(child.ClientWindow, Canvas, true);
                    }
                }

                return(true);
            }
Exemplo n.º 9
0
        protected void OnSkiaPaint(SKSurface e)
        {
            try
            {
                var surface = e;

                surface.Canvas.Clear(SKColors.Gray);

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

                surface.Canvas.Scale((float)scale.Width, (float)scale.Height);

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

                        try
                        {
                            DrawOntoSurface(form.Handle, surface);
                        }
                        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 = System.Windows.Forms.Control.FromHandle(hw.ClientWindow);
                        if (ctlmenu != null)
                        {
                            DrawOntoSurface(hw.ClientWindow, surface);
                        }
                    }
                }

                {
                    surface.Canvas.ClipRect(
                        SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width * 2,
                                      Screen.PrimaryScreen.Bounds.Height * 2), (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 * 2,
                                                   Screen.PrimaryScreen.Bounds.Bottom * 2), (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.DrawRect(x, y, ctl.Width, ctl.Height, new SKPaint()
                        {
                            Color = SKColors.Red, Style = SKPaintStyle.Stroke
                        });

                        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
            {
            }
        }
Exemplo n.º 10
0
            protected override void OnSkiaPaint(SKSurface e)
            {
                try
                {
                    var canvas = e.Canvas;

                    canvas.Clear(SKColors.Gray);

                    canvas.Scale((float)scale.Width, (float)scale.Height);

                    canvas.Save();

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

                            try
                            {
                                DrawOntoCanvas(form.Handle, canvas, true);
                            }
                            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)
                    {
                        var ctlmenu = Control.FromHandle(hw.ClientWindow);
                        if (ctlmenu != null)
                        {
                            DrawOntoCanvas(hw.ClientWindow, canvas, true);
                        }
                    }

                    canvas.Restore();

                    //if (Device.RuntimePlatform != Device.macOS && Device.RuntimePlatform != Device.UWP)
                    {/*
                      * canvas.ClipRect(
                      *     SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width,
                      *         Screen.PrimaryScreen.Bounds.Height), SKClipOperation.Intersect);
                      */
                        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));

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


                        {
                            Control ctl = null;

                            var cnt = Application.OpenForms.Count;
                            while (cnt > 0 && ctl == null)
                            {
                                int x = XplatUI.driver.MousePosition.X, y = XplatUI.driver.MousePosition.Y;

                                var hwnd = Hwnd.ObjectFromHandle(Application.OpenForms[cnt - 1].Handle);
                                if (x < hwnd.X || y < hwnd.Y || x > hwnd.x + hwnd.width || y > hwnd.y + hwnd.height)
                                {
                                    cnt--;
                                    continue;
                                }

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

                                ctl = XplatUIMine.FindControlAtPoint(Application.OpenForms[cnt - 1],
                                                                     new Point(x, y));
                                if (ctl == null)
                                {
                                    ctl = Application.OpenForms[cnt - 1];
                                }

                                cnt--;
                            }

                            canvas.DrawText("" + ctl?.Name + "HERE!!!",
                                            new SKPoint(100, 100), new SKPaint()
                            {
                                Color = SKColor.Parse("ffff00")
                            });
                        }
                    }

                    canvas.DrawText("" + DateTime.Now.ToString("HH:mm:ss.fff"),
                                    new SKPoint(10, 10), new SKPaint()
                    {
                        Color = SKColor.Parse("ffff00")
                    });

                    canvas.Flush();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                }
            }
Exemplo n.º 11
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
            {
            }
        }