From e5d0cb92cfd69c575fb56a433299d78d06d4a96c Mon Sep 17 00:00:00 2001 From: InkSoul Date: Thu, 1 Jun 2023 00:05:36 +0800 Subject: [PATCH] update UI for file open dialog (BROKEN!) --- src/render/GUIFunction.cpp | 17 +++++++++++++---- src/render/GUIFunction.h | 18 +++++++----------- src/render/render.cpp | 22 +++++++++++++++++++--- src/render/render.h | 1 + 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/render/GUIFunction.cpp b/src/render/GUIFunction.cpp index ecce00c..339b621 100644 --- a/src/render/GUIFunction.cpp +++ b/src/render/GUIFunction.cpp @@ -3,10 +3,15 @@ // win32 api IFileOpenDialog -PWSTR GUIFunction::openFileFolderDialog(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) + + +// TO DO: rewrite this function to bool and get file path through public value +bool GUIFunction::openFileFolderDialog() { //initialize COM lib + HRESULT hResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + if (SUCCEEDED(hResult)) { IFileOpenDialog* pFileOpen = nullptr; @@ -27,21 +32,25 @@ PWSTR GUIFunction::openFileFolderDialog(HINSTANCE hInstance, HINSTANCE, PWSTR pC { PWSTR pszFilePath; hResult = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); - + filePath = pszFilePath; // Display the file name to the user. if (SUCCEEDED(hResult)) { MessageBoxW(NULL, pszFilePath, L"File Path", MB_OK); CoTaskMemFree(pszFilePath); - stringFilePath == pszFilePath; + } pItem->Release(); } + return true; } pFileOpen->Release(); + return false; } + CoUninitialize(); + return false; } - return stringFilePath; + return false; }; \ No newline at end of file diff --git a/src/render/GUIFunction.h b/src/render/GUIFunction.h index d2e1893..5ee9c71 100644 --- a/src/render/GUIFunction.h +++ b/src/render/GUIFunction.h @@ -8,20 +8,16 @@ class GUIFunction { public: - GUIFunction(); - ~GUIFunction(); - PWSTR openFileFolderDialog(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow); + PWSTR filePath; + + + + bool openFileFolderDialog(); private: - PWSTR stringFilePath; + }; -GUIFunction::GUIFunction() -{ -} - -GUIFunction::~GUIFunction() -{ -} + diff --git a/src/render/render.cpp b/src/render/render.cpp index 89d0226..3f7a62b 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -1,4 +1,3 @@ -#pragma once /* * Vulkan Example - glTF scene loading and rendering @@ -31,6 +30,7 @@ #include "render.h" +#include "GUIFunction.h" @@ -1287,7 +1287,7 @@ auto tEnd = std::chrono::high_resolution_clock::now(); auto tDiff = std::chrono::duration(tEnd - tStart).count(); - std::cout << "Generating pre-filtered enivornment cube with " << numMips << " mip levels took " << tDiff << " ms" << std::endl; + std::cout << "Generating pre-filtered environment cube with " << numMips << " mip levels took " << tDiff << " ms" << std::endl; } void VulkanExample::GenerateBRDFLUT() @@ -1382,7 +1382,7 @@ dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; - // Create the actual renderpass + // Create the actual render pass VkRenderPassCreateInfo renderPassCI = vks::initializers::renderPassCreateInfo(); renderPassCI.attachmentCount = 1; renderPassCI.pAttachments = &attDesc; @@ -1650,6 +1650,22 @@ { overlay->checkBox("Pause", &paused); } + if (overlay->header("file")) + { + if (overlay->button("select model")) + { + GUIFunction guiFunc{}; + + if (guiFunc.openFileFolderDialog()) + { + std::cout << guiFunc.filePath << std::endl; + } + else + { + std::cerr << "file select error" << std::endl; + } + } + } } diff --git a/src/render/render.h b/src/render/render.h index fb7c267..b5c0356 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -27,6 +27,7 @@ #include "vulkanexamplebase.h" #include "glTFModel.h" + #define ENABLE_VALIDATION false