summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Linn <jl@conductive.de>2019-11-18 00:43:17 +0100
committerRick Gibbed <rick@gibbed.us>2019-11-20 08:05:40 -0600
commit03d5455a2f8b5c5d029d7612a37cf7a24a64fc18 (patch)
tree340947f1b0628e6b53994eeec0ca89bc833f2776
parent19851699246ef63cf4b6a6e5740de8d3535089f7 (diff)
[imgui] Fixes to work with new api.
- Font atlas is now owned by context. - Switch from deprecated io.RenderDrawListsFn callback to dedicated call in window.cc. - Replaced deprecated ImGuiCol_ModalWindowDarkening with ImGuiCol_ModalWindowDimBg. - Replaced deprecated SetScrollHere() with SetScrollHereY(). - Replaced deprecated GetContentRegionAvailWidth() with GetContentRegionAvail().x. - Replaced deprecated ShowTestWindow() with ShowDemoWindow(). - Replaced deprecated ImGuiCol_ChildWindowBg with ImGuiCol_ChildBg. - Replaced deprecated SetNextTreeNodeOpen() with SetNextItemOpen().
-rw-r--r--src/xenia/debug/ui/debug_window.cc14
-rw-r--r--src/xenia/gpu/trace_viewer.cc4
-rw-r--r--src/xenia/ui/imgui_drawer.cc26
-rw-r--r--src/xenia/ui/imgui_drawer.h3
-rw-r--r--src/xenia/ui/window.cc1
-rw-r--r--src/xenia/ui/window_demo.cc2
6 files changed, 21 insertions, 29 deletions
diff --git a/src/xenia/debug/ui/debug_window.cc b/src/xenia/debug/ui/debug_window.cc
index de1034d97..5d9472359 100644
--- a/src/xenia/debug/ui/debug_window.cc
+++ b/src/xenia/debug/ui/debug_window.cc
@@ -140,7 +140,7 @@ void DebugWindow::DrawFrame() {
float top_panes_height =
ImGui::GetContentRegionAvail().y - bottom_panes_height;
float log_pane_width =
- ImGui::GetContentRegionAvailWidth() - breakpoints_pane_width;
+ ImGui::GetContentRegionAvail().x - breakpoints_pane_width;
ImGui::BeginChild("##toolbar", ImVec2(0, 25), true);
DrawToolbar();
@@ -237,12 +237,10 @@ void DebugWindow::DrawFrame() {
ImGui::PopStyleVar();
if (cvars::imgui_debug) {
- ImGui::ShowTestWindow();
+ ImGui::ShowDemoWindow();
ImGui::ShowMetricsWindow();
}
- ImGui::Render();
-
// Continuous paint.
window_->Invalidate();
}
@@ -340,7 +338,7 @@ void DebugWindow::DrawSourcePane() {
ImGui::SameLine();
char name[256];
std::strcpy(name, function->name().c_str());
- ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() - 10);
+ ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - 10);
if (ImGui::InputText("##name", name, sizeof(name),
ImGuiInputTextFlags_AutoSelectAll)) {
function->set_name(name);
@@ -623,7 +621,7 @@ void DebugWindow::DrawBreakpointGutterButton(
void DebugWindow::ScrollToSourceIfPcChanged() {
if (state_.has_changed_pc) {
// TODO(benvanik): not so annoying scroll.
- ImGui::SetScrollHere();
+ ImGui::SetScrollHereY(0.5f);
state_.has_changed_pc = false;
}
}
@@ -1006,7 +1004,7 @@ void DebugWindow::DrawThreadsPane() {
continue;
}
if (is_current_thread && state_.has_changed_thread) {
- ImGui::SetScrollHere();
+ ImGui::SetScrollHereY(0.5f);
state_.has_changed_thread = false;
}
if (!is_current_thread) {
@@ -1017,7 +1015,7 @@ void DebugWindow::DrawThreadsPane() {
}
ImGui::PushID(thread_info);
if (is_current_thread) {
- ImGui::SetNextTreeNodeOpen(true, ImGuiCond_Always);
+ ImGui::SetNextItemOpen(true, ImGuiCond_Always);
}
const char* state_label = "?";
if (thread->can_debugger_suspend()) {
diff --git a/src/xenia/gpu/trace_viewer.cc b/src/xenia/gpu/trace_viewer.cc
index 822286650..298c0b887 100644
--- a/src/xenia/gpu/trace_viewer.cc
+++ b/src/xenia/gpu/trace_viewer.cc
@@ -192,7 +192,7 @@ void TraceViewer::DrawMultilineString(const std::string& str) {
}
void TraceViewer::DrawUI() {
- // ImGui::ShowTestWindow();
+ // ImGui::ShowDemoWindow();
DrawControllerUI();
DrawCommandListUI();
@@ -538,7 +538,7 @@ void TraceViewer::DrawCommandListUI() {
}
ImGui::PopID();
if (did_seek && target_command == -1) {
- ImGui::SetScrollHereY();
+ ImGui::SetScrollHereY(0.5f);
}
auto id = RecursiveDrawCommandBufferUI(frame, frame->command_tree.get());
diff --git a/src/xenia/ui/imgui_drawer.cc b/src/xenia/ui/imgui_drawer.cc
index 8a12afd8e..f38f20901 100644
--- a/src/xenia/ui/imgui_drawer.cc
+++ b/src/xenia/ui/imgui_drawer.cc
@@ -26,8 +26,6 @@ const char kProggyTinyCompressedDataBase85[10950 + 1] =
static_assert(sizeof(ImmediateVertex) == sizeof(ImDrawVert),
"Vertex types must match");
-ImGuiDrawer* ImGuiDrawer::current_drawer_ = nullptr;
-
ImGuiDrawer::ImGuiDrawer(xe::ui::Window* window)
: window_(window), graphics_context_(window->context()) {
Initialize();
@@ -38,7 +36,6 @@ ImGuiDrawer::~ImGuiDrawer() {
ImGui::DestroyContext(internal_state_);
internal_state_ = nullptr;
}
- current_drawer_ = nullptr;
}
void ImGuiDrawer::Initialize() {
@@ -46,20 +43,11 @@ void ImGuiDrawer::Initialize() {
// This will give us state we can swap to the ImGui globals when in use.
internal_state_ = ImGui::CreateContext();
- current_drawer_ = this;
-
auto& io = ImGui::GetIO();
- font_atlas_ = std::make_unique<ImFontAtlas>();
- io.Fonts = font_atlas_.get();
-
SetupFont();
io.DeltaTime = 1.0f / 60.0f;
- io.RenderDrawListsFn = [](ImDrawData* data) {
- assert_not_null(current_drawer_);
- current_drawer_->RenderDrawLists(data);
- };
auto& style = ImGui::GetStyle();
style.ScrollbarRounding = 0;
@@ -67,7 +55,7 @@ void ImGuiDrawer::Initialize() {
style.Colors[ImGuiCol_Text] = ImVec4(0.89f, 0.90f, 0.90f, 1.00f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.06f, 0.00f, 1.00f);
- style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
+ style.Colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_Border] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f);
@@ -105,8 +93,7 @@ void ImGuiDrawer::Initialize() {
style.Colors[ImGuiCol_PlotHistogramHovered] =
ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 1.00f, 0.00f, 0.21f);
- style.Colors[ImGuiCol_ModalWindowDarkening] =
- ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
+ style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
io.KeyMap[ImGuiKey_Tab] = 0x09; // VK_TAB;
io.KeyMap[ImGuiKey_LeftArrow] = 0x25;
@@ -221,11 +208,18 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) {
}
ImGuiIO& ImGuiDrawer::GetIO() {
- current_drawer_ = this;
ImGui::SetCurrentContext(internal_state_);
return ImGui::GetIO();
}
+void ImGuiDrawer::RenderDrawLists() {
+ ImGui::SetCurrentContext(internal_state_);
+ auto draw_data = ImGui::GetDrawData();
+ if (draw_data) {
+ RenderDrawLists(draw_data);
+ }
+}
+
void ImGuiDrawer::OnKeyDown(KeyEvent* e) {
auto& io = GetIO();
io.KeysDown[e->key_code()] = true;
diff --git a/src/xenia/ui/imgui_drawer.h b/src/xenia/ui/imgui_drawer.h
index 15ee84121..e2038f1bf 100644
--- a/src/xenia/ui/imgui_drawer.h
+++ b/src/xenia/ui/imgui_drawer.h
@@ -17,7 +17,6 @@
#include "xenia/ui/window_listener.h"
struct ImDrawData;
-struct ImFontAtlas;
struct ImGuiContext;
struct ImGuiIO;
@@ -35,6 +34,7 @@ class ImGuiDrawer : public WindowListener {
void SetupDefaultInput() {}
ImGuiIO& GetIO();
+ void RenderDrawLists();
static const uint64_t kIgnoreAlpha = (1ull << 63);
@@ -58,7 +58,6 @@ class ImGuiDrawer : public WindowListener {
GraphicsContext* graphics_context_ = nullptr;
ImGuiContext* internal_state_ = nullptr;
- std::unique_ptr<ImFontAtlas> font_atlas_;
std::unique_ptr<ImmediateTexture> font_texture_;
};
diff --git a/src/xenia/ui/window.cc b/src/xenia/ui/window.cc
index 4e03b35c6..0f955924a 100644
--- a/src/xenia/ui/window.cc
+++ b/src/xenia/ui/window.cc
@@ -210,6 +210,7 @@ void Window::OnPaint(UIEvent* e) {
// Flush ImGui buffers before we swap.
ImGui::Render();
+ imgui_drawer_->RenderDrawLists();
ForEachListener([e](auto listener) { listener->OnPainted(e); });
on_painted(e);
diff --git a/src/xenia/ui/window_demo.cc b/src/xenia/ui/window_demo.cc
index 2895c2a6e..edb6654dc 100644
--- a/src/xenia/ui/window_demo.cc
+++ b/src/xenia/ui/window_demo.cc
@@ -102,7 +102,7 @@ int window_demo_main(const std::vector<std::wstring>& args) {
window->on_painting.AddListener([&](xe::ui::UIEvent* e) {
auto& io = window->imgui_drawer()->GetIO();
- ImGui::ShowTestWindow();
+ ImGui::ShowDemoWindow();
ImGui::ShowMetricsWindow();
// Continuous paint.