Skip to content

Commit

Permalink
Migrated to OGRE's built-in DearIMGUI
Browse files Browse the repository at this point in the history
STATUS:
- ogre imgui port: keyboard/mouse input working!
- ogre imgui port: FIXME: hacked Renderdash to build, but imgui will likely render into it - how to disable??
- ogre imgui port: builds and runs with default font.
- under Debug I get asserts about NewFrame()/EndFrame() mismatches, to be fixed later.
�CODECHANGES:
* imgui deprecated - renamed ImGui::AlignFirstTextHeightToWidgets() to ImGui::AlignTextToFramePadding()
* imgui deprecated - ImGui::GetContentRegionAvailWidth() -> use ImGui::GetContentRegionAvail().x
* imgui deprecated -  GetWindowContentRegionWidth() function. -> 'GetWindowContentRegionMax().x
* imgui deprecated - SetScrollHere() -> SetScrollHereX() + SetScollHereY()
* imgui deprecated - ImGui::TreeAdvanceToLabelPos()      -> use ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetTreeNodeToLabelSpacing());
* imgui deprecated - renamed SetNextTreeNodeOpen() to SetNextItemOpen().
* imgui deprecated - renamed ListBoxHeader(const char* label, ImVec2 size) to BeginListBox().
* imgui deprecated - removed BeginPopupContextWindow(const char*, int mouse_button, bool also_over_items) in favor of BeginPopupContextWindow(const char*, ImGuiPopupFlags flags) with ImGuiPopupFlags_NoOverItems.
* imgui deprecated - removed CalcListClipping() function. Prefer using ImGuiListClipper which can return non-contiguous ranges.
* imgui deprecated - ImGuiCol_ChildWindowBg              -> use ImGuiCol_ChildBg
* imgui deprecated - style: renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg
* imgui deprecated - GetItemsLineHeightWithSpacing()     -> use GetFrameHeightWithSpacing()
* imgui deprecated - InputText: Renamed  ImGuiTextEditCallbackData to ImGuiInputTextCallbackData
* imgui deprecated - SetNextWindowContentWidth(float w)    ->    SetNextWindowContentSize(ImVec2(w, 0.0f))
* imgui deprecated - SetNextWindowPosCenter(ImGuiCond c=0) { SetNextWindowPos(GetMainViewport()->GetCenter(), c, ImVec2(0.5f,0.5f));
* ogre imgui port: use public `GetFont()/GetFontSize()` instead of internal `ImGuiContext->Font/FontSize`
* VehicleAI panel: `Push/PopItemFlag(Disabled)` (imgui_internal) -> `Begin/EndDisabled()` (public BETA API)
  • Loading branch information
ohlidalp committed Feb 4, 2023
1 parent b6b4302 commit 87aa958
Show file tree
Hide file tree
Showing 58 changed files with 277 additions and 37,965 deletions.
12 changes: 6 additions & 6 deletions source/main/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool AppContext::SetUpInput()
bool AppContext::mouseMoved(const OgreBites::MouseMotionEvent& arg) // overrides OgreBites::InputListener
{
App::GetGuiManager()->WakeUpGUI();
App::GetGuiManager()->GetImGui().InjectMouseMoved(arg);
App::GetGuiManager()->GetImGuiInputListener()->mouseMoved(arg);

if (!ImGui::GetIO().WantCaptureMouse) // true if mouse is over any window
{
Expand All @@ -99,7 +99,7 @@ bool AppContext::mouseMoved(const OgreBites::MouseMotionEvent& arg) // overrides
bool AppContext::mouseWheelRolled(const OgreBites::MouseWheelEvent& arg)
{
App::GetGuiManager()->WakeUpGUI();
App::GetGuiManager()->GetImGui().InjectMouseWheelRolled(arg);
App::GetGuiManager()->GetImGuiInputListener()->mouseWheelRolled(arg);

if (!ImGui::GetIO().WantCaptureMouse) // true if mouse is over any window
{
Expand All @@ -112,7 +112,7 @@ bool AppContext::mouseWheelRolled(const OgreBites::MouseWheelEvent& arg)
bool AppContext::mousePressed(const OgreBites::MouseButtonEvent& arg) // overrides OgreBites::InputListener
{
App::GetGuiManager()->WakeUpGUI();
App::GetGuiManager()->GetImGui().InjectMousePressed(arg);
App::GetGuiManager()->GetImGuiInputListener()->mousePressed(arg);

if (!ImGui::GetIO().WantCaptureMouse) // true if mouse is over any window
{
Expand All @@ -135,7 +135,7 @@ bool AppContext::mousePressed(const OgreBites::MouseButtonEvent& arg) // overrid
bool AppContext::mouseReleased(const OgreBites::MouseButtonEvent& arg) // overrides OgreBites::InputListener
{
App::GetGuiManager()->WakeUpGUI();
App::GetGuiManager()->GetImGui().InjectMouseReleased(arg);
App::GetGuiManager()->GetImGuiInputListener()->mouseReleased(arg);

if (!ImGui::GetIO().WantCaptureMouse) // true if mouse is over any window
{
Expand All @@ -155,7 +155,7 @@ bool AppContext::mouseReleased(const OgreBites::MouseButtonEvent& arg) // overri

bool AppContext::keyPressed(const OgreBites::KeyboardEvent& arg)
{
App::GetGuiManager()->GetImGui().InjectKeyPressed(arg);
App::GetGuiManager()->GetImGuiInputListener()->keyPressed(arg);

if (!App::GetGuiManager()->IsGuiCaptureKeyboardRequested() &&
!ImGui::GetIO().WantCaptureKeyboard)
Expand All @@ -168,7 +168,7 @@ bool AppContext::keyPressed(const OgreBites::KeyboardEvent& arg)

bool AppContext::keyReleased(const OgreBites::KeyboardEvent& arg)
{
App::GetGuiManager()->GetImGui().InjectKeyReleased(arg);
App::GetGuiManager()->GetImGuiInputListener()->keyReleased(arg);

if (!App::GetGuiManager()->IsGuiCaptureKeyboardRequested() &&
!ImGui::GetIO().WantCaptureKeyboard)
Expand Down
12 changes: 0 additions & 12 deletions source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ set(SOURCE_FILES
gui/GUIUtils.{h,cpp}
gui/OverlayWrapper.{h,cpp}
gui/RTTLayer.{h,cpp}
gui/imgui/imgui.{h,cpp}
gui/imgui/imgui_demo.cpp
gui/imgui/imgui_draw.cpp
gui/imgui/imgui_widgets.cpp
gui/imgui/OgreImGuiOverlay.{h,cpp}
gui/imgui/OgreImGui.{h,cpp}
gui/imgui/imconfig.h
gui/imgui/imgui_internal.h
gui/imgui/imstb_rectpack.h
gui/imgui/imstb_textedit.h
gui/imgui/imstb_truetype.h
gui/panels/GUI_AngelScriptExamples.{h,cpp}
gui/panels/GUI_CollisionsDebug.{h,cpp}
gui/panels/GUI_ConsoleView.{h,cpp}
Expand Down Expand Up @@ -323,7 +312,6 @@ target_include_directories(${BINNAME} PRIVATE
gfx/particle
gfx/skyx
gui
gui/imgui
gui/mygui
gui/panels
network
Expand Down
4 changes: 2 additions & 2 deletions source/main/gfx/GfxActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "InputEngine.h" // TODO: Keys shouldn't be queried from here, but buffered in sim. loop ~ only_a_ptr, 06/2018
#include "MeshObject.h"
#include "MovableText.h"
#include "OgreImGui.h"

#include "Renderdash.h" // classic 'renderdash' material
#include "ActorSpawner.h"
#include "SlideNode.h"
Expand All @@ -50,7 +50,7 @@
#include "TurboProp.h"
#include "Utils.h"

#include "imgui_internal.h"


#include <Ogre.h>

Expand Down
5 changes: 2 additions & 3 deletions source/main/gfx/GfxScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "TerrainObjectManager.h"
#include "Utils.h"

#include "imgui_internal.h"


#include <Ogre.h>

Expand Down Expand Up @@ -369,7 +369,6 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string
GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme();

ImDrawList* drawlist = GetImDummyFullscreenWindow();
ImGuiContext* g = ImGui::GetCurrentContext();

ImVec2 text_pos(pos.x - ((text_size.x / 2)), pos.y - ((text_size.y / 2)));

Expand All @@ -384,7 +383,7 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string
// draw colored text
Ogre::ColourValue color = App::GetNetwork()->GetPlayerColor(colornum);
ImVec4 text_color(color.r, color.g, color.b, 1.f);
drawlist->AddText(g->Font, g->FontSize, text_pos, ImColor(text_color), caption.c_str());
drawlist->AddText(ImGui::GetFont(), ImGui::GetFontSize(), text_pos, ImColor(text_color), caption.c_str());
}
}

6 changes: 4 additions & 2 deletions source/main/gfx/Renderdash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ void RoR::Renderdash::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
App::GetGfxScene()->GetSceneManager()->setFindVisibleObjects(false);

// Disable DearIMGUI overlay
App::GetGfxScene()->GetSceneManager()->removeRenderQueueListener(&App::GetGuiManager()->GetImGui());
// FIXME: how to prevent OGRE builtin IMGUI from rendering to renderdash?
// App::GetGfxScene()->GetSceneManager()->removeRenderQueueListener(App::GetGuiManager()->GetImGui());

// Disable other overlays
App::GetOverlayWrapper()->HideRacingOverlay();
Expand All @@ -111,7 +112,8 @@ void RoR::Renderdash::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
App::GetGfxScene()->GetSceneManager()->setFindVisibleObjects(true);

// Enable DearIMGUI overlay
App::GetGfxScene()->GetSceneManager()->addRenderQueueListener(&App::GetGuiManager()->GetImGui());
// FIXME: how to prevent OGRE builtin IMGUI from rendering to renderdash?
// App::GetGfxScene()->GetSceneManager()->addRenderQueueListener(&App::GetGuiManager()->GetImGui());

// Overlays 'racing' and 'direction arrow' are re-enabled automatically if needed

Expand Down
33 changes: 24 additions & 9 deletions source/main/gui/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "GUIUtils.h"
#include "InputEngine.h"
#include "Language.h"
#include "OgreImGui.h"

#include "OverlayWrapper.h"
#include "PlatformUtils.h"
#include "RTTLayer.h"
Expand Down Expand Up @@ -310,23 +310,40 @@ void GUIManager::NewImGuiFrame(float dt)
io.KeySuper = false;

// Call IMGUI
Ogre::FrameEvent ev;
ev.timeSinceLastFrame = dt;
Ogre::ImGuiOverlay::NewFrame(ev);
Ogre::ImGuiOverlay::NewFrame();

// Reset state
m_gui_kb_capture_queued = false;
}

void GUIManager::SetupImGui()
{
m_imgui.Init();
// Initialize OGRE's builtin DearIMGUI
// see OGRE source file '/Samples/Simple/include/ImGuiDemo.h'
m_imgui_overlay = new Ogre::ImGuiOverlay();

// handle DPI scaling
float vpScale = Ogre::OverlayManager::getSingleton().getPixelRatio();
ImGui::GetIO().FontGlobalScale = std::round(vpScale); // default font does not work with fractional scaling
ImGui::GetStyle().ScaleAllSizes(vpScale);

m_imgui_overlay->setZOrder(300);
m_imgui_overlay->show();
Ogre::OverlayManager::getSingleton().addOverlay(m_imgui_overlay); // now owned by overlaymgr

// NOTE:
// Custom apps will ASSERT on ImGuiOverlay::NewFrame() and not display any UI if they
// have not registered the overlay system by calling mSceneMgr->addRenderQueueListener(mOverlaySystem).
// Rigs of Rods does this in main().

m_imgui_input_listener = new OgreBites::ImGuiInputListener();

// Colors
ImGuiStyle& style = ImGui::GetStyle();
style.Colors[ImGuiCol_Text] = ImVec4(0.90f, 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.06f, 0.06f, 0.06f, 0.90f);
style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.1f);
style.Colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.1f);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
style.Colors[ImGuiCol_Border] = ImVec4(0.20f, 0.20f, 0.20f, 0.90f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.90f);
Expand Down Expand Up @@ -358,7 +375,7 @@ void GUIManager::SetupImGui()
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.18f, 0.53f, 0.79f, 0.90f);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.13f, 0.40f, 0.60f, 0.90f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.90f);
style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.90f);
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.90f);
// Styles
style.WindowPadding = ImVec2(10.f, 10.f);
style.FrameRounding = 2.f;
Expand All @@ -367,8 +384,6 @@ void GUIManager::SetupImGui()
style.ItemSpacing = ImVec2(5.f, 5.f);
style.GrabRounding = 3.f;
style.WindowBorderSize = 0.f;

App::GetGfxScene()->GetSceneManager()->addRenderQueueListener(&m_imgui);
}

void GUIManager::DrawCommonGui()
Expand Down
14 changes: 10 additions & 4 deletions source/main/gui/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#pragma once

#include "OgreImGui.h"

#include "Application.h"
#include "GUI_MessageBox.h"
#include "GUIUtils.h"

// GUI panels
#include "GUI_CollisionsDebug.h"
Expand Down Expand Up @@ -55,11 +55,13 @@
#include "GUI_VehicleButtons.h"

// Deps
#include <Bites/OgreImGuiInputListener.h>
#include <Bites/OgreWindowEventUtilities.h>
#include <MyGUI.h>
#include <MyGUI_OgrePlatform.h>
#include <MyGUI_UString.h>
#include <OgreOverlay.h>
#include <OgreImGuiOverlay.h>

namespace RoR {

Expand Down Expand Up @@ -154,7 +156,8 @@ class GUIManager: public ZeroedMemoryAllocator

void SetUpMenuWallpaper();

inline OgreImGui& GetImGui() { return m_imgui; }
inline Ogre::ImGuiOverlay* GetImGui() { return m_imgui_overlay; }
OgreBites::ImGuiInputListener* GetImGuiInputListener() { return m_imgui_input_listener; }
inline GuiTheme& GetTheme() { return m_theme; }

void WakeUpGUI();
Expand All @@ -169,12 +172,15 @@ class GUIManager: public ZeroedMemoryAllocator
MyGUI::Gui* m_mygui = nullptr;
MyGUI::OgrePlatform* m_mygui_platform = nullptr;
bool m_hide_gui = false;
OgreImGui m_imgui;
GuiTheme m_theme;
bool m_gui_kb_capture_queued = false; //!< Resets and accumulates every frame
bool m_gui_kb_capture_requested = false; //!< Effective value, persistent
Ogre::Timer m_last_mousemove_time;
bool m_is_cursor_supressed = false; //!< True if cursor was manually hidden.

// DearIMGUI integration
Ogre::ImGuiOverlay* m_imgui_overlay = nullptr;
OgreBites::ImGuiInputListener* m_imgui_input_listener = nullptr;
};

} // namespace RoR
Loading

0 comments on commit 87aa958

Please sign in to comment.