src/video/android/SDL_androidwindow.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 10 May 2013 21:08:37 +0200
changeset 7163 55eb3d3135eb
parent 7037 3fedf1f25b94
child 7191 75360622e65f
permissions -rw-r--r--
Fixed implicit function declaration warnings.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6654
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#if SDL_VIDEO_DRIVER_ANDROID
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    24
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "../SDL_sysvideo.h"
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_androidvideo.h"
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_androidwindow.h"
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
7163
55eb3d3135eb Fixed implicit function declaration warnings.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
    30
#include "../../core/android/SDL_android.h"
55eb3d3135eb Fixed implicit function declaration warnings.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
    31
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
int
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
Android_CreateWindow(_THIS, SDL_Window * window)
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
{
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    35
    if (Android_Window) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
    36
        return SDL_SetError("Android only supports one window");
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    37
    }
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    38
    Android_Window = window;
6330
0fa55ca2efdd Fixes #1422, restores GL context automatically under Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6262
diff changeset
    39
    Android_PauseSem = SDL_CreateSemaphore(0);
0fa55ca2efdd Fixes #1422, restores GL context automatically under Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6262
diff changeset
    40
    Android_ResumeSem = SDL_CreateSemaphore(0);
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    41
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
    /* Adjust the window data to match the screen */
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
    window->x = 0;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
    window->y = 0;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
    window->w = Android_ScreenWidth;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
    window->h = Android_ScreenHeight;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
5222
c66b2a778b7e Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents: 5001
diff changeset
    48
    window->flags &= ~SDL_WINDOW_RESIZABLE;     /* window is NEVER resizeable */
c66b2a778b7e Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents: 5001
diff changeset
    49
    window->flags |= SDL_WINDOW_FULLSCREEN;     /* window is always fullscreen */
6262
47d6b41996e4 Fixed setting the window visibility on iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    50
    window->flags &= ~SDL_WINDOW_HIDDEN;
5222
c66b2a778b7e Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents: 5001
diff changeset
    51
    window->flags |= SDL_WINDOW_SHOWN;          /* only one window on Android */
c66b2a778b7e Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents: 5001
diff changeset
    52
    window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */    
c66b2a778b7e Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents: 5001
diff changeset
    53
6651
17ef8a7cab55 Added mouse emulation for touch events on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6330
diff changeset
    54
    /* One window, it always has focus */
17ef8a7cab55 Added mouse emulation for touch events on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6330
diff changeset
    55
    SDL_SetMouseFocus(window);
6654
2ecfb25be1e2 Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents: 6651
diff changeset
    56
    SDL_SetKeyboardFocus(window);
6651
17ef8a7cab55 Added mouse emulation for touch events on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6330
diff changeset
    57
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    return 0;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
}
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
void
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
Android_SetWindowTitle(_THIS, SDL_Window * window)
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
{
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    Android_JNI_SetActivityTitle(window->title);
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
}
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
void
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
Android_DestroyWindow(_THIS, SDL_Window * window)
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
{
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    70
    if (window == Android_Window) {
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    71
        Android_Window = NULL;
6330
0fa55ca2efdd Fixes #1422, restores GL context automatically under Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6262
diff changeset
    72
        if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem);
0fa55ca2efdd Fixes #1422, restores GL context automatically under Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6262
diff changeset
    73
        if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem);
0fa55ca2efdd Fixes #1422, restores GL context automatically under Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6262
diff changeset
    74
        Android_PauseSem = NULL;
0fa55ca2efdd Fixes #1422, restores GL context automatically under Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6262
diff changeset
    75
        Android_ResumeSem = NULL;
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    76
    }
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
}
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    79
#endif /* SDL_VIDEO_DRIVER_ANDROID */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    80
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
/* vi: set ts=4 sw=4 expandtab: */