Compare commits
3 Commits
0f2f5973fb
...
917309e99c
Author | SHA1 | Date | |
---|---|---|---|
917309e99c | |||
66668959d3 | |||
58329a2033 |
@ -5,7 +5,7 @@ env = SConscript('external/scons-plus-plus/SConscript', exports = ['config'])
|
||||
env.Append(CPPPATH = [Dir('private'), Dir('public')])
|
||||
|
||||
# add the default recipe repository
|
||||
env.RecipeRepo('mewin-stable', 'https://git.mewin.de/mewin/spp_recipes.git', 'stable')
|
||||
env.RecipeRepo('mewin', 'https://git.mewin.de/mewin/spp_recipes.git', 'stable')
|
||||
|
||||
# library
|
||||
env = env.Module('private/raid/SModule')
|
||||
|
@ -4,7 +4,7 @@ import json
|
||||
Import('env')
|
||||
|
||||
if not hasattr(env, 'Jinja'):
|
||||
env.Error('RAID requires the Jinja tool.')
|
||||
env.Error('RAID requires Jinja.')
|
||||
|
||||
src_files = Split("""
|
||||
application.cpp
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <mijin/virtual_filesystem/mapping.hpp>
|
||||
#include <mijin/virtual_filesystem/relative.hpp>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <backends/imgui_impl_sdl3.h>
|
||||
#include <stb_image.h>
|
||||
@ -289,6 +290,11 @@ void Application::handleSDLEvent(const SDL_Event& event)
|
||||
}
|
||||
}
|
||||
|
||||
void Application::handleSDLError(const char* message)
|
||||
{
|
||||
msgError("SDL: {}", message);
|
||||
}
|
||||
|
||||
bool Application::init()
|
||||
{
|
||||
auto addConfigDir = [&](const fs::path& path)
|
||||
@ -419,12 +425,19 @@ void Application::cleanup()
|
||||
|
||||
bool Application::initSDL()
|
||||
{
|
||||
if (!SDL_Init(0))
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
// prefer x11 over wayland, as ImGui viewports don't work with wayland
|
||||
// TODO: this still doesn't work all the time, maybe there will be an update to ImGui in the future?
|
||||
SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "x11,wayland");
|
||||
#endif
|
||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
msgError("Error initializing SDL: {}.", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
msgInfo("SDL video driver: {}", SDL_GetCurrentVideoDriver());
|
||||
|
||||
// GL attributes must be set before window creation
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||
@ -475,12 +488,18 @@ bool Application::initImGui()
|
||||
{
|
||||
IMGUI_CHECKVERSION(); // not exactly useful when using static libs, but won't hurt
|
||||
|
||||
if (ImGui::CreateContext() == nullptr)
|
||||
ImGuiContext* imguiContext = ImGui::CreateContext();
|
||||
if (imguiContext == nullptr)
|
||||
{
|
||||
msgError("Error initializing ImGui context.");
|
||||
return false;
|
||||
}
|
||||
|
||||
imguiContext->ErrorCallbackUserData = this;
|
||||
imguiContext->ErrorCallback = [](ImGuiContext* /* ctx */, void* userData, const char* msg) {
|
||||
static_cast<Application*>(userData)->handleSDLError(msg);
|
||||
};
|
||||
|
||||
loadImGuiConfig();
|
||||
|
||||
configureImgui();
|
||||
@ -503,6 +522,16 @@ bool Application::initImGui()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (imguiIO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
if (!(imguiIO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports)) {
|
||||
msgWarning("ImGUI viewports enabled, but platform doesn't support them.");
|
||||
}
|
||||
if (!(imguiIO.BackendFlags & ImGuiBackendFlags_RendererHasViewports)) {
|
||||
msgWarning("ImGUI viewports enabled, but renderer doesn't support them.");
|
||||
}
|
||||
}
|
||||
|
||||
// init font
|
||||
if (imguiIO.Fonts->Fonts.empty())
|
||||
{
|
||||
|
@ -3,6 +3,8 @@ Import('env')
|
||||
|
||||
src_files = Split("""
|
||||
main.cpp
|
||||
|
||||
application.cpp
|
||||
""")
|
||||
|
||||
prog_app = env.UnityProgram(
|
||||
|
57
private/raid_test/application.cpp
Normal file
57
private/raid_test/application.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
#include "raid_test/application.hpp"
|
||||
|
||||
namespace raid_test
|
||||
{
|
||||
Application gApplication;
|
||||
|
||||
bool Application::init()
|
||||
{
|
||||
if (!raid::Application::init()) {
|
||||
return false;
|
||||
}
|
||||
setMainWindowFlags(raid::DEFAULT_MAIN_WINDOW_FLAGS | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking);
|
||||
setMainWindowStyle(ImGuiStyleVar_WindowPadding, ImVec2());
|
||||
setMainWindowStyle(ImGuiStyleVar_WindowBorderSize, 0.f);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::configureImgui()
|
||||
{
|
||||
raid::Application::configureImgui();
|
||||
ImGuiIO& imguiIO = ImGui::GetIO();
|
||||
imguiIO.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
}
|
||||
|
||||
void Application::render()
|
||||
{
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
{
|
||||
if (ImGui::MenuItem("Quit"))
|
||||
{
|
||||
requestQuit();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
ImGui::Text("hi");
|
||||
|
||||
ImGui::ShowMetricsWindow();
|
||||
ImGui::Begin("Test");
|
||||
ImGui::Text("Test Content");
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
std::string Application::getFolderName()
|
||||
{
|
||||
return "raid_test_app";
|
||||
}
|
||||
|
||||
std::string Application::getWindowTitle()
|
||||
{
|
||||
return "RAID Test Application";
|
||||
}
|
||||
} // namespace raid_test
|
24
private/raid_test/application.hpp
Normal file
24
private/raid_test/application.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(RAID_TEST_APPLICATION_HPP_INCLUDED)
|
||||
#define RAID_TEST_APPLICATION_HPP_INCLUDED 1
|
||||
|
||||
#include "raid/raid.hpp"
|
||||
|
||||
namespace raid_test
|
||||
{
|
||||
class Application : public raid::Application
|
||||
{
|
||||
protected:
|
||||
bool init() override;
|
||||
void configureImgui() override;
|
||||
void render() override;
|
||||
std::string getFolderName() override;
|
||||
std::string getWindowTitle() override;
|
||||
};
|
||||
|
||||
extern Application gApplication;
|
||||
} // namespace raid_test
|
||||
|
||||
#endif // !defined(RAID_TEST_APPLICATION_HPP_INCLUDED)
|
@ -1,40 +1,7 @@
|
||||
|
||||
#include "raid/raid.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
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::Begin("Test");
|
||||
ImGui::Text("Test Content");
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
#include "./application.hpp"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return raid::runQuick(argc, argv, {
|
||||
.callbacks = {
|
||||
.render = &render
|
||||
},
|
||||
.folderName = "raid_test_app",
|
||||
.windowTitle = "RAID Test App",
|
||||
.mainWindowFlags = raid::DEFAULT_MAIN_WINDOW_FLAGS | ImGuiWindowFlags_MenuBar
|
||||
});
|
||||
return raid_test::gApplication.run(argc, argv);
|
||||
}
|
||||
|
@ -138,6 +138,7 @@ protected:
|
||||
virtual void initMemoryFS();
|
||||
virtual void handleMessage(const Message& message);
|
||||
virtual void handleSDLEvent(const SDL_Event& event);
|
||||
virtual void handleSDLError(const char* message);
|
||||
|
||||
void msgInfo(const char* text)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user