Ejemplo n.º 1
0
        /// <summary>
        /// Makes a new instance of <see cref="GlfwMouse"/> class.
        /// </summary>
        /// <param name="window">Current context.</param>
        public GlfwMouse(GlfwWindow window)
        {
            handler = window;

            handler.OnRestore += Handler_OnRestore;

            cursorCallback = (w, x, y) =>
            {
                OnMove?.Invoke(this, new MousePositiontEventArgs
                {
                    Position = new Vector2((float)x, (float)y)
                });
            };

            scrollCallback = (w, x, y) =>
            {
                OnScroll?.Invoke(this, new MouseOffsetEventArgs
                {
                    Offset = new Vector2((float)x, (float)y)
                });
            };

            buttonCallback = (w, button, action, modifiers) =>
            {
                OnButtonEvent?.Invoke(this, new MouseKeyEventArgs
                {
                    Key       = (MouseButton)button,
                    Action    = (KeyState)action,
                    Modifiers = (KeyModifier)modifiers
                });
            };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialises the Glfw library and creates a window
        /// </summary>
        internal void Init()
        {
            // Get the specified Glfw.dll's directory
            Glfw.ConfigureNativesDirectory("..//..//Vendor/");

            // Init library
            if (!Glfw.Init())
            {
                Debug.Log("Could not initialise Glfw", Debug.DebugLayer.Application, Debug.DebugLevel.Error);
            }

            // Get monitor settings
            monitor = Glfw.GetPrimaryMonitor();

            // Create window
            window = Glfw.CreateWindow(width, height, title, Glfw.Monitor.None, Glfw.Window.None);
            if (!window)
            {
                Debug.Log("Could not create window", Debug.DebugLayer.Application, Debug.DebugLevel.Error);
            }

            // Make the current window the context
            Glfw.MakeContextCurrent(window);

            // Let glfw swap the buffers as fast as possible - 0 for fast 1 - for v sync
            Glfw.SwapInterval(0);

            // Set callbacks
            keyboardDel    = KeyboardCallBack;
            mouseButtonDel = MouseButtonCallBack;
            cursorPosDel   = CursorPosCallBack;

            Glfw.SetKeyCallback(window, keyboardDel);
            Glfw.SetMouseButtonCallback(window, mouseButtonDel);
            Glfw.SetCursorPosCallback(window, cursorPosDel);


            Debug.Log("Window Created size " + width + "x" + height, Debug.DebugLayer.Application, Debug.DebugLevel.Information);
        }