Added advanced point-and-click features: right mouse click via several methods, left click configurable, and showing part of screen under finger in small window

This commit is contained in:
pelya
2010-11-09 16:05:39 +02:00
parent d77db689e6
commit 8f6f72b1fb
13 changed files with 260 additions and 74 deletions

View File

@@ -476,6 +476,7 @@ cat project/src/Globals.java | \
sed "s/public static boolean HorizontalOrientation = .*;/public static boolean HorizontalOrientation = $HorizontalOrientation;/" | \
sed "s/public static boolean InhibitSuspend = .*;/public static boolean InhibitSuspend = $InhibitSuspend;/" | \
sed "s/public static boolean AppUsesMouse = .*;/public static boolean AppUsesMouse = $AppUsesMouse;/" | \
sed "s/public static boolean AppNeedsTwoButtonMouse = .*;/public static boolean AppNeedsTwoButtonMouse = $AppNeedsTwoButtonMouse;/" | \
sed "s/public static boolean AppNeedsArrowKeys = .*;/public static boolean AppNeedsArrowKeys = $AppNeedsArrowKeys;/" | \
sed "s/public static boolean AppNeedsTextInput = .*;/public static boolean AppNeedsTextInput = $AppNeedsTextInput;/" | \
sed "s/public static boolean AppUsesJoystick = .*;/public static boolean AppUsesJoystick = $AppUsesJoystick;/" | \

View File

@@ -57,9 +57,10 @@ class Globals {
public static int TrackballDampening = 0;
public static int AudioBufferConfig = 0;
public static boolean OptionalDataDownload[] = null;
public static final int RIGHT_CLICK_WITH_MENU_BUTTON = 0;
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
public static final int RIGHT_CLICK_NONE = 0;
public static final int RIGHT_CLICK_WITH_MENU_BUTTON = 1;
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 2;
public static final int RIGHT_CLICK_WITH_PRESSURE = 3;
public static int RightClickMethod = RIGHT_CLICK_WITH_MENU_BUTTON;
public static boolean LeftClickUsesPressure = false;
public static boolean ShowScreenUnderFinger = false;

View File

@@ -55,6 +55,7 @@ public class MainActivity extends Activity {
onClickListener( MainActivity _p ) { p = _p; }
public void onClick(View v)
{
setUpStatusLabel();
System.out.println("libSDL: User clicked change phone config button");
Settings.showConfig(p);
}
@@ -106,6 +107,23 @@ public class MainActivity extends Activity {
changeConfigAlertThread.start();
}
}
public void setUpStatusLabel()
{
MainActivity Parent = this; // Too lazy to rename
if( Parent._btn != null )
{
Parent._layout2.removeView(Parent._btn);
Parent._btn = null;
}
if( Parent._tv == null )
{
Parent._tv = new TextView(Parent);
Parent._tv.setMaxLines(1);
Parent._tv.setText(R.string.init);
Parent._layout2.addView(Parent._tv);
}
}
public void startDownloader()
{
@@ -115,20 +133,7 @@ public class MainActivity extends Activity {
public MainActivity Parent;
public void run()
{
System.out.println("libSDL: Removing button from startup screen and adding status text");
if( Parent._btn != null )
{
Parent._layout2.removeView(Parent._btn);
Parent._btn = null;
}
if( Parent._tv == null )
{
Parent._tv = new TextView(Parent);
Parent._tv.setMaxLines(1);
Parent._tv.setText(R.string.init);
Parent._layout2.addView(Parent._tv);
}
setUpStatusLabel();
System.out.println("libSDL: Starting downloader");
if( Parent.downloader == null )
Parent.downloader = new DataDownloader(Parent, Parent._tv);
@@ -284,6 +289,9 @@ public class MainActivity extends Activity {
else
if( _btn != null )
return _btn.dispatchTouchEvent(ev);
else
if( _touchMeasurementTool != null )
_touchMeasurementTool.onTouchEvent(ev);
return true;
}
@@ -297,17 +305,18 @@ public class MainActivity extends Activity {
{
class Callback implements Runnable
{
public TextView Status;
MainActivity Parent;
public String text;
public void run()
{
if(Status != null)
Status.setText(text);
Parent.setUpStatusLabel();
if(Parent._tv != null)
Parent._tv.setText(text);
}
}
Callback cb = new Callback();
cb.text = new String(t);
cb.Status = _tv;
cb.Parent = this;
this.runOnUiThread(cb);
}
@@ -348,5 +357,6 @@ public class MainActivity extends Activity {
private FrameLayout _videoLayout = null;
private EditText _screenKeyboard = null;
private boolean sdlInited = false;
public Settings.TouchMeasurementTool _touchMeasurementTool = null;
}

View File

@@ -124,6 +124,7 @@ class Settings
*/
System.out.println("libSDL: Settings.Load(): loading settings failed, running config dialog");
p.setUpStatusLabel();
showConfig(p);
}
@@ -208,6 +209,8 @@ class Settings
static void showKeyboardConfig(final MainActivity p)
{
Globals.PhoneHasArrowKeys = false;
Globals.PhoneHasTrackball = false;
if( ! Globals.AppNeedsArrowKeys )
{
showTrackballConfig(p);
@@ -270,6 +273,9 @@ class Settings
static void showAdditionalInputConfig(final MainActivity p)
{
Globals.UseTouchscreenKeyboard = false;
Globals.UseAccelerometerAsArrowKeys = false;
if( ! ( Globals.AppNeedsArrowKeys || Globals.AppNeedsTextInput || Globals.AppTouchscreenKeyboardKeysAmount > 0 ) && ! Globals.AppUsesJoystick )
{
showAccelerometerConfig(p);
@@ -280,9 +286,6 @@ class Settings
p.getResources().getString(R.string.controls_accelnav),
};
Globals.UseTouchscreenKeyboard = false;
Globals.UseAccelerometerAsArrowKeys = false;
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(p.getResources().getString(R.string.controls_additional));
builder.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener()
@@ -406,7 +409,7 @@ class Settings
Globals.TouchscreenKeyboardTheme = 0;
if( ! Globals.UseTouchscreenKeyboard )
{
showRightClickConfigConfig(p);
showAudioConfig(p);
return;
}
@@ -426,6 +429,29 @@ class Settings
if( item == 1 )
Globals.TouchscreenKeyboardTheme = 0;
dialog.dismiss();
showAudioConfig(p);
}
});
AlertDialog alert = builder.create();
alert.setOwnerActivity(p);
alert.show();
}
static void showAudioConfig(final MainActivity p)
{
final CharSequence[] items = { p.getResources().getString(R.string.audiobuf_verysmall),
p.getResources().getString(R.string.audiobuf_small),
p.getResources().getString(R.string.audiobuf_medium),
p.getResources().getString(R.string.audiobuf_large) };
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(R.string.audiobuf_question);
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
Globals.AudioBufferConfig = item;
dialog.dismiss();
showRightClickConfigConfig(p);
}
@@ -437,7 +463,7 @@ class Settings
static void showRightClickConfigConfig(final MainActivity p)
{
Globals.RightClickMethod = RIGHT_CLICK_WITH_MENU_BUTTON;
Globals.RightClickMethod = Globals.RIGHT_CLICK_NONE;
if( ! Globals.AppNeedsTwoButtonMouse )
{
showAdvancedPointAndClickConfigConfig(p);
@@ -453,7 +479,7 @@ class Settings
{
public void onClick(DialogInterface dialog, int item)
{
Globals.RightClickMethod = item;
Globals.RightClickMethod = item + 1;
dialog.dismiss();
showAdvancedPointAndClickConfigConfig(p);
}
@@ -470,13 +496,16 @@ class Settings
if( ! Globals.AppNeedsTwoButtonMouse )
{
showAudioConfig(p);
showTouchPressureMeasurementTool(p);
return;
}
final CharSequence[] items = (Globals.RightClickMethod == RIGHT_CLICK_WITH_PRESSURE) ?
{ p.getResources().getString(R.string.pointandclick_showcreenunderfinger) } :
{ p.getResources().getString(R.string.pointandclick_showcreenunderfinger),
p.getResources().getString(R.string.pointandclick_usepressure) };
CharSequence[] items = { p.getResources().getString(R.string.pointandclick_showcreenunderfinger),
p.getResources().getString(R.string.pointandclick_usepressure) };
if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE )
{
CharSequence[] items2 = { p.getResources().getString(R.string.pointandclick_showcreenunderfinger) };
items = items2;
}
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(p.getResources().getString(R.string.pointandclick_question));
@@ -495,7 +524,7 @@ class Settings
public void onClick(DialogInterface dialog, int item)
{
dialog.dismiss();
showAudioConfig(p);
showTouchPressureMeasurementTool(p);
}
});
@@ -504,29 +533,72 @@ class Settings
alert.show();
}
static void showAudioConfig(final MainActivity p)
public static class TouchMeasurementTool
{
final CharSequence[] items = { p.getResources().getString(R.string.audiobuf_verysmall),
p.getResources().getString(R.string.audiobuf_small),
p.getResources().getString(R.string.audiobuf_medium),
p.getResources().getString(R.string.audiobuf_large) };
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(R.string.audiobuf_question);
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
MainActivity p;
ArrayList<Integer> force = new ArrayList<Integer>();
ArrayList<Integer> radius = new ArrayList<Integer>();
static final int maxEventAmount = 100;
public TouchMeasurementTool(MainActivity _p)
{
public void onClick(DialogInterface dialog, int item)
p = _p;
}
public void onTouchEvent(final MotionEvent ev)
{
force.add(new Integer((int)(ev.getPressure() * 1000.0)));
radius.add(new Integer((int)(ev.getSize() * 1000.0)));
p.setText(p.getResources().getString(R.string.measurepressure_response, force.get(force.size()-1), radius.get(radius.size()-1)));
try {
Thread.sleep(10L);
} catch (InterruptedException e) { }
if( force.size() >= maxEventAmount )
{
Globals.AudioBufferConfig = item;
dialog.dismiss();
p._touchMeasurementTool = null;
Globals.ClickScreenPressure = getAverageForce();
Globals.ClickScreenTouchspotSize = getAverageRadius();
System.out.println("SDL: measured average force " + Globals.ClickScreenPressure + " radius " + Globals.ClickScreenTouchspotSize);
Save(p);
p.startDownloader();
}
});
AlertDialog alert = builder.create();
alert.setOwnerActivity(p);
alert.show();
}
int getAverageForce()
{
int avg = 0;
for(Integer f: force)
{
avg += f;
}
return avg / force.size();
}
int getAverageRadius()
{
int avg = 0;
for(Integer r: radius)
{
avg += r;
}
return avg / radius.size();
}
}
static void showTouchPressureMeasurementTool(final MainActivity p)
{
if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickUsesPressure )
{
p.setText(p.getResources().getString(R.string.measurepressure_touchplease));
p._touchMeasurementTool = new TouchMeasurementTool(p);
}
else
{
Save(p);
p.startDownloader();
}
}
static void Apply(Activity p)
{

View File

@@ -61,10 +61,15 @@
<string name="rightclick_question">Right mouse click triggered by:</string>
<string name="rightclick_menu">Menu key</string>
<string name="rightclick_multitouch">Touching screen with second finger (device should support that)</string>
<string name="rightclick_pressure">Pressing screen with force (device should support that)</string>
<string name="rightclick_multitouch">Touch screen with second finger</string>
<string name="rightclick_pressure">Touch screen with force</string>
<string name="rightclick_question">Right mouse click triggered by:</string>
<string name="pointandclick_question">Advanced point-and-click features</string>
<string name="pointandclick_showcreenunderfinger">Show screen under finger in separate window</string>
<string name="pointandclick_usepressure">Left click triggered by touch force</string>
<string name="measurepressure_touchplease">Please slide finger across the screen for two seconds</string>
<string name="measurepressure_response">Pressure %03d radius %03d</string>
<string name="audiobuf_verysmall">Very small (fast devices, less lag)</string>
<string name="audiobuf_small">Small</string>

View File

@@ -1,5 +1,5 @@
# The application settings for Android libSDL port
AppSettingVersion=12
AppSettingVersion=14
LibSdlVersion=1.2
AppName="Pachi el marciano"
AppFullName=net.sourceforge.dragontech.pachi
@@ -10,7 +10,9 @@ SdlVideoResize=y
SdlVideoResizeKeepAspect=n
NeedDepthBuffer=n
AppUsesMouse=n
AppNeedsTwoButtonMouse=n
AppNeedsArrowKeys=y
AppNeedsTextInput=y
AppUsesJoystick=n
AppHandlesJoystickSensitivity=n
AppUsesMultitouch=n

View File

@@ -1,21 +1,23 @@
# The application settings for Android libSDL port
AppSettingVersion=12
AppSettingVersion=14
LibSdlVersion=1.2
AppName="ScummVM"
AppFullName=org.scummvm.sdl
ScreenOrientation=h
InhibitSuspend=n
AppDataDownloadUrl="Data files size is 3 Mb|https://sites.google.com/site/xpelyax/Home/scummvm-1.2.0-data-1.zip?attredirects=0&d=1^Lure of the Temptress (10 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Lure%20of%20the%20Temptress/lure-1.1.zip/download"
AppDataDownloadUrl="Data files size is 3.5 Mb|http://sourceforge.net/projects/libsdl-android/files/ScummVM/scummvm-1.2.0-data.zip/download^Lure of the Temptress (English, 10 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Lure%20of%20the%20Temptress/lure-1.1.zip/download^Lure of the Temptress (German, 10 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Lure%20of%20the%20Temptress/lure-de-1.1.zip/download^Lure of the Temptress (French, 10 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Lure%20of%20the%20Temptress/lure-fr-1.1.zip/download^Lure of the Temptress (Italian, 10 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Lure%20of%20the%20Temptress/lure-it-1.1.zip/download^Lure of the Temptress (Spanish, 10 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Lure%20of%20the%20Temptress/lure-es-1.1.zip/download^Beneath a Steel Sky (CD version, 70 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Beneath%20a%20Steel%20Sky/bass-cd-1.2.zip/download^Beneath a Steel Sky (floppy version, 10 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Beneath%20a%20Steel%20Sky/BASS-Floppy-1.3.zip/download^Flight of the Amazon Queen (23 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Flight%20of%20the%20Amazon%20Queen/FOTAQ_Floppy.zip/download^Flight of the Amazon Queen - voice addon (English, 35 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Flight%20of%20the%20Amazon%20Queen/FOTAQ_Talkie-1.1.zip/download^Flight of the Amazon Queen - voice addon (German, 80 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Flight%20of%20the%20Amazon%20Queen/FOTAQ_Ger_talkie-1.0.zip/download^Flight of the Amazon Queen - voice addon (Hebrew, 70 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Flight%20of%20the%20Amazon%20Queen/FOTAQ_Heb_talkie.zip/download^Drascula: The Vampire Strikes Back (35 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Drascula_%20The%20Vampire%20Strikes%20Back/drascula-1.0.zip/download^Drascula: The Vampire Strikes Back - translations addon (35 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Drascula_%20The%20Vampire%20Strikes%20Back/drascula-int-1.1.zip/download^Drascula: The Vampire Strikes Back - audio addon (40 Mb)|http://sourceforge.net/projects/scummvm/files/extras/Drascula_%20The%20Vampire%20Strikes%20Back/drascula-audio-2.0.zip/download"
SdlVideoResize=y
SdlVideoResizeKeepAspect=n
NeedDepthBuffer=n
AppUsesMouse=y
AppNeedsArrowKeys=y
AppNeedsTwoButtonMouse=y
AppNeedsArrowKeys=n
AppNeedsTextInput=n
AppUsesJoystick=n
AppHandlesJoystickSensitivity=n
AppUsesMultitouch=n
NonBlockingSwapBuffers=n
RedefinedKeys="SPACE RETURN LCTRL LALT SPACE"
RedefinedKeys="LALT F7 ESCAPE F11 ESCAPE F11 ESCAPE"
AppTouchscreenKeyboardKeysAmount=0
AppTouchscreenKeyboardKeysAmountAutoFire=0
MultiABI=n

View File

@@ -21,7 +21,7 @@ ln -sf libtremor.a $LOCAL_PATH/../../../obj/local/armeabi/libvorbisidec.a
ln -sf libflac.a $LOCAL_PATH/../../../obj/local/armeabi/libFLAC.a
if [ \! -f scummvm/config.mk ] ; then
../setEnvironment.sh sh -c "cd scummvm && env LIBS='-lflac -ltremor -logg -lmad -lz -lgcc' ./configure --host=androidsdl --enable-zlib --enable-tremor --enable-mad --enable-flac --enable-vkeybd --enable-verbose-build --disable-hq-scalers --disable-readline --disable-nasm --datadir=."
../setEnvironment.sh sh -c "cd scummvm && env LIBS='-lflac -ltremor -logg -lmad -lz -lgcc' ./configure --host=androidsdl --enable-zlib --enable-tremor --enable-mad --enable-flac --enable-vkeybd --enable-keymapper --enable-verbose-build --disable-hq-scalers --disable-readline --disable-nasm --datadir=."
fi
../setEnvironment.sh make -C scummvm -j2
cp -f scummvm/scummvm libapplication.so

View File

@@ -1 +1 @@
sc2
scummvm

View File

@@ -744,6 +744,10 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
rect.h = SDL_CurrentVideoSurface->h;
SDL_UpdateTexture((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &rect, SDL_CurrentVideoSurface->pixels, SDL_CurrentVideoSurface->pitch);
SDL_RenderCopy((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &rect, &rect);
if( SDL_ANDROID_ShowScreenUnderFinger )
{
SDL_RenderCopy((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &SDL_ANDROID_ShowScreenUnderFingerRectSrc, &SDL_ANDROID_ShowScreenUnderFingerRect);
}
}
SDL_ANDROID_CallJavaSwapBuffers();

View File

@@ -500,10 +500,10 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
data->texw = (GLfloat) texture->w / texture_w;
data->texh = (GLfloat) texture->h / texture_h;
if( renderer->info.max_texture_width < texture_w || renderer->info.max_texture_height < texture_h )
__android_log_print(ANDROID_LOG_WARNING, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than largest possible device texture %dx%d",
__android_log_print(ANDROID_LOG_WARN, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than largest possible device texture %dx%d",
texture_w, texture_h, renderer->info.max_texture_width, renderer->info.max_texture_height );
else if( texture_w > 1024 || texture_h > 1024 )
__android_log_print(ANDROID_LOG_WARNING, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than 1024x1024 - this code will not work on HTC G1", texture_w, texture_h );
__android_log_print(ANDROID_LOG_WARN, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than 1024x1024 - this code will not work on HTC G1", texture_w, texture_h );
data->format = format;
data->formattype = type;

View File

@@ -46,9 +46,10 @@ SDLKey SDL_android_keymap[KEYCODE_LAST+1];
static int isTrackballUsed = 0;
static int isMouseUsed = 0;
enum { RIGHT_CLICK_WITH_MENU_BUTTON = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2 };
static int rightClickMethod = RIGHT_CLICK_WITH_MENU_BUTTON;
static int showScreenUnderFinger = 0;
enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MENU_BUTTON = 1, RIGHT_CLICK_WITH_MULTITOUCH = 2, RIGHT_CLICK_WITH_PRESSURE = 3 };
static int rightClickMethod = RIGHT_CLICK_NONE;
int SDL_ANDROID_ShowScreenUnderFinger = 0;
SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect = {0, 0, 0, 0}, SDL_ANDROID_ShowScreenUnderFingerRectSrc = {0, 0, 0, 0};
static int leftClickUsesPressure = 0;
static int maxForce = 0;
static int maxRadius = 0;
@@ -58,6 +59,58 @@ SDL_Joystick *SDL_ANDROID_CurrentJoysticks[MAX_MULTITOUCH_POINTERS+1] = {NULL};
static int TrackballDampening = 0; // in milliseconds
static int lastTrackballAction = 0;
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 );
}
void UpdateScreenUnderFingerRect(int x, int y)
{
int screenX = 320, screenY = 240;
if( !SDL_ANDROID_ShowScreenUnderFinger )
return;
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_Window * window = SDL_GetFocusWindow();
if( window && window->renderer->window ) {
screenX = window->w;
screenY = window->h;
}
#else
screenX = SDL_ANDROID_sFakeWindowWidth;
screenY = SDL_ANDROID_sFakeWindowHeight;
#endif
SDL_ANDROID_ShowScreenUnderFingerRectSrc.w = screenX / 4;
SDL_ANDROID_ShowScreenUnderFingerRectSrc.h = screenY / 4;
SDL_ANDROID_ShowScreenUnderFingerRectSrc.x = x - SDL_ANDROID_ShowScreenUnderFingerRectSrc.w/2;
SDL_ANDROID_ShowScreenUnderFingerRectSrc.y = y - SDL_ANDROID_ShowScreenUnderFingerRectSrc.h/2;
if( SDL_ANDROID_ShowScreenUnderFingerRectSrc.x < 0 )
SDL_ANDROID_ShowScreenUnderFingerRectSrc.x = 0;
if( SDL_ANDROID_ShowScreenUnderFingerRectSrc.y < 0 )
SDL_ANDROID_ShowScreenUnderFingerRectSrc.y = 0;
if( SDL_ANDROID_ShowScreenUnderFingerRectSrc.x > screenX - SDL_ANDROID_ShowScreenUnderFingerRectSrc.w )
SDL_ANDROID_ShowScreenUnderFingerRectSrc.x = screenX - SDL_ANDROID_ShowScreenUnderFingerRectSrc.w;
if( SDL_ANDROID_ShowScreenUnderFingerRectSrc.y > screenY - SDL_ANDROID_ShowScreenUnderFingerRectSrc.h )
SDL_ANDROID_ShowScreenUnderFingerRectSrc.y = screenY - SDL_ANDROID_ShowScreenUnderFingerRectSrc.h;
SDL_ANDROID_ShowScreenUnderFingerRect.w = SDL_ANDROID_ShowScreenUnderFingerRectSrc.w * 3 / 2;
SDL_ANDROID_ShowScreenUnderFingerRect.h = SDL_ANDROID_ShowScreenUnderFingerRectSrc.h * 3 / 2;
SDL_ANDROID_ShowScreenUnderFingerRect.x = x + SDL_ANDROID_ShowScreenUnderFingerRect.w/10;
SDL_ANDROID_ShowScreenUnderFingerRect.y = y - SDL_ANDROID_ShowScreenUnderFingerRect.h*11/10;
if( SDL_ANDROID_ShowScreenUnderFingerRect.x < 0 )
SDL_ANDROID_ShowScreenUnderFingerRect.x = 0;
if( SDL_ANDROID_ShowScreenUnderFingerRect.y < 0 )
SDL_ANDROID_ShowScreenUnderFingerRect.y = 0;
if( SDL_ANDROID_ShowScreenUnderFingerRect.x + SDL_ANDROID_ShowScreenUnderFingerRect.w > screenX )
SDL_ANDROID_ShowScreenUnderFingerRect.x = screenX - SDL_ANDROID_ShowScreenUnderFingerRect.w;
if( SDL_ANDROID_ShowScreenUnderFingerRect.y + SDL_ANDROID_ShowScreenUnderFingerRect.h > screenY )
SDL_ANDROID_ShowScreenUnderFingerRect.y = screenY - SDL_ANDROID_ShowScreenUnderFingerRect.h;
if( InsideRect(&SDL_ANDROID_ShowScreenUnderFingerRect, x, y) )
SDL_ANDROID_ShowScreenUnderFingerRect.x = x - SDL_ANDROID_ShowScreenUnderFingerRect.w*11/10;
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId, jint force, jint radius )
{
@@ -119,22 +172,51 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j
if( !isMouseUsed )
return;
if( action == MOUSE_DOWN || action == MOUSE_UP )
if( pointerId == 0 )
{
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SendMouseMotion(NULL, 0, x, y);
SDL_SendMouseButton(NULL, (action == MOUSE_DOWN) ? SDL_PRESSED : SDL_RELEASED, 1 );
#else
SDL_PrivateMouseMotion(0, 0, x, y);
SDL_PrivateMouseButton( (action == MOUSE_DOWN) ? SDL_PRESSED : SDL_RELEASED, 1, x, y );
#define SDL_SendMouseButton(N, A, B) SDL_PrivateMouseButton( A, B, 0, 0 )
#endif
if( action == MOUSE_UP )
{
if( SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_LEFT) )
SDL_SendMouseButton( NULL, SDL_RELEASED, SDL_BUTTON_LEFT );
if( SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_RIGHT) )
SDL_SendMouseButton( NULL, SDL_RELEASED, SDL_BUTTON_RIGHT );
SDL_ANDROID_ShowScreenUnderFingerRect.w = SDL_ANDROID_ShowScreenUnderFingerRect.h = 0;
SDL_ANDROID_ShowScreenUnderFingerRectSrc.w = SDL_ANDROID_ShowScreenUnderFingerRectSrc.h = 0;
}
if( action == MOUSE_DOWN )
{
if( !leftClickUsesPressure )
SDL_SendMouseButton( NULL, (action == MOUSE_DOWN) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT );
else
action == MOUSE_MOVE;
UpdateScreenUnderFingerRect(x, y);
}
if( action == MOUSE_MOVE )
{
if( rightClickMethod == RIGHT_CLICK_WITH_PRESSURE || leftClickUsesPressure )
{
int button = leftClickUsesPressure ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT;
int buttonState = ( force > maxForce || radius > maxRadius );
if( button == SDL_BUTTON_RIGHT && (SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_LEFT)) )
SDL_SendMouseButton( NULL, SDL_RELEASED, SDL_BUTTON_LEFT );
if( ( (SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(button)) != 0 ) != buttonState )
SDL_SendMouseButton( NULL, buttonState ? SDL_PRESSED : SDL_RELEASED, button );
}
UpdateScreenUnderFingerRect(x, y);
}
}
if( pointerId == 1 && rightClickMethod == RIGHT_CLICK_WITH_MULTITOUCH && (action == MOUSE_DOWN || action == MOUSE_UP) )
{
if( SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_LEFT) )
SDL_SendMouseButton( NULL, SDL_RELEASED, SDL_BUTTON_LEFT );
SDL_SendMouseButton( NULL, (action == MOUSE_DOWN) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT );
}
if( action == MOUSE_MOVE )
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SendMouseMotion(NULL, 0, x, y);
#else
SDL_PrivateMouseMotion(0, 0, x, y);
#endif
}
static int processAndroidTrackball(int key, int action);
@@ -145,6 +227,11 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint
if( isTrackballUsed )
if( processAndroidTrackball(key, action) )
return;
if( key == KEYCODE_MENU && rightClickMethod == RIGHT_CLICK_WITH_MENU_BUTTON )
{
SDL_SendMouseButton( NULL, action ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT );
return;
}
SDL_keysym keysym;
SDL_SendKeyboardKey( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key ,&keysym) );
}
@@ -209,7 +296,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz, jint
{
isMouseUsed = 1;
rightClickMethod = RightClickMethod;
showScreenUnderFinger = ShowScreenUnderFinger;
SDL_ANDROID_ShowScreenUnderFinger = ShowScreenUnderFinger;
leftClickUsesPressure = LeftClickUsesPressure;
maxForce = MaxForce;
maxRadius = MaxRadius;

View File

@@ -31,6 +31,8 @@ extern int SDL_ANDROID_sWindowWidth;
extern int SDL_ANDROID_sWindowHeight;
extern int SDL_ANDROID_sFakeWindowWidth; // SDL 1.2 only
extern int SDL_ANDROID_sFakeWindowHeight; // SDL 1.2 only
extern int SDL_ANDROID_ShowScreenUnderFinger;
extern SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect, SDL_ANDROID_ShowScreenUnderFingerRectSrc;
extern int SDL_ANDROID_CallJavaSwapBuffers();
extern void SDL_ANDROID_CallJavaShowScreenKeyboard();
extern int SDL_ANDROID_drawTouchscreenKeyboard();