Example #1
0
    public static string GetClipboardText()
    {
        IntPtr ptr = GetError(SDL_GetClipboardText());

        if (ptr == IntPtr.Zero)
        {
            return(string.Empty);
        }
        return(InteropHelpers.Utf8ToString(ptr));
    }
            public static string GetName(IntPtr joystick)
            {
                var namePtr = JoystickName(joystick);

                try
                {
                    return(InteropHelpers.Utf8ToString(namePtr));
                }
                finally
                {
                    Free(namePtr);
                }
            }
Example #3
0
        internal static void PopulateCaptureDevices()
        {
            // clear microphones
            if (_allMicrophones != null)
            {
                _allMicrophones.Clear();
            }
            else
            {
                _allMicrophones = new List <Microphone>();
            }

            _default = null;

            // default device
            string defaultDevice = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier);

#if true //DESKTOPGL
            // enumerating capture devices
            IntPtr deviceList = Alc.alcGetString(IntPtr.Zero, (int)AlcGetString.CaptureDeviceSpecifier);

            // Marshal native UTF-8 character array to .NET string
            // The native string is a null-char separated list of known capture device specifiers ending with an empty string

            while (true)
            {
                var deviceIdentifier = InteropHelpers.Utf8ToString(deviceList);

                if (string.IsNullOrEmpty(deviceIdentifier))
                {
                    break;
                }

                var microphone = new Microphone(deviceIdentifier);
                _allMicrophones.Add(microphone);
                if (deviceIdentifier == defaultDevice)
                {
                    _default = microphone;
                }

                // increase the offset, add one extra for the terminator
                deviceList += deviceIdentifier.Length + 1;
            }
#else
            // Xamarin platforms don't provide an handle to alGetString that allow to marshal string arrays
            // so we're basically only adding the default microphone
            Microphone microphone = new Microphone(defaultDevice);
            _allMicrophones.Add(microphone);
            _default = microphone;
#endif
        }
Example #4
0
        public static string GetMapping(IntPtr gamecontroller)
        {
            IntPtr nativeStr = SDL_GameControllerMapping(gamecontroller);

            if (nativeStr == IntPtr.Zero)
            {
                return(string.Empty);
            }

            string mappingStr = InteropHelpers.Utf8ToString(nativeStr);

            //The mapping string returned by SDL is owned by us and thus must be freed
            SDL_Free(nativeStr);

            return(mappingStr);
        }
Example #5
0
        public static string GetClipboardText()
        {
            if (!HasClipboardText())
            {
                return(string.Empty);
            }

            IntPtr nativeStr = SDL_GetClipboardText();

            try
            {
                return(InteropHelpers.Utf8ToString(GetError(nativeStr)));
            }
            finally
            {
                Free(nativeStr);
            }
        }
            public static string GetMapping(IntPtr gamecontroller)
            {
                IntPtr mappingStr = GameControllerMapping(gamecontroller);

                if (mappingStr == IntPtr.Zero)
                {
                    return(string.Empty);
                }

                try
                {
                    return(InteropHelpers.Utf8ToString(mappingStr));
                }
                finally
                {
                    //The mapping string returned by SDL is owned by us and thus must be freed
                    SDL_Free(mappingStr);
                }
            }
Example #7
0
 public static string GetDisplayName(int index)
 {
     return(InteropHelpers.Utf8ToString(LogOnError(SDL_GetDisplayName(index))));
 }
Example #8
0
 public static string GetError()
 {
     return(InteropHelpers.Utf8ToString(GetErrorFunc()));
 }
Example #9
0
 public static string GetPlatform()
 {
     return(InteropHelpers.Utf8ToString(ThrowOnError(GetPlatformFunc())));
 }
Example #10
0
        private void SdlRunLoop()
        {
            Sdl.Event ev;

            while (Sdl.PollEvent(out ev) == 1)
            {
                if (ev.Type == Sdl.EventType.Quit)
                {
                    _isExiting++;
                }
                else if (ev.Type == Sdl.EventType.JoyDeviceAdded)
                {
                    Joystick.AddDevice(ev.JoystickDevice.Which);
                }
                else if (ev.Type == Sdl.EventType.ControllerDeviceRemoved)
                {
                    GamePad.RemoveDevice(ev.ControllerDevice.Which);
                }
                else if (ev.Type == Sdl.EventType.JoyDeviceRemoved)
                {
                    Joystick.RemoveDevice(ev.JoystickDevice.Which);
                }
                else if (ev.Type == Sdl.EventType.MouseWheel)
                {
                    const int wheelDelta = 120;
                    Mouse.ScrollY += ev.Wheel.Y * wheelDelta;
                    Mouse.ScrollX += ev.Wheel.X * wheelDelta;
                }
                else if (ev.Type == Sdl.EventType.MouseMotion)
                {
                    Window.MouseState.X = ev.Motion.X;
                    Window.MouseState.Y = ev.Motion.Y;
                }
                else if (ev.Type == Sdl.EventType.DropFile)
                {
                    string file = InteropHelpers.Utf8ToString(ev.DropEvent.File);
                    Sdl.Free(ev.DropEvent.File); //required according to SDL's documentation
                    _view.DropFile(file);
                }
                else if (ev.Type == Sdl.EventType.KeyDown)
                {
                    var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);

                    if (!_keys.Contains(key))
                    {
                        _keys.Add(key);
                    }

                    //TODO: rethink all of this
                    char character = (char)KeyboardUtil.ApplyModifiers(ev.Key.Keysym.Sym, ev.Key.Keysym.Mod);

                    if ((int)((char)ev.Key.Keysym.Sym) != ev.Key.Keysym.Sym)
                    {
                        character = '\0';
                    }

                    if (char.IsControl(character) ||
                        key == Keys.Left ||
                        key == Keys.Right ||
                        key == Keys.Up ||
                        key == Keys.Down)
                    {
                        _view.CallTextInput(character, key);
                    }
                }
                else if (ev.Type == Sdl.EventType.KeyUp)
                {
                    var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);
                    _keys.Remove(key);
                }
                else if (ev.Type == Sdl.EventType.TextInput)
                {
                    int    len  = 0;
                    string text = String.Empty;
                    unsafe
                    {
                        while (Marshal.ReadByte((IntPtr)ev.Text.Text, len) != 0)
                        {
                            len++;
                        }
                        var buffer = new byte [len];
                        Marshal.Copy((IntPtr)ev.Text.Text, buffer, 0, len);
                        text = System.Text.Encoding.UTF8.GetString(buffer);
                    }
                    if (text.Length == 0)
                    {
                        continue;
                    }
                    foreach (var c in text)
                    {
                        var key = KeyboardUtil.ToXna((int)c);
                        _view.CallTextInput(c, key);
                    }
                }
                else if (ev.Type == Sdl.EventType.WindowEvent)
                {
                    if (ev.Window.WindowID == _view.Id)
                    {
                        if (ev.Window.EventID == Sdl.Window.EventId.Resized || ev.Window.EventID == Sdl.Window.EventId.SizeChanged)
                        {
                            _view.ClientResize(ev.Window.Data1, ev.Window.Data2);
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.FocusGained)
                        {
                            IsActive = true;
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.FocusLost)
                        {
                            IsActive = false;
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.Moved)
                        {
                            _view.Moved();
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.Close)
                        {
                            _isExiting++;
                        }
                    }
                }
            }
        }
Example #11
0
 public static string GetHint(string name)
 {
     return(InteropHelpers.Utf8ToString(SDL_GetHint(name)));
 }
Example #12
0
 public static string GetName(IntPtr gamecontroller)
 {
     return(InteropHelpers.Utf8ToString(SDL_GameControllerName(gamecontroller)));
 }
Example #13
0
 public static string GetJoystickName(IntPtr joystick)
 {
     return(InteropHelpers.Utf8ToString(JoystickName(joystick)));
 }