[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 =
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()) {

View File

@ -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());

View File

@ -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;

View File

@ -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_;
};

View File

@ -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);

View File

@ -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.