diff options
Diffstat (limited to 'samples/DX_APIUsage/Main.cpp')
| -rw-r--r-- | samples/DX_APIUsage/Main.cpp | 159 |
1 files changed, 146 insertions, 13 deletions
diff --git a/samples/DX_APIUsage/Main.cpp b/samples/DX_APIUsage/Main.cpp index 386b4db..803d799 100644 --- a/samples/DX_APIUsage/Main.cpp +++ b/samples/DX_APIUsage/Main.cpp @@ -18,14 +18,15 @@ #include <fstream> #include <codecvt> #include <locale> +#include <array> #include <json/json.h> #include <Shlwapi.h> #ifdef GFESDKDEMO_BUILD_C -#include "GfeSDKHighlights.h" +#include "GfeSDKWrapper.h" #else -#include "GfeSDKHighlights.hpp" +#include "GfeSDKWrapper.hpp" using namespace GfeSDK; #endif @@ -119,7 +120,7 @@ struct HighlightsData std::vector<NVGSDK_Highlight> highlights; }; -HighlightsWrapper g_highlights; +GfeSdkWrapper g_highlights; NVGSDK_HighlightSignificance g_sigFilter = NVGSDK_HIGHLIGHT_SIGNIFICANCE_NONE; NVGSDK_HighlightType g_tagFilter = NVGSDK_HIGHLIGHT_TYPE_NONE; std::wstring_convert<std::codecvt_utf8<wchar_t>> g_converter; @@ -127,6 +128,127 @@ HighlightsData g_highlightsConfig; char const* GROUP1_ID = "GROUP1"; char const* GROUP2_ID = "GROUP2"; + +class SettingsManager +{ +public: + + enum class BackgroundColor + { + Default, + Red, + Blue, + }; + + SettingsManager(const std::wstring& configPath) + : m_color(BackgroundColor::Default), + m_configPath(configPath) + { + LoadConfig(); + } + + std::array<float, 4> GetBackgroundColorArray() const + { + switch(m_color) + { + case BackgroundColor::Red: + return { 0.25f, 0.10f, 0.10f, 0.55f }; + case BackgroundColor::Blue: + return { 0.10f, 0.10f, 0.25f, 0.55f }; + case BackgroundColor::Default: + default: + return { 0.0f, 0.25f, 0.25f, 0.55f }; + } + } + + std::string GetBackgroundColorString() const + { + switch(m_color) + { + case BackgroundColor::Red: + return "Red"; + case BackgroundColor::Blue: + return "Blue"; + case BackgroundColor::Default: + default: + return "Default"; + } + } + + void ToggleBackgroundColor() + { + switch(m_color) + { + case BackgroundColor::Default: + m_color = BackgroundColor::Red; + break; + case BackgroundColor::Red: + m_color = BackgroundColor::Blue; + break; + case BackgroundColor::Blue: + m_color = BackgroundColor::Default; + break; + default: + m_color = BackgroundColor::Default; + } + + SaveConfig(); + } + + void SaveConfig() + { + Json::Value root; + root["Background"] = GetBackgroundColorString(); + + std::ofstream f(m_configPath); + if(!f.good()) + { + TRACE("Cannot open config file for saving!"); + return; + } + + f << root; + } + + void LoadConfig() + { + std::ifstream f(m_configPath); + if(!f.good()) + { + return; + } + + Json::Value root; + + std::string errs; + Json::CharReaderBuilder builder; + if(!Json::parseFromStream(builder, f, &root, &errs)) + { + TRACE("FAILED to read json file\n"); + return; + } + + m_color = BackgroundColorFromString(root["Background"].asString()); + } + +private: + + static BackgroundColor BackgroundColorFromString(const std::string& c) + { + if(c == "Red") return BackgroundColor::Red; + if(c == "Blue") return BackgroundColor::Blue; + if(c == "Default") return BackgroundColor::Default; + + return BackgroundColor::Default; + } + + const std::wstring m_configPath; + BackgroundColor m_color; +}; + +std::unique_ptr<SettingsManager> g_settingsManager; + + AppState g_state = AppState::Init; //-------------------------------------------------------------------------------------- @@ -202,6 +324,11 @@ void ToggleTagBit(NVGSDK_HighlightType bit) g_tagFilter = static_cast<NVGSDK_HighlightType>(g_tagFilter ^ bit); } +void HandleOpsNotification() +{ + g_settingsManager->LoadConfig(); +} + //-------------------------------------------------------------------------------------- // Initialize the app //-------------------------------------------------------------------------------------- @@ -220,23 +347,26 @@ void InitApp() g_HUD.SetCallback(OnGUIEvent); - InitHighlightsWrapper(&g_highlights); + InitGfeSdkWrapper(&g_highlights); // Find the path to the executable - char path[MAX_PATH]; - GetModuleFileNameA(NULL, path, MAX_PATH); - PathRemoveFileSpecA(path); - std::string pathStr(path); + wchar_t path[MAX_PATH] = { 0 }; + GetModuleFileNameW(NULL, path, MAX_PATH); + PathRemoveFileSpecW(path); + const std::wstring pathStr(path); + g_settingsManager.reset(new SettingsManager(pathStr + L"/settings.json")); + + // Load highlights config Json::Value jsonHighlightsConfig; { - std::ifstream inFile(pathStr + "/highlights_config.json"); + std::ifstream inFile(pathStr + L"/highlights_config.json"); if (!inFile.good()) { - inFile = std::ifstream(pathStr + "/../highlights_config.json"); + inFile = std::ifstream(pathStr + L"/../highlights_config.json"); if (!inFile.good()) { - inFile = std::ifstream(pathStr + "/../../highlights_config.json"); + inFile = std::ifstream(pathStr + L"/../../highlights_config.json"); } } @@ -281,6 +411,7 @@ void InitApp() int iY = 10; int const PAD = 26; g_HUD.AddButtonCallback([]() {DXUTToggleFullScreen(); }, L"Toggle full screen", 0, iY, 170, 23); + g_HUD.AddButtonCallback([]() { g_settingsManager->ToggleBackgroundColor(); }, L"Toggle background color", 0, iY += PAD, 170, 23); g_HUD.AddButtonCallback([]() {g_highlights.OnRequestLanguage(); }, L"Get Overlay Language", 0, iY += PAD, 170, 23); g_HUD.AddButtonCallback([]() {g_highlights.OnRequestUserSettings(); }, L"Get User Settings", 0, iY += PAD, 170, 23); @@ -407,6 +538,9 @@ void RenderText() g_pTxtHelper->DrawTextLine( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) ); g_pTxtHelper->DrawTextLine( DXUTGetDeviceStats() ); + // Settings + g_pTxtHelper->DrawFormattedTextLine(L"Background color: %S", g_settingsManager->GetBackgroundColorString().c_str()); + // Draw help if( g_bShowHelp ) { @@ -724,9 +858,8 @@ void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* case AppState::Main: { // Clear the render target and depth stencil - float ClearColor[4] = { 0.0f, 0.25f, 0.25f, 0.55f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); - pd3dImmediateContext->ClearRenderTargetView(pRTV, ClearColor); + pd3dImmediateContext->ClearRenderTargetView(pRTV, g_settingsManager->GetBackgroundColorArray().data()); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH, 1.0, 0); |