-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60e7850
commit 8cdbed4
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#pragma once | ||
|
||
#include "tactile/base/container/expected.hpp" | ||
#include "tactile/base/container/smart_ptr.hpp" | ||
#include "tactile/base/prelude.hpp" | ||
#include "tactile/render/window.hpp" | ||
#include "tactile/vulkan/api.hpp" | ||
|
||
struct SDL_Window; | ||
|
||
namespace tactile { | ||
|
||
/// \addtogroup Vulkan | ||
/// \{ | ||
|
||
/** | ||
* Represents a window usable in Vulkan contexts. | ||
*/ | ||
class TACTILE_VULKAN_API VulkanWindow final : public IWindow | ||
{ | ||
public: | ||
TACTILE_DELETE_COPY(VulkanWindow); | ||
TACTILE_DEFAULT_MOVE(VulkanWindow); | ||
|
||
~VulkanWindow() noexcept override = default; | ||
|
||
/** | ||
* Creates a Vulkan window. | ||
* | ||
* \return | ||
* A Vulkan window if successful; an error code otherwise. | ||
*/ | ||
[[nodiscard]] | ||
static auto make() -> Result<VulkanWindow>; | ||
|
||
void show() override; | ||
|
||
void hide() override; | ||
|
||
void maximize() override; | ||
|
||
private: | ||
struct WindowDeleter final | ||
{ | ||
void operator()(SDL_Window* window) noexcept; | ||
}; | ||
|
||
Unique<SDL_Window, WindowDeleter> mWindow; | ||
|
||
explicit VulkanWindow(SDL_Window* window); | ||
}; | ||
|
||
/// \} | ||
|
||
} // namespace tactile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#include "tactile/vulkan/vulkan_window.hpp" | ||
|
||
#include <SDL2/SDL.h> | ||
|
||
#include "tactile/vulkan/vulkan_error.hpp" | ||
|
||
namespace tactile { | ||
|
||
void VulkanWindow::WindowDeleter::operator()(SDL_Window* window) noexcept | ||
{ | ||
SDL_DestroyWindow(window); | ||
} | ||
|
||
auto VulkanWindow::make() -> Result<VulkanWindow> | ||
{ | ||
const auto window_flags = | ||
SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_VULKAN; | ||
auto* window = SDL_CreateWindow("Tactile " TACTILE_VERSION_STRING, | ||
SDL_WINDOWPOS_CENTERED, | ||
SDL_WINDOWPOS_CENTERED, | ||
800, | ||
600, | ||
window_flags); | ||
|
||
if (!window) { | ||
return unexpected(make_error(VulkanError::kInitFailed)); | ||
} | ||
|
||
return VulkanWindow {window}; | ||
} | ||
|
||
VulkanWindow::VulkanWindow(SDL_Window* window) | ||
: mWindow {window} | ||
{} | ||
|
||
void VulkanWindow::show() | ||
{ | ||
SDL_ShowWindow(mWindow.get()); | ||
} | ||
|
||
void VulkanWindow::hide() | ||
{ | ||
SDL_HideWindow(mWindow.get()); | ||
} | ||
|
||
void VulkanWindow::maximize() | ||
{ | ||
SDL_MaximizeWindow(mWindow.get()); | ||
} | ||
|
||
} // namespace tactile |