After experimenting with integrating Dear ImGui into Panda3D in C++, I remembered the possibility of using Interrogate. Thanks to @rdb, I managed to achieve these results.
This is achieved using this python code.
from direct.showbase.ShowBase import ShowBase
from panda3d.imgui import PImGui, PImGuiCond, PImGuiWindowFlags
from panda3d.core import LPoint2f
class DemoImGui(ShowBase):
def __init__(self):
ShowBase.__init__(self)
PImGui.init(base.cam2d.node().get_display_region(0), self.instruction)
self.window_show_exit = [True]
def instruction(self, index, control):
if self.window_show_exit[0]:
PImGui.window_pos("Panda3D", LPoint2f(50, 50), PImGuiCond.once.value)
PImGui.begin("Panda3D", self.window_show_exit, PImGuiWindowFlags.menu_bar.value | PImGuiWindowFlags.unsaved_document.value)
PImGui.end()
app = DemoImGui()
app.run()
There are annoying factors:
self.window_show_exit = [True]
Since it is not possible to change a variable in place, you have to use dynamic ones.
PImGuiWindowFlags.menu_bar.value
At the moment, why is it impossible to get data from enum immediately without accessing a member named value…
This example does not work, without a patch. On the C++ side, this is implemented in such a way that when the mouse is over the Dear ImGui elements, the ignore button input flag for Panda3D is set.
void PImGui::change_control(bool flag){
NodePath top_node_paths = display_region->get_camera().get_top();
NodePathCollection children = top_node_paths.get_children();
for (int i = 0; i < children.get_num_paths(); ++i) {
NodePath node_path = children.get_path(i);
PT(PandaNode) node = node_path.node();
if (node->get_type().get_name() == "PGTop"){
PT(PGTop) pg_top = DCAST(PGTop, node);
PT(MouseWatcher) mouse_watcher = pg_top->get_mouse_watcher();
PT(MouseAndKeyboard) mouse_keyboard = DCAST(MouseAndKeyboard, mouse_watcher->get_parent(0));
mouse_keyboard->ignore_input = flag;
}
}
}
However, there is a problem, the backend does not always have time to switch the flag back so that Panda3D can process button input again. This often happens when the window is closed via the X icon, as shown in the screenshot.