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(ImGui::GetMainViewport(),
32 ImGuiDockNodeFlags_NoDockingOverCentralNode |
33 ImGuiDockNodeFlags_PassthruCentralNode);
34
35 if (first) {
36 // on startup, focus main openMSX window instead of the GUI window
37 first = false;
38 ImGui::SetWindowFocus(nullptr);
39 }
40
41 // Rendering
42 const ImGuiIO& io = ImGui::GetIO();
43 ImGui::Render();
44 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
45
46 // Update and Render additional Platform Windows
47 // (Platform functions may change the current OpenGL context, so we
48 // save/restore it to make it easier to paste this code elsewhere.
49 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
50 SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
51 SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
52 ImGui::UpdatePlatformWindows();
53 ImGui::RenderPlatformWindowsDefault();
54 SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
55 }
56}
57
58} // 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.
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