Initial scaffolding.
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
project(hdk-sdl
|
||||||
|
VERSION 0.0.0
|
||||||
|
LANGUAGES CXX
|
||||||
|
)
|
||||||
|
|
||||||
|
# hdk-sdl OPTIONS
|
||||||
|
option(HDK_SDL_BUILD_TESTS "Build hdk-sdl tests" OFF)
|
||||||
|
# TODO: Unit testing
|
||||||
|
if(HDK_SDL_BUILD_TESTS)
|
||||||
|
message(WARNING "hdk-sdl tests are not implemented yet.")
|
||||||
|
endif()
|
||||||
|
option(HDK_SDL_BUILD_EXAMPLES "Build hdk-sdl examples" OFF)
|
||||||
|
if(HDK_SDL_BUILD_EXAMPLES)
|
||||||
|
add_subdirectory(examples)
|
||||||
|
endif()
|
||||||
|
option(HDK_SDL_BUILD_COVERAGE "Build hdk-sdl with coverage reporting enabled" OFF)
|
||||||
|
if(HDK_SDL_BUILD_COVERAGE)
|
||||||
|
message(WARNING "hdk-sdl coverage testing is not implemented yet.")
|
||||||
|
endif()
|
||||||
|
# TODO: Coverage testing
|
||||||
|
|
||||||
|
# FOR SDL Building
|
||||||
|
set(SDL_TEST OFF CACHE BOOL "Disable SDL tests" FORCE)
|
||||||
|
set(SDL_EXAMPLES OFF CACHE BOOL "Disable SDL examples" FORCE)
|
||||||
|
set(SDL_INSTALL OFF CACHE BOOL "Disable SDL install" FORCE)
|
||||||
|
# NOTE: Possibly disable SDL_PIPEWIRE and/or SDL_PIPEWIRE_SHARED?
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
SDL3
|
||||||
|
GIT_REPOSITORY http://github.com/libsdl-org/SDL.git
|
||||||
|
GIT_TAG release-3.4.0
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(SDL3)
|
||||||
|
add_library(hdk-sdl INTERFACE)
|
||||||
|
target_link_libraries(hdk-sdl INTERFACE SDL3::SDL3 hdk-grid)
|
||||||
|
target_include_directories(hdk-sdl INTERFACE ${SDL3_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Simple examples for using hdk-sdl.
|
||||||
|
|
||||||
|
add_executable(HelloWorld HelloWorld.cpp)
|
||||||
|
target_link_libraries(HelloWorld PRIVATE hdk-sdl)
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#include <hdk/sdl.hpp>
|
||||||
|
|
||||||
|
using namespace hdk::sdl;
|
||||||
|
|
||||||
|
Window window { nullptr };
|
||||||
|
//Renderer renderer { nullptr };
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
window = Window::Create("Hello World", 800, 600, 0);
|
||||||
|
if (!window) {
|
||||||
|
SDL_Log("Failed to create window: %s", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
SDL_Event event;
|
||||||
|
bool running = true;
|
||||||
|
while (running) {
|
||||||
|
while (SDL_PollEvent(&event)) {
|
||||||
|
if (event.type == SDL_EVENT_QUIT) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = nullptr; // Explicitly release the window before quitting SDL
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
/**
|
||||||
|
* @file sdl.hpp
|
||||||
|
* @brief HDK - SDL Frontend API
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <hdk/sdl/video/Window.hpp>
|
||||||
|
// TODO #include <hd/sdl/video/Surface.hpp>
|
||||||
|
// TODO #include <hd/sdl/render/Renderer.hpp>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
/**
|
||||||
|
* @file Window.hpp
|
||||||
|
* @brief HDK sdl video header only wrapper for SDL_Window struct & related functions
|
||||||
|
*/
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <hdk/grid/SharedPtrWrapper.hpp>
|
||||||
|
/** Windows are the primary interface for rendering and interacting with the user in SDL */
|
||||||
|
namespace hdk::sdl {
|
||||||
|
class Window : public hdk::grid::SharedPtrWrapper<SDL_Window> {
|
||||||
|
public:
|
||||||
|
/** Inherit constructors from SharedPtrWrapper */
|
||||||
|
using hdk::grid::SharedPtrWrapper<SDL_Window>::SharedPtrWrapper;
|
||||||
|
/**
|
||||||
|
* https://wiki.libsdl.org/SDL3/SDL_CreateWindow
|
||||||
|
* https://wiki.libsdl.org/SDL3/SDL_DestroyWindowSurface
|
||||||
|
*
|
||||||
|
* @param title The title of the window, in UTF-8 encoding. If the title contains UTF-8 characters, you should use SDL_CreateWindowUTF8() instead.
|
||||||
|
* @param w The width of the window in pixels.
|
||||||
|
* @param h The height of the window in pixels.
|
||||||
|
* @param flags 0, or one or more SDL_WindowFlags OR'd together.
|
||||||
|
* @return A Window instance that manages the created SDL_Window. If window creation fails, the returned Window will evaluate to false (i.e., it will be null).
|
||||||
|
*/
|
||||||
|
static Window Create(const char* title, int w, int h, SDL_WindowFlags flags)
|
||||||
|
{
|
||||||
|
return Window(get_or_cache(SDL_CreateWindow(title, w, h, flags), SDL_DestroyWindow));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* https://wiki.libsdl.org/SDL3/SDL_GetWindowFromID
|
||||||
|
* @brief Get window for WindowID
|
||||||
|
* @param id The ID of the window.
|
||||||
|
* @return A Window instance that wraps the SDL_Window. If no window with the given ID exists, the returned Window will evaluate to false (i.e., it will be null).
|
||||||
|
*/
|
||||||
|
static Window GetFromID(SDL_WindowID id)
|
||||||
|
{
|
||||||
|
/** Because it is possible windows were created by other means, we use get_or_view to wrap the SDL_Window without taking ownership */
|
||||||
|
return Window(get_or_view(SDL_GetWindowFromID(id)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user