[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().
This commit is contained in:
Joel Linn 2019-11-18 00:43:17 +01:00 committed by Rick Gibbed
parent 1985169924
commit 03d5455a2f
6 changed files with 21 additions and 29 deletions

View File

@ -140,7 +140,7 @@ void DebugWindow::DrawFrame() {
float top_panes_height = float top_panes_height =
ImGui::GetContentRegionAvail().y - bottom_panes_height; ImGui::GetContentRegionAvail().y - bottom_panes_height;
float log_pane_width = float log_pane_width =
ImGui::GetContentRegionAvailWidth() - breakpoints_pane_width; ImGui::GetContentRegionAvail().x - breakpoints_pane_width;
ImGui::BeginChild("##toolbar", ImVec2(0, 25), true); ImGui::BeginChild("##toolbar", ImVec2(0, 25), true);
DrawToolbar(); DrawToolbar();
@ -237,12 +237,10 @@ void DebugWindow::DrawFrame() {
ImGui::PopStyleVar(); ImGui::PopStyleVar();
if (cvars::imgui_debug) { if (cvars::imgui_debug) {
ImGui::ShowTestWindow(); ImGui::ShowDemoWindow();
ImGui::ShowMetricsWindow(); ImGui::ShowMetricsWindow();
} }
ImGui::Render();
// Continuous paint. // Continuous paint.
window_->Invalidate(); window_->Invalidate();
} }
@ -340,7 +338,7 @@ void DebugWindow::DrawSourcePane() {
ImGui::SameLine(); ImGui::SameLine();
char name[256]; char name[256];
std::strcpy(name, function->name().c_str()); 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), if (ImGui::InputText("##name", name, sizeof(name),
ImGuiInputTextFlags_AutoSelectAll)) { ImGuiInputTextFlags_AutoSelectAll)) {
function->set_name(name); function->set_name(name);
@ -623,7 +621,7 @@ void DebugWindow::DrawBreakpointGutterButton(
void DebugWindow::ScrollToSourceIfPcChanged() { void DebugWindow::ScrollToSourceIfPcChanged() {
if (state_.has_changed_pc) { if (state_.has_changed_pc) {
// TODO(benvanik): not so annoying scroll. // TODO(benvanik): not so annoying scroll.
ImGui::SetScrollHere(); ImGui::SetScrollHereY(0.5f);
state_.has_changed_pc = false; state_.has_changed_pc = false;
} }
} }
@ -1006,7 +1004,7 @@ void DebugWindow::DrawThreadsPane() {
continue; continue;
} }
if (is_current_thread && state_.has_changed_thread) { if (is_current_thread && state_.has_changed_thread) {
ImGui::SetScrollHere(); ImGui::SetScrollHereY(0.5f);
state_.has_changed_thread = false; state_.has_changed_thread = false;
} }
if (!is_current_thread) { if (!is_current_thread) {
@ -1017,7 +1015,7 @@ void DebugWindow::DrawThreadsPane() {
} }
ImGui::PushID(thread_info); ImGui::PushID(thread_info);
if (is_current_thread) { if (is_current_thread) {
ImGui::SetNextTreeNodeOpen(true, ImGuiCond_Always); ImGui::SetNextItemOpen(true, ImGuiCond_Always);
} }
const char* state_label = "?"; const char* state_label = "?";
if (thread->can_debugger_suspend()) { if (thread->can_debugger_suspend()) {

View File

@ -192,7 +192,7 @@ void TraceViewer::DrawMultilineString(const std::string& str) {
} }
void TraceViewer::DrawUI() { void TraceViewer::DrawUI() {
// ImGui::ShowTestWindow(); // ImGui::ShowDemoWindow();
DrawControllerUI(); DrawControllerUI();
DrawCommandListUI(); DrawCommandListUI();
@ -538,7 +538,7 @@ void TraceViewer::DrawCommandListUI() {
} }
ImGui::PopID(); ImGui::PopID();
if (did_seek && target_command == -1) { if (did_seek && target_command == -1) {
ImGui::SetScrollHereY(); ImGui::SetScrollHereY(0.5f);
} }
auto id = RecursiveDrawCommandBufferUI(frame, frame->command_tree.get()); auto id = RecursiveDrawCommandBufferUI(frame, frame->command_tree.get());

View File

@ -26,8 +26,6 @@ const char kProggyTinyCompressedDataBase85[10950 + 1] =
static_assert(sizeof(ImmediateVertex) == sizeof(ImDrawVert), static_assert(sizeof(ImmediateVertex) == sizeof(ImDrawVert),
"Vertex types must match"); "Vertex types must match");
ImGuiDrawer* ImGuiDrawer::current_drawer_ = nullptr;
ImGuiDrawer::ImGuiDrawer(xe::ui::Window* window) ImGuiDrawer::ImGuiDrawer(xe::ui::Window* window)
: window_(window), graphics_context_(window->context()) { : window_(window), graphics_context_(window->context()) {
Initialize(); Initialize();
@ -38,7 +36,6 @@ ImGuiDrawer::~ImGuiDrawer() {
ImGui::DestroyContext(internal_state_); ImGui::DestroyContext(internal_state_);
internal_state_ = nullptr; internal_state_ = nullptr;
} }
current_drawer_ = nullptr;
} }
void ImGuiDrawer::Initialize() { 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. // This will give us state we can swap to the ImGui globals when in use.
internal_state_ = ImGui::CreateContext(); internal_state_ = ImGui::CreateContext();
current_drawer_ = this;
auto& io = ImGui::GetIO(); auto& io = ImGui::GetIO();
font_atlas_ = std::make_unique<ImFontAtlas>();
io.Fonts = font_atlas_.get();
SetupFont(); SetupFont();
io.DeltaTime = 1.0f / 60.0f; io.DeltaTime = 1.0f / 60.0f;
io.RenderDrawListsFn = [](ImDrawData* data) {
assert_not_null(current_drawer_);
current_drawer_->RenderDrawLists(data);
};
auto& style = ImGui::GetStyle(); auto& style = ImGui::GetStyle();
style.ScrollbarRounding = 0; 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_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_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_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_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_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); style.Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f);
@ -105,8 +93,7 @@ void ImGuiDrawer::Initialize() {
style.Colors[ImGuiCol_PlotHistogramHovered] = style.Colors[ImGuiCol_PlotHistogramHovered] =
ImVec4(1.00f, 0.60f, 0.00f, 1.00f); 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_TextSelectedBg] = ImVec4(0.00f, 1.00f, 0.00f, 0.21f);
style.Colors[ImGuiCol_ModalWindowDarkening] = style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
io.KeyMap[ImGuiKey_Tab] = 0x09; // VK_TAB; io.KeyMap[ImGuiKey_Tab] = 0x09; // VK_TAB;
io.KeyMap[ImGuiKey_LeftArrow] = 0x25; io.KeyMap[ImGuiKey_LeftArrow] = 0x25;
@ -221,11 +208,18 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) {
} }
ImGuiIO& ImGuiDrawer::GetIO() { ImGuiIO& ImGuiDrawer::GetIO() {
current_drawer_ = this;
ImGui::SetCurrentContext(internal_state_); ImGui::SetCurrentContext(internal_state_);
return ImGui::GetIO(); 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) { void ImGuiDrawer::OnKeyDown(KeyEvent* e) {
auto& io = GetIO(); auto& io = GetIO();
io.KeysDown[e->key_code()] = true; io.KeysDown[e->key_code()] = true;

View File

@ -17,7 +17,6 @@
#include "xenia/ui/window_listener.h" #include "xenia/ui/window_listener.h"
struct ImDrawData; struct ImDrawData;
struct ImFontAtlas;
struct ImGuiContext; struct ImGuiContext;
struct ImGuiIO; struct ImGuiIO;
@ -35,6 +34,7 @@ class ImGuiDrawer : public WindowListener {
void SetupDefaultInput() {} void SetupDefaultInput() {}
ImGuiIO& GetIO(); ImGuiIO& GetIO();
void RenderDrawLists();
static const uint64_t kIgnoreAlpha = (1ull << 63); static const uint64_t kIgnoreAlpha = (1ull << 63);
@ -58,7 +58,6 @@ class ImGuiDrawer : public WindowListener {
GraphicsContext* graphics_context_ = nullptr; GraphicsContext* graphics_context_ = nullptr;
ImGuiContext* internal_state_ = nullptr; ImGuiContext* internal_state_ = nullptr;
std::unique_ptr<ImFontAtlas> font_atlas_;
std::unique_ptr<ImmediateTexture> font_texture_; std::unique_ptr<ImmediateTexture> font_texture_;
}; };

View File

@ -210,6 +210,7 @@ void Window::OnPaint(UIEvent* e) {
// Flush ImGui buffers before we swap. // Flush ImGui buffers before we swap.
ImGui::Render(); ImGui::Render();
imgui_drawer_->RenderDrawLists();
ForEachListener([e](auto listener) { listener->OnPainted(e); }); ForEachListener([e](auto listener) { listener->OnPainted(e); });
on_painted(e); on_painted(e);

View File

@ -102,7 +102,7 @@ int window_demo_main(const std::vector<std::wstring>& args) {
window->on_painting.AddListener([&](xe::ui::UIEvent* e) { window->on_painting.AddListener([&](xe::ui::UIEvent* e) {
auto& io = window->imgui_drawer()->GetIO(); auto& io = window->imgui_drawer()->GetIO();
ImGui::ShowTestWindow(); ImGui::ShowDemoWindow();
ImGui::ShowMetricsWindow(); ImGui::ShowMetricsWindow();
// Continuous paint. // Continuous paint.