Beispiel #1
0
        /// <summary>
        /// The create window.
        /// </summary>
        private void CreateWindow()
        {
            var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            _windowProc = WindowProc;

            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "chromelywindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = GetIconHandle(),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = _windowProc,
                InstanceHandle        = instanceHandle
            };

            var resReg = User32Methods.RegisterClassEx(ref wc);

            if (resReg == 0)
            {
                Log.Error("chromelywindow registration failed");
                return;
            }

            var styles = GetWindowStyles(_hostConfig.HostPlacement.State);

            var placement = _hostConfig.HostPlacement;

            NativeMethods.RECT rect;
            rect.Left   = placement.Left;
            rect.Top    = placement.Top;
            rect.Right  = placement.Left + placement.Width;
            rect.Bottom = placement.Top + placement.Height;
            NativeMethods.AdjustWindowRectEx(ref rect, styles.Item1, false, styles.Item2);

            var hwnd = User32Methods.CreateWindowEx(
                styles.Item2,
                wc.ClassName,
                _hostConfig.HostPlacement.Frameless ? string.Empty : _hostConfig.HostTitle,
                styles.Item1,
                rect.Left,
                rect.Top,
                rect.Right - rect.Left,
                rect.Bottom - rect.Top,
                IntPtr.Zero,
                IntPtr.Zero,
                instanceHandle,
                IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
            {
                Log.Error("chromelywindow creation failed");
                return;
            }

            User32Methods.ShowWindow(Handle, styles.Item3);
            User32Methods.UpdateWindow(Handle);
        }
Beispiel #2
0
        public void Init(string title, int width, int height, bool vsync, bool fullscreen)
        {
            if (m_Info != null)
            {
                throw new InvalidOperationException("application already initialized");
            }
            m_Info = new ApplicationInfo
            {
                Title      = title,
                Width      = width,
                Height     = height,
                VSync      = vsync,
                FullScreen = fullscreen
            };

            IntPtr hInstance = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            m_WindowProc = WindowProc;
            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "MainWindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = m_WindowProc,
                InstanceHandle        = hInstance
            };

            if (User32Methods.RegisterClassEx(ref wc) == 0)
            {
                throw new ExternalException("window registration failed");
            }

            NetCoreEx.Geometry.Rectangle size = new NetCoreEx.Geometry.Rectangle(0, 0, width, height);
            User32Methods.AdjustWindowRectEx(ref size, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS,
                                             false, WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE);

            m_hWnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE, wc.ClassName,
                                                  title, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS,
                                                  (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT,
                                                  size.Right + (-size.Left), size.Bottom + (-size.Top), IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero);

            if (m_hWnd == IntPtr.Zero)
            {
                throw new ExternalException("window creation failed");
            }

            User32Methods.ShowWindow(m_hWnd, ShowWindowCommands.SW_SHOWNORMAL);
            User32Methods.UpdateWindow(m_hWnd);

            Context.Instance.Init(m_hWnd, m_Info);
            Renderer.Instance.Init();
            Script.LuaEngine.Instance.Init();
        }
Beispiel #3
0
        static int Main(string[] args)
        {
            var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "MainWindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = WindowProc,
                InstanceHandle        = instanceHandle
            };

            var resReg = User32Methods.RegisterClassEx(ref wc);

            if (resReg == 0)
            {
                Console.Error.WriteLine("registration failed");
                return(-1);
            }

            var hwnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW,
                                                    wc.ClassName, "Hello", WindowStyles.WS_OVERLAPPEDWINDOW,
                                                    (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT,
                                                    (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT,
                                                    IntPtr.Zero, IntPtr.Zero, instanceHandle, IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
            {
                Console.Error.WriteLine("window creation failed");
                return(-1);
            }

            User32Methods.ShowWindow(hwnd, ShowWindowCommands.SW_SHOWNORMAL);
            User32Methods.UpdateWindow(hwnd);

            Message msg;
            int     res;

            while ((res = User32Methods.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)
            {
                User32Methods.TranslateMessage(ref msg);
                User32Methods.DispatchMessage(ref msg);
            }

            return(res);
        }
Beispiel #4
0
        /// <summary>
        /// The create window.
        /// </summary>
        private void CreateWindow()
        {
            var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "chromelywindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = GetIconHandle(),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = WindowProc,
                InstanceHandle        = instanceHandle
            };

            var resReg = User32Methods.RegisterClassEx(ref wc);

            if (resReg == 0)
            {
                Log.Error("chromelywindow registration failed");
                return;
            }

            var styles = GetWindowStyles(mHostConfig.HostState);

            var hwnd = User32Methods.CreateWindowEx(
                styles.Item2,
                wc.ClassName,
                mHostConfig.HostTitle,
                styles.Item1,
                0,
                0,
                mHostConfig.HostWidth,
                mHostConfig.HostHeight,
                IntPtr.Zero,
                IntPtr.Zero,
                instanceHandle,
                IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
            {
                Log.Error("chromelywindow creation failed");
                return;
            }

            User32Methods.ShowWindow(Handle, styles.Item3);
            User32Methods.UpdateWindow(Handle);
        }
Beispiel #5
0
        protected override void SetupInternal(Configurator config)
        {
            bool initSuccess = Glfw.Init();

            if (!initSuccess)
            {
                Engine.Log.Error("Couldn't initialize glfw.", MessageSource.Glfw);
                return;
            }

            _errorCallback = ErrorCallback;
            Glfw.SetErrorCallback(_errorCallback);

#if ANGLE
            LoadLibrary("libEGL");
            LoadLibrary("libGLESv2");
            Glfw.WindowHint(Glfw.Hint.ClientApi, Glfw.ClientApi.OpenGLES);
            Glfw.WindowHint(Glfw.Hint.ContextCreationApi, Glfw.ContextApi.EGL);
            Glfw.WindowHint(Glfw.Hint.ContextVersionMajor, 3);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Kernel32Methods.GetModuleHandle("renderdoc.dll") != IntPtr.Zero)
            {
                Glfw.WindowHint(Glfw.Hint.ContextVersionMinor, 1);
            }
#endif

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                // Macs need a very specific context to be requested.
                Glfw.WindowHint(Glfw.Hint.ContextVersionMajor, 3);
                Glfw.WindowHint(Glfw.Hint.ContextVersionMinor, 2);
                Glfw.WindowHint(Glfw.Hint.OpenglForwardCompat, true);
                Glfw.WindowHint(Glfw.Hint.OpenglProfile, Glfw.OpenGLProfile.Core);
            }
            else
            {
                // Version set by the angle ifdef shouldn't be overwritten.
#if !ANGLE
                Glfw.WindowHint(Glfw.Hint.ContextVersionMajor, 3);
                Glfw.WindowHint(Glfw.Hint.ContextVersionMinor, 3);
                Glfw.WindowHint(Glfw.Hint.OpenglForwardCompat, true);
                Glfw.WindowHint(Glfw.Hint.OpenglProfile, Glfw.OpenGLProfile.Core);
#endif
            }

            Glfw.Window?win = Glfw.CreateWindow((int)config.HostSize.X, (int)config.HostSize.Y, config.HostTitle);
            if (win == null || win.Value.Ptr == IntPtr.Zero)
            {
                Engine.Log.Error("Couldn't create window.", MessageSource.Glfw);
                return;
            }

            _win = win.Value;

            Glfw.SetWindowSizeLimits(_win, (int)config.RenderSize.X, (int)config.RenderSize.Y, -1, -1);

            _focusCallback = FocusCallback;
            Glfw.SetWindowFocusCallback(_win, _focusCallback);
            _resizeCallback = ResizeCallback;
            Glfw.SetFramebufferSizeCallback(_win, _resizeCallback);
            Context = new GlfwGraphicsContext(_win);
            Context.MakeCurrent();

            _keyInputCallback = KeyInput;
            Glfw.SetKeyCallback(_win, _keyInputCallback);

            _mouseButtonFunc = MouseButtonKeyInput;
            Glfw.SetMouseButtonCallback(_win, _mouseButtonFunc);

            _mouseScrollFunc = MouseScrollInput;
            Glfw.SetScrollCallback(_win, _mouseScrollFunc);

            void TextInputRedirect(Glfw.Window _, uint codePoint)
            {
                UpdateTextInput((char)codePoint);
            }

            _textInputCallback = TextInputRedirect;
            Glfw.SetCharCallback(_win, _textInputCallback);

            Glfw.Monitor[] monitors = Glfw.GetMonitors();
            for (var i = 0; i < monitors.Length; i++)
            {
                Glfw.GetMonitorPos(monitors[i], out int x, out int y);
                Glfw.VideoMode videoMode = Glfw.GetVideoMode(monitors[i]);
                var            mon       = new GlfwMonitor(new Vector2(x, y), new Vector2(videoMode.Width, videoMode.Height));
                UpdateMonitor(mon, true, i == 0);
            }

            FocusChanged(true);
            Glfw.FocusWindow(_win);

#if OpenAL
            Audio = OpenALAudioAdapter.TryCreate(this) ?? (AudioContext) new NullAudioContext();
#else
            Audio = new NullAudioContext();
#endif
        }
Beispiel #6
0
        /// <summary>
        /// The create window.
        /// </summary>
        private void CreateWindow()
        {
            var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            _windowProc = WindowProc;

            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "chromelywindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = GetIconHandle(),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = _windowProc,
                InstanceHandle        = instanceHandle
            };

            var resReg = User32Methods.RegisterClassEx(ref wc);

            if (resReg == 0)
            {
                Log.Error("chromelywindow registration failed");
                return;
            }

            var styles = GetWindowStyles(_hostConfig.HostPlacement.State);

            var placement = _hostConfig.HostPlacement;

            NativeMethods.RECT rect;
            rect.Left   = placement.Left;
            rect.Top    = placement.Top;
            rect.Right  = placement.Left + placement.Width;
            rect.Bottom = placement.Top + placement.Height;

            NativeMethods.AdjustWindowRectEx(ref rect, styles.Item1, false, styles.Item2);

            var hwnd = User32Methods.CreateWindowEx(
                styles.Item2,
                wc.ClassName,
                _hostConfig.HostPlacement.Frameless ? string.Empty : _hostConfig.HostTitle,
                styles.Item1,
                rect.Left,
                rect.Top,
                rect.Right - rect.Left,
                rect.Bottom - rect.Top,
                IntPtr.Zero,
                IntPtr.Zero,
                instanceHandle,
                IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
            {
                Log.Error("chromelywindow creation failed");
                return;
            }

            if (_hostConfig.HostPlacement.KioskMode)
            {
                //// Set new window style and size.
                var windowHDC        = User32Methods.GetDC(Handle);
                var fullscreenWidth  = Gdi32Methods.GetDeviceCaps(windowHDC, (int)DeviceCapsParams.HORZRES);
                var fullscreenHeight = Gdi32Methods.GetDeviceCaps(windowHDC, (int)DeviceCapsParams.VERTRES);
                User32Methods.ReleaseDC(Handle, windowHDC);

                User32Methods.SetWindowLongPtr(Handle, (int)WindowLongFlags.GWL_STYLE, (IntPtr)styles.Item1);
                User32Methods.SetWindowLongPtr(Handle, (int)WindowLongFlags.GWL_EXSTYLE, (IntPtr)styles.Item2);

                User32Methods.SetWindowPos(Handle, (IntPtr)HwndZOrder.HWND_TOP, 0, 0, fullscreenWidth, fullscreenHeight,
                                           WindowPositionFlags.SWP_NOZORDER | WindowPositionFlags.SWP_FRAMECHANGED);

                User32Methods.ShowWindow(Handle, ShowWindowCommands.SW_MAXIMIZE);

                try
                {
                    this._hookID = NativeMethods.SetHook(_hookCallback);
                }
                catch
                {
                    DetachKeyboardHook();
                }
            }
            else
            {
                User32Methods.ShowWindow(Handle, styles.Item3);
            }
            User32Methods.UpdateWindow(Handle);

            User32Methods.RegisterHotKey(IntPtr.Zero, 1, KeyModifierFlags.MOD_CONTROL, VirtualKey.L);
        }