Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::FileDialogs Class Reference

Cross-platform file dialog utilities. More...

#include <PlatformUtils.h>

Static Public Member Functions

static std::string OpenFile (const char *filter)
 Opens a file dialog to select a file to open.
static std::string SaveFile (const char *filter)
 Opens a file dialog to select a location to save a file.

Detailed Description

Cross-platform file dialog utilities.

Member Function Documentation

◆ OpenFile()

std::string Vesper::FileDialogs::OpenFile ( const char * filter)
static

Opens a file dialog to select a file to open.

Parameters
filterThe file type filter for the dialog.
Returns
The selected file path or an empty string if cancelled.
12 {
13
14 OPENFILENAMEA ofn;
15 CHAR szFile[260] = { 0 };
16 ZeroMemory(&ofn, sizeof(ofn));
17 ofn.lStructSize = sizeof(ofn);
18 ofn.hwndOwner = glfwGetWin32Window((GLFWwindow*)Vesper::Application::Get().GetWindow().GetNativeWindow());
19 ofn.lpstrFile = szFile;
20 ofn.nMaxFile = sizeof(szFile);
21 ofn.lpstrFilter = filter;
22 ofn.nFilterIndex = 1;
23 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
24 if (GetOpenFileNameA(&ofn) == TRUE)
25 return std::string(ofn.lpstrFile);
26 return std::string();
27 }
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:67

◆ SaveFile()

std::string Vesper::FileDialogs::SaveFile ( const char * filter)
static

Opens a file dialog to select a location to save a file.

Parameters
filterThe file type filter for the dialog.
Returns
The selected file path or an empty string if cancelled.
29 {
30
31 OPENFILENAMEA ofn;
32 CHAR szFile[260] = { 0 };
33 CHAR currentDir[256] = { 0 };
34 ZeroMemory(&ofn, sizeof(OPENFILENAME));
35 ofn.lStructSize = sizeof(OPENFILENAME);
36 ofn.hwndOwner = glfwGetWin32Window((GLFWwindow*)Application::Get().GetWindow().GetNativeWindow());
37 ofn.lpstrFile = szFile;
38 ofn.nMaxFile = sizeof(szFile);
39 if (GetCurrentDirectoryA(256, currentDir))
40 ofn.lpstrInitialDir = currentDir;
41 ofn.lpstrFilter = filter;
42 ofn.nFilterIndex = 1;
43 ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR;
44
45 // Sets the default extension by extracting it from the filter
46 ofn.lpstrDefExt = strchr(filter, '\0') + 1;
47
48 if (GetSaveFileNameA(&ofn) == TRUE)
49 return ofn.lpstrFile;
50
51 return std::string();
52
53 }

The documentation for this class was generated from the following files: