diff --git a/fggl/CMakeLists.txt b/fggl/CMakeLists.txt index 4e91e98df5050d043205853e86db5a90607761bf..baa89489ec1371668d7afb836166972744491b17 100644 --- a/fggl/CMakeLists.txt +++ b/fggl/CMakeLists.txt @@ -85,6 +85,9 @@ add_subdirectory(phys/bullet) # Debug backend add_subdirectory(debug) +# platform integrations +add_subdirectory(platform) + ## # begin windows support ## diff --git a/fggl/platform/CMakeLists.txt b/fggl/platform/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5895d7d4093503cd44a7586e8370daf9b5adf9cc --- /dev/null +++ b/fggl/platform/CMakeLists.txt @@ -0,0 +1,3 @@ +if ( CMAKE_SYSTEM_NAME MATCHES "Linux" ) + add_subdirectory(linux) +endif() \ No newline at end of file diff --git a/fggl/platform/linux/CMakeLists.txt b/fggl/platform/linux/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..baafc294c2ee4bb9999032d8e46e527013927caf --- /dev/null +++ b/fggl/platform/linux/CMakeLists.txt @@ -0,0 +1,7 @@ +find_package(Fontconfig) +target_link_libraries(fggl PRIVATE Fontconfig::Fontconfig) + +target_sources( fggl + PRIVATE + fonts.cpp +) \ No newline at end of file diff --git a/fggl/platform/linux/fonts.cpp b/fggl/platform/linux/fonts.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49db2f848ffb4c3abaffd86a995cbffe395e6a19 --- /dev/null +++ b/fggl/platform/linux/fonts.cpp @@ -0,0 +1,34 @@ +/* + * This file is part of FGGL. + * + * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with FGGL. + * If not, see <https://www.gnu.org/licenses/>. + */ + +// +// Created by webpigeon on 23/06/22. +// + +#include <fontconfig/fontconfig.h> + +namespace fggl::platform::Linux { + + void get_font() { + /* FcConfig *config = FcInitLoadConfigAndFonts(); + FcPattern* pat = FcPatternCreate(); + FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT, FC_PIXEL_SIZE, FC_SIZE, nullptr); + FcFontSet* fs = FcFontList(config, pat, os); + + if ( fs ) { + FcFontSetDestroy(fs); + }*/ + } + +} // namespace fggl::platform::linux \ No newline at end of file diff --git a/include/fggl/platform/linux/paths.hpp b/include/fggl/platform/linux/paths.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6a66d5f732a24ab5f20b703fe6748d515959b526 --- /dev/null +++ b/include/fggl/platform/linux/paths.hpp @@ -0,0 +1,63 @@ +/* + * This file is part of FGGL. + * + * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with FGGL. + * If not, see <https://www.gnu.org/licenses/>. + */ + +// +// Low-Level Linux-specific path management +// Created by webpigeon on 23/06/22. +// see https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html +// + +#ifndef FGGL_PLATFORM_LINUX_PATHS_HPP +#define FGGL_PLATFORM_LINUX_PATHS_HPP + +#include <filesystem> +#include <array> + +namespace fggl::platform::Linux { + + constexpr const char* ENV_USER_CONFIG = "XDG_CONFIG_HOME"; + constexpr const char* EVN_USER_DATA = "XDG_DATA_HOME"; + constexpr const char* ENV_USER_CACHE = "XDG_CACHE_HOME"; + + constexpr const char* ENV_DATA_DIRS = "XDG_DATA_DIRS"; + constexpr const char* ENV_CONFIG_DIRS = "XDG_CONFIG_DIRS"; + + // fallback user paths defined in the XDG spec + constexpr const char* DEFAULT_USER_CONFIG = "~/.config"; + constexpr const char* DEFAULT_USER_DATA = "~/.local/share"; + constexpr const char* DEFAULT_USER_CACHE = "~/.cache"; + + // fallback search paths defined in the XDG spec + constexpr const std::array<const char*, 2> DEFAULT_DATA_DIRS = {"/usr/local/share/", "/usr/share/"}; + constexpr const std::array<const char*, 1> DEFAULT_CONFIG_DIRS = {"/etc/xdg"}; + + // search routines for finding data and configuration files + std::filesystem::path locate_data(const std::string& base, const std::filesystem::path& relPath); + std::filesystem::path locate_config(const std::string& base, const std::filesystem::path& relPath); + + // helper functions for getting file pointers + FILE* open_user_config(std::string& base, const std::filesystem::path& relPath); + FILE* open_user_config_rw(std::string& base, const std::filesystem::path& relPath, bool create = true); + + FILE* open_user_cache(std::string& base, const std::filesystem::path& relPath); + FILE* open_user_cache_rw(std::string& base, const std::filesystem::path& relPath, bool create = true); + + FILE* open_user_data(std::string& base, const std::filesystem::path& relPath); + FILE* open_user_data_rw(std::string& base, const std::filesystem::path& relPath, bool create = true); + + // game data is always read only + FILE* open_game_data(std::string& base, const std::filesystem::path& relPath); +} + +#endif //FGGL_PLATFORM_LINUX_PATHS_HPP