Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
d8e077ad
Commit
d8e077ad
authored
Jul 06, 2010
by
Paul Hunkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added preliminary keyboard event support
parent
26a7c004
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
112 additions
and
19 deletions
+112
-19
app-android.cpp
android/testproject/jni/app-android.cpp
+16
-0
lesson05.c
android/testproject/jni/lesson05.c
+15
-2
SDLActivity.java
android/testproject/src/org/libsdl/android/SDLActivity.java
+38
-13
SDL_keyboard.c
src/events/SDL_keyboard.c
+12
-4
SDL_androidevents.c
src/video/android/SDL_androidevents.c
+28
-0
SDL_androidevents.h
src/video/android/SDL_androidevents.h
+1
-0
SDL_androidvideo.c
src/video/android/SDL_androidvideo.c
+2
-0
No files found.
android/testproject/jni/app-android.cpp
View file @
d8e077ad
...
@@ -36,6 +36,8 @@ jmethodID midCreateGLContext;
...
@@ -36,6 +36,8 @@ jmethodID midCreateGLContext;
jmethodID
midFlipBuffers
;
jmethodID
midFlipBuffers
;
extern
"C"
int
SDL_main
();
extern
"C"
int
SDL_main
();
extern
"C"
int
Android_OnKeyDown
(
int
keycode
);
extern
"C"
int
Android_OnKeyUp
(
int
keycode
);
/*******************************************************************************
/*******************************************************************************
Functions called by JNI
Functions called by JNI
...
@@ -77,6 +79,20 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
...
@@ -77,6 +79,20 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
return
JNI_VERSION_1_4
;
return
JNI_VERSION_1_4
;
}
}
extern
"C"
void
Java_org_libsdl_android_SDLActivity_onNativeKeyDown
(
JNIEnv
*
env
,
jobject
obj
,
jint
keycode
){
int
r
=
Android_OnKeyDown
(
keycode
);
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: native key down %d, %d
\n
"
,
keycode
,
r
);
}
extern
"C"
void
Java_org_libsdl_android_SDLActivity_onNativeKeyUp
(
JNIEnv
*
env
,
jobject
obj
,
jint
keycode
){
int
r
=
Android_OnKeyUp
(
keycode
);
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"SDL: native key up %d, %d
\n
"
,
keycode
,
r
);
}
/*******************************************************************************
/*******************************************************************************
...
...
android/testproject/jni/lesson05.c
View file @
d8e077ad
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
/* This is our SDL surface */
/* This is our SDL surface */
SDL_Surface
*
surface
;
SDL_Surface
*
surface
;
int
rotation
=
0
;
/**************************************
/**************************************
gluperspective implementation
gluperspective implementation
...
@@ -196,10 +198,20 @@ void handleKeyPress( SDL_keysym *keysym )
...
@@ -196,10 +198,20 @@ void handleKeyPress( SDL_keysym *keysym )
*/
*/
SDL_WM_ToggleFullScreen
(
surface
);
SDL_WM_ToggleFullScreen
(
surface
);
break
;
break
;
case
SDLK_LEFT
:
rotation
-=
30
;
break
;
case
SDLK_RIGHT
:
rotation
+=
30
;
break
;
default
:
default
:
break
;
break
;
}
}
__android_log_print
(
ANDROID_LOG_INFO
,
"SDL"
,
"Keycode: %d, %d, %d
\n
"
,
keysym
->
sym
,
SDLK_LEFT
,
SDLK_RIGHT
);
return
;
return
;
}
}
...
@@ -231,6 +243,7 @@ int initGL( GLvoid )
...
@@ -231,6 +243,7 @@ int initGL( GLvoid )
/* Here goes our drawing code */
/* Here goes our drawing code */
int
drawGLScene
(
GLvoid
)
int
drawGLScene
(
GLvoid
)
{
{
static
int
Frames
=
0
;
static
int
Frames
=
0
;
static
int
T0
=
0
;
static
int
T0
=
0
;
...
@@ -253,14 +266,14 @@ int drawGLScene( GLvoid )
...
@@ -253,14 +266,14 @@ int drawGLScene( GLvoid )
//Draw a triangle
//Draw a triangle
//glRotatef(iRot, 0, 1, 0);
//glRotatef(iRot, 0, 1, 0);
glRotatef
(
Frames
%
360
,
0
.
0
f
,
1
.
0
f
,
0
.
0
f
);
glRotatef
(
rotation
,
0
.
0
f
,
1
.
0
f
,
0
.
0
f
);
glEnableClientState
(
GL_VERTEX_ARRAY
);
glEnableClientState
(
GL_VERTEX_ARRAY
);
glEnableClientState
(
GL_COLOR_ARRAY
);
glEnableClientState
(
GL_COLOR_ARRAY
);
/* Rotate The Triangle On The Y axis ( NEW ) */
/* Rotate The Triangle On The Y axis ( NEW ) */
glRotatef
(
Frames
%
360
,
0
.
0
f
,
1
.
0
f
,
0
.
0
f
);
//
glRotatef( Frames % 360, 0.0f, 1.0f, 0.0f );
/* GLES variant of drawing a triangle */
/* GLES variant of drawing a triangle */
const
GLfloat
triVertices
[][
9
]
=
{
const
GLfloat
triVertices
[][
9
]
=
{
...
...
android/testproject/src/org/libsdl/android/SDLActivity.java
View file @
d8e077ad
...
@@ -4,14 +4,14 @@ import javax.microedition.khronos.egl.EGLConfig;
...
@@ -4,14 +4,14 @@ import javax.microedition.khronos.egl.EGLConfig;
import
javax.microedition.khronos.opengles.GL10
;
import
javax.microedition.khronos.opengles.GL10
;
import
javax.microedition.khronos.egl.*
;
import
javax.microedition.khronos.egl.*
;
import
android.app.Activity
;
import
android.app.*
;
import
android.content.Context
;
import
android.content.*
;
import
android.view.SurfaceHolder
;
import
android.view.*
;
import
android.view.SurfaceView
;
import
android.os.*
;
import
android.os.Bundle
;
import
android.view.MotionEvent
;
import
android.util.Log
;
import
android.util.Log
;
import
android.graphics.*
;
import
android.graphics.*
;
import
android.text.method.*
;
import
android.text.*
;
import
java.lang.*
;
import
java.lang.*
;
...
@@ -55,13 +55,14 @@ public class SDLActivity extends Activity {
...
@@ -55,13 +55,14 @@ public class SDLActivity extends Activity {
super
.
onResume
();
super
.
onResume
();
}
}
//C functions we call
//C functions we call
public
static
native
void
nativeInit
();
public
static
native
void
nativeInit
();
public
static
native
void
onNativeKeyDown
(
int
keycode
);
public
static
native
void
onNativeKeyUp
(
int
keycode
);
...
@@ -82,8 +83,7 @@ public class SDLActivity extends Activity {
...
@@ -82,8 +83,7 @@ public class SDLActivity extends Activity {
//EGL context creation
}
}
...
@@ -104,7 +104,7 @@ class SDLRunner implements Runnable{
...
@@ -104,7 +104,7 @@ class SDLRunner implements Runnable{
Because of this, that's where we set up the SDL thread
Because of this, that's where we set up the SDL thread
*/
*/
class
SDLSurface
extends
SurfaceView
implements
SurfaceHolder
.
Callback
{
class
SDLSurface
extends
SurfaceView
implements
SurfaceHolder
.
Callback
,
View
.
OnKeyListener
{
//This is what SDL runs in. It invokes SDL_main(), eventually
//This is what SDL runs in. It invokes SDL_main(), eventually
private
Thread
mSDLThread
;
private
Thread
mSDLThread
;
...
@@ -117,7 +117,12 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
...
@@ -117,7 +117,12 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
//Startup
//Startup
public
SDLSurface
(
Context
context
)
{
public
SDLSurface
(
Context
context
)
{
super
(
context
);
super
(
context
);
getHolder
().
addCallback
(
this
);
getHolder
().
addCallback
(
this
);
setFocusable
(
true
);
setFocusableInTouchMode
(
true
);
requestFocus
();
setOnKeyListener
(
this
);
}
}
//Called when we have a valid drawing surface
//Called when we have a valid drawing surface
...
@@ -175,13 +180,13 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
...
@@ -175,13 +180,13 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
mEGLDisplay
=
dpy
;
mEGLDisplay
=
dpy
;
mEGLSurface
=
surface
;
mEGLSurface
=
surface
;
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
Log
.
v
(
"SDL"
,
e
+
""
);
Log
.
v
(
"SDL"
,
e
+
""
);
for
(
StackTraceElement
s
:
e
.
getStackTrace
()){
for
(
StackTraceElement
s
:
e
.
getStackTrace
()){
Log
.
v
(
"SDL"
,
s
.
toString
());
Log
.
v
(
"SDL"
,
s
.
toString
());
}
}
}
}
Log
.
v
(
"SDL"
,
"Done making!"
);
Log
.
v
(
"SDL"
,
"Done making!"
);
return
true
;
return
true
;
...
@@ -211,6 +216,26 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
...
@@ -211,6 +216,26 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
}
}
}
}
}
}
public
boolean
onKey
(
View
v
,
int
keyCode
,
KeyEvent
event
){
if
(
event
.
getAction
()
==
KeyEvent
.
ACTION_DOWN
){
SDLActivity
.
onNativeKeyDown
(
keyCode
);
return
true
;
}
else
if
(
event
.
getAction
()
==
KeyEvent
.
ACTION_UP
){
SDLActivity
.
onNativeKeyUp
(
keyCode
);
return
true
;
}
return
false
;
}
}
}
src/events/SDL_keyboard.c
View file @
d8e077ad
...
@@ -694,8 +694,16 @@ SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
...
@@ -694,8 +694,16 @@ SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
Uint16
modstate
;
Uint16
modstate
;
Uint32
type
;
Uint32
type
;
if
(
!
keyboard
){
return
7
;
}
if
(
!
scancode
){
return
8
;
}
if
(
!
keyboard
||
!
scancode
)
{
if
(
!
keyboard
||
!
scancode
)
{
return
0
;
return
1
;
}
}
#if 0
#if 0
printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
...
@@ -788,7 +796,7 @@ SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
...
@@ -788,7 +796,7 @@ SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
break
;
break
;
default:
default:
/* Invalid state -- bail */
/* Invalid state -- bail */
return
0
;
return
2
;
}
}
/* Drop events that don't change state */
/* Drop events that don't change state */
...
@@ -796,14 +804,14 @@ SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
...
@@ -796,14 +804,14 @@ SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
#if 0
#if 0
printf("Keyboard event didn't change state - dropped!\n");
printf("Keyboard event didn't change state - dropped!\n");
#endif
#endif
return
0
;
return
3
;
}
}
/* Update internal keyboard state */
/* Update internal keyboard state */
keyboard
->
keystate
[
scancode
]
=
state
;
keyboard
->
keystate
[
scancode
]
=
state
;
/* Post the event, if desired */
/* Post the event, if desired */
posted
=
0
;
posted
=
4
;
if
(
SDL_GetEventState
(
type
)
==
SDL_ENABLE
)
{
if
(
SDL_GetEventState
(
type
)
==
SDL_ENABLE
)
{
SDL_Event
event
;
SDL_Event
event
;
event
.
key
.
type
=
type
;
event
.
key
.
type
=
type
;
...
...
src/video/android/SDL_androidevents.c
View file @
d8e077ad
...
@@ -30,6 +30,24 @@
...
@@ -30,6 +30,24 @@
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_events_c.h"
#include "SDL_androidevents.h"
void
Android_InitEvents
(){
SDL_Keyboard
keyboard
;
SDL_zero
(
keyboard
);
SDL_AddKeyboard
(
&
keyboard
,
-
1
);
SDLKey
keymap
[
SDL_NUM_SCANCODES
];
/* Add default scancode to key mapping */
SDL_GetDefaultKeymap
(
keymap
);
SDL_SetKeymap
(
0
,
0
,
keymap
,
SDL_NUM_SCANCODES
);
}
void
void
Android_PumpEvents
(
_THIS
)
Android_PumpEvents
(
_THIS
)
{
{
...
@@ -49,4 +67,14 @@ Android_PumpEvents(_THIS)
...
@@ -49,4 +67,14 @@ Android_PumpEvents(_THIS)
*/
*/
}
}
int
Android_OnKeyDown
(
int
keycode
){
return
SDL_SendKeyboardKey
(
0
,
SDL_PRESSED
,
(
SDL_scancode
)
keycode
);
}
int
Android_OnKeyUp
(
int
keycode
){
return
SDL_SendKeyboardKey
(
0
,
SDL_RELEASED
,
(
SDL_scancode
)
keycode
);
}
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/video/android/SDL_androidevents.h
View file @
d8e077ad
...
@@ -24,5 +24,6 @@
...
@@ -24,5 +24,6 @@
#include "SDL_androidvideo.h"
#include "SDL_androidvideo.h"
extern
void
Android_PumpEvents
(
_THIS
);
extern
void
Android_PumpEvents
(
_THIS
);
extern
void
Android_InitEvents
();
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/video/android/SDL_androidvideo.c
View file @
d8e077ad
...
@@ -132,6 +132,8 @@ Android_VideoInit(_THIS)
...
@@ -132,6 +132,8 @@ Android_VideoInit(_THIS)
SDL_zero
(
mode
);
SDL_zero
(
mode
);
SDL_AddDisplayMode
(
&
_this
->
displays
[
0
],
&
mode
);
SDL_AddDisplayMode
(
&
_this
->
displays
[
0
],
&
mode
);
Android_InitEvents
();
/* We're done! */
/* We're done! */
return
0
;
return
0
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment