├── docs ├── package-list ├── script.js ├── overview-frame.html ├── uk │ └── co │ │ └── electronstudio │ │ └── sdl2gdx │ │ ├── tests │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── SDLHotplugTest.html │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ ├── package-summary.html │ │ ├── SDL2Controllers.html │ │ └── RumbleController.html ├── org │ └── libsdl │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ ├── package-summary.html │ │ ├── GameController.html │ │ ├── SDL_Error.html │ │ ├── SDL_GameControllerID.html │ │ └── SDL.Event.html ├── allclasses-noframe.html ├── index.html ├── allclasses-frame.html ├── deprecated-list.html ├── overview-summary.html ├── serialized-form.html ├── help-doc.html └── overview-tree.html ├── libs ├── windows32 │ └── sdl2gdx.dll ├── linux64 │ └── libsdl2gdx64.so ├── windows64 │ └── sdl2gdx64.dll └── macosx64 │ └── libsdl2gdx64.dylib ├── src ├── org │ └── libsdl │ │ ├── GameController.java │ │ ├── SDL_Error.java │ │ ├── SDL_GameControllerID.java │ │ ├── SDL_JoystickID.java │ │ └── SDL_GameController.java ├── uk │ └── co │ │ └── electronstudio │ │ └── sdl2gdx │ │ ├── SDL2Controllers.java │ │ ├── RumbleController.java │ │ ├── tests │ │ ├── SDLHotplugTest.java │ │ └── SDLTest.java │ │ ├── SDL2ControllerManager.java │ │ └── NativesBuild.java └── com │ └── badlogic │ └── gdx │ ├── controllers │ ├── desktop │ │ └── DesktopControllerManager.java │ └── lwjgl3 │ │ └── Lwjgl3ControllerManager.java │ └── jnigen │ └── BuildExecutorFixed.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── LICENSE ├── overview.html ├── .gitignore ├── ADVANCED.md ├── gradlew.bat ├── BUILDING.md ├── README.md └── gradlew /docs/package-list: -------------------------------------------------------------------------------- 1 | org.libsdl 2 | uk.co.electronstudio.sdl2gdx 3 | uk.co.electronstudio.sdl2gdx.tests 4 | -------------------------------------------------------------------------------- /libs/windows32/sdl2gdx.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/electronstudio/sdl2gdx/HEAD/libs/windows32/sdl2gdx.dll -------------------------------------------------------------------------------- /libs/linux64/libsdl2gdx64.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/electronstudio/sdl2gdx/HEAD/libs/linux64/libsdl2gdx64.so -------------------------------------------------------------------------------- /libs/windows64/sdl2gdx64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/electronstudio/sdl2gdx/HEAD/libs/windows64/sdl2gdx64.dll -------------------------------------------------------------------------------- /libs/macosx64/libsdl2gdx64.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/electronstudio/sdl2gdx/HEAD/libs/macosx64/libsdl2gdx64.dylib -------------------------------------------------------------------------------- /src/org/libsdl/GameController.java: -------------------------------------------------------------------------------- 1 | package org.libsdl; 2 | 3 | public class GameController { 4 | 5 | 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/electronstudio/sdl2gdx/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/uk/co/electronstudio/sdl2gdx/SDL2Controllers.java: -------------------------------------------------------------------------------- 1 | package uk.co.electronstudio.sdl2gdx; 2 | 3 | public class SDL2Controllers { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/org/libsdl/SDL_Error.java: -------------------------------------------------------------------------------- 1 | package org.libsdl; 2 | 3 | public class SDL_Error extends Exception{ 4 | public SDL_Error() { 5 | super(SDL.SDL_GetError()); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Electron Studio 2 | 3 | This project is released under 4 | 5 | GNU GENERAL PUBLIC LICENSE WITH THE CLASSPATH EXCEPTION 6 | 7 | However Github incorrectly detects this license, so it has been moved into REAL-LICENSE.txt file. -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/com/badlogic/gdx/controllers/desktop/DesktopControllerManager.java: -------------------------------------------------------------------------------- 1 | package com.badlogic.gdx.controllers.desktop; 2 | 3 | import uk.co.electronstudio.sdl2gdx.SDL2ControllerManager; 4 | 5 | public class DesktopControllerManager extends SDL2ControllerManager { 6 | } 7 | -------------------------------------------------------------------------------- /src/com/badlogic/gdx/controllers/lwjgl3/Lwjgl3ControllerManager.java: -------------------------------------------------------------------------------- 1 | package com.badlogic.gdx.controllers.lwjgl3; 2 | 3 | import uk.co.electronstudio.sdl2gdx.SDL2ControllerManager; 4 | 5 | public class Lwjgl3ControllerManager extends SDL2ControllerManager { 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/uk/co/electronstudio/sdl2gdx/RumbleController.java: -------------------------------------------------------------------------------- 1 | package uk.co.electronstudio.sdl2gdx; 2 | 3 | import com.badlogic.gdx.controllers.Controller; 4 | 5 | public interface RumbleController extends Controller { 6 | boolean rumble(float leftMagnitude, float rightMagnitude, int duration_ms); 7 | } 8 | -------------------------------------------------------------------------------- /src/org/libsdl/SDL_GameControllerID.java: -------------------------------------------------------------------------------- 1 | package org.libsdl; 2 | 3 | import java.util.Objects; 4 | 5 | public class SDL_GameControllerID { 6 | final int id; 7 | SDL_GameControllerID(int id) { this.id = id;} 8 | 9 | @Override 10 | public boolean equals(Object o) { 11 | if (this == o) return true; 12 | if (o == null || getClass() != o.getClass()) return false; 13 | SDL_GameControllerID that = (SDL_GameControllerID) o; 14 | return id == that.id; 15 | } 16 | 17 | @Override 18 | public int hashCode() { 19 | return Objects.hash(id); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/org/libsdl/SDL_JoystickID.java: -------------------------------------------------------------------------------- 1 | package org.libsdl; 2 | 3 | import java.util.Objects; 4 | 5 | public final class SDL_JoystickID { 6 | public final int id; 7 | SDL_JoystickID(int id) { this.id = id;} 8 | 9 | @Override 10 | public boolean equals(Object o) { 11 | if (this == o) return true; 12 | if (o == null || getClass() != o.getClass()) return false; 13 | SDL_JoystickID that = (SDL_JoystickID) o; 14 | return id == that.id; 15 | } 16 | 17 | @Override 18 | public int hashCode() { 19 | return Objects.hash(id); 20 | } 21 | 22 | @Override 23 | public String toString(){ 24 | return ""+id; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /overview.html: -------------------------------------------------------------------------------- 1 | 2 |

Java SDL - GDX Controllers

3 |

This library provides APIs at three layers:

4 |
    5 |
  1. A Java wrapper around SDL. Currently we wrap most of Joystick and GameController. PRs to wrap further APIs are welcome. This wrapper is as close to the C source as 6 | possible, so you should be able to port any SDL examples with no changes. 7 |
  2. An OO wrapper on top of layer 1. The same functions as provided by SDL, but with a class based API to make them more friendly to use. 8 |
  3. An implementation of LibGDX Controller API on top of layer 2. You can slot this straight in to any LibGDX app, or you can use it directly in a non-LibGDX app. 9 |
10 |

Thanks to Jamepad by William Harman for providing the build system and inspiring this project.

11 | 12 | 13 | -------------------------------------------------------------------------------- /docs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Java 2 | 3 | jni/ 4 | *.class 5 | *.war 6 | *.ear 7 | hs_err_pid* 8 | 9 | ## GWT 10 | war/ 11 | html/war/gwt_bree/ 12 | html/gwt-unitCache/ 13 | .apt_generated/ 14 | html/war/WEB-INF/deploy/ 15 | html/war/WEB-INF/classes/ 16 | .gwt/ 17 | gwt-unitCache/ 18 | www-test/ 19 | .gwt-tmp/ 20 | 21 | ## Android Studio and Intellij and Android in general 22 | android/libs/armeabi/ 23 | android/libs/armeabi-v7a/ 24 | android/libs/x86/ 25 | android/gen/ 26 | .idea/ 27 | *.ipr 28 | *.iws 29 | *.iml 30 | out/ 31 | com_crashlytics_export_strings.xml 32 | 33 | ## Eclipse 34 | .classpath 35 | .project 36 | .metadata 37 | **/bin/ 38 | tmp/ 39 | *.tmp 40 | *.bak 41 | *.swp 42 | *~.nib 43 | local.properties 44 | .settings/ 45 | .loadpath 46 | .externalToolBuilders/ 47 | *.launch 48 | 49 | ## NetBeans 50 | **/nbproject/private/ 51 | build/ 52 | nbbuild/ 53 | dist/ 54 | nbdist/ 55 | nbactions.xml 56 | nb-configuration.xml 57 | 58 | ## Gradle 59 | 60 | .gradle 61 | gradle-app.setting 62 | build/ 63 | 64 | ## OS Specific 65 | .DS_Store 66 | -------------------------------------------------------------------------------- /docs/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview List (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 |
All Classes
13 |
14 |

Packages

15 | 20 |
21 |

 

22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/tests/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | uk.co.electronstudio.sdl2gdx.tests (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 |

uk.co.electronstudio.sdl2gdx.tests

13 |
14 |

Classes

15 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/org/libsdl/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | org.libsdl (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 |

org.libsdl

13 |
14 |

Classes

15 | 24 |

Exceptions

25 | 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | uk.co.electronstudio.sdl2gdx (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 |

uk.co.electronstudio.sdl2gdx

13 |
14 |

Interfaces

15 | 18 |

Classes

19 | 24 |

Enums

25 | 30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /ADVANCED.md: -------------------------------------------------------------------------------- 1 | # what if you want to use a feature of SDL that is not supported by the LibGDX Controller API, e.g. rumble? 2 | 3 | #### 1 LibGDX core project 4 | 5 | You can make your core subproject depend on sdl2gdx. 6 | 7 | ```diff 8 | project(":core") { 9 | dependencies { 10 | + compile "uk.co.electronstudio.sdl2gdx:sdl2gdx:1.0.+" 11 | } 12 | } 13 | ``` 14 | 15 | Then typecast to SDL2Controller when you need to access the SDL2 APIs. 16 | 17 | ```java 18 | SDL2Controller controller = (SDL2Controller)Controllers.getControllers().get(0); 19 | controller.rumble(1.0f,1.0f,500); 20 | ``` 21 | 22 | Unforunately a GDX core subproject 23 | is not supposed to have native dependencies, so doing this will break other subprojects, e.g. 24 | mobile. 25 | 26 | 27 | #### 2 Reflection 28 | 29 | To avoid breaking things, you can add the dependency to your desktop subproject build, not core. Then in your core project, 30 | whenever you want to access an SDL feature, use reflection. 31 | 32 | ```java 33 | Method method = null; 34 | Controller controller = Controllers.getControllers().get(0); 35 | for( Method m: controller.getClass().getMethods()){ 36 | if(m.getName().equals("rumble"))method = m; 37 | } 38 | try { 39 | method.invoke(controller, 1f, 1f, 500); 40 | } catch (IllegalAccessException | InvocationTargetException e) { 41 | e.printStackTrace(); 42 | } 43 | ``` 44 | 45 | This is slower and unsafe, but avoids dependencies in your core project so your mobile projects still work. 46 | 47 | #### 3 Wrapper 48 | 49 | The 'proper' way to do it would be to write an interface around SDL2ControllerManager and then 50 | provide separate jars, one with the SDL native implementation to be used on desktop and one with a noop implementation for mobile. (Or an implementation that wraps GDXController.) 51 | 52 | But then you aren't using the GDX Controller API anymore, you're using a similiar but 53 | incompatible API. If you don't care about being a slot-in replacement for GDX Controller, maybe you'd prefer to just [call SDL directly](https://electronstudio.github.io/sdl2gdx/org/libsdl/SDL.html)? 54 | 55 | PRs and suggestions for this are welcome! -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /BUILDING.md: -------------------------------------------------------------------------------- 1 | # Building 2 | 3 | ## Overview 4 | 5 | 1. Clone the repo on Linux. Run `./gradlew linuxNatives` 6 | 2. The binaries for Windows are cross-compiled and so also need to be built on Linux (or MacOS). Run `./gradlew windowsNatives` 7 | 3. Clone the repo on a mac. Copy the files you just built (from the `libs` folder) to the mac. 8 | 4. On the mac, run `./gradlew OSXNatives` 9 | 5. Run `./gradlew uberjar` to generate a .jar file with all the dependencies bundled. 10 | 11 | ## Linux build dependencies 12 | 13 | The following packages (or equivalents) are needed: 14 | 15 | ``` 16 | ant 17 | build-essential 18 | sdl2-dev 19 | ``` 20 | 21 | If you've built C stuff for different platforms and bitnesses, you probably have all this stuff. If not, use your package manager to get them all. It should be something like this if you're on Ubuntu or Debian or whatever: 22 | 23 | ``` 24 | sudo apt-get install ant build-essential sdl2-dev 25 | ``` 26 | 27 | sdl2-config must be in the path. 28 | 29 | If your distro doesn't have an up to date version of SDL or you get errors, you can build it yourself from source: 30 | 31 | ``` 32 | make clean; ./configure CFLAGS="-fPIC -include src/force_link_glibc_2.5.h" CPPFLAGS="-fPIC -include src/force_link_glibc_2.5.h" --disable-audio --disable-render --disable-filesystem --enable-hidapi 33 | make -j 8; sudo make install 34 | ``` 35 | 36 | The glibc header is to allow it work on older versions of glibc than the one currently installed. 37 | 38 | ## Windows (cross-compiled on Linux/MacOS) build dependencies 39 | 40 | Linux: 41 | ``` 42 | sudo apt-get install ant mingw-w64 43 | ``` 44 | MacOS: 45 | ``` 46 | brew install ant mingw-w64 47 | ``` 48 | 49 | You need to install cross-compiled Windows 32 and 64 bit versions of SDL, e.g. 50 | 51 | ``` 52 | make clean; ./configure --host=i686-w64-mingw32 --disable-audio --disable-render --disable-filesystem --enable-hidapi ; make -j 8; sudo make install 53 | make clean; ./configure --host=x86_64-w64-mingw32 --disable-audio --disable-render --disable-filesystem --enable-hidapi ; make -j 8; sudo make install 54 | ``` 55 | 56 | sdl2-config is assumed to be in /usr/local/cross-tools/ if it is not found there you will need to edit JamepadNativesBuild.java with the correct path. 57 | 58 | ## MacOS build dependencies 59 | 60 | The MacOS binaries currently must be built on MacOS. (You can build the Windows ones here too with cross-compiler). It is probably possible to build the Linux binaries also, but I haven't found a cross-compiler that works fully. 61 | 62 | `brew install sdl2 ant` 63 | 64 | or build SDL yourself: 65 | 66 | ``` 67 | make clean; ./configure --disable-audio --disable-render --disable-filesystem ; make -j 8 ; sudo make install 68 | 69 | ``` 70 | 71 | -------------------------------------------------------------------------------- /docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | sdl2gdx API 7 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | <noscript> 69 | <div>JavaScript is disabled on your browser.</div> 70 | </noscript> 71 | <h2>Frame Alert</h2> 72 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /src/uk/co/electronstudio/sdl2gdx/tests/SDLHotplugTest.java: -------------------------------------------------------------------------------- 1 | package uk.co.electronstudio.sdl2gdx.tests; 2 | 3 | import com.badlogic.gdx.controllers.Controller; 4 | import com.badlogic.gdx.controllers.ControllerListener; 5 | import com.badlogic.gdx.controllers.PovDirection; 6 | import org.libsdl.SDL; 7 | import uk.co.electronstudio.sdl2gdx.SDL2ControllerManager; 8 | import com.badlogic.gdx.math.Vector3; 9 | import org.libsdl.SDL_Error; 10 | 11 | public class SDLHotplugTest { 12 | private static Controller recent; 13 | @SuppressWarnings("InfiniteLoopStatement") 14 | public static void main(String[] args){ 15 | SDL.SDL_SetHint("SDL_XINPUT_ENABLED", "0"); 16 | SDL2ControllerManager manager = new SDL2ControllerManager(); 17 | 18 | manager.addListenerAndRunForConnectedControllers(new ControllerListener() { 19 | @Override 20 | public void connected(Controller controller) { 21 | System.out.println("*** CONNECTED "+controller); 22 | recent=controller; 23 | } 24 | 25 | @Override 26 | public void disconnected(Controller controller) { 27 | System.out.println("*** DISCONNECTED "+controller); 28 | } 29 | 30 | @Override 31 | public boolean buttonDown(Controller controller, int buttonCode) { 32 | System.out.println("BUTTON DOWN "+controller+" "+buttonCode); 33 | return false; 34 | } 35 | 36 | @Override 37 | public boolean buttonUp(Controller controller, int buttonCode) { 38 | System.out.println("BUTTON UP "+controller+" "+buttonCode); 39 | return false; 40 | } 41 | 42 | @Override 43 | public boolean axisMoved(Controller controller, int axisCode, float value) { 44 | System.out.println("AXIS MOVED "+controller+" "+axisCode+" "+value); 45 | return false; 46 | } 47 | 48 | @Override 49 | public boolean povMoved(Controller controller, int povCode, PovDirection value) { 50 | System.out.println("POV MOVED +"+controller+" "+povCode+" "+value.toString()); 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean xSliderMoved(Controller controller, int sliderCode, boolean value) { 56 | System.out.println("XSLIDER MOVED +"+controller+" "+sliderCode+" "+value); 57 | return false; 58 | } 59 | 60 | @Override 61 | public boolean ySliderMoved(Controller controller, int sliderCode, boolean value) { 62 | System.out.println("YSLIDER MOVED +"+controller+" "+sliderCode+" "+value); 63 | return false; 64 | } 65 | 66 | @Override 67 | public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value) { 68 | System.out.println("ACCELEROMETER MOVED +"+controller+" "+accelerometerCode+" "+value); 69 | return false; 70 | } 71 | }); 72 | 73 | 74 | while (true){ 75 | try { 76 | manager.pollState(); 77 | // if(recent!=null){ 78 | // System.out.println(recent.getButton(0)); 79 | // } 80 | try { 81 | Thread.sleep(16); 82 | } catch (InterruptedException e) { 83 | e.printStackTrace(); 84 | } 85 | } catch (SDL_Error sdl_error) { 86 | sdl_error.printStackTrace(); 87 | } 88 | } 89 | 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Deprecated API

73 |

Contents

74 |
75 | 76 |
77 | 78 | 79 |
Skip navigation links
80 | 81 | 82 | 83 | 92 |
93 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Advert 2 | 3 | [RetroWar: 8-bit Party Battle](https://store.steampowered.com/app/664240/RetroWar_8bit_Party_Battle/?git) is out now. Defeat up to 15 of your friends in a tournament of 80s-inspired retro mini games. 4 | 5 | # sdl2gdx (Java SDL & GDX Controllers) 6 | 7 | ## What 8 | 9 | This library provides APIs at three layers: 10 | 1. [A Java wrapper around SDL](https://electronstudio.github.io/sdl2gdx/org/libsdl/SDL.html). Currently we wrap most of Joystick and GameController. PRs to wrap further APIs are welcome. This wrapper is as close to the C source as 11 | possible, so you should be able to port any SDL examples with no changes. 12 | 2. [An OO wrapper](https://electronstudio.github.io/sdl2gdx/org/libsdl/SDL_Joystick.html) on top of layer 1. The same functions as provided by SDL, but with a class based API to make them more friendly to use. 13 | 3. [An implementation of LibGDX Controller API](https://electronstudio.github.io/sdl2gdx/uk/co/electronstudio/sdl2gdx/SDL2Controller.html) on top of layer 2. You can slot this straight in to any LibGDX app, or you can use it directly in a non-LibGDX app. 14 | 15 | Thanks to [Jamepad](https://github.com/williamahartman/Jamepad) by William Harman for providing the basis, native build system and inspiration for this project. 16 | 17 | ## Why 18 | 19 | Compared to the default LibGDX Controller implementation: 20 | * __Hotplug__ works. 21 | * Doesn't quit working when the screenmode changes. 22 | * __Rumble__! 23 | * Can get more info, such as device power level and XInput Player LED number. 24 | * Database of __mappings__ for large number of controllers, so you don't have to worry about it. 25 | * SDL is recommended by Valve as second best way to do input for __Steam__ (after Steam Input of course!) 26 | * Supports __Nintendo__ and __Sony__ controllers using USB drivers taken from Steam. 27 | * Supports more than 4 XInput controllers 28 | 29 | ## How 30 | 31 | Add the repo if you don't have it in your build.gradle already 32 | 33 | ```diff 34 | buildscript{ 35 | repositories { 36 | + jcenter() 37 | } 38 | ``` 39 | 40 | ### For a project not using LibGDX 41 | 42 | ```diff 43 | dependencies { 44 | + compile "uk.co.electronstudio.sdl2gdx:sdl2gdx:1.0.+" 45 | } 46 | } 47 | ``` 48 | 49 | See examples and docs below for how to call the API. 50 | 51 | 52 | ### For a LibGDX desktop project 53 | 54 | ```diff 55 | project(":desktop") { 56 | dependencies { 57 | implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" 58 | implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" 59 | implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop" 60 | - implementation "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion" 61 | - implementation "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop" 62 | } 63 | } 64 | 65 | project(":core") { 66 | dependencies { 67 | implementation "com.badlogicgames.gdx:gdx:$gdxVersion" 68 | implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" 69 | implementation "com.badlogicgames.gdx:gdx-controllers:$gdxVersion" 70 | + implementation "uk.co.electronstudio.sdl2gdx:sdl2gdx:1.0.4" 71 | } 72 | } 73 | 74 | ``` 75 | 76 | This will use SDL under the hood for all your controllers. That's it, done, with 77 | no changes to your code! See [LibGDX docs](https://github.com/libgdx/libgdx/wiki/Controllers) for how to use controllers. 78 | 79 | Adding to the core project means you are free to use the additional SDL2 APIs anywhere in your code, but it won't work if 80 | you also have html5 or mobile projects. In that case add sdl2gdx to just the desktop project and not the core project. 81 | 82 | [Example LibGDX project](https://github.com/electronstudio/sdl2gdx-test) 83 | 84 | ### Rumble 85 | 86 | What if you want to use a feature of SDL that is not supported by the LibGDX Controller API, e.g. rumble? 87 | 88 | If you didn't add sdl2gdx to your core project, you will need instead to create a file `RumbleController.java` in your core project: 89 | 90 | ``` 91 | package uk.co.electronstudio.sdl2gdx; 92 | import com.badlogic.gdx.controllers.Controller; 93 | 94 | public interface RumbleController extends Controller { 95 | boolean rumble(float leftMagnitude, float rightMagnitude, int duration_ms); 96 | } 97 | 98 | ``` 99 | 100 | Then when you want to use rumble, make sure you're on Desktop platform and typecast: 101 | 102 | ``` 103 | if(Gdx.app.getType() == Application.ApplicationType.Desktop){ 104 | RumbleController controller = (RumbleController) Controllers.getControllers().get(0); 105 | controller.rumble(1.0f,1.0f,500); 106 | } 107 | ``` 108 | 109 | You could also typecast your Controller to SDL2Controller for other features like power level. 110 | 111 | ## Documentation 112 | 113 | * [API docs](https://electronstudio.github.io/sdl2gdx/) 114 | * [Hotplug CLI example](src/uk/co/electronstudio/sdl2gdx/tests/SDLHotplugTest.java) 115 | * [GUI example](src/uk/co/electronstudio/sdl2gdx/tests/SDLTest.java) 116 | 117 | 118 | ## You might also like 119 | * [Jamepad](https://github.com/williamahartman/Jamepad) - Alternate API for accessing sdl2gdx 120 | * [RetroWar-common](https://github.com/electronstudio/retrowar-common) - LibGDX extension library 121 | * [RetroWar](http://retrowar.net) - My game 122 | 123 | ## License 124 | 125 | sdl2gdx is distributed under the GPL license with the Classpath Exception to allow linking, the same as OpenJDK itself, so you can use it 126 | anywhere that you use the JDK, for both free and non-free ('closed source') projects. 127 | 128 | ## Building from source 129 | 130 | See [BUILDING](BUILDING.md). 131 | -------------------------------------------------------------------------------- /src/com/badlogic/gdx/jnigen/BuildExecutorFixed.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | package com.badlogic.gdx.jnigen; 18 | 19 | import java.io.BufferedReader; 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.io.InputStreamReader; 23 | import java.util.regex.Matcher; 24 | import java.util.regex.Pattern; 25 | 26 | /** Executes an ant script and its targets or an Android NDK build. See {@link AntScriptGenerator}. 27 | * @author mzechner */ 28 | public class BuildExecutorFixed { 29 | /** Execute the Ant script file with the given parameters. 30 | * @param buildFile 31 | * @param params 32 | * @return whether the Ant succeeded */ 33 | public static boolean executeAnt (String buildFile, String params) { 34 | 35 | FileDescriptor build = new FileDescriptor(buildFile); 36 | String ant = System.getProperty("os.name").contains("Windows") ? "ant.bat" : "ant"; 37 | String command = ant + " -f " + build.file().getAbsolutePath() + " " + params; 38 | System.out.println("Executing '" + command + "'"); 39 | return startProcess(command, build.parent().file()); 40 | } 41 | 42 | /** Execute ndk-build in the given directory 43 | * @param directory */ 44 | public static void executeNdk (String directory) { 45 | FileDescriptor build = new FileDescriptor(directory); 46 | String command = "ndk-build"; 47 | startProcess(command, build.file()); 48 | } 49 | 50 | private static boolean startProcess (String command, File directory) { 51 | try { 52 | final Process process = new ProcessBuilder(command.split(" ")).redirectErrorStream(true).start(); 53 | 54 | Thread t = new Thread(new Runnable() { 55 | @Override 56 | public void run () { 57 | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); 58 | String line = null; 59 | try { 60 | while ((line = reader.readLine()) != null) { 61 | // augment output with java file line references :D 62 | printFileLineNumber(line); 63 | } 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | private void printFileLineNumber (String line) { 70 | if (line.contains("warning") || line.contains("error")) { 71 | try { 72 | String fileName = getFileName(line); 73 | String error = getError(line); 74 | int lineNumber = getLineNumber(line) - 1; 75 | if (fileName != null && lineNumber >= 0) { 76 | FileDescriptor file = new FileDescriptor(fileName); 77 | if (file.exists()) { 78 | String[] content = file.readString().split("\n"); 79 | if (lineNumber < content.length) { 80 | for (int i = lineNumber; i >= 0; i--) { 81 | String contentLine = content[i]; 82 | if (contentLine.startsWith("//@line:")) { 83 | int javaLineNumber = Integer.parseInt(contentLine.split(":")[1].trim()); 84 | System.out.flush(); 85 | if (line.contains("warning")) { 86 | System.out.println("(" + file.nameWithoutExtension() + ".java:" 87 | + (javaLineNumber + (lineNumber - i) - 1) + "): " + error + ", original: " + line); 88 | System.out.flush(); 89 | } else { 90 | System.err.println("(" + file.nameWithoutExtension() + ".java:" 91 | + (javaLineNumber + (lineNumber - i) - 1) + "): " + error + ", original: " + line); 92 | System.err.flush(); 93 | } 94 | return; 95 | } 96 | } 97 | } 98 | } else { 99 | System.out.println(line); 100 | } 101 | } 102 | } catch (Throwable t) { 103 | System.out.println(line); 104 | // silent death... 105 | } 106 | } else { 107 | System.out.println(line); 108 | } 109 | } 110 | 111 | private String getFileName (String line) { 112 | Pattern pattern = Pattern.compile("(.*):([0-9])+:[0-9]+:"); 113 | Matcher matcher = pattern.matcher(line); 114 | matcher.find(); 115 | String fileName = matcher.groupCount() >= 2 ? matcher.group(1).trim() : null; 116 | if (fileName == null) return null; 117 | int index = fileName.indexOf(" "); 118 | if (index != -1) 119 | return fileName.substring(index).trim(); 120 | else 121 | return fileName; 122 | } 123 | 124 | private String getError (String line) { 125 | Pattern pattern = Pattern.compile(":[0-9]+:[0-9]+:(.+)"); 126 | Matcher matcher = pattern.matcher(line); 127 | matcher.find(); 128 | return matcher.groupCount() >= 1 ? matcher.group(1).trim() : null; 129 | } 130 | 131 | private int getLineNumber (String line) { 132 | Pattern pattern = Pattern.compile(":([0-9]+):[0-9]+:"); 133 | Matcher matcher = pattern.matcher(line); 134 | matcher.find(); 135 | return matcher.groupCount() >= 1 ? Integer.parseInt(matcher.group(1)) : -1; 136 | } 137 | }); 138 | t.setDaemon(true); 139 | t.start(); 140 | process.waitFor(); 141 | return process.exitValue() == 0; 142 | } catch (Exception e) { 143 | e.printStackTrace(); 144 | return false; 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /docs/overview-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

sdl2gdx API

73 |
74 |
75 |
76 |
Java SDL - GDX Controllers
77 |
78 |

See: Description

79 |
80 |
81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
Packages 
PackageDescription
org.libsdl 
uk.co.electronstudio.sdl2gdx 
uk.co.electronstudio.sdl2gdx.tests 
102 |
103 |
104 | 105 | 106 |

Java SDL - GDX Controllers

107 |

This library provides APIs at three layers:

108 |
    109 |
  1. A Java wrapper around SDL. Currently we wrap most of Joystick and GameController. PRs to wrap further APIs are welcome. This wrapper is as close to the C source as 110 | possible, so you should be able to port any SDL examples with no changes. 111 |
  2. An OO wrapper on top of layer 1. The same functions as provided by SDL, but with a class based API to make them more friendly to use. 112 |
  3. An implementation of LibGDX Controller API on top of layer 2. You can slot this straight in to any LibGDX app, or you can use it directly in a non-LibGDX app. 113 |
114 |

Thanks to Jamepad by William Harman for providing the build system and inspiring this project.

115 |
116 | 117 |
118 | 119 | 120 |
Skip navigation links
121 | 122 | 123 | 124 | 133 |
134 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/org/libsdl/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | org.libsdl Class Hierarchy (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package org.libsdl

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 102 |
103 | 104 |
105 | 106 | 107 |
Skip navigation links
108 | 109 | 110 | 111 | 120 |
121 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/tests/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | uk.co.electronstudio.sdl2gdx.tests (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package uk.co.electronstudio.sdl2gdx.tests

73 |
74 |
75 | 108 |
109 | 110 |
111 | 112 | 113 |
Skip navigation links
114 | 115 | 116 | 117 | 126 |
127 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/tests/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | uk.co.electronstudio.sdl2gdx.tests Class Hierarchy (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package uk.co.electronstudio.sdl2gdx.tests

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 106 |
107 | 108 |
109 | 110 | 111 |
Skip navigation links
112 | 113 | 114 | 115 | 124 |
125 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Serialized Form (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Serialized Form

73 |
74 |
75 | 160 |
161 | 162 |
163 | 164 | 165 |
Skip navigation links
166 | 167 | 168 | 169 | 178 |
179 | 206 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /docs/org/libsdl/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | org.libsdl (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package org.libsdl

73 |
74 |
75 | 138 |
139 | 140 |
141 | 142 | 143 |
Skip navigation links
144 | 145 | 146 | 147 | 156 |
157 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /src/org/libsdl/SDL_GameController.java: -------------------------------------------------------------------------------- 1 | package org.libsdl; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.nio.file.FileSystems; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.nio.file.StandardCopyOption; 9 | import java.util.Objects; 10 | 11 | public final class SDL_GameController { 12 | long ptr; 13 | 14 | final float AXIS_MIN, AXIS_MAX; 15 | 16 | SDL_GameController(long ptr){ 17 | this.ptr=ptr; 18 | AXIS_MAX=SDL.SDL_JOYSTICK_AXIS_MAX(); 19 | AXIS_MIN=SDL.SDL_JOYSTICK_AXIS_MIN(); 20 | } 21 | 22 | public void close(){ 23 | if(ptr !=0){ 24 | SDL.SDL_GameControllerClose(ptr); 25 | ptr=0; 26 | } 27 | } 28 | 29 | public boolean getAttached(){ 30 | return (ptr !=0 && SDL.SDL_GameControllerGetAttached(ptr)); 31 | } 32 | 33 | public float getAxis(int axis){ 34 | if(!getAttached()) return 0; // FIXME I don't think this check is necessary 35 | int i = SDL.SDL_GameControllerGetAxis(ptr, axis); 36 | if(i<0) return i/-AXIS_MIN; 37 | return i/AXIS_MAX; 38 | } 39 | 40 | // TODO 41 | //getAxisFromString 42 | // //getBindForButton 43 | 44 | public boolean getButton(int button){ 45 | return (getAttached() && SDL.SDL_GameControllerGetButton(ptr, button)==1); 46 | } 47 | 48 | 49 | //TODO 50 | 51 | //getButtonFromString 52 | 53 | 54 | 55 | 56 | 57 | public String name(){ 58 | return SDL.SDL_GameControllerName(ptr); 59 | } 60 | 61 | // public SDL_Joystick getJoystick(){ 62 | // return new SDL_Joystick(SDL.SDL_GameControllerGetJoystick(ptr)); 63 | // } 64 | 65 | //TODO 66 | //getStringForAxis 67 | //getStringForButton 68 | //getMapping 69 | 70 | 71 | /** 72 | * This method adds mappings held in the specified file. The file is copied to the temp folder so 73 | * that it can be read by the native code (if running from a .jar for instance) 74 | * 75 | * @param path The path to the file containing controller mappings. 76 | * @throws IOException if the file cannot be read, copied to a temp folder, or deleted. 77 | * @throws IllegalStateException if the mappings cannot be applied to SDL 78 | */ 79 | public static boolean addMappingsFromFile(String path, Class sourceClass) throws IOException, IllegalStateException, SDL_Error { 80 | /* 81 | Copy the file to a temp folder. SDL can't read files held in .jars, and that's probably how 82 | most people would use this library. 83 | */ 84 | Path extractedLoc = Files.createTempFile(null, null).toAbsolutePath(); 85 | InputStream source = null; 86 | if(sourceClass!=null) { 87 | try { 88 | source = sourceClass.getResourceAsStream(path); 89 | } catch (Exception e) { 90 | e.printStackTrace(); 91 | } 92 | } 93 | if(source==null) source = ClassLoader.getSystemResourceAsStream(path); 94 | if(source==null) throw new IOException("Cannot open resource from classpath "+path); 95 | 96 | Files.copy(source, extractedLoc, StandardCopyOption.REPLACE_EXISTING); 97 | 98 | System.out.println("EXTRACTED LOC "+extractedLoc.toString()); 99 | 100 | int result = SDL.SDL_GameControllerAddMappingsFromFile(extractedLoc.toString()); 101 | 102 | Files.delete(extractedLoc); 103 | 104 | return (intToBoolean(result)); 105 | } 106 | 107 | public static boolean addMappingsFromFile(String path) throws IOException, IllegalStateException, SDL_Error{ 108 | return addMappingsFromFile(path, null); 109 | } 110 | 111 | 112 | public boolean addMapping(String mappingString) throws SDL_Error{ 113 | return intToBoolean(SDL.SDL_GameControllerAddMapping(mappingString)); 114 | } 115 | 116 | public static boolean eventStateQuery() throws SDL_Error{ 117 | return eventState(-1); 118 | } 119 | 120 | public static boolean eventStateIgnore() throws SDL_Error{ 121 | return eventState(0); 122 | } 123 | 124 | public static boolean eventStateEnable() throws SDL_Error{ 125 | return eventState(1); 126 | } 127 | 128 | private static boolean eventState(int i) throws SDL_Error { 129 | return intToBoolean(SDL.SDL_GameControllerEventState(i)); 130 | } 131 | 132 | private static boolean intToBoolean(int i) throws SDL_Error{ 133 | if(i>0) return true; 134 | else if(i==0) return false; 135 | else throw new SDL_Error(); 136 | } 137 | 138 | 139 | // TODO 140 | //GameControllerGetDeviceGUID() 141 | 142 | //TODO 143 | //GameControllerGetGUIDFromString 144 | 145 | public static SDL_GameController GameControllerFromInstanceID(SDL_GameControllerID joyid){ 146 | return new SDL_GameController(SDL.SDL_GameControllerFromInstanceID(joyid.id)); 147 | } 148 | 149 | /** 150 | * Return the SDL_GameController associated with a player index. 151 | */ 152 | 153 | public static SDL_GameController SDL_GameControllerFromPlayerIndex(int player_index){ 154 | return new SDL_GameController(SDL.SDL_GameControllerFromPlayerIndex(player_index)); 155 | } 156 | 157 | /** 158 | * Get the implementation dependent name of a game controller. 159 | * This can be called before any controllers are opened. 160 | * If no name can be found, this function returns NULL. 161 | */ 162 | public static String GameControllerNameForIndex(int device_index){ 163 | return SDL.SDL_GameControllerNameForIndex(device_index); 164 | } 165 | 166 | /** 167 | * Return the type of this currently opened controller 168 | */ 169 | public int getType(){ 170 | return SDL.SDL_GameControllerGetType(ptr); 171 | } 172 | 173 | /** 174 | * Get the player index of an opened game controller, or -1 if it's not available 175 | * 176 | * For XInput controllers this returns the XInput user index. 177 | */ 178 | public int getPlayerIndex(){ 179 | return SDL.SDL_GameControllerGetPlayerIndex(ptr); 180 | } 181 | 182 | /** 183 | * Set the player index of an opened game controller 184 | */ 185 | public void setPlayerIndex(int player_index){ 186 | SDL.SDL_GameControllerSetPlayerIndex(ptr, player_index); 187 | } 188 | 189 | public static SDL_GameController GameControllerOpen(int i){ 190 | return new SDL_GameController(SDL.SDL_GameControllerOpen(i)); 191 | } 192 | 193 | public static void GameControllerUpdate(){ 194 | SDL.SDL_GameControllerUpdate(); 195 | } 196 | 197 | public boolean isGameController(int joystick_index){ 198 | return SDL.SDL_IsGameController(joystick_index); 199 | } 200 | 201 | 202 | 203 | 204 | @Override 205 | public boolean equals(Object o) { 206 | if (this == o) return true; 207 | if (o == null || getClass() != o.getClass()) return false; 208 | SDL_GameController that = (SDL_GameController) o; 209 | return ptr == that.ptr; 210 | } 211 | 212 | @Override 213 | public int hashCode() { 214 | return Objects.hash(ptr); 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | uk.co.electronstudio.sdl2gdx Class Hierarchy (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package uk.co.electronstudio.sdl2gdx

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 89 |

Interface Hierarchy

90 | 97 |

Enum Hierarchy

98 | 111 |
112 | 113 |
114 | 115 | 116 |
Skip navigation links
117 | 118 | 119 | 120 | 129 |
130 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /src/uk/co/electronstudio/sdl2gdx/SDL2ControllerManager.java: -------------------------------------------------------------------------------- 1 | package uk.co.electronstudio.sdl2gdx; 2 | 3 | 4 | import com.badlogic.gdx.Gdx; 5 | import com.badlogic.gdx.controllers.Controller; 6 | import com.badlogic.gdx.controllers.ControllerListener; 7 | import com.badlogic.gdx.controllers.ControllerManager; 8 | import com.badlogic.gdx.controllers.PovDirection; 9 | import com.badlogic.gdx.utils.Array; 10 | import com.badlogic.gdx.utils.IntArray; 11 | import org.libsdl.*; 12 | 13 | import static uk.co.electronstudio.sdl2gdx.SDL2ControllerManager.InputPreference.*; 14 | 15 | public class SDL2ControllerManager implements ControllerManager { 16 | 17 | private final Array controllers = new Array<>(); 18 | private final Array polledControllers = new Array<>(); 19 | private final IntArray connectedInstanceIds = new IntArray(128); 20 | private final Array listeners = new Array<>(); 21 | 22 | private boolean running = true; 23 | 24 | public SDL2ControllerManager() { 25 | this(getInputPreferenceProperty()); 26 | } 27 | 28 | private static InputPreference getInputPreferenceProperty() { 29 | String ip = System.getProperty("SDL.input"); 30 | if(ip==null) return XINPUT; 31 | switch (ip){ 32 | case "XINPUT": return XINPUT; 33 | case "RAW_INPUT": return RAW_INPUT; 34 | case "DIRECT_INPUT": return DIRECT_INPUT; 35 | default: return XINPUT; 36 | } 37 | } 38 | 39 | public enum InputPreference{ 40 | XINPUT, DIRECT_INPUT, RAW_INPUT 41 | } 42 | 43 | public SDL2ControllerManager(InputPreference inputPreference) { 44 | SDL.SDL_SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1"); 45 | SDL.SDL_SetHint("SDL_ACCELEROMETER_AS_JOYSTICK", "0"); 46 | SDL.SDL_SetHint("SDL_MAC_BACKGROUND_APP", "1"); 47 | 48 | switch (inputPreference) { 49 | case XINPUT: 50 | SDL.SDL_SetHint("SDL_XINPUT_ENABLED", "1"); 51 | SDL.SDL_SetHint("SDL_JOYSTICK_RAWINPUT", "0"); 52 | break; 53 | case RAW_INPUT: 54 | SDL.SDL_SetHint("SDL_XINPUT_ENABLED", "1"); 55 | SDL.SDL_SetHint("SDL_JOYSTICK_RAWINPUT", "1"); 56 | break; 57 | case DIRECT_INPUT: 58 | SDL.SDL_SetHint("SDL_XINPUT_ENABLED", "0"); 59 | SDL.SDL_SetHint("SDL_JOYSTICK_RAWINPUT", "0"); 60 | break; 61 | } 62 | 63 | if (SDL.SDL_Init(SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_JOYSTICK | SDL.SDL_INIT_GAMECONTROLLER) != 0) { 64 | throw new RuntimeException("SDL_Init failed: " + SDL.SDL_GetError()); 65 | } 66 | 67 | 68 | try { 69 | SDL_GameController.addMappingsFromFile("/gamecontrollerdb.txt", getClass()); 70 | } catch (Exception e) { 71 | System.out.println("Failed to load gamecontrollerdb.txt"); 72 | e.printStackTrace(); 73 | } 74 | 75 | try { 76 | for (int i = 0; i < SDL_Joystick.numJoysticks(); i++) { 77 | String name = SDL_Joystick.joystickNameForIndex(i); 78 | System.out.printf("Joystick %d: %s\n", i, name != null ? name : "Unknown Joystick"); 79 | connected(new SDL2Controller(this, i)); 80 | } 81 | } catch (SDL_Error e) { 82 | e.printStackTrace(); 83 | } 84 | 85 | if (Gdx.app != null) { 86 | Gdx.app.postRunnable(new Runnable() { 87 | @Override 88 | public void run() { 89 | if(!running) return; 90 | try { 91 | pollState(); 92 | } catch (SDL_Error e) { 93 | e.printStackTrace(); 94 | } 95 | Gdx.app.postRunnable(this); 96 | } 97 | }); 98 | } 99 | } 100 | 101 | 102 | public void pollState() throws SDL_Error { 103 | SDL.SDL_PumpEvents(); 104 | // SDL.SDL_JoystickUpdate(); 105 | // sdl.update(); 106 | 107 | // System.out.println("numJoysticks "+ SDL_Joystick.numJoysticks()); 108 | // System.out.println("connectedInstanceIds "+connectedInstanceIds); 109 | 110 | for (int i = 0; i < SDL_Joystick.numJoysticks(); i++) { 111 | int id = SDL.SDL_JoystickGetDeviceInstanceID(i); 112 | if (!connectedInstanceIds.contains(id)) { 113 | // System.out.println("connectedInstanceIds "+connectedInstanceIds+" does not contain "+id); 114 | connected(new SDL2Controller(this, i)); 115 | } 116 | } 117 | 118 | 119 | polledControllers.addAll(controllers); 120 | for (Controller controller : polledControllers) { 121 | SDL2Controller c = (SDL2Controller) controller; 122 | if (c.isConnected()) { 123 | c.pollState(); 124 | } else { 125 | disconnected(c); 126 | } 127 | } 128 | polledControllers.clear(); 129 | 130 | } 131 | 132 | @Override 133 | public Array getControllers() { 134 | return controllers; 135 | } 136 | 137 | @Override 138 | public void addListener(ControllerListener listener) { 139 | listeners.add(listener); 140 | } 141 | 142 | public void addListenerAndRunForConnectedControllers(ControllerListener listener){ 143 | for(Controller controller : controllers){ 144 | listener.connected(controller); 145 | } 146 | addListener(listener); 147 | } 148 | 149 | @Override 150 | public void removeListener(ControllerListener listener) { 151 | listeners.removeValue(listener, true); 152 | } 153 | 154 | @Override 155 | public void clearListeners() { 156 | listeners.clear(); 157 | } 158 | 159 | private void connected(SDL2Controller controller) { 160 | System.out.println("connected " + controller); 161 | controllers.add(controller); 162 | connectedInstanceIds.add(controller.joystick.instanceID().id); 163 | for (ControllerListener listener : listeners) { 164 | listener.connected(controller); 165 | } 166 | } 167 | 168 | private void disconnected(SDL2Controller controller) { 169 | System.out.println("disconnected " + controller); 170 | controllers.removeValue(controller, false); 171 | connectedInstanceIds.removeValue(controller.joystick.instanceID().id); 172 | for (ControllerListener listener : listeners) { 173 | listener.disconnected(controller); 174 | } 175 | controller.close(); 176 | } 177 | 178 | void axisChanged(SDL2Controller controller, int axisCode, float value) { 179 | for (ControllerListener listener : listeners) { 180 | listener.axisMoved(controller, axisCode, value); 181 | } 182 | } 183 | 184 | void buttonChanged(SDL2Controller controller, int buttonCode, boolean value) { 185 | for (ControllerListener listener : listeners) { 186 | if (value) { 187 | listener.buttonDown(controller, buttonCode); 188 | } else { 189 | listener.buttonUp(controller, buttonCode); 190 | } 191 | } 192 | } 193 | 194 | void hatChanged(SDL2Controller controller, int hatCode, PovDirection value) { 195 | for (ControllerListener listener : listeners) { 196 | listener.povMoved(controller, hatCode, value); 197 | } 198 | } 199 | 200 | @Override 201 | public Array getListeners() { 202 | return listeners; 203 | } 204 | 205 | public void close(){ 206 | running=false; 207 | SDL.SDL_Quit(); 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | uk.co.electronstudio.sdl2gdx (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package uk.co.electronstudio.sdl2gdx

73 |
74 |
75 | 138 |
139 | 140 |
141 | 142 | 143 | 144 | 145 | 146 | 147 | 156 |
157 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /docs/org/libsdl/GameController.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | GameController (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 85 | 86 | 87 |
88 |
org.libsdl
89 |

Class GameController

90 |
91 |
92 |
    93 |
  • java.lang.Object
  • 94 |
  • 95 |
      96 |
    • org.libsdl.GameController
    • 97 |
    98 |
  • 99 |
100 |
101 |
    102 |
  • 103 |
    104 |
    105 |
    public class GameController
    106 | extends java.lang.Object
    107 |
  • 108 |
109 |
110 |
111 |
    112 |
  • 113 | 114 |
      115 |
    • 116 | 117 | 118 |

      Constructor Summary

      119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
      Constructors 
      Constructor and Description
      GameController() 
      128 |
    • 129 |
    130 | 131 |
      132 |
    • 133 | 134 | 135 |

      Method Summary

      136 |
        137 |
      • 138 | 139 | 140 |

        Methods inherited from class java.lang.Object

        141 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • 142 |
      143 |
    • 144 |
    145 |
  • 146 |
147 |
148 |
149 |
    150 |
  • 151 | 152 |
      153 |
    • 154 | 155 | 156 |

      Constructor Detail

      157 | 158 | 159 | 160 |
        161 |
      • 162 |

        GameController

        163 |
        public GameController()
        164 |
      • 165 |
      166 |
    • 167 |
    168 |
  • 169 |
170 |
171 |
172 | 173 | 174 |
175 | 176 | 177 | 178 | 179 | 180 | 181 | 190 |
191 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /src/uk/co/electronstudio/sdl2gdx/NativesBuild.java: -------------------------------------------------------------------------------- 1 | package uk.co.electronstudio.sdl2gdx; 2 | 3 | import com.badlogic.gdx.jnigen.*; 4 | import com.badlogic.gdx.jnigen.BuildTarget.TargetOs; 5 | 6 | import java.io.FileNotFoundException; 7 | 8 | class NativesBuild { 9 | 10 | static final String win32crossCompilePath="/usr/local/cross-tools/i686-w64-mingw32/bin/"; 11 | static final String win64crossCompilePath="/usr/local/cross-tools/x86_64-w64-mingw32/bin/"; 12 | static final String minSDLversion="2.0.9"; 13 | static final String macLibPath ="/usr/local/lib/libSDL2.a"; 14 | 15 | public static void main(String[] args) throws Exception { 16 | //Deal with arguments 17 | boolean useSystemSDL = false; 18 | boolean buildWindows = false; 19 | boolean buildLinux = false; 20 | boolean buildOSX = false; 21 | 22 | for(String s: args) { 23 | switch (s) { 24 | case "system-SDL2": 25 | useSystemSDL = true; 26 | break; 27 | case "build-windows": 28 | buildWindows = true; 29 | break; 30 | case "build-linux": 31 | buildLinux = true; 32 | break; 33 | case "build-OSX": 34 | buildOSX = true; 35 | break; 36 | } 37 | } 38 | 39 | System.out.println("Using system SDL (arg: system-SDL2) " + (useSystemSDL ? "ON" : "OFF")); 40 | System.out.println("Building for Windows (arg: build-windows) " + (buildWindows ? "ON" : "OFF")); 41 | System.out.println("Building for Linux (arg: build-linux) " + (buildLinux ? "ON" : "OFF")); 42 | System.out.println("Building for OSX (arg: build-OSX) " + (buildOSX ? "ON" : "OFF")); 43 | System.out.println(); 44 | 45 | BuildTarget lin64 = BuildTarget.newDefaultTarget(TargetOs.Linux, true); 46 | BuildTarget win32 = BuildTarget.newDefaultTarget(TargetOs.Windows, false); 47 | BuildTarget win64 = BuildTarget.newDefaultTarget(TargetOs.Windows, true); 48 | BuildTarget mac64 = BuildTarget.newDefaultTarget(TargetOs.MacOsX, true); 49 | 50 | if(buildLinux) { 51 | checkSDLVersion("sdl2-config", minSDLversion); 52 | 53 | lin64.cIncludes = new String[] {}; 54 | String cflags = execCmd("sdl2-config --cflags"); // "-I/usr/local/include/SDL2" 55 | lin64.cFlags = lin64.cFlags + " " + cflags; 56 | lin64.cppFlags = lin64.cFlags; 57 | lin64.linkerFlags = "-shared -m64"; 58 | String libraries = execCmd("sdl2-config --static-libs") 59 | .replace("-lSDL2","-l:libSDL2.a" ) 60 | .replace("/usr/lib//libSDL2.a", "/usr/lib/x86_64-linux-gnu/libSDL2.a"); 61 | //"-L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -l:libSDL2.a -Wl,--no-undefined -lm -ldl -lsndio -lpthread -lrt"; 62 | lin64.libraries = libraries; 63 | } 64 | 65 | if(buildOSX){ 66 | checkSDLVersion("sdl2-config", minSDLversion); 67 | 68 | mac64.cIncludes = new String[] {}; 69 | //mac64.headerDirs = new String[] {"/usr/local/include/SDL2"}; 70 | String cflags = execCmd("sdl2-config --cflags"); 71 | mac64.cFlags = cflags + " -c -Wall -O2 -arch x86_64 -DFIXED_POINT -fmessage-length=0 -fPIC -mmacosx-version-min=10.9 -stdlib=libc++"; 72 | mac64.cppFlags = mac64.cFlags; 73 | mac64.linkerFlags = "-shared -arch x86_64 -mmacosx-version-min=10.9"; 74 | mac64.libraries = macLibPath +" -lm -liconv -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-weak_framework,QuartzCore -Wl,-weak_framework,Metal"; 75 | // we cant use: 76 | // execCmd("sdl2-config --static-libs").replace("-lSDL2","-l:libSDL2.a" ) 77 | // because OSX has Clang, not GCC. See https://jonwillia.ms/2018/02/02/static-linking for the problem 78 | 79 | } 80 | 81 | if(buildWindows){ 82 | checkSDLVersion(win32crossCompilePath+"sdl2-config", minSDLversion); 83 | checkSDLVersion(win64crossCompilePath+"sdl2-config", minSDLversion); 84 | 85 | win32.cFlags = win32.cFlags + " " +execCmd(win32crossCompilePath+"sdl2-config --cflags"); 86 | win32.cppFlags = win32.cFlags; 87 | win32.libraries = execCmd(win32crossCompilePath+"sdl2-config --static-libs"); 88 | 89 | win64.cFlags = win64.cFlags + " " +execCmd(win64crossCompilePath+"sdl2-config --cflags"); 90 | win64.cppFlags = win64.cFlags; 91 | win64.libraries = execCmd(win64crossCompilePath+"sdl2-config --static-libs"); 92 | } 93 | 94 | //Generate native code, build scripts 95 | System.out.println("##### GENERATING NATIVE CODE AND BUILD SCRIPTS #####"); 96 | new NativeCodeGenerator().generate("src", "build/classes/java/main", "jni"); 97 | new AntScriptGenerator().generate( 98 | new BuildConfig("sdl2gdx", "build/tmp", "libs", "jni"), win32, win64, lin64, mac64 99 | ); 100 | System.out.println(); 101 | 102 | if(!useSystemSDL) { 103 | throw new IllegalArgumentException("system SDL must be used!"); 104 | } 105 | 106 | //Build library for all platforms and bitnesses 107 | if (buildWindows) { 108 | System.out.println("##### COMPILING NATIVES FOR WINDOWS #####"); 109 | BuildExecutorFixed.executeAnt("jni/build-windows32.xml", "-Dhas-compiler=true -Drelease=true clean postcompile"); 110 | BuildExecutorFixed.executeAnt("jni/build-windows64.xml", "-Dhas-compiler=true -Drelease=true clean postcompile"); 111 | System.out.println(); 112 | } 113 | if (buildLinux) { 114 | System.out.println("##### COMPILING NATIVES FOR LINUX #####"); 115 | BuildExecutorFixed.executeAnt("jni/build-linux64.xml", "-Dhas-compiler=true -Drelease=true clean postcompile"); 116 | System.out.println(); 117 | } 118 | if (buildOSX) { 119 | System.out.println("##### COMPILING NATIVES FOR OSX #####"); 120 | BuildExecutorFixed.executeAnt("jni/build-macosx64.xml", "-Dhas-compiler=true -Drelease=true clean postcompile"); 121 | System.out.println(); 122 | } 123 | 124 | System.out.println("##### PACKING NATIVES INTO .JAR #####"); 125 | BuildExecutorFixed.executeAnt("jni/build.xml", "pack-natives"); 126 | } 127 | 128 | private static void checkSDLVersion(String command, String version) throws FileNotFoundException{ 129 | String sdl = "0"; 130 | try { 131 | sdl = execCmd(command+" --version").trim(); 132 | } catch (Exception e){ 133 | System.out.println("SDL must be installed and "+command+" command must be on path."); 134 | e.printStackTrace(); 135 | } 136 | System.out.println("SDL version found: "+sdl); 137 | if(compareVersions(sdl, version)<0){ 138 | throw new FileNotFoundException("\n!!! SDL version must be >= "+version); 139 | } 140 | } 141 | 142 | public static String execCmd(String cmd) throws java.io.IOException { 143 | java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A"); 144 | return s.hasNext() ? s.next().trim() : ""; 145 | } 146 | 147 | public static int compareVersions(String v1, String v2) { 148 | String[] components1 = v1.split("\\."); 149 | String[] components2 = v2.split("\\."); 150 | int length = Math.min(components1.length, components2.length); 151 | for(int i = 0; i < length; i++) { 152 | int result = new Integer(components1[i]).compareTo(Integer.parseInt(components2[i])); 153 | if(result != 0) { 154 | return result; 155 | } 156 | } 157 | return Integer.compare(components1.length, components2.length); 158 | } 159 | } -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/SDL2Controllers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SDL2Controllers (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 85 | 86 | 87 |
88 |
uk.co.electronstudio.sdl2gdx
89 |

Class SDL2Controllers

90 |
91 |
92 |
    93 |
  • java.lang.Object
  • 94 |
  • 95 |
      96 |
    • uk.co.electronstudio.sdl2gdx.SDL2Controllers
    • 97 |
    98 |
  • 99 |
100 |
101 |
    102 |
  • 103 |
    104 |
    105 |
    public class SDL2Controllers
    106 | extends java.lang.Object
    107 |
  • 108 |
109 |
110 |
111 |
    112 |
  • 113 | 114 |
      115 |
    • 116 | 117 | 118 |

      Constructor Summary

      119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
      Constructors 
      Constructor and Description
      SDL2Controllers() 
      128 |
    • 129 |
    130 | 131 |
      132 |
    • 133 | 134 | 135 |

      Method Summary

      136 |
        137 |
      • 138 | 139 | 140 |

        Methods inherited from class java.lang.Object

        141 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • 142 |
      143 |
    • 144 |
    145 |
  • 146 |
147 |
148 |
149 |
    150 |
  • 151 | 152 |
      153 |
    • 154 | 155 | 156 |

      Constructor Detail

      157 | 158 | 159 | 160 |
        161 |
      • 162 |

        SDL2Controllers

        163 |
        public SDL2Controllers()
        164 |
      • 165 |
      166 |
    • 167 |
    168 |
  • 169 |
170 |
171 |
172 | 173 | 174 |
175 | 176 | 177 | 178 | 179 | 180 | 181 | 190 |
191 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /docs/org/libsdl/SDL_Error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SDL_Error (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 85 | 86 | 87 |
88 |
org.libsdl
89 |

Class SDL_Error

90 |
91 |
92 |
    93 |
  • java.lang.Object
  • 94 |
  • 95 |
      96 |
    • java.lang.Throwable
    • 97 |
    • 98 |
        99 |
      • java.lang.Exception
      • 100 |
      • 101 |
          102 |
        • org.libsdl.SDL_Error
        • 103 |
        104 |
      • 105 |
      106 |
    • 107 |
    108 |
  • 109 |
110 |
111 |
    112 |
  • 113 |
    114 |
    All Implemented Interfaces:
    115 |
    java.io.Serializable
    116 |
    117 |
    118 |
    119 |
    public class SDL_Error
    120 | extends java.lang.Exception
    121 |
    122 |
    See Also:
    123 |
    Serialized Form
    124 |
    125 |
  • 126 |
127 |
128 |
129 |
    130 |
  • 131 | 132 |
      133 |
    • 134 | 135 | 136 |

      Constructor Summary

      137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |
      Constructors 
      Constructor and Description
      SDL_Error() 
      146 |
    • 147 |
    148 | 149 |
      150 |
    • 151 | 152 | 153 |

      Method Summary

      154 |
        155 |
      • 156 | 157 | 158 |

        Methods inherited from class java.lang.Throwable

        159 | addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • 160 |
      161 |
        162 |
      • 163 | 164 | 165 |

        Methods inherited from class java.lang.Object

        166 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • 167 |
      168 |
    • 169 |
    170 |
  • 171 |
172 |
173 |
174 |
    175 |
  • 176 | 177 |
      178 |
    • 179 | 180 | 181 |

      Constructor Detail

      182 | 183 | 184 | 185 |
        186 |
      • 187 |

        SDL_Error

        188 |
        public SDL_Error()
        189 |
      • 190 |
      191 |
    • 192 |
    193 |
  • 194 |
195 |
196 |
197 | 198 | 199 |
200 | 201 | 202 | 203 | 204 | 205 | 206 | 215 |
216 | 258 | 259 | 260 | 261 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/RumbleController.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | RumbleController (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 48 |
49 | 91 | 92 | 93 |
94 |
uk.co.electronstudio.sdl2gdx
95 |

Interface RumbleController

96 |
97 |
98 |
99 |
    100 |
  • 101 |
    102 |
    All Superinterfaces:
    103 |
    com.badlogic.gdx.controllers.Controller
    104 |
    105 |
    106 |
    All Known Implementing Classes:
    107 |
    SDL2Controller
    108 |
    109 |
    110 |
    111 |
    public interface RumbleController
    112 | extends com.badlogic.gdx.controllers.Controller
    113 |
  • 114 |
115 |
116 |
117 |
    118 |
  • 119 | 120 |
      121 |
    • 122 | 123 | 124 |

      Method Summary

      125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 136 | 137 |
      All Methods Instance Methods Abstract Methods 
      Modifier and TypeMethod and Description
      booleanrumble(float leftMagnitude, 134 | float rightMagnitude, 135 | int duration_ms) 
      138 |
        139 |
      • 140 | 141 | 142 |

        Methods inherited from interface com.badlogic.gdx.controllers.Controller

        143 | addListener, getAccelerometer, getAxis, getButton, getName, getPov, getSliderX, getSliderY, removeListener, setAccelerometerSensitivity
      • 144 |
      145 |
    • 146 |
    147 |
  • 148 |
149 |
150 |
151 |
    152 |
  • 153 | 154 |
      155 |
    • 156 | 157 | 158 |

      Method Detail

      159 | 160 | 161 | 162 |
        163 |
      • 164 |

        rumble

        165 |
        boolean rumble(float leftMagnitude,
        166 |                float rightMagnitude,
        167 |                int duration_ms)
        168 |
      • 169 |
      170 |
    • 171 |
    172 |
  • 173 |
174 |
175 |
176 | 177 | 178 |
179 | 180 | 181 | 182 | 183 | 184 | 185 | 194 |
195 | 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /docs/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | API Help (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

How This API Document Is Organized

73 |
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
74 |
75 |
76 |
    77 |
  • 78 |

    Overview

    79 |

    The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

    80 |
  • 81 |
  • 82 |

    Package

    83 |

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    84 |
      85 |
    • Interfaces (italic)
    • 86 |
    • Classes
    • 87 |
    • Enums
    • 88 |
    • Exceptions
    • 89 |
    • Errors
    • 90 |
    • Annotation Types
    • 91 |
    92 |
  • 93 |
  • 94 |

    Class/Interface

    95 |

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    96 |
      97 |
    • Class inheritance diagram
    • 98 |
    • Direct Subclasses
    • 99 |
    • All Known Subinterfaces
    • 100 |
    • All Known Implementing Classes
    • 101 |
    • Class/interface declaration
    • 102 |
    • Class/interface description
    • 103 |
    104 |
      105 |
    • Nested Class Summary
    • 106 |
    • Field Summary
    • 107 |
    • Constructor Summary
    • 108 |
    • Method Summary
    • 109 |
    110 |
      111 |
    • Field Detail
    • 112 |
    • Constructor Detail
    • 113 |
    • Method Detail
    • 114 |
    115 |

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    116 |
  • 117 |
  • 118 |

    Annotation Type

    119 |

    Each annotation type has its own separate page with the following sections:

    120 |
      121 |
    • Annotation Type declaration
    • 122 |
    • Annotation Type description
    • 123 |
    • Required Element Summary
    • 124 |
    • Optional Element Summary
    • 125 |
    • Element Detail
    • 126 |
    127 |
  • 128 |
  • 129 |

    Enum

    130 |

    Each enum has its own separate page with the following sections:

    131 |
      132 |
    • Enum declaration
    • 133 |
    • Enum description
    • 134 |
    • Enum Constant Summary
    • 135 |
    • Enum Constant Detail
    • 136 |
    137 |
  • 138 |
  • 139 |

    Tree (Class Hierarchy)

    140 |

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    141 |
      142 |
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • 143 |
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • 144 |
    145 |
  • 146 |
  • 147 |

    Deprecated API

    148 |

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    149 |
  • 150 |
  • 151 |

    Index

    152 |

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    153 |
  • 154 |
  • 155 |

    Prev/Next

    156 |

    These links take you to the next or previous class, interface, package, or related page.

    157 |
  • 158 |
  • 159 |

    Frames/No Frames

    160 |

    These links show and hide the HTML frames. All pages are available with or without frames.

    161 |
  • 162 |
  • 163 |

    All Classes

    164 |

    The All Classes link shows all classes and interfaces except non-static nested types.

    165 |
  • 166 |
  • 167 |

    Serialized Form

    168 |

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    169 |
  • 170 |
  • 171 |

    Constant Field Values

    172 |

    The Constant Field Values page lists the static final fields and their values.

    173 |
  • 174 |
175 | This help file applies to API documentation generated using the standard doclet.
176 | 177 |
178 | 179 | 180 | 181 | 182 | 183 | 184 | 193 |
194 | 221 | 222 | 223 | 224 | -------------------------------------------------------------------------------- /docs/org/libsdl/SDL_GameControllerID.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SDL_GameControllerID (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 48 |
49 | 91 | 92 | 93 |
94 |
org.libsdl
95 |

Class SDL_GameControllerID

96 |
97 |
98 |
    99 |
  • java.lang.Object
  • 100 |
  • 101 |
      102 |
    • org.libsdl.SDL_GameControllerID
    • 103 |
    104 |
  • 105 |
106 |
107 |
    108 |
  • 109 |
    110 |
    111 |
    public class SDL_GameControllerID
    112 | extends java.lang.Object
    113 |
  • 114 |
115 |
116 |
117 |
    118 |
  • 119 | 120 |
      121 |
    • 122 | 123 | 124 |

      Method Summary

      125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      booleanequals(java.lang.Object o) 
      inthashCode() 
      140 |
        141 |
      • 142 | 143 | 144 |

        Methods inherited from class java.lang.Object

        145 | clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • 146 |
      147 |
    • 148 |
    149 |
  • 150 |
151 |
152 |
153 |
    154 |
  • 155 | 156 |
      157 |
    • 158 | 159 | 160 |

      Method Detail

      161 | 162 | 163 | 164 |
        165 |
      • 166 |

        equals

        167 |
        public boolean equals(java.lang.Object o)
        168 |
        169 |
        Overrides:
        170 |
        equals in class java.lang.Object
        171 |
        172 |
      • 173 |
      174 | 175 | 176 | 177 |
        178 |
      • 179 |

        hashCode

        180 |
        public int hashCode()
        181 |
        182 |
        Overrides:
        183 |
        hashCode in class java.lang.Object
        184 |
        185 |
      • 186 |
      187 |
    • 188 |
    189 |
  • 190 |
191 |
192 |
193 | 194 | 195 |
196 | 197 | 198 | 199 | 200 | 201 | 202 | 211 |
212 | 254 | 255 | 256 | 257 | -------------------------------------------------------------------------------- /docs/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Class Hierarchy (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For All Packages

73 | Package Hierarchies: 74 | 79 |
80 |
81 |

Class Hierarchy

82 |
    83 |
  • java.lang.Object 84 |
      85 |
    • java.awt.Component (implements java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable) 86 |
        87 |
      • java.awt.Container 88 |
          89 |
        • javax.swing.JComponent (implements java.io.Serializable) 90 |
            91 |
          • javax.swing.JPanel (implements javax.accessibility.Accessible) 92 | 96 |
          • 97 |
          98 |
        • 99 |
        100 |
      • 101 |
      102 |
    • 103 |
    • org.libsdl.GameController
    • 104 |
    • org.libsdl.SDL
    • 105 |
    • org.libsdl.SDL_GameController
    • 106 |
    • org.libsdl.SDL_GameControllerID
    • 107 |
    • org.libsdl.SDL_Joystick
    • 108 |
    • org.libsdl.SDL_JoystickID
    • 109 |
    • org.libsdl.SDL.Event
    • 110 |
    • uk.co.electronstudio.sdl2gdx.SDL2Controller (implements uk.co.electronstudio.sdl2gdx.RumbleController)
    • 111 |
    • uk.co.electronstudio.sdl2gdx.SDL2ControllerManager (implements com.badlogic.gdx.controllers.ControllerManager)
    • 112 |
    • uk.co.electronstudio.sdl2gdx.SDL2Controllers
    • 113 |
    • uk.co.electronstudio.sdl2gdx.tests.SDLHotplugTest
    • 114 |
    • uk.co.electronstudio.sdl2gdx.tests.SDLTest
    • 115 |
    • java.lang.Throwable (implements java.io.Serializable) 116 |
        117 |
      • java.lang.Exception 118 | 121 |
      • 122 |
      123 |
    • 124 |
    125 |
  • 126 |
127 |

Interface Hierarchy

128 |
    129 |
  • com.badlogic.gdx.controllers.Controller 130 | 133 |
  • 134 |
135 |

Enum Hierarchy

136 | 149 |
150 | 151 |
152 | 153 | 154 | 155 | 156 | 157 | 158 | 167 |
168 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /docs/uk/co/electronstudio/sdl2gdx/tests/SDLHotplugTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SDLHotplugTest (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 48 |
49 | 91 | 92 | 93 |
94 |
uk.co.electronstudio.sdl2gdx.tests
95 |

Class SDLHotplugTest

96 |
97 |
98 |
    99 |
  • java.lang.Object
  • 100 |
  • 101 |
      102 |
    • uk.co.electronstudio.sdl2gdx.tests.SDLHotplugTest
    • 103 |
    104 |
  • 105 |
106 |
107 |
    108 |
  • 109 |
    110 |
    111 |
    public class SDLHotplugTest
    112 | extends java.lang.Object
    113 |
  • 114 |
115 |
116 |
117 |
    118 |
  • 119 | 120 |
      121 |
    • 122 | 123 | 124 |

      Constructor Summary

      125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
      Constructors 
      Constructor and Description
      SDLHotplugTest() 
      134 |
    • 135 |
    136 | 137 |
      138 |
    • 139 | 140 | 141 |

      Method Summary

      142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 |
      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethod and Description
      static voidmain(java.lang.String[] args) 
      153 |
        154 |
      • 155 | 156 | 157 |

        Methods inherited from class java.lang.Object

        158 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • 159 |
      160 |
    • 161 |
    162 |
  • 163 |
164 |
165 |
166 |
    167 |
  • 168 | 169 |
      170 |
    • 171 | 172 | 173 |

      Constructor Detail

      174 | 175 | 176 | 177 |
        178 |
      • 179 |

        SDLHotplugTest

        180 |
        public SDLHotplugTest()
        181 |
      • 182 |
      183 |
    • 184 |
    185 | 186 |
      187 |
    • 188 | 189 | 190 |

      Method Detail

      191 | 192 | 193 | 194 |
        195 |
      • 196 |

        main

        197 |
        public static void main(java.lang.String[] args)
        198 |
      • 199 |
      200 |
    • 201 |
    202 |
  • 203 |
204 |
205 |
206 | 207 | 208 |
209 | 210 | 211 | 212 | 213 | 214 | 215 | 224 |
225 | 267 | 268 | 269 | 270 | -------------------------------------------------------------------------------- /docs/org/libsdl/SDL.Event.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SDL.Event (sdl2gdx API) 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 85 | 86 | 87 |
88 |
org.libsdl
89 |

Class SDL.Event

90 |
91 |
92 |
    93 |
  • java.lang.Object
  • 94 |
  • 95 |
      96 |
    • org.libsdl.SDL.Event
    • 97 |
    98 |
  • 99 |
100 |
101 |
    102 |
  • 103 |
    104 |
    Enclosing class:
    105 |
    SDL
    106 |
    107 |
    108 |
    109 |
    public static class SDL.Event
    110 | extends java.lang.Object
    111 |
  • 112 |
113 |
114 |
115 |
    116 |
  • 117 | 118 |
      119 |
    • 120 | 121 | 122 |

      Field Summary

      123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |
      Fields 
      Modifier and TypeField and Description
      static intSDL_JOYDEVICEADDED 
      static intSDL_JOYDEVICEREMOVED 
      inttimestamp 
      inttype 
      146 |
    • 147 |
    148 | 149 |
      150 |
    • 151 | 152 | 153 |

      Constructor Summary

      154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 |
      Constructors 
      Constructor and Description
      Event() 
      163 |
    • 164 |
    165 | 166 |
      167 |
    • 168 | 169 | 170 |

      Method Summary

      171 |
        172 |
      • 173 | 174 | 175 |

        Methods inherited from class java.lang.Object

        176 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • 177 |
      178 |
    • 179 |
    180 |
  • 181 |
182 |
183 |
184 |
    185 |
  • 186 | 187 |
      188 |
    • 189 | 190 | 191 |

      Field Detail

      192 | 193 | 194 | 195 |
        196 |
      • 197 |

        SDL_JOYDEVICEADDED

        198 |
        public static int SDL_JOYDEVICEADDED
        199 |
      • 200 |
      201 | 202 | 203 | 204 |
        205 |
      • 206 |

        SDL_JOYDEVICEREMOVED

        207 |
        public static int SDL_JOYDEVICEREMOVED
        208 |
      • 209 |
      210 | 211 | 212 | 213 |
        214 |
      • 215 |

        type

        216 |
        public int type
        217 |
      • 218 |
      219 | 220 | 221 | 222 |
        223 |
      • 224 |

        timestamp

        225 |
        public int timestamp
        226 |
      • 227 |
      228 |
    • 229 |
    230 | 231 |
      232 |
    • 233 | 234 | 235 |

      Constructor Detail

      236 | 237 | 238 | 239 |
        240 |
      • 241 |

        Event

        242 |
        public Event()
        243 |
      • 244 |
      245 |
    • 246 |
    247 |
  • 248 |
249 |
250 |
251 | 252 | 253 |
254 | 255 | 256 | 257 | 258 | 259 | 260 | 269 |
270 | 312 | 313 | 314 | 315 | -------------------------------------------------------------------------------- /src/uk/co/electronstudio/sdl2gdx/tests/SDLTest.java: -------------------------------------------------------------------------------- 1 | package uk.co.electronstudio.sdl2gdx.tests; 2 | 3 | import com.badlogic.gdx.controllers.Controller; 4 | import org.libsdl.SDL; 5 | import org.libsdl.SDL_Error; 6 | import uk.co.electronstudio.sdl2gdx.SDL2Controller; 7 | import uk.co.electronstudio.sdl2gdx.SDL2ControllerManager; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.ActionListener; 13 | import java.lang.reflect.InvocationTargetException; 14 | import java.lang.reflect.Method; 15 | import java.util.Arrays; 16 | 17 | /** 18 | * A quick and dirty interface to check if a controller is working. I hope you like swing! 19 | */ 20 | public class SDLTest { 21 | public static int NUM_CONTROLLERS = 5; 22 | public static SDL2ControllerManager controllerManager; 23 | public volatile static boolean requestRestart = false; 24 | 25 | static JComboBox inputPref = new JComboBox(new SDL2ControllerManager.InputPreference[]{SDL2ControllerManager.InputPreference.XINPUT, SDL2ControllerManager.InputPreference.DIRECT_INPUT, SDL2ControllerManager.InputPreference.RAW_INPUT}); 26 | 27 | 28 | 29 | public static void main(String[] args) { 30 | init(); 31 | 32 | //rumbleExample(controllerManager); 33 | //reflectionExample(controllerManager); 34 | //testEventPoll(); 35 | 36 | 37 | JTabbedPane tabbedPane = new JTabbedPane(); 38 | JFrame testFrame = new JFrame(); 39 | SDLInfoPanel[] controllerTabs = setup(tabbedPane, testFrame); 40 | 41 | while (true) { 42 | mainLoop(testFrame, controllerTabs); 43 | } 44 | } 45 | 46 | private static void testEventPoll(){ 47 | SDL.Event event = new SDL.Event(); 48 | event.type = 100; 49 | 50 | while(true) { 51 | if(SDL.SDL_PollEvent(event)) { 52 | 53 | System.out.println("EVENT TYPE: " + event.type + " time "+event.timestamp); 54 | if(event.type==SDL.Event.SDL_JOYDEVICEADDED){ 55 | System.out.println("joydeviceadded"); 56 | } 57 | if(event.type==SDL.Event.SDL_JOYDEVICEREMOVED){ 58 | System.out.println("joydeviceremoved"); 59 | } 60 | 61 | } 62 | } 63 | } 64 | 65 | private static void init() { 66 | 67 | //System.setProperty("SDL.input","DIRECT_INPUT"); 68 | //controllerManager = new SDL2ControllerManager(); 69 | controllerManager = new SDL2ControllerManager((SDL2ControllerManager.InputPreference) inputPref.getSelectedItem()); 70 | 71 | 72 | } 73 | 74 | private static void mainLoop(JFrame testFrame, SDLInfoPanel[] controllerTabs) { 75 | if (requestRestart) { 76 | controllerManager.close(); 77 | init(); 78 | requestRestart = false; 79 | } 80 | try { 81 | Thread.sleep(30); 82 | } catch (InterruptedException e) { 83 | e.printStackTrace(); 84 | } 85 | 86 | try { 87 | controllerManager.pollState(); 88 | } catch (SDL_Error sdl_error) { 89 | sdl_error.printStackTrace(); 90 | } 91 | for (int i = 0; i < controllerManager.getControllers().size; i++) { 92 | Controller controllerAtIndex = controllerManager.getControllers().get(i); 93 | controllerTabs[i].updatePanel((SDL2Controller) controllerAtIndex); 94 | } 95 | testFrame.repaint(); 96 | } 97 | 98 | private static SDLInfoPanel[] setup(JTabbedPane tabbedPane, JFrame testFrame) { 99 | testFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 100 | testFrame.setLocationRelativeTo(null); 101 | testFrame.setMinimumSize(new Dimension(1000, 350)); 102 | testFrame.setResizable(true); 103 | testFrame.setVisible(true); 104 | 105 | SDLInfoPanel[] controllerTabs = new SDLInfoPanel[NUM_CONTROLLERS]; 106 | for (int i = 0; i < NUM_CONTROLLERS; i++) { 107 | controllerTabs[i] = new SDLInfoPanel(); 108 | tabbedPane.add(" Controller " + (i + 1) + " ", controllerTabs[i]); 109 | } 110 | tabbedPane.add("Options", new OptionPanel()); 111 | testFrame.setContentPane(tabbedPane); 112 | return controllerTabs; 113 | } 114 | 115 | private static void rumbleExample(SDL2ControllerManager controllerManager) { 116 | SDL2Controller controller = (SDL2Controller) controllerManager.getControllers().get(0); 117 | controller.rumble(1.0f, 1.0f, 500); 118 | } 119 | 120 | private static void reflectionExample(SDL2ControllerManager controllerManager) { 121 | Method method = null; 122 | Controller controller = controllerManager.getControllers().get(0); 123 | for (Method m : controller.getClass().getMethods()) { 124 | if (m.getName().equals("rumble")) method = m; 125 | } 126 | try { 127 | method.invoke(controller, 1f, 1f, 500); 128 | } catch (IllegalAccessException | InvocationTargetException e) { 129 | e.printStackTrace(); 130 | } 131 | } 132 | 133 | /** 134 | * A JPanel that displays information about a given ControllerIndex. 135 | */ 136 | public static class SDLInfoPanel extends JPanel { 137 | private JPanel title; 138 | private JPanel axes; 139 | private JPanel buttons; 140 | private JPanel pov; 141 | private JSlider leftRumble, rightRumble; 142 | private JButton vibrateButton; 143 | private JLabel titleLabel; 144 | 145 | public SDLInfoPanel() { 146 | setLayout(new BorderLayout()); 147 | 148 | title = new JPanel(); 149 | axes = new JPanel(); 150 | buttons = new JPanel(); 151 | pov = new JPanel(); 152 | 153 | JPanel vibratePanel = new JPanel(); 154 | vibrateButton = new JButton("Rumble"); 155 | leftRumble = new JSlider(0, 100, 100); 156 | rightRumble = new JSlider(0, 100, 100); 157 | 158 | vibratePanel.add(leftRumble); 159 | vibratePanel.add(rightRumble); 160 | vibratePanel.add(vibrateButton); 161 | 162 | 163 | title.setLayout(new BoxLayout(title, BoxLayout.Y_AXIS)); 164 | title.setAlignmentX(Component.CENTER_ALIGNMENT); 165 | titleLabel = new JLabel(); 166 | title.add(titleLabel); 167 | 168 | JPanel middlePanel = new JPanel(); 169 | middlePanel.setLayout(new BoxLayout(middlePanel, BoxLayout.Y_AXIS)); 170 | middlePanel.add(title); 171 | middlePanel.add(axes); 172 | middlePanel.add(pov); 173 | middlePanel.add(buttons); 174 | 175 | add(middlePanel); 176 | add(vibratePanel, BorderLayout.SOUTH); 177 | } 178 | 179 | public void updatePanel(SDL2Controller c) { 180 | try { 181 | titleLabel.setText(c.getName()); 182 | 183 | axes.removeAll(); 184 | for (int i = 0; i < c.joystick.numAxes(); i++) { 185 | JLabel label = new JLabel(); 186 | label.setPreferredSize(new Dimension(100, 30)); 187 | label.setText(SDL.SDL_GameControllerGetStringForAxis(i)); 188 | 189 | JProgressBar progressBar = new JProgressBar(-100, 100); 190 | progressBar.setPreferredSize(new Dimension(200, 30)); 191 | progressBar.setValue((int) (c.getAxis(i) * 100)); 192 | 193 | JPanel axisPanel = new JPanel(); 194 | axisPanel.setLayout(new BoxLayout(axisPanel, BoxLayout.X_AXIS)); 195 | axisPanel.add(label); 196 | axisPanel.add(progressBar); 197 | axes.add(axisPanel); 198 | } 199 | 200 | buttons.removeAll(); 201 | for (int i = 0; i < c.joystick.numButtons(); i++) { 202 | JButton button = new JButton(SDL.SDL_GameControllerGetStringForButton(i)); 203 | button.setEnabled(c.getButton(i)); 204 | buttons.add(button); 205 | } 206 | 207 | Arrays.stream(vibrateButton.getActionListeners()).forEach(vibrateButton::removeActionListener); 208 | vibrateButton.addActionListener(event -> { 209 | c.rumble(leftRumble.getValue() / 100f, rightRumble.getValue() / 100f, 1000); 210 | 211 | }); 212 | 213 | pov.removeAll(); 214 | pov.add(new JLabel("HAT: "+c.getPov(0).toString())); 215 | pov.add(new JLabel("POWER: "+c.getPowerLevel().toString())); 216 | pov.add(new JLabel("TYPE: "+c.getType().toString())); 217 | pov.add(new JLabel("INDEX: "+c.getPlayerIndex())); 218 | 219 | } catch (SDL_Error e) { 220 | e.printStackTrace(); 221 | 222 | titleLabel.setText("SDL error occurred!"); 223 | axes.removeAll(); 224 | buttons.removeAll(); 225 | 226 | axes.add(new JLabel(e.getMessage())); 227 | } 228 | } 229 | 230 | public void setAsDisconnected() { 231 | titleLabel.setText("No controller connected at this index!"); 232 | axes.removeAll(); 233 | buttons.removeAll(); 234 | } 235 | } 236 | 237 | public static class OptionPanel extends JPanel { 238 | private JPanel title; 239 | 240 | private JButton restartButton; 241 | private JLabel titleLabel; 242 | 243 | public OptionPanel() { 244 | setLayout(new BorderLayout()); 245 | 246 | title = new JPanel(); 247 | 248 | 249 | JPanel panel = new JPanel(); 250 | restartButton = new JButton("Restart SDL"); 251 | restartButton.addActionListener(new ActionListener() { 252 | @Override 253 | public void actionPerformed(ActionEvent e) { 254 | requestRestart = true; 255 | } 256 | }); 257 | 258 | 259 | panel.add(restartButton); 260 | panel.add(inputPref); 261 | // panel.add(xinput); 262 | // panel.add(rawinput); 263 | 264 | 265 | title.setLayout(new BoxLayout(title, BoxLayout.Y_AXIS)); 266 | title.setAlignmentX(Component.CENTER_ALIGNMENT); 267 | titleLabel = new JLabel(); 268 | title.add(titleLabel); 269 | 270 | JPanel middlePanel = new JPanel(); 271 | middlePanel.setLayout(new BoxLayout(middlePanel, BoxLayout.Y_AXIS)); 272 | middlePanel.add(title); 273 | 274 | 275 | add(middlePanel); 276 | add(panel, BorderLayout.SOUTH); 277 | } 278 | 279 | 280 | } 281 | 282 | } 283 | --------------------------------------------------------------------------------