From 88be24efa2ee67041a7e28151196dd3786f3b63f Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Thu, 23 Jun 2022 23:14:22 +0100 Subject: [PATCH] make a start on platform APIs --- fggl/CMakeLists.txt | 3 ++ fggl/platform/CMakeLists.txt | 3 ++ fggl/platform/linux/CMakeLists.txt | 7 +++ fggl/platform/linux/fonts.cpp | 34 +++++++++++++++ include/fggl/platform/linux/paths.hpp | 63 +++++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 fggl/platform/CMakeLists.txt create mode 100644 fggl/platform/linux/CMakeLists.txt create mode 100644 fggl/platform/linux/fonts.cpp create mode 100644 include/fggl/platform/linux/paths.hpp diff --git a/fggl/CMakeLists.txt b/fggl/CMakeLists.txt index 4e91e98..baa8948 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 0000000..5895d7d --- /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 0000000..baafc29 --- /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 0000000..49db2f8 --- /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 0000000..6a66d5f --- /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 -- GitLab