mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-19 13:00:11 -07:00
Restructure sohimgui code a bit and add graphics menu
This commit is contained in:
parent
ab77198789
commit
31e221bc92
6 changed files with 52 additions and 60 deletions
|
@ -50,6 +50,11 @@ struct SoHConfigType {
|
||||||
bool moon_jump_on_l = false;
|
bool moon_jump_on_l = false;
|
||||||
bool super_tunic = false;
|
bool super_tunic = false;
|
||||||
} cheats;
|
} cheats;
|
||||||
|
|
||||||
|
// Graphics
|
||||||
|
struct {
|
||||||
|
bool show = false;
|
||||||
|
} graphics;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SeqPlayers {
|
enum SeqPlayers {
|
||||||
|
|
|
@ -2690,7 +2690,7 @@ struct GfxRenderingAPI *gfx_get_current_rendering_api(void) {
|
||||||
void gfx_start_frame(void) {
|
void gfx_start_frame(void) {
|
||||||
gfx_wapi->handle_events();
|
gfx_wapi->handle_events();
|
||||||
gfx_wapi->get_dimensions(&gfx_current_window_dimensions.width, &gfx_current_window_dimensions.height);
|
gfx_wapi->get_dimensions(&gfx_current_window_dimensions.width, &gfx_current_window_dimensions.height);
|
||||||
SohImGui::Draw1();
|
SohImGui::DrawMainMenuAndCalculateGameSize();
|
||||||
if (gfx_current_dimensions.height == 0) {
|
if (gfx_current_dimensions.height == 0) {
|
||||||
// Avoid division by zero
|
// Avoid division by zero
|
||||||
gfx_current_dimensions.height = 1;
|
gfx_current_dimensions.height = 1;
|
||||||
|
@ -2738,7 +2738,7 @@ void gfx_run(Gfx *commands) {
|
||||||
|
|
||||||
if (!gfx_wapi->start_frame()) {
|
if (!gfx_wapi->start_frame()) {
|
||||||
dropped_frame = true;
|
dropped_frame = true;
|
||||||
SohImGui::Draw2();
|
SohImGui::DrawFramebufferAndGameInput();
|
||||||
SohImGui::CancelFrame();
|
SohImGui::CancelFrame();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2769,7 +2769,7 @@ void gfx_run(Gfx *commands) {
|
||||||
SohUtils::saveEnvironmentVar("framebuffer", std::to_string((uintptr_t)gfx_rapi->get_framebuffer_texture_id(game_framebuffer)));
|
SohUtils::saveEnvironmentVar("framebuffer", std::to_string((uintptr_t)gfx_rapi->get_framebuffer_texture_id(game_framebuffer)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SohImGui::Draw2();
|
SohImGui::DrawFramebufferAndGameInput();
|
||||||
SohImGui::Render();
|
SohImGui::Render();
|
||||||
double t1 = gfx_wapi->get_time();
|
double t1 = gfx_wapi->get_time();
|
||||||
//printf("Process %f %f\n", t1, t1 - t0);
|
//printf("Process %f %f\n", t1, t1 - t0);
|
||||||
|
|
|
@ -502,7 +502,6 @@ namespace ImGui
|
||||||
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
|
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
|
||||||
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0); // flexible button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
|
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0); // flexible button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
|
||||||
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape
|
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape
|
||||||
IMGUI_API void ImageSimple(ImTextureID tex_id, ImVec2 center, ImVec2 size);
|
|
||||||
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
|
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
|
||||||
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
|
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
|
||||||
IMGUI_API bool Checkbox(const char* label, bool* v);
|
IMGUI_API bool Checkbox(const char* label, bool* v);
|
||||||
|
|
|
@ -1007,33 +1007,6 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
|
||||||
return held;
|
return held;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::ImageSimple(ImTextureID tex_id, ImVec2 center, ImVec2 size) {
|
|
||||||
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
|
||||||
if (window->SkipItems)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
||||||
ImRect bb(window->DC.CursorPos + ImVec2(size.x / 2, size.y / 2), window->DC.CursorPos + size);
|
|
||||||
|
|
||||||
ImVec2 pos[4] =
|
|
||||||
{
|
|
||||||
center + bb.Min + ImVec2(-size.x * 0.5f, -size.y * 0.5f),
|
|
||||||
center + bb.Min + ImVec2(+size.x * 0.5f, -size.y * 0.5f),
|
|
||||||
center + bb.Min + ImVec2(+size.x * 0.5f, +size.y * 0.5f),
|
|
||||||
center + bb.Min + ImVec2(-size.x * 0.5f, +size.y * 0.5f)
|
|
||||||
};
|
|
||||||
ImVec2 uvs[4] =
|
|
||||||
{
|
|
||||||
ImVec2(0.0f, 0.0f),
|
|
||||||
ImVec2(1.0f, 0.0f),
|
|
||||||
ImVec2(1.0f, 1.0f),
|
|
||||||
ImVec2(0.0f, 1.0f)
|
|
||||||
};
|
|
||||||
|
|
||||||
draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)
|
void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
|
@ -248,7 +248,7 @@ namespace SohImGui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw1() {
|
void DrawMainMenuAndCalculateGameSize() {
|
||||||
console->Update();
|
console->Update();
|
||||||
ImGuiBackendNewFrame();
|
ImGuiBackendNewFrame();
|
||||||
ImGuiWMNewFrame();
|
ImGuiWMNewFrame();
|
||||||
|
@ -408,6 +408,11 @@ namespace SohImGui {
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::BeginMenu("Graphics")) {
|
||||||
|
HOOK(ImGui::MenuItem("Anti-aliasing", nullptr, &Game::Settings.graphics.show));
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::BeginMenu("Cheats")) {
|
if (ImGui::BeginMenu("Cheats")) {
|
||||||
if (ImGui::Checkbox("Infinite Money", &Game::Settings.cheats.infinite_money)) {
|
if (ImGui::Checkbox("Infinite Money", &Game::Settings.cheats.infinite_money)) {
|
||||||
CVar_SetS32("gInfiniteMoney", Game::Settings.cheats.infinite_money);
|
CVar_SetS32("gInfiniteMoney", Game::Settings.cheats.infinite_money);
|
||||||
|
@ -465,6 +470,38 @@ namespace SohImGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
if (Game::Settings.debug.soh) {
|
||||||
|
const float framerate = ImGui::GetIO().Framerate;
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
||||||
|
ImGui::Begin("Debug Stats", nullptr, ImGuiWindowFlags_None);
|
||||||
|
|
||||||
|
ImGui::Text("Platform: Windows");
|
||||||
|
ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate);
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Game::Settings.graphics.show) {
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
||||||
|
ImGui::Begin("Anti-aliasing settings", nullptr, ImGuiWindowFlags_None);
|
||||||
|
ImGui::Text("Internal Resolution:");
|
||||||
|
ImGui::SliderInt("Mul", reinterpret_cast<int*>(&gfx_current_dimensions.internal_mul), 1, 8);
|
||||||
|
ImGui::Text("MSAA:");
|
||||||
|
ImGui::SliderInt("MSAA", reinterpret_cast<int*>(&gfx_msaa_level), 1, 8);
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
console->Draw();
|
||||||
|
|
||||||
|
for (auto& windowIter : customWindows) {
|
||||||
|
CustomWindow& window = windowIter.second;
|
||||||
|
if (window.drawFunc != nullptr) {
|
||||||
|
window.drawFunc(window.enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
|
||||||
|
@ -496,7 +533,7 @@ namespace SohImGui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw2() {
|
void DrawFramebufferAndGameInput() {
|
||||||
ImVec2 main_pos = ImGui::GetWindowPos();
|
ImVec2 main_pos = ImGui::GetWindowPos();
|
||||||
ImVec2 size = ImGui::GetContentRegionAvail();
|
ImVec2 size = ImGui::GetContentRegionAvail();
|
||||||
ImVec2 pos = ImVec2(0, 0);
|
ImVec2 pos = ImVec2(0, 0);
|
||||||
|
@ -508,26 +545,13 @@ namespace SohImGui {
|
||||||
std::string fb_str = SohUtils::getEnvironmentVar("framebuffer");
|
std::string fb_str = SohUtils::getEnvironmentVar("framebuffer");
|
||||||
if (!fb_str.empty()) {
|
if (!fb_str.empty()) {
|
||||||
uintptr_t fbuf = (uintptr_t)std::stoull(fb_str);
|
uintptr_t fbuf = (uintptr_t)std::stoull(fb_str);
|
||||||
ImGui::ImageSimple(reinterpret_cast<ImTextureID>(fbuf), pos, size);
|
//ImGui::ImageSimple(reinterpret_cast<ImTextureID>(fbuf), pos, size);
|
||||||
|
ImGui::SetCursorPos(pos);
|
||||||
|
ImGui::Image(reinterpret_cast<ImTextureID>(fbuf), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
if (Game::Settings.debug.soh) {
|
|
||||||
const float framerate = ImGui::GetIO().Framerate;
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
|
||||||
ImGui::Begin("Debug Stats", nullptr, ImGuiWindowFlags_None);
|
|
||||||
|
|
||||||
ImGui::Text("Platform: Windows");
|
|
||||||
ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate);
|
|
||||||
ImGui::Text("Internal Resolution:");
|
|
||||||
ImGui::SliderInt("Mul", reinterpret_cast<int*>(&gfx_current_dimensions.internal_mul), 1, 8);
|
|
||||||
ImGui::Text("MSAA:");
|
|
||||||
ImGui::SliderInt("MSAA", reinterpret_cast<int*>(&gfx_msaa_level), 1, 8);
|
|
||||||
ImGui::End();
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
const float scale = Game::Settings.controller.input_scale;
|
const float scale = Game::Settings.controller.input_scale;
|
||||||
ImVec2 BtnPos = ImVec2(160 * scale, 85 * scale);
|
ImVec2 BtnPos = ImVec2(160 * scale, 85 * scale);
|
||||||
|
|
||||||
|
@ -577,15 +601,6 @@ namespace SohImGui {
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console->Draw();
|
|
||||||
|
|
||||||
for (auto& windowIter : customWindows) {
|
|
||||||
CustomWindow& window = windowIter.second;
|
|
||||||
if (window.drawFunc != nullptr) {
|
|
||||||
window.drawFunc(window.enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render() {
|
void Render() {
|
||||||
|
|
|
@ -59,8 +59,8 @@ namespace SohImGui {
|
||||||
extern Console* console;
|
extern Console* console;
|
||||||
void Init(WindowImpl window_impl);
|
void Init(WindowImpl window_impl);
|
||||||
void Update(EventImpl event);
|
void Update(EventImpl event);
|
||||||
void Draw1(void);
|
void DrawMainMenuAndCalculateGameSize(void);
|
||||||
void Draw2(void);
|
void DrawFramebufferAndGameInput(void);
|
||||||
void Render(void);
|
void Render(void);
|
||||||
void CancelFrame(void);
|
void CancelFrame(void);
|
||||||
void ShowCursor(bool hide, Dialogues w);
|
void ShowCursor(bool hide, Dialogues w);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue