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.Monitors.push_back(monitor);
|
||||||
|
|
||||||
platform_io.Platform_CreateWindow = [](ImGuiViewport* viewport) {
|
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_io.Platform_DestroyWindow = [](ImGuiViewport* viewport) {
|
||||||
platform::close_window(viewport->PlatformHandle);
|
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_io.Platform_SetWindowPos = [](ImGuiViewport* viewport, const ImVec2 pos) {
|
||||||
platform::set_window_position(viewport->PlatformHandle, 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.
|
/// Requestable window flags, which may or may not be respected by the platform.
|
||||||
enum class WindowFlags {
|
enum class WindowFlags {
|
||||||
None,
|
None = 0,
|
||||||
Resizable,
|
Resizable = 2,
|
||||||
Borderless
|
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.
|
/// Represents a button. This includes keyboard, gamepad and mouse buttons.
|
||||||
enum class InputButton {
|
enum class InputButton {
|
||||||
Invalid,
|
Invalid,
|
||||||
|
@ -134,6 +143,9 @@ namespace platform {
|
||||||
/// Sets the window title.
|
/// Sets the window title.
|
||||||
void set_window_title(window_ptr window, std::string_view 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.
|
/// Queries whether or not the button is currently pressed.
|
||||||
bool get_key_down(InputButton key);
|
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();
|
auto& win = windows.emplace_back();
|
||||||
|
|
||||||
int sdl_flags = SDL_WINDOW_VULKAN | SDL_WINDOW_ALLOW_HIGHDPI;
|
int sdl_flags = SDL_WINDOW_VULKAN | SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
if(flags == WindowFlags::Borderless)
|
if(flags & WindowFlags::Borderless)
|
||||||
sdl_flags |= SDL_WINDOW_BORDERLESS;
|
sdl_flags |= SDL_WINDOW_BORDERLESS;
|
||||||
if(flags == WindowFlags::Resizable)
|
|
||||||
|
if(flags & WindowFlags::Resizable)
|
||||||
sdl_flags |= SDL_WINDOW_RESIZABLE;
|
sdl_flags |= SDL_WINDOW_RESIZABLE;
|
||||||
|
|
||||||
|
if(flags & WindowFlags::Hidden)
|
||||||
|
sdl_flags |= SDL_WINDOW_HIDDEN;
|
||||||
|
|
||||||
auto resolution = platform::get_monitor_resolution();
|
auto resolution = platform::get_monitor_resolution();
|
||||||
|
|
||||||
int real_x = rect.offset.x;
|
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());
|
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) {
|
bool platform::get_key_down(const InputButton key) {
|
||||||
const Uint8 *state = SDL_GetKeyboardState(NULL);
|
const Uint8 *state = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
|
|
Reference in a new issue