build-scripts/androidbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 17 Aug 2014 14:57:52 -0700
changeset 9086 c5e33f9a0d03
parent 7974 8af2b2344e9e
child 9823 9fb8a612dd7c
permissions -rwxr-xr-x
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different

Tim McDaniel

On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.

I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.

If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
gabomdq@7793
     1
#!/bin/bash
gabomdq@7793
     2
gabomdq@7793
     3
SOURCES=()
gabomdq@7793
     4
MKSOURCES=""
gabomdq@7793
     5
CURDIR=`pwd -P`
gabomdq@7793
     6
gabomdq@7793
     7
# Fetch sources
gabomdq@7793
     8
if [[ $# -ge 2 ]]; then
gabomdq@7793
     9
    for src in ${@:2}
gabomdq@7793
    10
    do
gabomdq@7793
    11
        SOURCES+=($src)
gabomdq@7793
    12
        MKSOURCES="$MKSOURCES $(basename $src)"
gabomdq@7793
    13
    done
gabomdq@7793
    14
else
gabomdq@7793
    15
    if [ -n "$1" ]; then
gabomdq@7793
    16
        while read src
gabomdq@7793
    17
        do
gabomdq@7793
    18
            SOURCES+=($src)
gabomdq@7793
    19
            MKSOURCES="$MKSOURCES $(basename $src)"
gabomdq@7793
    20
        done
gabomdq@7793
    21
    fi
gabomdq@7793
    22
fi
gabomdq@7793
    23
gabomdq@7793
    24
if [ -z "$1" ] || [ -z "$SOURCES" ]; then
gabomdq@7793
    25
    echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
gabomdq@7793
    26
    echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
gabomdq@7907
    27
    echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... "
gabomdq@7974
    28
    echo "You can pass additional arguments to ndk-build with the NDKARGS variable: NDKARGS=\"-s\" androidbuild.sh ..."
gabomdq@7793
    29
    exit 1
gabomdq@7793
    30
fi
gabomdq@7793
    31
gabomdq@7793
    32
gabomdq@7793
    33
gabomdq@7793
    34
SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
gabomdq@7793
    35
gabomdq@7793
    36
NDKBUILD=`which ndk-build`
gabomdq@7793
    37
if [ -z "$NDKBUILD" ];then
gabomdq@7793
    38
    echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
gabomdq@7793
    39
    exit 1
gabomdq@7793
    40
fi
gabomdq@7793
    41
gabomdq@7793
    42
ANDROID=`which android`
gabomdq@7793
    43
if [ -z "$ANDROID" ];then
gabomdq@7793
    44
    echo "Could not find the android utility, install Android's SDK and add it to the path"
gabomdq@7793
    45
    exit 1
gabomdq@7793
    46
fi
gabomdq@7793
    47
gabomdq@7793
    48
ANT=`which ant`
gabomdq@7793
    49
gabomdq@7793
    50
if [ -z "$ANT" ];then
gabomdq@7793
    51
    echo "Could not find the ant utility, install Android's SDK and add it to the path"
gabomdq@7793
    52
    exit 1
gabomdq@7793
    53
fi
gabomdq@7793
    54
gabomdq@7974
    55
NCPUS="1"
gabomdq@7974
    56
case "$OSTYPE" in
gabomdq@7974
    57
    darwin*)
gabomdq@7974
    58
        NCPU=`sysctl -n hw.ncpu`
gabomdq@7974
    59
        ;; 
gabomdq@7974
    60
    linux*)
gabomdq@7974
    61
        if [ -n `which nproc` ]; then
gabomdq@7974
    62
            NCPUS=`nproc`
gabomdq@7974
    63
        fi  
gabomdq@7974
    64
        ;;
gabomdq@7974
    65
  *);;
gabomdq@7974
    66
esac
gabomdq@7974
    67
gabomdq@7793
    68
APP="$1"
gabomdq@7793
    69
APPARR=(${APP//./ })
gabomdq@7793
    70
BUILDPATH="$SDLPATH/build/$APP"
gabomdq@7793
    71
gabomdq@7793
    72
# Start Building
gabomdq@7793
    73
gabomdq@7793
    74
rm -rf $BUILDPATH
gabomdq@7793
    75
mkdir -p $BUILDPATH
gabomdq@7793
    76
gabomdq@7793
    77
cp -r $SDLPATH/android-project/* $BUILDPATH
gabomdq@7793
    78
gabomdq@7793
    79
# Copy SDL sources
gabomdq@7793
    80
mkdir -p $BUILDPATH/jni/SDL
gabomdq@7907
    81
if [ -z "$COPYSOURCE" ]; then
gabomdq@7907
    82
    ln -s $SDLPATH/src $BUILDPATH/jni/SDL
gabomdq@7907
    83
    ln -s $SDLPATH/include $BUILDPATH/jni/SDL
gabomdq@7907
    84
else
gabomdq@7907
    85
    cp -r $SDLPATH/src $BUILDPATH/jni/SDL
gabomdq@7907
    86
    cp -r $SDLPATH/include $BUILDPATH/jni/SDL
gabomdq@7907
    87
fi
gabomdq@7907
    88
gabomdq@7907
    89
cp -r $SDLPATH/Android.mk $BUILDPATH/jni/SDL
gabomdq@7793
    90
sed -i "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
gabomdq@7793
    91
sed -i "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
gabomdq@7793
    92
gabomdq@7793
    93
# Copy user sources
gabomdq@7793
    94
for src in "${SOURCES[@]}"
gabomdq@7793
    95
do
gabomdq@7793
    96
    cp $src $BUILDPATH/jni/src
gabomdq@7793
    97
done
gabomdq@7793
    98
gabomdq@7793
    99
# Create an inherited Activity
gabomdq@7793
   100
cd $BUILDPATH/src
gabomdq@7793
   101
for folder in "${APPARR[@]}"
gabomdq@7793
   102
do
gabomdq@7793
   103
    mkdir -p $folder
gabomdq@7793
   104
    cd $folder
gabomdq@7793
   105
done
gabomdq@7793
   106
gabomdq@7793
   107
ACTIVITY="${folder}Activity"
gabomdq@7793
   108
sed -i "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
gabomdq@7793
   109
sed -i "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
gabomdq@7793
   110
gabomdq@7793
   111
# Fill in a default Activity
gabomdq@7793
   112
echo "package $APP;" >  "$ACTIVITY.java"
gabomdq@7793
   113
echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
gabomdq@7793
   114
echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
gabomdq@7793
   115
gabomdq@7793
   116
# Update project and build
gabomdq@7793
   117
cd $BUILDPATH
gabomdq@7793
   118
android update project --path $BUILDPATH
gabomdq@7974
   119
$NDKBUILD -j $NCPUS $NDKARGS
gabomdq@7793
   120
$ANT debug
gabomdq@7793
   121
gabomdq@7793
   122
cd $CURDIR
gabomdq@7793
   123
gabomdq@7793
   124
APK="$BUILDPATH/bin/$APP-debug.apk"
gabomdq@7793
   125
gabomdq@7793
   126
if [ -f "$APK" ]; then
gabomdq@7793
   127
    echo "Your APK is ready at $APK"
gabomdq@7793
   128
    echo "To install to your device: "
gabomdq@7793
   129
    echo "cd  $BUILDPATH"
gabomdq@7793
   130
    echo "ant debug install"
gabomdq@7793
   131
    exit 0
gabomdq@7793
   132
fi
gabomdq@7793
   133
gabomdq@7793
   134
echo "There was an error building the APK"
gabomdq@7793
   135
exit 1