src/video/uikit/SDL_uikitevents.m
author Sam Lantinga <slouken@libsdl.org>
Wed, 05 Jun 2013 21:48:53 -0700
changeset 7285 bcfd0bcaf4f3
parent 7284 ac3f4830ae25
child 8093 b43765095a6f
permissions -rw-r--r--
Fixed compile errors on iOS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
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: 6857
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
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.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
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:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
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.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
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: 6003
diff changeset
    23
#if SDL_VIDEO_DRIVER_UIKIT
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6003
diff changeset
    24
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "../../events/SDL_events_c.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_uikitvideo.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_uikitevents.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#import <Foundation/Foundation.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
6346
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    32
static BOOL UIKit_EventPumpEnabled = YES;
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    33
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    34
void
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    35
SDL_iPhoneSetEventPump(SDL_bool enabled)
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    36
{
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    37
    UIKit_EventPumpEnabled = enabled;
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    38
}
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    39
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
UIKit_PumpEvents(_THIS)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
{
6346
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    43
    if (!UIKit_EventPumpEnabled)
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    44
        return;
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    45
7284
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    46
    /* Let the run loop run for a short amount of time: long enough for
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    47
       touch events to get processed (which is important to get certain
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    48
       elements of Game Center's GKLeaderboardViewController to respond
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    49
       to touch input), but not long enough to introduce a significant
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    50
       delay in the rest of the app.
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    51
    */
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    52
    const CFTimeInterval seconds = 0.000002;
6857
dd4c12f0358b converted tabs to spaces in iOS/UIKit PumpEvents code
DavidLudwig <dludwig@pobox.com>
parents: 6685
diff changeset
    53
7284
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    54
    /* Pump most event types. */
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    55
    SInt32 result;
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    56
    do {
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    57
        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, seconds, TRUE);
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    58
    } while (result == kCFRunLoopRunHandledSource);
6857
dd4c12f0358b converted tabs to spaces in iOS/UIKit PumpEvents code
DavidLudwig <dludwig@pobox.com>
parents: 6685
diff changeset
    59
7284
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    60
    /* Make sure UIScrollView objects scroll properly. */
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    61
    do {
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    62
        result = CFRunLoopRunInMode((CFStringRef)UITrackingRunLoopMode, seconds, TRUE);
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    63
    } while(result == kCFRunLoopRunHandledSource);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6003
diff changeset
    66
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6003
diff changeset
    67
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
/* vi: set ts=4 sw=4 expandtab: */