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

            handler.OnRestore += Handler_OnRestore;

            keyCallback = (w, key, scancode, state, modifiers) =>
            {
                OnKeyEvent?.Invoke(this, new KeyboardKeyEventArgs
                {
                    Key       = (KeyboardKey)key,
                    Scancode  = scancode,
                    Action    = (KeyState)state,
                    Modifiers = (KeyModifier)modifiers
                });
            };

            charCallback = (w, c) =>
            {
                OnType?.Invoke(this, new KeyboardTypeEventArgs
                {
                    Point = (char)c
                });
            };

            charModsCallback = (w, c, modifiers) =>
            {
                OnTypeWithMods?.Invoke(this, new KeyboardModTypeEventArgs
                {
                    Point     = (char)c,
                    Modifiers = (KeyModifier)modifiers
                });
            };
        }
Ejemplo n.º 2
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.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GlfwDeviceManager"/> class.
        /// </summary>
        /// <
        public GlfwDeviceManager(GlfwWindow context)
        {
            handler = context;

            devices = new List <IDevice>();

            joypadCallback = JoypadConnectionCallback;
        }
Ejemplo n.º 4
0
        public unsafe GlfwInputContext(GlfwWindow window)
        {
            void OnConnectionChanged(IInputDevice a, bool b) => ConnectionChanged?.Invoke(a, b);

            if (window is null)
            {
                throw new ArgumentNullException
                          (nameof(window), "Attempted to create input context for null or non-GLFW window.");
            }

            Handle = window.Handle;
            for (var i = 0; i < _gamepads.Length; i++)
            {
                _gamepads[i] = new GlfwGamepad(i)
                {
                    OnConnectionChanged = OnConnectionChanged
                };
            }

            for (var i = 0; i < _joysticks.Length; i++)
            {
                _joysticks[i] = new GlfwJoystick(i)
                {
                    OnConnectionChanged = OnConnectionChanged
                };
            }

            _subscribers[0] = _keyboards[0] = new GlfwKeyboard();
            _subscribers[1] = _mice[0] = new GlfwMouse();

            Gamepads  = new IsConnectedWrapper <GlfwGamepad>(_gamepads);
            Joysticks = new IsConnectedWrapper <GlfwJoystick>(_joysticks);
            Keyboards = _keyboards;
            Mice      = _mice;

            GlfwInputPlatform.RegisterWindow((WindowHandle *)Handle, _subscribers);
            window.Update += _update = _ =>
            {
                foreach (var updatable in _mice)
                {
                    updatable.Update();
                }

                foreach (var updatable in _gamepads)
                {
                    updatable.Update();
                }

                foreach (var updatable in _joysticks)
                {
                    updatable.Update();
                }
            };

            _window = window;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Makes a new instance of <see cref="WindowsRuntime"/>, a specific
        /// implementation of pEngine for windows platform.
        /// </summary>
        public WindowsRuntime() : base()
        {
            // - Add Binaries folder to the search path
            LibraryLoader.Initialize();

            // - Initialize GLFW
            GLFW.Glfw.Init();

            // - Create the game window instance
            Surface = new GlfwWindow(new Vector2i(500, 500), Environment.Engine.Name);
        }
Ejemplo n.º 6
0
        public static void CenterWindow(GlfwWindow window)
        {
            int windowW, windowH;

            GetWindowSize(window, out windowW, out windowH);

            GlfwVidMode mode = GetVideoMode(GetPrimaryMonitor());

            int desktopW = mode.Width;
            int desktopH = mode.Height;

            SetWindowPos(window, desktopW / 2 - windowW / 2, desktopH / 2 - windowH / 2);
        }
Ejemplo n.º 7
0
        public GlfwInputContext(GlfwWindow window)
        {
            Handle  = window.Handle;
            _window = window;
            InputHandler.RegisterContext(this);

            // initialize auto-properties
            Gamepads  = new GlfwGamepadCollection(this);
            Joysticks = new GlfwJoystickCollection(this);
            Keyboards = new GlfwKeyboardCollection(this);
            Mice      = new GlfwMouseCollection(this);

            // initialize joysticks
            _joysticks = new List <GlfwJoystick>(Enumerable.Range(0, 16).Select(i => new GlfwJoystick(i)));
            _gamepads  = new List <GlfwGamepad>(Enumerable.Range(0, 16).Select(i => new GlfwGamepad(i)));
            _keyboard  = new GlfwKeyboard(this);
            _mouse     = new GlfwMouse(this);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var windowCreateInfo = new WindowCreateInfo(new Point(100, 100), new Size(640, 480), WindowState.Normal, "Glfw Example", ContextAPI.OpenGL);
            var window           = new GlfwWindow(windowCreateInfo, new GlfwWindowCreateInfo(IntPtr.Zero, false));

            window.TextInput += (w, args) =>
            {
                Console.Write($"{(char)args.Unicode}");
            };

            while (window.Exists)
            {
                var task = window.ProcessEventsAsync();
                Thread.Sleep(1);
                task.Wait();
            }

            window.WaitClose();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Makes a new instance of <see cref="GlfwJoypad"/> class.
 /// </summary>
 /// <param name="window">Current context.</param>
 public GlfwJoypad(GlfwWindow window, int index)
 {
     handler = window;
     Index   = index;
 }