src/video/windowsrt/SDL_WinRTApp.cpp
author David Ludwig <dludwig@pobox.com>
Tue, 08 Jan 2013 23:11:22 -0500
changeset 8384 bc7a52629e1e
parent 8383 1f415392ccf0
child 8385 e954dfbf2ecc
permissions -rw-r--r--
WinRT: converted tabs to spaces in src/video/windowsrt/*
dludwig@8322
     1
#include "SDLmain_WinRT_common.h"
dludwig@8322
     2
#include "SDL_WinRTApp.h"
dludwig@8322
     3
dludwig@8329
     4
extern "C" {
dludwig@8329
     5
#include "SDL_assert.h"
dludwig@8329
     6
#include "SDL_stdinc.h"
dludwig@8329
     7
#include "../SDL_sysvideo.h"
dludwig@8332
     8
#include "../../events/SDL_mouse_c.h"
dludwig@8336
     9
#include "../../events/SDL_keyboard_c.h"
dludwig@8383
    10
#include "../../events/SDL_windowevents_c.h"
dludwig@8332
    11
#include "SDL_events.h"
dludwig@8333
    12
#include "SDL_log.h"
dludwig@8329
    13
}
dludwig@8329
    14
dludwig@8342
    15
// TODO, WinRT: Remove reference(s) to BasicTimer.h
David@8376
    16
//#include "BasicTimer.h"
dludwig@8342
    17
dludwig@8324
    18
// HACK, DLudwig: The C-style main() will get loaded via the app's
dludwig@8324
    19
// WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp.
dludwig@8324
    20
// This seems wrong on some level, but does seem to work.
dludwig@8324
    21
typedef int (*SDL_WinRT_MainFunction)(int, char **);
dludwig@8324
    22
static SDL_WinRT_MainFunction SDL_WinRT_main = nullptr;
dludwig@8324
    23
dludwig@8329
    24
// HACK, DLudwig: record a reference to the global, Windows RT 'app'/view.
dludwig@8329
    25
// SDL/WinRT will use this throughout its code.
dludwig@8329
    26
//
dludwig@8329
    27
// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
dludwig@8329
    28
// non-global, such as something created inside
dludwig@8329
    29
// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
dludwig@8329
    30
// SDL_CreateWindow().
dludwig@8329
    31
SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
dludwig@8329
    32
dludwig@8324
    33
dludwig@8322
    34
using namespace Windows::ApplicationModel;
dludwig@8322
    35
using namespace Windows::ApplicationModel::Core;
dludwig@8322
    36
using namespace Windows::ApplicationModel::Activation;
dludwig@8378
    37
using namespace Windows::Devices::Input;
dludwig@8322
    38
using namespace Windows::UI::Core;
dludwig@8322
    39
using namespace Windows::System;
dludwig@8322
    40
using namespace Windows::Foundation;
dludwig@8322
    41
using namespace Windows::Graphics::Display;
dludwig@8322
    42
using namespace concurrency;
dludwig@8322
    43
dludwig@8322
    44
SDL_WinRTApp::SDL_WinRTApp() :
dludwig@8384
    45
    m_windowClosed(false),
dludwig@8384
    46
    m_windowVisible(true),
dludwig@8378
    47
    m_sdlWindowData(NULL),
dludwig@8378
    48
    m_useRelativeMouseMode(false)
dludwig@8322
    49
{
dludwig@8322
    50
}
dludwig@8322
    51
dludwig@8322
    52
void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
dludwig@8322
    53
{
dludwig@8384
    54
    applicationView->Activated +=
dludwig@8322
    55
        ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
dludwig@8322
    56
dludwig@8384
    57
    CoreApplication::Suspending +=
dludwig@8322
    58
        ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
dludwig@8322
    59
dludwig@8384
    60
    CoreApplication::Resuming +=
dludwig@8322
    61
        ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
dludwig@8322
    62
dludwig@8384
    63
    m_renderer = ref new SDL_winrtrenderer();
dludwig@8322
    64
}
dludwig@8322
    65
dludwig@8322
    66
void SDL_WinRTApp::SetWindow(CoreWindow^ window)
dludwig@8322
    67
{
dludwig@8384
    68
    window->SizeChanged += 
dludwig@8322
    69
        ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
dludwig@8322
    70
dludwig@8384
    71
    window->VisibilityChanged +=
dludwig@8384
    72
        ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
dludwig@8322
    73
dludwig@8384
    74
    window->Closed += 
dludwig@8322
    75
        ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
dludwig@8322
    76
dludwig@8384
    77
    window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
dludwig@8322
    78
dludwig@8384
    79
    window->PointerPressed +=
dludwig@8384
    80
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
dludwig@8322
    81
dludwig@8332
    82
    window->PointerReleased +=
dludwig@8384
    83
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
dludwig@8332
    84
dludwig@8384
    85
    window->PointerMoved +=
dludwig@8384
    86
        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
dludwig@8322
    87
dludwig@8378
    88
    // Retrieves relative-only mouse movements:
dludwig@8378
    89
    Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
dludwig@8378
    90
        ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
dludwig@8378
    91
dludwig@8336
    92
    window->KeyDown +=
dludwig@8384
    93
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
dludwig@8336
    94
dludwig@8384
    95
    window->KeyUp +=
dludwig@8384
    96
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
dludwig@8336
    97
dludwig@8336
    98
dludwig@8384
    99
    m_renderer->Initialize(CoreWindow::GetForCurrentThread());
dludwig@8322
   100
}
dludwig@8322
   101
dludwig@8322
   102
void SDL_WinRTApp::Load(Platform::String^ entryPoint)
dludwig@8322
   103
{
dludwig@8322
   104
}
dludwig@8322
   105
dludwig@8322
   106
void SDL_WinRTApp::Run()
dludwig@8322
   107
{
dludwig@8324
   108
    if (SDL_WinRT_main)
dludwig@8324
   109
    {
dludwig@8324
   110
        // TODO, WinRT: pass the C-style main() a reasonably realistic
dludwig@8324
   111
        // representation of command line arguments.
dludwig@8324
   112
        int argc = 0;
dludwig@8324
   113
        char **argv = NULL;
dludwig@8324
   114
        SDL_WinRT_main(argc, argv);
dludwig@8324
   115
    }
dludwig@8331
   116
}
dludwig@8324
   117
dludwig@8331
   118
void SDL_WinRTApp::PumpEvents()
dludwig@8331
   119
{
dludwig@8384
   120
    if (!m_windowClosed)
dludwig@8384
   121
    {
dludwig@8384
   122
        if (m_windowVisible)
dludwig@8384
   123
        {
dludwig@8384
   124
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
dludwig@8384
   125
        }
dludwig@8384
   126
        else
dludwig@8384
   127
        {
dludwig@8384
   128
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
dludwig@8384
   129
        }
dludwig@8384
   130
    }
dludwig@8322
   131
}
dludwig@8322
   132
dludwig@8342
   133
void SDL_WinRTApp::UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects)
dludwig@8342
   134
{
dludwig@8342
   135
    if (!m_windowClosed && m_windowVisible)
dludwig@8384
   136
    {
dludwig@8384
   137
        m_renderer->Render(surface, rects, numrects);
dludwig@8384
   138
        m_renderer->Present(); // This call is synchronized to the display frame rate.
dludwig@8384
   139
    }
dludwig@8342
   140
}
dludwig@8342
   141
dludwig@8322
   142
void SDL_WinRTApp::Uninitialize()
dludwig@8322
   143
{
dludwig@8322
   144
}
dludwig@8322
   145
dludwig@8322
   146
void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
dludwig@8322
   147
{
dludwig@8384
   148
    m_renderer->UpdateForWindowSizeChange();
dludwig@8322
   149
}
dludwig@8322
   150
dludwig@8322
   151
void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
dludwig@8322
   152
{
dludwig@8384
   153
    m_windowVisible = args->Visible;
dludwig@8322
   154
}
dludwig@8322
   155
dludwig@8322
   156
void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
dludwig@8322
   157
{
dludwig@8384
   158
    m_windowClosed = true;
dludwig@8322
   159
}
dludwig@8322
   160
dludwig@8322
   161
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
dludwig@8322
   162
{
dludwig@8333
   163
    if (m_sdlWindowData)
dludwig@8333
   164
    {
dludwig@8384
   165
        SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT);
dludwig@8333
   166
    }
dludwig@8332
   167
}
dludwig@8332
   168
dludwig@8332
   169
void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
dludwig@8332
   170
{
dludwig@8333
   171
    if (m_sdlWindowData)
dludwig@8333
   172
    {
dludwig@8384
   173
        SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT);
dludwig@8333
   174
    }
dludwig@8322
   175
}
dludwig@8322
   176
dludwig@8379
   177
static inline int _lround(float arg) {
dludwig@8379
   178
    if (arg >= 0.0f) {
dludwig@8379
   179
        return (int)floor(arg + 0.5f);
dludwig@8379
   180
    } else {
dludwig@8379
   181
        return (int)ceil(arg - 0.5f);
dludwig@8379
   182
    }
dludwig@8379
   183
}
dludwig@8379
   184
dludwig@8378
   185
void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
dludwig@8378
   186
{
dludwig@8378
   187
    if (m_sdlWindowData && m_useRelativeMouseMode) {
dludwig@8378
   188
        // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
dludwig@8378
   189
        // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
dludwig@8378
   190
        // MouseDelta field often reports very large values.  More information
dludwig@8378
   191
        // on this can be found at the following pages on MSDN:
dludwig@8378
   192
        //  - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
dludwig@8378
   193
        //  - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
dludwig@8378
   194
        //
dludwig@8378
   195
        // The values do not appear to be as large when running on some systems,
dludwig@8378
   196
        // most notably a Surface RT.  Furthermore, the values returned by
dludwig@8378
   197
        // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
dludwig@8378
   198
        // method, do not ever appear to be large, even when MouseEventArgs'
dludwig@8378
   199
        // MouseDelta is reporting to the contrary.
dludwig@8378
   200
        //
dludwig@8378
   201
        // On systems with the large-values behavior, it appears that the values
dludwig@8378
   202
        // get reported as if the screen's size is 65536 units in both the X and Y
dludwig@8378
   203
        // dimensions.  This can be viewed by using Windows' now-private, "Raw Input"
dludwig@8378
   204
        // APIs.  (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
dludwig@8378
   205
        //
dludwig@8378
   206
        // MSDN's documentation on MouseEventArgs' MouseDelta field (at
dludwig@8378
   207
        // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
dludwig@8378
   208
        // does not seem to indicate (to me) that its values should be so large.  It
dludwig@8378
   209
        // says that its values should be a "change in screen location".  I could
dludwig@8378
   210
        // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: 
dludwig@8378
   211
        // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
dludwig@8378
   212
        // indicates that these values are in DIPs, which is the same unit used
dludwig@8378
   213
        // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
dludwig@8378
   214
        // property.  See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
dludwig@8378
   215
        // for details.)
dludwig@8378
   216
        //
dludwig@8378
   217
        // To note, PointerMoved events are sent a 'RawPosition' value (via the
dludwig@8378
   218
        // CurrentPoint property in MouseEventArgs), however these do not seem
dludwig@8378
   219
        // to exhibit the same large-value behavior.
dludwig@8378
   220
        //
dludwig@8378
   221
        // The values passed via PointerMoved events can't always be used for relative
dludwig@8378
   222
        // mouse motion, unfortunately.  Its values are bound to the cursor's position,
dludwig@8378
   223
        // which stops when it hits one of the screen's edges.  This can be a problem in
dludwig@8378
   224
        // first person shooters, whereby it is normal for mouse motion to travel far
dludwig@8378
   225
        // along any one axis for a period of time.  MouseMoved events do not have the
dludwig@8378
   226
        // screen-bounding limitation, and can be used regardless of where the system's
dludwig@8378
   227
        // cursor is.
dludwig@8378
   228
        //
dludwig@8378
   229
        // One possible workaround would be to programmatically set the cursor's
dludwig@8378
   230
        // position to the screen's center (when SDL's relative mouse mode is enabled),
dludwig@8378
   231
        // however Windows RT does not yet seem to have the ability to set the cursor's
dludwig@8378
   232
        // position via a public API.  Win32 did this via an API call, SetCursorPos,
dludwig@8378
   233
        // however WinRT makes this function be private.  Apps that use it won't get
dludwig@8378
   234
        // approved for distribution in the Windows Store.  I've yet to be able to find
dludwig@8378
   235
        // a suitable, store-friendly counterpart for WinRT.
dludwig@8378
   236
        //
dludwig@8378
   237
        // There may be some room for a workaround whereby OnPointerMoved's values
dludwig@8378
   238
        // are compared to the values from OnMouseMoved in order to detect
dludwig@8378
   239
        // when this bug is active.  A suitable transformation could then be made to
dludwig@8378
   240
        // OnMouseMoved's values.  For now, however, the system-reported values are sent
dludwig@8379
   241
        // to SDL with minimal transformation: from native screen coordinates (in DIPs)
dludwig@8379
   242
        // to SDL window coordinates.
dludwig@8378
   243
        //
dludwig@8379
   244
        const Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
dludwig@8379
   245
        const Point mouseDeltaInSDLWindowCoords = TransformCursor(mouseDeltaInDIPs);
dludwig@8379
   246
        SDL_SendMouseMotion(
dludwig@8379
   247
            m_sdlWindowData->sdlWindow,
dludwig@8379
   248
            1,
dludwig@8379
   249
            _lround(mouseDeltaInSDLWindowCoords.X),
dludwig@8379
   250
            _lround(mouseDeltaInSDLWindowCoords.Y));
dludwig@8378
   251
    }
dludwig@8378
   252
}
dludwig@8378
   253
dludwig@8372
   254
// Applies necessary geometric transformations to raw cursor positions:
dludwig@8372
   255
Point SDL_WinRTApp::TransformCursor(Point rawPosition)
dludwig@8372
   256
{
dludwig@8372
   257
    if ( ! m_sdlWindowData || ! m_sdlWindowData->sdlWindow ) {
dludwig@8372
   258
        return rawPosition;
dludwig@8372
   259
    }
dludwig@8372
   260
    CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
dludwig@8372
   261
    Point outputPosition;
dludwig@8372
   262
    outputPosition.X = rawPosition.X * (((float32)m_sdlWindowData->sdlWindow->w) / nativeWindow->Bounds.Width);
dludwig@8372
   263
    outputPosition.Y = rawPosition.Y * (((float32)m_sdlWindowData->sdlWindow->h) / nativeWindow->Bounds.Height);
dludwig@8372
   264
    return outputPosition;
dludwig@8372
   265
}
dludwig@8372
   266
dludwig@8322
   267
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
dludwig@8322
   268
{
dludwig@8378
   269
    if (m_sdlWindowData && ! m_useRelativeMouseMode)
dludwig@8333
   270
    {
dludwig@8372
   271
        Point transformedPoint = TransformCursor(args->CurrentPoint->Position);
dludwig@8372
   272
        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
dludwig@8333
   273
    }
dludwig@8322
   274
}
dludwig@8322
   275
dludwig@8336
   276
static SDL_Scancode WinRT_Keycodes[] = {
dludwig@8336
   277
    SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
dludwig@8336
   278
    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
dludwig@8336
   279
    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
dludwig@8336
   280
    SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
dludwig@8336
   281
    SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
dludwig@8336
   282
    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
dludwig@8336
   283
    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
dludwig@8336
   284
    SDL_SCANCODE_UNKNOWN, // -- 7
dludwig@8336
   285
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Back -- 8  (maybe SDL_SCANCODE_AC_BACK ?)
dludwig@8336
   286
    SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
dludwig@8336
   287
    SDL_SCANCODE_UNKNOWN, // -- 10
dludwig@8336
   288
    SDL_SCANCODE_UNKNOWN, // -- 11
dludwig@8336
   289
    SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
dludwig@8336
   290
    SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
dludwig@8336
   291
    SDL_SCANCODE_UNKNOWN, // -- 14
dludwig@8336
   292
    SDL_SCANCODE_UNKNOWN, // -- 15
dludwig@8336
   293
    SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
dludwig@8336
   294
    SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
dludwig@8336
   295
    SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
dludwig@8336
   296
    SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
dludwig@8336
   297
    SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
dludwig@8336
   298
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
dludwig@8336
   299
    SDL_SCANCODE_UNKNOWN, // -- 22
dludwig@8336
   300
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
dludwig@8336
   301
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
dludwig@8336
   302
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
dludwig@8336
   303
    SDL_SCANCODE_UNKNOWN, // -- 26
dludwig@8336
   304
    SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
dludwig@8336
   305
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
dludwig@8336
   306
    SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
dludwig@8336
   307
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
dludwig@8336
   308
    SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31  (maybe SDL_SCANCODE_MODE ?)
dludwig@8336
   309
    SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
dludwig@8336
   310
    SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
dludwig@8336
   311
    SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
dludwig@8336
   312
    SDL_SCANCODE_END, // VirtualKey.End -- 35
dludwig@8336
   313
    SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
dludwig@8336
   314
    SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
dludwig@8336
   315
    SDL_SCANCODE_UP, // VirtualKey.Up -- 38
dludwig@8336
   316
    SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
dludwig@8336
   317
    SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
dludwig@8336
   318
    SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
dludwig@8336
   319
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42  (maybe SDL_SCANCODE_PRINTSCREEN ?)
dludwig@8336
   320
    SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
dludwig@8336
   321
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
dludwig@8336
   322
    SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
dludwig@8336
   323
    SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
dludwig@8336
   324
    SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
dludwig@8336
   325
    SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
dludwig@8336
   326
    SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
dludwig@8336
   327
    SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
dludwig@8336
   328
    SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
dludwig@8336
   329
    SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
dludwig@8336
   330
    SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
dludwig@8336
   331
    SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
dludwig@8336
   332
    SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
dludwig@8336
   333
    SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
dludwig@8336
   334
    SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
dludwig@8336
   335
    SDL_SCANCODE_UNKNOWN, // -- 58
dludwig@8336
   336
    SDL_SCANCODE_UNKNOWN, // -- 59
dludwig@8336
   337
    SDL_SCANCODE_UNKNOWN, // -- 60
dludwig@8336
   338
    SDL_SCANCODE_UNKNOWN, // -- 61
dludwig@8336
   339
    SDL_SCANCODE_UNKNOWN, // -- 62
dludwig@8336
   340
    SDL_SCANCODE_UNKNOWN, // -- 63
dludwig@8336
   341
    SDL_SCANCODE_UNKNOWN, // -- 64
dludwig@8336
   342
    SDL_SCANCODE_A, // VirtualKey.A -- 65
dludwig@8336
   343
    SDL_SCANCODE_B, // VirtualKey.B -- 66
dludwig@8336
   344
    SDL_SCANCODE_C, // VirtualKey.C -- 67
dludwig@8336
   345
    SDL_SCANCODE_D, // VirtualKey.D -- 68
dludwig@8336
   346
    SDL_SCANCODE_E, // VirtualKey.E -- 69
dludwig@8336
   347
    SDL_SCANCODE_F, // VirtualKey.F -- 70
dludwig@8336
   348
    SDL_SCANCODE_G, // VirtualKey.G -- 71
dludwig@8336
   349
    SDL_SCANCODE_H, // VirtualKey.H -- 72
dludwig@8336
   350
    SDL_SCANCODE_I, // VirtualKey.I -- 73
dludwig@8336
   351
    SDL_SCANCODE_J, // VirtualKey.J -- 74
dludwig@8336
   352
    SDL_SCANCODE_K, // VirtualKey.K -- 75
dludwig@8336
   353
    SDL_SCANCODE_L, // VirtualKey.L -- 76
dludwig@8336
   354
    SDL_SCANCODE_M, // VirtualKey.M -- 77
dludwig@8336
   355
    SDL_SCANCODE_N, // VirtualKey.N -- 78
dludwig@8336
   356
    SDL_SCANCODE_O, // VirtualKey.O -- 79
dludwig@8336
   357
    SDL_SCANCODE_P, // VirtualKey.P -- 80
dludwig@8336
   358
    SDL_SCANCODE_Q, // VirtualKey.Q -- 81
dludwig@8336
   359
    SDL_SCANCODE_R, // VirtualKey.R -- 82
dludwig@8336
   360
    SDL_SCANCODE_S, // VirtualKey.S -- 83
dludwig@8336
   361
    SDL_SCANCODE_T, // VirtualKey.T -- 84
dludwig@8336
   362
    SDL_SCANCODE_U, // VirtualKey.U -- 85
dludwig@8336
   363
    SDL_SCANCODE_V, // VirtualKey.V -- 86
dludwig@8336
   364
    SDL_SCANCODE_W, // VirtualKey.W -- 87
dludwig@8336
   365
    SDL_SCANCODE_X, // VirtualKey.X -- 88
dludwig@8336
   366
    SDL_SCANCODE_Y, // VirtualKey.Y -- 89
dludwig@8336
   367
    SDL_SCANCODE_Z, // VirtualKey.Z -- 90
dludwig@8336
   368
    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
dludwig@8336
   369
    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
dludwig@8336
   370
    SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
dludwig@8336
   371
    SDL_SCANCODE_UNKNOWN, // -- 94
dludwig@8336
   372
    SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
dludwig@8336
   373
    SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
dludwig@8336
   374
    SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
dludwig@8336
   375
    SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
dludwig@8336
   376
    SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
dludwig@8336
   377
    SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
dludwig@8336
   378
    SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
dludwig@8336
   379
    SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
dludwig@8336
   380
    SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
dludwig@8336
   381
    SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
dludwig@8336
   382
    SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
dludwig@8336
   383
    SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
dludwig@8336
   384
    SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
dludwig@8336
   385
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
dludwig@8336
   386
    SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
dludwig@8336
   387
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110  (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
dludwig@8336
   388
    SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
dludwig@8336
   389
    SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
dludwig@8336
   390
    SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
dludwig@8336
   391
    SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
dludwig@8336
   392
    SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
dludwig@8336
   393
    SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
dludwig@8336
   394
    SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
dludwig@8336
   395
    SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
dludwig@8336
   396
    SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
dludwig@8336
   397
    SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
dludwig@8336
   398
    SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
dludwig@8336
   399
    SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
dludwig@8336
   400
    SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
dludwig@8336
   401
    SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
dludwig@8336
   402
    SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
dludwig@8336
   403
    SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
dludwig@8336
   404
    SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
dludwig@8336
   405
    SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
dludwig@8336
   406
    SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
dludwig@8336
   407
    SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
dludwig@8336
   408
    SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
dludwig@8336
   409
    SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
dludwig@8336
   410
    SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
dludwig@8336
   411
    SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
dludwig@8336
   412
    SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
dludwig@8336
   413
    SDL_SCANCODE_UNKNOWN, // -- 136
dludwig@8336
   414
    SDL_SCANCODE_UNKNOWN, // -- 137
dludwig@8336
   415
    SDL_SCANCODE_UNKNOWN, // -- 138
dludwig@8336
   416
    SDL_SCANCODE_UNKNOWN, // -- 139
dludwig@8336
   417
    SDL_SCANCODE_UNKNOWN, // -- 140
dludwig@8336
   418
    SDL_SCANCODE_UNKNOWN, // -- 141
dludwig@8336
   419
    SDL_SCANCODE_UNKNOWN, // -- 142
dludwig@8336
   420
    SDL_SCANCODE_UNKNOWN, // -- 143
dludwig@8336
   421
    SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
dludwig@8336
   422
    SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
dludwig@8336
   423
    SDL_SCANCODE_UNKNOWN, // -- 146
dludwig@8336
   424
    SDL_SCANCODE_UNKNOWN, // -- 147
dludwig@8336
   425
    SDL_SCANCODE_UNKNOWN, // -- 148
dludwig@8336
   426
    SDL_SCANCODE_UNKNOWN, // -- 149
dludwig@8336
   427
    SDL_SCANCODE_UNKNOWN, // -- 150
dludwig@8336
   428
    SDL_SCANCODE_UNKNOWN, // -- 151
dludwig@8336
   429
    SDL_SCANCODE_UNKNOWN, // -- 152
dludwig@8336
   430
    SDL_SCANCODE_UNKNOWN, // -- 153
dludwig@8336
   431
    SDL_SCANCODE_UNKNOWN, // -- 154
dludwig@8336
   432
    SDL_SCANCODE_UNKNOWN, // -- 155
dludwig@8336
   433
    SDL_SCANCODE_UNKNOWN, // -- 156
dludwig@8336
   434
    SDL_SCANCODE_UNKNOWN, // -- 157
dludwig@8336
   435
    SDL_SCANCODE_UNKNOWN, // -- 158
dludwig@8336
   436
    SDL_SCANCODE_UNKNOWN, // -- 159
dludwig@8336
   437
    SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
dludwig@8336
   438
    SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
dludwig@8336
   439
    SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
dludwig@8336
   440
    SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
dludwig@8336
   441
    SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
dludwig@8336
   442
    SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
dludwig@8336
   443
};
dludwig@8336
   444
dludwig@8336
   445
static SDL_Scancode
dludwig@8336
   446
TranslateKeycode(int keycode)
dludwig@8336
   447
{
dludwig@8336
   448
    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
dludwig@8336
   449
    if (keycode < SDL_arraysize(WinRT_Keycodes)) {
dludwig@8336
   450
        scancode = WinRT_Keycodes[keycode];
dludwig@8336
   451
    }
dludwig@8336
   452
    if (scancode == SDL_SCANCODE_UNKNOWN) {
dludwig@8336
   453
        SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
dludwig@8336
   454
    }
dludwig@8336
   455
    return scancode;
dludwig@8336
   456
}
dludwig@8336
   457
dludwig@8336
   458
void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
dludwig@8336
   459
{
dludwig@8336
   460
#if 0
dludwig@8336
   461
    SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, scan code=%d, was down?=%s, vkey=%d\n",
dludwig@8336
   462
        (args->Handled ? "1" : "0"),
dludwig@8336
   463
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
dludwig@8336
   464
        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
dludwig@8336
   465
        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
dludwig@8336
   466
        args->KeyStatus.RepeatCount,
dludwig@8336
   467
        args->KeyStatus.ScanCode,
dludwig@8336
   468
        (args->KeyStatus.WasKeyDown ? "1" : "0"),
dludwig@8336
   469
        args->VirtualKey);
dludwig@8336
   470
    //args->Handled = true;
dludwig@8336
   471
    //VirtualKey vkey = args->VirtualKey;
dludwig@8336
   472
#endif
dludwig@8336
   473
    SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode((int)args->VirtualKey));
dludwig@8336
   474
}
dludwig@8336
   475
dludwig@8336
   476
void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
dludwig@8336
   477
{
dludwig@8336
   478
#if 0
dludwig@8336
   479
    SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, scan code=%d, was down?=%s, vkey=%d\n",
dludwig@8336
   480
        (args->Handled ? "1" : "0"),
dludwig@8336
   481
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
dludwig@8336
   482
        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
dludwig@8336
   483
        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
dludwig@8336
   484
        args->KeyStatus.RepeatCount,
dludwig@8336
   485
        args->KeyStatus.ScanCode,
dludwig@8336
   486
        (args->KeyStatus.WasKeyDown ? "1" : "0"),
dludwig@8336
   487
        args->VirtualKey);
dludwig@8336
   488
    //args->Handled = true;
dludwig@8336
   489
#endif
dludwig@8336
   490
    SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode((int)args->VirtualKey));
dludwig@8336
   491
}
dludwig@8336
   492
dludwig@8322
   493
void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
dludwig@8322
   494
{
dludwig@8384
   495
    CoreWindow::GetForCurrentThread()->Activate();
dludwig@8322
   496
}
dludwig@8322
   497
dludwig@8383
   498
static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event * event)
dludwig@8383
   499
{
dludwig@8383
   500
    if (event->type == SDL_WINDOWEVENT)
dludwig@8383
   501
    {
dludwig@8383
   502
        switch (event->window.event)
dludwig@8383
   503
        {
dludwig@8383
   504
            case SDL_WINDOWEVENT_MINIMIZED:
dludwig@8383
   505
            case SDL_WINDOWEVENT_RESTORED:
dludwig@8383
   506
                // Return 0 to indicate that the event should be removed from the
dludwig@8383
   507
                // event queue:
dludwig@8383
   508
                return 0;
dludwig@8383
   509
            default:
dludwig@8383
   510
                break;
dludwig@8383
   511
        }
dludwig@8383
   512
    }
dludwig@8383
   513
dludwig@8383
   514
    // Return 1 to indicate that the event should stay in the event queue:
dludwig@8383
   515
    return 1;
dludwig@8383
   516
}
dludwig@8383
   517
dludwig@8322
   518
void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
dludwig@8322
   519
{
dludwig@8384
   520
    // Save app state asynchronously after requesting a deferral. Holding a deferral
dludwig@8384
   521
    // indicates that the application is busy performing suspending operations. Be
dludwig@8384
   522
    // aware that a deferral may not be held indefinitely. After about five seconds,
dludwig@8384
   523
    // the app will be forced to exit.
dludwig@8384
   524
    SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
dludwig@8384
   525
    create_task([this, deferral]()
dludwig@8384
   526
    {
dludwig@8383
   527
        // Send a window-minimized event immediately to observers.
dludwig@8383
   528
        // CoreDispatcher::ProcessEvents, which is the backbone on which
dludwig@8383
   529
        // SDL_WinRTApp::PumpEvents is built, will not return to its caller
dludwig@8383
   530
        // once it sends out a suspend event.  Any events posted to SDL's
dludwig@8383
   531
        // event queue won't get received until the WinRT app is resumed.
dludwig@8383
   532
        // SDL_AddEventWatch() may be used to receive app-suspend events on
dludwig@8383
   533
        // WinRT.
dludwig@8383
   534
        //
dludwig@8383
   535
        // In order to prevent app-suspend events from being received twice:
dludwig@8383
   536
        // first via a callback passed to SDL_AddEventWatch, and second via
dludwig@8383
   537
        // SDL's event queue, the event will be sent to SDL, then immediately
dludwig@8383
   538
        // removed from the queue.
dludwig@8383
   539
        if (m_sdlWindowData)
dludwig@8383
   540
        {
dludwig@8383
   541
            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)
dludwig@8383
   542
            SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
dludwig@8383
   543
        }
dludwig@8384
   544
        deferral->Complete();
dludwig@8384
   545
    });
dludwig@8322
   546
}
dludwig@8383
   547
dludwig@8322
   548
void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
dludwig@8322
   549
{
dludwig@8384
   550
    // Restore any data or state that was unloaded on suspend. By default, data
dludwig@8384
   551
    // and state are persisted when resuming from suspend. Note that this event
dludwig@8384
   552
    // does not occur if the app was previously terminated.
dludwig@8383
   553
    if (m_sdlWindowData)
dludwig@8383
   554
    {
dludwig@8383
   555
        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)
dludwig@8383
   556
dludwig@8383
   557
        // Remove the app-resume event from the queue, as is done with the
dludwig@8383
   558
        // app-suspend event.
dludwig@8383
   559
        //
dludwig@8383
   560
        // TODO, WinRT: consider posting this event to the queue even though
dludwig@8383
   561
        // its counterpart, the app-suspend event, effectively has to be
dludwig@8383
   562
        // processed immediately.
dludwig@8383
   563
        SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
dludwig@8383
   564
    }
dludwig@8322
   565
}
dludwig@8322
   566
dludwig@8329
   567
SDL_DisplayMode SDL_WinRTApp::GetMainDisplayMode()
dludwig@8329
   568
{
dludwig@8329
   569
    SDL_DisplayMode mode;
dludwig@8329
   570
    SDL_zero(mode);
dludwig@8329
   571
    mode.format = SDL_PIXELFORMAT_RGB888;
dludwig@8329
   572
    mode.w = (int) CoreWindow::GetForCurrentThread()->Bounds.Width;
dludwig@8329
   573
    mode.h = (int) CoreWindow::GetForCurrentThread()->Bounds.Height;
dludwig@8329
   574
    mode.refresh_rate = 0;  // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
dludwig@8329
   575
    mode.driverdata = NULL;
dludwig@8329
   576
    return mode;
dludwig@8329
   577
}
dludwig@8329
   578
dludwig@8335
   579
const SDL_WindowData * SDL_WinRTApp::GetSDLWindowData() const
dludwig@8335
   580
{
dludwig@8335
   581
    return m_sdlWindowData;
dludwig@8335
   582
}
dludwig@8335
   583
dludwig@8334
   584
bool SDL_WinRTApp::HasSDLWindowData() const
dludwig@8334
   585
{
dludwig@8334
   586
    return (m_sdlWindowData != NULL);
dludwig@8334
   587
}
dludwig@8334
   588
dludwig@8378
   589
void SDL_WinRTApp::SetRelativeMouseMode(bool enable)
dludwig@8378
   590
{
dludwig@8378
   591
    m_useRelativeMouseMode = enable;
dludwig@8378
   592
}
dludwig@8378
   593
dludwig@8333
   594
void SDL_WinRTApp::SetSDLWindowData(const SDL_WindowData* windowData)
dludwig@8333
   595
{
dludwig@8333
   596
    m_sdlWindowData = windowData;
dludwig@8333
   597
}
dludwig@8333
   598
dludwig@8367
   599
void SDL_WinRTApp::ResizeMainTexture(int w, int h)
dludwig@8367
   600
{
dludwig@8367
   601
    m_renderer->ResizeMainTexture(w, h);
dludwig@8367
   602
}
dludwig@8367
   603
dludwig@8322
   604
IFrameworkView^ Direct3DApplicationSource::CreateView()
dludwig@8322
   605
{
dludwig@8329
   606
    // TODO, WinRT: see if this function (CreateView) can ever get called
dludwig@8329
   607
    // more than once.  For now, just prevent it from ever assigning
dludwig@8329
   608
    // SDL_WinRTGlobalApp more than once.
dludwig@8329
   609
    SDL_assert(!SDL_WinRTGlobalApp);
dludwig@8329
   610
    SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
dludwig@8329
   611
    if (!SDL_WinRTGlobalApp)
dludwig@8329
   612
    {
dludwig@8329
   613
        SDL_WinRTGlobalApp = app;
dludwig@8329
   614
    }
dludwig@8329
   615
    return app;
dludwig@8322
   616
}
dludwig@8322
   617
dludwig@8324
   618
__declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFunction)
dludwig@8322
   619
{
dludwig@8324
   620
    SDL_WinRT_main = mainFunction;
dludwig@8324
   621
    auto direct3DApplicationSource = ref new Direct3DApplicationSource();
dludwig@8384
   622
    CoreApplication::Run(direct3DApplicationSource);
dludwig@8384
   623
    return 0;
dludwig@8322
   624
}