src/video/windowsrt/SDL_WinRTApp.cpp
changeset 8384 bc7a52629e1e
parent 8383 1f415392ccf0
child 8385 e954dfbf2ecc
     1.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Jan 08 22:50:29 2013 -0500
     1.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Jan 08 23:11:22 2013 -0500
     1.3 @@ -42,8 +42,8 @@
     1.4  using namespace concurrency;
     1.5  
     1.6  SDL_WinRTApp::SDL_WinRTApp() :
     1.7 -	m_windowClosed(false),
     1.8 -	m_windowVisible(true),
     1.9 +    m_windowClosed(false),
    1.10 +    m_windowVisible(true),
    1.11      m_sdlWindowData(NULL),
    1.12      m_useRelativeMouseMode(false)
    1.13  {
    1.14 @@ -51,52 +51,52 @@
    1.15  
    1.16  void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
    1.17  {
    1.18 -	applicationView->Activated +=
    1.19 +    applicationView->Activated +=
    1.20          ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
    1.21  
    1.22 -	CoreApplication::Suspending +=
    1.23 +    CoreApplication::Suspending +=
    1.24          ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
    1.25  
    1.26 -	CoreApplication::Resuming +=
    1.27 +    CoreApplication::Resuming +=
    1.28          ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
    1.29  
    1.30 -	m_renderer = ref new SDL_winrtrenderer();
    1.31 +    m_renderer = ref new SDL_winrtrenderer();
    1.32  }
    1.33  
    1.34  void SDL_WinRTApp::SetWindow(CoreWindow^ window)
    1.35  {
    1.36 -	window->SizeChanged += 
    1.37 +    window->SizeChanged += 
    1.38          ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
    1.39  
    1.40 -	window->VisibilityChanged +=
    1.41 -		ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
    1.42 +    window->VisibilityChanged +=
    1.43 +        ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
    1.44  
    1.45 -	window->Closed += 
    1.46 +    window->Closed += 
    1.47          ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
    1.48  
    1.49 -	window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
    1.50 +    window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
    1.51  
    1.52 -	window->PointerPressed +=
    1.53 -		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
    1.54 +    window->PointerPressed +=
    1.55 +        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
    1.56  
    1.57      window->PointerReleased +=
    1.58 -		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
    1.59 +        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
    1.60  
    1.61 -	window->PointerMoved +=
    1.62 -		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
    1.63 +    window->PointerMoved +=
    1.64 +        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
    1.65  
    1.66      // Retrieves relative-only mouse movements:
    1.67      Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
    1.68          ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
    1.69  
    1.70      window->KeyDown +=
    1.71 -		ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
    1.72 +        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
    1.73  
    1.74 -	window->KeyUp +=
    1.75 -		ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
    1.76 +    window->KeyUp +=
    1.77 +        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
    1.78  
    1.79  
    1.80 -	m_renderer->Initialize(CoreWindow::GetForCurrentThread());
    1.81 +    m_renderer->Initialize(CoreWindow::GetForCurrentThread());
    1.82  }
    1.83  
    1.84  void SDL_WinRTApp::Load(Platform::String^ entryPoint)
    1.85 @@ -117,26 +117,26 @@
    1.86  
    1.87  void SDL_WinRTApp::PumpEvents()
    1.88  {
    1.89 -	if (!m_windowClosed)
    1.90 -	{
    1.91 -		if (m_windowVisible)
    1.92 -		{
    1.93 -			CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
    1.94 -		}
    1.95 -		else
    1.96 -		{
    1.97 -			CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
    1.98 -		}
    1.99 -	}
   1.100 +    if (!m_windowClosed)
   1.101 +    {
   1.102 +        if (m_windowVisible)
   1.103 +        {
   1.104 +            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
   1.105 +        }
   1.106 +        else
   1.107 +        {
   1.108 +            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
   1.109 +        }
   1.110 +    }
   1.111  }
   1.112  
   1.113  void SDL_WinRTApp::UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects)
   1.114  {
   1.115      if (!m_windowClosed && m_windowVisible)
   1.116 -	{
   1.117 -		m_renderer->Render(surface, rects, numrects);
   1.118 -		m_renderer->Present(); // This call is synchronized to the display frame rate.
   1.119 -	}
   1.120 +    {
   1.121 +        m_renderer->Render(surface, rects, numrects);
   1.122 +        m_renderer->Present(); // This call is synchronized to the display frame rate.
   1.123 +    }
   1.124  }
   1.125  
   1.126  void SDL_WinRTApp::Uninitialize()
   1.127 @@ -145,24 +145,24 @@
   1.128  
   1.129  void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
   1.130  {
   1.131 -	m_renderer->UpdateForWindowSizeChange();
   1.132 +    m_renderer->UpdateForWindowSizeChange();
   1.133  }
   1.134  
   1.135  void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
   1.136  {
   1.137 -	m_windowVisible = args->Visible;
   1.138 +    m_windowVisible = args->Visible;
   1.139  }
   1.140  
   1.141  void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
   1.142  {
   1.143 -	m_windowClosed = true;
   1.144 +    m_windowClosed = true;
   1.145  }
   1.146  
   1.147  void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
   1.148  {
   1.149      if (m_sdlWindowData)
   1.150      {
   1.151 -    	SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT);
   1.152 +        SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT);
   1.153      }
   1.154  }
   1.155  
   1.156 @@ -170,7 +170,7 @@
   1.157  {
   1.158      if (m_sdlWindowData)
   1.159      {
   1.160 -    	SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT);
   1.161 +        SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT);
   1.162      }
   1.163  }
   1.164  
   1.165 @@ -492,7 +492,7 @@
   1.166  
   1.167  void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
   1.168  {
   1.169 -	CoreWindow::GetForCurrentThread()->Activate();
   1.170 +    CoreWindow::GetForCurrentThread()->Activate();
   1.171  }
   1.172  
   1.173  static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event * event)
   1.174 @@ -517,13 +517,13 @@
   1.175  
   1.176  void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
   1.177  {
   1.178 -	// Save app state asynchronously after requesting a deferral. Holding a deferral
   1.179 -	// indicates that the application is busy performing suspending operations. Be
   1.180 -	// aware that a deferral may not be held indefinitely. After about five seconds,
   1.181 -	// the app will be forced to exit.
   1.182 -	SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
   1.183 -	create_task([this, deferral]()
   1.184 -	{
   1.185 +    // Save app state asynchronously after requesting a deferral. Holding a deferral
   1.186 +    // indicates that the application is busy performing suspending operations. Be
   1.187 +    // aware that a deferral may not be held indefinitely. After about five seconds,
   1.188 +    // the app will be forced to exit.
   1.189 +    SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
   1.190 +    create_task([this, deferral]()
   1.191 +    {
   1.192          // Send a window-minimized event immediately to observers.
   1.193          // CoreDispatcher::ProcessEvents, which is the backbone on which
   1.194          // SDL_WinRTApp::PumpEvents is built, will not return to its caller
   1.195 @@ -541,15 +541,15 @@
   1.196              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)
   1.197              SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
   1.198          }
   1.199 -		deferral->Complete();
   1.200 -	});
   1.201 +        deferral->Complete();
   1.202 +    });
   1.203  }
   1.204  
   1.205  void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
   1.206  {
   1.207 -	// Restore any data or state that was unloaded on suspend. By default, data
   1.208 -	// and state are persisted when resuming from suspend. Note that this event
   1.209 -	// does not occur if the app was previously terminated.
   1.210 +    // Restore any data or state that was unloaded on suspend. By default, data
   1.211 +    // and state are persisted when resuming from suspend. Note that this event
   1.212 +    // does not occur if the app was previously terminated.
   1.213      if (m_sdlWindowData)
   1.214      {
   1.215          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)
   1.216 @@ -619,6 +619,6 @@
   1.217  {
   1.218      SDL_WinRT_main = mainFunction;
   1.219      auto direct3DApplicationSource = ref new Direct3DApplicationSource();
   1.220 -	CoreApplication::Run(direct3DApplicationSource);
   1.221 -	return 0;
   1.222 +    CoreApplication::Run(direct3DApplicationSource);
   1.223 +    return 0;
   1.224  }