mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2025-02-06 15:41:16 +00:00
added more GUI helper functions
This commit is contained in:
parent
68d32e69e9
commit
aa88622348
4 changed files with 109 additions and 26 deletions
|
@ -99,6 +99,33 @@ void ToggleBooleanWithShortcut(bool& value, ImGuiKey key)
|
|||
}
|
||||
}
|
||||
|
||||
void RadioButton(int* argValue, float titleWidth, const char* title, int count, ...)
|
||||
{
|
||||
const float x = ImGui::GetCursorPosX();
|
||||
ImGui::Text(title);
|
||||
ImGui::SameLine();
|
||||
if(titleWidth > 0.0f)
|
||||
{
|
||||
ImGui::SetCursorPosX(x + titleWidth);
|
||||
}
|
||||
|
||||
ImGui::PushID(title);
|
||||
va_list args;
|
||||
va_start(args, count);
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
const char* const name = va_arg(args, const char*);
|
||||
const int value = va_arg(args, int);
|
||||
ImGui::RadioButton(name, argValue, value);
|
||||
if(i < count - 1)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
}
|
||||
}
|
||||
va_end(args);
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
struct FileDialog
|
||||
{
|
||||
char folder[MAX_QPATH];
|
||||
|
@ -110,10 +137,13 @@ struct FileDialog
|
|||
int fileCount;
|
||||
int selectedFileIndex;
|
||||
bool saveMode;
|
||||
bool folderMode;
|
||||
};
|
||||
|
||||
static FileDialog saveFile;
|
||||
static FileDialog openFile;
|
||||
static FileDialog saveFolder;
|
||||
static FileDialog openFolder;
|
||||
|
||||
static bool PathHasExtension(const char* path, const char* extension)
|
||||
{
|
||||
|
@ -149,10 +179,17 @@ static bool DoFileDialog(FileDialog& dialog)
|
|||
bool success = false;
|
||||
if(ImGui::BeginPopupModal(dialog.dialogName, NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
if(BeginTable("Files", 1))
|
||||
if(BeginTable(dialog.folderMode ? "Folders" : "Files", 1))
|
||||
{
|
||||
for(int i = 0; i < dialog.fileCount; i++)
|
||||
{
|
||||
if(dialog.folderMode &&
|
||||
(Q_stricmp(dialog.filePaths[i], ".") == 0 ||
|
||||
Q_stricmp(dialog.filePaths[i], "..") == 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
if(ImGui::Selectable(dialog.filePaths[i], i == dialog.selectedFileIndex,
|
||||
|
@ -167,7 +204,7 @@ static bool DoFileDialog(FileDialog& dialog)
|
|||
|
||||
if(dialog.saveMode)
|
||||
{
|
||||
if(ImGui::InputText("File path", dialog.fileName, sizeof(dialog.fileName)))
|
||||
if(ImGui::InputText(dialog.folderMode ? "Folder path" : "File path", dialog.fileName, sizeof(dialog.fileName)))
|
||||
{
|
||||
dialog.selectedFileIndex = -1;
|
||||
}
|
||||
|
@ -222,38 +259,68 @@ static bool DoFileDialog(FileDialog& dialog)
|
|||
return success;
|
||||
}
|
||||
|
||||
void OpenSaveFileDialog(const char* folder, const char* extension)
|
||||
void SaveFileDialog_Open(const char* folder, const char* extension)
|
||||
{
|
||||
Q_assert(extension[0] == '.');
|
||||
OpenFileDialog(saveFile, folder, extension);
|
||||
}
|
||||
|
||||
bool SaveFileDialog()
|
||||
bool SaveFileDialog_Do()
|
||||
{
|
||||
return DoFileDialog(saveFile);
|
||||
}
|
||||
|
||||
const char* GetSaveFileDialogPath()
|
||||
const char* SaveFileDialog_GetPath()
|
||||
{
|
||||
return saveFile.filePath;
|
||||
}
|
||||
|
||||
void OpenOpenFileDialog(const char* folder, const char* extension)
|
||||
void OpenFileDialog_Open(const char* folder, const char* extension)
|
||||
{
|
||||
Q_assert(extension[0] == '.');
|
||||
OpenFileDialog(openFile, folder, extension);
|
||||
}
|
||||
|
||||
bool OpenFileDialog()
|
||||
bool OpenFileDialog_Do()
|
||||
{
|
||||
return DoFileDialog(openFile);
|
||||
}
|
||||
|
||||
const char* GetOpenFileDialogPath()
|
||||
const char* OpenFileDialog_GetPath()
|
||||
{
|
||||
return openFile.filePath;
|
||||
}
|
||||
|
||||
void SaveFolderDialog_Open(const char* folder)
|
||||
{
|
||||
OpenFileDialog(saveFolder, folder, "/");
|
||||
}
|
||||
|
||||
bool SaveFolderDialog_Do()
|
||||
{
|
||||
return DoFileDialog(saveFolder);
|
||||
}
|
||||
|
||||
const char* SaveFolderDialog_GetPath()
|
||||
{
|
||||
return saveFolder.filePath;
|
||||
}
|
||||
|
||||
void OpenFolderDialog_Open(const char* folder)
|
||||
{
|
||||
OpenFileDialog(openFolder, folder, "/");
|
||||
}
|
||||
|
||||
bool OpenFolderDialog_Do()
|
||||
{
|
||||
return DoFileDialog(openFolder);
|
||||
}
|
||||
|
||||
const char* OpenFolderDialog_GetPath()
|
||||
{
|
||||
return openFolder.filePath;
|
||||
}
|
||||
|
||||
struct MainMenuItem
|
||||
{
|
||||
GUI_MainMenu::Id menu;
|
||||
|
@ -399,6 +466,9 @@ static void ImGUI_ApplyTheme()
|
|||
colors[ImGuiCol_TabHovered] = hover;
|
||||
colors[ImGuiCol_TabActive] = active;
|
||||
colors[ImGuiCol_NavHighlight] = hover;
|
||||
colors[ImGuiCol_Separator] = hover;
|
||||
colors[ImGuiCol_SeparatorHovered] = hover;
|
||||
colors[ImGuiCol_SeparatorActive] = hover;
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.WindowPadding = ImVec2(8.00f, 8.00f);
|
||||
|
@ -613,6 +683,11 @@ void CL_IMGUI_Init()
|
|||
saveFile.saveMode = true;
|
||||
saveFile.dialogName = "Save file";
|
||||
openFile.dialogName = "Open file";
|
||||
saveFolder.folderMode = true;
|
||||
saveFolder.saveMode = true;
|
||||
saveFolder.dialogName = "Save folder";
|
||||
openFolder.folderMode = true;
|
||||
openFolder.dialogName = "Open folder";
|
||||
}
|
||||
|
||||
void CL_IMGUI_Frame()
|
||||
|
|
|
@ -36,12 +36,19 @@ void TableRow2(const char* item0, int item1);
|
|||
void TableRow2(const char* item0, float item1, const char* format = "%g");
|
||||
bool IsShortcutPressed(ImGuiKey key);
|
||||
void ToggleBooleanWithShortcut(bool& value, ImGuiKey key);
|
||||
void OpenSaveFileDialog(const char* folder, const char* extension);
|
||||
bool SaveFileDialog(); // true when the user clicked the save button
|
||||
const char* GetSaveFileDialogPath();
|
||||
void OpenOpenFileDialog(const char* folder, const char* extension);
|
||||
bool OpenFileDialog(); // true when the user clicked the open button
|
||||
const char* GetOpenFileDialogPath();
|
||||
void RadioButton(int* value, float titleWidth, const char* title, int count, ...); // count (const char* name, int value) pairs
|
||||
void SaveFileDialog_Open(const char* folder, const char* extension);
|
||||
bool SaveFileDialog_Do(); // true when the user clicked the save button
|
||||
const char* SaveFileDialog_GetPath();
|
||||
void OpenFileDialog_Open(const char* folder, const char* extension);
|
||||
bool OpenFileDialog_Do(); // true when the user clicked the open button
|
||||
const char* OpenFileDialog_GetPath();
|
||||
void SaveFolderDialog_Open(const char* folder);
|
||||
bool SaveFolderDialog_Do(); // true when the user clicked the save button
|
||||
const char* SaveFolderDialog_GetPath();
|
||||
void OpenFolderDialog_Open(const char* folder);
|
||||
bool OpenFolderDialog_Do(); // true when the user clicked the open button
|
||||
const char* OpenFolderDialog_GetPath();
|
||||
|
||||
#define MAIN_MENU_LIST(M) \
|
||||
M(Tools, "Tools") \
|
||||
|
|
|
@ -180,12 +180,12 @@ void SunlightEditor::DrawGUI()
|
|||
ImGui::NewLine();
|
||||
if(ImGui::Button("Save Config..."))
|
||||
{
|
||||
OpenSaveFileDialog("sun", ".sun");
|
||||
SaveFileDialog_Open("sun", ".sun");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("Open Config..."))
|
||||
{
|
||||
OpenOpenFileDialog("sun", ".sun");
|
||||
OpenFileDialog_Open("sun", ".sun");
|
||||
}
|
||||
if(skyShader != NULL)
|
||||
{
|
||||
|
@ -196,14 +196,14 @@ void SunlightEditor::DrawGUI()
|
|||
}
|
||||
}
|
||||
|
||||
if(SaveFileDialog())
|
||||
if(SaveFileDialog_Do())
|
||||
{
|
||||
SaveSunFile(GetSaveFileDialogPath());
|
||||
SaveSunFile(SaveFileDialog_GetPath());
|
||||
}
|
||||
|
||||
if(OpenFileDialog())
|
||||
if(OpenFileDialog_Do())
|
||||
{
|
||||
LoadSunFile(GetOpenFileDialogPath());
|
||||
LoadSunFile(OpenFileDialog_GetPath());
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
|
|
@ -1390,12 +1390,12 @@ void VolumetricLight::DrawGUI()
|
|||
ImGui::SameLine();
|
||||
if(fogCount > 0 && ImGui::Button("Save Config..."))
|
||||
{
|
||||
OpenSaveFileDialog("fogs", ".fogs");
|
||||
SaveFileDialog_Open("fogs", ".fogs");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("Open Config..."))
|
||||
{
|
||||
OpenOpenFileDialog("fogs", ".fogs");
|
||||
OpenFileDialog_Open("fogs", ".fogs");
|
||||
}
|
||||
|
||||
const char* axisNames[3] = { "X", "Y", "Z" };
|
||||
|
@ -1467,16 +1467,17 @@ void VolumetricLight::DrawGUI()
|
|||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
|
||||
if(SaveFileDialog())
|
||||
if(SaveFileDialog_Do())
|
||||
{
|
||||
SaveFogFile(GetSaveFileDialogPath());
|
||||
SaveFogFile(SaveFileDialog_GetPath());
|
||||
}
|
||||
|
||||
if(OpenFileDialog())
|
||||
if(OpenFileDialog_Do())
|
||||
{
|
||||
LoadFogFile(GetOpenFileDialogPath());
|
||||
LoadFogFile(OpenFileDialog_GetPath());
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
|
Loading…
Reference in a new issue