[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

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