src/core/winrt/SDL_winrtapp_direct3d.cpp
author David Ludwig <dludwig@pobox.com>
Sun, 23 Mar 2014 11:04:47 -0400
changeset 8666 20d52dc1a24a
parent 8665 b987c561c218
child 8678 7149b02f106b
permissions -rw-r--r--
WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions SDL_WINDOWEVENT_FOCUS_LOST is now sent when an app's native window is hidden. Likewise, SDL_WINDOWEVENT_FOCUS_GAINED is sent when an app's window is shown. This mimicks behavior seen on iOS and Android. SDL_WINDOWEVENT_MINIMIZED and SDL_WINDOWEVENT_RESTORED are now sent when the app's native window is hidden and shown. Previously, these were sent when an app was suspended and resumed. On Windows 8.x/RT, an app may be sent to the background without being suspended, which previously meant that SDL_WINDOWEVENT_MINIMIZED might never have been sent. (On Windows Phone 8, however, this seems to be different, whereby apps sent to the background appear to always get suspended.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8616
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     1
/*
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     2
  Simple DirectMedia Layer
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     4
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     5
  This software is provided 'as-is', without any express or implied
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     7
  arising from the use of this software.
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     8
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    11
  freely, subject to the following restrictions:
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    12
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    14
     claim that you wrote the original software. If you use this software
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    16
     appreciated but is not required.
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    18
     misrepresented as being the original software.
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    20
*/
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    21
#include "../../SDL_internal.h"
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 8600
diff changeset
    22
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    23
/* Standard C++11 includes */
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    24
#include <functional>
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    25
#include <string>
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    26
#include <sstream>
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    27
using namespace std;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    28
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    29
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    30
/* Windows includes */
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    31
#include "ppltasks.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    32
using namespace concurrency;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    33
using namespace Windows::ApplicationModel;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    34
using namespace Windows::ApplicationModel::Core;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    35
using namespace Windows::ApplicationModel::Activation;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    36
using namespace Windows::Devices::Input;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    37
using namespace Windows::Graphics::Display;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    38
using namespace Windows::Foundation;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    39
using namespace Windows::System;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    40
using namespace Windows::UI::Core;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    41
using namespace Windows::UI::Input;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    42
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    43
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    44
using namespace Windows::Phone::UI::Input;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    45
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    46
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    47
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    48
/* SDL includes */
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    49
extern "C" {
8600
092802455aed build fixes for most WinRT-related files
David Ludwig <dludwig@pobox.com>
parents: 8582
diff changeset
    50
#include "../../SDL_internal.h"
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    51
#include "SDL_assert.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    52
#include "SDL_events.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    53
#include "SDL_hints.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    54
#include "SDL_log.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    55
#include "SDL_main.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    56
#include "SDL_stdinc.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    57
#include "SDL_render.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    58
#include "../../video/SDL_sysvideo.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    59
//#include "../../SDL_hints_c.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    60
#include "../../events/SDL_events_c.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    61
#include "../../events/SDL_keyboard_c.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    62
#include "../../events/SDL_mouse_c.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    63
#include "../../events/SDL_windowevents_c.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    64
#include "../../render/SDL_sysrender.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    65
#include "../windows/SDL_windows.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    66
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    67
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    68
#include "../../video/winrt/SDL_winrtevents_c.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    69
#include "../../video/winrt/SDL_winrtvideo_cpp.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    70
#include "SDL_winrtapp_common.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    71
#include "SDL_winrtapp_direct3d.h"
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    72
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    73
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    74
// Compile-time debugging options:
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    75
// To enable, uncomment; to disable, comment them out.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    76
//#define LOG_POINTER_EVENTS 1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    77
//#define LOG_WINDOW_EVENTS 1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    78
//#define LOG_ORIENTATION_EVENTS 1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    79
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    80
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    81
// HACK, DLudwig: record a reference to the global, WinRT 'app'/view.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    82
// SDL/WinRT will use this throughout its code.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    83
//
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    84
// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    85
// non-global, such as something created inside
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    86
// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    87
// SDL_CreateWindow().
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    88
SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    89
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    90
ref class SDLApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    91
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    92
public:
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    93
    virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    94
};
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    95
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    96
IFrameworkView^ SDLApplicationSource::CreateView()
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    97
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    98
    // TODO, WinRT: see if this function (CreateView) can ever get called
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
    99
    // more than once.  For now, just prevent it from ever assigning
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   100
    // SDL_WinRTGlobalApp more than once.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   101
    SDL_assert(!SDL_WinRTGlobalApp);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   102
    SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   103
    if (!SDL_WinRTGlobalApp)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   104
    {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   105
        SDL_WinRTGlobalApp = app;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   106
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   107
    return app;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   108
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   109
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   110
int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **))
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   111
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   112
    WINRT_SDLAppEntryPoint = mainFunction;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   113
    auto direct3DApplicationSource = ref new SDLApplicationSource();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   114
    CoreApplication::Run(direct3DApplicationSource);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   115
    return 0;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   116
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   117
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   118
static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   119
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   120
    SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   121
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   122
    // Start with no orientation flags, then add each in as they're parsed
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   123
    // from newValue.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   124
    unsigned int orientationFlags = 0;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   125
    if (newValue) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   126
        std::istringstream tokenizer(newValue);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   127
        while (!tokenizer.eof()) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   128
            std::string orientationName;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   129
            std::getline(tokenizer, orientationName, ' ');
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   130
            if (orientationName == "LandscapeLeft") {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   131
                orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   132
            } else if (orientationName == "LandscapeRight") {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   133
                orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   134
            } else if (orientationName == "Portrait") {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   135
                orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   136
            } else if (orientationName == "PortraitUpsideDown") {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   137
                orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   138
            }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   139
        }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   140
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   141
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   142
    // If no valid orientation flags were specified, use a reasonable set of defaults:
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   143
    if (!orientationFlags) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   144
        // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   145
        orientationFlags = (unsigned int) ( \
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   146
            DisplayOrientations::Landscape |
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   147
            DisplayOrientations::LandscapeFlipped |
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   148
            DisplayOrientations::Portrait |
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   149
            DisplayOrientations::PortraitFlipped);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   150
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   151
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   152
    // Set the orientation/rotation preferences.  Please note that this does
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   153
    // not constitute a 100%-certain lock of a given set of possible
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   154
    // orientations.  According to Microsoft's documentation on WinRT [1]
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   155
    // when a device is not capable of being rotated, Windows may ignore
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   156
    // the orientation preferences, and stick to what the device is capable of
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   157
    // displaying.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   158
    //
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   159
    // [1] Documentation on the 'InitialRotationPreference' setting for a
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   160
    // Windows app's manifest file describes how some orientation/rotation
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   161
    // preferences may be ignored.  See
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   162
    // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   163
    // for details.  Microsoft's "Display orientation sample" also gives an
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   164
    // outline of how Windows treats device rotation
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   165
    // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
8621
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   166
#if NTDDI_VERSION > NTDDI_WIN8
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   167
    DisplayInformation::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   168
#else
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   169
    DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
8621
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   170
#endif
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   171
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   172
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   173
static void
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   174
WINRT_ProcessWindowSizeChange()
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   175
{
8664
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   176
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   177
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   178
    // Make the new window size be the one true fullscreen mode.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   179
    // This change was initially done, in part, to allow the Direct3D 11.1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   180
    // renderer to receive window-resize events as a device rotates.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   181
    // Before, rotating a device from landscape, to portrait, and then
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   182
    // back to landscape would cause the Direct3D 11.1 swap buffer to
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   183
    // not get resized appropriately.  SDL would, on the rotation from
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   184
    // landscape to portrait, re-resize the SDL window to it's initial
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   185
    // size (landscape).  On the subsequent rotation, SDL would drop the
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   186
    // window-resize event as it appeared the SDL window didn't change
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   187
    // size, and the Direct3D 11.1 renderer wouldn't resize its swap
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   188
    // chain.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   189
    SDL_DisplayMode newDisplayMode;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   190
    if (WINRT_CalcDisplayModeUsingNativeWindow(&newDisplayMode) != 0) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   191
        return;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   192
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   193
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   194
    // Make note of the old display mode, and it's old driverdata.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   195
    SDL_DisplayMode oldDisplayMode;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   196
    SDL_zero(oldDisplayMode);
8664
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   197
    if (_this) {
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   198
        oldDisplayMode = _this->displays[0].desktop_mode;
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   199
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   200
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   201
    // Setup the new display mode in the appropriate spots.
8664
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   202
    if (_this) {
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   203
        // Make a full copy of the display mode for display_modes[0],
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   204
        // one with with a separately malloced 'driverdata' field.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   205
        // SDL_VideoQuit(), if called, will attempt to free the driverdata
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   206
        // fields in 'desktop_mode' and each entry in the 'display_modes'
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   207
        // array.
8664
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   208
        if (_this->displays[0].display_modes[0].driverdata) {
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   209
            // Free the previous mode's memory
8664
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   210
            SDL_free(_this->displays[0].display_modes[0].driverdata);
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   211
            _this->displays[0].display_modes[0].driverdata = NULL;
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   212
        }
8664
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   213
        if (WINRT_DuplicateDisplayMode(&(_this->displays[0].display_modes[0]), &newDisplayMode) != 0) {
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   214
            // Uh oh, something went wrong.  A malloc call probably failed.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   215
            SDL_free(newDisplayMode.driverdata);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   216
            return;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   217
        }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   218
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   219
        // Install 'newDisplayMode' into 'current_mode' and 'desktop_mode'.
8664
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   220
        _this->displays[0].current_mode = newDisplayMode;
565698ab1c40 WinRT globals cleanup: Removed WINRT_GlobalSDLVideoDevice
David Ludwig <dludwig@pobox.com>
parents: 8621
diff changeset
   221
        _this->displays[0].desktop_mode = newDisplayMode;
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   222
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   223
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   224
    if (WINRT_GlobalSDLWindow) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   225
        // Send a window-resize event to the rest of SDL, and to apps:
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   226
        SDL_SendWindowEvent(
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   227
            WINRT_GlobalSDLWindow,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   228
            SDL_WINDOWEVENT_RESIZED,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   229
            newDisplayMode.w,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   230
            newDisplayMode.h);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   231
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   232
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   233
        // HACK: On Windows Phone, make sure that orientation changes from
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   234
        // Landscape to LandscapeFlipped, Portrait to PortraitFlipped,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   235
        // or vice-versa on either of those two, lead to the Direct3D renderer
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   236
        // getting updated.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   237
        const DisplayOrientations oldOrientation = ((SDL_DisplayModeData *)oldDisplayMode.driverdata)->currentOrientation;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   238
        const DisplayOrientations newOrientation = ((SDL_DisplayModeData *)newDisplayMode.driverdata)->currentOrientation;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   239
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   240
        if ((oldOrientation == DisplayOrientations::Landscape && newOrientation == DisplayOrientations::LandscapeFlipped) ||
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   241
            (oldOrientation == DisplayOrientations::LandscapeFlipped && newOrientation == DisplayOrientations::Landscape) ||
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   242
            (oldOrientation == DisplayOrientations::Portrait && newOrientation == DisplayOrientations::PortraitFlipped) ||
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   243
            (oldOrientation == DisplayOrientations::PortraitFlipped && newOrientation == DisplayOrientations::Portrait))
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   244
        {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   245
            // One of the reasons this event is getting sent out is because SDL
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   246
            // will ignore requests to send out SDL_WINDOWEVENT_RESIZED events
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   247
            // if and when the event size doesn't change (and the Direct3D 11.1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   248
            // renderer doesn't get the memo).
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   249
            //
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   250
            // Make sure that the display/window size really didn't change.  If
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   251
            // it did, then a SDL_WINDOWEVENT_SIZE_CHANGED event got sent, and
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   252
            // the Direct3D 11.1 renderer picked it up, presumably.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   253
            if (oldDisplayMode.w == newDisplayMode.w &&
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   254
                oldDisplayMode.h == newDisplayMode.h)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   255
            {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   256
                SDL_SendWindowEvent(
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   257
                    WINRT_GlobalSDLWindow,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   258
                    SDL_WINDOWEVENT_SIZE_CHANGED,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   259
                    newDisplayMode.w,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   260
                    newDisplayMode.h);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   261
            }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   262
        }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   263
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   264
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   265
    
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   266
    // Finally, free the 'driverdata' field of the old 'desktop_mode'.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   267
    if (oldDisplayMode.driverdata) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   268
        SDL_free(oldDisplayMode.driverdata);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   269
        oldDisplayMode.driverdata = NULL;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   270
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   271
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   272
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   273
SDL_WinRTApp::SDL_WinRTApp() :
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   274
    m_windowClosed(false),
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   275
    m_windowVisible(true)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   276
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   277
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   278
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   279
void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   280
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   281
    applicationView->Activated +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   282
        ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   283
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   284
    CoreApplication::Suspending +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   285
        ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   286
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   287
    CoreApplication::Resuming +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   288
        ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   289
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   290
    CoreApplication::Exiting +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   291
        ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnExiting);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   292
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   293
8621
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   294
#if NTDDI_VERSION > NTDDI_WIN8
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   295
void SDL_WinRTApp::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   296
#else
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   297
void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
8621
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   298
#endif
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   299
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   300
#if LOG_ORIENTATION_EVENTS==1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   301
    CoreWindow^ window = CoreWindow::GetForCurrentThread();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   302
    if (window) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   303
        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Size={%f,%f}\n",
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   304
            __FUNCTION__,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   305
            (int)DisplayProperties::CurrentOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   306
            (int)DisplayProperties::NativeOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   307
            (int)DisplayProperties::AutoRotationPreferences,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   308
            window->Bounds.Width,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   309
            window->Bounds.Height);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   310
    } else {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   311
        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   312
            __FUNCTION__,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   313
            (int)DisplayProperties::CurrentOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   314
            (int)DisplayProperties::NativeOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   315
            (int)DisplayProperties::AutoRotationPreferences);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   316
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   317
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   318
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   319
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   320
    // On Windows Phone, treat an orientation change as a change in window size.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   321
    // The native window's size doesn't seem to change, however SDL will simulate
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   322
    // a window size change.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   323
    WINRT_ProcessWindowSizeChange();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   324
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   325
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   326
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   327
void SDL_WinRTApp::SetWindow(CoreWindow^ window)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   328
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   329
#if LOG_WINDOW_EVENTS==1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   330
    SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window Size={%f,%f}\n",
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   331
        __FUNCTION__,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   332
        (int)DisplayProperties::CurrentOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   333
        (int)DisplayProperties::NativeOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   334
        (int)DisplayProperties::AutoRotationPreferences,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   335
        window->Bounds.Width,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   336
        window->Bounds.Height);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   337
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   338
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   339
    window->SizeChanged += 
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   340
        ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   341
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   342
    window->VisibilityChanged +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   343
        ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   344
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   345
    window->Closed += 
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   346
        ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   347
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   348
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   349
    window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   350
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   351
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   352
    window->PointerPressed +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   353
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   354
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   355
    window->PointerMoved +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   356
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   357
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   358
    window->PointerReleased +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   359
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   360
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   361
    window->PointerWheelChanged +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   362
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   363
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   364
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   365
    // Retrieves relative-only mouse movements:
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   366
    Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   367
        ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   368
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   369
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   370
    window->KeyDown +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   371
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   372
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   373
    window->KeyUp +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   374
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   375
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   376
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   377
    HardwareButtons::BackPressed +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   378
        ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   379
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   380
8621
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   381
#if NTDDI_VERSION > NTDDI_WIN8
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   382
    DisplayInformation::GetForCurrentView()->OrientationChanged +=
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   383
        ref new TypedEventHandler<Windows::Graphics::Display::DisplayInformation^, Object^>(this, &SDL_WinRTApp::OnOrientationChanged);
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   384
#else
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   385
    DisplayProperties::OrientationChanged +=
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   386
        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   387
#endif
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   388
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   389
    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   390
    // TODO, WinRT: see if an app's default orientation can be found out via WinRT API(s), then set the initial value of SDL_HINT_ORIENTATIONS accordingly.
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   391
    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
5252788cb448 Fixed broken rotation detection routines on WinRT
David Ludwig <dludwig@pobox.com>
parents: 8616
diff changeset
   392
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   393
#if WINAPI_FAMILY == WINAPI_FAMILY_APP  // for Windows 8/8.1/RT apps... (and not Phone apps)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   394
    // Make sure we know when a user has opened the app's settings pane.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   395
    // This is needed in order to display a privacy policy, which needs
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   396
    // to be done for network-enabled apps, as per Windows Store requirements.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   397
    using namespace Windows::UI::ApplicationSettings;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   398
    SettingsPane::GetForCurrentView()->CommandsRequested +=
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   399
        ref new TypedEventHandler<SettingsPane^, SettingsPaneCommandsRequestedEventArgs^>
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   400
            (this, &SDL_WinRTApp::OnSettingsPaneCommandsRequested);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   401
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   402
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   403
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   404
void SDL_WinRTApp::Load(Platform::String^ entryPoint)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   405
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   406
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   407
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   408
void SDL_WinRTApp::Run()
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   409
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   410
    SDL_SetMainReady();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   411
    if (WINRT_SDLAppEntryPoint)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   412
    {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   413
        // TODO, WinRT: pass the C-style main() a reasonably realistic
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   414
        // representation of command line arguments.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   415
        int argc = 0;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   416
        char **argv = NULL;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   417
        WINRT_SDLAppEntryPoint(argc, argv);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   418
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   419
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   420
8666
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   421
static bool IsSDLWindowEventPending(SDL_WindowEventID windowEventID)
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   422
{
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   423
    SDL_Event events[128];
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   424
    const int count = SDL_PeepEvents(events, sizeof(events)/sizeof(SDL_Event), SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT);
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   425
    for (int i = 0; i < count; ++i) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   426
        if (events[i].window.event == windowEventID) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   427
            return true;
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   428
        }
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   429
    }
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   430
    return false;
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   431
}
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   432
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   433
bool SDL_WinRTApp::ShouldWaitForAppResumeEvents()
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   434
{
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   435
    /* Don't wait if the app is visible: */
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   436
    if (m_windowVisible) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   437
        return false;
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   438
    }
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   439
    
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   440
    /* Don't wait until the window-hide events finish processing.
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   441
     * Do note that if an app-suspend event is sent (as indicated
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   442
     * by SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   443
     * events), then this code may be a moot point, as WinRT's
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   444
     * own event pump (aka ProcessEvents()) will pause regardless
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   445
     * of what we do here.  This happens on Windows Phone 8, to note.
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   446
     * Windows 8.x apps, on the other hand, may get a chance to run
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   447
     * these.
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   448
     */
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   449
    if (IsSDLWindowEventPending(SDL_WINDOWEVENT_HIDDEN)) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   450
        return false;
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   451
    } else if (IsSDLWindowEventPending(SDL_WINDOWEVENT_FOCUS_LOST)) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   452
        return false;
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   453
    } else if (IsSDLWindowEventPending(SDL_WINDOWEVENT_MINIMIZED)) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   454
        return false;
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   455
    }
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   456
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   457
    return true;
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   458
}
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   459
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   460
void SDL_WinRTApp::PumpEvents()
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   461
{
8666
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   462
    if (!m_windowClosed) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   463
        if (!ShouldWaitForAppResumeEvents()) {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   464
            /* This is the normal way in which events should be pumped.
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   465
             * 'ProcessAllIfPresent' will make ProcessEvents() process anywhere
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   466
             * from zero to N events, and will then return.
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   467
             */
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   468
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
8666
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   469
        } else {
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   470
            /* This style of event-pumping, with 'ProcessOneAndAllPending',
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   471
             * will cause anywhere from one to N events to be processed.  If
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   472
             * at least one event is processed, the call will return.  If
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   473
             * no events are pending, then the call will wait until one is
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   474
             * available, and will not return (to the caller) until this
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   475
             * happens!  This should only occur when the app is hidden.
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   476
             */
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   477
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   478
        }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   479
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   480
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   481
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   482
void SDL_WinRTApp::Uninitialize()
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   483
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   484
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   485
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   486
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   487
void SDL_WinRTApp::OnSettingsPaneCommandsRequested(
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   488
    Windows::UI::ApplicationSettings::SettingsPane ^p,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   489
    Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   490
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   491
    using namespace Platform;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   492
    using namespace Windows::UI::ApplicationSettings;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   493
    using namespace Windows::UI::Popups;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   494
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   495
    String ^privacyPolicyURL = nullptr;     // a URL to an app's Privacy Policy
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   496
    String ^privacyPolicyLabel = nullptr;   // label/link text
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   497
    const char *tmpHintValue = NULL;        // SDL_GetHint-retrieved value, used immediately
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   498
    wchar_t *tmpStr = NULL;                 // used for UTF8 to UCS2 conversion
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   499
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   500
    // Setup a 'Privacy Policy' link, if one is available (via SDL_GetHint):
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   501
    tmpHintValue = SDL_GetHint(SDL_HINT_WINRT_PRIVACY_POLICY_URL);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   502
    if (tmpHintValue && tmpHintValue[0] != '\0') {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   503
        // Convert the privacy policy's URL to UCS2:
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   504
        tmpStr = WIN_UTF8ToString(tmpHintValue);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   505
        privacyPolicyURL = ref new String(tmpStr);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   506
        SDL_free(tmpStr);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   507
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   508
        // Optionally retrieve custom label-text for the link.  If this isn't
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   509
        // available, a default value will be used instead.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   510
        tmpHintValue = SDL_GetHint(SDL_HINT_WINRT_PRIVACY_POLICY_LABEL);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   511
        if (tmpHintValue && tmpHintValue[0] != '\0') {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   512
            tmpStr = WIN_UTF8ToString(tmpHintValue);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   513
            privacyPolicyLabel = ref new String(tmpStr);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   514
            SDL_free(tmpStr);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   515
        } else {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   516
            privacyPolicyLabel = ref new String(L"Privacy Policy");
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   517
        }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   518
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   519
        // Register the link, along with a handler to be called if and when it is
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   520
        // clicked:
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   521
        auto cmd = ref new SettingsCommand(L"privacyPolicy", privacyPolicyLabel,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   522
            ref new UICommandInvokedHandler([=](IUICommand ^) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   523
                Windows::System::Launcher::LaunchUriAsync(ref new Uri(privacyPolicyURL));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   524
        }));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   525
        args->Request->ApplicationCommands->Append(cmd);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   526
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   527
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   528
#endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   529
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   530
void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   531
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   532
#if LOG_WINDOW_EVENTS==1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   533
    SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   534
        __FUNCTION__,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   535
        args->Size.Width, args->Size.Height,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   536
        (int)DisplayProperties::CurrentOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   537
        (int)DisplayProperties::NativeOrientation,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   538
        (int)DisplayProperties::AutoRotationPreferences,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   539
        (WINRT_GlobalSDLWindow ? "yes" : "no"));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   540
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   541
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   542
    WINRT_ProcessWindowSizeChange();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   543
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   544
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   545
void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   546
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   547
#if LOG_WINDOW_EVENTS==1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   548
    SDL_Log("%s, visible?=%s, WINRT_GlobalSDLWindow?=%s\n",
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   549
        __FUNCTION__,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   550
        (args->Visible ? "yes" : "no"),
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   551
        (WINRT_GlobalSDLWindow ? "yes" : "no"));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   552
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   553
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   554
    m_windowVisible = args->Visible;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   555
    if (WINRT_GlobalSDLWindow) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   556
        SDL_bool wasSDLWindowSurfaceValid = WINRT_GlobalSDLWindow->surface_valid;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   557
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   558
        if (args->Visible) {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   559
            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
8666
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   560
            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   561
            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_RESTORED, 0, 0);
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   562
        } else {
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   563
            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
8666
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   564
            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   565
            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   566
        }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   567
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   568
        // HACK: Prevent SDL's window-hide handling code, which currently
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   569
        // triggers a fake window resize (possibly erronously), from
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   570
        // marking the SDL window's surface as invalid.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   571
        //
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   572
        // A better solution to this probably involves figuring out if the
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   573
        // fake window resize can be prevented.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   574
        WINRT_GlobalSDLWindow->surface_valid = wasSDLWindowSurfaceValid;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   575
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   576
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   577
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   578
void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   579
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   580
#if LOG_WINDOW_EVENTS==1
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   581
    SDL_Log("%s\n", __FUNCTION__);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   582
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   583
    m_windowClosed = true;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   584
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   585
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   586
void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   587
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   588
    CoreWindow::GetForCurrentThread()->Activate();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   589
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   590
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   591
void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   592
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   593
    // Save app state asynchronously after requesting a deferral. Holding a deferral
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   594
    // indicates that the application is busy performing suspending operations. Be
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   595
    // aware that a deferral may not be held indefinitely. After about five seconds,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   596
    // the app will be forced to exit.
8665
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   597
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   598
    // ... but first, let the app know it's about to go to the background.
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   599
    // The separation of events may be important, given that the deferral
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   600
    // runs in a separate thread.  This'll make SDL_APP_WILLENTERBACKGROUND
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   601
    // the only event among the two that runs in the main thread.  Given
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   602
    // that a few WinRT operations can only be done from the main thread
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   603
    // (things that access the WinRT CoreWindow are one example of this),
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   604
    // this could be important.
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   605
    SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
b987c561c218 WinRT: Made app-backgrounded events get sent at separate, distinct times.
David Ludwig <dludwig@pobox.com>
parents: 8664
diff changeset
   606
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   607
    SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   608
    create_task([this, deferral]()
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   609
    {
8666
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   610
        // Send an app did-enter-background event immediately to observers.
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   611
        // CoreDispatcher::ProcessEvents, which is the backbone on which
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   612
        // SDL_WinRTApp::PumpEvents is built, will not return to its caller
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   613
        // once it sends out a suspend event.  Any events posted to SDL's
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   614
        // event queue won't get received until the WinRT app is resumed.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   615
        // SDL_AddEventWatch() may be used to receive app-suspend events on
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   616
        // WinRT.
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   617
        SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   618
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   619
        deferral->Complete();
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   620
    });
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   621
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   622
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   623
void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   624
{
8666
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   625
    // Restore any data or state that was unloaded on suspend. By default, data
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   626
    // and state are persisted when resuming from suspend. Note that these events
20d52dc1a24a WinRT: Miscellaneous app-backgrounding/restoring event fixes and additions
David Ludwig <dludwig@pobox.com>
parents: 8665
diff changeset
   627
    // do not occur if the app was previously terminated.
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   628
    SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   629
    SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   630
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   631
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   632
void SDL_WinRTApp::OnExiting(Platform::Object^ sender, Platform::Object^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   633
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   634
    SDL_SendAppEvent(SDL_APP_TERMINATING);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   635
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   636
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   637
static void
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   638
WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   639
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   640
    Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   641
    SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   642
        header,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   643
        pt->Position.X, pt->Position.Y,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   644
        transformedPoint.X, transformedPoint.Y,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   645
        pt->Properties->MouseWheelDelta,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   646
        pt->FrameId,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   647
        pt->PointerId,
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   648
        WINRT_GetSDLButtonForPointerPoint(pt));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   649
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   650
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   651
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   652
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   653
#if LOG_POINTER_EVENTS
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   654
    WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   655
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   656
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   657
    WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   658
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   659
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   660
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   661
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   662
#if LOG_POINTER_EVENTS
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   663
    WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   664
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   665
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   666
    WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   667
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   668
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   669
void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   670
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   671
#if LOG_POINTER_EVENTS
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   672
    WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   673
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   674
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   675
    WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   676
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   677
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   678
void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   679
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   680
#if LOG_POINTER_EVENTS
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   681
    WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   682
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   683
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   684
    WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   685
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   686
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   687
void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   688
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   689
    WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   690
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   691
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   692
void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   693
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   694
    WINRT_ProcessKeyDownEvent(args);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   695
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   696
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   697
void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   698
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   699
    WINRT_ProcessKeyUpEvent(args);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   700
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   701
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   702
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   703
void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args)
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   704
{
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   705
    SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   706
    SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK);
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   707
8577
462760a8b82e WinRT: simulate keyboard events on Windows Phone 8 back-button presses
David Ludwig <dludwig@pobox.com>
parents: 8576
diff changeset
   708
    const char *hint = SDL_GetHint(SDL_HINT_WINRT_HANDLE_BACK_BUTTON);
462760a8b82e WinRT: simulate keyboard events on Windows Phone 8 back-button presses
David Ludwig <dludwig@pobox.com>
parents: 8576
diff changeset
   709
    if (hint) {
462760a8b82e WinRT: simulate keyboard events on Windows Phone 8 back-button presses
David Ludwig <dludwig@pobox.com>
parents: 8576
diff changeset
   710
        if (*hint == '1') {
462760a8b82e WinRT: simulate keyboard events on Windows Phone 8 back-button presses
David Ludwig <dludwig@pobox.com>
parents: 8576
diff changeset
   711
            args->Handled = true;
462760a8b82e WinRT: simulate keyboard events on Windows Phone 8 back-button presses
David Ludwig <dludwig@pobox.com>
parents: 8576
diff changeset
   712
        }
8582
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   713
    }
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   714
}
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   715
#endif
c3e9a2b93517 Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents: 8581
diff changeset
   716