[imgui] Make code compile with new imgui.

This commit is contained in:
Joel Linn
2019-11-17 23:54:59 +01:00
committed by Rick Gibbed
parent e4c9078cb5
commit 1985169924
5 changed files with 46 additions and 47 deletions

View File

@@ -34,21 +34,18 @@ ImGuiDrawer::ImGuiDrawer(xe::ui::Window* window)
}
ImGuiDrawer::~ImGuiDrawer() {
auto previous_state = ImGui::GetInternalState();
ImGui::SetInternalState(internal_state_.data());
ImGui::Shutdown();
if (previous_state != internal_state_.data()) {
ImGui::SetInternalState(previous_state);
if (internal_state_) {
ImGui::DestroyContext(internal_state_);
internal_state_ = nullptr;
}
current_drawer_ = nullptr;
}
void ImGuiDrawer::Initialize() {
// Setup ImGui internal state.
// This will give us state we can swap to the ImGui globals when in use.
internal_state_.resize(ImGui::GetInternalStateSize());
ImGui::SetInternalState(internal_state_.data(), true);
internal_state_ = ImGui::CreateContext();
current_drawer_ = this;
auto& io = ImGui::GetIO();
@@ -66,7 +63,6 @@ void ImGuiDrawer::Initialize() {
auto& style = ImGui::GetStyle();
style.ScrollbarRounding = 0;
style.WindowFillAlphaDefault = 1.0f;
style.WindowRounding = 0;
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);
@@ -87,7 +83,7 @@ void ImGuiDrawer::Initialize() {
ImVec4(0.00f, 1.00f, 0.15f, 0.62f);
style.Colors[ImGuiCol_ScrollbarGrabActive] =
ImVec4(0.00f, 0.91f, 0.09f, 0.40f);
style.Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.74f, 0.90f, 0.72f, 0.50f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.34f, 0.75f, 0.11f, 1.00f);
@@ -97,23 +93,18 @@ void ImGuiDrawer::Initialize() {
style.Colors[ImGuiCol_Header] = ImVec4(0.00f, 0.40f, 0.00f, 0.71f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.00f, 0.60f, 0.26f, 0.80f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.00f, 0.75f, 0.00f, 0.80f);
style.Colors[ImGuiCol_Column] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.36f, 0.89f, 0.38f, 1.00f);
style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.13f, 0.50f, 0.11f, 1.00f);
style.Colors[ImGuiCol_Separator] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.36f, 0.89f, 0.38f, 1.00f);
style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.13f, 0.50f, 0.11f, 1.00f);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
style.Colors[ImGuiCol_CloseButton] = ImVec4(0.00f, 0.72f, 0.00f, 0.96f);
style.Colors[ImGuiCol_CloseButtonHovered] =
ImVec4(0.38f, 1.00f, 0.42f, 0.60f);
style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.56f, 1.00f, 0.64f, 1.00f);
style.Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
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_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
style.Colors[ImGuiCol_ModalWindowDarkening] =
ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
@@ -231,7 +222,7 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) {
ImGuiIO& ImGuiDrawer::GetIO() {
current_drawer_ = this;
ImGui::SetInternalState(internal_state_.data());
ImGui::SetCurrentContext(internal_state_);
return ImGui::GetIO();
}

View File

@@ -18,6 +18,7 @@
struct ImDrawData;
struct ImFontAtlas;
struct ImGuiContext;
struct ImGuiIO;
namespace xe {
@@ -56,7 +57,7 @@ class ImGuiDrawer : public WindowListener {
Window* window_ = nullptr;
GraphicsContext* graphics_context_ = nullptr;
std::vector<uint8_t> internal_state_;
ImGuiContext* internal_state_ = nullptr;
std::unique_ptr<ImFontAtlas> font_atlas_;
std::unique_ptr<ImmediateTexture> font_texture_;
};