Example #1
0
        private static bool EnumMonitorsProc(IntPtr hMonitor, IntPtr hdcMonitor, ref RectStruct lprcMonitor, IntPtr dwData)
        {
            MonitorInfoEx mi = new MonitorInfoEx();

            mi.Size = (uint)Marshal.SizeOf(mi);

            bool success = GetMonitorInfo(hMonitor, ref mi);

            if (success)
            {
                ScreenInfo si = new ScreenInfo();
                si.MonitorArea     = Oblong.FromRectStruct(mi.Monitor);
                si.WorkArea        = Oblong.FromRectStruct(mi.WorkArea);
                si.DeviceName      = mi.DeviceName;
                si.IsPrimaryScreen = ((mi.Flags & MONITORINFOF_PRIMARY) == 1);;

                DEVMODE DeviceMode = new DEVMODE();
                DeviceMode.Initialize();

                if (EnumDisplaySettingsEx(ToLPTStr(mi.DeviceName), -1, ref DeviceMode))
                {
                    si.Scaling = Math.Round(((double)DeviceMode.dmPelsHeight / (mi.Monitor.bottom - mi.Monitor.top)) * 100);
                }

                si.NativeWorkArea = new Oblong((int)(mi.WorkArea.left * si.Scaling) / 100, (int)(mi.WorkArea.top * si.Scaling) / 100, (int)(mi.WorkArea.right * si.Scaling) / 100, (int)(mi.WorkArea.bottom * si.Scaling) / 100);
                si.NativeArea     = new Oblong((int)(mi.Monitor.left * si.Scaling) / 100, (int)(mi.Monitor.top * si.Scaling) / 100, (int)(mi.Monitor.right * si.Scaling) / 100, (int)(mi.Monitor.bottom * si.Scaling) / 100);

                Display.Screens.Add(si);
            }

            return(true);
        }
Example #2
0
        internal static Rect GetWindowBounds(IntPtr windowHandle)
        {
            RectStruct winRectStruct = new RectStruct();

            GetWindowRect(windowHandle, ref winRectStruct);
            Rect winRect = RectFromRectStruct(winRectStruct);

            return(winRect);
        }
Example #3
0
        private static bool MonitorEnumCallBack(IntPtr hMonitor, IntPtr hdcMonitor, ref RectStruct lprcMonitor, IntPtr dwData)
        {
            MonitorInfoEx mon_info = new MonitorInfoEx();

            mon_info.Init();
            mon_info.Size = Marshal.SizeOf(mon_info);
            GetMonitorInfo(hMonitor, ref mon_info);
            ///Monitor info is stored in 'mon_info'
            return(true);
        }
Example #4
0
        /// <summary>Return the position of the windows as X, Y coordinates</summary>
        public Point Position()
        {
            RectStruct rect = new RectStruct();

            GetWindowRect(this.Handle, ref rect);

            rect.Width  = rect.Right - rect.Left + Amount;
            rect.Height = rect.Bottom - rect.Top + Amount;
            return(new Point(rect.Left, rect.Top));
        }
Example #5
0
        internal static Rect GetWindowBounds(IntPtr windowHandle)
        {
            RectStruct winRectStruct = new RectStruct();

            GetWindowRect(windowHandle, ref winRectStruct);
            LogWin32Error("Error getting window rect.");
            Rect winRect = RectFromRectStruct(winRectStruct);

            return(winRect);
        }
Example #6
0
        /// <summary>Return the position and size of the windows as X, Y, with, height coordinates</summary>
        public Rect Area()
        {
            RectStruct rect = new RectStruct();

            GetWindowRect(this.Handle, ref rect);

            rect.Width  = rect.Right - rect.Left + Amount;
            rect.Height = rect.Bottom - rect.Top + Amount;
            return(new Rect(rect.Left, rect.Top, rect.Width, rect.Height));
        }
Example #7
0
        /// <summary>Move the current window with the given params</summary>
        /// <param name="X">New X coordinate of the current windows</param>
        /// <param name="Y">New Y coordinate of the current windows</param>
        public bool Move(int X, int Y)
        {
            RectStruct rect = new RectStruct();

            GetWindowRect(this.Handle, ref rect);

            rect.Width  = rect.Right - rect.Left + Amount;
            rect.Height = rect.Bottom - rect.Top + Amount;
            return(MoveWindow(this.Handle, X, Y, rect.Width, rect.Height, true));
        }
Example #8
0
        internal static Rect GetWindowPhysicalBounds(IntPtr windowHandle)
        {
            RectStruct winRect = new RectStruct();

            GetWindowRect(windowHandle, ref winRect);
            LogWin32Error("Error getting window rect." + " Top: " + winRect.Top + " Bottom: " + winRect.Bottom);
            POINT winTopLeft        = GetPhysicalPoint(windowHandle, new POINT(winRect.Left, winRect.Top));
            POINT win100            = GetPhysicalPoint(windowHandle, new POINT(winRect.Left + 100, winRect.Top));
            float scalingFactor     = (win100.X - winTopLeft.X) / 100f;
            Rect  winPhysicalBounds = new Rect(winTopLeft.X, winTopLeft.Y, Mathf.CeilToInt((winRect.Right - winRect.Left) * scalingFactor), Mathf.CeilToInt((winRect.Bottom - winRect.Top) * scalingFactor));

            return(winPhysicalBounds);
        }
Example #9
0
    StaticBody2D loadRectBody(StadiumObject stadiumObject, StaticBody2D body)
    {
        CollisionShape2D collider = new CollisionShape2D();

        RectangleShape2D shape      = new RectangleShape2D();
        RectStruct       rectStruct = (RectStruct)stadiumObject.ShapeStruct;

        shape.Extents  = new Godot.Vector2((float)rectStruct.Position.X / 2, (float)rectStruct.Position.Y / 2);
        collider.Shape = shape;
        body.AddChild(collider);

        return(body);
    }
Example #10
0
        public static WindowInfo GetWindowInfo(IntPtr hwnd)
        {
            RectStruct WindowRect          = new RectStruct();
            RectStruct ExtendedFrameBounds = new RectStruct();
            RectStruct Border = new RectStruct();
            WindowInfo result = new WindowInfo();
            WindowSize Size   = new WindowSize();
            WindowSize SizeExtendedFrameBounds = new WindowSize();

            int size = Marshal.SizeOf(typeof(RectStruct));

            if (GetWindowRect(hwnd, out WindowRect))
            {
                DwmGetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE.ExtendedFrameBounds, out ExtendedFrameBounds, size);
            }

            IntPtr        screen        = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
            MonitorInfoEx currentScreen = GetScreenFromWindow(hwnd);

            result.ScreenName    = currentScreen.DeviceName;
            result.ScalingFactor = getMonitorScaling(currentScreen);
            result.hwnd          = hwnd;

            // Update the rectangle with the current monitor scaling
            WindowRect.left   = (int)(WindowRect.left * result.ScalingFactor);
            WindowRect.top    = (int)(WindowRect.top * result.ScalingFactor);
            WindowRect.right  = (int)(WindowRect.right * result.ScalingFactor);
            WindowRect.bottom = (int)(WindowRect.bottom * result.ScalingFactor);

            // https://stackoverflow.com/questions/34139450/getwindowrect-returns-a-size-including-invisible-borders
            Border.left   = ExtendedFrameBounds.left - WindowRect.left;
            Border.top    = ExtendedFrameBounds.top - WindowRect.top;
            Border.right  = WindowRect.right - ExtendedFrameBounds.right;
            Border.bottom = WindowRect.bottom - ExtendedFrameBounds.bottom;

            result.WindowRect          = WindowRect;
            result.ExtendedFrameBounds = ExtendedFrameBounds;
            result.Border = Border;

            Size.height = WindowRect.bottom - WindowRect.top;
            Size.width  = WindowRect.right - WindowRect.left;

            SizeExtendedFrameBounds.height = ExtendedFrameBounds.bottom - ExtendedFrameBounds.top;
            SizeExtendedFrameBounds.width  = ExtendedFrameBounds.right - ExtendedFrameBounds.left;

            result.SizeWindow = Size;
            result.SizeExtendedFrameBounds = SizeExtendedFrameBounds;

            return(result);
        }
Example #11
0
        internal static Vector2 GetPhysicalPoint(Vector2 logicalPoint)
        {
            IntPtr     mainWindowHandle = GetProcessMainWindow();
            RectStruct winRect          = new RectStruct();

            GetWindowRect(mainWindowHandle, ref winRect);
            POINT winTopLeft    = GetPhysicalPoint(mainWindowHandle, new POINT(winRect.Left, winRect.Top));
            POINT win100        = GetPhysicalPoint(mainWindowHandle, new POINT(winRect.Left + 100, winRect.Top));
            float scalingFactor = (win100.X - winTopLeft.X) / 100f;

            Vector2 physicalPoint = logicalPoint * scalingFactor;

            physicalPoint.x = Mathf.RoundToInt(physicalPoint.x);
            physicalPoint.y = Mathf.RoundToInt(physicalPoint.y);
            return(physicalPoint);
        }
Example #12
0
        public void render(Shape.Rectangle rect, int thickness = 1, Brush color = null)
        {
            Pen pcolor;

            if (color == null)
            {
                pcolor = new Pen(Brushes.Black, thickness);
            }
            else
            {
                pcolor = new Pen(color, thickness);
            }
            RectStruct rs = new RectStruct(rect, pcolor);

            renderlist.Add(rs);
            renderct++;
        }
Example #13
0
 private static Rect RectFromRectStruct(RectStruct rectStruct)
 {
     return(new Rect(rectStruct.Left, rectStruct.Top, rectStruct.Right - rectStruct.Left, rectStruct.Bottom - rectStruct.Top));
 }
Example #14
0
 public static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out RectStruct pvAttribute, int cbAttribute);
Example #15
0
 /// <summary>
 /// Convert RectStruct from opencv to Unity space.
 /// bottom left = 0,1, top right = 0,1 in OpenCV
 /// bottom left = 0,0, top right = 1,1 in Unity
 /// </summary>
 /// <param name="rect">The rect to convert space.</param>
 /// <returns>The new rect.</returns>
 protected RectStruct ConvertRectToUnityScreen(RectStruct rect)
 {
     rect.y      = parameters.camera_height - rect.y;
     rect.height = -rect.height;
     return(rect);
 }
Example #16
0
 private static extern bool GetWindowRect(IntPtr hWnd, ref RectStruct rectangle);
Example #17
0
 public static extern bool GetClientRect(IntPtr hWnd, out RectStruct lpRect);
Example #18
0
 public static extern bool GetWindowRect(IntPtr hwnd, ref RectStruct rect);
Example #19
0
    /// <summary>
    /// Start point.
    /// </summary>
    protected void OnEnable()
    {
        DebugTargets[] debugs = gameObject.GetComponents <DebugTargets>();
        if (debugs.Length > 0)
        {
            Debug.LogError("Debug create dynamically, component will be removed.");
            foreach (DebugTargets debug in debugs)
            {
                DestroyImmediate(debug);
            }
        }

        Debug.Log("Start tracking.");

        //File calibration
        if (parameters.use_file_calibration)
        {
            string path = Path.Combine(Application.streamingAssetsPath, parameters.path_subfolder_calibration);
            if (!Directory.Exists(path))
            {
                throw new System.Exception("Folder " + path + " does not exist.");
            }
            if (!CARDSCalibrationPlugin.GetPoseParametersWrapped(path, ref parameters.calibration))
            {
                throw new System.Exception("Loading parameters " + path + " failed.");
            }
        }
        else if (parameters.device_index != -1)
        {
            Debug.LogWarning("Not recommended to not use calibrtation file in other context than virtual.");
        }

        // Init video
        if (parameters.UseWebcam)
        {
            video = new WebcamTexture();
            gameObject.AddComponent <DebugTargetsWebcam>();
        }
        else if (parameters.device_index == -1)
        {
            video = new VirtualCameraTexture();
            gameObject.AddComponent <DebugTargetsVirtual>();
        }
        else if (parameters.device_index == -2)
        {
            video = new VideoFileTexture();
            gameObject.AddComponent <DebugTargetsVideo>();
        }
        video.Init(parameters);

        // Init plugin
        unsafe
        {
            fixed(Target *outTargets = targets)
            {
                CARDSTrackingPlugin.InitWrapped(outTargets, ref nb_targets, max_targets);
            }
        }

        //Init detection
        if (parameters.use_detection)
        {
            zone_detection = ConvertUnityScreenToRect(parameters.rect_detection);
        }

        nb_frame = -1;
    }
Example #20
0
 public static extern bool GetWindowRect(IntPtr hwnd, out RectStruct lpRect);
 protected Vector2 GetCenterScreenTarget(RectStruct rect)
 {
     return(new Vector2(rect.x + (rect.width / 2.0f), (rect.y + (rect.height / 2.0f))));
 }
Example #22
0
 // This method takes a Win32 RECT-style struct (with exclusive values
 // for Right and Bottom) and returns a new Oblong (with inclusive values
 // for Right and Bottom).
 public static Oblong FromRectStruct(RectStruct rectStruct)
 {
     return(new Oblong(rectStruct.left, rectStruct.top,
                       rectStruct.right - 1, rectStruct.bottom - 1));
 }
Example #23
0
 public static extern int Shell_NotifyIconGetRect([In] ref NOTIFYICONIDENTIFIER identifier, [Out] out RectStruct iconLocation);
        private bool MonitorEnum(IntPtr hMonitor, IntPtr hdcMonitor, ref RectStruct lprcMonitor, IntPtr dwData)
        {
            MonitorInfo mi = new MonitorInfo();
            mi.size = (uint)Marshal.SizeOf(mi);
            GetMonitorInfo(hMonitor, ref mi);

            bool isPrimary = (mi.flags == 1) ? true : false;

            Rectangle bounds = new Rectangle(mi.monitor.left, mi.monitor.top,
                mi.monitor.right - mi.monitor.left, mi.monitor.bottom - mi.monitor.top);

            Screen screen = new Screen(m_screens.Count, bounds, isPrimary);

            if (isPrimary) m_primary = m_screens.Count;

            m_screens.Add(screen);

            return true;
        }