More config options, menu bar and global getter for QuickApp.
This commit is contained in:
parent
7a18cce60c
commit
75773778e9
@ -20,6 +20,7 @@ namespace
|
|||||||
{
|
{
|
||||||
constexpr int GL_COLOR_BUFFER_BIT = 0x00004000;
|
constexpr int GL_COLOR_BUFFER_BIT = 0x00004000;
|
||||||
const char* IMGUI_GLSL_VERSION = "#version 130";
|
const char* IMGUI_GLSL_VERSION = "#version 130";
|
||||||
|
QuickApp* gAppInstance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::run(int argc, char** argv)
|
int Application::run(int argc, char** argv)
|
||||||
@ -93,7 +94,7 @@ int Application::run(int argc, char** argv)
|
|||||||
ImGui::SetNextWindowPos({0, 0});
|
ImGui::SetNextWindowPos({0, 0});
|
||||||
ImGui::SetNextWindowSize(imguiIO.DisplaySize);
|
ImGui::SetNextWindowSize(imguiIO.DisplaySize);
|
||||||
|
|
||||||
ImGui::Begin("##main", nullptr, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration);
|
ImGui::Begin("##main", nullptr, mMainWindowFlags);
|
||||||
render();
|
render();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
@ -304,22 +305,31 @@ void Application::saveImGuiConfig()
|
|||||||
void QuickApp::init(QuickAppOptions options)
|
void QuickApp::init(QuickAppOptions options)
|
||||||
{
|
{
|
||||||
MIJIN_ASSERT_FATAL(options.callbacks.render, "Missing render callback.");
|
MIJIN_ASSERT_FATAL(options.callbacks.render, "Missing render callback.");
|
||||||
mOptions = std::move(options);
|
mRenderCallback = std::move(options.callbacks.render);
|
||||||
|
mFolderName = std::move(options.folderName);
|
||||||
|
setMainWindowFlags(options.mainWindowFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
QuickApp& QuickApp::get()
|
||||||
|
{
|
||||||
|
MIJIN_ASSERT_FATAL(gAppInstance != nullptr, "No QuickApp is running.");
|
||||||
|
return *gAppInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickApp::render()
|
void QuickApp::render()
|
||||||
{
|
{
|
||||||
mOptions.callbacks.render();
|
mRenderCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string QuickApp::getFolderName()
|
std::string QuickApp::getFolderName()
|
||||||
{
|
{
|
||||||
return mOptions.folderName;
|
return mFolderName;
|
||||||
}
|
}
|
||||||
|
|
||||||
int runQuick(int argc, char* argv[], QuickAppOptions options)
|
int runQuick(int argc, char* argv[], QuickAppOptions options)
|
||||||
{
|
{
|
||||||
QuickApp app;
|
QuickApp app;
|
||||||
|
gAppInstance = &app;
|
||||||
app.init(std::move(options));
|
app.init(std::move(options));
|
||||||
return app.run(argc, argv);
|
return app.run(argc, argv);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,18 @@ namespace
|
|||||||
{
|
{
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
|
if (ImGui::BeginMenuBar())
|
||||||
|
{
|
||||||
|
if (ImGui::BeginMenu("File"))
|
||||||
|
{
|
||||||
|
if (ImGui::MenuItem("Quit"))
|
||||||
|
{
|
||||||
|
raid::QuickApp::get().requestQuit();
|
||||||
|
}
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
ImGui::EndMenuBar();
|
||||||
|
}
|
||||||
ImGui::Text("hi");
|
ImGui::Text("hi");
|
||||||
|
|
||||||
ImGui::Begin("Test");
|
ImGui::Begin("Test");
|
||||||
@ -20,6 +32,8 @@ int main(int argc, char* argv[])
|
|||||||
return raid::runQuick(argc, argv, {
|
return raid::runQuick(argc, argv, {
|
||||||
.callbacks = {
|
.callbacks = {
|
||||||
.render = &render
|
.render = &render
|
||||||
}
|
},
|
||||||
|
.folderName = "raid_test_app",
|
||||||
|
.mainWindowFlags = raid::DEFAULT_MAIN_WINDOW_FLAGS | ImGuiWindowFlags_MenuBar
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,18 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
#include <imgui.h>
|
||||||
#include <mijin/virtual_filesystem/stacked.hpp>
|
#include <mijin/virtual_filesystem/stacked.hpp>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace raid
|
namespace raid
|
||||||
{
|
{
|
||||||
inline constexpr int ERR_INIT_FAILED = 100;
|
inline constexpr int ERR_INIT_FAILED = 100;
|
||||||
|
inline constexpr ImGuiWindowFlags DEFAULT_MAIN_WINDOW_FLAGS = 0
|
||||||
|
| ImGuiWindowFlags_NoBackground
|
||||||
|
| ImGuiWindowFlags_NoDecoration
|
||||||
|
| ImGuiWindowFlags_NoBringToFrontOnFocus
|
||||||
|
| ImGuiWindowFlags_NoNav;
|
||||||
|
|
||||||
enum class MessageSeverity : unsigned char
|
enum class MessageSeverity : unsigned char
|
||||||
{
|
{
|
||||||
@ -30,12 +36,14 @@ struct Message
|
|||||||
class Application
|
class Application
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool mRunning = true;
|
|
||||||
SDL_Window* mWindow = nullptr;
|
SDL_Window* mWindow = nullptr;
|
||||||
SDL_GLContext mGLContext = nullptr;
|
SDL_GLContext mGLContext = nullptr;
|
||||||
|
|
||||||
mijin::StackedFileSystemAdapter mFS;
|
mijin::StackedFileSystemAdapter mFS;
|
||||||
|
|
||||||
|
bool mRunning = true;
|
||||||
|
ImGuiWindowFlags mMainWindowFlags = DEFAULT_MAIN_WINDOW_FLAGS;
|
||||||
|
|
||||||
using glClear_fn_t = void (*)(std::uint32_t);
|
using glClear_fn_t = void (*)(std::uint32_t);
|
||||||
using glClearColor_fn_t = void (*)(float, float, float, float);
|
using glClearColor_fn_t = void (*)(float, float, float, float);
|
||||||
|
|
||||||
@ -44,6 +52,13 @@ private:
|
|||||||
public:
|
public:
|
||||||
virtual ~Application() = default;
|
virtual ~Application() = default;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
ImGuiWindowFlags getMainWindowFlags() const { return mMainWindowFlags; }
|
||||||
|
|
||||||
|
void setMainWindowFlags(ImGuiWindowFlags flags) { mMainWindowFlags = flags; }
|
||||||
|
|
||||||
|
void requestQuit() { mRunning = false; }
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int run(int argc, char* argv[]);
|
int run(int argc, char* argv[]);
|
||||||
|
|
||||||
@ -122,16 +137,20 @@ struct QuickAppOptions
|
|||||||
render_cb_t render;
|
render_cb_t render;
|
||||||
} callbacks;
|
} callbacks;
|
||||||
std::string folderName = "raid";
|
std::string folderName = "raid";
|
||||||
|
ImGuiWindowFlags mainWindowFlags = DEFAULT_MAIN_WINDOW_FLAGS;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QuickApp : public Application
|
class QuickApp : public Application
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
QuickAppOptions mOptions;
|
render_cb_t mRenderCallback;
|
||||||
|
std::string mFolderName;
|
||||||
public:
|
public:
|
||||||
void init(QuickAppOptions options);
|
void init(QuickAppOptions options);
|
||||||
void render() override;
|
void render() override;
|
||||||
std::string getFolderName() override;
|
std::string getFolderName() override;
|
||||||
|
|
||||||
|
static QuickApp& get();
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user