Ejemplo n.º 1
0
        private void Awake()
        {
            bgImage         = GetComponent <Image>();
            bgImage.enabled = false;
            rootRT          = SimulatorManager.Instance.UIManager.VisualizerCanvasGO.GetComponent <RectTransform>();
            HeaderRT.gameObject.SetActive(false);
            ContractTextGO.SetActive(false);
            ExpandTextGO.SetActive(false);
            windowSize            = new Vector2(Screen.width / 4f, Screen.height / 4f);
            fullSize              = new Vector2(Screen.width, Screen.height);
            rt                    = GetComponent <RectTransform>();
            headerAnchoredYPos    = HeaderRT.anchoredPosition.y;
            CurrentWindowSizeType = WindowSizeType.Window;

            CameraRawImage = CameraVisualGO.GetComponentInChildren <RawImage>();
            cameraRT       = CameraVisualGO.GetComponent <RectTransform>();
            ValuesText     = ValuesVisualGO.GetComponent <Text>();
            fitter         = CameraVisualGO.GetComponentInChildren <AspectRatioFitter>();
            windowResizers = GetComponentsInChildren <VisualizerWindowResize>(true).ToList();
            windowResizers.ForEach(win => win.gameObject.SetActive(true));
            CameraVisualGO.SetActive(false);
            ValuesVisualGO.SetActive(false);

            UpdateWindowSize((int)CurrentWindowSizeType);
        }
Ejemplo n.º 2
0
        public void UpdateWindowSize(int type = -1)
        {
            CurrentWindowSizeType = type == -1 ? ((int)CurrentWindowSizeType == System.Enum.GetValues(typeof(WindowSizeType)).Length - 1) ? 0 : CurrentWindowSizeType + 1 : (WindowSizeType)type;

            switch (CurrentWindowSizeType)
            {
            case WindowSizeType.Small:
                rt.sizeDelta = smallSize;
                HeaderRT.anchoredPosition = new Vector2(0f, headerAnchoredYPos);
                ContractTextGO.SetActive(false);
                ExpandTextGO.SetActive(true);
                break;

            case WindowSizeType.Medium:
                rt.sizeDelta = medSize;
                HeaderRT.anchoredPosition = new Vector2(0f, headerAnchoredYPos);
                ContractTextGO.SetActive(false);
                ExpandTextGO.SetActive(true);
                break;

            case WindowSizeType.Full:
                HeaderRT.anchoredPosition = new Vector2(0f, -headerAnchoredYPos);
                rt.sizeDelta     = fullSize;
                rt.localPosition = Vector2.zero;
                ContractTextGO.SetActive(true);
                ExpandTextGO.SetActive(false);
                break;

            default:
                Debug.LogError("WindowSizeType out of bounds");
                break;
            }
        }
Ejemplo n.º 3
0
        public void UpdateWindowSize(int type = -1)
        {
            CurrentWindowSizeType = type == -1 ? ((int)CurrentWindowSizeType == System.Enum.GetValues(typeof(WindowSizeType)).Length - 1) ? 0 : CurrentWindowSizeType + 1 : (WindowSizeType)type;

            switch (CurrentWindowSizeType)
            {
            case WindowSizeType.Window:
                rt.sizeDelta              = windowSize;
                rt.localPosition          = windowPosition;
                HeaderRT.anchoredPosition = new Vector2(0f, headerAnchoredYPos);
                ContractTextGO.SetActive(false);
                ExpandTextGO.SetActive(true);
                windowResizers.ForEach(win => win.gameObject.SetActive(true));
                break;

            case WindowSizeType.Full:
                rt.sizeDelta              = fullSize;
                rt.localPosition          = new Vector3(-fullSize.x / 2, fullSize.y / 2, 0f);
                HeaderRT.anchoredPosition = new Vector2(0f, -headerAnchoredYPos);
                ContractTextGO.SetActive(true);
                ExpandTextGO.SetActive(false);
                windowResizers.ForEach(win => win.gameObject.SetActive(false));
                break;
            }
        }
Ejemplo n.º 4
0
        private void Init(int x, int y, int width, int height, WindowSizeType sizeType, WindowType type, WindowStartupPosition startupPosition)
        {
            // set form type
            switch (type)
            {
            case WindowType.Tool:
                form.MaximizeBox     = false;
                form.MinimizeBox     = false;
                form.FormBorderStyle = FormBorderStyle.FixedSingle;
                break;

            case WindowType.Popup:
                form.MaximizeBox     = false;
                form.MinimizeBox     = false;
                form.FormBorderStyle = FormBorderStyle.None;
                break;
            }

            // set form size
            SetSize(width, height, sizeType);

            // set form startup position
            switch (startupPosition)
            {
            case WindowStartupPosition.Custom:
                form.StartPosition = FormStartPosition.Manual;
                SetPosition(x, y);
                break;

            case WindowStartupPosition.CenterScreen:
                form.StartPosition = FormStartPosition.CenterScreen;
                break;
            }
        }
Ejemplo n.º 5
0
        public override void SetSize(int width, int height, WindowSizeType type)
        {
            if (type == WindowSizeType.WorkingArea)
            {
                var rect = new RECT();
                if (GetWindowRect(hWnd, &rect) == 0)
                {
                    return;
                }
                int rectWidth  = rect.right - rect.left;
                int rectHeight = rect.bottom - rect.top;

                var clientRect = new RECT();
                if (GetClientRect(hWnd, &clientRect) == 0)
                {
                    return;
                }
                int clientRectWidth  = clientRect.right - clientRect.left;
                int clientRectHeight = clientRect.bottom - clientRect.top;

                width  += (rectWidth - clientRectWidth);
                height += (rectHeight - clientRectHeight);
            }

            SetWindowPos(hWnd, HWND.Zero, 0, 0, width, height, SWP_NOMOVE);
        }
Ejemplo n.º 6
0
        public void UpdateWindowSize(int type = -1, bool isSaved = false)
        {
            CurrentWindowSizeType = type == -1 ? ((int)CurrentWindowSizeType == System.Enum.GetValues(typeof(WindowSizeType)).Length - 1) ? 0 : CurrentWindowSizeType + 1 : (WindowSizeType)type;

            switch (CurrentWindowSizeType)
            {
            case WindowSizeType.Window:
                if (!isSaved)
                {
                    rt.sizeDelta     = windowSize;
                    rt.localPosition = windowPosition;
                }
                ContractTextGO.SetActive(false);
                ExpandTextGO.SetActive(true);
                break;

            case WindowSizeType.Full:
                if (!isSaved)
                {
                    rt.sizeDelta     = new Vector2(Screen.width, Screen.height);
                    rt.localPosition = new Vector3(-Screen.width / 2, Screen.height / 2, 0f);
                }
                ContractTextGO.SetActive(true);
                ExpandTextGO.SetActive(false);
                break;
            }
        }
Ejemplo n.º 7
0
 public override void SetSize(int width, int height, WindowSizeType type)
 {
     if (type == WindowSizeType.WorkingArea)
     {
         form.ClientSize = new Size(width, height);
     }
     else
     {
         form.Size = new Size(width, height);
     }
 }
Ejemplo n.º 8
0
 public override Size2 GetSize(WindowSizeType type)
 {
     if (type == WindowSizeType.WorkingArea)
     {
         return(new Size2((int)window.Width, (int)window.Height));
     }
     else
     {
         return(new Size2((int)window.Width, (int)window.Height));
     }
 }
Ejemplo n.º 9
0
 public override Size2 GetSize(WindowSizeType type)
 {
     if (type == WindowSizeType.WorkingArea)
     {
         var size = form.ClientSize;
         return(new Size2(size.Width, size.Height));
     }
     else
     {
         var size = form.Size;
         return(new Size2(size.Width, size.Height));
     }
 }
Ejemplo n.º 10
0
        public override Size2 GetSize(WindowSizeType type)
        {
            var rect = new RECT();

            if (type == WindowSizeType.WorkingArea)
            {
                if (GetClientRect(hWnd, &rect) == 0)
                {
                    throw new Exception("GetClientRect failed");
                }
            }
            else
            {
                if (GetWindowRect(hWnd, &rect) == 0)
                {
                    throw new Exception("GetWindowRect failed");
                }
            }
            return(new Size2(rect.right - rect.left, rect.bottom - rect.top));
        }
Ejemplo n.º 11
0
        public override void SetSize(int width, int height, WindowSizeType type)
        {
            if (type == WindowSizeType.WorkingArea)
            {
                // get window rect and size
                RECT rect   = new RECT();
                int  result = GetWindowRect(handle, ref rect);
                if (result == 0)
                {
                    throw new Exception("GetWindowRect failed");
                }
                int rectWidth  = rect.right - rect.left;
                int rectHeight = rect.bottom - rect.top;

                // get client rect and size
                RECT clientRect = new RECT();
                result = GetClientRect(handle, ref clientRect);
                if (result == 0)
                {
                    throw new Exception("GetClientRect failed");
                }
                int clientRectWidth  = clientRect.right - clientRect.left;
                int clientRectHeight = clientRect.bottom - clientRect.top;

                // increase size based on client side decoration delta
                width  = width + (rectWidth - clientRectWidth);
                height = height + (rectHeight - clientRectHeight);

                // apply new adjusted window size
                result = SetWindowPos(handle, IntPtr.Zero, 0, 0, width, height, SWP_NOMOVE);
                if (result == 0)
                {
                    throw new Exception("SetWindowPos failed");
                }
            }
            else
            {
                window.Width  = width;
                window.Height = height;
            }
        }
Ejemplo n.º 12
0
        private void Awake()
        {
            HeaderRT.gameObject.SetActive(false);
            ContractTextGO.SetActive(false);
            ExpandTextGO.SetActive(false);
            smallSize             = new Vector2((Screen.width / 8), Screen.height / 8);
            medSize               = new Vector2(Screen.width / 4, Screen.height / 4);
            fullSize              = new Vector2(Screen.width, Screen.height);
            rt                    = GetComponent <RectTransform>();
            rt.sizeDelta          = smallSize;
            headerAnchoredYPos    = HeaderRT.anchoredPosition.y;
            CurrentWindowSizeType = WindowSizeType.Small;
            UpdateWindowSize((int)CurrentWindowSizeType);

            CameraRawImage = CameraVisualGO.GetComponent <RawImage>();
            cameraRT       = CameraVisualGO.GetComponent <RectTransform>();
            ValuesText     = ValuesVisualGO.GetComponent <Text>();
            fitter         = CameraVisualGO.GetComponent <AspectRatioFitter>();
            CameraVisualGO.SetActive(false);
            ValuesVisualGO.SetActive(false);
        }
Ejemplo n.º 13
0
        private void Init(int x, int y, int width, int height, WindowSizeType sizeType, WindowType type, WindowStartupPosition startupPosition)
        {
            // get native HWND handle
            handle = new WindowInteropHelper(window).EnsureHandle();
            if (handle == IntPtr.Zero)
            {
                throw new Exception("WindowInteropHelper HWND failed");
            }

            // set form type
            switch (type)
            {
            case WindowType.Tool:
                window.ResizeMode = System.Windows.ResizeMode.NoResize;
                break;

            case WindowType.Popup:
                window.WindowStyle = System.Windows.WindowStyle.None;
                break;
            }

            // set form size
            SetSize(width, height, sizeType);

            // set form startup position
            switch (startupPosition)
            {
            case WindowStartupPosition.Custom:
                window.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
                SetPosition(x, y);
                break;

            case WindowStartupPosition.CenterScreen:
                window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                break;
            }

            // watch for close event
            window.Closed += Window_Closed;
        }
Ejemplo n.º 14
0
        public void Init(string name)
        {
            this.name = name;
            VisualizerNameText.text = name;

            if (rt == null)
            {
                return;
            }

            if (PlayerPrefs.HasKey($"Visualizer/{name}/position/x"))
            {
                var posX = PlayerPrefs.GetFloat($"Visualizer/{name}/position/x");
                var posY = PlayerPrefs.GetFloat($"Visualizer/{name}/position/y");
                if (posX != 0 && posY != 0)
                {
                    rt.localPosition = new Vector3(posX * Screen.width, posY * Screen.height, 0);
                }
            }

            if (PlayerPrefs.HasKey($"Visualizer/{name}/size/x"))
            {
                var sizeX = PlayerPrefs.GetFloat($"Visualizer/{name}/size/x");
                var sizeY = PlayerPrefs.GetFloat($"Visualizer/{name}/size/y");
                if (sizeX != 0 && sizeY != 0)
                {
                    rt.sizeDelta = new Vector2(sizeX * Screen.width, sizeY * Screen.height);
                }
            }

            if (PlayerPrefs.HasKey($"Visualizer/{name}/widowsizetype"))
            {
                CurrentWindowSizeType = (WindowSizeType)System.Enum.Parse(typeof(WindowSizeType), PlayerPrefs.GetString($"Visualizer/{name}/widowsizetype"));
            }

            UpdateWindowSize((int)CurrentWindowSizeType, true);
        }
Ejemplo n.º 15
0
 public abstract void SetSize(int width, int height, WindowSizeType type);
Ejemplo n.º 16
0
 public Window(int x, int y, int width, int height, WindowSizeType sizeType, WindowType type, WindowStartupPosition startupPosition)
 {
     window = new WPFWindow();
     Init(x, y, width, height, sizeType, type, startupPosition);
 }
Ejemplo n.º 17
0
 public Window(Point2 position, Size2 size, WindowSizeType sizeType, WindowType type, WindowStartupPosition startupPosition)
 {
     window = new WPFWindow();
     Init(position.x, position.y, size.width, size.height, sizeType, type, startupPosition);
 }
Ejemplo n.º 18
0
 public override void SetSize(Size2 size, WindowSizeType type)
 {
     SetSize(size.width, size.height, type);
 }
Ejemplo n.º 19
0
 public abstract Size2 GetSize(WindowSizeType type);
Ejemplo n.º 20
0
 public void SetWindowType()
 {
     CurrentWindowSizeType = WindowSizeType.Window;
     ContractTextGO.SetActive(false);
     ExpandTextGO.SetActive(true);
 }
Ejemplo n.º 21
0
 public abstract void SetSize(Size2 size, WindowSizeType type);
Ejemplo n.º 22
0
        private void Init(int x, int y, int width, int height, WindowSizeType sizeType, WindowType type, WindowStartupPosition startupPosition)
        {
            // register window class
            var wcex = new WNDCLASSEXA();

            wcex.cbSize     = (UINT)Marshal.SizeOf <WNDCLASSEXA>();
            wcex.style      = CS_HREDRAW | CS_VREDRAW;
            wndProcDelegate = new WndProcDelegate(WndProc);
                        #if CS2X
            Marshal.GetFunctionPointerForDelegate <WndProcDelegate>(wndProcDelegate, out _, out wcex.lpfnWndProc);
                        #else
            wcex.lpfnWndProc = Marshal.GetFunctionPointerForDelegate <WndProcDelegate>(wndProcDelegate);
                        #endif
            wcex.cbClsExtra = 0;
            wcex.cbWndExtra = 0;
            wcex.hInstance  = Application.hInstance;
            //wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSDESKTOPVCPP));
            //wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
            wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

            var    guid       = Guid.NewGuid();
            string guidString = guid.ToString();
            fixed(char *guidStringPtr = guidString)
            {
                wcex.lpszClassName = (LPCSTR)guidStringPtr;                // set class name to guid
                atom = RegisterClassExA(&wcex);
            }

            // create window
            RECT rect;
            if (startupPosition == WindowStartupPosition.CenterScreen)
            {
                HWND desktop = GetDesktopWindow();
                GetClientRect(desktop, &rect);
                x = (rect.right / 2) - (width / 2);
                y = (rect.bottom / 2) - (height / 2);
            }
            else if (startupPosition == WindowStartupPosition.Default)
            {
                x = unchecked ((int)CW_USEDEFAULT);
                y = unchecked ((int)CW_USEDEFAULT);
            }

            DWORD windowStyle = WS_OVERLAPPEDWINDOW;
            switch (type)
            {
            case WindowType.Tool:
                windowStyle ^= WS_MAXIMIZEBOX;
                windowStyle ^= WS_MINIMIZEBOX;
                windowStyle ^= WS_THICKFRAME;                        // disable window resize
                break;

            case WindowType.Popup:
                windowStyle = WS_POPUPWINDOW;
                break;
            }

            byte *title = stackalloc byte[1];
            title[0] = 0;
            hWnd     = CreateWindowExA(0, (LPCSTR)atom, (LPCSTR)title, windowStyle, x, y, width, height, HWND.Zero, HMENU.Zero, Application.hInstance, IntPtr.Zero);
            if (hWnd == HWND.Zero)
            {
                throw new Exception("CreateWindowExA failed");
            }

            // adjust working area / client size and position
            if (sizeType == WindowSizeType.WorkingArea)
            {
                if (GetWindowRect(hWnd, &rect) == 0)
                {
                    throw new Exception("GetWindowRect failed");
                }
                int rectWidth  = rect.right - rect.left;
                int rectHeight = rect.bottom - rect.top;

                RECT clientRect;
                if (GetClientRect(hWnd, &clientRect) == 0)
                {
                    throw new Exception("GetWindowRect failed");
                }
                int clientRectWidth  = clientRect.right - clientRect.left;
                int clientRectHeight = clientRect.bottom - clientRect.top;

                int offsetX = (rectWidth - clientRectWidth);
                int offsetY = (rectHeight - clientRectHeight);
                width  += offsetX;
                height += offsetY;

                UINT flags = SWP_NOMOVE;
                if (startupPosition == WindowStartupPosition.CenterScreen)
                {
                    flags = 0;
                    x    -= offsetX / 2;
                    y    -= offsetY;
                }

                if (SetWindowPos(hWnd, HWND.Zero, x, y, width, height, flags) == 0)
                {
                    throw new Exception("SetWindowPos failed");
                }
            }

            // track window
            windows.Add(this);
        }