src/core/winrt/SDL_winrtapp.cpp
author David Ludwig <dludwig@pobox.com>
Tue, 27 Aug 2013 09:53:58 -0400
changeset 8490 b05c6db83a07
parent 8489 7fd62b320c31
child 8491 50b0bdce11cd
permissions -rw-r--r--
WinRT: removed a deprecated hack regarding window resizing and Direct3D viewports
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8443
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
     1

8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
     2
#include <functional>
8443
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
     3
#include <string>
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
     4
#include <sstream>
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
     5
8417
43f837ba544b WinRT: made use of SDL's framebuffer emulation code, instead of the custom stuff; then removed SDL_winrtrenderer
David Ludwig <dludwig@pobox.com>
parents: 8415
diff changeset
     6
#include "ppltasks.h"
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     7
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
     8
extern "C" {
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
     9
#include "SDL_assert.h"
8443
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
    10
#include "SDL_events.h"
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
    11
#include "SDL_hints.h"
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
    12
#include "SDL_log.h"
8481
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    13
#include "SDL_main.h"
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
    14
#include "SDL_stdinc.h"
8443
210a3869a783 WinRT: cleaned up headers in src\video\windowsrt\
David Ludwig <dludwig@pobox.com>
parents: 8441
diff changeset
    15
#include "SDL_render.h"
8483
d403ded25942 WinRT: file naming and placement cleanup
David Ludwig <dludwig@pobox.com>
parents: 8481
diff changeset
    16
#include "../../video/SDL_sysvideo.h"
8478
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8474
diff changeset
    17
//#include "../../SDL_hints_c.h"
8332
ea83d191cc17 WinRT: added mouse button event support
David Ludwig <dludwig@pobox.com>
parents: 8331
diff changeset
    18
#include "../../events/SDL_mouse_c.h"
8383
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
    19
#include "../../events/SDL_windowevents_c.h"
8434
c49d0a46f516 WinRT: another device-rotation and rendering fix
David Ludwig <dludwig@pobox.com>
parents: 8433
diff changeset
    20
#include "../../render/SDL_sysrender.h"
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
    21
}
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
    22
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    23
#include "../../video/winrt/SDL_winrtevents_c.h"
8483
d403ded25942 WinRT: file naming and placement cleanup
David Ludwig <dludwig@pobox.com>
parents: 8481
diff changeset
    24
#include "../../video/winrt/SDL_winrtvideo.h"
d403ded25942 WinRT: file naming and placement cleanup
David Ludwig <dludwig@pobox.com>
parents: 8481
diff changeset
    25
#include "SDL_winrtapp.h"
8435
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    26
8436
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    27
using namespace concurrency;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    28
using namespace std;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    29
using namespace Windows::ApplicationModel;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    30
using namespace Windows::ApplicationModel::Core;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    31
using namespace Windows::ApplicationModel::Activation;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    32
using namespace Windows::Devices::Input;
8435
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    33
using namespace Windows::Graphics::Display;
8436
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    34
using namespace Windows::Foundation;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    35
using namespace Windows::System;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    36
using namespace Windows::UI::Core;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    37
using namespace Windows::UI::Input;
8342
05d7aa70928e WinRT: started work on renderer by getting Direct3D 11.1 to display a single, fullscreen rectangle
David Ludwig <dludwig@pobox.com>
parents: 8336
diff changeset
    38
8468
51de52f20d4b WinRT: mouse-pointer debugging improvements
David Ludwig <dludwig@pobox.com>
parents: 8467
diff changeset
    39
// Compile-time debugging options:
51de52f20d4b WinRT: mouse-pointer debugging improvements
David Ludwig <dludwig@pobox.com>
parents: 8467
diff changeset
    40
// To enable, uncomment; to disable, comment them out.
51de52f20d4b WinRT: mouse-pointer debugging improvements
David Ludwig <dludwig@pobox.com>
parents: 8467
diff changeset
    41
//#define LOG_POINTER_EVENTS 1
8474
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
    42
//#define LOG_WINDOW_EVENTS 1
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
    43
//#define LOG_ORIENTATION_EVENTS 1
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
    44
8468
51de52f20d4b WinRT: mouse-pointer debugging improvements
David Ludwig <dludwig@pobox.com>
parents: 8467
diff changeset
    45
8324
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
    46
// HACK, DLudwig: The C-style main() will get loaded via the app's
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
    47
// WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp.
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
    48
// This seems wrong on some level, but does seem to work.
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
    49
typedef int (*SDL_WinRT_MainFunction)(int, char **);
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
    50
static SDL_WinRT_MainFunction SDL_WinRT_main = nullptr;
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
    51
8436
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    52
// HACK, DLudwig: record a reference to the global, Windows RT 'app'/view.
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    53
// SDL/WinRT will use this throughout its code.
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    54
//
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    55
// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    56
// non-global, such as something created inside
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    57
// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    58
// SDL_CreateWindow().
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    59
SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
6d2329b6f7c7 WinRT: minor cleanup in top-level app code
David Ludwig <dludwig@pobox.com>
parents: 8435
diff changeset
    60
8437
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    61
ref class SDLApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    62
{
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    63
public:
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    64
    virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    65
};
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    66
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    67
IFrameworkView^ SDLApplicationSource::CreateView()
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    68
{
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    69
    // TODO, WinRT: see if this function (CreateView) can ever get called
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    70
    // more than once.  For now, just prevent it from ever assigning
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    71
    // SDL_WinRTGlobalApp more than once.
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    72
    SDL_assert(!SDL_WinRTGlobalApp);
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    73
    SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    74
    if (!SDL_WinRTGlobalApp)
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    75
    {
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    76
        SDL_WinRTGlobalApp = app;
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    77
    }
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    78
    return app;
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    79
}
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    80
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    81
__declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFunction)
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    82
{
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    83
    SDL_WinRT_main = mainFunction;
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    84
    auto direct3DApplicationSource = ref new SDLApplicationSource();
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    85
    CoreApplication::Run(direct3DApplicationSource);
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    86
    return 0;
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    87
}
d6a6c3ebdf3e WinRT: more minor code cleanups
David Ludwig <dludwig@pobox.com>
parents: 8436
diff changeset
    88
8478
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8474
diff changeset
    89
static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
8435
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    90
{
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    91
    SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    92
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    93
    // Start with no orientation flags, then add each in as they're parsed
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    94
    // from newValue.
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
    95
    unsigned int orientationFlags = 0;
8481
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    96
    if (newValue) {
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    97
        std::istringstream tokenizer(newValue);
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    98
        while (!tokenizer.eof()) {
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    99
            std::string orientationName;
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   100
            std::getline(tokenizer, orientationName, ' ');
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   101
            if (orientationName == "LandscapeLeft") {
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   102
                orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   103
            } else if (orientationName == "LandscapeRight") {
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   104
                orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   105
            } else if (orientationName == "Portrait") {
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   106
                orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   107
            } else if (orientationName == "PortraitUpsideDown") {
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   108
                orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   109
            }
8435
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   110
        }
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   111
    }
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   112
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   113
    // If no valid orientation flags were specified, use a reasonable set of defaults:
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   114
    if (!orientationFlags) {
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   115
        // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   116
        orientationFlags = (unsigned int) ( \
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   117
            DisplayOrientations::Landscape |
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   118
            DisplayOrientations::LandscapeFlipped |
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   119
            DisplayOrientations::Portrait |
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   120
            DisplayOrientations::PortraitFlipped);
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   121
    }
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   122
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   123
    // Set the orientation/rotation preferences.  Please note that this does
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   124
    // not constitute a 100%-certain lock of a given set of possible
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   125
    // orientations.  According to Microsoft's documentation on Windows RT [1]
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   126
    // when a device is not capable of being rotated, Windows may ignore
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   127
    // the orientation preferences, and stick to what the device is capable of
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   128
    // displaying.
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   129
    //
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   130
    // [1] Documentation on the 'InitialRotationPreference' setting for a
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   131
    // Windows app's manifest file describes how some orientation/rotation
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   132
    // preferences may be ignored.  See
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   133
    // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   134
    // for details.  Microsoft's "Display orientation sample" also gives an
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   135
    // outline of how Windows treats device rotation
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   136
    // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   137
    DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   138
}
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   139
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   140
SDL_WinRTApp::SDL_WinRTApp() :
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   141
    m_windowClosed(false),
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   142
    m_windowVisible(true),
8378
357a8e1166e5 WinRT: added support for SDL_SetRelativeMouseMode
David Ludwig <dludwig@pobox.com>
parents: 8376
diff changeset
   143
    m_sdlWindowData(NULL),
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   144
    m_sdlVideoDevice(NULL)
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   145
{
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   146
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   147
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   148
void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   149
{
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   150
    applicationView->Activated +=
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   151
        ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   152
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   153
    CoreApplication::Suspending +=
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   154
        ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   155
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   156
    CoreApplication::Resuming +=
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   157
        ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
8435
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   158
8474
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   159
    DisplayProperties::OrientationChanged +=
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   160
        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   161
8435
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   162
    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.  This needs to be
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   163
    // done before the hint's callback is registered (as of Feb 22, 2013),
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   164
    // otherwise the hint callback won't get registered.
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   165
    //
2d3fe6870df3 WinRT: allowed setting the device rotation preference via SDL_HINT_ORIENTATIONS
David Ludwig <dludwig@pobox.com>
parents: 8434
diff changeset
   166
    // WinRT, TODO: 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.
8478
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8474
diff changeset
   167
    //SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");   // DavidL: this is no longer needed (for SDL_AddHintCallback)
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8474
diff changeset
   168
    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   169
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   170
8474
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   171
void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   172
{
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   173
#if LOG_ORIENTATION_EVENTS==1
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   174
    CoreWindow^ window = CoreWindow::GetForCurrentThread();
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   175
    if (window) {
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   176
        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Size={%f,%f}\n",
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   177
            __FUNCTION__,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   178
            (int)DisplayProperties::CurrentOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   179
            (int)DisplayProperties::NativeOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   180
            (int)DisplayProperties::AutoRotationPreferences,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   181
            window->Bounds.Width,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   182
            window->Bounds.Height);
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   183
    } else {
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   184
        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   185
            __FUNCTION__,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   186
            (int)DisplayProperties::CurrentOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   187
            (int)DisplayProperties::NativeOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   188
            (int)DisplayProperties::AutoRotationPreferences);
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   189
    }
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   190
#endif
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   191
}
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   192
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   193
void SDL_WinRTApp::SetWindow(CoreWindow^ window)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   194
{
8474
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   195
#if LOG_WINDOW_EVENTS==1
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   196
    SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window Size={%f,%f}\n",
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   197
        __FUNCTION__,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   198
        (int)DisplayProperties::CurrentOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   199
        (int)DisplayProperties::NativeOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   200
        (int)DisplayProperties::AutoRotationPreferences,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   201
        window->Bounds.Width,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   202
        window->Bounds.Height);
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   203
#endif
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   204
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   205
    window->SizeChanged += 
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   206
        ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   207
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   208
    window->VisibilityChanged +=
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   209
        ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   210
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   211
    window->Closed += 
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   212
        ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   213
8399
1fa9dcfbeac5 WinRT: Windows Phone fixes. SDL can now display images, and respond to input, on Microsoft's Windows Phone 8 emulator.
David Ludwig <dludwig@pobox.com>
parents: 8394
diff changeset
   214
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   215
    window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
8399
1fa9dcfbeac5 WinRT: Windows Phone fixes. SDL can now display images, and respond to input, on Microsoft's Windows Phone 8 emulator.
David Ludwig <dludwig@pobox.com>
parents: 8394
diff changeset
   216
#endif
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   217
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   218
    window->PointerPressed +=
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   219
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   220
8332
ea83d191cc17 WinRT: added mouse button event support
David Ludwig <dludwig@pobox.com>
parents: 8331
diff changeset
   221
    window->PointerReleased +=
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   222
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
8332
ea83d191cc17 WinRT: added mouse button event support
David Ludwig <dludwig@pobox.com>
parents: 8331
diff changeset
   223
8422
73abaf9e1fae WinRT: emit SDL_MOUSEWHEEL events
David Ludwig <dludwig@pobox.com>
parents: 8421
diff changeset
   224
    window->PointerWheelChanged +=
73abaf9e1fae WinRT: emit SDL_MOUSEWHEEL events
David Ludwig <dludwig@pobox.com>
parents: 8421
diff changeset
   225
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
73abaf9e1fae WinRT: emit SDL_MOUSEWHEEL events
David Ludwig <dludwig@pobox.com>
parents: 8421
diff changeset
   226
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   227
    window->PointerMoved +=
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   228
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   229
8399
1fa9dcfbeac5 WinRT: Windows Phone fixes. SDL can now display images, and respond to input, on Microsoft's Windows Phone 8 emulator.
David Ludwig <dludwig@pobox.com>
parents: 8394
diff changeset
   230
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
8378
357a8e1166e5 WinRT: added support for SDL_SetRelativeMouseMode
David Ludwig <dludwig@pobox.com>
parents: 8376
diff changeset
   231
    // Retrieves relative-only mouse movements:
357a8e1166e5 WinRT: added support for SDL_SetRelativeMouseMode
David Ludwig <dludwig@pobox.com>
parents: 8376
diff changeset
   232
    Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
357a8e1166e5 WinRT: added support for SDL_SetRelativeMouseMode
David Ludwig <dludwig@pobox.com>
parents: 8376
diff changeset
   233
        ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
8399
1fa9dcfbeac5 WinRT: Windows Phone fixes. SDL can now display images, and respond to input, on Microsoft's Windows Phone 8 emulator.
David Ludwig <dludwig@pobox.com>
parents: 8394
diff changeset
   234
#endif
8378
357a8e1166e5 WinRT: added support for SDL_SetRelativeMouseMode
David Ludwig <dludwig@pobox.com>
parents: 8376
diff changeset
   235
8336
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   236
    window->KeyDown +=
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   237
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
8336
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   238
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   239
    window->KeyUp +=
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   240
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   241
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   242
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   243
void SDL_WinRTApp::Load(Platform::String^ entryPoint)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   244
{
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   245
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   246
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   247
void SDL_WinRTApp::Run()
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   248
{
8481
e412893178a8 WinRT: fixed a crash in some display orientation hint code
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   249
    SDL_SetMainReady();
8324
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   250
    if (SDL_WinRT_main)
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   251
    {
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   252
        // TODO, WinRT: pass the C-style main() a reasonably realistic
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   253
        // representation of command line arguments.
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   254
        int argc = 0;
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   255
        char **argv = NULL;
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   256
        SDL_WinRT_main(argc, argv);
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   257
    }
8331
737dc8a4f49f WinRT: made SDL_PumpEvents() work, in theory
David Ludwig <dludwig@pobox.com>
parents: 8330
diff changeset
   258
}
8324
285388934ded WinRT: got a C-style main(int,char**) function to be called on app init
David Ludwig <dludwig@pobox.com>
parents: 8323
diff changeset
   259
8331
737dc8a4f49f WinRT: made SDL_PumpEvents() work, in theory
David Ludwig <dludwig@pobox.com>
parents: 8330
diff changeset
   260
void SDL_WinRTApp::PumpEvents()
737dc8a4f49f WinRT: made SDL_PumpEvents() work, in theory
David Ludwig <dludwig@pobox.com>
parents: 8330
diff changeset
   261
{
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   262
    if (!m_windowClosed)
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   263
    {
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   264
        if (m_windowVisible)
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   265
        {
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   266
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   267
        }
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   268
        else
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   269
        {
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   270
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   271
        }
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   272
    }
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   273
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   274
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   275
void SDL_WinRTApp::Uninitialize()
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   276
{
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   277
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   278
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   279
void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   280
{
8474
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   281
#if LOG_WINDOW_EVENTS==1
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   282
    SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, m_sdlWindowData?=%s\n",
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   283
        __FUNCTION__,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   284
        args->Size.Width, args->Size.Height,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   285
        (int)DisplayProperties::CurrentOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   286
        (int)DisplayProperties::NativeOrientation,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   287
        (int)DisplayProperties::AutoRotationPreferences,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   288
        (m_sdlWindowData ? "yes" : "no"));
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   289
#endif
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   290
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   291
    if (m_sdlWindowData) {
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   292
        // Make the new window size be the one true fullscreen mode.
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   293
        // This change was done, in part, to allow the Direct3D 11.1 renderer
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   294
        // to receive window-resize events as a device rotates.
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   295
        // Before, rotating a device from landscape, to portrait, and then
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   296
        // back to landscape would cause the Direct3D 11.1 swap buffer to
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   297
        // not get resized appropriately.  SDL would, on the rotation from
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   298
        // landscape to portrait, re-resize the SDL window to it's initial
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   299
        // size (landscape).  On the subsequent rotation, SDL would drop the
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   300
        // window-resize event as it appeared the SDL window didn't change
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   301
        // size, and the Direct3D 11.1 renderer wouldn't resize its swap
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   302
        // chain.
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   303
        //
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   304
        // TODO, WinRT: consider dropping old display modes after the fullscreen window changes size (from rotations, etc.)
8490
b05c6db83a07 WinRT: removed a deprecated hack regarding window resizing and Direct3D viewports
David Ludwig <dludwig@pobox.com>
parents: 8489
diff changeset
   305
        m_sdlWindowData->sdlWindow->fullscreen_mode = GetMainDisplayMode();
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   306
        SDL_AddDisplayMode(&m_sdlVideoDevice->displays[0], &m_sdlWindowData->sdlWindow->fullscreen_mode);
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   307
8434
c49d0a46f516 WinRT: another device-rotation and rendering fix
David Ludwig <dludwig@pobox.com>
parents: 8433
diff changeset
   308
        // Send the window-resize event to the rest of SDL, and to apps:
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   309
        const int windowWidth = (int) ceil(args->Size.Width);
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   310
        const int windowHeight = (int) ceil(args->Size.Height);
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   311
        SDL_SendWindowEvent(
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   312
            m_sdlWindowData->sdlWindow,
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   313
            SDL_WINDOWEVENT_RESIZED,
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   314
            windowWidth,
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   315
            windowHeight);
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   316
    }
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   317
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   318
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   319
void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   320
{
8474
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   321
#if LOG_WINDOW_EVENTS==1
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   322
    SDL_Log("%s, visible?=%s, m_sdlWindowData?=%s\n",
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   323
        __FUNCTION__,
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   324
        (args->Visible ? "yes" : "no"),
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   325
        (m_sdlWindowData ? "yes" : "no"));
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   326
#endif
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   327
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   328
    m_windowVisible = args->Visible;
8385
e954dfbf2ecc WinRT: emit SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN
David Ludwig <dludwig@pobox.com>
parents: 8384
diff changeset
   329
    if (m_sdlWindowData) {
8390
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   330
        SDL_bool wasSDLWindowSurfaceValid = m_sdlWindowData->sdlWindow->surface_valid;
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   331
8385
e954dfbf2ecc WinRT: emit SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN
David Ludwig <dludwig@pobox.com>
parents: 8384
diff changeset
   332
        if (args->Visible) {
e954dfbf2ecc WinRT: emit SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN
David Ludwig <dludwig@pobox.com>
parents: 8384
diff changeset
   333
            SDL_SendWindowEvent(m_sdlWindowData->sdlWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
e954dfbf2ecc WinRT: emit SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN
David Ludwig <dludwig@pobox.com>
parents: 8384
diff changeset
   334
        } else {
e954dfbf2ecc WinRT: emit SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN
David Ludwig <dludwig@pobox.com>
parents: 8384
diff changeset
   335
            SDL_SendWindowEvent(m_sdlWindowData->sdlWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
e954dfbf2ecc WinRT: emit SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN
David Ludwig <dludwig@pobox.com>
parents: 8384
diff changeset
   336
        }
8390
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   337
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   338
        // HACK: Prevent SDL's window-hide handling code, which currently
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   339
        // triggers a fake window resize (possibly erronously), from
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   340
        // marking the SDL window's surface as invalid.
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   341
        //
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   342
        // A better solution to this probably involves figuring out if the
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   343
        // fake window resize can be prevented.
0770debe7b3b WinRT: hack-fixed a bug whereby SDL_UpdateWindowSurface would fail if the app was hidden, then re-shown
David Ludwig <dludwig@pobox.com>
parents: 8386
diff changeset
   344
        m_sdlWindowData->sdlWindow->surface_valid = wasSDLWindowSurfaceValid;
8385
e954dfbf2ecc WinRT: emit SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN
David Ludwig <dludwig@pobox.com>
parents: 8384
diff changeset
   345
    }
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   346
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   347
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   348
void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   349
{
8474
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   350
#if LOG_WINDOW_EVENTS==1
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   351
    SDL_Log("%s\n", __FUNCTION__);
cbf580f6ea1b WinRT: added code to help debug events related to window-sizing and device-orientation
David Ludwig <dludwig@pobox.com>
parents: 8468
diff changeset
   352
#endif
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   353
    m_windowClosed = true;
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   354
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   355
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   356
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   357
{
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   358
    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   359
    WINRT_ProcessPointerPressedEvent(window, args);
8332
ea83d191cc17 WinRT: added mouse button event support
David Ludwig <dludwig@pobox.com>
parents: 8331
diff changeset
   360
}
ea83d191cc17 WinRT: added mouse button event support
David Ludwig <dludwig@pobox.com>
parents: 8331
diff changeset
   361
ea83d191cc17 WinRT: added mouse button event support
David Ludwig <dludwig@pobox.com>
parents: 8331
diff changeset
   362
void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
ea83d191cc17 WinRT: added mouse button event support
David Ludwig <dludwig@pobox.com>
parents: 8331
diff changeset
   363
{
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   364
    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   365
    WINRT_ProcessPointerReleasedEvent(window, args);
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   366
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   367
8422
73abaf9e1fae WinRT: emit SDL_MOUSEWHEEL events
David Ludwig <dludwig@pobox.com>
parents: 8421
diff changeset
   368
void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
73abaf9e1fae WinRT: emit SDL_MOUSEWHEEL events
David Ludwig <dludwig@pobox.com>
parents: 8421
diff changeset
   369
{
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   370
    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   371
    WINRT_ProcessPointerWheelChangedEvent(window, args);
8379
1237c440712b WinRT: scaled relative mouse mode values from the native screen size to SDL's window size
David Ludwig <dludwig@pobox.com>
parents: 8378
diff changeset
   372
}
1237c440712b WinRT: scaled relative mouse mode values from the native screen size to SDL's window size
David Ludwig <dludwig@pobox.com>
parents: 8378
diff changeset
   373
8378
357a8e1166e5 WinRT: added support for SDL_SetRelativeMouseMode
David Ludwig <dludwig@pobox.com>
parents: 8376
diff changeset
   374
void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
357a8e1166e5 WinRT: added support for SDL_SetRelativeMouseMode
David Ludwig <dludwig@pobox.com>
parents: 8376
diff changeset
   375
{
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   376
    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   377
    WINRT_ProcessMouseMovedEvent(window, args);
8372
e6c3e06ba940 WinRT: fixed incorrect cursor positions when using non-native screen resolutions
David Ludwig <dludwig@pobox.com>
parents: 8367
diff changeset
   378
}
e6c3e06ba940 WinRT: fixed incorrect cursor positions when using non-native screen resolutions
David Ludwig <dludwig@pobox.com>
parents: 8367
diff changeset
   379
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   380
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   381
{
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   382
    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   383
    WINRT_ProcessPointerMovedEvent(window, args);
8336
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   384
}
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   385
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   386
void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   387
{
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   388
    WINRT_ProcessKeyDownEvent(args);
8336
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   389
}
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   390
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   391
void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   392
{
8489
7fd62b320c31 WinRT: moved most platform-specific keyboard and mouse code to shared locations
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   393
    WINRT_ProcessKeyUpEvent(args);
8336
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   394
}
0b9aa42be7ae WinRT: added key event support for most WinRT/VirtualKey-based keys
David Ludwig <dludwig@pobox.com>
parents: 8335
diff changeset
   395
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   396
void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   397
{
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   398
    CoreWindow::GetForCurrentThread()->Activate();
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   399
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   400
8383
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   401
static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event * event)
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   402
{
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   403
    if (event->type == SDL_WINDOWEVENT)
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   404
    {
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   405
        switch (event->window.event)
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   406
        {
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   407
            case SDL_WINDOWEVENT_MINIMIZED:
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   408
            case SDL_WINDOWEVENT_RESTORED:
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   409
                // Return 0 to indicate that the event should be removed from the
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   410
                // event queue:
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   411
                return 0;
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   412
            default:
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   413
                break;
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   414
        }
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   415
    }
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   416
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   417
    // Return 1 to indicate that the event should stay in the event queue:
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   418
    return 1;
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   419
}
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   420
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   421
void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   422
{
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   423
    // Save app state asynchronously after requesting a deferral. Holding a deferral
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   424
    // indicates that the application is busy performing suspending operations. Be
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   425
    // aware that a deferral may not be held indefinitely. After about five seconds,
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   426
    // the app will be forced to exit.
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   427
    SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   428
    create_task([this, deferral]()
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   429
    {
8383
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   430
        // Send a window-minimized event immediately to observers.
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   431
        // CoreDispatcher::ProcessEvents, which is the backbone on which
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   432
        // SDL_WinRTApp::PumpEvents is built, will not return to its caller
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   433
        // once it sends out a suspend event.  Any events posted to SDL's
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   434
        // event queue won't get received until the WinRT app is resumed.
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   435
        // SDL_AddEventWatch() may be used to receive app-suspend events on
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   436
        // WinRT.
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   437
        //
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   438
        // In order to prevent app-suspend events from being received twice:
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   439
        // first via a callback passed to SDL_AddEventWatch, and second via
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   440
        // SDL's event queue, the event will be sent to SDL, then immediately
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   441
        // removed from the queue.
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   442
        if (m_sdlWindowData)
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   443
        {
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   444
            SDL_SendWindowEvent(m_sdlWindowData->sdlWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);   // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   445
            SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   446
        }
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   447
        deferral->Complete();
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   448
    });
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   449
}
8383
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   450
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   451
void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   452
{
8384
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   453
    // Restore any data or state that was unloaded on suspend. By default, data
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   454
    // and state are persisted when resuming from suspend. Note that this event
bc7a52629e1e WinRT: converted tabs to spaces in src/video/windowsrt/*
David Ludwig <dludwig@pobox.com>
parents: 8383
diff changeset
   455
    // does not occur if the app was previously terminated.
8383
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   456
    if (m_sdlWindowData)
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   457
    {
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   458
        SDL_SendWindowEvent(m_sdlWindowData->sdlWindow, SDL_WINDOWEVENT_RESTORED, 0, 0);    // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   459
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   460
        // Remove the app-resume event from the queue, as is done with the
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   461
        // app-suspend event.
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   462
        //
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   463
        // TODO, WinRT: consider posting this event to the queue even though
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   464
        // its counterpart, the app-suspend event, effectively has to be
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   465
        // processed immediately.
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   466
        SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
1f415392ccf0 WinRT: send window 'minimized' and 'restored' events for app-suspend and app-resume. Use SDL_AddEventWatch() to receive these.
David Ludwig <dludwig@pobox.com>
parents: 8379
diff changeset
   467
    }
8322
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   468
}
839cd578a474 WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   469
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   470
SDL_DisplayMode SDL_WinRTApp::GetMainDisplayMode()
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   471
{
8467
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   472
    // Create an empty, zeroed-out display mode:
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   473
    SDL_DisplayMode mode;
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   474
    SDL_zero(mode);
8467
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   475
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   476
    // Fill in most fields:
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   477
    mode.format = SDL_PIXELFORMAT_RGB888;
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   478
    mode.refresh_rate = 0;  // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   479
    mode.driverdata = NULL;
8467
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   480
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   481
    // Calculate the display size given the window size, taking into account
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   482
    // the current display's DPI:
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   483
    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   484
    const float dipsPerInch = 96.0f;
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   485
    mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   486
    mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
d99fb48fcded WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
David Ludwig <dludwig@pobox.com>
parents: 8466
diff changeset
   487
8329
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   488
    return mode;
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   489
}
c3047b88e35b WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
David Ludwig <dludwig@pobox.com>
parents: 8324
diff changeset
   490
8335
4f41add2ff00 WinRT: fixed bug whereby attempting to create a 2nd window (which intentionall fails, for now) would cause mouse input to stop working
David Ludwig <dludwig@pobox.com>
parents: 8334
diff changeset
   491
const SDL_WindowData * SDL_WinRTApp::GetSDLWindowData() const
4f41add2ff00 WinRT: fixed bug whereby attempting to create a 2nd window (which intentionall fails, for now) would cause mouse input to stop working
David Ludwig <dludwig@pobox.com>
parents: 8334
diff changeset
   492
{
4f41add2ff00 WinRT: fixed bug whereby attempting to create a 2nd window (which intentionall fails, for now) would cause mouse input to stop working
David Ludwig <dludwig@pobox.com>
parents: 8334
diff changeset
   493
    return m_sdlWindowData;
4f41add2ff00 WinRT: fixed bug whereby attempting to create a 2nd window (which intentionall fails, for now) would cause mouse input to stop working
David Ludwig <dludwig@pobox.com>
parents: 8334
diff changeset
   494
}
4f41add2ff00 WinRT: fixed bug whereby attempting to create a 2nd window (which intentionall fails, for now) would cause mouse input to stop working
David Ludwig <dludwig@pobox.com>
parents: 8334
diff changeset
   495
8334
09b0670fece4 WinRT: explicitly allowed only one window at a time, pending multimonitor support (in SDL/WinRT)
David Ludwig <dludwig@pobox.com>
parents: 8333
diff changeset
   496
bool SDL_WinRTApp::HasSDLWindowData() const
09b0670fece4 WinRT: explicitly allowed only one window at a time, pending multimonitor support (in SDL/WinRT)
David Ludwig <dludwig@pobox.com>
parents: 8333
diff changeset
   497
{
09b0670fece4 WinRT: explicitly allowed only one window at a time, pending multimonitor support (in SDL/WinRT)
David Ludwig <dludwig@pobox.com>
parents: 8333
diff changeset
   498
    return (m_sdlWindowData != NULL);
09b0670fece4 WinRT: explicitly allowed only one window at a time, pending multimonitor support (in SDL/WinRT)
David Ludwig <dludwig@pobox.com>
parents: 8333
diff changeset
   499
}
09b0670fece4 WinRT: explicitly allowed only one window at a time, pending multimonitor support (in SDL/WinRT)
David Ludwig <dludwig@pobox.com>
parents: 8333
diff changeset
   500
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   501
void SDL_WinRTApp::SetSDLWindowData(const SDL_WindowData * windowData)
8333
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   502
{
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   503
    m_sdlWindowData = windowData;
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   504
}
49973bfb8d23 WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
David Ludwig <dludwig@pobox.com>
parents: 8332
diff changeset
   505
8433
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   506
void SDL_WinRTApp::SetSDLVideoDevice(const SDL_VideoDevice * videoDevice)
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   507
{
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   508
    m_sdlVideoDevice = videoDevice;
3017f87e4479 WinRT: bug fixes for device orientation + Direct3D 11.1 rendering
David Ludwig <dludwig@pobox.com>
parents: 8422
diff changeset
   509
}