Files
spice2x.github.io/src/spice2x/overlay/window.h
T
bicarus 100caa0f5c overlay: refactor overlay layering (#739)
## Link to GitHub Issue or related Pull Request, if one exists
n/a

## Description of change

Create three distinct layers for the overlay:

1. Bottommost persistent layer - non-interactable layer that is always
on. This was only for notifications, but now the FPS widget lives here
as well.
2. Overlay windows layer - most interactable windows go here.
3. Topmost main menu - this is reserved for the main menu (escape key)
and this is a modal dialog that occludes the layers below.

Why? 

- `toggle overlay` behavior with FPS widget *also* toggling on/off was a
bit confusing (now they're two separate keys)
- FPS widget is popular, but it caused the entire overlay to be active,
which affects how input is handled
- the main menu being a standalone window was a little awkward (now it's
a modal)

## Testing
2026-06-07 17:23:08 -07:00

66 lines
2.1 KiB
C++

#pragma once
#include <string>
#include "external/imgui/imgui.h"
#include "external/imgui/misc/cpp/imgui_stdlib.h"
#include "overlay.h"
namespace overlay {
class Window {
public:
virtual ~Window();
// an opportunity to calculate initial window position and size within the ImGui
// window context, since it may not be possible in the Window constructor
virtual void calculate_initial_window() {}
virtual void build_content() = 0;
virtual void update();
virtual void after_render() {};
void build();
void toggle_active();
void set_active(bool active);
bool get_active();
// raise this window to the top of the z-order on its next build. only
// call in response to an explicit user action (keyboard toggle, UI
// button) - not for auto-show / programmatic shows.
void bring_to_front();
protected:
// state
SpiceOverlay *overlay;
bool active = false;
// set when the window transitions to visible so build() raises it to the
// top of the z-order on the next frame
bool request_focus = false;
std::vector<Window*> children;
// settings
bool remove_window_padding = false;
// custom inner window padding, applied before Begin() (preserving border /
// rounding) when x >= 0; ignored if remove_window_padding is set
ImVec2 window_padding = ImVec2(-1, -1);
bool draws_window = true;
ImGuiSizeCallback resize_callback = nullptr;
std::string title = "Title";
ImGuiWindowFlags flags = 0;
size_t toggle_button = ~0u;
bool toggle_button_state = false;
// init settings
// calculate_initial_window() runs only once; results feed ImGuiCond_Once
bool initial_window_calculated = false;
ImVec2 init_pos = ImVec2(0, 0);
ImVec2 init_size = ImVec2(0, 0);
ImVec2 size_min = ImVec2(0, 0);
ImVec2 size_max = ImVec2(-1, -1);
float bg_alpha = 0.96f;
Window(SpiceOverlay *overlay);
};
}