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 c1c660c commit 464fdfc
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 16 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" }
16 changes: 11 additions & 5 deletions src/core/Core/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include "Application.hpp"

#include <SDL.h>
#include <SDL_error.h>
#include <SDL_events.h>
#include <SDL_filesystem.h>
#include <SDL_video.h>
#include <SDL2/SDL.h>
#include <backends/imgui_impl_opengl3.h>
#include <backends/imgui_impl_sdl2.h>
#include <glad/glad.h>
Expand Down Expand Up @@ -180,10 +176,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 @@ -198,14 +198,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
4 changes: 2 additions & 2 deletions 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 All @@ -10,7 +10,7 @@

namespace App {

enum class ExitStatus : int { SUCCESS = 0, FAILURE = 1 };
enum class ExitStatus : std::uint8_t { SUCCESS = 0, FAILURE = 1 };

class Application {
public:
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
6 changes: 5 additions & 1 deletion src/core/Core/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Window.hpp"

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

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

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

return m_window;
}

SDL_GLContext Window::get_native_context() const {
APP_PROFILE_FUNCTION();

return m_gl_context;
}

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
2 changes: 1 addition & 1 deletion src/core/Platform/Linux/DPIHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Core/DPIHandler.hpp"

#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
2 changes: 1 addition & 1 deletion src/core/Platform/Mac/DPIHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Core/DPIHandler.hpp"

#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
2 changes: 1 addition & 1 deletion src/core/Platform/Windows/DPIHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Core/DPIHandler.hpp"

#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 464fdfc

Please sign in to comment.