Esempio n. 1
0
        protected Application(WindowProps props, Type windowType, GraphicsBackend backend)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            CultureInfo.DefaultThreadCurrentCulture   = CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
            Logger.Init();
            Logger.Assert(App == null, "App already initialized");
            App                  = this;
            LayerStack           = new LayerStack();
            Window               = WindowBase.CreateMainWindow(windowType, props, backend: backend);
            Window.EventCallback = OnEvent;
            ImGuiLayer           = new ImGuiLayer();
            LayerStack.PushOverlay(ImGuiLayer);
        }
Esempio n. 2
0
        private void Initialize(WindowProps props, GraphicsBackend backend)
        {
            InputManager.CreateInstance <WindowsInput>();

            GcHandle = GCHandle.Alloc(this);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions()
            {
                Debug = false,
                PreferDepthRangeZeroToOne         = true,
                PreferStandardClipSpaceYDirection = false,
                ResourceBindingModel = ResourceBindingModel.Improved,
                SyncToVerticalBlank  = props.VSync,
                HasMainSwapchain     = true,
                SwapchainDepthFormat = PixelFormat.R16_UNorm,
                SwapchainSrgbFormat  = false
            };

#if DEBUG
            options.Debug = true;
#endif
            WindowStartup.CreateWindowAndGraphicsDevice(props, options, backend, out window, out graphicsDevice);

            VSync     = props.VSync;
            swapchain = graphicsDevice.MainSwapchain;

            // Called twice possibly because of 2 events being fired: Resize and SizeChanged (and Maximized)
            // #TODO treat it here or hope for Veldrid to be updated with this (Maybe clone and alter source code myself)
            // currently deduplicated in the application
            window.Resized += () =>
            {
                EventCallback(new WindowResizeEvent(window.Width, window.Height));
            };

            window.Closed += () => EventCallback(new WindowCloseEvent());

            window.KeyUp   += (keyEvent) => EventCallback(new KeyReleasedEvent((int)keyEvent.Key));
            window.KeyDown += (keyEvent) => EventCallback(new KeyPressedEvent((int)keyEvent.Key, 1));

            window.MouseDown  += (mouseEvent) => EventCallback(new MouseButtonPressedEvent((int)mouseEvent.MouseButton));
            window.MouseUp    += (mouseEvent) => EventCallback(new MouseButtonReleasedEvent((int)mouseEvent.MouseButton));
            window.MouseWheel += (mouseEvent) => EventCallback(new MouseScrolledEvent(mouseEvent.WheelDelta));
            window.MouseMove  += (mouseEvent) => EventCallback(new MouseMovedEvent(mouseEvent.MousePosition.X, mouseEvent.MousePosition.Y));
        }
Esempio n. 3
0
 public WindowsWindow(WindowProps props, GraphicsBackend backend)
 {
     Initialize(props, backend);
 }
Esempio n. 4
0
 public TReturnType GetWindowProperty <TReturnType>(IWindowInfo win, WindowProps property)
 {
     return(default(TReturnType));
 }
Esempio n. 5
0
 public void SetWindowProperty(IWindowInfo win, WindowProps property, string value)
 {
     // throw new NotImplementedException();
 }
Esempio n. 6
0
        private void Init(WindowProps props)
        {
            m_Data.Title  = props.Title;
            m_Data.Width  = props.Width;
            m_Data.Height = props.Height;

            Debug.DLog($"Creating Window {props.Title} ({props.Width}, {props.Height})");

            if (!s_GLFWInitialized)
            {
                bool succes = Glfw.Init();

                if (!succes)
                {
                    Debug.DLogError("Could not initailize GLFW!");
                    return;
                }
                Glfw.SetErrorCallback(GLFWErrorCallback);
                s_GLFWInitialized = true;
            }


            m_Window = Glfw.CreateWindow((int)props.Width, (int)props.Height, props.Title, Monitor.None, Window.None);
            Glfw.MakeContextCurrent(m_Window);
            int status = Glad.LoadGLLoader(_GetProcAddress);

            Debug.DLog(status);
            SetVSync(true);

            #region // Set GLFW callbacks
            Glfw.SetWindowSizeCallback(m_Window, delegate(Window window, int width, int height)
            {
                WindowsWindow.m_Data.Width  = (uint)width;
                WindowsWindow.m_Data.Height = (uint)height;

                WindowsWindow.m_Data.d(new WindowResizeEvent((uint)width, (uint)height));
            });

            Glfw.SetCloseCallback(m_Window, delegate(Window window)
            {
                WindowsWindow.m_Data.d(new WindowCloseEvent());
            });

            Glfw.SetKeyCallback(m_Window, delegate(Window window, Keys key, int scanCode, InputState state, ModifierKeys mods)
            {
                switch (state)
                {
                case InputState.Release:
                    {
                        WindowsWindow.m_Data.d(new KeyReleasedEvent((int)key));
                    }
                    break;

                case InputState.Press:
                    {
                        WindowsWindow.m_Data.d(new KeyPressedEvent((int)key, 0));
                    }
                    break;

                case InputState.Repeat:
                    {
                        WindowsWindow.m_Data.d(new KeyPressedEvent((int)key, 1));
                    }
                    break;
                }
            });

            Glfw.SetMouseButtonCallback(m_Window, delegate(Window window, MouseButton button, InputState state, ModifierKeys modifiers)
            {
                switch (state)
                {
                case InputState.Release:
                    {
                        WindowsWindow.m_Data.d(new MouseButtonReleasedEvent((int)button));
                    }
                    break;

                case InputState.Press:
                    {
                        WindowsWindow.m_Data.d(new MouseButtenPressedEvent((int)button));
                    }
                    break;
                }
            });

            Glfw.SetScrollCallback(m_Window, delegate(Window window, double x, double y)
            {
                WindowsWindow.m_Data.d(new MouseScrolledEvent((float)x, (float)y));
            });

            Glfw.SetCursorPositionCallback(m_Window, delegate(Window window, double x, double y)
            {
                WindowsWindow.m_Data.d(new MouseMovedEvent((float)x, (float)y));
            });

            #endregion
        }
Esempio n. 7
0
 public WindowsWindow(WindowProps props)
 {
     Init(props);
 }