Initial touchscreen code - it does not compile yet

This commit is contained in:
pelya
2010-08-17 15:24:24 +03:00
parent f38d325a1b
commit 9d970a7326
4 changed files with 356 additions and 117 deletions

View File

@@ -52,9 +52,10 @@
#include "../../joystick/SDL_joystick_c.h"
#include "SDL_androidvideo.h"
#include "SDL_androidinput.h"
static SDLKey keymap[KEYCODE_LAST+1];
SDLKey SDL_android_keymap[KEYCODE_LAST+1];
/* JNI-C++ wrapper stuff */
@@ -65,130 +66,20 @@ static SDLKey keymap[KEYCODE_LAST+1];
#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package)
#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH)
#if SDL_VERSION_ATLEAST(1,3,0)
#define SDL_KEY2(X) SDL_SCANCODE_ ## X
#define SDL_KEY(X) SDL_KEY2(X)
static SDL_scancode TranslateKey(int scancode, SDL_keysym *keysym)
{
if ( scancode >= SDL_arraysize(keymap) )
scancode = KEYCODE_UNKNOWN;
return keymap[scancode];
}
static SDL_scancode GetKeysym(SDL_scancode scancode, SDL_keysym *keysym)
{
return scancode;
}
#define SDL_SendKeyboardKey(X, Y) SDL_SendKeyboardKey(X, Y, SDL_FALSE)
#else
#define SDL_KEY2(X) SDLK_ ## X
#define SDL_KEY(X) SDL_KEY2(X)
#define SDL_SendKeyboardKey SDL_PrivateKeyboard
// Randomly redefining SDL 1.3 scancodes to SDL 1.2 keycodes
#define KP_0 KP0
#define KP_1 KP1
#define KP_2 KP2
#define KP_3 KP3
#define KP_4 KP4
#define KP_5 KP5
#define KP_6 KP6
#define KP_7 KP7
#define KP_8 KP8
#define KP_9 KP9
#define NUMLOCKCLEAR NUMLOCK
#define GRAVE DOLLAR
#define APOSTROPHE QUOTE
#define LGUI LMETA
// Overkill haha
#define A a
#define B b
#define C c
#define D d
#define E e
#define F f
#define G g
#define H h
#define I i
#define J j
#define K k
#define L l
#define M m
#define N n
#define O o
#define P p
#define Q q
#define R r
#define S s
#define T t
#define U u
#define V v
#define W w
#define X x
#define Y y
#define Z z
#define SDL_scancode SDLKey
static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
{
/* Sanity check */
if ( scancode >= SDL_arraysize(keymap) )
scancode = KEYCODE_UNKNOWN;
/* Set the keysym information */
keysym->scancode = scancode;
keysym->sym = keymap[scancode];
keysym->mod = KMOD_NONE;
/* If UNICODE is on, get the UNICODE value for the key */
keysym->unicode = 0;
if ( SDL_TranslateUNICODE ) {
/* Populate the unicode field with the ASCII value */
keysym->unicode = scancode;
}
return(keysym);
}
static SDL_keysym *GetKeysym(SDLKey scancode, SDL_keysym *keysym)
{
/* Sanity check */
/* Set the keysym information */
keysym->scancode = scancode;
keysym->sym = scancode;
keysym->mod = KMOD_NONE;
/* If UNICODE is on, get the UNICODE value for the key */
keysym->unicode = 0;
if ( SDL_TranslateUNICODE ) {
/* Populate the unicode field with the ASCII value */
keysym->unicode = scancode;
}
return(keysym);
}
#endif
#define SDL_KEY_VAL(X) X
static int isTrackballUsed = 0;
static int isMouseUsed = 0;
static int isJoystickUsed = 0;
static int isMultitouchUsed = 0;
static int isTouchscreenKeyboardUsed = 0;
static SDL_Joystick *CurrentJoysticks[4] = {NULL, NULL, NULL, NULL};
enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 };
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId, jint force, jint radius )
{
if( isTouchscreenKeyboardUsed )
if( SDL_android_processTouchscreenKeyboard(x, y, action) )
return;
#if SDL_VIDEO_RENDER_RESIZE
// Translate mouse coordinates
@@ -311,6 +202,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetMultitouchUsed) ( JNIEnv* env, jobject thiz)
void ANDROID_InitOSKeymap()
{
int i;
SDLKey * keymap = SDL_android_keymap;
#if (SDL_VERSION_ATLEAST(1,3,0))
SDLKey defaultKeymap[SDL_NUM_SCANCODES];
@@ -320,8 +212,8 @@ void ANDROID_InitOSKeymap()
// TODO: keys are mapped rather randomly
for (i=0; i<SDL_arraysize(keymap); ++i)
keymap[i] = SDL_KEY(UNKNOWN);
for (i=0; i<SDL_arraysize(SDL_android_keymap); ++i)
SDL_android_keymap[i] = SDL_KEY(UNKNOWN);
keymap[KEYCODE_UNKNOWN] = SDL_KEY(UNKNOWN);

View File

@@ -0,0 +1,175 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifndef _SDL_ANDROIDINPUT_H_
#define _SDL_ANDROIDINPUT_H_
#include "SDL_config.h"
#include "SDL_version.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "SDL_events.h"
#if (SDL_VERSION_ATLEAST(1,3,0))
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
#include "SDL_scancode.h"
#include "SDL_compat.h"
#else
#include "SDL_keysym.h"
#include "../../events/SDL_events_c.h"
#endif
#include "SDL_joystick.h"
#include "../../joystick/SDL_sysjoystick.h"
#include "../../joystick/SDL_joystick_c.h"
#include "SDL_androidvideo.h"
extern SDLKey SDL_android_keymap[KEYCODE_LAST+1];
/* JNI-C++ wrapper stuff */
#if SDL_VERSION_ATLEAST(1,3,0)
#define SDL_KEY2(X) SDL_SCANCODE_ ## X
#define SDL_KEY(X) SDL_KEY2(X)
static inline SDL_scancode TranslateKey(int scancode, SDL_keysym *keysym)
{
if ( scancode >= SDL_arraysize(SDL_android_keymap) )
scancode = KEYCODE_UNKNOWN;
return SDL_android_keymap[scancode];
}
static inline SDL_scancode GetKeysym(SDL_scancode scancode, SDL_keysym *keysym)
{
return scancode;
}
#define SDL_SendKeyboardKey(X, Y) SDL_SendKeyboardKey(X, Y, SDL_FALSE)
#else
#define SDL_KEY2(X) SDLK_ ## X
#define SDL_KEY(X) SDL_KEY2(X)
#define SDL_SendKeyboardKey SDL_PrivateKeyboard
// Randomly redefining SDL 1.3 scancodes to SDL 1.2 keycodes
#define KP_0 KP0
#define KP_1 KP1
#define KP_2 KP2
#define KP_3 KP3
#define KP_4 KP4
#define KP_5 KP5
#define KP_6 KP6
#define KP_7 KP7
#define KP_8 KP8
#define KP_9 KP9
#define NUMLOCKCLEAR NUMLOCK
#define GRAVE DOLLAR
#define APOSTROPHE QUOTE
#define LGUI LMETA
// Overkill haha
#define A a
#define B b
#define C c
#define D d
#define E e
#define F f
#define G g
#define H h
#define I i
#define J j
#define K k
#define L l
#define M m
#define N n
#define O o
#define P p
#define Q q
#define R r
#define S s
#define T t
#define U u
#define V v
#define W w
#define X x
#define Y y
#define Z z
#define SDL_scancode SDLKey
static inline SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
{
/* Sanity check */
if ( scancode >= SDL_arraysize(SDL_android_keymap) )
scancode = KEYCODE_UNKNOWN;
/* Set the keysym information */
keysym->scancode = scancode;
keysym->sym = SDL_android_keymap[scancode];
keysym->mod = KMOD_NONE;
/* If UNICODE is on, get the UNICODE value for the key */
keysym->unicode = 0;
if ( SDL_TranslateUNICODE ) {
/* Populate the unicode field with the ASCII value */
keysym->unicode = scancode;
}
return(keysym);
}
static inline SDL_keysym *GetKeysym(SDLKey scancode, SDL_keysym *keysym)
{
/* Sanity check */
/* Set the keysym information */
keysym->scancode = scancode;
keysym->sym = scancode;
keysym->mod = KMOD_NONE;
/* If UNICODE is on, get the UNICODE value for the key */
keysym->unicode = 0;
if ( SDL_TranslateUNICODE ) {
/* Populate the unicode field with the ASCII value */
keysym->unicode = scancode;
}
return(keysym);
}
#endif
#define SDL_KEY_VAL(X) X
enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 };
extern int SDL_android_drawTouchscreenKeyboard();
extern int SDL_android_processTouchscreenKeyboard(int x, int y, int action);
#endif

View File

@@ -0,0 +1,107 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include <jni.h>
#include <android/log.h>
#include <sys/time.h>
#include <time.h>
#include <stdint.h>
#include <math.h>
#include <string.h> // for memset()
#include "SDL_config.h"
#include "SDL_version.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "SDL_events.h"
#if (SDL_VERSION_ATLEAST(1,3,0))
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
#include "SDL_scancode.h"
#include "SDL_compat.h"
#else
#include "SDL_keysym.h"
#include "../../events/SDL_events_c.h"
#endif
#include "SDL_joystick.h"
#include "../../joystick/SDL_sysjoystick.h"
#include "../../joystick/SDL_joystick_c.h"
#include "SDL_androidvideo.h"
#include "SDL_androidinput.h"
#include "touchscreenfont.h"
enum {
FONT_LEFT = 0, FONT_RIGHT = 1, FONT_UP = 2, FONT_DOWN = 3,
FONT_BTN1 = 4, FONT_BTN2 = 5, FONT_BTN3 = 6, FONT_BTN4 = 7
};
int SDL_android_processTouchscreenKeyboard(int x, int y, int action)
{
};
static const float inv255f = 1.0f / 255.0f;
// TODO: use SDL 1.3 renderer routines? It will not be pixel-aligned then, if the screen is resized
void drawChar(int idx, Uint16 x, Uint16 y, float scale, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
int i;
GLshort *vertices;
int count = 0;
for( i = 0; i < FONT_MAX_LINES_PER_CHAR; i++ )
if( font[idx][i].x1 == 0 && font[idx][i].y1 == 0 &&
font[idx][i].x2 == 0 && font[idx][i].y2 == 0 )
break;
count = i;
if( count <= 0 )
return;
glColor4f((GLfloat) r * inv255f,
(GLfloat) g * inv255f,
(GLfloat) b * inv255f,
(GLfloat) a * inv255f);
vertices = SDL_stack_alloc(GLshort, count*4);
for (i = 0; i < count; ++i) {
vertices[4*i+0] = (GLshort)(x + font[idx][i].x1 * scale);
vertices[4*i+1] = (GLshort)(y + font[idx][i].y1 * scale);
vertices[4*i+2] = (GLshort)(x + font[idx][i].x2 * scale);
vertices[4*i+3] = (GLshort)(y + font[idx][i].y2 * scale);
}
glVertexPointer(2, GL_SHORT, 0, vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, count*2);
glDisableClientState(GL_VERTEX_ARRAY);
SDL_stack_free(vertices);
}
int SDL_android_drawTouchscreenKeyboard()
{
};

View File

@@ -0,0 +1,65 @@
/* This file should be edited using Touchscreen Editor utility */
#ifndef _TOUCHSCREENFONT_H_
#define _TOUCHSCREENFONT_H_
#include <SDL_types.h>
typedef struct font_line_t { Uint8 x1, y1, x2, y2; } font_line_t;
enum { FONT_MAX_LINES_PER_CHAR = 5 };
font_line_t font[8][FONT_MAX_LINES_PER_CHAR] = {
{
{ 27, 136, 182, 136 },
{ 27, 136, 94, 104 },
{ 27, 136, 89, 162 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
},
{
{ 192, 123, 61, 123 },
{ 150, 103, 192, 123 },
{ 192, 123, 155, 144 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
},
{
{ 118, 43, 118, 188 },
{ 118, 43, 131, 88 },
{ 118, 43, 104, 87 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
},
{
{ 122, 45, 122, 200 },
{ 122, 200, 138, 156 },
{ 122, 200, 106, 158 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
},
{
{ 77, 204, 132, 64 },
{ 132, 64, 175, 200 },
{ 175, 200, 76, 204 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
},
{
{ 74, 190, 74, 73 },
{ 74, 73, 189, 74 },
{ 189, 74, 189, 180 },
{ 189, 180, 74, 190 },
{ 0, 0, 0, 0 }
},
{
{ 75, 78, 201, 183 },
{ 198, 66, 86, 193 },
{ 61, 135, 220, 128 },
{ 135, 59, 145, 199 },
{ 0, 0, 0, 0 }
},
{
{ 60, 200, 126, 50 },
{ 126, 50, 172, 199 },
{ 172, 199, 46, 85 },
{ 46, 85, 199, 85 },
{ 199, 85, 60, 200 }
}
};
#endif