Skip to content

Commit

Permalink
Merge pull request #110 from fallahn/golf-1.16
Browse files Browse the repository at this point in the history
Golf 1.16.2
  • Loading branch information
fallahn authored Apr 20, 2024
2 parents 9e9065a + c78f2ff commit aeb53ef
Show file tree
Hide file tree
Showing 45 changed files with 5,541 additions and 290 deletions.
2 changes: 1 addition & 1 deletion crogine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Global
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|ARM.ActiveCfg = Debug|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|ARM64.ActiveCfg = Debug|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|x64.ActiveCfg = Debug|x64
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|x64.Build.0 = Debug|x64
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|x86.ActiveCfg = Debug|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.DebugASan|Any CPU.ActiveCfg = DebugASan|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.DebugASan|ARM.ActiveCfg = DebugASan|Win32
Expand All @@ -290,7 +291,6 @@ Global
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|ARM.ActiveCfg = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|ARM64.ActiveCfg = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x64.ActiveCfg = Debug|x64
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x64.Build.0 = Debug|x64
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x86.ActiveCfg = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x86.Build.0 = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.DebugASan|Any CPU.ActiveCfg = DebugASan|Win32
Expand Down
1 change: 1 addition & 0 deletions crogine/include/crogine/gui/Gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ source distribution.
#include "detail/imgui.h"
#include "detail/imgui_stdlib.h"
#include "detail/ImGuizmo.h"
#include "detail/imfilebrowser.h"

#include <crogine/Config.hpp>
#include <crogine/graphics/MaterialData.hpp>
Expand Down
242 changes: 242 additions & 0 deletions crogine/include/crogine/gui/detail/imfilebrowser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
/*
MIT License
Copyright (c) 2019-2022 Zhuang Guan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#pragma once

#include <crogine/Config.hpp>

#include <filesystem>
#include <memory>
#include <string>
#include <vector>
#include <set>


#ifndef IMGUI_VERSION
# error "include imgui.h before this header"
#endif

using ImGuiFileBrowserFlags = int;

enum ImGuiFileBrowserFlags_
{
ImGuiFileBrowserFlags_SelectDirectory = 1 << 0, // select directory instead of regular file
ImGuiFileBrowserFlags_EnterNewFilename = 1 << 1, // allow user to enter new filename when selecting regular file
ImGuiFileBrowserFlags_NoModal = 1 << 2, // file browsing window is modal by default. specify this to use a popup window
ImGuiFileBrowserFlags_NoTitleBar = 1 << 3, // hide window title bar
ImGuiFileBrowserFlags_NoStatusBar = 1 << 4, // hide status bar at the bottom of browsing window
ImGuiFileBrowserFlags_CloseOnEsc = 1 << 5, // close file browser when pressing 'ESC'
ImGuiFileBrowserFlags_CreateNewDir = 1 << 6, // allow user to create new directory
ImGuiFileBrowserFlags_MultipleSelection = 1 << 7, // allow user to select multiple files. this will hide ImGuiFileBrowserFlags_EnterNewFilename
ImGuiFileBrowserFlags_HideRegularFiles = 1 << 8, // hide regular files when ImGuiFileBrowserFlags_SelectDirectory is enabled
ImGuiFileBrowserFlags_ConfirmOnEnter = 1 << 9, // confirm selection when pressing 'ENTER'
};

namespace ImGui
{
/*!
Usage: Create an instance of the the FileBrowser object, usually at State scope.
ImGuiFileBrowserFlags can be passed to ctor to configure behaviour such as multiple
file selection or opening a directory.
Then:
\code
//configure properties
m_fileBrowser.SetTitle("My Browser");
m_fileBrowser.SetTypeFileters({".png"});
registerWindow([]()
{
if(ImGui::Begin("My Window"))
{
if(ImGui::Button("Open Image"))
{
m_fileBrowser.Open();
}
m_fileBrowser.Display(); //updates internal render list
if(m_fileBrowser.HasSelected())
{
const std::string path = m_fileBrowser.GetSelected().string(); //note actually returns std::filesystem::path - may be more useful
m_fileBrowser.ClearSelected();
//do stuff with file path
}
}
ImGui::End();
});
\endcode
*/
class CRO_EXPORT_API FileBrowser
{
public:

// pwd is set to current working directory by default
explicit FileBrowser(ImGuiFileBrowserFlags flags = 0);

FileBrowser(const FileBrowser &copyFrom);

FileBrowser &operator=(const FileBrowser &copyFrom);

// set the window position (in pixels)
// default is centered
void SetWindowPos(int posx, int posy) noexcept;

// set the window size (in pixels)
// default is (700, 450)
void SetWindowSize(int width, int height) noexcept;

// set the window title text
void SetTitle(std::string title);

// open the browsing window
void Open();

// close the browsing window
void Close();

// the browsing window is opened or not
bool IsOpened() const noexcept;

// display the browsing window if opened
void Display();

// returns true when there is a selected filename
bool HasSelected() const noexcept;

// set current browsing directory
bool SetPwd(const std::filesystem::path &pwd =
std::filesystem::current_path());

// get current browsing directory
const std::filesystem::path &GetPwd() const noexcept;

// returns selected filename. make sense only when HasSelected returns true
// when ImGuiFileBrowserFlags_MultipleSelection is enabled, only one of
// selected filename will be returned
std::filesystem::path GetSelected() const;

// returns all selected filenames.
// when ImGuiFileBrowserFlags_MultipleSelection is enabled, use this
// instead of GetSelected
std::vector<std::filesystem::path> GetMultiSelected() const;

// set selected filename to empty
void ClearSelected();

// (optional) set file type filters. eg. { ".h", ".cpp", ".hpp" }
// ".*" matches any file types
void SetTypeFilters(const std::vector<std::string> &typeFilters);

// set currently applied type filter
// default value is 0 (the first type filter)
void SetCurrentTypeFilterIndex(int index);

// when ImGuiFileBrowserFlags_EnterNewFilename is set
// this function will pre-fill the input dialog with a filename.
void SetInputName(std::string_view input);

private:

template <class Functor>
struct ScopeGuard
{
ScopeGuard(Functor&& t) : func(std::move(t)) { }

~ScopeGuard() { func(); }

private:

Functor func;
};

struct FileRecord
{
bool isDir = false;
std::filesystem::path name;
std::string showName;
std::filesystem::path extension;
};

static std::string ToLower(const std::string &s);

void UpdateFileRecords();

void SetPwdUncatched(const std::filesystem::path &pwd);

bool IsExtensionMatched(const std::filesystem::path &extension) const;

void ClearRangeSelectionState();

#ifdef _WIN32
static std::uint32_t GetDrivesBitMask();
#endif

// for c++17 compatibility

#if defined(__cpp_lib_char8_t)
static std::string u8StrToStr(std::u8string s);
#endif
static std::string u8StrToStr(std::string s);

int width_;
int height_;
int posX_;
int posY_;
ImGuiFileBrowserFlags flags_;

std::string title_;
std::string openLabel_;

bool openFlag_;
bool closeFlag_;
bool isOpened_;
bool ok_;
bool posIsSet_;

std::string statusStr_;

std::vector<std::string> typeFilters_;
unsigned int typeFilterIndex_;
bool hasAllFilter_;

std::filesystem::path pwd_;
std::set<std::filesystem::path> selectedFilenames_;
unsigned int rangeSelectionStart_; // enable range selection when shift is pressed

std::vector<FileRecord> fileRecords_;

// IMPROVE: truncate when selectedFilename_.length() > inputNameBuf_.size() - 1
static constexpr size_t INPUT_NAME_BUF_SIZE = 512;
std::unique_ptr<std::array<char, INPUT_NAME_BUF_SIZE>> inputNameBuf_;

std::string openNewDirLabel_;
std::unique_ptr<std::array<char, INPUT_NAME_BUF_SIZE>> newDirNameBuf_;

#ifdef _WIN32
uint32_t drives_;
#endif
};
} // namespace ImGui
1 change: 1 addition & 0 deletions crogine/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ set(PROJECT_SRC
${PROJECT_DIR}/imgui/Gui.cpp
${PROJECT_DIR}/imgui/GuiClient.cpp
${PROJECT_DIR}/imgui/ImCurveEdit.cpp
${PROJECT_DIR}/imgui/imfilebrowser.cpp
${PROJECT_DIR}/imgui/ImGradient.cpp
${PROJECT_DIR}/imgui/imgui.cpp
${PROJECT_DIR}/imgui/imgui_demo.cpp
Expand Down
16 changes: 16 additions & 0 deletions crogine/src/core/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static void winFPE(int)

#include "../detail/GLCheck.hpp"
#include "../detail/SDLImageRead.hpp"
#include "../detail/fa-regular-400.hpp"
#include "../detail/IconsFontAwesome6.h"
#include "../imgui/imgui_impl_opengl3.h"
#include "../imgui/imgui_impl_sdl.h"

Expand Down Expand Up @@ -341,6 +343,9 @@ void App::run()

LogI << "Using SDL " << (int)v.major << "." << (int)v.minor << "." << (int)v.patch << std::endl;

//hmm we have to *copy* this ?? (it also has to live as long as the app runs)
std::vector<std::uint8_t> fontBuff(std::begin(FA_Regular400), std::end(FA_Regular400));

auto settings = loadSettings();
glm::uvec2 size = settings.fullscreen ? glm::uvec2(settings.windowedSize) : glm::uvec2(settings.width, settings.height);

Expand Down Expand Up @@ -382,6 +387,17 @@ void App::run()
ImGui_ImplOpenGL3_Init();
#endif


ImFontConfig config;
config.MergeMode = true;
config.FontDataOwnedByAtlas = false; //held in vector above
config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
config.FontBuilderFlags |= (1 << 8) | (1 << 9); //enables colour rendering
static constexpr ImWchar ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };

ImGui::GetIO().Fonts->AddFontDefault();
ImGui::GetIO().Fonts->AddFontFromMemoryTTF(fontBuff.data(), fontBuff.size(), 13.f, &config, ranges);

m_window.setIcon(defaultIcon);
m_window.setFullScreen(settings.fullscreen);
m_window.setVsyncEnabled(settings.vsync);
Expand Down
Loading

0 comments on commit aeb53ef

Please sign in to comment.