Skip to content

Commit

Permalink
Update SDL2 header usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHelmut committed Apr 1, 2024
1 parent 4ebeb76 commit ba2df71
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 21 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ CheckOptions:
- { key: readability-identifier-length.MinimumVariableNameLength, value: 2 }
- { key: readability-identifier-length.MinimumParameterNameLength, value: 2 }
- { key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors, value: '1' }
- { key: misc-include-cleaner.IgnoreHeaders, value: "SDL2/SDL\.h" }
2 changes: 1 addition & 1 deletion docs/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ add_library(imgui
${imgui_SOURCE_DIR}/imstb_rectpack.h ${imgui_SOURCE_DIR}/imstb_textedit.h
${imgui_SOURCE_DIR}/imstb_truetype.h
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer.cpp)
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer2.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer2.cpp)
# Set include directory based in populated variable `imgui_SOURCE_DIR`.
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
Expand Down
17 changes: 11 additions & 6 deletions src/core/Core/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#include "Application.hpp"

#include <SDL.h>
#include <SDL_error.h>
#include <SDL_events.h>
#include <SDL_filesystem.h>
#include <SDL_render.h>
#include <SDL_video.h>
#include <SDL2/SDL.h>
#include <backends/imgui_impl_sdl2.h>
#include <backends/imgui_impl_sdlrenderer2.h>
#include <imgui.h>
Expand Down Expand Up @@ -162,10 +157,14 @@ ExitStatus App::Application::run() {
}

void App::Application::stop() {
APP_PROFILE_FUNCTION();

m_running = false;
}

void Application::on_event(const SDL_WindowEvent& event) {
APP_PROFILE_FUNCTION();

switch (event.event) {
case SDL_WINDOWEVENT_CLOSE:
return on_close();
Expand All @@ -180,14 +179,20 @@ void Application::on_event(const SDL_WindowEvent& event) {
}

void Application::on_minimize() {
APP_PROFILE_FUNCTION();

m_minimized = true;
}

void Application::on_shown() {
APP_PROFILE_FUNCTION();

m_minimized = false;
}

void Application::on_close() {
APP_PROFILE_FUNCTION();

stop();
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Core/Application.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <SDL.h>
#include <SDL2/SDL.h>

#include <memory>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Core/DPIHandler.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <SDL.h>
#include <SDL2/SDL.h>
#include <imgui.h>

#include "Core/Window.hpp"
Expand Down
7 changes: 5 additions & 2 deletions src/core/Core/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Window.hpp"

#include <SDL_render.h>
#include <SDL_video.h>
#include <SDL2/SDL.h>

#include "Core/DPIHandler.hpp"
#include "Core/Debug/Instrumentor.hpp"
Expand Down Expand Up @@ -47,10 +46,14 @@ Window::~Window() {
}

SDL_Window* Window::get_native_window() const {
APP_PROFILE_FUNCTION();

return m_window;
}

SDL_Renderer* Window::get_native_renderer() const {
APP_PROFILE_FUNCTION();

return m_renderer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Core/Window.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <SDL.h>
#include <SDL2/SDL.h>

#include <string>

Expand Down
3 changes: 1 addition & 2 deletions src/core/Platform/Linux/DPIHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Core/DPIHandler.hpp"

#include <SDL_render.h>
#include <SDL_video.h>
#include <SDL2/SDL.h>
#include <imgui.h>

#include "Core/Debug/Instrumentor.hpp"
Expand Down
8 changes: 7 additions & 1 deletion src/core/Platform/Linux/Resources.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#include "Core/Resources.hpp"

#include <SDL_filesystem.h>
#include <SDL2/SDL.h>

#include <filesystem>
#include <string>
#include <string_view>

#include "Core/Debug/Instrumentor.hpp"

namespace App {

static const std::string BASE_PATH{SDL_GetBasePath()};

std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) {
APP_PROFILE_FUNCTION();

std::filesystem::path font_path{BASE_PATH};
font_path /= "../share";
font_path /= "fonts" / file_path;
return font_path;
}

std::filesystem::path Resources::font_path(const std::string_view& font_file) {
APP_PROFILE_FUNCTION();

return resource_path(font_file);
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/Platform/Mac/DPIHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Core/DPIHandler.hpp"

#include <SDL_render.h>
#include <SDL_video.h>
#include <SDL2/SDL.h>
#include <imgui.h>

#include <cmath>
Expand Down
8 changes: 7 additions & 1 deletion src/core/Platform/Mac/Resources.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#include "Core/Resources.hpp"

#include <SDL_filesystem.h>
#include <SDL2/SDL.h>

#include <filesystem>
#include <string>
#include <string_view>

#include "Core/Debug/Instrumentor.hpp"

namespace App {

static const std::string BASE_PATH{SDL_GetBasePath()};

std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) {
APP_PROFILE_FUNCTION();

std::filesystem::path font_path{BASE_PATH};
font_path /= file_path;
return font_path;
}

std::filesystem::path Resources::font_path(const std::string_view& font_file) {
APP_PROFILE_FUNCTION();

return resource_path(font_file);
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/Platform/Windows/DPIHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Core/DPIHandler.hpp"

#include <SDL_render.h>
#include <SDL_video.h>
#include <SDL2/SDL.h>
#include <imgui.h>

#include "Core/Debug/Instrumentor.hpp"
Expand Down
8 changes: 7 additions & 1 deletion src/core/Platform/Windows/Resources.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#include "Core/Resources.hpp"

#include <SDL_filesystem.h>
#include <SDL2/SDL.h>

#include <filesystem>
#include <string>
#include <string_view>

#include "Core/Debug/Instrumentor.hpp"

namespace App {

static const std::string BASE_PATH{SDL_GetBasePath()};

std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) {
APP_PROFILE_FUNCTION();

std::filesystem::path font_path{BASE_PATH};
font_path /= "../share" / file_path;
return font_path;
}

std::filesystem::path Resources::font_path(const std::string_view& font_file) {
APP_PROFILE_FUNCTION();

return resource_path("fonts") / font_file;
}

Expand Down

0 comments on commit ba2df71

Please sign in to comment.