Added SDL 1.2 multitouch example
This commit is contained in:
44
project/jni/application/multitouch/AndroidAppSettings.cfg
Normal file
44
project/jni/application/multitouch/AndroidAppSettings.cfg
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# The application settings for Android libSDL port
|
||||||
|
AppSettingVersion=17
|
||||||
|
LibSdlVersion=1.2
|
||||||
|
AppName="Example multitouch"
|
||||||
|
AppFullName=org.libsdl.example.multitouch
|
||||||
|
ScreenOrientation=h
|
||||||
|
InhibitSuspend=n
|
||||||
|
AppDataDownloadUrl="Game data is 1 Mb|ballfield2.zip"
|
||||||
|
VideoDepthBpp=16
|
||||||
|
NeedDepthBuffer=n
|
||||||
|
NeedStencilBuffer=n
|
||||||
|
NeedGles2=n
|
||||||
|
SwVideoMode=y
|
||||||
|
SdlVideoResize=y
|
||||||
|
SdlVideoResizeKeepAspect=n
|
||||||
|
CompatibilityHacks=n
|
||||||
|
AppUsesMouse=y
|
||||||
|
AppNeedsTwoButtonMouse=y
|
||||||
|
ShowMouseCursor=n
|
||||||
|
ForceRelativeMouseMode=n
|
||||||
|
AppNeedsArrowKeys=n
|
||||||
|
AppNeedsTextInput=y
|
||||||
|
AppUsesJoystick=y
|
||||||
|
AppHandlesJoystickSensitivity=n
|
||||||
|
AppUsesMultitouch=y
|
||||||
|
NonBlockingSwapBuffers=n
|
||||||
|
RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE"
|
||||||
|
AppTouchscreenKeyboardKeysAmount=0
|
||||||
|
AppTouchscreenKeyboardKeysAmountAutoFire=0
|
||||||
|
RedefinedKeysScreenKb="1 2 3 4 5 6 1 2 3 4"
|
||||||
|
StartupMenuButtonTimeout=3000
|
||||||
|
HiddenMenuOptions='OptionalDownloadConfig'
|
||||||
|
FirstStartMenuOptions=''
|
||||||
|
MultiABI=n
|
||||||
|
AppVersionCode=101
|
||||||
|
AppVersionName="1.01"
|
||||||
|
ResetSdlConfigForThisVersion=n
|
||||||
|
CompiledLibraries="sdl_mixer sdl_image"
|
||||||
|
CustomBuildScript=n
|
||||||
|
AppCflags='-O2 -finline-functions'
|
||||||
|
AppLdflags=''
|
||||||
|
AppSubdirsBuild=''
|
||||||
|
AppCmdline=''
|
||||||
|
ReadmeText='^Readme text'
|
||||||
BIN
project/jni/application/multitouch/AndroidData/ballfield2.zip
Normal file
BIN
project/jni/application/multitouch/AndroidData/ballfield2.zip
Normal file
Binary file not shown.
72
project/jni/application/multitouch/example.cpp
Normal file
72
project/jni/application/multitouch/example.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
|
||||||
|
SDL_Surface * screen = SDL_SetVideoMode(640, 480, 16, 0);
|
||||||
|
|
||||||
|
enum { MAX_POINTERS = 16, PTR_PRESSED = 4 };
|
||||||
|
int touchPointers[MAX_POINTERS][5];
|
||||||
|
int accel[5];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(touchPointers, 0, sizeof(touchPointers));
|
||||||
|
memset(accel, 0, sizeof(accel));
|
||||||
|
SDL_Joystick * joysticks[MAX_POINTERS+1];
|
||||||
|
for(i=0; i<MAX_POINTERS; i++)
|
||||||
|
joysticks[i] = SDL_JoystickOpen(i);
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
SDL_Event evt;
|
||||||
|
while( SDL_PollEvent(&evt) )
|
||||||
|
{
|
||||||
|
if( evt.type == SDL_JOYAXISMOTION )
|
||||||
|
{
|
||||||
|
if( evt.jaxis.which == 0 ) // 0 = The accelerometer
|
||||||
|
{
|
||||||
|
accel[evt.jaxis.axis] = evt.jaxis.value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int joyid = evt.jaxis.which - 1;
|
||||||
|
touchPointers[joyid][evt.jaxis.axis] = evt.jaxis.value; // Axis 0 and 1 are coordinates, 2 and 3 are pressure and touch point radius
|
||||||
|
}
|
||||||
|
if( evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP )
|
||||||
|
{
|
||||||
|
if( evt.jbutton.which == 0 ) // 0 = The accelerometer
|
||||||
|
continue;
|
||||||
|
int joyid = evt.jbutton.which - 1;
|
||||||
|
touchPointers[joyid][PTR_PRESSED] = (evt.jbutton.state == SDL_PRESSED);
|
||||||
|
}
|
||||||
|
if(evt.type == SDL_KEYDOWN && evt.key.keysym.sym == SDLK_ESCAPE)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
SDL_FillRect(screen, 0, 0);
|
||||||
|
SDL_Rect r;
|
||||||
|
for(i=0; i<MAX_POINTERS; i++)
|
||||||
|
{
|
||||||
|
if( !touchPointers[i][PTR_PRESSED] )
|
||||||
|
continue;
|
||||||
|
r.x = touchPointers[i][0];
|
||||||
|
r.y = touchPointers[i][1];
|
||||||
|
r.w = 80 + touchPointers[i][2] / 10; // Pressure
|
||||||
|
r.h = 80 + touchPointers[i][3] / 10; // Touch point size
|
||||||
|
r.x -= r.w/2;
|
||||||
|
r.y -= r.h/2;
|
||||||
|
SDL_FillRect(screen, &r, 0xffffff);
|
||||||
|
}
|
||||||
|
r.x = 320 + accel[0] / 100;
|
||||||
|
r.y = 240 + accel[1] / 100;
|
||||||
|
r.w = 10 + abs(accel[2]);
|
||||||
|
r.h = 10;
|
||||||
|
r.x -= r.w/2;
|
||||||
|
r.y -= r.h/2;
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "Example", "Accelerometer %06d %06d %06d", accel[0], accel[1], accel[2]);
|
||||||
|
SDL_FillRect(screen, &r, 0xaaaaaa);
|
||||||
|
SDL_Flip(screen);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
project/jni/application/multitouch/icon.png
Normal file
BIN
project/jni/application/multitouch/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user