openMSX
ImGuiLayer.cc
Go to the documentation of this file.
1#include "ImGuiLayer.hh"
2
3#include "ImGuiManager.hh"
4
5#include <imgui.h>
6#include <imgui_impl_sdl2.h>
7#include <imgui_impl_opengl3.h>
8
9#include <SDL.h>
10
11namespace openmsx {
12
14 : Layer(Layer::Coverage::PARTIAL, Layer::ZIndex::IMGUI)
15 , manager(manager_)
16{
17}
18
19void ImGuiLayer::paint(OutputSurface& /*surface*/)
20{
21 manager.preNewFrame();
22
23 // Start the Dear ImGui frame
26 ImGui::NewFrame();
27
28 manager.paintImGui();
29
30 // Allow docking in main window
31 ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(),
32 ImGuiDockNodeFlags_NoDockingOverCentralNode |
33 ImGuiDockNodeFlags_PassthruCentralNode);
34
35 if (ImGui::GetFrameCount() == 1) {
36 // on startup, focus main openMSX window instead of the GUI window
37 ImGui::SetWindowFocus(nullptr);
38 }
39
40 // Rendering
41 const ImGuiIO& io = ImGui::GetIO();
42 ImGui::Render();
43 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
44
45 // Update and Render additional Platform Windows
46 // (Platform functions may change the current OpenGL context, so we
47 // save/restore it to make it easier to paste this code elsewhere.
48 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
49 SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
50 SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
51 ImGui::UpdatePlatformWindows();
52 ImGui::RenderPlatformWindowsDefault();
53 SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
54
55#ifdef __APPLE__
56 if (ImGui::GetFrameCount() == 1) {
57 // On startup, bring main openMSX window to front, which it doesn't
58 // do it by itself due to creation of platform windows for viewports.
59 SDL_RaiseWindow(SDL_GetWindowFromID(WindowEvent::getMainWindowId()));
60 }
61#endif
62 }
63}
64
65} // namespace openmsx
ImGuiLayer(ImGuiManager &manager)
Definition ImGuiLayer.cc:13
Interface for display layers.
Definition Layer.hh:14
Coverage
Describes how much of the screen is currently covered by a particular layer.
Definition Layer.hh:31
ZIndex
Determines stacking order of layers: layers with higher Z-indices are closer to the viewer.
Definition Layer.hh:19
A frame buffer where pixels can be written to.
static uint32_t getMainWindowId()
Definition Event.hh:218
void ImGui_ImplOpenGL3_NewFrame()
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData *draw_data)
void ImGui_ImplSDL2_NewFrame()
This file implemented 3 utility functions:
Definition Autofire.cc:11