SDL: increased on-screen keyboard to 12 keys

This commit is contained in:
Sergii Pylypenko
2021-05-23 03:12:03 +03:00
parent cc6cebb094
commit 5e27a1f850
8 changed files with 232 additions and 195 deletions

View File

@@ -150,7 +150,9 @@ echo "# If you'll start Description with '!' symbol it will be enabled by defaul
echo "# If the URL in in the form ':dir/file.dat:http://URL/' it will be downloaded as binary BLOB to the application dir and not unzipped" >> AndroidAppSettings.cfg
echo "# If the URL does not contain 'http://' or 'https://', it is treated as file from 'project/jni/application/src/AndroidData' dir -" >> AndroidAppSettings.cfg
echo "# these files are put inside .apk package by the build system" >> AndroidAppSettings.cfg
echo "# You can specify Google Play expansion files in the form 'obb:main.12345' or 'obb:patch.12345' where 12345 is the app version for obb file" >> AndroidAppSettings.cfg
echo "# You can specify Google Play expansion files in the form 'obb:main.12345' or 'obb:patch.12345' where 12345 is the app version for the obb file" >> AndroidAppSettings.cfg
echo "# You can mount expansion files created with jobb tool if you put 'mnt:main.12345' or 'mnt:patch.12345'" >> AndroidAppSettings.cfg
echo "# The mount directory will be returned by calling getenv(\"ANDROID_OBB_MOUNT_DIR\")" >> AndroidAppSettings.cfg
echo "# You can use .zip.xz archives for better compression, but you need to add 'lzma' to CompiledLibraries" >> AndroidAppSettings.cfg
echo "# Generate .zip.xz files like this: zip -0 -r data.zip your-data/* ; xz -8 data.zip" >> AndroidAppSettings.cfg
echo AppDataDownloadUrl=\"$AppDataDownloadUrl\" >> AndroidAppSettings.cfg
@@ -343,10 +345,11 @@ echo "# Use word NO_REMAP if you want to preserve native functionality for certa
echo "# Keys: TOUCHSCREEN (works only when AppUsesMouse=n), DPAD_CENTER/SEARCH, VOLUMEUP, VOLUMEDOWN, MENU, BACK, CAMERA" >> AndroidAppSettings.cfg
echo RedefinedKeys=\"$RedefinedKeys\" >> AndroidAppSettings.cfg
echo >> AndroidAppSettings.cfg
echo "# Number of virtual keyboard keys (currently 6 is maximum)" >> AndroidAppSettings.cfg
echo "# Number of virtual keyboard keys - currently 12 keys is the maximum" >> AndroidAppSettings.cfg
echo AppTouchscreenKeyboardKeysAmount=$AppTouchscreenKeyboardKeysAmount >> AndroidAppSettings.cfg
echo >> AndroidAppSettings.cfg
echo "# Redefine on-screen keyboard keys to SDL keysyms - 6 keyboard keys + 4 multitouch gestures (zoom in/out and rotate left/right)" >> AndroidAppSettings.cfg
echo "# Redefine on-screen keyboard keys to SDL keysyms - 6 keyboard keys + 4 multitouch gestures (zoom in/out and rotate left/right) + 6 additional keyboard keys" >> AndroidAppSettings.cfg
echo "# Multitouch gestures should be moved to a separate variable, but are left here for compatibility" >> AndroidAppSettings.cfg
echo RedefinedKeysScreenKb=\"$RedefinedKeysScreenKb\" >> AndroidAppSettings.cfg
echo >> AndroidAppSettings.cfg
echo "# Names for on-screen keyboard keys, such as Fire, Jump, Run etc, separated by spaces, they are used in SDL config menu" >> AndroidAppSettings.cfg

View File

@@ -132,12 +132,66 @@ class Globals
public static boolean KeepAspectRatio = KeepAspectRatioDefaultSetting;
public static boolean TvBorders = true;
public static int RemapHwKeycode[] = new int[SDL_Keys.JAVA_KEYCODE_LAST];
public static int RemapScreenKbKeycode[] = new int[6];
public static int ScreenKbControlsLayout[][] = AppUsesThirdJoystick ? // Values for 800x480 resolution
new int[][] { { 0, 303, 177, 480 }, { 0, 0, 48, 48 }, { 400, 392, 488, 480 }, { 312, 392, 400, 480 }, { 400, 304, 488, 392 }, { 312, 304, 400, 392 }, { 400, 216, 488, 304 }, { 312, 216, 400, 304 }, { 623, 303, 800, 480 }, { 623, 126, 800, 303 } } :
AppUsesSecondJoystick ?
new int[][] { { 0, 303, 177, 480 }, { 0, 0, 48, 48 }, { 400, 392, 488, 480 }, { 312, 392, 400, 480 }, { 400, 304, 488, 392 }, { 312, 304, 400, 392 }, { 400, 216, 488, 304 }, { 312, 216, 400, 304 }, { 623, 303, 800, 480 } } :
new int[][] { { 0, 303, 177, 480 }, { 0, 0, 48, 48 }, { 712, 392, 800, 480 }, { 624, 392, 712, 480 }, { 712, 304, 800, 392 }, { 624, 304, 712, 392 }, { 712, 216, 800, 304 }, { 624, 216, 712, 304 } };
public static int RemapScreenKbKeycode[] = new int[12];
// Values for 800x480 resolution
public static int ScreenKbControlsLayout[][] =
AppUsesThirdJoystick ? new int[][]
{
{ 0, 303, 177, 480 }, // Main joystick/DPAD
{ 0, 0, 48, 48 }, // Text input button
{ 400, 392, 488, 480 }, // Button 0
{ 312, 392, 400, 480 }, // Button 1
{ 400, 304, 488, 392 }, // Button 2
{ 312, 304, 400, 392 }, // Button 3
{ 400, 216, 488, 304 }, // Button 4
{ 312, 216, 400, 304 }, // Button 5
{ 623, 303, 800, 480 }, // Joystick 2
{ 623, 126, 800, 303 }, // Joystick 3
{ 400, 392, 488, 480 }, // Button 6 - copy of button 0, to be redefined in the code
{ 312, 392, 400, 480 }, // Button 7 - copy of button 1, to be redefined in the code
{ 400, 304, 488, 392 }, // Button 8 - copy of button 2, to be redefined in the code
{ 312, 304, 400, 392 }, // Button 9 - copy of button 3, to be redefined in the code
{ 400, 216, 488, 304 }, // Button 10 - copy of button 4, to be redefined in the code
{ 312, 216, 400, 304 }, // Button 11 - copy of button 5, to be redefined in the code
}
: AppUsesSecondJoystick ? new int[][]
{
{ 0, 303, 177, 480 }, // Main joystick/DPAD
{ 0, 0, 48, 48 }, // Text input button
{ 400, 392, 488, 480 }, // Button 0
{ 312, 392, 400, 480 }, // Button 1
{ 400, 304, 488, 392 }, // Button 2
{ 312, 304, 400, 392 }, // Button 3
{ 400, 216, 488, 304 }, // Button 4
{ 312, 216, 400, 304 }, // Button 5
{ 623, 303, 800, 480 }, // Joystick 2
{ 0, 0, 0, 0, }, // Joystick 3
{ 400, 392, 488, 480 }, // Button 6 - copy of button 0, to be redefined in the code
{ 312, 392, 400, 480 }, // Button 7 - copy of button 1, to be redefined in the code
{ 400, 304, 488, 392 }, // Button 8 - copy of button 2, to be redefined in the code
{ 312, 304, 400, 392 }, // Button 9 - copy of button 3, to be redefined in the code
{ 400, 216, 488, 304 }, // Button 10 - copy of button 4, to be redefined in the code
{ 312, 216, 400, 304 }, // Button 11 - copy of button 5, to be redefined in the code
}
: new int[][]
{
{ 0, 303, 177, 480 }, // Main joystick/DPAD
{ 0, 0, 48, 48 }, // Text input button
{ 712, 392, 800, 480 }, // Button 0
{ 624, 392, 712, 480 }, // Button 1
{ 712, 304, 800, 392 }, // Button 2
{ 624, 304, 712, 392 }, // Button 3
{ 712, 216, 800, 304 }, // Button 4
{ 624, 216, 712, 304 }, // Button 5
{ 0, 0, 0, 0, }, // Joystick 2
{ 0, 0, 0, 0, }, // Joystick 3
{ 536, 392, 624, 480 }, // Button 6
{ 448, 392, 536, 480 }, // Button 7
{ 536, 304, 624, 392 }, // Button 8
{ 448, 304, 536, 392 }, // Button 9
{ 536, 216, 624, 304 }, // Button 10
{ 448, 216, 536, 304 }, // Button 11
};
public static boolean ScreenKbControlsShown[] = new boolean[ScreenKbControlsLayout.length]; /* Also joystick and text input button added */
public static int RemapMultitouchGestureKeycode[] = new int[4];
public static boolean MultitouchGesturesUsed[] = new boolean[4];

View File

@@ -230,20 +230,22 @@ public class Settings
Globals.KeepAspectRatio = settingsFile.readBoolean();
Globals.MoveMouseWithJoystickSpeed = settingsFile.readInt();
Globals.MoveMouseWithJoystickAccel = settingsFile.readInt();
int readKeys = settingsFile.readInt();
for( int i = 0; i < readKeys; i++ )
int readKeysSize = settingsFile.readInt();
for( int i = 0; i < readKeysSize; i++ )
{
Globals.RemapHwKeycode[i] = settingsFile.readInt();
}
if( settingsFile.readInt() != Globals.RemapScreenKbKeycode.length )
int readScreenKbRemapKeysSize = settingsFile.readInt();
if( readScreenKbRemapKeysSize > Globals.RemapScreenKbKeycode.length )
throw new IOException();
for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ )
for( int i = 0; i < readScreenKbRemapKeysSize; i++ )
{
Globals.RemapScreenKbKeycode[i] = settingsFile.readInt();
}
if( settingsFile.readInt() != Globals.ScreenKbControlsShown.length )
int readScreenKbShownSize = settingsFile.readInt();
if( readScreenKbShownSize > Globals.ScreenKbControlsShown.length )
throw new IOException();
for( int i = 0; i < Globals.ScreenKbControlsShown.length; i++ )
for( int i = 0; i < readScreenKbShownSize; i++ )
{
Globals.ScreenKbControlsShown[i] = settingsFile.readBoolean();
}
@@ -270,9 +272,10 @@ public class Settings
b.append( settingsFile.readChar() );
Globals.CommandLine = b.toString();
if( settingsFile.readInt() != Globals.ScreenKbControlsLayout.length )
int screenKbControlsLayoutSize = settingsFile.readInt();
if( screenKbControlsLayoutSize > Globals.ScreenKbControlsLayout.length )
throw new IOException();
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int i = 0; i < screenKbControlsLayoutSize; i++ )
for( int ii = 0; ii < 4; ii++ )
Globals.ScreenKbControlsLayout[i][ii] = settingsFile.readInt();
Globals.LeftClickKey = settingsFile.readInt();
@@ -362,12 +365,14 @@ public class Settings
}
Globals.ScreenKbControlsShown[0] = (Globals.AppNeedsArrowKeys || Globals.AppUsesJoystick);
Globals.ScreenKbControlsShown[1] = Globals.AppNeedsTextInput;
for( int i = 2; i < Globals.ScreenKbControlsShown.length; i++ )
for( int i = 2; i < 8; i++ )
Globals.ScreenKbControlsShown[i] = ( i - 2 < Globals.AppTouchscreenKeyboardKeysAmount );
if( Globals.AppUsesSecondJoystick )
Globals.ScreenKbControlsShown[8] = true;
if( Globals.AppUsesThirdJoystick )
Globals.ScreenKbControlsShown[9] = true;
for( int i = 10; i < Globals.ScreenKbControlsShown.length; i++ )
Globals.ScreenKbControlsShown[i] = ( i - 4 < Globals.AppTouchscreenKeyboardKeysAmount );
for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ )
{
int sdlKey = nativeGetKeymapKeyMultitouchGesture(i);

View File

@@ -386,26 +386,22 @@ class SettingsMenuKeyboard extends SettingsMenu
p.getResources().getString(R.string.remap_screenkb_button) + " 4",
p.getResources().getString(R.string.remap_screenkb_button) + " 5",
p.getResources().getString(R.string.remap_screenkb_button) + " 6",
p.getResources().getString(R.string.remap_screenkb_joystick) + " 2",
p.getResources().getString(R.string.remap_screenkb_joystick) + " 3",
p.getResources().getString(R.string.remap_screenkb_button) + " 7",
p.getResources().getString(R.string.remap_screenkb_button) + " 8",
p.getResources().getString(R.string.remap_screenkb_button) + " 9",
p.getResources().getString(R.string.remap_screenkb_button) + " 10",
p.getResources().getString(R.string.remap_screenkb_button) + " 11",
p.getResources().getString(R.string.remap_screenkb_button) + " 12",
};
boolean defaults[] = Arrays.copyOf(Globals.ScreenKbControlsShown, Globals.ScreenKbControlsShown.length);
if( Globals.AppUsesSecondJoystick )
{
items = Arrays.copyOf(items, items.length + 1);
items[items.length - 1] = p.getResources().getString(R.string.remap_screenkb_joystick) + " 2";
defaults = Arrays.copyOf(defaults, defaults.length + 1);
defaults[defaults.length - 1] = true;
}
if( Globals.AppUsesThirdJoystick )
{
items = Arrays.copyOf(items, items.length + 1);
items[items.length - 1] = p.getResources().getString(R.string.remap_screenkb_joystick) + " 3";
defaults = Arrays.copyOf(defaults, defaults.length + 1);
defaults[defaults.length - 1] = true;
}
for( int i = 0; i < Math.min(6, Globals.AppTouchscreenKeyboardKeysNames.length); i++ )
items[i+2] = items[i+2] + " - " + Globals.AppTouchscreenKeyboardKeysNames[i].replace("_", " ");
for( int i = 6; i < Math.min(12, Globals.AppTouchscreenKeyboardKeysNames.length); i++ )
items[i+4] = items[i+4] + " - " + Globals.AppTouchscreenKeyboardKeysNames[i].replace("_", " ");
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(p.getResources().getString(R.string.remap_screenkb));
@@ -445,9 +441,15 @@ class SettingsMenuKeyboard extends SettingsMenu
p.getResources().getString(R.string.remap_screenkb_button) + " 4",
p.getResources().getString(R.string.remap_screenkb_button) + " 5",
p.getResources().getString(R.string.remap_screenkb_button) + " 6",
p.getResources().getString(R.string.remap_screenkb_button) + " 7",
p.getResources().getString(R.string.remap_screenkb_button) + " 8",
p.getResources().getString(R.string.remap_screenkb_button) + " 9",
p.getResources().getString(R.string.remap_screenkb_button) + " 10",
p.getResources().getString(R.string.remap_screenkb_button) + " 11",
p.getResources().getString(R.string.remap_screenkb_button) + " 12",
};
for( int i = 0; i < Math.min(6, Globals.AppTouchscreenKeyboardKeysNames.length); i++ )
for( int i = 0; i < Math.min(12, Globals.AppTouchscreenKeyboardKeysNames.length); i++ )
items[i] = items[i] + " - " + Globals.AppTouchscreenKeyboardKeysNames[i].replace("_", " ");
if( currentButton >= Globals.RemapScreenKbKeycode.length )
@@ -657,7 +659,13 @@ class SettingsMenuKeyboard extends SettingsMenu
R.drawable.b5,
R.drawable.b6,
R.drawable.dpad,
R.drawable.dpad
R.drawable.dpad,
R.drawable.b1,
R.drawable.b2,
R.drawable.b3,
R.drawable.b4,
R.drawable.b5,
R.drawable.b6,
};
int oldX = 0, oldY = 0;
boolean resizing = false;
@@ -780,6 +788,10 @@ class SettingsMenuKeyboard extends SettingsMenu
buttonText = "Joystick 2";
if( i == 9 )
buttonText = "Joystick 3";
if( i >= 10 && i <= 15 )
buttonText = p.getResources().getString(R.string.remap_screenkb_button) + (i - 4);
if( i >= 10 && i - 4 < Globals.AppTouchscreenKeyboardKeysNames.length )
buttonText = Globals.AppTouchscreenKeyboardKeysNames[i - 4].replace("_", " ");
p.setText(p.getResources().getString(R.string.screenkb_custom_layout_help) + "\n" + buttonText);
}
@@ -879,7 +891,7 @@ class SettingsMenuKeyboard extends SettingsMenu
p.getResources().getString(R.string.screenkb_floating_joystick),
};
boolean defaults[] = {
boolean defaults[] = {
Globals.FloatingScreenJoystick,
};

View File

@@ -147,7 +147,7 @@ AppNeedsArrowKeys=y
FloatingScreenJoystick=n
# Application needs text input (y) or (n), enables button for text input on screen
AppNeedsTextInput=y
AppNeedsTextInput=n
# Application uses joystick (y) or (n), the on-screen DPAD will be used as joystick 0 axes 0-1
# This will disable AppNeedsArrowKeys option
@@ -211,13 +211,13 @@ NonBlockingSwapBuffers=n
RedefinedKeys="SPACE SPACE NO_REMAP NO_REMAP RETURN ESCAPE LCTRL"
# Number of virtual keyboard keys (currently 6 is maximum)
AppTouchscreenKeyboardKeysAmount=6
AppTouchscreenKeyboardKeysAmount=8
# Redefine on-screen keyboard keys to SDL keysyms - 6 keyboard keys + 4 multitouch gestures (zoom in/out and rotate left/right)
RedefinedKeysScreenKb="SLASH BACKSPACE TAB END LCTRL SPACE UNKNOWN UNKNOWN UNKNOWN UNKNOWN"
RedefinedKeysScreenKb="SLASH BACKSPACE TAB END LCTRL SPACE UNKNOWN UNKNOWN UNKNOWN UNKNOWN T BACKQUOTE"
# Names for on-screen keyboard keys, such as Fire, Jump, Run etc, separated by spaces, they are used in SDL config menu
RedefinedKeysScreenKbNames="Change_weapon Sniper_view Show_scores Quick_rotate Fire Jump"
RedefinedKeysScreenKbNames="Change_weapon Sniper_view Show_scores Quick_rotate Fire Jump Chat Console"
# On-screen keys theme
# 0 = Ultimate Droid by Sean Stieber (green, with cross joystick)

View File

@@ -57,6 +57,13 @@ enum {
SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2, /* Second joystick button */
SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3, /* Third joystick button */
SDL_ANDROID_SCREENKEYBOARD_BUTTON_6, /* Has the same graphics as the first 6 keys */
SDL_ANDROID_SCREENKEYBOARD_BUTTON_7,
SDL_ANDROID_SCREENKEYBOARD_BUTTON_8,
SDL_ANDROID_SCREENKEYBOARD_BUTTON_9,
SDL_ANDROID_SCREENKEYBOARD_BUTTON_10,
SDL_ANDROID_SCREENKEYBOARD_BUTTON_11,
SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM
};

View File

@@ -210,6 +210,24 @@ extern int SDL_ANDROID_isTouchscreenKeyboardUsed;
#ifndef SDL_ANDROID_SCREENKB_KEYCODE_9
#define SDL_ANDROID_SCREENKB_KEYCODE_9 UNKNOWN
#endif
#ifndef SDL_ANDROID_SCREENKB_KEYCODE_10
#define SDL_ANDROID_SCREENKB_KEYCODE_10 UNKNOWN
#endif
#ifndef SDL_ANDROID_SCREENKB_KEYCODE_11
#define SDL_ANDROID_SCREENKB_KEYCODE_11 UNKNOWN
#endif
#ifndef SDL_ANDROID_SCREENKB_KEYCODE_12
#define SDL_ANDROID_SCREENKB_KEYCODE_12 UNKNOWN
#endif
#ifndef SDL_ANDROID_SCREENKB_KEYCODE_13
#define SDL_ANDROID_SCREENKB_KEYCODE_13 UNKNOWN
#endif
#ifndef SDL_ANDROID_SCREENKB_KEYCODE_14
#define SDL_ANDROID_SCREENKB_KEYCODE_14 UNKNOWN
#endif
#ifndef SDL_ANDROID_SCREENKB_KEYCODE_15
#define SDL_ANDROID_SCREENKB_KEYCODE_15 UNKNOWN
#endif
// Gamepad keys
#ifndef SDL_ANDROID_GAMEPAD_0_KEYCODE_0

View File

@@ -51,7 +51,13 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
// TODO: this code is a HUGE MESS
enum { MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM-1, MAX_JOYSTICKS = 3, MAX_BUTTONS_AUTOFIRE = 2, BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, BUTTON_ARROWS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD } ; // Max amount of custom buttons
enum {
MAX_JOYSTICKS = 3,
MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM, // Max amount of custom buttons
MAX_BUTTONS_AUTOFIRE = 2,
BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT,
BUTTON_ARROWS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD
};
int SDL_ANDROID_isTouchscreenKeyboardUsed = 0;
static short touchscreenKeyboardTheme = 0;
@@ -71,15 +77,24 @@ SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_2)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_3)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_4)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_5)),
0
SDLK_UNKNOWN, // Text input
SDLK_UNKNOWN, // Joystick 0
SDLK_UNKNOWN, // Joystick 1
SDLK_UNKNOWN, // Joystick 2
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_10)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_11)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_12)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_13)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_14)),
SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_15)),
};
enum { ARROW_LEFT = 1, ARROW_RIGHT = 2, ARROW_UP = 4, ARROW_DOWN = 8 };
static short oldArrows = 0;
static Sint8 pointerInButtonRect[MAX_BUTTONS + MAX_JOYSTICKS];
static Sint8 buttonsGenerateSdlEvents[MAX_BUTTONS + MAX_JOYSTICKS];
static Sint8 buttonsStayPressedAfterTouch[MAX_BUTTONS + MAX_JOYSTICKS];
static Sint8 pointerInButtonRect[MAX_BUTTONS];
static Sint8 buttonsGenerateSdlEvents[MAX_BUTTONS];
static Sint8 buttonsStayPressedAfterTouch[MAX_BUTTONS];
typedef struct
{
@@ -100,8 +115,6 @@ static int floatingScreenJoystick = 0;
int SDL_ANDROID_AsyncTextInputActive = 0;
static void R_DumpOpenGlState(void);
static inline int InsideRect(const SDL_Rect * r, int x, int y)
{
return ( x >= r->x && x <= r->x + r->w ) && ( y >= r->y && y <= r->y + r->h );
@@ -178,8 +191,6 @@ static inline void beginDrawingTex()
glGetIntegerv(GL_ACTIVE_TEXTURE, &oldGlState.texunitId);
#endif
//R_DumpOpenGlState();
/*
glActiveTexture(GL_TEXTURE1);
glClientActiveTexture(GL_TEXTURE1);
@@ -372,11 +383,14 @@ static void drawTouchscreenKeyboardSun()
for( i = 0; i < MAX_BUTTONS; i++ )
{
int pressed = SDL_GetKeyboardState(NULL)[buttonKeysyms[i]];
int flip = (i >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_2 && i <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5) ||
(i >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_8 && i <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_11);
if( ! buttons[i].h || ! buttons[i].w )
continue;
drawCharTexFlip( &buttonImages[ pressed ? (i * 2 + 1) : (i * 2) ],
NULL, &buttonsDraw[i], (i >= 2 && pressed), 0, 1.0f, 1.0f, 1.0f, transparency );
NULL, &buttonsDraw[i], (flip && pressed), 0, 1.0f, 1.0f, 1.0f, transparency );
}
}
@@ -405,17 +419,19 @@ static void drawTouchscreenKeyboardDualShock()
touch.y = arrowsDraw[i].y + touch.h / 4;
drawCharTex( &arrowImages[6], NULL, &touch, 1.0f, 1.0f, 1.0f, transparency );
}
}
for( i = 0; i < MAX_BUTTONS; i++ )
{
int pressed = SDL_GetKeyboardState(NULL)[buttonKeysyms[i]];
int flip = (i >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_2 && i <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5) ||
(i >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_8 && i <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_11);
if( ! buttons[i].h || ! buttons[i].w )
continue;
drawCharTexFlip( &buttonImages[ pressed ? (i * 2 + 1) : (i * 2) ],
NULL, &buttonsDraw[i], (i >= 2 && pressed), 0, 1.0f, 1.0f, 1.0f, transparency );
NULL, &buttonsDraw[i], (flip && pressed), 0, 1.0f, 1.0f, 1.0f, transparency );
}
}
@@ -496,8 +512,10 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
if( pointerInButtonRect[i] != -1 )
{
pointerInButtonRect[i] = -1;
if( i != BUTTON_TEXT_INPUT )
if( buttonKeysyms[i] != SDLK_UNKNOWN )
{
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, buttonKeysyms[i], 0 );
}
}
}
for( j = 0; j < joyAmount; j++ )
@@ -540,11 +558,16 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
{
pointerInButtonRect[i] = pointerId;
if( i == BUTTON_TEXT_INPUT )
{
SDL_ANDROID_ToggleScreenKeyboardTextInput(NULL);
else if( buttonsStayPressedAfterTouch[i] )
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_GetKeyboardState(NULL)[buttonKeysyms[i]] == 0 ? SDL_PRESSED : SDL_RELEASED, buttonKeysyms[i], 0 );
else
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, buttonKeysyms[i], 0 );
}
else if( buttonKeysyms[i] != SDLK_UNKNOWN )
{
if( buttonsStayPressedAfterTouch[i] )
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_GetKeyboardState(NULL)[buttonKeysyms[i]] == 0 ? SDL_PRESSED : SDL_RELEASED, buttonKeysyms[i], 0 );
else
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, buttonKeysyms[i], 0 );
}
if( preventButtonOverlap )
{
processOtherButtons = 0;
@@ -649,7 +672,7 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
{
processed |= 1<<i;
pointerInButtonRect[i] = -1;
if( i != BUTTON_TEXT_INPUT && !buttonsStayPressedAfterTouch[i] )
if( i != BUTTON_TEXT_INPUT && !buttonsStayPressedAfterTouch[i] && buttonKeysyms[i] != SDLK_UNKNOWN )
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, buttonKeysyms[i], 0 );
}
}
@@ -761,7 +784,7 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
if( ! InsideRect( &buttons[i], x, y ) && ! buttonsGenerateSdlEvents[i] )
{
pointerInButtonRect[i] = -1;
if( i != BUTTON_TEXT_INPUT )
if( i != BUTTON_TEXT_INPUT && buttonKeysyms[i] != SDLK_UNKNOWN )
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, buttonKeysyms[i], 0 );
}
}
@@ -999,6 +1022,9 @@ static int setupScreenKeyboardButtonLegacy( int buttonID, Uint8 * charBuf )
else // Error, array too big
return 12; // Return value bigger than zero to iterate it
for( int i = SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 * 2; i < SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 * 2; i++ )
buttonImages[i + SDL_ANDROID_SCREENKEYBOARD_BUTTON_6 * 2] = buttonImages[i];
return setupScreenKeyboardButtonTexture(data, charBuf);
}
@@ -1024,9 +1050,9 @@ static int setupScreenKeyboardButtonSun( int buttonID, Uint8 * charBuf )
ret = setupScreenKeyboardButtonTexture(data, charBuf);
for( i = 1; i <=4; i++ )
for( i = 1; i <= 4; i++ )
arrowImages[i] = arrowImages[0];
for( i = 2; i < MAX_BUTTONS; i++ )
buttonImages[i * 2 + 1] = buttonImages[i * 2];
@@ -1036,6 +1062,9 @@ static int setupScreenKeyboardButtonSun( int buttonID, Uint8 * charBuf )
buttonImages[BUTTON_TEXT_INPUT*2] = buttonImages[10];
buttonImages[BUTTON_TEXT_INPUT*2+1] = buttonImages[10];
for( int i = SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 * 2; i < SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 * 2; i++ )
buttonImages[i + SDL_ANDROID_SCREENKEYBOARD_BUTTON_6 * 2] = buttonImages[i];
return ret;
}
@@ -1073,6 +1102,9 @@ static int setupScreenKeyboardButtonDualShock( int buttonID, Uint8 * charBuf )
buttonImages[BUTTON_TEXT_INPUT*2] = arrowImages[5];
buttonImages[BUTTON_TEXT_INPUT*2+1] = arrowImages[5];
for( int i = SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 * 2; i < SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 * 2; i++ )
buttonImages[i + SDL_ANDROID_SCREENKEYBOARD_BUTTON_6 * 2] = buttonImages[i];
return ret;
}
@@ -1120,11 +1152,15 @@ JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboardButtons) ( JNIEnv* env, jobj
JNIEXPORT jint JNICALL
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyScreenKb) (JNIEnv* env, jobject thiz, jint keynum)
{
if( keynum < 0 || keynum > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 + 4 )
return SDL_KEY(UNKNOWN);
if( keynum <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 )
return SDL_ANDROID_GetScreenKeyboardButtonKey(keynum + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0);
if( keynum >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 && keynum <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 )
{
return SDL_ANDROID_GetScreenKeyboardButtonKey(keynum);
}
if( keynum >= 6 && keynum <= 11 )
{
return SDL_ANDROID_GetScreenKeyboardButtonKey(keynum - 6 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_6);
}
return SDL_KEY(UNKNOWN);
}
@@ -1132,17 +1168,20 @@ JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyScreenKb) (JNIEnv* env, jobject thiz
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKeyScreenKb) (JNIEnv* env, jobject thiz, jint keynum, jint key)
{
if( keynum < 0 || keynum > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 + 4 )
return;
if( keynum <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 )
SDL_ANDROID_SetScreenKeyboardButtonKey(keynum + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, key);
if( keynum >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 && keynum <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 )
{
SDL_ANDROID_SetScreenKeyboardButtonKey(keynum, key);
}
if( keynum >= 6 && keynum <= 11 )
{
SDL_ANDROID_SetScreenKeyboardButtonKey(keynum - 6 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_6, key);
}
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyUsed) (JNIEnv* env, jobject thiz, jint keynum, jint used)
static int convertJavaKeyIdToC(int keynum)
{
SDL_Rect rect = {0, 0, 0, 0};
// Why didn't I use consistent IDs between Java and C code?
int key = -1;
if( keynum == 0 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD;
@@ -1150,11 +1189,16 @@ JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyUsed) (JNIEnv* env, jobject thiz,
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT;
if( keynum - 2 >= 0 && keynum - 2 <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 )
key = keynum - 2 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
if( keynum >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2 && keynum < SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM )
key = keynum; // This one is consistent by chance
return key;
}
if( keynum == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2;
if( keynum == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3;
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyUsed) (JNIEnv* env, jobject thiz, jint keynum, jint used)
{
SDL_Rect rect = {0, 0, 0, 0};
int key = convertJavaKeyIdToC(keynum);
if( key >= 0 && !used )
SDL_ANDROID_SetScreenKeyboardButtonPos(key, &rect);
@@ -1216,15 +1260,22 @@ int SDL_ANDROID_GetScreenKeyboardButtonPos(int buttonId, SDL_Rect * pos)
int SDL_ANDROID_SetScreenKeyboardButtonKey(int buttonId, SDLKey key)
{
if( buttonId < 0 || buttonId > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 || ! key )
return 0;
buttonKeysyms[buttonId] = key;
return 1;
if( buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 && buttonId <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 )
{
buttonKeysyms[buttonId] = key;
return 1;
}
if( buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_6 && buttonId <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_11 )
{
buttonKeysyms[buttonId] = key;
return 1;
}
return 0;
};
SDLKey SDL_ANDROID_GetScreenKeyboardButtonKey(int buttonId)
{
if( buttonId < 0 || buttonId > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 )
if( buttonId < 0 || buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM )
return SDLK_UNKNOWN;
return buttonKeysyms[buttonId];
};
@@ -1363,23 +1414,6 @@ int SDLCALL SDL_ANDROID_SetScreenKeyboardTransparency(int alpha)
static int ScreenKbRedefinedByUser = 0;
static int convertJavaKeyIdToC(int keynum)
{
// Why didn't I use consistent IDs between Java and C code?
int key = -1;
if( keynum == 0 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD;
if( keynum == 1 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT;
if( keynum - 2 >= 0 && keynum - 2 <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 )
key = keynum - 2 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
if( keynum == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2 ) // This one is consistent by chance
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2;
if( keynum == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3 ) // This one is consistent by chance
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3;
return key;
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz, jint keynum, jint x1, jint y1, jint x2, jint y2)
{
@@ -1448,99 +1482,3 @@ extern DECLSPEC int SDL_ANDROID_ScreenKeyboardUpdateToNewVideoMode(int oldx, int
}
return 0;
}
/**
* @brief Dumps OpenGL state for debugging - typically every capability set with glEnable().
*/
void R_DumpOpenGlState(void)
{
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
#define CAPABILITY( X ) {GL_ ## X, # X}
/* List taken from here: http://www.khronos.org/opengles/sdk/1.1/docs/man/glIsEnabled.xml */
const struct { GLenum idx; const char * text; } openGLCaps[] = {
CAPABILITY(ALPHA_TEST),
CAPABILITY(BLEND),
CAPABILITY(COLOR_ARRAY),
CAPABILITY(COLOR_LOGIC_OP),
CAPABILITY(COLOR_MATERIAL),
CAPABILITY(CULL_FACE),
CAPABILITY(DEPTH_TEST),
CAPABILITY(DITHER),
CAPABILITY(FOG),
CAPABILITY(LIGHTING),
CAPABILITY(LINE_SMOOTH),
CAPABILITY(MULTISAMPLE),
CAPABILITY(NORMAL_ARRAY),
CAPABILITY(NORMALIZE),
CAPABILITY(POINT_SMOOTH),
CAPABILITY(POLYGON_OFFSET_FILL),
CAPABILITY(RESCALE_NORMAL),
CAPABILITY(SAMPLE_ALPHA_TO_COVERAGE),
CAPABILITY(SAMPLE_ALPHA_TO_ONE),
CAPABILITY(SAMPLE_COVERAGE),
CAPABILITY(SCISSOR_TEST),
CAPABILITY(STENCIL_TEST),
CAPABILITY(VERTEX_ARRAY)
};
#undef CAPABILITY
char s[1024] = "";
GLint i;
GLint maxTexUnits = 0;
GLint activeTexUnit = 0;
GLint activeClientTexUnit = 0;
GLint activeTexId = 0;
GLfloat texEnvMode = 0;
const char * texEnvModeStr = "UNKNOWN";
GLfloat color[4];
for (i = 0; i < sizeof(openGLCaps) / sizeof(openGLCaps[0]); i++) {
if (glIsEnabled(openGLCaps[i].idx)) {
strcat(s, openGLCaps[i].text);
strcat(s, " ");
}
}
glGetFloatv(GL_CURRENT_COLOR, color);
__android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL enabled caps: %s color %f %f %f %f \n", s, color[0], color[1], color[2], color[3]);
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexUnit);
glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &activeClientTexUnit);
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits);
for (i = GL_TEXTURE0; i < GL_TEXTURE0 + maxTexUnits; i++) {
glActiveTexture(i);
glClientActiveTexture(i);
strcpy(s, "");
if (glIsEnabled (GL_TEXTURE_2D))
strcat(s, "enabled, ");
if (glIsEnabled (GL_TEXTURE_COORD_ARRAY))
strcat(s, "with texcoord array, ");
if (i == activeTexUnit)
strcat(s, "active, ");
if (i == activeClientTexUnit)
strcat(s, "client active, ");
glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexId);
glGetTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texEnvMode);
if (fabs(texEnvMode - GL_ADD) < 0.1f)
texEnvModeStr = "ADD";
if (fabs(texEnvMode - GL_MODULATE) < 0.1f)
texEnvModeStr = "MODULATE";
if (fabs(texEnvMode - GL_DECAL) < 0.1f)
texEnvModeStr = "DECAL";
if (fabs(texEnvMode - GL_BLEND) < 0.1f)
texEnvModeStr = "BLEND";
if (fabs(texEnvMode - GL_REPLACE) < 0.1f)
texEnvModeStr = "REPLACE";
if (fabs(texEnvMode - GL_COMBINE) < 0.1f)
texEnvModeStr = "COMBINE";
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Texunit: %d texID %d %s texEnv mode %s\n", i - GL_TEXTURE0, activeTexId, s, texEnvModeStr);
}
glActiveTexture(activeTexUnit);
glClientActiveTexture(activeClientTexUnit);
#endif
}