Add hidden window flag, to be in line with how imgui's sdl backend works
This commit is contained in:
parent
3f2be1e26a
commit
5226aa1200
3 changed files with 31 additions and 7 deletions
|
@ -109,14 +109,16 @@ imgui_backend::imgui_backend() {
|
|||
platform_io.Monitors.push_back(monitor);
|
||||
|
||||
platform_io.Platform_CreateWindow = [](ImGuiViewport* viewport) {
|
||||
viewport->PlatformHandle = platform::open_window("", {viewport->Pos, viewport->Size}, WindowFlags::Borderless);
|
||||
viewport->PlatformHandle = platform::open_window("", {viewport->Pos, viewport->Size}, WindowFlags::Borderless | WindowFlags::Hidden);
|
||||
};
|
||||
|
||||
platform_io.Platform_DestroyWindow = [](ImGuiViewport* viewport) {
|
||||
platform::close_window(viewport->PlatformHandle);
|
||||
};
|
||||
|
||||
platform_io.Platform_ShowWindow = [](ImGuiViewport*) {};
|
||||
platform_io.Platform_ShowWindow = [](ImGuiViewport* viewport) {
|
||||
platform::show_window(viewport->PlatformHandle);
|
||||
};
|
||||
|
||||
platform_io.Platform_SetWindowPos = [](ImGuiViewport* viewport, const ImVec2 pos) {
|
||||
platform::set_window_position(viewport->PlatformHandle, pos);
|
||||
|
|
|
@ -8,11 +8,20 @@
|
|||
|
||||
/// Requestable window flags, which may or may not be respected by the platform.
|
||||
enum class WindowFlags {
|
||||
None,
|
||||
Resizable,
|
||||
Borderless
|
||||
None = 0,
|
||||
Resizable = 2,
|
||||
Borderless = 4,
|
||||
Hidden = 8
|
||||
};
|
||||
|
||||
inline WindowFlags operator|(const WindowFlags a, const WindowFlags b) {
|
||||
return static_cast<WindowFlags>(static_cast<int>(a) | static_cast<int>(b));
|
||||
}
|
||||
|
||||
inline bool operator&(const WindowFlags a, const WindowFlags b) {
|
||||
return static_cast<int>(a) & static_cast<int>(b);
|
||||
}
|
||||
|
||||
/// Represents a button. This includes keyboard, gamepad and mouse buttons.
|
||||
enum class InputButton {
|
||||
Invalid,
|
||||
|
@ -134,6 +143,9 @@ namespace platform {
|
|||
/// Sets the window title.
|
||||
void set_window_title(window_ptr window, std::string_view title);
|
||||
|
||||
/// Show window
|
||||
void show_window(window_ptr window);
|
||||
|
||||
/// Queries whether or not the button is currently pressed.
|
||||
bool get_key_down(InputButton key);
|
||||
|
||||
|
|
|
@ -81,11 +81,15 @@ platform::window_ptr platform::open_window(const std::string_view title, const p
|
|||
auto& win = windows.emplace_back();
|
||||
|
||||
int sdl_flags = SDL_WINDOW_VULKAN | SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
if(flags == WindowFlags::Borderless)
|
||||
if(flags & WindowFlags::Borderless)
|
||||
sdl_flags |= SDL_WINDOW_BORDERLESS;
|
||||
if(flags == WindowFlags::Resizable)
|
||||
|
||||
if(flags & WindowFlags::Resizable)
|
||||
sdl_flags |= SDL_WINDOW_RESIZABLE;
|
||||
|
||||
if(flags & WindowFlags::Hidden)
|
||||
sdl_flags |= SDL_WINDOW_HIDDEN;
|
||||
|
||||
auto resolution = platform::get_monitor_resolution();
|
||||
|
||||
int real_x = rect.offset.x;
|
||||
|
@ -212,6 +216,12 @@ void platform::set_window_title(const platform::window_ptr index, const std::str
|
|||
SDL_SetWindowTitle(window, title.data());
|
||||
}
|
||||
|
||||
void platform::show_window(const platform::window_ptr index) {
|
||||
auto window = get_window(index);
|
||||
|
||||
SDL_ShowWindow(window);
|
||||
}
|
||||
|
||||
bool platform::get_key_down(const InputButton key) {
|
||||
const Uint8 *state = SDL_GetKeyboardState(NULL);
|
||||
|
||||
|
|
Reference in a new issue