Added system mouse cursor support

This commit is contained in:
pelya
2011-10-31 14:49:07 +03:00
parent e583e21999
commit 585ac4140e
19 changed files with 932 additions and 784 deletions

View File

@@ -224,6 +224,16 @@ if [ -n "$var" ] ; then
fi
fi
if [ -z "$ShowMouseCursor" -o -z "$AUTO" ]; then
echo
echo -n "Show SDL mouse cursor, for applicaitons that do not draw it (y) or (n) ($ShowMouseCursor): "
read var
if [ -n "$var" ] ; then
ShowMouseCursor="$var"
CHANGED=1
fi
fi
if [ -z "$AppNeedsArrowKeys" -o -z "$AUTO" ]; then
echo
echo "Application needs arrow keys (y) or (n), if (y) the accelerometer or touchscreen keyboard"
@@ -536,6 +546,7 @@ echo SdlVideoResizeKeepAspect=$SdlVideoResizeKeepAspect >> AndroidAppSettings.cf
echo CompatibilityHacks=$CompatibilityHacks >> AndroidAppSettings.cfg
echo AppUsesMouse=$AppUsesMouse >> AndroidAppSettings.cfg
echo AppNeedsTwoButtonMouse=$AppNeedsTwoButtonMouse >> AndroidAppSettings.cfg
echo ShowMouseCursor=$ShowMouseCursor >> AndroidAppSettings.cfg
echo ForceRelativeMouseMode=$ForceRelativeMouseMode >> AndroidAppSettings.cfg
echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg
echo AppNeedsTextInput=$AppNeedsTextInput >> AndroidAppSettings.cfg
@@ -647,6 +658,12 @@ else
ForceRelativeMouseMode=false
fi
if [ "$ShowMouseCursor" = "y" ] ; then
ShowMouseCursor=true
else
ShowMouseCursor=false
fi
if [ "$AppNeedsArrowKeys" = "y" ] ; then
AppNeedsArrowKeys=true
else
@@ -761,6 +778,7 @@ cat project/src/Globals.java | \
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 ForceRelativeMouseMode = .*;/public static boolean ForceRelativeMouseMode = $ForceRelativeMouseMode;/" | \
sed "s/public static boolean ShowMouseCursor = .*;/public static boolean ShowMouseCursor = $ShowMouseCursor;/" | \
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

@@ -45,6 +45,7 @@ class Globals {
public static boolean AppUsesMouse = false;
public static boolean AppNeedsTwoButtonMouse = false;
public static boolean ForceRelativeMouseMode = false; // If both on-screen keyboard and mouse are needed, this will only set the default setting, user may override it later
public static boolean ShowMouseCursor = false;
public static boolean AppNeedsArrowKeys = true;
public static boolean AppNeedsTextInput = true;
public static boolean AppUsesJoystick = false;

View File

@@ -2385,7 +2385,8 @@ class Settings
Globals.RightClickTimeout,
Globals.RelativeMouseMovement ? 1 : 0,
Globals.RelativeMouseMovementSpeed,
Globals.RelativeMouseMovementAccel );
Globals.RelativeMouseMovementAccel,
Globals.ShowMouseCursor ? 1 : 0 );
if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) )
nativeSetJoystickUsed();
if( Globals.AppUsesMultitouch )
@@ -2484,7 +2485,8 @@ class Settings
int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel,
int leftClickKeycode, int rightClickKeycode,
int leftClickTimeout, int rightClickTimeout,
int relativeMovement, int relativeMovementSpeed, int relativeMovementAccel);
int relativeMovement, int relativeMovementSpeed,
int relativeMovementAccel, int showMouseCursor);
private static native void nativeSetJoystickUsed();
private static native void nativeSetMultitouchUsed();
private static native void nativeSetTouchscreenKeyboardUsed();

View File

@@ -6,15 +6,20 @@ AppFullName=org.milkytracker.sdl
ScreenOrientation=h
InhibitSuspend=y
AppDataDownloadUrl="!Example songs|MilkyTracker-ExampleSongs.zip"
VideoDepthBpp=16
NeedDepthBuffer=n
NeedStencilBuffer=n
NeedGles2=n
SwVideoMode=y
SdlVideoResize=y
SdlVideoResizeKeepAspect=n
NeedDepthBuffer=n
SwVideoMode=y
CompatibilityHacks=y
AppUsesMouse=y
AppNeedsTwoButtonMouse=y
ShowMouseCursor=y
ForceRelativeMouseMode=n
AppNeedsArrowKeys=n
AppNeedsTextInput=n
AppNeedsTextInput=y
AppUsesJoystick=n
AppHandlesJoystickSensitivity=y
AppUsesMultitouch=n
@@ -25,10 +30,10 @@ AppTouchscreenKeyboardKeysAmountAutoFire=0
RedefinedKeysScreenKb="SPACE TAB PLUS MINUS RETURN ESCAPE DELETE"
StartupMenuButtonTimeout=3000
HiddenMenuOptions='OptionalDownloadConfig'
FirstStartMenuOptions='new Settings.CalibrateTouchscreenMenu()'
FirstStartMenuOptions='new Settings.CalibrateTouchscreenMenu(), new Settings.DisplaySizeConfig(true)'
MultiABI=n
AppVersionCode=0908502
AppVersionName="0.90.85.02"
AppVersionCode=0908503
AppVersionName="0.90.85.03"
CompiledLibraries="jpeg png"
CustomBuildScript=y
AppCflags=''

View File

@@ -1 +1 @@
openttd
milkytracker

View File

@@ -855,6 +855,17 @@ static void ANDROID_FlipHWSurfaceInternal()
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);
static int MousePointerAlpha = 255;
if(SDL_ANDROID_ShowMouseCursor)
{
int x, y;
SDL_GetMouseState(&x, &y);
x = x * SDL_ANDROID_sRealWindowWidth / SDL_ANDROID_sFakeWindowWidth;
y = y * SDL_ANDROID_sRealWindowHeight / SDL_ANDROID_sFakeWindowHeight;
SDL_ANDROID_DrawMouseCursor( x, y, 0, MousePointerAlpha );
if( MousePointerAlpha > 64 )
MousePointerAlpha -= 10 ;
}
if( SDL_ANDROID_ShowScreenUnderFinger && SDL_ANDROID_ShowScreenUnderFingerRect.w > 0 )
{
SDL_RenderCopy((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &SDL_ANDROID_ShowScreenUnderFingerRectSrc, &SDL_ANDROID_ShowScreenUnderFingerRect);
@@ -883,7 +894,22 @@ static void ANDROID_FlipHWSurfaceInternal()
glDrawArrays(GL_LINE_LOOP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
glFlush();
if(SDL_ANDROID_ShowMouseCursor)
{
MousePointerAlpha = 255;
int x, y;
SDL_GetMouseState(&x, &y);
x = SDL_ANDROID_ShowScreenUnderFingerRect.x +
( x - SDL_ANDROID_ShowScreenUnderFingerRectSrc.x ) *
SDL_ANDROID_ShowScreenUnderFingerRect.w / SDL_ANDROID_ShowScreenUnderFingerRectSrc.w;
y = SDL_ANDROID_ShowScreenUnderFingerRect.y +
( y - SDL_ANDROID_ShowScreenUnderFingerRectSrc.y ) *
SDL_ANDROID_ShowScreenUnderFingerRect.h / SDL_ANDROID_ShowScreenUnderFingerRectSrc.h;
x = x * SDL_ANDROID_sRealWindowWidth / SDL_ANDROID_sFakeWindowWidth;
y = y * SDL_ANDROID_sRealWindowHeight / SDL_ANDROID_sFakeWindowHeight;
SDL_ANDROID_DrawMouseCursor( x, y, 16, 255 );
}
//glFlush();
}
}
};
@@ -1053,7 +1079,7 @@ void SDL_ANDROID_MultiThreadedVideoLoop()
SDL_mutexP(videoThread.mutex);
videoThread.threadReady = 1;
SDL_CondSignal(videoThread.cond2);
ret = SDL_CondWaitTimeout(videoThread.cond, videoThread.mutex, SDL_ANDROID_CompatibilityHacks ? 400 : 1000);
ret = SDL_CondWaitTimeout(videoThread.cond, videoThread.mutex, SDL_ANDROID_CompatibilityHacks ? 100 : 1000);
if( videoThread.execute )
{
videoThread.threadReady = 0;

View File

@@ -37,7 +37,7 @@
#define SDL_VIDEO_RENDER_OGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES_GL_CONTEXT_LOSING_IMMUNE 1
/* SDL uses some OpenGL textures for drawing in-screen keyboard, so application should allocate OpenGL texture ID-s starting from this value */
#define SDL_GL_FIRST_SAFE_TEXTURE_ID 25
#define SDL_GL_FIRST_SAFE_TEXTURE_ID 26
#define SDL_AUDIO_DRIVER_ANDROID 1

View File

@@ -789,7 +789,8 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz,
jint MoveMouseWithJoystickSpeed, jint MoveMouseWithJoystickAccel,
jint LeftClickKeycode, jint RightClickKeycode,
jint LeftClickTimeout, jint RightClickTimeout,
jint RelativeMovement, jint RelativeMovementSpeed, jint RelativeMovementAccel)
jint RelativeMovement, jint RelativeMovementSpeed, jint RelativeMovementAccel,
jint ShowMouseCursor)
{
isMouseUsed = 1;
rightClickMethod = RightClickMethod;
@@ -808,6 +809,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz,
relativeMovement = RelativeMovement;
relativeMovementSpeed = RelativeMovementSpeed;
relativeMovementAccel = RelativeMovementAccel;
SDL_ANDROID_ShowMouseCursor = ShowMouseCursor;
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "relativeMovementSpeed %d relativeMovementAccel %d", relativeMovementSpeed, relativeMovementAccel);
}

View File

@@ -71,7 +71,7 @@ int SDL_ANDROID_CompatibilityHacks = 0;
int SDL_ANDROID_BYTESPERPIXEL = 2;
int SDL_ANDROID_BITSPERPIXEL = 16;
int SDL_ANDROID_UseGles2 = 0;
int SDL_ANDROID_ShowMouseCursor = 0;
static void appPutToBackgroundCallbackDefault(void)
{

View File

@@ -41,6 +41,7 @@ extern int SDL_ANDROID_TouchscreenCalibrationY;
extern int SDL_ANDROID_SmoothVideo;
extern int SDL_ANDROID_VideoMultithreaded;
extern int SDL_ANDROID_CompatibilityHacks;
extern int SDL_ANDROID_ShowMouseCursor;
extern int SDL_ANDROID_UseGles2;
extern int SDL_ANDROID_BYTESPERPIXEL;
extern int SDL_ANDROID_BITSPERPIXEL;
@@ -62,6 +63,9 @@ extern void SDL_ANDROID_initFakeStdout();
extern SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex);
extern void SDL_ANDROID_ProcessDeferredEvents();
extern void SDL_ANDROID_WarpMouse(int x, int y);
extern void SDL_ANDROID_DrawMouseCursor(int x, int y, int size, int alpha);
extern void SDL_ANDROID_DrawMouseCursorIfNeeded();
#if SDL_VERSION_ATLEAST(1,3,0)
extern SDL_Window * ANDROID_CurrentWindow;

View File

@@ -87,7 +87,8 @@ typedef struct
static GLTexture_t arrowImages[5] = { {0, 0, 0}, };
static GLTexture_t buttonAutoFireImages[MAX_BUTTONS_AUTOFIRE*2] = { {0, 0, 0}, };
static GLTexture_t buttonImages[MAX_BUTTONS*2] = { {0, 0, 0}, };
static GLTexture_t mousePointer;
enum { MOUSE_POINTER_W = 32, MOUSE_POINTER_H = 32, MOUSE_POINTER_X = 5, MOUSE_POINTER_Y = 7 }; // X and Y are offsets of the pointer tip
static inline int InsideRect(const SDL_Rect * r, int x, int y)
{
@@ -643,13 +644,25 @@ JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thi
}
};
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenKeyboardUsed) ( JNIEnv* env, jobject thiz)
{
SDL_ANDROID_isTouchscreenKeyboardUsed = 1;
}
void SDL_ANDROID_DrawMouseCursor(int x, int y, int size, int alpha)
{
SDL_Rect r;
// I've failed with size calcualtions, so leaving it as-is
r.x = x - MOUSE_POINTER_X;
r.y = y - MOUSE_POINTER_Y;
r.w = MOUSE_POINTER_W;
r.h = MOUSE_POINTER_H;
beginDrawingTex();
drawCharTex( &mousePointer, NULL, &r, 255, 255, 255, alpha );
endDrawingTex();
}
static int
power_of_2(int input)
{
@@ -676,7 +689,9 @@ static int setupScreenKeyboardButton( int buttonID, Uint8 * charBuf )
else
data = &(buttonImages[buttonID-9]);
if( buttonID > 22 ) // Error, array too big
if( buttonID == 23 )
data = &mousePointer;
else if( buttonID > 22 ) // Error, array too big
return 12; // Return value bigger than zero to iterate it
memcpy(&w, charBuf, sizeof(int));

View File

@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-12

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -35,6 +35,7 @@ button6 \
button6pressed \
button7 \
button7 \
mouse_pointer \
; do
if [ \! -e ../../res/raw/ultimatedroid$F.png.raw ]; then
echo Cannot find ../../res/raw/ultimatedroid$F.png.raw - check if all files are in place
@@ -89,6 +90,7 @@ dpad_down \
6pressed \
keyboard \
keyboard \
mouse_pointer \
; do
if [ \! -e ../../res/raw/simpletheme$F.png.raw ]; then
echo Cannot find ../../res/raw/simpletheme$F.png.raw - check if all files are in place

File diff suppressed because it is too large Load Diff

View File

@@ -23,7 +23,7 @@ How to compile demo application
===============================
Launch commands
android update project -p project
android update project -p project -t android-12
rm project/jni/application/src
ln -s ballfield project/jni/application/src
ChangeAppSettings.sh -a