Handle Quit event more gracefully

This commit is contained in:
elasota
2020-04-18 05:51:39 -04:00
parent 94f26d0be1
commit 69e3fb3023
9 changed files with 87 additions and 3 deletions

View File

@@ -0,0 +1,16 @@
#include "AppEventHandler.h"
namespace PortabilityLayer
{
IAppEventHandler *AppEventHandler::ms_instance;
IAppEventHandler *AppEventHandler::GetInstance()
{
return ms_instance;
}
void AppEventHandler::SetInstance(IAppEventHandler *instance)
{
ms_instance = instance;
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
namespace PortabilityLayer
{
struct IAppEventHandler
{
virtual void OnQuit() = 0;
};
class AppEventHandler
{
public:
static IAppEventHandler *GetInstance();
static void SetInstance(IAppEventHandler *instance);
private:
static IAppEventHandler *ms_instance;
};
}

View File

@@ -1,4 +1,5 @@
#include "PLCore.h"
#include "AppEventHandler.h"
#include "PLEventQueue.h"
#include "PLKeyEncoding.h"
#include "PLMovies.h"
@@ -135,6 +136,14 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
case GpVOSEventTypes::kVideoResolutionChanged:
TranslateVideoResolutionChangedEvent(vosEvent->m_event.m_resolutionChangedEvent);
break;
case GpVOSEventTypes::kQuit:
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp);
if (PortabilityLayer::IAppEventHandler *appHandler = PortabilityLayer::AppEventHandler::GetInstance())
appHandler->OnQuit();
break;
}
}

View File

@@ -146,6 +146,7 @@
<ClInclude Include="AEHandlerDesc.h" />
<ClInclude Include="AEManager.h" />
<ClInclude Include="AntiAliasTable.h" />
<ClInclude Include="AppEventHandler.h" />
<ClInclude Include="ArrayTools.h" />
<ClInclude Include="BinarySearch.h" />
<ClInclude Include="BinHex4.h" />
@@ -303,6 +304,7 @@
<ClCompile Include="..\stb\stb_image_write.c" />
<ClCompile Include="AEManager.cpp" />
<ClCompile Include="AntiAliasTable.cpp" />
<ClCompile Include="AppEventHandler.cpp" />
<ClCompile Include="BinHex4.cpp" />
<ClCompile Include="BitmapImage.cpp" />
<ClCompile Include="ByteSwap.cpp" />

View File

@@ -483,6 +483,9 @@
<ClInclude Include="ArrayTools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AppEventHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CFileStream.cpp">
@@ -758,5 +761,8 @@
<ClCompile Include="TextPlacer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AppEventHandler.cpp">
<Filter>Header Files</Filter>
</ClCompile>
</ItemGroup>
</Project>