diff --git a/.clang-tidy b/.clang-tidy index d6348c4..5d7d22e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -14,10 +14,11 @@ Checks: > -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-macro-usage, + -cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -readability-magic-numbers, -readability-function-cognitive-complexity, - -readability-magic-numbers, -misc-non-private-member-variables-in-classes, -clang-analyzer-optin.cplusplus.UninitializedObject, -misc-static-assert, diff --git a/.gitattributes b/.gitattributes_example similarity index 61% rename from .gitattributes rename to .gitattributes_example index 5f25b9e..8a55791 100644 --- a/.gitattributes +++ b/.gitattributes_example @@ -2,6 +2,11 @@ *.jpg filter=lfs diff=lfs merge=lfs -text *.jpeg filter=lfs diff=lfs merge=lfs -text *.gif filter=lfs diff=lfs merge=lfs -text +*.ico filter=lfs diff=lfs merge=lfs -text +*.icns filter=lfs diff=lfs merge=lfs -text +*.bmp filter=lfs diff=lfs merge=lfs -text +*.tif filter=lfs diff=lfs merge=lfs -text +*.tiff filter=lfs diff=lfs merge=lfs -text *.webp filter=lfs diff=lfs merge=lfs -text *.mp4 filter=lfs diff=lfs merge=lfs -text *.webm filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 221ab66..adc24d6 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -11,14 +11,13 @@ env: jobs: build: - runs-on: macos-latest + runs-on: macos-latest-xlarge steps: - uses: actions/checkout@v3 - name: Install GitHub CLI run: | - brew update brew install llvm ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format" ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy" diff --git a/.gitignore b/.gitignore index 4637fee..da693f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,15 @@ +# Application build output build/ + +# Created by CPack when executing tests. +Testing/ + +# Generated by the profiler on debug. +profile.json *-profile.json + +# Created by running the application. *.log + +# User defined CMake preset file. +CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 488509f..832ab41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,29 @@ cmake_minimum_required(VERSION 3.22) -include(cmake/AppleBuild.cmake) +include(cmake/UniversalAppleBuild.cmake) project( - BasicGuiProjectSetupSDL2OpenGL + BasicGuiProjectSetupOpenGL DESCRIPTION "Base gui project setup with SDL2 and OpenGL." + VERSION 1.0.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(PROJECT_COMPANY_NAME "My Company") +set(PROJECT_COMPANY_NAMESPACE "com.mycompany") # Reverse domain name notation + include(cmake/StandardProjectSettings.cmake) +include(GNUInstallDirs) -# Link this "library" to use the warnings specified in CompilerWarnings.cmake +# Link this "library" to use the warnings specified in CompilerWarnings.cmake. add_library(project_warnings INTERFACE) include(cmake/CompilerWarnings.cmake) set_project_warnings(project_warnings) +enable_testing() + +add_subdirectory(packaging) add_subdirectory(vendor) add_subdirectory(src) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..89d8f55 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 22, + "patch": 0 + }, + "configurePresets": [ + { + "name": "debug", + "displayName": "Debug", + "generator": "Ninja", + "binaryDir": "build/debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release", + "displayName": "Release", + "generator": "Ninja", + "binaryDir": "build/release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "xcode-debug", + "displayName": "Debug (Xcode)", + "generator": "Xcode", + "binaryDir": "build/xcode-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "xcode-release", + "displayName": "Release (Xcode)", + "generator": "Xcode", + "binaryDir": "build/xcode-release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ] +} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1c8e83f..c769e20 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -101,7 +101,7 @@ Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an +standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within diff --git a/LICENSE b/LICENSE index f41d1f2..b1503be 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Martin Helmut Fieber +Copyright (c) 2022-2023 Martin Helmut Fieber Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 1917d1b..c92f1b5 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,22 @@ # Base GUI project setup with SDL2 and OpenGL -C++ gui project template with SDL2 and OpenGL 4.1. +C++ GUI project template with [SDL2](https://www.libsdl.org) and [Dear ImGUI](https://github.com/ocornut/imgui) with +OpenGL 4.1. ![Image of the example app.](example-app.png) -## Setup +## How to get started -The project uses [CMake](https://cmake.org) and [Ninja](https://ninja-build.org). +After using this template to create your own repository, it is time to first run and then customize! -Build the application in debug mode: +- Start here: [Quick Start](docs/QuickStart.md) +- Continue here: [Usage Guide](docs/README.md) -```shell -cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug -ninja -C build/debug -``` +## Other versions -Run the application: - -```shell -cd ./build/debug/src/app && ./App -``` - -### Using Litr - -When using [Litr](https://github.com/krieselreihe/litr), the quick setup to build and run the application is: - -```shell -litr build,start -``` +There is also a [SDL2 version using the SDL2 Renderer](https://github.com/MartinHelmut/cpp-gui-template-sdl2) instead of +OpenGL specifically, but it does not support +multi-viewports or detached widgets. ## Disclaimer diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 7ace506..4c7aa5c 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -41,7 +41,7 @@ function(set_project_warnings project_name) set(CLANG_WARNINGS -Wall -Wextra # reasonable and standard - # -Wshadow # warn the user if a variable declaration shadows one from a + -Wshadow # warn the user if a variable declaration shadows one from a # parent context -Wnon-virtual-dtor # warn the user if a class with virtual functions has a # non-virtual destructor. This helps catch hard to @@ -56,9 +56,6 @@ function(set_project_warnings project_name) -Wnull-dereference # warn if a null dereference is detected -Wformat=2 # warn on security issues around functions that format output # (ie printf) - # @todo: Temporarily deactivated for SDL2 - # -Wdouble-promotion # warn if float is implicit promoted to double - # -Wold-style-cast # warn for c-style casts ) if (WARNINGS_AS_ERRORS) @@ -69,7 +66,7 @@ function(set_project_warnings project_name) set(GCC_WARNINGS ${CLANG_WARNINGS} -Wmisleading-indentation # warn if indentation implies blocks where blocks - # @todo: Currently not supported in CI due to an old gcc version. + # @todo: Somehow those make problems in some versions of Clang in Windows. So I deactivate them for now. # -Wduplicated-branches # warn if if / else branches have duplicated code # -Wduplicated-cond # warn if if / else chain has duplicated conditions # -Wlogical-op # warn about logical operations being used where bitwise were diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 6e7c820..3625da5 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -4,7 +4,7 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui, ccmake - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo") endif () find_program(CCACHE ccache) @@ -23,11 +23,6 @@ if (DEACTIVATE_LOGGING) add_compile_definitions(APP_DEACTIVATE_LOGGING) endif () -option(TRACE "Enable detailed execution flow tracing" OFF) -if (TRACE) - add_compile_definitions(TRACE) -endif () - option(DEBUG "Enable debug statements and asserts" OFF) if (DEBUG OR CMAKE_BUILD_TYPE STREQUAL "Debug") add_compile_definitions(DEBUG APP_PROFILE) diff --git a/cmake/StaticAnalyzers.cmake b/cmake/StaticAnalyzers.cmake index 95b68ee..2d0406f 100644 --- a/cmake/StaticAnalyzers.cmake +++ b/cmake/StaticAnalyzers.cmake @@ -1,14 +1,14 @@ if (NOT CMAKE_BUILD_TYPE STREQUAL "Release") find_program(CLANGTIDY clang-tidy) if (CLANGTIDY) - message(STATUS "Using clang-tidy") + message(STATUS "Using clang-tidy, found ${CLANGTIDY}") set(CMAKE_CXX_CLANG_TIDY "${CLANGTIDY};-extra-arg=-Wno-unknown-warning-option") else () message(WARNING "clang-tidy requested but executable not found") endif () # This will gradually increase memory usage of the program, - # running on Apple M1, 13.0. + # discovered on Apple M1, 13.0. if (NOT WIN32) message(STATUS "Using address sanitizer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -fsanitize=address -g") diff --git a/cmake/AppleBuild.cmake b/cmake/UniversalAppleBuild.cmake similarity index 63% rename from cmake/AppleBuild.cmake rename to cmake/UniversalAppleBuild.cmake index 5f88786..edf74f9 100644 --- a/cmake/AppleBuild.cmake +++ b/cmake/UniversalAppleBuild.cmake @@ -1,9 +1,8 @@ # This file needs to be included before calling `project`. -if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if (APPLE AND "${CMAKE_GENERATOR}" STREQUAL "Xcode") # Generate universal executable for Apple hardware. - set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "") + set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)") # Support older macOS versions. set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "Minimum OS X deployment version") - set(CMAKE_OSX_SYSROOT macosx10.15) endif () diff --git a/docs/ApplicationIcons.md b/docs/ApplicationIcons.md new file mode 100644 index 0000000..5d64b44 --- /dev/null +++ b/docs/ApplicationIcons.md @@ -0,0 +1,120 @@ +# Application icons + +## Generate app icons + +### macOS + +To generate a `.icns` file on macOS, an `.iconset` folder needs to be converted via `iconutil`. The +folder `src/assets/icons/icon.iconset` contains all needed icon sizes. To generate the needed app icon under `src/assets/icons/icon.icns`, run from inside the `src/assets/icons` folder: + +```shell +iconutil -c icns icon.iconset +``` + +### Windows + +To create the `icon.ico` file [ImageMagick](https://www.imagemagick.org) is used. From inside the `src/assets/icons` folder run: + +```shell +convert \ + windows/icon_16x16.png windows/icon_32x32.png \ + windows/icon_64x64.png windows/icon_128x128.png \ + windows/icon_256x256.png windows/icon_512x512.png \ + icon.ico +``` + +Verify that the `icon.ico` was successfully created: + +```shell +identify icon.ico +``` + +### Linux + +There is no need to generate an icon set for Linux. A high resolution PNG (1024x1024px) is enough for the app icon. This is located under `icons/BaseAppIcon.png`. + +## Icon design guidelines + +The example project contains an example icon. To get guiding for creating an own unique app icon, here a couple of resources: + +- [Windows app icon guidelines](https://learn.microsoft.com/en-us/windows/apps/design/style/iconography/app-icon-design) +- [Apple human interface design, icons guide](https://developer.apple.com/design/human-interface-guidelines/foundations/app-icons/) + +## Integrating icons + +How are those application icons connected to become the icon of the generated executable? Through the packaging process and manifest files. + +### Package app icons + +For macOS and Windows app icons are packed as static resources via CMake's [target_sources](https://cmake.org/cmake/help/latest/command/target_sources.html) function in `src/app/cmake/AppAssets.cmake`. For example, adding the Windows `.ico` file to the main executable: + +```cmake +# src/app/cmake/AppAssets.cmake +target_sources(App PUBLIC ${PROJECT_SOURCE_DIR}/src/assets/icons/icon.ico) +``` + +On Linux, it needs to be part of the installation process that is defined in `src/app/cmake/packaging/Linux.cmake`, where application icons are installed in a shared directory `share/pixmaps`. This does look like the following: + +```cmake +# src/app/cmake/packaging/Linux.cmake +install(FILES ${PROJECT_SOURCE_DIR}/src/assets/icons/BaseAppIcon.png + DESTINATION share/pixmaps) +``` + +### Manifest files + +The manifest files then link the app icon to the executable. + +#### macOS + +For macOS the manifest file is an [Info.plist](https://developer.apple.com/documentation/bundleresources/information_property_list) defining application properties. It is located at `src/app/Manifests/Info.plist` and added to the app bundle through `src/app/cmake/packaging/Darwin.cmake`. Here the CMake function [set_target_properties](https://cmake.org/cmake/help/latest/command/set_target_properties.html) defines `MACOSX_BUNDLE_INFO_PLIST` for the manifest location. The icon name is defined inside the `Info.plist` file under the property name `CFBundleIconFile`. + +```cmake +# src/app/cmake/packaging/Darwin.cmake + +# Reduced version of `set_target_properties` as example to set the manifest file. +set_target_properties(App PROPERTIES + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Manifests/Info.plist") +``` + +#### Windows + +The resource file `src/app/Manifests/app.rc` will bind the icon to the Windows executable. The resource file itself is then added as part of the application bundle via [target_sources](https://cmake.org/cmake/help/latest/command/target_sources.html) in `src/app/cmake/AppAssets.cmake`. + +```cmake +target_sources(App PUBLIC + ${PROJECT_SOURCE_DIR}/src/assets/icons/icon.ico + ${PROJECT_SOURCE_DIR}/src/app/Manifests/app.rc) +``` + +#### Linux + +For Linux a `src/app/Manifests/App.desktop.in` defines the created shortcut with icon. The `.in` file will be processed by CMake via [configure_file](https://cmake.org/cmake/help/latest/command/configure_file.html) in `src/app/cmake/packaging/Linux.cmake`. + +It will take the `.in` file and produce a final `.desktop` file for Linux with the given icon name under the property `Icon=`. + +```cmake +# src/app/cmake/packaging/Linux.cmake +configure_file( + ${PROJECT_SOURCE_DIR}/src/app/Manifests/App.desktop.in + ${CMAKE_CURRENT_BINARY_DIR}/App.desktop + @ONLY) +``` + +The icon and the `.desktop` file then need to be installed. + +```cmake +# src/app/cmake/packaging/Linux.cmake + +# Install .desktop file under share/applications +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/App.desktop + DESTINATION share/applications) + +# Install icon file under share/pixmaps +install(FILES ${PROJECT_SOURCE_DIR}/src/assets/icons/BaseAppIcon.png + DESTINATION share/pixmaps) +``` + +*** + +Next up: [Fonts](Fonts.md) diff --git a/docs/BuildAndExecution.md b/docs/BuildAndExecution.md new file mode 100644 index 0000000..b6754c5 --- /dev/null +++ b/docs/BuildAndExecution.md @@ -0,0 +1,123 @@ +# Build and execution + +## Configure + +There are options that can be used to create the project configuration before build. + +### `CMAKE_BUILD_TYPE` + +Always needs to be set, usual values are `Debug`, `Release`, or `RelWithDebInfo` for the different build targets. + +**Example:** + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug +``` + +### `DEACTIVATE_LOGGING` + +Can be set to stop the application from logging. + +**Example:** + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DDEACTIVATE_LOGGING -B build/debug +``` + +### `DEBUG` + +Will not only enable application internal debugging, but also profiling (`APP_PROFILE`). This option is mainly useful to get debugging and profiling output on release builds. + +**Example:** + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DDEBUG -B build/release +``` + +### `APP_PROFILE` + +Enable profiling, useful for profiling a release build. + +**Example:** + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DAPP_PROFILE -B build/release +``` + +### `WARNINGS_AS_ERRORS` + +Treat compiler warnings as errors. This option is by default **true**. To disable set it to `FALSE`. + +**Example:** + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DWARNINGS_AS_ERRORS=FALSE -B build/debug +``` + +## Build + +After configuration the application can be built through CMake via `cmake --build`, passing a build folder as argument. + +**Example:** + +```shell +cmake --build build/debug +``` + +This will build the application with the given configuration. Depending on the platform it was executed on a different build directory structure will be generated, reflecting how the application will latter be [installed on packaging](Packaging.md). + +## Execute + +When not running through an [IDE like CLion](https://www.jetbrains.com/clion), the built application can be run by directly executing the generated binary. Depending on the operating system it can be found at a different place, as different build directory structures are generated. + +### macOS + +On Apple devices an app package structure is created under `./build//src/app/App.app`, where `` is the build target like **debug** or **release**. Inside that [application bundle](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html#//apple_ref/doc/uid/10000123i-CH100-SW1) is the app executable. + +Run on a built target, in this example **debug**: + +```shell +./build/debug/src/app/App.app/Contents/MacOS/App +``` + +Though, even better is to use **XCode as generator** to create app builds on macOS. Only difference in usage is running CMake with `-GXCode`. If `CMAKE_OSX_ARCHITECTURES` is not set, it will create universal binaries on M1/2 macs. + +To run a **debug** build created with XCode: + +```shell +./build/xcode/src/app/Debug/App.app/Contents/MacOS/App +``` + +To run a **release** build created with XCode: + +```shell +./build/xcode/src/app/Release/App.app/Contents/MacOS/App +``` + +### Windows + +To run a **debug** build: + +```shell +build/debug/src/app/App.exe +``` + +To run a **release** build: + +```shell +build/release/src/app/App.exe +``` + +### Linux + +For Linux the generated structure is a direct executable, as libraries and assets have dedicated locations on the system. + +Run on a built target, in this example **debug**: + +```shell +./build/debug/src/app/App +``` + +*** + +Next up: [Testing](Testing.md) diff --git a/docs/Dependencies.md b/docs/Dependencies.md new file mode 100644 index 0000000..3ab49c5 --- /dev/null +++ b/docs/Dependencies.md @@ -0,0 +1,104 @@ +# Dependencies + +Dependencies are located in `vendor/`. The `vendor/CMakeLists.txt` uses +CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) to load dependencies on configure +time. Every dependency also has an associated folder containing a `CMakeLists.txt` for configuration. + +## Already included + +The following set of dependencies is already included: + +- [Doctest](https://github.com/doctest/doctest) - Testing framework +- [fmtlib](https://fmt.dev/latest/index.html) - Formatting library +- [Dear ImGUI](https://github.com/ocornut/imgui) - Immediate mode GUI library +- [SDL2](https://www.libsdl.org) - Media layer library for rendering and input abstraction +- [spdlog](https://github.com/gabime/spdlog) - Logging library + +## Add new dependency with CMake support + +If a package to be included already supports CMake the process of adding it is rather straight forward. It needs a new +entry in `vendor/CMakeLists.txt` to fetch the actual contents. Via `FetchContent_Declare` a name, repo URL and tag, +branch, or commit name is given. + +```cmake +# vendor/CMakeLists.txt + +# Example inclusion of spdlog +FetchContent_Declare( + spdlog + GIT_REPOSITORY "https://github.com/gabime/spdlog.git" + GIT_TAG v1.11.0 +) +add_subdirectory(spdlog) +``` + +After adding this to the `vendor` CMake file, a new `CMakeLists.txt` needs to be created in a new folder for the +dependency. Again with the spdlog example: + +```cmake +# vendor/spdlog/CMakeLists.txt + +message(STATUS "Fetching spdlog ...") + +# Any package build settings here +set(SPDLOG_FMT_EXTERNAL "ON") + +FetchContent_MakeAvailable(spdlog) +``` + +This dependency specific CMake file will contain a message for fetching the library, any package configuration, and a +call to `FetchContent_MakeAvailable` with the given name to add them to the build. + +## New dependency without CMake support + +Adding a package that does not support CMake works almost the same as with support above. The difference is that the new +library needs to be declared. Taking Dear ImGui as an example, that does not support CMake, this is how the setup is +done: + +```cmake +message(STATUS "Fetching imgui ...") + +# Define build options. +set(CMAKE_CXX_STANDARD 20) + +# Populate scope with library variables to get access to source and build directories. +FetchContent_GetProperties(imgui) +if (NOT imgui_POPULATED) + FetchContent_Populate(imgui) +endif () + +# Add Dear ImGUI as library with needed source files. +add_library(imgui + ${imgui_SOURCE_DIR}/imgui.cpp ${imgui_SOURCE_DIR}/imgui.h + ${imgui_SOURCE_DIR}/imconfig.h ${imgui_SOURCE_DIR}/imgui_demo.cpp + ${imgui_SOURCE_DIR}/imgui_draw.cpp ${imgui_SOURCE_DIR}/imgui_internal.h + ${imgui_SOURCE_DIR}/imgui_tables.cpp ${imgui_SOURCE_DIR}/imgui_widgets.cpp + ${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_opengl3.h ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp) + +# Set include directory based in populated variable `imgui_SOURCE_DIR`. +target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) + +# Link external library SDL2, part of the dependencies as well. +target_link_libraries(imgui PUBLIC SDL2::SDL2) + +# Add to main build +FetchContent_MakeAvailable(imgui) +``` + +## Link dependency + +After adding a new dependency, to actually use it, it needs to be added to a target via `target_link_libraries`. For +example adding ImGUI to Core: + +```cmake +# other CMake ... + +target_link_libraries(Core PUBLIC imgui) +``` + +*** + +Next up: [Packaging](Packaging.md) diff --git a/docs/Fonts.md b/docs/Fonts.md new file mode 100644 index 0000000..d7779f9 --- /dev/null +++ b/docs/Fonts.md @@ -0,0 +1,35 @@ +# Fonts + +Applications fonts are in `src/assets/fonts`, and the template comes with the amazing open source font [Manrope](https://manropefont.com). + +## Add new font + +After adding a new font to the `src/assets/fonts` folder, the fonts needs to be added to ImGUI. This is done in `src/core/Core/Application.cpp`, the `run` method. + +```c++ +ExitStatus App::Application::run() { + // other code ... + + // Get DPI scaling for high DPI display handling. + const float font_scaling_factor{DPIHandler::get_scale()}; + + // Sets the base font size, scaled relative to the monitor DPI. + const float font_size{18.0F * font_scaling_factor}; + + // Load the actual font file from resources. + const std::string font_path{Resources::font_path("Manrope.ttf").generic_string()}; + + // Add font to make it available for display. + io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); + + // Set default font file. + io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); + + // DPI handling. + DPIHandler::set_global_font_scaling(&io); +} +``` + +*** + +Next up: [High DPI support](HighDPISupport.md) diff --git a/docs/HighDPISupport.md b/docs/HighDPISupport.md new file mode 100644 index 0000000..2676391 --- /dev/null +++ b/docs/HighDPISupport.md @@ -0,0 +1,13 @@ +# High DPI support + +The template app supports high DPI displays out-of-the-box. The header `src/core/Core/DPIHandler.hpp` defines the interface for DPI handling. The implementations are in `src/core/Platform` under `DPIHandler.cpp` per platform. + +The following two functions are important for DPI handling. + +## `get_scale()` + +Returns a `float` scaling factor used to set render and font scale. Should be used whenever a relative scaling is needed. See usage in platform `DPIhandler.cpp` files and `src/core/Core/Application.cpp`, `run` method. + +## `get_dpi_aware_window_size()` + +Returns a `WindowSize`, a struct with height and width as `int`. Will scale `Window::Settings` DPI aware per platform. See file `src/core/Core/Window.cpp`. diff --git a/docs/Logging.md b/docs/Logging.md new file mode 100644 index 0000000..31e5ef3 --- /dev/null +++ b/docs/Logging.md @@ -0,0 +1,46 @@ +# Logging + +The library [spdlog](https://github.com/gabime/spdlog) is used for logging. The logger is set up in `src/core/Core/Log.{cpp,hpp}` that will define a default logger writing to stdout and into a `app.log` file. The macros used for logging are defined in `src/core/Core/Log.hpp`. + +## Available macros + +The available macros are defined in order of severity. + +- `APP_TRACE` +- `APP_DEBUG` +- `APP_INFO` +- `APP_WARN` +- `APP_ERROR` +- `APP_FATAL` + +The levels `APP_TRACE` and `APP_DEBUG` are only enabled in debug mode or when `DEBUG` is defined through CMake. + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DDEBUG -B build/release +``` + +Logging can also fully be **deactivated** via `DEACTIVATE_LOGGING`. + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DDEACTIVATE_LOGGING -B build/debug +``` + +## Usage + +Include the logger and use one of the macros. All logger macros use fmt under the hood for string formatting. + +```c++ +#include "Core/Log.hpp" + +namespace App { + +Window::Window(const Settings& settings) { + APP_DEBUG("Window created: {}", settings.title); +} + +} +``` + +*** + +Next up: [Dependencies](Dependencies.md) diff --git a/docs/MakeItYourOwn.md b/docs/MakeItYourOwn.md new file mode 100644 index 0000000..ac79e0d --- /dev/null +++ b/docs/MakeItYourOwn.md @@ -0,0 +1,43 @@ +# Make it your own + +There are some variables and settings that should be adapted to specific project needs. + +## Project name and company + +Inside the root `CMakeLists.txt`, the CMake [project](https://cmake.org/cmake/help/latest/command/project.html) call also defines the project name as `CMAKE_PROJECT_NAME` variable. This is currently called `BasicGuiProjectSetup`. Here an example how this could look like: + +```cmake +# CMakeLists.txt +project( + MySuperAppName + DESCRIPTION "This is a crazy good app." + VERSION 1.0.0 + LANGUAGES CXX) +``` + +In that same file, the **project company name and namespace** ([Reverse domain name notation](https://en.wikipedia.org/wiki/Reverse_domain_name_notation)) are defined. + +```cmake +# CMakeLists.txt + +# ... + +set(PROJECT_COMPANY_NAME "My Company") +set(PROJECT_COMPANY_NAMESPACE "com.mycompany") # Reverse domain name notation +``` + +## App icons + +App icons are located under `src/assets/icons/`. There is dedicated documentation on how to update and integrate those into the project under [Application Icons](ApplicationIcons.md). + +## Installer graphics + +The installer on macOS and Windows are graphical and use some images to properly represent the app. Images and documentation for macOS are in `packaging/dmg/`, same for Windows under `packaging/nsis/`. + +## Code of conduct + +There is a basic Code of Conduct (CoC) provided by https://www.contributor-covenant.org in `CODE_OF_CONDUCT.md`. Search for `EMAIL` inside that document to provide a contact for the CoC. + +*** + +Next up: [Build and Execution](BuildAndExecution.md) diff --git a/docs/Packaging.md b/docs/Packaging.md new file mode 100644 index 0000000..4a7afbc --- /dev/null +++ b/docs/Packaging.md @@ -0,0 +1,73 @@ +# Packaging + +The app comes with packaging through [CPack](https://cmake.org/cmake/help/latest/module/CPack.html), creating installer for macOS, Windows, and Linux. + +General packaging settings are located under `packaging/`. Executable specific settings in `src/app/cmake/Packaging.cmake` and OS specifics under `src/app/cmake/packaging/`. + +## General packaging settings + +General packaging settings are in `packaging/CMakeLists.txt`. It defines names, versions, metadata, where to build the package to (`build/distribution/`), and more. + +## OS specific settings + +### macOS + +For macOS a `.dmg` (DragNDrop) file will be generated. Resources for the installer are located under `packaging/dmg/`, containing the background image for the DMG view and an apple script to generate the custom DMG view. + +Packaging settings for the application executable are in `src/app/cmake/packaging/Darwin.cmake`. + +The final application build for Apple devices should be built via the `Xcode` generator with CMake. + +```shell +cmake -GXCode -DCMAKE_BUILD_TYPE=Release -B build/xcode +cmake --build build/xcode +``` + +### Windows + +On Windows a `.exe` is created via [NSIS](https://nsis.sourceforge.io/Main_Page). NSIS **needs to be installed** in Windows to create the package. Resources for the installer are located under `packaging/nsis/`, containing installer images and the uninstaller icon. + +Packaging settings for the application executable are in `src/app/cmake/packaging/Windows.cmake`. + +For windows there are also installer texts defined in `packaging/CMakeLists.txt`. Specifically a welcome text, description, readme, and license; as txt files under `packaging/`. The CPack variables are: + +```cmake +set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_LIST_DIR}/Welcome.txt) +set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_LIST_DIR}/Description.txt) +set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_LIST_DIR}/Readme.txt) +set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_LIST_DIR}/License.txt) +``` + +### Linux + +On Linux a `.deb` file will be created that can be installed via the systems package manager. + +Packaging settings for the application executable are in `src/app/cmake/packaging/Linux.cmake`. + +## Distribution package creation + +A release build is needed before creating the distribution package. Packages **for a system** are created **on the system**. + +### macOS + +XCode should be used to create the release build for the application distributable. + +```shell +cmake -GXCode -DCMAKE_BUILD_TYPE=Release -B build/xcode +cmake --build build/xcode +cpack --config build/xcode/CPackConfig.cmake +``` + +**Attention:** Creating the package will open a Finder window a couple of times to set the DMG window properties. This windows should be ignored and will auto-close. + +### Windows & Linux + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Release -B build/release +cmake --build build/release +cpack --config build/release/CPackConfig.cmake +``` + +*** + +Next up: [Platform dependent code](PlatformCode.md) diff --git a/docs/PlatformCode.md b/docs/PlatformCode.md new file mode 100644 index 0000000..c448cc2 --- /dev/null +++ b/docs/PlatformCode.md @@ -0,0 +1,67 @@ +# Platform dependent code + +Platform dependent code is implemented via [CMake's target_sources](https://cmake.org/cmake/help/latest/command/target_sources.html) function, adding files conditionally to a target. + +## Example + +Currently, the _Core_ library has platform dependent code. Let's take the `Resources` class as example. A common interface is defined in `src/core/Core/Resources.hpp`, looking as follows. + +```c++ +// src/core/Core/Resources.hpp +#pragma once + +#include +#include + +namespace App { + +class Resources { + public: + [[nodiscard]] static std::filesystem::path resource_path(const std::filesystem::path& file_path); + [[nodiscard]] static std::filesystem::path font_path(const std::string_view& font_file); +}; + +} // namespace App +``` + +The platform specific implementations are then defined in `src/core/Platform`, e.g. for macOS. + +```c++ +// src/core/Platform/Mac/Resources.cpp +#include "Core/Resources.hpp" + +namespace App { + +std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) { + // ... +} + +std::filesystem::path Resources::font_path(const std::string_view& font_file) { + // ... +} + +} // namespace App +``` + +In Core's CMake file `src/core/CMakeLists.txt` the function `target_sources` is used to conditionally include those implementations. + +```cmake +# src/core/CMakeLists.txt + +# other CMake code ... + +# Define the set of OS specific target files. +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_sources(Core PRIVATE Platform/Windows/Resources.cpp) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_sources(Core PRIVATE Platform/Mac/Resources.cpp) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_sources(Core PRIVATE Platform/Linux/Resources.cpp) +endif () +``` + +The same approach can be extended to include other platforms, too. + +*** + +Next up: [Application icons](ApplicationIcons.md) diff --git a/docs/Profiling.md b/docs/Profiling.md new file mode 100644 index 0000000..aa6c076 --- /dev/null +++ b/docs/Profiling.md @@ -0,0 +1,74 @@ +# Profiling + +The template comes with a small profiling tool included, defining a set of macros in `src/core/Core/Debug/Instrumentor.hpp`. + +**Remark:** For growing application needs consider using another option like tools built into your IDE, or find the right tool here: [List of profiling and benchmarking tools](https://hackingcpp.com/cpp/tools/profilers.html). + +## Setup + +The profiler is set up inside the application main entry file `src/app/App/Main.cpp`. A profiling session is defined through `APP_PROFILE_BEGIN_SESSION_WITH_FILE` and `APP_PROFILE_END_SESSION`. + +The `APP_PROFILE_BEGIN_SESSION_WITH_FILE` macro takes a session name and a file where the profiling results will be written to. The profiler is defined as a set of **macros to be stripped on release** builds. + +```c++ +#include "Core/Debug/Instrumentor.hpp" + +int main() { + APP_PROFILE_BEGIN_SESSION_WITH_FILE("App", "profile.json"); + + // other code ... + + APP_PROFILE_END_SESSION(); + + return 0; +} +``` + +## Add to code + +There are two different macros defined to profile code: `APP_PROFILE_FUNCTION` and `APP_PROFILE_SCOPE`. + +### `APP_PROFILE_FUNCTION` + +This macro will profile a function and will automatically take its name from the function name. It needs to be set at the beginning of the function. + +```c++ +// src/core/Core/Application.cpp +Application::Application(const std::string& title) { + APP_PROFILE_FUNCTION(); + + // More code ... + m_window = std::make_unique(Window::Settings{title}); +} +``` + +To fully capture profiling data all functions should start with the `APP_PROFILE_FUNCTION` macro. + +### `APP_PROFILE_SCOPE` + +If a custom scope needs to be profiled `APP_PROFILE_SCOPE` can be used. It takes a name for the scope. + +```c++ +// Example function +int Application::run() { + // ... + + while (something) { + APP_PROFILE_SCOPE("MainLoop"); + + // loop ... + } +} +``` + +## Show results + +The resulting JSON file uses the [Trace Event Format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview). Any tool that can read this format can visualize the profiler data. For example the web tool [Perfetto](https://ui.perfetto.dev/) or Chromes built in [chrome://tracing](chrome://tracing). Just drag&drop the generated profiler JSON file onto the tool to load it. + +This is roughly how this looks like on Chrome. + +![chrome-trace.png](assets/chrome-trace.png) + +*** + +Next up: [Logging](Logging.md) diff --git a/docs/QuickStart.md b/docs/QuickStart.md new file mode 100644 index 0000000..b3a1c30 --- /dev/null +++ b/docs/QuickStart.md @@ -0,0 +1,127 @@ +# Quick Start + +Having all [requirements](README.md#requirements) set, here you can find how to quickly build and run the application. + +## Table of contents + +- [Build](#build) +- [Execute](#execute) + - [macOS](#macos) + - [Windows](#windows) + - [Linux](#linux) +- [Distribution](#distribution) +- [Tests](#tests) + +## Build + +Usually available build modes are `Debug`, `Release`, and `RelWithDebInfo`. + +To run a **debug** build: + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug +cmake --build build/debug +``` + +To run a **release** build: + +```shell +cmake -GNinja -DCMAKE_BUILD_TYPE=Release -B build/release +cmake --build build/release +``` + +On macOS XCode should be used as generator via `-GXCode`. For example creating a release build with XCode. + +```shell +# Using XCode +cmake -GXCode -DCMAKE_BUILD_TYPE=Release -B build/xcode +cmake --build build/xcode +``` + +## Execute + +When not running through an [IDE like CLion](https://www.jetbrains.com/clion), the built application can be run by directly executing the generated binary. + +### macOS + +To run a **debug** build: + +```shell +./build/debug/src/app/App.app/Contents/MacOS/App +``` + +To run a **release** build: + +```shell +./build/release/src/app/App.app/Contents/MacOS/App +``` + +To run a **debug** build created **with XCode**: + +```shell +./build/xcode/src/app/Debug/App.app/Contents/MacOS/App +``` + +To run a **release** build created **with XCode**: + +```shell +./build/xcode/src/app/Release/App.app/Contents/MacOS/App +``` + +### Windows + +To run a **debug** build: + +```shell +build/debug/src/app/App.exe +``` + +To run a **release** build: + +```shell +build/release/src/app/App.exe +``` + +### Linux + +To run a **debug** build: + +```shell +./build/debug/src/app/App +``` + +To run a **release** build: + +```shell +./build/release/src/app/App +``` + +## Distribution + +To bundle the application and create a distribution package CPack is used. Before executing CPack a [release build needs to be generated](#build). + +```shell +cpack --config build/release/CPackConfig.cmake +``` + +## Tests + +On any [generated build](#build) tests can be executed by using CTest, e.g. a Debug build: + +```shell +ctest --test-dir build/debug +``` + +## Preview + +Here a preview of the app running on macOS, Windows, and Linux (Ubuntu), in that order. + +![A screenshot of the app running on macOS](assets/app_macos.png) + +![A screenshot of the app running on Windows](assets/app_windows.png) + +![A screenshot of the app running on Ubuntu](assets/app_ubuntu.png) + +*** + +Next up: [Where is What?](WhereIsWhat.md) diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..7521006 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,65 @@ +# Usage Guide + +This is the user guide for the template and how to adapt it to your own needs. + +## Table of contents + +- [Requirements](#requirements) +- [Quick Start](QuickStart.md) +- [Where is What?](WhereIsWhat.md) +- [Make it your own](MakeItYourOwn.md) +- [Build and Execution](BuildAndExecution.md) +- [Testing](Testing.md) +- [Profiling](Profiling.md) +- [Logging](Logging.md) +- [Dependencies](Dependencies.md) +- [Packaging](Packaging.md) +- [Platform dependent code](PlatformCode.md) +- [Application Icons](ApplicationIcons.md) +- [Fonts](Fonts.md) +- [High DPI support](HighDPISupport.md) + +*** + +## Requirements + +### Git LFS + +This template contains assets, specifically [icons and fonts](WhereIsWhat.md#static-assets). When starting a new project +from a template it gets a clean history. Nevertheless, all assets should be stored +through [Git Large File Storage (LFS)](https://git-lfs.com). + +As preparation this template contains a `.gitattributes` marking all necessary files. **After project creation** from +this +template [git lfs migrate](https://github.com/git-lfs/git-lfs/wiki/Tutorial#migrating-existing-repository-data-to-lfs) +should be executed. It requires Git LFS v2.2.1 or later to be installed. + +Have a look +at [Migrating existing repository data to LFS](https://github.com/git-lfs/git-lfs/wiki/Tutorial#migrating-existing-repository-data-to-lfs) +for an in-depth how-to or run the following commands. + +```shell +# Initialize Git LFS +git lfs install + +# Track files +git mv .gitattributes_example .gitattributes +git commit -m "Add .gitattributes" + +# Migrate history to track files and store them in Git LFS +git lfs migrate import --everything --include="*.png,*.tiff,*.bmp,*.ico,*.icns,*.ttf" +git push --force-with-lease + +# Clear local .git cache +git reflog expire --expire-unreachable=now --all +git gc --prune=now +``` + +### CMake + +The project uses [CMake](https://cmake.org) version >=3.22. + +### Ninja or XCode + +Depending on the operating system, the project uses either [Ninja](https://ninja-build.org) version >=1 for Windows and +Linux, or XCode version >=13 on macOS. diff --git a/docs/Testing.md b/docs/Testing.md new file mode 100644 index 0000000..21deb89 --- /dev/null +++ b/docs/Testing.md @@ -0,0 +1,89 @@ +# Testing + +## Setup + +The repo uses [Doctest](https://github.com/doctest/doctest) for testing. The dependency to Doctest is defined in `vendor/CMakeLists.txt` and configured in `vendor/doctest/CMakeLists.txt`. + +The setup of the test runner is done in `src/tests/` through `src/tests/TestRunner.cpp`. + +In general, tests are located **close to the associated source code**. That means for example the tests for the Core library `src/core/Core/` are located in `src/core/Tests/`. + +## Creation + +Let's create the test setup for _App_. Add a new _Tests_ folder to app including a CMake file `src/app/Tests/CMakeLists.txt`. + +```cmake +# src/app/Tests/CMakeLists.txt + +# Tests will be defined here ... +``` + +Include the new test directory in the apps CMake file: + +```cmake +# src/app/CMakeLists.txt + +# All other App CMake code ... + +add_subdirectory(Tests) +``` + +A new test is a combination of an entry in the tests CMake file and a C++ file containing the actual test. In this example, inside the `src/app/Tests/CMakeLists.txt` file a new test is adding an executable, declaring the test and linking Doctest plus any other required dependencies. + +The example test defines a new test named `AppTest`, using `App.spec.cpp` as test file. The `$` [CMake generator expression](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html) includes the test runner. + +It then declares a test with `add_test` and links doctest and Core as dependencies through `target_link_libraries`. + +```cmake +# src/app/Tests/CMakeLists.txt +add_executable(AppTest App.spec.cpp $) +add_test(NAME AppTest COMMAND AppTest) +target_link_libraries(AppTest PRIVATE doctest Core) +``` + +The test file `App.spec.cpp` will include the actual test suite. In this case an example test. The `NOLINT` comments are for clang-tidy to accept Doctest, and are only defined at the start and end of a test file. + +```c++ +#include +#include + +// NOLINTBEGIN(misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while, cert-err33-c) + +TEST_SUITE("App") { + TEST_CASE("Example") { + const std::string input{"A"}; + CHECK_EQ(input, "A"); + } +} + +// NOLINTEND(misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while, cert-err33-c) +``` + +## Execution + +Before being able to run tests they need to be built. Either have a look at the [Quick Start guide for building](QuickStart.md#build) or try running the following command. + +```shell +cmake --build build/debug +``` + +Then you can run all tests from the build target. Executing the App test will look something like this: + +```shell +$ ctest --test-dir build/debug + +Internal ctest changing into directory: /Projects/_templates/cpp-gui-template-sdl2/build/debug +Test project /Projects/_templates/cpp-gui-template-sdl2/build/debug + Start 1: AppTest +1/1 Test #1: AppTest .................... Passed 0.06 sec + +100% tests passed, 0 tests failed out of 1 + +Total Test time (real) = 0.07 sec +``` + +This can also be done through an IDE like CLion, usually providing an _"All Tests"_ target configuration that will work out of the box. + +*** + +Next up: [Profiling](Profiling.md) diff --git a/docs/WhereIsWhat.md b/docs/WhereIsWhat.md new file mode 100644 index 0000000..f128c84 --- /dev/null +++ b/docs/WhereIsWhat.md @@ -0,0 +1,63 @@ +# Where is what + +Where to find what inside the project, from folder structure to configuration. + +## Source code + +All relevant source code is located in `src/`. The example setup is having one library, here called _"Core"_ under `src/core/`, and the application called _"App"_ under `src/app/`. + +## Tests + +The test setup is done under `src/tests/`. Test implementations are under the respective source code unit, e.g. App tests would be located under `src/app/Tests/`, where Core tests are located under `src/core/Tests/`. + +## Static assets + +Static assets like fonts and images are under `src/assets/`. This also includes all application icons in `src/assets/icons/`. + +## Manifest files + +Manifest files contain operating system dependent configuration. They all are located under `src/app/Manifests/`. + +- `src/app/Manifests/Info.plist` - Apple properties file ([ref](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html#//apple_ref/doc/uid/TP40009254-SW1)) +- `src/app/Manifests/App.manifest` - Windows manifest file ([ref](https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests)) +- `src/app/Manifests/app.rc` - Windows resource file ([ref](https://learn.microsoft.com/en-us/windows/win32/menurc/about-resource-files)) +- `src/app/Manifests/App.desktop.in` - Linux app icon configuration ([ref](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html)) + +## Dependencies + +Generally dependencies are located in `vendor/`. The `vendor/CMakeLists.txt` uses CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) to load dependencies on configure time. Every dependency also has an associated folder containing a `CMakeLists.txt` for configuration. + +## Configurations + +### Project + +General CMake project settings are defined under `cmake/StandardProjectSettings.cmake`, containing build types and compiler flags. + +### Compiler + +Compiler warnings for all platforms are defined in `cmake/CompilerWarnings.cmake`. + +### Static analyzers + +Clang Tidy and Address Sanitizer setup is located in `cmake/StaticAnalyzers.cmake`. Clang-tidy is configured through `.clang-tidy`. + +### Code format + +In the root of the project a `.clang-format` together with the `.editorconfig` define the code style of the project. + +### Apple build + +To configure how to build for Apple Silicon or Intel the `cmake/UniversalAppleBuild.cmake` defines the behavior on release builds. + +### Packaging + +The main configuration to create distributable packages is in `packaging/`. Besides general files it also contains platform dependent resources. + +- `packaging/dmg/` - Apple DMG files +- `packaging/nsis/` - Windows NSIS files + +Under `src/app/cmake/` are specific packaging files for the main executable. + +*** + +Next up: [Make it your own](MakeItYourOwn.md) diff --git a/docs/assets/app_macos.png b/docs/assets/app_macos.png new file mode 100644 index 0000000..0a73d1f Binary files /dev/null and b/docs/assets/app_macos.png differ diff --git a/docs/assets/app_ubuntu.png b/docs/assets/app_ubuntu.png new file mode 100644 index 0000000..e507eed Binary files /dev/null and b/docs/assets/app_ubuntu.png differ diff --git a/docs/assets/app_windows.png b/docs/assets/app_windows.png new file mode 100644 index 0000000..7930188 Binary files /dev/null and b/docs/assets/app_windows.png differ diff --git a/docs/assets/chrome-trace.png b/docs/assets/chrome-trace.png new file mode 100644 index 0000000..fc075fd Binary files /dev/null and b/docs/assets/chrome-trace.png differ diff --git a/litr.toml b/litr.toml deleted file mode 100644 index 713df62..0000000 --- a/litr.toml +++ /dev/null @@ -1,24 +0,0 @@ -[commands.build] -script = [ - "cmake -GNinja -DCMAKE_BUILD_TYPE=%{target} -B build/%{target}", - "ninja -C build/%{target}" -] -description = "Build the application for a given target." - -[commands.start] -script = "cd ./build/%{target}/src/app && ./App" -description = "Start the application." - -[commands.test] -script = "echo 'No tests defined, yet!'" -description = "Run all tests." - -[commands.format] -script = "find src -iname *.hpp -o -iname *.cpp | xargs clang-format -i" -description = "Format project sources via clang-format." - -[params.target] -shortcut = "t" -description = "Define the application build target." -type = ["debug", "release"] -default = "debug" diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt new file mode 100644 index 0000000..4b244ea --- /dev/null +++ b/packaging/CMakeLists.txt @@ -0,0 +1,68 @@ +# Value populated by CMAKE_PROJECT_NAME +# set(CPACK_PACKAGE_NAME MyProj) + +# Value populated by CMAKE_PROJECT_DESCRIPTION +# set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Example project") + +# Base package settings +set(CPACK_PACKAGE_VENDOR ${PROJECT_COMPANY_NAME}) +set(CPACK_PACKAGE_DIRECTORY build/distribution) +set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}") +set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH}) +set(CPACK_VERBATIM_VARIABLES YES) + +# Package resources +set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_LIST_DIR}/Welcome.txt) +set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_LIST_DIR}/Description.txt) +set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_LIST_DIR}/Readme.txt) +set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_LIST_DIR}/License.txt) + +# This option will change the mount drive icon used. +# set(CPACK_PACKAGE_ICON ${CMAKE_CURRENT_LIST_DIR}/dmg/volume.icns) + +# macOS settings for DragNDrop generator +set(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE OFF) +set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_LIST_DIR}/dmg/AppDMGBackground.tiff") +set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/dmg/AppDMGSetup.scpt") +set(CPACK_DMG_VOLUME_NAME "${CMAKE_PROJECT_NAME}") + +# Windows settings for NSIS generator +set(CPACK_NSIS_DISPLAY_NAME ${CMAKE_PROJECT_NAME}) +set(CPACK_NSIS_PACKAGE_NAME ${CPACK_PACKAGE_NAME}) +set(CPACK_NSIS_MANIFEST_DPI_AWARE true) +set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL YES) +set(CPACK_NSIS_MUI_ICON ${PROJECT_SOURCE_DIR}/src\\\\assets\\\\icons\\\\icon.ico) +set(CPACK_NSIS_INSTALLED_ICON_NAME ${PROJECT_SOURCE_DIR}/src\\\\assets\\\\icons\\\\icon.ico) +set(CPACK_NSIS_MUI_UNIICON ${CMAKE_CURRENT_LIST_DIR}/nsis\\\\uninstall_icon.ico) +set(CPACK_NSIS_MUI_HEADERIMAGE ${CMAKE_CURRENT_LIST_DIR}/nsis\\\\nsis_header.bmp) +set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP ${CMAKE_CURRENT_LIST_DIR}/nsis\\\\nsis_install_welcome.bmp) +set(CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP ${CMAKE_CURRENT_LIST_DIR}/nsis\\\\nsis_uninstall_welcome.bmp) + +# Linux DEB settings +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl2-2.0-0") +# Section list: https://packages.debian.org/unstable/ +set(CPACK_DEBIAN_PACKAGE_SECTION Miscellaneous) +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Maintainer Name") + +# Define how to install and uninstall start menu entries on Windows +set(CPACK_NSIS_CREATE_ICONS_EXTRA + "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\${CMAKE_PROJECT_NAME}.lnk' '$INSTDIR\\\\bin\\\\App.exe'") +set(CPACK_NSIS_DELETE_ICONS_EXTRA + "Delete '$SMPROGRAMS\\\\$START_MENU\\\\${CMAKE_PROJECT_NAME}.lnk'") + +# Generator selection per platform +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(CPACK_GENERATOR ZIP NSIS) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(CPACK_GENERATOR TGZ DragNDrop) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(CPACK_GENERATOR TGZ DEB) +else () + set(CPACK_GENERATOR TGZ) +endif () + +include(CPack) diff --git a/packaging/Description.txt b/packaging/Description.txt new file mode 100644 index 0000000..998b100 --- /dev/null +++ b/packaging/Description.txt @@ -0,0 +1 @@ +This is a longer description of the project. diff --git a/packaging/License.txt b/packaging/License.txt new file mode 100644 index 0000000..f77f665 --- /dev/null +++ b/packaging/License.txt @@ -0,0 +1 @@ +The projects license text. diff --git a/packaging/Readme.txt b/packaging/Readme.txt new file mode 100644 index 0000000..835d55e --- /dev/null +++ b/packaging/Readme.txt @@ -0,0 +1 @@ +A project readme. diff --git a/packaging/Welcome.txt b/packaging/Welcome.txt new file mode 100644 index 0000000..051870b --- /dev/null +++ b/packaging/Welcome.txt @@ -0,0 +1 @@ +Project installer welcome message. diff --git a/packaging/dmg/AppDMGBackground.tiff b/packaging/dmg/AppDMGBackground.tiff new file mode 100644 index 0000000..da0a073 Binary files /dev/null and b/packaging/dmg/AppDMGBackground.tiff differ diff --git a/packaging/dmg/AppDMGSetup.scpt b/packaging/dmg/AppDMGSetup.scpt new file mode 100644 index 0000000..9cba2e3 --- /dev/null +++ b/packaging/dmg/AppDMGSetup.scpt @@ -0,0 +1,95 @@ +-- This code was adapted to serve the application needs. +-- +-- Original code from: https://gitlab.kitware.com/cmake/cmake/-/blob/d3812437036e95329fbee0773282b88e8b013fbe/Packaging/CMakeDMGSetup.scpt +-- Original license text: +-- +-- CMake - Cross Platform Makefile Generator +-- Copyright 2000-2016 Kitware, Inc. +-- Copyright 2000-2011 Insight Software Consortium +-- All rights reserved. +-- +-- Redistribution and use in source and binary forms, with or without +-- modification, are permitted provided that the following conditions +-- are met: +-- +-- * Redistributions of source code must retain the above copyright +-- notice, this list of conditions and the following disclaimer. +-- +-- * Redistributions in binary form must reproduce the above copyright +-- notice, this list of conditions and the following disclaimer in the +-- documentation and/or other materials provided with the distribution. +-- +-- * Neither the names of Kitware, Inc., the Insight Software Consortium, +-- nor the names of their contributors may be used to endorse or promote +-- products derived from this software without specific prior written +-- permission. +-- +-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +on run argv + set image_name to item 1 of argv + + tell application "Finder" + tell disk image_name + + -- Wait for the image to finish mounting. + set open_attempts to 0 + repeat while open_attempts < 4 + try + open + delay 1 + set open_attempts to 5 + close + on error errStr number errorNumber + set open_attempts to open_attempts + 1 + delay 10 + end try + end repeat + delay 5 + + -- Open the image and save a .DS_Store with background and icon setup. + open + set current view of container window to icon view + set theViewOptions to the icon view options of container window + set background picture of theViewOptions to file ".background:background.tiff" + set arrangement of theViewOptions to not arranged + set icon size of theViewOptions to 128 + delay 5 + close + + -- Setup the position of the app and Applications symlink + -- and hide all the window decoration. + open + tell container window + set sidebar width to 0 + set statusbar visible to false + set toolbar visible to false + -- Those bounds are defined as: + -- x-start, y-start, x-end, y-end (aka. x, z, width, height) + -- Making this 540 x 400 in size + some random 8 pixel to actually fit the content ¯\_(ツ)_/¯ + set the bounds to {400, 100, 940, 528} + set position of item "App.app" to {140, 200} + set position of item "Applications" to {405, 200} + end tell + delay 5 + close + + -- Open and close for visual verifycation. + open + delay 5 + close + + end tell + delay 1 + end tell +end run diff --git a/packaging/dmg/README.md b/packaging/dmg/README.md new file mode 100644 index 0000000..f36392d --- /dev/null +++ b/packaging/dmg/README.md @@ -0,0 +1,12 @@ +# Generate icons + +## Generate DMG background + +To properly support Retina displays, a TIFF with a high DPI version needs to be created. From the project root run: + +```shell +tiffutil \ + -cathidpicheck packaging/dmg/resources/AppDMGBackground.tiff \ + packaging/dmg/resources/AppDMGBackground@2x.tiff \ + -out packaging/dmg/AppDMGBackground.tiff +``` diff --git a/packaging/dmg/resources/AppDMGBackground.tiff b/packaging/dmg/resources/AppDMGBackground.tiff new file mode 100644 index 0000000..905bd0e Binary files /dev/null and b/packaging/dmg/resources/AppDMGBackground.tiff differ diff --git a/packaging/dmg/resources/AppDMGBackground@2x.tiff b/packaging/dmg/resources/AppDMGBackground@2x.tiff new file mode 100644 index 0000000..060ce38 Binary files /dev/null and b/packaging/dmg/resources/AppDMGBackground@2x.tiff differ diff --git a/packaging/nsis/README.md b/packaging/nsis/README.md new file mode 100644 index 0000000..1a19603 --- /dev/null +++ b/packaging/nsis/README.md @@ -0,0 +1,23 @@ +# NSIS images + +## Uninstall icon + +To create the `uninstall_icon.ico` file ImageMagick is used. From inside the `packaging/nsis` folder run: + +```shell +convert resources/uninstall_icon_16x16.png resources/uninstall_icon_32x32.png resources/uninstall_icon_64x64.png resources/uninstall_icon_128x128.png resources/uninstall_icon_256x256.png resources/uninstall_icon_512x512.png uninstall_icon.ico +``` + +Verify that the `uninstall_icon.ico` was successfully created: + +```shell +identify uninstall_icon.ico +``` + +## Installer images + +The NSIS installer uses `.bmp` files for the UI images, specifically BPM Windows 3.x format. To convert the appropriate images to `.bmp` files run the following command inside the `packaging/nsis` folder. + +```shell +convert resources/nsis_header.png BMP3:nsis_header.bmp && convert resources/nsis_install_welcome.png BMP3:nsis_install_welcome.bmp && convert resources/nsis_uninstall_welcome.png BMP3:nsis_uninstall_welcome.bmp +``` diff --git a/packaging/nsis/nsis_header.bmp b/packaging/nsis/nsis_header.bmp new file mode 100644 index 0000000..21e5322 Binary files /dev/null and b/packaging/nsis/nsis_header.bmp differ diff --git a/packaging/nsis/nsis_install_welcome.bmp b/packaging/nsis/nsis_install_welcome.bmp new file mode 100644 index 0000000..c99abc3 Binary files /dev/null and b/packaging/nsis/nsis_install_welcome.bmp differ diff --git a/packaging/nsis/nsis_uninstall_welcome.bmp b/packaging/nsis/nsis_uninstall_welcome.bmp new file mode 100644 index 0000000..89d8724 Binary files /dev/null and b/packaging/nsis/nsis_uninstall_welcome.bmp differ diff --git a/packaging/nsis/resources/nsis_header.png b/packaging/nsis/resources/nsis_header.png new file mode 100644 index 0000000..43e10e8 Binary files /dev/null and b/packaging/nsis/resources/nsis_header.png differ diff --git a/packaging/nsis/resources/nsis_install_welcome.png b/packaging/nsis/resources/nsis_install_welcome.png new file mode 100644 index 0000000..e9753ec Binary files /dev/null and b/packaging/nsis/resources/nsis_install_welcome.png differ diff --git a/packaging/nsis/resources/nsis_uninstall_welcome.png b/packaging/nsis/resources/nsis_uninstall_welcome.png new file mode 100644 index 0000000..b9dd0f4 Binary files /dev/null and b/packaging/nsis/resources/nsis_uninstall_welcome.png differ diff --git a/packaging/nsis/resources/uninstall_icon_128x128.png b/packaging/nsis/resources/uninstall_icon_128x128.png new file mode 100644 index 0000000..8bbd0cb Binary files /dev/null and b/packaging/nsis/resources/uninstall_icon_128x128.png differ diff --git a/packaging/nsis/resources/uninstall_icon_16x16.png b/packaging/nsis/resources/uninstall_icon_16x16.png new file mode 100644 index 0000000..998df02 Binary files /dev/null and b/packaging/nsis/resources/uninstall_icon_16x16.png differ diff --git a/packaging/nsis/resources/uninstall_icon_256x256.png b/packaging/nsis/resources/uninstall_icon_256x256.png new file mode 100644 index 0000000..e7bcb8d Binary files /dev/null and b/packaging/nsis/resources/uninstall_icon_256x256.png differ diff --git a/packaging/nsis/resources/uninstall_icon_32x32.png b/packaging/nsis/resources/uninstall_icon_32x32.png new file mode 100644 index 0000000..240dd25 Binary files /dev/null and b/packaging/nsis/resources/uninstall_icon_32x32.png differ diff --git a/packaging/nsis/resources/uninstall_icon_512x512.png b/packaging/nsis/resources/uninstall_icon_512x512.png new file mode 100644 index 0000000..c50fadd Binary files /dev/null and b/packaging/nsis/resources/uninstall_icon_512x512.png differ diff --git a/packaging/nsis/resources/uninstall_icon_64x64.png b/packaging/nsis/resources/uninstall_icon_64x64.png new file mode 100644 index 0000000..31e0763 Binary files /dev/null and b/packaging/nsis/resources/uninstall_icon_64x64.png differ diff --git a/packaging/nsis/uninstall_icon.ico b/packaging/nsis/uninstall_icon.ico new file mode 100644 index 0000000..6f40b60 Binary files /dev/null and b/packaging/nsis/uninstall_icon.ico differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1fa5116..1a6e55f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,2 +1,4 @@ -add_subdirectory(core) +add_subdirectory(tests) add_subdirectory(app) +add_subdirectory(core) +add_subdirectory(settings) diff --git a/src/app/App/Main.cpp b/src/app/App/Main.cpp index ac67542..120cb53 100644 --- a/src/app/App/Main.cpp +++ b/src/app/App/Main.cpp @@ -1,11 +1,7 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - -#define SDL_MAIN_HANDLED +#include #include "Core/Application.hpp" -#include "Core/Instrumentor.hpp" +#include "Core/Debug/Instrumentor.hpp" #include "Core/Log.hpp" int main() { diff --git a/src/app/App/assets/fonts/Manrope/Manrope-Bold.ttf b/src/app/App/assets/fonts/Manrope/Manrope-Bold.ttf deleted file mode 100644 index 2f84ae3..0000000 Binary files a/src/app/App/assets/fonts/Manrope/Manrope-Bold.ttf and /dev/null differ diff --git a/src/app/App/assets/fonts/Manrope/Manrope-ExtraBold.ttf b/src/app/App/assets/fonts/Manrope/Manrope-ExtraBold.ttf deleted file mode 100644 index 0192c9a..0000000 Binary files a/src/app/App/assets/fonts/Manrope/Manrope-ExtraBold.ttf and /dev/null differ diff --git a/src/app/App/assets/fonts/Manrope/Manrope-ExtraLight.ttf b/src/app/App/assets/fonts/Manrope/Manrope-ExtraLight.ttf deleted file mode 100644 index cf7cea3..0000000 Binary files a/src/app/App/assets/fonts/Manrope/Manrope-ExtraLight.ttf and /dev/null differ diff --git a/src/app/App/assets/fonts/Manrope/Manrope-Light.ttf b/src/app/App/assets/fonts/Manrope/Manrope-Light.ttf deleted file mode 100644 index 05ab753..0000000 Binary files a/src/app/App/assets/fonts/Manrope/Manrope-Light.ttf and /dev/null differ diff --git a/src/app/App/assets/fonts/Manrope/Manrope-Medium.ttf b/src/app/App/assets/fonts/Manrope/Manrope-Medium.ttf deleted file mode 100644 index 00067fc..0000000 Binary files a/src/app/App/assets/fonts/Manrope/Manrope-Medium.ttf and /dev/null differ diff --git a/src/app/App/assets/fonts/Manrope/Manrope-Regular.ttf b/src/app/App/assets/fonts/Manrope/Manrope-Regular.ttf deleted file mode 100644 index 2b8c03e..0000000 Binary files a/src/app/App/assets/fonts/Manrope/Manrope-Regular.ttf and /dev/null differ diff --git a/src/app/App/assets/fonts/Manrope/Manrope-SemiBold.ttf b/src/app/App/assets/fonts/Manrope/Manrope-SemiBold.ttf deleted file mode 100644 index c556d42..0000000 Binary files a/src/app/App/assets/fonts/Manrope/Manrope-SemiBold.ttf and /dev/null differ diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 8066730..ff61f23 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -2,18 +2,11 @@ set(NAME "App") include(${PROJECT_SOURCE_DIR}/cmake/StaticAnalyzers.cmake) -file(COPY App/assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +add_executable(${NAME} WIN32 MACOSX_BUNDLE App/Main.cpp) -add_executable(${NAME} App/Main.cpp) +include(${PROJECT_SOURCE_DIR}/src/app/cmake/AppAssets.cmake) +include(${PROJECT_SOURCE_DIR}/src/app/cmake/Packaging.cmake) -if (WIN32) - # Copy DLL files on Windows to the target App build folder. - add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - $ - $) -endif () - -target_include_directories(${NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(${NAME} PRIVATE cxx_std_20) target_link_libraries(${NAME} PRIVATE project_warnings Core) diff --git a/src/app/Manifests/App.desktop.in b/src/app/Manifests/App.desktop.in new file mode 100644 index 0000000..546448d --- /dev/null +++ b/src/app/Manifests/App.desktop.in @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=@NAME@ +GenericName=@CMAKE_PROJECT_NAME@ +Comment=@CMAKE_PROJECT_DESCRIPTION@ +Exec=@NAME@ +Icon=@NAME@_icon +Type=Application +Categories=Miscellaneous; diff --git a/src/app/Manifests/App.manifest b/src/app/Manifests/App.manifest new file mode 100644 index 0000000..f2708ec --- /dev/null +++ b/src/app/Manifests/App.manifest @@ -0,0 +1,9 @@ + + + + + true + PerMonitorV2 + + + diff --git a/src/app/Manifests/Info.plist b/src/app/Manifests/Info.plist new file mode 100644 index 0000000..df98ad0 --- /dev/null +++ b/src/app/Manifests/Info.plist @@ -0,0 +1,35 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + icon + CFBundleIdentifier + ${MACOSX_BUNDLE_GUI_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${MACOSX_BUNDLE_BUNDLE_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${MACOSX_BUNDLE_SHORT_VERSION_STRING} + CFBundleVersion + ${MACOSX_BUNDLE_BUNDLE_VERSION} + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + ${MACOSX_BUNDLE_COPYRIGHT} + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + NSHighResolutionCapable + + + diff --git a/src/app/Manifests/app.rc b/src/app/Manifests/app.rc new file mode 100644 index 0000000..5d03f3d --- /dev/null +++ b/src/app/Manifests/app.rc @@ -0,0 +1 @@ +app_icon ICON DISCARDABLE "../assets/icons/icon.ico" diff --git a/src/app/cmake/AppAssets.cmake b/src/app/cmake/AppAssets.cmake new file mode 100644 index 0000000..79e9b48 --- /dev/null +++ b/src/app/cmake/AppAssets.cmake @@ -0,0 +1,20 @@ +# Assets for all platforms +set(SHARED_STATIC_ASSETS ${PROJECT_SOURCE_DIR}/src/assets/fonts/Manrope.ttf) + +# Platform specific static assets +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_sources(${NAME} PUBLIC + ${SHARED_STATIC_ASSETS} + ${PROJECT_SOURCE_DIR}/src/assets/icons/icon.ico + ${PROJECT_SOURCE_DIR}/src/app/Manifests/app.rc + ${PROJECT_SOURCE_DIR}/src/app/Manifests/App.manifest) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(MACOSX_STATIC_ASSETS + ${SHARED_STATIC_ASSETS} + ${PROJECT_SOURCE_DIR}/src/assets/icons/icon.icns) + set_source_files_properties(${MACOSX_STATIC_ASSETS} + PROPERTIES MACOSX_PACKAGE_LOCATION ${CMAKE_INSTALL_DATADIR}) + target_sources(${NAME} PUBLIC ${MACOSX_STATIC_ASSETS}) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_sources(${NAME} PRIVATE ${SHARED_STATIC_ASSETS}) +endif () diff --git a/src/app/cmake/Packaging.cmake b/src/app/cmake/Packaging.cmake new file mode 100644 index 0000000..9f62f69 --- /dev/null +++ b/src/app/cmake/Packaging.cmake @@ -0,0 +1,15 @@ +# General target installation settings +install(TARGETS ${NAME} + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +# Settings for packaging per platform +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + include(${PROJECT_SOURCE_DIR}/src/app/cmake/packaging/Windows.cmake) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + include(${PROJECT_SOURCE_DIR}/src/app/cmake/packaging/Linux.cmake) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + include(${PROJECT_SOURCE_DIR}/src/app/cmake/packaging/Darwin.cmake) +endif () diff --git a/src/app/cmake/packaging/Darwin.cmake b/src/app/cmake/packaging/Darwin.cmake new file mode 100644 index 0000000..fe8f151 --- /dev/null +++ b/src/app/cmake/packaging/Darwin.cmake @@ -0,0 +1,30 @@ +# XCode generates build directories with build types inside. +if ("${CMAKE_GENERATOR}" STREQUAL "Xcode") + set(APP_BUNDLE_PATH "${CMAKE_BUILD_TYPE}/${NAME}.app") +else () + set(APP_BUNDLE_PATH "${NAME}.app") +endif () + +# Get dynamic SDL2 lib into Frameworks folder in app bundle. +# For development: +add_custom_command(TARGET ${NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $/../Frameworks/$) + +# For distribution without XCode: +if (NOT "${CMAKE_GENERATOR}" STREQUAL "Xcode") + install(FILES $ DESTINATION $/../Frameworks/) +endif () + +# macOS package settings +string(TIMESTAMP CURR_YEAR "%Y") +set_target_properties(${NAME} PROPERTIES + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" + MACOSX_BUNDLE_BUNDLE_VERSION "${BUILD_VERSION}" + MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}" + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Manifests/Info.plist" + MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_COMPANY_NAMESPACE}.${CMAKE_PROJECT_NAME}" + MACOSX_BUNDLE_COPYRIGHT "(c) ${CURR_YEAR} ${PROJECT_COMPANY_NAME}" + INSTALL_RPATH @executable_path/../Frameworks + RESOURCE "${MACOSX_STATIC_ASSETS}") diff --git a/src/app/cmake/packaging/Linux.cmake b/src/app/cmake/packaging/Linux.cmake new file mode 100644 index 0000000..ddb03ed --- /dev/null +++ b/src/app/cmake/packaging/Linux.cmake @@ -0,0 +1,32 @@ +# Copy .so files on Linux to the target App build folder. +# For development: +add_custom_command(TARGET ${NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $) + +# For distribution: +install(FILES $ + DESTINATION ${CMAKE_INSTALL_BINDIR} + RENAME ${NAME}_$) + +# Copy assets into app bundle +# For development: +add_custom_command(TARGET ${NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${PROJECT_SOURCE_DIR}/src/assets + $/../share) + +# For distribution: +install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/assets/ DESTINATION ${CMAKE_INSTALL_DATADIR}) + +# Linux app icon setup +configure_file( + ${PROJECT_SOURCE_DIR}/src/app/Manifests/App.desktop.in + ${CMAKE_CURRENT_BINARY_DIR}/App.desktop + @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/App.desktop + DESTINATION share/applications) +install(FILES ${PROJECT_SOURCE_DIR}/src/assets/icons/BaseAppIcon.png + DESTINATION share/pixmaps + RENAME ${APP_NAME}_icon.png) diff --git a/src/app/cmake/packaging/Windows.cmake b/src/app/cmake/packaging/Windows.cmake new file mode 100644 index 0000000..4e14044 --- /dev/null +++ b/src/app/cmake/packaging/Windows.cmake @@ -0,0 +1,22 @@ +# Use main entry for Windows GUI app. +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /subsystem:windows /entry:mainCRTStartup") + +# Copy .dll files on Windows to the target App build folder. +# For development: +add_custom_command(TARGET ${NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $) + +# For distribution: +install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR}) + +# Copy assets into app bundle +# For development: +add_custom_command(TARGET ${NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${PROJECT_SOURCE_DIR}/src/assets + $/../share) + +# For distribution: +install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/assets/ DESTINATION ${CMAKE_INSTALL_DATADIR}) diff --git a/src/assets/fonts/Manrope.ttf b/src/assets/fonts/Manrope.ttf new file mode 100644 index 0000000..7d21e1b Binary files /dev/null and b/src/assets/fonts/Manrope.ttf differ diff --git a/src/assets/fonts/OpenFontLicense-FAQ.txt b/src/assets/fonts/OpenFontLicense-FAQ.txt new file mode 100644 index 0000000..e058b79 --- /dev/null +++ b/src/assets/fonts/OpenFontLicense-FAQ.txt @@ -0,0 +1,436 @@ +OFL FAQ - Frequently Asked Questions about the SIL Open Font License (OFL) +Version 1.1-update6 - December 2020 +The OFL FAQ is copyright (c) 2005-2020 SIL International. +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. +(See http://scripts.sil.org/OFL for updates) + + +CONTENTS OF THIS FAQ +1 USING AND DISTRIBUTING FONTS LICENSED UNDER THE OFL +2 USING OFL FONTS FOR WEB PAGES AND ONLINE WEB FONT SERVICES +3 MODIFYING OFL-LICENSED FONTS +4 LICENSING YOUR ORIGINAL FONTS UNDER THE OFL +5 CHOOSING RESERVED FONT NAMES +6 ABOUT THE FONTLOG +7 MAKING CONTRIBUTIONS TO OFL PROJECTS +8 ABOUT THE LICENSE ITSELF +9 ABOUT SIL INTERNATIONAL +APPENDIX A - FONTLOG EXAMPLE + +1 USING AND DISTRIBUTING FONTS LICENSED UNDER THE OFL + +1.1 Can I use the fonts for a book or other print publication, to create logos or other graphics or even to manufacture objects based on their outlines? +Yes. You are very welcome to do so. Authors of fonts released under the OFL allow you to use their font software as such for any kind of design work. No additional license or permission is required, unlike with some other licenses. Some examples of these uses are: logos, posters, business cards, stationery, video titling, signage, t-shirts, personalised fabric, 3D-printed/laser-cut shapes, sculptures, rubber stamps, cookie cutters and lead type. + +1.1.1 Does that restrict the license or distribution of that artwork? +No. You remain the author and copyright holder of that newly derived graphic or object. You are simply using an open font in the design process. It is only when you redistribute, bundle or modify the font itself that other conditions of the license have to be respected (see below for more details). + +1.1.2 Is any kind of acknowledgement required? +No. Font authors may appreciate being mentioned in your artwork's acknowledgements alongside the name of the font, possibly with a link to their website, but that is not required. + +1.2 Can the fonts be included with Free/Libre and Open Source Software collections such as GNU/Linux and BSD distributions and repositories? +Yes! Fonts licensed under the OFL can be freely included alongside other software under FLOSS (Free/Libre and Open Source Software) licenses. Since fonts are typically aggregated with, not merged into, existing software, there is little need to be concerned about incompatibility with existing software licenses. You may also repackage the fonts and the accompanying components in a .rpm or .deb package (or other similar package formats or installers) and include them in distribution CD/DVDs and online repositories. (Also see section 5.9 about rebuilding from source.) + +1.3 I want to distribute the fonts with my program. Does this mean my program also has to be Free/Libre and Open Source Software? +No. Only the portions based on the Font Software are required to be released under the OFL. The intent of the license is to allow aggregation or bundling with software under restricted licensing as well. + +1.4 Can I sell a software package that includes these fonts? +Yes, you can do this with both the Original Version and a Modified Version of the fonts. Examples of bundling made possible by the OFL would include: word processors, design and publishing applications, training and educational software, games and entertainment software, mobile device applications, etc. + +1.5 Can I include the fonts on a CD of freeware or commercial fonts? +Yes, as long some other font or software is also on the disk, so the OFL font is not sold by itself. + +1.6 Why won't the OFL let me sell the fonts alone? +The intent is to keep people from making money by simply redistributing the fonts. The only people who ought to profit directly from the fonts should be the original authors, and those authors have kindly given up potential direct income to distribute their fonts under the OFL. Please honour and respect their contribution! + +1.7 What about sharing OFL fonts with friends on a CD, DVD or USB stick? +You are very welcome to share open fonts with friends, family and colleagues through removable media. Just remember to include the full font package, including any copyright notices and licensing information as available in OFL.txt. In the case where you sell the font, it has to come bundled with software. + +1.8 Can I host the fonts on a web site for others to use? +Yes, as long as you make the full font package available. In most cases it may be best to point users to the main site that distributes the Original Version so they always get the most recent stable and complete version. See also discussion of web fonts in Section 2. + +1.9 Can I host the fonts on a server for use over our internal network? +Yes. If the fonts are transferred from the server to the client computer by means that allow them to be used even if the computer is no longer attached to the network, the full package (copyright notices, licensing information, etc.) should be included. + +1.10 Does the full OFL license text always need to accompany the font? +The only situation in which an OFL font can be distributed without the text of the OFL (either in a separate file or in font metadata), is when a font is embedded in a document or bundled within a program. In the case of metadata included within a font, it is legally sufficient to include only a link to the text of the OFL on http://scripts.sil.org/OFL, but we strongly recommend against this. Most modern font formats include metadata fields that will accept the full OFL text, and full inclusion increases the likelihood that users will understand and properly apply the license. + +1.11 What do you mean by 'embedding'? How does that differ from other means of distribution? +By 'embedding' we mean inclusion of the font in a document or file in a way that makes extraction (and redistribution) difficult or clearly discouraged. In many cases the names of embedded fonts might also not be obvious to those reading the document, the font data format might be altered, and only a subset of the font - only the glyphs required for the text - might be included. Any other means of delivering a font to another person is considered 'distribution', and needs to be accompanied by any copyright notices and licensing information available in OFL.txt. + +1.12 So can I embed OFL fonts in my document? +Yes, either in full or a subset. The restrictions regarding font modification and redistribution do not apply, as the font is not intended for use outside the document. + +1.13 Does embedding alter the license of the document itself? +No. Referencing or embedding an OFL font in any document does not change the license of the document itself. The requirement for fonts to remain under the OFL does not apply to any document created using the fonts and their derivatives. Similarly, creating any kind of graphic using a font under OFL does not make the resulting artwork subject to the OFL. + +1.14 If OFL fonts are extracted from a document in which they are embedded (such as a PDF file), what can be done with them? Is this a risk to author(s)? +The few utilities that can extract fonts embedded in a PDF will typically output limited amounts of outlines - not a complete font. To create a working font from this method is much more difficult and time consuming than finding the source of the original OFL font. So there is little chance that an OFL font would be extracted and redistributed inappropriately through this method. Even so, copyright laws address any misrepresentation of authorship. All Font Software released under the OFL and marked as such by the author(s) is intended to remain under this license regardless of the distribution method, and cannot be redistributed under any other license. We strongly discourage any font extraction - we recommend directly using the font sources instead - but if you extract font outlines from a document, please be considerate: respect the work of the author(s) and the licensing model. + +1.15 What about distributing fonts with a document? Within a compressed folder structure? Is it distribution, bundling or embedding? +Certain document formats may allow the inclusion of an unmodified font within their file structure which may consist of a compressed folder containing the various resources forming the document (such as pictures and thumbnails). Including fonts within such a structure is understood as being different from embedding but rather similar to bundling (or mere aggregation) which the license explicitly allows. In this case the font is conveyed unchanged whereas embedding a font usually transforms it from the original format. The OFL does not allow anyone to extract the font from such a structure to then redistribute it under another license. The explicit permission to redistribute and embed does not cancel the requirement for the Font Software to remain under the license chosen by its author(s). Even if the font travels inside the document as one of its assets, it should not lose its authorship information and licensing. + +1.16 What about ebooks shipping with open fonts? +The requirements differ depending on whether the fonts are linked, embedded or distributed (bundled or aggregated). Some ebook formats use web technologies to do font linking via @font-face, others are designed for font embedding, some use fonts distributed with the document or reading software, and a few rely solely on the fonts already present on the target system. The license requirements depend on the type of inclusion as discussed in 1.15. + +1.17 Can Font Software released under the OFL be subject to URL-based access restrictions methods or DRM (Digital Rights Management) mechanisms? +Yes, but these issues are out-of-scope for the OFL. The license itself neither encourages their use nor prohibits them since such mechanisms are not implemented in the components of the Font Software but through external software. Such restrictions are put in place for many different purposes corresponding to various usage scenarios. One common example is to limit potentially dangerous cross-site scripting attacks. However, in the spirit of libre/open fonts and unrestricted writing systems, we strongly encourage open sharing and reuse of OFL fonts, and the establishment of an environment where such restrictions are unnecessary. Note that whether you wish to use such mechanisms or you prefer not to, you must still abide by the rules set forth by the OFL when using fonts released by their authors under this license. Derivative fonts must be licensed under the OFL, even if they are part of a service for which you charge fees and/or for which access to source code is restricted. You may not sell the fonts on their own - they must be part of a larger software package, bundle or subscription plan. For example, even if the OFL font is distributed in a software package or via an online service using a DRM mechanism, the user would still have the right to extract that font, use, study, modify and redistribute it under the OFL. + +1.18 I've come across a font released under the OFL. How can I easily get more information about the Original Version? How can I know where it stands compared to the Original Version or other Modified Versions? +Consult the copyright statement(s) in the license for ways to contact the original authors. Consult the FONTLOG (see section 6 for more details and examples) for information on how the font differs from the Original Version, and get in touch with the various contributors via the information in the acknowledgement section. Please consider using the Original Versions of the fonts whenever possible. + +1.19 What do you mean in condition 4 of the OFL's permissions and conditions? Can you provide examples of abusive promotion / endorsement / advertisement vs. normal acknowledgement? +The intent is that the goodwill and reputation of the author(s) should not be used in a way that makes it sound like the original author(s) endorse or approve of a specific Modified Version or software bundle. For example, it would not be right to advertise a word processor by naming the author(s) in a listing of software features, or to promote a Modified Version on a web site by saying "designed by ...". However, it would be appropriate to acknowledge the author(s) if your software package has a list of people who deserve thanks. We realize that this can seem to be a grey area, but the standard used to judge an acknowledgement is that if the acknowledgement benefits the author(s) it is allowed, but if it primarily benefits other parties, or could reflect poorly on the author(s), then it is not. + +1.20 I'm writing a small app for mobile platforms, do I need to include the whole package? +If you bundle a font under the OFL with your mobile app you must comply with the terms of the license. At a minimum you must include the copyright statement, the license notice and the license text. A mention of this information in your About box or Changelog, with a link to where the font package is from, is good practice, and the extra space needed to carry these items is very small. You do not, however, need to include the full contents of the font package - only the fonts you use and the copyright and license that apply to them. For example, if you only use the regular weight in your app, you do not need to include the italic and bold versions. + +1.21 What about including OFL fonts by default in my firmware or dedicated operating system? +Many such systems are restricted and turned into appliances so that users cannot study or modify them. Using open fonts to increase quality and language coverage is a great idea, but you need to be aware that if there is a way for users to extract fonts you cannot legally prevent them from doing that. The fonts themselves, including any changes you make to them, must be distributed under the OFL even if your firmware has a more restrictive license. If you do transform the fonts and change their formats when you include them in your firmware you must respect any names reserved by the font authors via the RFN mechanism and pick your own font name. Alternatively if you directly add a font under the OFL to the font folder of your firmware without modifying or optimizing it you are simply bundling the font like with any other software collection, and do not need to make any further changes. + +1.22 Can I make and publish CMS themes or templates that use OFL fonts? Can I include the fonts themselves in the themes or templates? Can I sell the whole package? +Yes, you are very welcome to integrate open fonts into themes and templates for your preferred CMS and make them more widely available. Remember that you can only sell the fonts and your CMS add-on as part of a software bundle. (See 1.4 for details and examples about selling bundles). + +1.23 Can OFL fonts be included in services that deliver fonts to the desktop from remote repositories? Even if they contain both OFL and non-OFL fonts? +Yes. Some foundries have set up services to deliver fonts to subscribers directly to desktops from their online repositories; similarly, plugins are available to preview and use fonts directly in your design tool or publishing suite. These services may mix open and restricted fonts in the same channel, however they should make a clear distinction between them to users. These services should also not hinder users (such as through DRM or obfuscation mechanisms) from extracting and using the OFL fonts in other environments, or continuing to use OFL fonts after subscription terms have ended, as those uses are specifically allowed by the OFL. + +1.24 Can services that provide or distribute OFL fonts restrict my use of them? +No. The terms of use of such services cannot replace or restrict the terms of the OFL, as that would be the same as distributing the fonts under a different license, which is not allowed. You are still entitled to use, modify and redistribute them as the original authors have intended outside of the sole control of that particular distribution channel. Note, however, that the fonts provided by these services may differ from the Original Versions. + + +2 USING OFL FONTS FOR WEBPAGES AND ONLINE WEB FONT SERVICES + +NOTE: This section often refers to a separate paper on 'Web Fonts & RFNs'. This is available at http://scripts.sil.org/OFL_web_fonts_and_RFNs + +2.1 Can I make webpages using these fonts? +Yes! Go ahead! Using CSS (Cascading Style Sheets) is recommended. Your three best options are: +- referring directly in your stylesheet to open fonts which may be available on the user's system +- providing links to download the full package of the font - either from your own website or from elsewhere - so users can install it themselves +- using @font-face to distribute the font directly to browsers. This is recommended and explicitly allowed by the licensing model because it is distribution. The font file itself is distributed with other components of the webpage. It is not embedded in the webpage but referenced through a web address which will cause the browser to retrieve and use the corresponding font to render the webpage (see 1.11 and 1.15 for details related to embedding fonts into documents). As you take advantage of the @font-face cross-platform standard, be aware that web fonts are often tuned for a web environment and not intended for installation and use outside a browser. The reasons in favour of using web fonts are to allow design of dynamic text elements instead of static graphics, to make it easier for content to be localized and translated, indexed and searched, and all this with cross-platform open standards without depending on restricted extensions or plugins. You should check the CSS cascade (the order in which fonts are being called or delivered to your users) when testing. + +2.2 Can I make and use WOFF (Web Open Font Format) versions of OFL fonts? +Yes, but you need to be careful. A change in font format normally is considered modification, and Reserved Font Names (RFNs) cannot be used. Because of the design of the WOFF format, however, it is possible to create a WOFF version that is not considered modification, and so would not require a name change. You are allowed to create, use and distribute a WOFF version of an OFL font without changing the font name, but only if: + +- the original font data remains unchanged except for WOFF compression, and +- WOFF-specific metadata is either omitted altogether or present and includes, unaltered, the contents of all equivalent metadata in the original font. + +If the original font data or metadata is changed, or the WOFF-specific metadata is incomplete, the font must be considered a Modified Version, the OFL restrictions would apply and the name of the font must be changed: any RFNs cannot be used and copyright notices and licensing information must be included and cannot be deleted or modified. You must come up with a unique name - we recommend one corresponding to your domain or your particular web application. Be aware that only the original author(s) can use RFNs. This is to prevent collisions between a derivative tuned to your audience and the original upstream version and so to reduce confusion. + +Please note that most WOFF conversion tools and online services do not meet the two requirements listed above, and so their output must be considered a Modified Version. So be very careful and check to be sure that the tool or service you're using is compressing unchanged data and completely and accurately reflecting the original font metadata. + +2.3 What about other web font formats such as EOT/EOTLite/CWT/etc.? +In most cases these formats alter the original font data more than WOFF, and do not completely support appropriate metadata, so their use must be considered modification and RFNs may not be used. However, there may be certain formats or usage scenarios that may allow the use of RFNs. See http://scripts.sil.org/OFL_web_fonts_and_RFNs + +2.4 Can I make OFL fonts available through web font online services? +Yes, you are welcome to include OFL fonts in online web font services as long as you properly meet all the conditions of the license. The origin and open status of the font should be clear among the other fonts you are hosting. Authorship, copyright notices and license information must be sufficiently visible to your users or subscribers so they know where the font comes from and the rights granted by the author(s). Make sure the font file contains the needed copyright notice(s) and licensing information in its metadata. Please double-check the accuracy of every field to prevent contradictory information. Other font formats, including EOT/EOTLite/CWT and superior alternatives like WOFF, already provide fields for this information. Remember that if you modify the font within your library or convert it to another format for any reason the OFL restrictions apply and you need to change the names accordingly. Please respect the author's wishes as expressed in the OFL and do not misrepresent original designers and their work. Don't lump quality open fonts together with dubious freeware or public domain fonts. Consider how you can best work with the original designers and foundries, support their efforts and generate goodwill that will benefit your service. (See 1.17 for details related to URL-based access restrictions methods or DRM mechanisms). + +2.5 Some web font formats and services provide ways of "optimizing" the font for a particular website or web application; is that allowed? +Yes, it is permitted, but remember that these optimized versions are Modified Versions and so must follow OFL requirements like appropriate renaming. Also you need to bear in mind the other important parameters beyond compression, speed and responsiveness: you need to consider the audience of your particular website or web application, as choosing some optimization parameters may turn out to be less than ideal for them. Subsetting by removing certain glyphs or features may seriously limit functionality of the font in various languages that your users expect. It may also introduce degradation of quality in the rendering or specific bugs on the various target platforms compared to the original font from upstream. In other words, remember that one person's optimized font may be another person's missing feature. Various advanced typographic features (OpenType, Graphite or AAT) are also available through CSS and may provide the desired effects without the need to modify the font. + +2.6 Is subsetting a web font considered modification? +Yes. Removing any parts of the font when delivering a web font to a browser, including unused glyphs and smart font code, is considered modification. This is permitted by the OFL but would not normally allow the use of RFNs. Some newer subsetting technologies may be able to subset in a way that allows users to effectively have access to the complete font, including smart font behaviour. See 2.8 and http://scripts.sil.org/OFL_web_fonts_and_RFNs + +2.7 Are there any situations in which a modified web font could use RFNs? +Yes. If a web font is optimized only in ways that preserve Functional Equivalence (see 2.8), then it may use RFNs, as it reasonably represents the Original Version and respects the intentions of the author(s) and the main purposes of the RFN mechanism (avoids collisions, protects authors, minimizes support, encourages derivatives). However this is technically very difficult and often impractical, so a much better scenario is for the web font service or provider to sign a separate agreement with the author(s) that allows the use of RFNs for Modified Versions. + +2.8 How do you know if an optimization to a web font preserves Functional Equivalence? +Functional Equivalence is described in full in the 'Web fonts and RFNs' paper at http://scripts.sil.org/OFL_web_fonts_and_RFNs, in general, an optimized font is deemed to be Functionally Equivalent (FE) to the Original Version if it: + +- Supports the same full character inventory. If a character can be properly displayed using the Original Version, then that same character, encoded correctly on a web page, will display properly. +- Provides the same smart font behavior. Any dynamic shaping behavior that works with the Original Version should work when optimized, unless the browser or environment does not support it. There does not need to be guaranteed support in the client, but there should be no forced degradation of smart font or shaping behavior, such as the removal or obfuscation of OpenType, Graphite or AAT tables. +- Presents text with no obvious degradation in visual quality. The lettershapes should be equally (or more) readable, within limits of the rendering platform. +- Preserves original author, project and license metadata. At a minimum, this should include: Copyright and authorship; The license as stated in the Original Version, whether that is the full text of the OFL or a link to the web version; Any RFN declarations; Information already present in the font or documentation that points back to the Original Version, such as a link to the project or the author's website. + +If an optimized font meets these requirements, and so is considered to be FE, then it's very likely that the original author would feel that the optimized font is a good and reasonable equivalent. If it falls short of any of these requirements, the optimized font does not reasonably represent the Original Version, and so should be considered to be a Modified Version. Like other Modified Versions, it would not be allowed to use any RFNs and you simply need to pick your own font name. + +2.9 Isn't use of web fonts another form of embedding? +No. Unlike embedded fonts in a PDF, web fonts are not an integrated part of the document itself. They are not specific to a single document and are often applied to thousands of documents around the world. The font data is not stored alongside the document data and often originates from a different location. The ease by which the web fonts used by a document may be identified and downloaded for desktop use demonstrates that they are philosophically and technically separate from the web pages that specify them. See http://scripts.sil.org/OFL_web_fonts_and_RFNs + +2.10 So would it be better to not use RFNs at all if you want your font to be distributed by a web fonts service? +No. Although the OFL does not require authors to use RFNs, the RFN mechanism is an important part of the OFL model and completely compatible with web font services. If that web font service modifies the fonts, then the best solution is to sign a separate agreement for the use of any RFNs. It is perfectly valid for an author to not declare any RFNs, but before they do so they need to fully understand the benefits they are giving up, and the overall negative effect of allowing many different versions bearing the same name to be widely distributed. As a result, we don't generally recommend it. + +2.11 What should an agreement for the use of RFNs say? Are there any examples? +There is no prescribed format for this agreement, as legal systems vary, and no recommended examples. Authors may wish to add specific clauses to further restrict use, require author review of Modified Versions, establish user support mechanisms or provide terms for ending the agreement. Such agreements are usually not public, and apply only to the main parties. However, it would be very beneficial for web font services to clearly state when they have established such agreements, so that the public understands clearly that their service is operating appropriately. + +See the separate paper on 'Web Fonts & RFNs' for in-depth discussion of issues related to the use of RFNs for web fonts. This is available at http://scripts.sil.org/OFL_web_fonts_and_RFNs + + +3 MODIFYING OFL-LICENSED FONTS + +3.1 Can I change the fonts? Are there any limitations to what things I can and cannot change? +You are allowed to change anything, as long as such changes do not violate the terms of the license. In other words, you are not allowed to remove the copyright statement(s) from the font, but you could put additional information into it that covers your contribution. See the placeholders in the OFL header template for recommendations on where to add your own statements. (Remember that, when authors have reserved names via the RFN mechanism, you need to change the internal names of the font to your own font name when making your modified version even if it is just a small change.) + +3.2 I have a font that needs a few extra glyphs - can I take them from an OFL licensed font and copy them into mine? +Yes, but if you distribute that font to others it must be under the OFL, and include the information mentioned in condition 2 of the license. + +3.3 Can I charge people for my additional work? In other words, if I add a bunch of special glyphs or OpenType/Graphite/AAT code, can I sell the enhanced font? +Not by itself. Derivative fonts must be released under the OFL and cannot be sold by themselves. It is permitted, however, to include them in a larger software package (such as text editors, office suites or operating systems), even if the larger package is sold. In that case, you are strongly encouraged, but not required, to also make that derived font easily and freely available outside of the larger package. + +3.4 Can I pay someone to enhance the fonts for my use and distribution? +Yes. This is a good way to fund the further development of the fonts. Keep in mind, however, that if the font is distributed to others it must be under the OFL. You won't be able to recover your investment by exclusively selling the font, but you will be making a valuable contribution to the community. Please remember how you have benefited from the contributions of others. + +3.5 I need to make substantial revisions to the font to make it work with my program. It will be a lot of work, and a big investment, and I want to be sure that it can only be distributed with my program. Can I restrict its use? +No. If you redistribute a Modified Version of the font it must be under the OFL. You may not restrict it in any way beyond what the OFL permits and requires. This is intended to ensure that all released improvements to the fonts become available to everyone. But you will likely get an edge over competitors by being the first to distribute a bundle with the enhancements. Again, please remember how you have benefited from the contributions of others. + +3.6 Do I have to make any derivative fonts (including extended source files, build scripts, documentation, etc.) publicly available? +No, but please consider sharing your improvements with others. You may find that you receive in return more than what you gave. + +3.7 If a trademark is claimed in the OFL font, does that trademark need to remain in modified fonts? +Yes. Any trademark notices must remain in any derivative fonts to respect trademark laws, but you may add any additional trademarks you claim, officially registered or not. For example if an OFL font called "Foo" contains a notice that "Foo is a trademark of Acme", then if you rename the font to "Bar" when creating a Modified Version, the new trademark notice could say "Foo is a trademark of Acme Inc. - Bar is a trademark of Roadrunner Technologies Ltd.". Trademarks work alongside the OFL and are not subject to the terms of the licensing agreement. The OFL does not grant any rights under trademark law. Bear in mind that trademark law varies from country to country and that there are no international trademark conventions as there are for copyright. You may need to significantly invest in registering and defending a trademark for it to remain valid in the countries you are interested in. This may be costly for an individual independent designer. + +3.8 If I commit changes to a font (or publish a branch in a DVCS) as part of a public open source software project, do I have to change the internal font names? +Only if there are declared RFNs. Making a public commit or publishing a public branch is effectively redistributing your modifications, so any change to the font will require that you do not use the RFNs. Even if there are no RFNs, it may be useful to change the name or add a suffix indicating that a particular version of the font is still in development and not released yet. This will clearly indicate to users and fellow designers that this particular font is not ready for release yet. See section 5 for more details. + + +4 LICENSING YOUR ORIGINAL FONTS UNDER THE OFL + +4.1 Can I use the SIL OFL for my own fonts? +Yes! We heartily encourage everyone to use the OFL to distribute their own original fonts. It is a carefully constructed license that allows great freedom along with enough artistic integrity protection for the work of the authors as well as clear rules for other contributors and those who redistribute the fonts. The licensing model is used successfully by various organisations, both for-profit and not-for-profit, to release fonts of varying levels of scope and complexity. + +4.2 What do I have to do to apply the OFL to my font? +If you want to release your fonts under the OFL, we recommend you do the following: + +4.2.1 Put your copyright and Reserved Font Names information at the beginning of the main OFL.txt file in place of the dedicated placeholders (marked with the <> characters). Include this file in your release package. + +4.2.2 Put your copyright and the OFL text with your chosen Reserved Font Name(s) into your font files (the copyright and license fields). A link to the OFL text on the OFL web site is an acceptable (but not recommended) alternative. Also add this information to any other components (build scripts, glyph databases, documentation, test files, etc). Accurate metadata in your font files is beneficial to you as an increasing number of applications are exposing this information to the user. For example, clickable links can bring users back to your website and let them know about other work you have done or services you provide. Depending on the format of your fonts and sources, you can use template human-readable headers or machine-readable metadata. You should also double-check that there is no conflicting metadata in the font itself contradicting the license, such as the fstype bits in the os2 table or fields in the name table. + +4.2.3 Write an initial FONTLOG.txt for your font and include it in the release package (see Section 6 and Appendix A for details including a template). + +4.2.4 Include the relevant practical documentation on the license by adding the current OFL-FAQ.txt file in your package. + +4.2.5 If you wish you can use the OFL graphics (http://scripts.sil.org/OFL_logo) on your website. + +4.3 Will you make my font OFL for me? +We won't do the work for you. We can, however, try to answer your questions, unfortunately we do not have the resources to review and check your font packages for correct use of the OFL. We recommend you turn to designers, foundries or consulting companies with experience in doing open font design to provide this service to you. + +4.4 Will you distribute my OFL font for me? +No, although if the font is of sufficient quality and general interest we may include a link to it on our partial list of OFL fonts on the OFL web site. You may wish to consider other open font catalogs or hosting services, such as the Unifont Font Guide (http://unifont.org/fontguide), The League of Movable Type (http://theleagueofmovabletype.com) or the Open Font Library (http://openfontlibrary.org/), which despite the name has no direct relationship to the OFL or SIL. We do not endorse any particular catalog or hosting service - it is your responsibility to determine if the service is right for you and if it treats authors with fairness. + +4.5 Why should I use the OFL for my fonts? +- to meet needs for fonts that can be modified to support lesser-known languages +- to provide a legal and clear way for people to respect your work but still use it (and reduce piracy) +- to involve others in your font project +- to enable your fonts to be expanded with new weights and improved writing system/language support +- to allow more technical font developers to add features to your design (such as OpenType, Graphite or AAT support) +- to renew the life of an old font lying on your hard drive with no business model +- to allow your font to be included in Libre Software operating systems like Ubuntu +- to give your font world status and wide, unrestricted distribution +- to educate students about quality typeface and font design +- to expand your test base and get more useful feedback +- to extend your reach to new markets when users see your metadata and go to your website +- to get your font more easily into one of the web font online services +- to attract attention for your commercial fonts +- to make money through web font services +- to make money by bundling fonts with applications +- to make money adjusting and extending existing open fonts +- to get a better chance that foundations/NGOs/charities/companies who commission fonts will pick you +- to be part of a sharing design and development community +- to give back and contribute to a growing body of font sources + + +5 CHOOSING RESERVED FONT NAMES + +5.1 What are Reserved Font Names? +These are font names, or portions of font names, that the author has chosen to reserve for use only with the Original Version of the font, or for Modified Version(s) created by the original author. + +5.2 Why can't I use the Reserved Font Names in my derivative font names? I'd like people to know where the design came from. +The best way to acknowledge the source of the design is to thank the original authors and any other contributors in the files that are distributed with your revised font (although no acknowledgement is required). The FONTLOG is a natural place to do this. Reserved Font Names ensure that the only fonts that have the original names are the unmodified Original Versions. This allows designers to maintain artistic integrity while allowing collaboration to happen. It eliminates potential confusion and name conflicts. When choosing a name, be creative and avoid names that reuse almost all the same letters in the same order or sound like the original. It will help everyone if Original Versions and Modified Versions can easily be distinguished from one another and from other derivatives. Any substitution and matching mechanism is outside the scope of the license. + +5.3 What do you mean by "primary name as presented to the user"? Are you referring to the font menu name? +Yes, this applies to the font menu name and other mechanisms that specify a font in a document. It would be fine, however, to keep a text reference to the original fonts in the description field, in your modified source file or in documentation provided alongside your derivative as long as no one could be confused that your modified source is the original. But you cannot use the Reserved Font Names in any way to identify the font to the user (unless the Copyright Holder(s) allow(s) it through a separate agreement). Users who install derivatives (Modified Versions) on their systems should not see any of the original Reserved Font Names in their font menus, for example. Again, this is to ensure that users are not confused and do not mistake one font for another and so expect features only another derivative or the Original Version can actually offer. + +5.4 Am I not allowed to use any part of the Reserved Font Names? +You may not use individual words from the Reserved Font Names, but you would be allowed to use parts of words, as long as you do not use any word from the Reserved Font Names entirely. We do not recommend using parts of words because of potential confusion, but it is allowed. For example, if "Foobar" was a Reserved Font Name, you would be allowed to use "Foo" or "bar", although we would not recommend it. Such an unfortunate choice would confuse the users of your fonts as well as make it harder for other designers to contribute. + +5.5 So what should I, as an author, identify as Reserved Font Names? +Original authors are encouraged to name their fonts using clear, distinct names, and only declare the unique parts of the name as Reserved Font Names. For example, the author of a font called "Foobar Sans" would declare "Foobar" as a Reserved Font Name, but not "Sans", as that is a common typographical term, and may be a useful word to use in a derivative font name. Reserved Font Names should also be single words for simplicity and legibility. A font called "Flowing River" should have Reserved Font Names "Flowing" and "River", not "Flowing River". You also need to be very careful about reserving font names which are already linked to trademarks (whether registered or not) which you do not own. + +5.6 Do I, as an author, have to identify any Reserved Font Names? +No. RFNs are optional and not required, but we encourage you to use them. This is primarily to avoid confusion between your work and Modified Versions. As an author you can release a font under the OFL and not declare any Reserved Font Names. There may be situations where you find that using no RFNs and letting your font be changed and modified - including any kind of modification - without having to change the original name is desirable. However you need to be fully aware of the consequences. There will be no direct way for end-users and other designers to distinguish your Original Version from many Modified Versions that may be created. You have to trust whoever is making the changes and the optimizations to not introduce problematic changes. The RFNs you choose for your own creation have value to you as an author because they allow you to maintain artistic integrity and keep some control over the distribution channel to your end-users. For discussion of RFNs and web fonts see section 2. + +5.7 Are any names (such as the main font name) reserved by default? +No. That is a change to the license as of version 1.1. If you want any names to be Reserved Font Names, they must be specified after the copyright statement(s). + +5.8 Is there any situation in which I can use Reserved Font Names for a Modified Version? +The Copyright Holder(s) can give certain trusted parties the right to use any of the Reserved Font Names through separate written agreements. For example, even if "Foobar" is a RFN, you could write up an agreement to give company "XYZ" the right to distribute a modified version with a name that includes "Foobar". This allows for freedom without confusion. The existence of such an agreement should be made as clear as possible to downstream users and designers in the distribution package and the relevant documentation. They need to know if they are a party to the agreement or not and what they are practically allowed to do or not even if all the details of the agreement are not public. + +5.9 Do font rebuilds require a name change? Do I have to change the name of the font when my packaging workflow includes a full rebuild from source? +Yes, all rebuilds which change the font data and the smart code are Modified Versions and the requirements of the OFL apply: you need to respect what the Author(s) have chosen in terms of Reserved Font Names. However if a package (or installer) is simply a wrapper or a compressed structure around the final font - leaving them intact on the inside - then no name change is required. Please get in touch with the author(s) and copyright holder(s) to inquire about the presence of font sources beyond the final font file(s) and the recommended build path. That build path may very well be non-trivial and hard to reproduce accurately by the maintainer. If a full font build path is made available by the upstream author(s) please be aware that any regressions and changes you may introduce when doing a rebuild for packaging purposes is your own responsibility as a package maintainer since you are effectively creating a separate branch. You should make it very clear to your users that your rebuilt version is not the canonical one from upstream. + +5.10 Can I add other Reserved Font Names when making a derivative font? +Yes. List your additional Reserved Font Names after your additional copyright statement, as indicated with example placeholders at the top of the OFL.txt file. Be sure you do not remove any existing RFNs but only add your own. RFN statements should be placed next to the copyright statement of the relevant author as indicated in the OFL.txt template to make them visible to designers wishing to make their separate version. + + +6 ABOUT THE FONTLOG + +6.1 What is this FONTLOG thing exactly? +It has three purposes: 1) to provide basic information on the font to users and other designers and developers, 2) to document changes that have been made to the font or accompanying files, either by the original authors or others, and 3) to provide a place to acknowledge authors and other contributors. Please use it! + +6.2 Is the FONTLOG required? +It is not a requirement of the license, but we strongly recommend you have one. + +6.3 Am I required to update the FONTLOG when making Modified Versions? +No, but users, designers and other developers might get very frustrated with you if you don't. People need to know how derivative fonts differ from the original, and how to take advantage of the changes, or build on them. There are utilities that can help create and maintain a FONTLOG, such as the FONTLOG support in FontForge. + +6.4 What should the FONTLOG look like? +It is typically a separate text file (FONTLOG.txt), but can take other formats. It commonly includes these four sections: + +- brief header describing the FONTLOG itself and name of the font family +- Basic Font Information - description of the font family, purpose and breadth +- ChangeLog - chronological listing of changes +- Acknowledgements - list of authors and contributors with contact information + +It could also include other sections, such as: where to find documentation, how to make contributions, information on contributing organizations, source code details, and a short design guide. See Appendix A for an example FONTLOG. + + +7 MAKING CONTRIBUTIONS TO OFL PROJECTS + +7.1 Can I contribute work to OFL projects? +In many cases, yes. It is common for OFL fonts to be developed by a team of people who welcome contributions from the wider community. Contact the original authors for specific information on how to participate in their projects. + +7.2 Why should I contribute my changes back to the original authors? +It would benefit many people if you contributed back in response to what you've received. Your contributions and improvements to the fonts and other components could be a tremendous help and would encourage others to contribute as well and 'give back'. You will then benefit from other people's contributions as well. Sometimes maintaining your own separate version takes more effort than merging back with the original. Be aware that any contributions, however, must be either your own original creation or work that you own, and you may be asked to affirm that clearly when you contribute. + +7.3 I've made some very nice improvements to the font. Will you consider adopting them and putting them into future Original Versions? +Most authors would be very happy to receive such contributions. Keep in mind that it is unlikely that they would want to incorporate major changes that would require additional work on their end. Any contributions would likely need to be made for all the fonts in a family and match the overall design and style. Authors are encouraged to include a guide to the design with the fonts. It would also help to have contributions submitted as patches or clearly marked changes - the use of smart source revision control systems like subversion, mercurial, git or bzr is a good idea. Please follow the recommendations given by the author(s) in terms of preferred source formats and configuration parameters for sending contributions. If this is not indicated in a FONTLOG or other documentation of the font, consider asking them directly. Examples of useful contributions are bug fixes, additional glyphs, stylistic alternates (and the smart font code to access them) or improved hinting. Keep in mind that some kinds of changes (esp. hinting) may be technically difficult to integrate. + +7.4 How can I financially support the development of OFL fonts? +It is likely that most authors of OFL fonts would accept financial contributions - contact them for instructions on how to do this. Such contributions would support future development. You can also pay for others to enhance the fonts and contribute the results back to the original authors for inclusion in the Original Version. + + +8 ABOUT THE LICENSE ITSELF + +8.1 I see that this is version 1.1 of the license. Will there be later changes? +Version 1.1 is the first minor revision of the OFL. We are confident that version 1.1 will meet most needs, but are open to future improvements. Any revisions would be for future font releases, and previously existing licenses would remain in effect. No retroactive changes are possible, although the Copyright Holder(s) can re-release the font under a revised OFL. All versions will be available on our web site: http://scripts.sil.org/OFL. + +8.2 Does this license restrict the rights of the Copyright Holder(s)? +No. The Copyright Holder(s) still retain(s) all the rights to their creation; they are only releasing a portion of it for use in a specific way. For example, the Copyright Holder(s) may choose to release a 'basic' version of their font under the OFL, but sell a restricted 'enhanced' version under a different license. They may also choose to release the same font under both the OFL and some other license. Only the Copyright Holder(s) can do this, and doing so does not change the terms of the OFL as it applies to that font. + +8.3 Is the OFL a contract or a license? +The OFL is a worldwide license based on international copyright agreements and conventions. It is not a contract and so does not require you to sign it to have legal validity. By using, modifying and redistributing components under the OFL you indicate that you accept the license. + +8.4 I really like the terms of the OFL, but want to change it a little. Am I allowed to take ideas and actual wording from the OFL and put them into my own custom license for distributing my fonts? +We strongly recommend against creating your very own unique open licensing model. Using a modified or derivative license will likely cut you off - along with the font(s) under that license - from the community of designers using the OFL, potentially expose you and your users to legal liabilities, and possibly put your work and rights at risk. The OFL went though a community and legal review process that took years of effort, and that review is only applicable to an unmodified OFL. The text of the OFL has been written by SIL (with review and consultation from the community) and is copyright (c) 2005-2017 SIL International. You may re-use the ideas and wording (in part, not in whole) in another non-proprietary license provided that you call your license by another unambiguous name, that you do not use the preamble, that you do not mention SIL and that you clearly present your license as different from the OFL so as not to cause confusion by being too similar to the original. If you feel the OFL does not meet your needs for an open license, please contact us. + +8.5 Can I quote from the OFL FAQ? +Yes, SIL gives permission to quote from the OFL FAQ (OFL-FAQ.txt), in whole or in part, provided that the quoted text is: + +- unmodified, +- used to help explain the intent of the OFL, rather than cause misunderstanding, and +- accompanied with the following attribution: "From the OFL FAQ (OFL-FAQ.txt), copyright (c) 2005-2020 SIL International. Used by permission. http://scripts.sil.org/OFL-FAQ_web". + +8.6 Can I translate the license and the FAQ into other languages? +SIL certainly recognises the need for people who are not familiar with English to be able to understand the OFL and its use. Making the license very clear and readable has been a key goal for the OFL, but we know that people understand their own language best. + +If you are an experienced translator, you are very welcome to translate the OFL and OFL-FAQ so that designers and users in your language community can understand the license better. But only the original English version of the license has legal value and has been approved by the community. Translations do not count as legal substitutes and should only serve as a way to explain the original license. SIL - as the author and steward of the license for the community at large - does not approve any translation of the OFL as legally valid because even small translation ambiguities could be abused and create problems. + +SIL gives permission to publish unofficial translations into other languages provided that they comply with the following guidelines: + +- Put the following disclaimer in both English and the target language stating clearly that the translation is unofficial: + +"This is an unofficial translation of the SIL Open Font License into . It was not published by SIL International, and does not legally state the distribution terms for fonts that use the OFL. A release under the OFL is only valid when using the original English text. However, we recognize that this unofficial translation will help users and designers not familiar with English to better understand and use the OFL. We encourage designers who consider releasing their creation under the OFL to read the OFL-FAQ in their own language if it is available. Please go to http://scripts.sil.org/OFL for the official version of the license and the accompanying OFL-FAQ." + +- Keep your unofficial translation current and update it at our request if needed, for example if there is any ambiguity which could lead to confusion. + +If you start such a unofficial translation effort of the OFL and OFL-FAQ please let us know. + +8.7 Does the OFL have an explicit expiration term? +No, the implicit intent of the OFL is that the permissions granted are perpetual and irrevocable. + + +9 ABOUT SIL INTERNATIONAL + +9.1 Who is SIL International and what do they do? +SIL serves language communities worldwide, building their capacity for sustainable language development, by means of research, translation, training and materials development. SIL makes its services available to all without regard to religious belief, political ideology, gender, race, or ethnic background. SIL's members and volunteers share a Christian commitment. + +9.2 What does this have to do with font licensing? +The ability to read, write, type and publish in one's own language is one of the most critical needs for millions of people around the world. This requires fonts that are widely available and support lesser-known languages. SIL develops - and encourages others to develop - a complete stack of writing systems implementation components available under open licenses. This open stack includes input methods, smart fonts, smart rendering libraries and smart applications. There has been a need for a common open license that is specifically applicable to fonts and related software (a crucial component of this stack), so SIL developed the SIL Open Font License with the help of the Free/Libre and Open Source Software community. + +9.3 How can I contact SIL? +Our main web site is: http://www.sil.org/ +Our site about complex scripts is: http://scripts.sil.org/ +Information about this license (and contact information) is at: http://scripts.sil.org/OFL + + +APPENDIX A - FONTLOG EXAMPLE + +Here is an example of the recommended format for a FONTLOG, although other formats are allowed. + +----- +FONTLOG for the GlobalFontFamily fonts + +This file provides detailed information on the GlobalFontFamily Font Software. This information should be distributed along with the GlobalFontFamily fonts and any derivative works. + +Basic Font Information + +GlobalFontFamily is a Unicode typeface family that supports all languages that use the Latin script and its variants, and could be expanded to support other scripts. + +NewWorldFontFamily is based on the GlobalFontFamily and also supports Greek, Hebrew, Cyrillic and Armenian. + +More specifically, this release supports the following Unicode ranges... +This release contains... +Documentation can be found at... +To contribute to the project... + +ChangeLog + +10 December 2010 (Fred Foobar) GlobalFontFamily-devel version 1.4 +- fix new build and testing system (bug #123456) + +1 August 2008 (Tom Parker) GlobalFontFamily version 1.2.1 +- Tweaked the smart font code (Branch merged with trunk version) +- Provided improved build and debugging environment for smart behaviours + +7 February 2007 (Pat Johnson) NewWorldFontFamily Version 1.3 +- Added Greek and Cyrillic glyphs + +7 March 2006 (Fred Foobar) NewWorldFontFamily Version 1.2 +- Tweaked contextual behaviours + +1 Feb 2005 (Jane Doe) NewWorldFontFamily Version 1.1 +- Improved build script performance and verbosity +- Extended the smart code documentation +- Corrected minor typos in the documentation +- Fixed position of combining inverted breve below (U+032F) +- Added OpenType/Graphite smart code for Armenian +- Added Armenian glyphs (U+0531 -> U+0587) +- Released as "NewWorldFontFamily" + +1 Jan 2005 (Joe Smith) GlobalFontFamily Version 1.0 +- Initial release + +Acknowledgements + +If you make modifications be sure to add your name (N), email (E), web-address (if you have one) (W) and description (D). This list is in alphabetical order. + +N: Jane Doe +E: jane@university.edu +W: http://art.university.edu/projects/fonts +D: Contributor - Armenian glyphs and code + +N: Fred Foobar +E: fred@foobar.org +W: http://foobar.org +D: Contributor - misc Graphite fixes + +N: Pat Johnson +E: pat@fontstudio.org +W: http://pat.fontstudio.org +D: Designer - Greek & Cyrillic glyphs based on Roman design + +N: Tom Parker +E: tom@company.com +W: http://www.company.com/tom/projects/fonts +D: Engineer - original smart font code + +N: Joe Smith +E: joe@fontstudio.org +W: http://joe.fontstudio.org +D: Designer - original Roman glyphs + +Fontstudio.org is an not-for-profit design group whose purpose is... +Foobar.org is a distributed community of developers... +Company.com is a small business who likes to support community designers... +University.edu is a renowned educational institution with a strong design department... +----- + diff --git a/src/assets/fonts/OpenFontLicense.txt b/src/assets/fonts/OpenFontLicense.txt new file mode 100644 index 0000000..f1a20ac --- /dev/null +++ b/src/assets/fonts/OpenFontLicense.txt @@ -0,0 +1,97 @@ +Copyright (c) , (), +with Reserved Font Name . +Copyright (c) , (), +with Reserved Font Name . +Copyright (c) , (). + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/assets/icons/BaseAppIcon.png b/src/assets/icons/BaseAppIcon.png new file mode 100755 index 0000000..2d5df1e Binary files /dev/null and b/src/assets/icons/BaseAppIcon.png differ diff --git a/src/assets/icons/icon.icns b/src/assets/icons/icon.icns new file mode 100644 index 0000000..c151543 Binary files /dev/null and b/src/assets/icons/icon.icns differ diff --git a/src/assets/icons/icon.ico b/src/assets/icons/icon.ico new file mode 100644 index 0000000..d0f2bad Binary files /dev/null and b/src/assets/icons/icon.ico differ diff --git a/src/assets/icons/icon.iconset/icon_128x128.png b/src/assets/icons/icon.iconset/icon_128x128.png new file mode 100755 index 0000000..8606b87 Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_128x128.png differ diff --git a/src/assets/icons/icon.iconset/icon_128x128@2x.png b/src/assets/icons/icon.iconset/icon_128x128@2x.png new file mode 100755 index 0000000..9a9ff5a Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_128x128@2x.png differ diff --git a/src/assets/icons/icon.iconset/icon_16x16.png b/src/assets/icons/icon.iconset/icon_16x16.png new file mode 100755 index 0000000..6764885 Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_16x16.png differ diff --git a/src/assets/icons/icon.iconset/icon_16x16@2x.png b/src/assets/icons/icon.iconset/icon_16x16@2x.png new file mode 100755 index 0000000..087b71a Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_16x16@2x.png differ diff --git a/src/assets/icons/icon.iconset/icon_256x256.png b/src/assets/icons/icon.iconset/icon_256x256.png new file mode 100755 index 0000000..ec7ab2b Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_256x256.png differ diff --git a/src/assets/icons/icon.iconset/icon_256x256@2x.png b/src/assets/icons/icon.iconset/icon_256x256@2x.png new file mode 100755 index 0000000..6ff1cd9 Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_256x256@2x.png differ diff --git a/src/assets/icons/icon.iconset/icon_32x32.png b/src/assets/icons/icon.iconset/icon_32x32.png new file mode 100755 index 0000000..57a21b8 Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_32x32.png differ diff --git a/src/assets/icons/icon.iconset/icon_32x32@2x.png b/src/assets/icons/icon.iconset/icon_32x32@2x.png new file mode 100755 index 0000000..a480603 Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_32x32@2x.png differ diff --git a/src/assets/icons/icon.iconset/icon_512x512.png b/src/assets/icons/icon.iconset/icon_512x512.png new file mode 100755 index 0000000..dadddb6 Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_512x512.png differ diff --git a/src/assets/icons/icon.iconset/icon_512x512@2x.png b/src/assets/icons/icon.iconset/icon_512x512@2x.png new file mode 100755 index 0000000..2d5df1e Binary files /dev/null and b/src/assets/icons/icon.iconset/icon_512x512@2x.png differ diff --git a/src/assets/icons/icon.svg b/src/assets/icons/icon.svg new file mode 100644 index 0000000..edaaaa4 --- /dev/null +++ b/src/assets/icons/icon.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/icons/windows/icon_128x128.png b/src/assets/icons/windows/icon_128x128.png new file mode 100755 index 0000000..8606b87 Binary files /dev/null and b/src/assets/icons/windows/icon_128x128.png differ diff --git a/src/assets/icons/windows/icon_16x16.png b/src/assets/icons/windows/icon_16x16.png new file mode 100755 index 0000000..6764885 Binary files /dev/null and b/src/assets/icons/windows/icon_16x16.png differ diff --git a/src/assets/icons/windows/icon_256x256.png b/src/assets/icons/windows/icon_256x256.png new file mode 100755 index 0000000..ec7ab2b Binary files /dev/null and b/src/assets/icons/windows/icon_256x256.png differ diff --git a/src/assets/icons/windows/icon_32x32.png b/src/assets/icons/windows/icon_32x32.png new file mode 100755 index 0000000..57a21b8 Binary files /dev/null and b/src/assets/icons/windows/icon_32x32.png differ diff --git a/src/assets/icons/windows/icon_512x512.png b/src/assets/icons/windows/icon_512x512.png new file mode 100755 index 0000000..dadddb6 Binary files /dev/null and b/src/assets/icons/windows/icon_512x512.png differ diff --git a/src/assets/icons/windows/icon_64x64.png b/src/assets/icons/windows/icon_64x64.png new file mode 100755 index 0000000..a480603 Binary files /dev/null and b/src/assets/icons/windows/icon_64x64.png differ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4b80ab1..471fd74 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -3,12 +3,26 @@ set(NAME "Core") include(${PROJECT_SOURCE_DIR}/cmake/StaticAnalyzers.cmake) add_library(${NAME} STATIC - Core/Log.cpp Core/Log.hpp Core/Instrumentor.hpp - Core/Application.cpp Core/Application.hpp - Core/Window.cpp Core/Window.hpp) + Core/Log.cpp Core/Log.hpp Core/Debug/Instrumentor.hpp + Core/Application.cpp Core/Application.hpp Core/Window.cpp Core/Window.hpp + Core/Resources.hpp Core/DPIHandler.hpp) + +# Define set of OS specific files to include +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_sources(${NAME} PRIVATE + Platform/Windows/Resources.cpp Platform/Windows/DPIHandler.cpp) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_sources(${NAME} PRIVATE + Platform/Mac/Resources.cpp Platform/Mac/DPIHandler.cpp) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_sources(${NAME} PRIVATE + Platform/Linux/Resources.cpp Platform/Linux/DPIHandler.cpp) +endif () target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(${NAME} PRIVATE cxx_std_20) target_link_libraries(${NAME} PRIVATE project_warnings - PUBLIC spdlog SDL2::SDL2 glad imgui) + PUBLIC fmt spdlog SDL2::SDL2 glad imgui Settings) + +add_subdirectory(Tests) diff --git a/src/core/Core/Application.cpp b/src/core/Core/Application.cpp index f31a6bc..816ba7c 100644 --- a/src/core/Core/Application.cpp +++ b/src/core/Core/Application.cpp @@ -1,22 +1,32 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #include "Application.hpp" +#include +#include +#include +#include +#include #include -#include +#include #include #include -#include "Core/Instrumentor.hpp" +#include +#include + +#include "Core/DPIHandler.hpp" +#include "Core/Debug/Instrumentor.hpp" +#include "Core/Log.hpp" +#include "Core/Resources.hpp" +#include "Core/Window.hpp" +#include "Settings/Project.hpp" namespace App { Application::Application(const std::string& title) { APP_PROFILE_FUNCTION(); - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { + const unsigned int init_flags{SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER}; + if (SDL_Init(init_flags) != 0) { APP_ERROR("Error: %s\n", SDL_GetError()); m_exit_status = ExitStatus::FAILURE; } @@ -26,17 +36,7 @@ Application::Application(const std::string& title) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - m_window = std::make_shared(Window::Settings{title}); - - // Setup Dear ImGui context - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - - set_theme(); - - // Setup Platform/Renderer backends - ImGui_ImplSDL2_InitForOpenGL(m_window->get_native_window(), m_window->get_native_context()); - ImGui_ImplOpenGL3_Init("#version 410 core"); + m_window = std::make_unique(Window::Settings{title}); } Application::~Application() { @@ -56,15 +56,43 @@ ExitStatus App::Application::run() { return m_exit_status; } - m_state.running = true; + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io{ImGui::GetIO()}; + + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_DockingEnable | + ImGuiConfigFlags_ViewportsEnable; + + // @info: https://github.com/ocornut/imgui/issues/2361 + io.ConfigDockingTransparentPayload = true; + + const std::string user_config_path{SDL_GetPrefPath(COMPANY_NAMESPACE.c_str(), APP_NAME.c_str())}; + APP_DEBUG("User config path: {}", user_config_path); + + // Absolute imgui.ini path to preserve settings independent of app location. + static const std::string imgui_ini_filename{user_config_path + "imgui.ini"}; + io.IniFilename = imgui_ini_filename.c_str(); - const ImGuiIO& io{ImGui::GetIO()}; + // ImGUI font + const float font_scaling_factor{DPIHandler::get_scale()}; + const float font_size{18.0F * font_scaling_factor}; + const std::string font_path{Resources::font_path("Manrope.ttf").generic_string()}; + + io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); + io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size); + DPIHandler::set_global_font_scaling(&io); + + // Setup Platform/Renderer backends + ImGui_ImplSDL2_InitForOpenGL(m_window->get_native_window(), m_window->get_native_context()); + ImGui_ImplOpenGL3_Init("#version 410 core"); - while (m_state.running) { + m_running = true; + while (m_running) { APP_PROFILE_SCOPE("MainLoop"); SDL_Event event{}; - while (SDL_PollEvent(&event) != 0) { + while (SDL_PollEvent(&event) == 1) { APP_PROFILE_SCOPE("EventPolling"); ImGui_ImplSDL2_ProcessEvent(&event); @@ -84,7 +112,7 @@ ExitStatus App::Application::run() { ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - if (!m_state.minimized) { + if (!m_minimized) { ImGui::DockSpaceOverViewport(); if (ImGui::BeginMainMenuBar()) { @@ -95,24 +123,43 @@ ExitStatus App::Application::run() { ImGui::EndMenu(); } if (ImGui::BeginMenu("View")) { - ImGui::MenuItem("Some Panel", nullptr, &m_state.show_some_panel); + ImGui::MenuItem("Some Panel", nullptr, &m_show_some_panel); + ImGui::MenuItem("ImGui Demo Panel", nullptr, &m_show_demo_panel); + ImGui::MenuItem("Debug Panel", nullptr, &m_show_debug_panel); ImGui::EndMenu(); } ImGui::EndMainMenuBar(); } - } - // Whatever GUI to implement here ... - if (m_state.show_some_panel) { - ImGui::Begin("Some panel", &m_state.show_some_panel); - // NOLINTNEXTLINE - ImGui::Text("Hello World"); - ImGui::End(); + // Whatever GUI to implement here ... + if (m_show_some_panel) { + ImGui::Begin("Some panel", &m_show_some_panel); + ImGui::Text("Hello World"); + ImGui::End(); + } + + // ImGUI demo panel + if (m_show_demo_panel) { + ImGui::ShowDemoWindow(&m_show_demo_panel); + } + + // Debug panel + if (m_show_debug_panel) { + ImGui::Begin("Debug panel", &m_show_debug_panel); + ImGui::Text("User config path: %s", user_config_path.c_str()); + ImGui::Separator(); + ImGui::Text("Font path: %s", font_path.c_str()); + ImGui::Text("Font size: %f", font_size); + ImGui::Text("Global font scaling %f", io.FontGlobalScale); + ImGui::Text("UI scaling factor: %f", font_scaling_factor); + ImGui::End(); + } } // Rendering ImGui::Render(); + glViewport(0, 0, static_cast(io.DisplaySize.x), static_cast(io.DisplaySize.y)); glClearColor(0.5F, 0.5F, 0.5F, 1.00F); glClear(GL_COLOR_BUFFER_BIT); @@ -133,12 +180,10 @@ ExitStatus App::Application::run() { } void App::Application::stop() { - m_state.running = false; + m_running = false; } void Application::on_event(const SDL_WindowEvent& event) { - APP_PROFILE_FUNCTION(); - switch (event.event) { case SDL_WINDOWEVENT_CLOSE: return on_close(); @@ -146,62 +191,22 @@ void Application::on_event(const SDL_WindowEvent& event) { return on_minimize(); case SDL_WINDOWEVENT_SHOWN: return on_shown(); - case SDL_WINDOWEVENT_RESIZED: - return on_resize(event); + default: + // Do nothing otherwise + return; } } -// Can be static, but will serve as an example call, so ignore. -// NOLINTNEXTLINE -void Application::on_resize([[maybe_unused]] const SDL_WindowEvent& event) { - APP_DEBUG("RESIZE {} {}", event.data1, event.data2); -} - void Application::on_minimize() { - m_state.minimized = true; + m_minimized = true; } void Application::on_shown() { - m_state.minimized = false; + m_minimized = false; } void Application::on_close() { stop(); } -void Application::set_theme() const { - APP_PROFILE_FUNCTION(); - - ImGuiIO& io{ImGui::GetIO()}; - ImGuiStyle& style{ImGui::GetStyle()}; - - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_DockingEnable | - ImGuiConfigFlags_ViewportsEnable; - - // ImGui font - const float font_scaling_factor{m_window->get_scale()}; - const float font_size{18.0F * font_scaling_factor}; - - io.Fonts->AddFontFromFileTTF("assets/fonts/Manrope/Manrope-Regular.ttf", font_size); - io.FontDefault = - io.Fonts->AddFontFromFileTTF("assets/fonts/Manrope/Manrope-Regular.ttf", font_size); - io.FontGlobalScale = 1.0F / font_scaling_factor; - - style.WindowRounding = 5.3F; - style.GrabRounding = style.FrameRounding = 2.3F; - style.ScrollbarRounding = 5.0F; - style.FrameBorderSize = 1.0F; - style.ItemSpacing.y = 6.5F; - - if ((io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != 0) { - style.WindowRounding = 0.0F; - style.Colors[ImGuiCol_WindowBg].w = 1.0F; - } - - // Theme setup ... - // auto* colors{static_cast(style.Colors)}; - // colors[ImGuiCol_Text] = {0.73333335F, 0.73333335F, 0.73333335F, 1.00F}; - // ... -} - } // namespace App diff --git a/src/core/Core/Application.hpp b/src/core/Core/Application.hpp index 0ee14e9..f7c9f1b 100644 --- a/src/core/Core/Application.hpp +++ b/src/core/Core/Application.hpp @@ -1,7 +1,3 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #pragma once #include @@ -30,23 +26,19 @@ class Application { void stop(); void on_event(const SDL_WindowEvent& event); - void on_resize(const SDL_WindowEvent& event); void on_minimize(); void on_shown(); void on_close(); private: - struct State { - bool running{false}; - bool minimized{false}; - bool show_some_panel{true}; - }; - - void set_theme() const; - ExitStatus m_exit_status{ExitStatus::SUCCESS}; - std::shared_ptr m_window{nullptr}; - State m_state{}; + std::unique_ptr m_window{nullptr}; + + bool m_running{true}; + bool m_minimized{false}; + bool m_show_some_panel{true}; + bool m_show_debug_panel{false}; + bool m_show_demo_panel{false}; }; } // namespace App diff --git a/src/core/Core/DPIHandler.hpp b/src/core/Core/DPIHandler.hpp new file mode 100644 index 0000000..66048e5 --- /dev/null +++ b/src/core/Core/DPIHandler.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include "Core/Window.hpp" + +namespace App { + +struct WindowSize { + int width; + int height; +}; + +class DPIHandler { + public: + [[nodiscard]] static float get_scale(); + + [[nodiscard]] static WindowSize get_dpi_aware_window_size(const Window::Settings& settings); + + static void set_global_font_scaling(ImGuiIO* io); +}; + +} // namespace App diff --git a/src/core/Core/Instrumentor.hpp b/src/core/Core/Debug/Instrumentor.hpp similarity index 96% rename from src/core/Core/Instrumentor.hpp rename to src/core/Core/Debug/Instrumentor.hpp index 9584247..cb267a7 100644 --- a/src/core/Core/Instrumentor.hpp +++ b/src/core/Core/Debug/Instrumentor.hpp @@ -1,7 +1,3 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #pragma once #include @@ -28,7 +24,7 @@ struct ProfileResult { struct InstrumentationSession { const std::string name; - explicit InstrumentationSession(std::string name) : name(std::move(name)) {} + explicit InstrumentationSession(std::string session_name) : name(std::move(session_name)) {} }; class Instrumentor { @@ -39,7 +35,7 @@ class Instrumentor { Instrumentor& operator=(Instrumentor&& other) = delete; void begin_session(const std::string& name, const std::string& filepath = "results.json") { - std::lock_guard lock(m_mutex); + const std::lock_guard lock(m_mutex); if (m_current_session != nullptr) { // If there is already a current session, then close it before beginning new one. @@ -62,7 +58,7 @@ class Instrumentor { } void end_session() { - std::lock_guard lock(m_mutex); + const std::lock_guard lock(m_mutex); internal_end_session(); } @@ -83,7 +79,7 @@ class Instrumentor { json << "\"ts\":" << result.start.count(); json << "}"; - std::lock_guard lock(m_mutex); + const std::lock_guard lock(m_mutex); if (m_current_session != nullptr) { m_output_stream << json.str(); m_output_stream.flush(); diff --git a/src/core/Core/Log.cpp b/src/core/Core/Log.cpp index 8488213..5d01b9c 100644 --- a/src/core/Core/Log.cpp +++ b/src/core/Core/Log.cpp @@ -1,12 +1,12 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #include "Log.hpp" +#include +#include #include #include +#include +#include #include namespace App { @@ -14,11 +14,7 @@ namespace App { Log::Log() { std::vector log_sinks; -#ifdef TRACE - const spdlog::level::level_enum level{spdlog::level::trace}; -#else const spdlog::level::level_enum level{spdlog::level::debug}; -#endif log_sinks.emplace_back(std::make_shared()); log_sinks.emplace_back(std::make_shared("app.log", true)); diff --git a/src/core/Core/Log.hpp b/src/core/Core/Log.hpp index f09b607..ffd4c7d 100644 --- a/src/core/Core/Log.hpp +++ b/src/core/Core/Log.hpp @@ -1,7 +1,3 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #pragma once #include diff --git a/src/core/Core/Resources.hpp b/src/core/Core/Resources.hpp new file mode 100644 index 0000000..96c49b4 --- /dev/null +++ b/src/core/Core/Resources.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +namespace App { + +class Resources { + public: + [[nodiscard]] static std::filesystem::path resource_path(const std::filesystem::path& file_path); + [[nodiscard]] static std::filesystem::path font_path(const std::string_view& font_file); +}; + +} // namespace App diff --git a/src/core/Core/Window.cpp b/src/core/Core/Window.cpp index 2a6aa52..073e22e 100644 --- a/src/core/Core/Window.cpp +++ b/src/core/Core/Window.cpp @@ -1,12 +1,11 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #include "Window.hpp" +#include #include -#include "Core/Instrumentor.hpp" +#include "Core/DPIHandler.hpp" +#include "Core/Debug/Instrumentor.hpp" +#include "Core/Log.hpp" namespace App { @@ -21,12 +20,13 @@ Window::Window(const Settings& settings) { constexpr auto window_flags{static_cast( SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI)}; constexpr int window_center_flag{SDL_WINDOWPOS_CENTERED}; + const WindowSize size{DPIHandler::get_dpi_aware_window_size(settings)}; m_window = SDL_CreateWindow(settings.title.c_str(), window_center_flag, window_center_flag, - settings.width, - settings.height, + size.width, + size.height, window_flags); // NOLINTNEXTLINE @@ -48,22 +48,6 @@ Window::~Window() { SDL_DestroyWindow(m_window); } -float Window::get_scale() const { - APP_PROFILE_FUNCTION(); - - int window_width{0}; - int window_height{0}; - SDL_GetWindowSize(m_window, &window_width, &window_height); - - int pixel_width{0}; - int pixel_height{0}; - SDL_GL_GetDrawableSize(m_window, &pixel_width, &pixel_height); - - const auto scale_x{static_cast(pixel_width) / static_cast(window_width)}; - - return scale_x; -} - SDL_Window* Window::get_native_window() const { return m_window; } diff --git a/src/core/Core/Window.hpp b/src/core/Core/Window.hpp index c878b26..653a6eb 100644 --- a/src/core/Core/Window.hpp +++ b/src/core/Core/Window.hpp @@ -1,7 +1,3 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #pragma once #include @@ -14,8 +10,8 @@ class Window { public: struct Settings { std::string title; - const int width{1280}; - const int height{720}; + int width{1280}; + int height{720}; }; explicit Window(const Settings& settings); @@ -26,14 +22,12 @@ class Window { Window& operator=(Window other) = delete; Window& operator=(Window&& other) = delete; - [[nodiscard]] float get_scale() const; - [[nodiscard]] SDL_Window* get_native_window() const; [[nodiscard]] SDL_GLContext get_native_context() const; private: - SDL_Window* m_window; - SDL_GLContext m_gl_context; + SDL_Window* m_window{nullptr}; + SDL_GLContext m_gl_context{nullptr}; }; } // namespace App diff --git a/src/core/Platform/Linux/DPIHandler.cpp b/src/core/Platform/Linux/DPIHandler.cpp new file mode 100644 index 0000000..bb0cbf8 --- /dev/null +++ b/src/core/Platform/Linux/DPIHandler.cpp @@ -0,0 +1,34 @@ +#include "Core/DPIHandler.hpp" + +#include +#include + +#include "Core/Debug/Instrumentor.hpp" +#include "Core/Window.hpp" + +namespace App { + +float DPIHandler::get_scale() { + APP_PROFILE_FUNCTION(); + + constexpr int display_index{0}; + const float default_dpi{96.0F}; + float dpi{default_dpi}; + + SDL_GetDisplayDPI(display_index, nullptr, &dpi, nullptr); + + return dpi / default_dpi; +} + +WindowSize DPIHandler::get_dpi_aware_window_size(const Window::Settings& settings) { + APP_PROFILE_FUNCTION(); + + return {settings.width, settings.height}; +} + +void DPIHandler::set_global_font_scaling([[maybe_unused]] ImGuiIO* io) { + APP_PROFILE_FUNCTION(); + // do nothing +} + +} // namespace App diff --git a/src/core/Platform/Linux/Resources.cpp b/src/core/Platform/Linux/Resources.cpp new file mode 100644 index 0000000..8d8f944 --- /dev/null +++ b/src/core/Platform/Linux/Resources.cpp @@ -0,0 +1,24 @@ +#include "Core/Resources.hpp" + +#include + +#include +#include +#include + +namespace App { + +static const std::string BASE_PATH{SDL_GetBasePath()}; + +std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) { + 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) { + return resource_path(font_file); +} + +} // namespace App diff --git a/src/core/Platform/Mac/DPIHandler.cpp b/src/core/Platform/Mac/DPIHandler.cpp new file mode 100644 index 0000000..ddeab4c --- /dev/null +++ b/src/core/Platform/Mac/DPIHandler.cpp @@ -0,0 +1,39 @@ +#include "Core/DPIHandler.hpp" + +#include +#include + +#include + +#include "Core/Debug/Instrumentor.hpp" +#include "Core/Window.hpp" + +namespace App { + +float DPIHandler::get_scale() { + APP_PROFILE_FUNCTION(); + + constexpr int display_index{0}; + // @todo: This should be 72.0F on Mac, but it seems like it is not. I'm not + // sure why, but this works ¯\_(ツ)_/¯ + const float default_dpi{96.0F}; + float dpi{default_dpi}; + + SDL_GetDisplayDPI(display_index, nullptr, &dpi, nullptr); + + return std::floor(dpi / default_dpi); +} + +WindowSize DPIHandler::get_dpi_aware_window_size(const Window::Settings& settings) { + APP_PROFILE_FUNCTION(); + + return {settings.width, settings.height}; +} + +void DPIHandler::set_global_font_scaling(ImGuiIO* io) { + APP_PROFILE_FUNCTION(); + + io->FontGlobalScale = 1.0F / get_scale(); +} + +} // namespace App diff --git a/src/core/Platform/Mac/Resources.cpp b/src/core/Platform/Mac/Resources.cpp new file mode 100644 index 0000000..6e2f076 --- /dev/null +++ b/src/core/Platform/Mac/Resources.cpp @@ -0,0 +1,23 @@ +#include "Core/Resources.hpp" + +#include + +#include +#include +#include + +namespace App { + +static const std::string BASE_PATH{SDL_GetBasePath()}; + +std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) { + 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) { + return resource_path(font_file); +} + +} // namespace App diff --git a/src/core/Platform/Windows/DPIHandler.cpp b/src/core/Platform/Windows/DPIHandler.cpp new file mode 100644 index 0000000..84bd8e6 --- /dev/null +++ b/src/core/Platform/Windows/DPIHandler.cpp @@ -0,0 +1,37 @@ +#include "Core/DPIHandler.hpp" + +#include +#include + +#include "Core/Debug/Instrumentor.hpp" +#include "Core/Window.hpp" + +namespace App { + +float DPIHandler::get_scale() { + APP_PROFILE_FUNCTION(); + + constexpr int display_index{0}; + const float default_dpi{96.0F}; + float dpi{default_dpi}; + + SDL_GetDisplayDPI(display_index, nullptr, &dpi, nullptr); + + return dpi / default_dpi; +} + +WindowSize DPIHandler::get_dpi_aware_window_size(const Window::Settings& settings) { + APP_PROFILE_FUNCTION(); + + const float scale{DPIHandler::get_scale()}; + const int width{static_cast(static_cast(settings.width) * scale)}; + const int height{static_cast(static_cast(settings.height) * scale)}; + return {width, height}; +} + +void DPIHandler::set_global_font_scaling([[maybe_unused]] ImGuiIO* io) { + APP_PROFILE_FUNCTION(); + // do nothing +} + +} // namespace App diff --git a/src/core/Platform/Windows/Resources.cpp b/src/core/Platform/Windows/Resources.cpp new file mode 100644 index 0000000..0226643 --- /dev/null +++ b/src/core/Platform/Windows/Resources.cpp @@ -0,0 +1,23 @@ +#include "Core/Resources.hpp" + +#include + +#include +#include +#include + +namespace App { + +static const std::string BASE_PATH{SDL_GetBasePath()}; + +std::filesystem::path Resources::resource_path(const std::filesystem::path& file_path) { + 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) { + return resource_path("fonts") / font_file; +} + +} // namespace App diff --git a/src/core/Tests/CMakeLists.txt b/src/core/Tests/CMakeLists.txt new file mode 100644 index 0000000..ece8d74 --- /dev/null +++ b/src/core/Tests/CMakeLists.txt @@ -0,0 +1,5 @@ +# Test cases + +add_executable(ResourcesTest Resources.spec.cpp $) +add_test(NAME ResourcesTest COMMAND ResourcesTest) +target_link_libraries(ResourcesTest PRIVATE doctest Core) diff --git a/src/core/Tests/Resources.spec.cpp b/src/core/Tests/Resources.spec.cpp new file mode 100644 index 0000000..927e33e --- /dev/null +++ b/src/core/Tests/Resources.spec.cpp @@ -0,0 +1,13 @@ +#include +#include + +// NOLINTBEGIN(misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while, cert-err33-c) + +TEST_SUITE("Core::Resources") { + TEST_CASE("Example") { + const std::string input{"A"}; + CHECK_EQ(input, "A"); + } +} + +// NOLINTEND(misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while, cert-err33-c) diff --git a/src/settings/CMakeLists.txt b/src/settings/CMakeLists.txt new file mode 100644 index 0000000..672f62d --- /dev/null +++ b/src/settings/CMakeLists.txt @@ -0,0 +1,11 @@ +set(NAME "Settings") + +include(${PROJECT_SOURCE_DIR}/cmake/StaticAnalyzers.cmake) + +configure_file(Settings/Project.cpp.in Settings/Project.cpp @ONLY) + +add_library(${NAME} STATIC Settings/Project.hpp Settings/Project.cpp) + +target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_features(${NAME} PRIVATE cxx_std_20) +target_link_libraries(${NAME} PRIVATE project_warnings) diff --git a/src/settings/Settings/Project.cpp.in b/src/settings/Settings/Project.cpp.in new file mode 100644 index 0000000..5255e58 --- /dev/null +++ b/src/settings/Settings/Project.cpp.in @@ -0,0 +1,10 @@ +#include + +#include "Settings/Project.hpp" + +namespace App { + +const std::string COMPANY_NAMESPACE{"@PROJECT_COMPANY_NAMESPACE@"}; +const std::string APP_NAME{"@CMAKE_PROJECT_NAME@"}; + +} // namespace App diff --git a/src/settings/Settings/Project.hpp b/src/settings/Settings/Project.hpp new file mode 100644 index 0000000..586ff0c --- /dev/null +++ b/src/settings/Settings/Project.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace App { + +extern const std::string COMPANY_NAMESPACE; +extern const std::string APP_NAME; + +} // namespace App diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000..c5f818c --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,5 @@ +set(NAME "TestRunner") + +add_library(${NAME} OBJECT ${PROJECT_SOURCE_DIR}/src/tests/TestRunner.cpp) +target_compile_features(${NAME} PRIVATE cxx_std_20) +target_link_libraries(${NAME} PUBLIC doctest) diff --git a/src/tests/TestRunner.cpp b/src/tests/TestRunner.cpp new file mode 100644 index 0000000..0a3f254 --- /dev/null +++ b/src/tests/TestRunner.cpp @@ -0,0 +1,2 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 71f72fa..afbcc4d 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -3,14 +3,14 @@ include(FetchContent) FetchContent_Declare( doctest GIT_REPOSITORY "https://github.com/onqtam/doctest.git" - GIT_TAG v2.4.9 + GIT_TAG v2.4.11 ) add_subdirectory(doctest) FetchContent_Declare( fmt GIT_REPOSITORY "https://github.com/fmtlib/fmt.git" - GIT_TAG 9.1.0 + GIT_TAG 10.1.1 ) add_subdirectory(fmt) @@ -24,20 +24,20 @@ add_subdirectory(glad) FetchContent_Declare( imgui GIT_REPOSITORY "https://github.com/ocornut/imgui.git" - GIT_TAG c191faf0ba478e9c58a69c63306986a21ebfb6e4 # docking-latest + GIT_TAG 72ebd91567148b4d3dca073c7229c4c0462a0586 # Branch: docking, date: 05.10.2023, 15:10 GMT+2 ) add_subdirectory(imgui) FetchContent_Declare( SDL2 GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" - GIT_TAG release-2.26.1 + GIT_TAG release-2.28.4 ) add_subdirectory(sdl) FetchContent_Declare( spdlog GIT_REPOSITORY "https://github.com/gabime/spdlog.git" - GIT_TAG v1.11.0 + GIT_TAG v1.12.0 ) add_subdirectory(spdlog) diff --git a/vendor/doctest/CMakeLists.txt b/vendor/doctest/CMakeLists.txt index 2afc2a6..7016f17 100644 --- a/vendor/doctest/CMakeLists.txt +++ b/vendor/doctest/CMakeLists.txt @@ -1,3 +1,5 @@ message(STATUS "Fetching Doctest ...") +set(DOCTEST_NO_INSTALL ON) + FetchContent_MakeAvailable(doctest) diff --git a/vendor/fmt/CMakeLists.txt b/vendor/fmt/CMakeLists.txt index 9fffb7b..3dafef0 100644 --- a/vendor/fmt/CMakeLists.txt +++ b/vendor/fmt/CMakeLists.txt @@ -1,3 +1,5 @@ message(STATUS "Fetching fmt ...") +option(FMT_INSTALL "Enable installation for the {fmt} project." OFF) + FetchContent_MakeAvailable(fmt) diff --git a/vendor/imgui/CMakeLists.txt b/vendor/imgui/CMakeLists.txt index de997b0..502a96f 100644 --- a/vendor/imgui/CMakeLists.txt +++ b/vendor/imgui/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(imgui ${imgui_SOURCE_DIR}/imgui_tables.cpp ${imgui_SOURCE_DIR}/imgui_widgets.cpp ${imgui_SOURCE_DIR}/imstb_rectpack.h ${imgui_SOURCE_DIR}/imstb_textedit.h ${imgui_SOURCE_DIR}/imstb_truetype.h - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl.cpp + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp) target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) diff --git a/vendor/sdl/CMakeLists.txt b/vendor/sdl/CMakeLists.txt index 3d5006e..6ddfa32 100644 --- a/vendor/sdl/CMakeLists.txt +++ b/vendor/sdl/CMakeLists.txt @@ -1,3 +1,5 @@ message(STATUS "Fetching SDL ...") +option(SDL2_DISABLE_SDL2MAIN "Disable building/installation of SDL2main" ON) + FetchContent_MakeAvailable(SDL2)