diff options
author | Vittorio Romeo <vittorio.romeo@outlook.com> | 2021-11-13 18:55:13 +0000 |
---|---|---|
committer | Vittorio Romeo <vittorio.romeo@outlook.com> | 2021-11-13 18:55:13 +0000 |
commit | e18e22136dd4d6bdde01214cca4acd89bcb4bcba (patch) | |
tree | 8af5c58e30eaf434b0cdae0a978db30809eaa455 | |
parent | 1df43347263193b82acb24626a1c5bbc811eccfb (diff) |
Some preliminary changes for Android builds
-rwxr-xr-x | .gitignore | bin | 3503 -> 3518 bytes | |||
-rw-r--r-- | CMakeLists.txt | 169 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Core/HexagonClient.hpp | 2 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Global/Imgui.hpp | 22 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Global/PCH.hpp | 2 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/Discord.cpp | 39 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/HGGraphics.cpp | 10 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/HGUpdate.cpp | 6 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/HexagonGame.cpp | 14 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/Steam.cpp | 116 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/main.cpp | 10 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Global/Imgui.cpp | 64 |
12 files changed, 367 insertions, 87 deletions
Binary files differ diff --git a/CMakeLists.txt b/CMakeLists.txt index 89322263..9ed4fd34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,21 @@ cmake_minimum_required(VERSION 3.9) # # # ----------------------------------------------------------------------------- +# Android build +# ----------------------------------------------------------------------------- + +string(TOLOWER "${CMAKE_SYSTEM_NAME}" SSVOH_SYSTEM_NAME_LOWERCASE) + +if(SSVOH_SYSTEM_NAME_LOWERCASE STREQUAL "android") + set(SSVOH_ANDROID TRUE) + add_definitions(-DSSVOH_ANDROID) +else() + set(SSVOH_ANDROID FALSE) +endif() + +# +# +# ----------------------------------------------------------------------------- # Colored output # ----------------------------------------------------------------------------- @@ -125,22 +140,24 @@ file(WRITE "${zlib_SOURCE_DIR}/CMakeLists.txt" "${STRIPPED1}") # CPM: imgui # ----------------------------------------------------------------------------- -CPMAddPackage( - NAME imgui - GITHUB_REPOSITORY ocornut/imgui - GIT_TAG 19c3773cc09fffdf950c3e88273f0a15adad1176 - DOWNLOAD_ONLY YES -) +if(NOT SSVOH_ANDROID) + CPMAddPackage( + NAME imgui + GITHUB_REPOSITORY ocornut/imgui + GIT_TAG 19c3773cc09fffdf950c3e88273f0a15adad1176 + DOWNLOAD_ONLY YES + ) -if (imgui_ADDED) - # imgui has no CMake support, so we create our own target + if (imgui_ADDED) + # imgui has no CMake support, so we create our own target - FILE(GLOB imgui_sources ${imgui_SOURCE_DIR}/*.cpp) - FILE(GLOB imgui_sources_cpp ${imgui_SOURCE_DIR}/misc/cpp/*.cpp) + FILE(GLOB imgui_sources ${imgui_SOURCE_DIR}/*.cpp) + FILE(GLOB imgui_sources_cpp ${imgui_SOURCE_DIR}/misc/cpp/*.cpp) - set(IMGUI_DIR ${imgui_SOURCE_DIR}) - set(IMGUI_INCLUDE_DIR ${imgui_SOURCE_DIR}) - set(IMGUI_SOURCES ${imgui_sources} ${imgui_sources_cpp}) + set(IMGUI_DIR ${imgui_SOURCE_DIR}) + set(IMGUI_INCLUDE_DIR ${imgui_SOURCE_DIR}) + set(IMGUI_SOURCES ${imgui_sources} ${imgui_sources_cpp}) + endif() endif() # @@ -149,13 +166,15 @@ endif() # CPM: imgui-sfml # ----------------------------------------------------------------------------- -CPMAddPackage( - NAME imgui-sfml - GITHUB_REPOSITORY eliasdaler/imgui-sfml - GIT_TAG 8bc196c5eaadb342712407eb06fc2f53edfde227 - ) +if(NOT SSVOH_ANDROID) + CPMAddPackage( + NAME imgui-sfml + GITHUB_REPOSITORY eliasdaler/imgui-sfml + GIT_TAG 8bc196c5eaadb342712407eb06fc2f53edfde227 + ) -set_target_properties(ImGui-SFML PROPERTIES UNITY_BUILD ON) + set_target_properties(ImGui-SFML PROPERTIES UNITY_BUILD ON) +endif() # # @@ -361,21 +380,25 @@ set(PUBLIC_INCLUDE_DIRS "public" "public/sqlite" "public/sqlite_orm") set(SFML_LIBRARIES sfml-system sfml-window sfml-graphics sfml-audio sfml-network) -if(WIN32) - set(PUBLIC_LIBRARIES - "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/steam_api64.lib" - "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/discord_game_sdk.dll.lib" - "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/sdkencryptedappticket64.lib" - sodium - ) +if(NOT SSVOH_ANDROID) + if(WIN32) + set(PUBLIC_LIBRARIES + "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/steam_api64.lib" + "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/discord_game_sdk.dll.lib" + "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/sdkencryptedappticket64.lib" + sodium + ) + else() + set(PUBLIC_LIBRARIES + "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libsteam_api.so" + "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libdiscord_game_sdk.so" + "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libsdkencryptedappticket.so" + Xcursor + sodium + ) + endif() else() - set(PUBLIC_LIBRARIES - "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libsteam_api.so" - "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libdiscord_game_sdk.so" - "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libsdkencryptedappticket.so" - Xcursor - sodium - ) + set(PUBLIC_LIBRARIES sodium) endif() target_include_directories( @@ -384,7 +407,6 @@ target_include_directories( PUBLIC ${zlib_SOURCE_DIR} PUBLIC ${zlib_BINARY_DIR} PUBLIC ${luajit_SOURCE_DIR}/src - PUBLIC ${imgui_SOURCE_DIR} PUBLIC ${boostpfr_INCLUDE_DIR} ) @@ -393,9 +415,13 @@ target_link_libraries( libluajit zlib ${PUBLIC_LIBRARIES} - ImGui-SFML::ImGui-SFML ) +if(NOT SSVOH_ANDROID) + target_include_directories(SSVOpenHexagonLib SYSTEM PUBLIC ${imgui_SOURCE_DIR}) + target_link_libraries(SSVOpenHexagonLib ImGui-SFML::ImGui-SFML) +endif() + macro(ssvoh_find_extlib_for_target target extlib) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../${extlib}/cmake/modules/" @@ -426,8 +452,11 @@ set(SSVOH_INCLUDE_DIRECTORIES ${SFML_SOURCE_DIR}/include ${PUBLIC_INCLUDE_DIRS} ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR} - ${LUASRC} - ${imgui_SOURCE_DIR}) + ${LUASRC}) + +if(NOT SSVOH_ANDROID) + set(SSVOH_INCLUDE_DIRECTORIES "${SSVOH_INCLUDE_DIRECTORIES} ${imgui_SOURCE_DIR}") +endif() target_include_directories( SSVOpenHexagon SYSTEM PUBLIC ${SSVOH_INCLUDE_DIRECTORIES} @@ -460,29 +489,31 @@ endif() # Workshop uploader tool # ----------------------------------------------------------------------------- -if(WIN32) - set(STEAM_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/steam_api64.lib") -else() - set(STEAM_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libsteam_api.so") -endif() +if(NOT SSVOH_ANDROID) + if(WIN32) + set(STEAM_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/steam_api64.lib") + else() + set(STEAM_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/_RELEASE/libsteam_api.so") + endif() -add_executable( - OHWorkshopUploader "${CMAKE_CURRENT_SOURCE_DIR}/src/OHWorkshopUploader/main.cpp" -) + add_executable( + OHWorkshopUploader "${CMAKE_CURRENT_SOURCE_DIR}/src/OHWorkshopUploader/main.cpp" + ) -target_include_directories( - OHWorkshopUploader SYSTEM PUBLIC ${PUBLIC_INCLUDE_DIRS} -) + target_include_directories( + OHWorkshopUploader SYSTEM PUBLIC ${PUBLIC_INCLUDE_DIRS} + ) -target_link_libraries(OHWorkshopUploader ${STEAM_LIBRARIES}) + target_link_libraries(OHWorkshopUploader ${STEAM_LIBRARIES}) -if(UNIX AND NOT APPLE) - target_link_libraries(OHWorkshopUploader pthread) -endif() + if(UNIX AND NOT APPLE) + target_link_libraries(OHWorkshopUploader pthread) + endif() -install( - TARGETS OHWorkshopUploader RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/_RELEASE/ -) + install( + TARGETS OHWorkshopUploader RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/_RELEASE/ + ) +endif() # # @@ -490,23 +521,25 @@ install( # Server control tool # ----------------------------------------------------------------------------- -add_executable( - OHServerControl "${CMAKE_CURRENT_SOURCE_DIR}/src/OHServerControl/main.cpp" -) +if(NOT SSVOH_ANDROID) + add_executable( + OHServerControl "${CMAKE_CURRENT_SOURCE_DIR}/src/OHServerControl/main.cpp" + ) -target_include_directories( - OHServerControl SYSTEM PUBLIC ${SFML_SOURCE_DIR}/include -) + target_include_directories( + OHServerControl SYSTEM PUBLIC ${SFML_SOURCE_DIR}/include + ) -target_link_libraries(OHServerControl sfml-system sfml-network) + target_link_libraries(OHServerControl sfml-system sfml-network) -if(UNIX AND NOT APPLE) - target_link_libraries(OHServerControl pthread) -endif() + if(UNIX AND NOT APPLE) + target_link_libraries(OHServerControl pthread) + endif() -install( - TARGETS OHServerControl RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/_RELEASE/ -) + install( + TARGETS OHServerControl RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/_RELEASE/ + ) +endif() # # diff --git a/include/SSVOpenHexagon/Core/HexagonClient.hpp b/include/SSVOpenHexagon/Core/HexagonClient.hpp index 8b8a808d..aa758d77 100644 --- a/include/SSVOpenHexagon/Core/HexagonClient.hpp +++ b/include/SSVOpenHexagon/Core/HexagonClient.hpp @@ -22,9 +22,7 @@ #include <vector> namespace hg::Steam { - class steam_manager; - } namespace hg { diff --git a/include/SSVOpenHexagon/Global/Imgui.hpp b/include/SSVOpenHexagon/Global/Imgui.hpp new file mode 100644 index 00000000..b7c4394e --- /dev/null +++ b/include/SSVOpenHexagon/Global/Imgui.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2013-2020 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: https://opensource.org/licenses/AFL-3.0 + +#pragma once + +namespace sf { +class Event; +class RenderTarget; +class RenderWindow; +} // namespace sf + +namespace hg::Imgui { + +void initialize(sf::RenderWindow&); +void shutdown(); +[[nodiscard]] bool wantCaptureKeyboard(); +[[nodiscard]] bool wantCaptureMouse(); +void processEvent(const sf::Event&); +void render(sf::RenderTarget& renderTarget); + +} // namespace hg::Imgui diff --git a/include/SSVOpenHexagon/Global/PCH.hpp b/include/SSVOpenHexagon/Global/PCH.hpp index 6a28abc3..98a8404f 100644 --- a/include/SSVOpenHexagon/Global/PCH.hpp +++ b/include/SSVOpenHexagon/Global/PCH.hpp @@ -45,9 +45,11 @@ #include <sodium.h> +#ifndef SSVOH_ANDROID #include <imgui.h> #include <imgui-SFML.h> #include <misc/cpp/imgui_stdlib.h> +#endif #include <sqlite3.h> #include <sqlite_orm.h> diff --git a/src/SSVOpenHexagon/Core/Discord.cpp b/src/SSVOpenHexagon/Core/Discord.cpp index ba264e4c..ee3a50c8 100644 --- a/src/SSVOpenHexagon/Core/Discord.cpp +++ b/src/SSVOpenHexagon/Core/Discord.cpp @@ -9,7 +9,11 @@ #include <cstdint>
#include <chrono>
+#ifndef SSVOH_ANDROID
#include "discord/discord.h"
+#endif
+
+#ifndef SSVOH_ANDROID
namespace hg::Discord {
@@ -179,3 +183,38 @@ bool discord_manager::set_rich_presence_in_game( }
} // namespace hg::Discord
+
+#else
+
+namespace hg::Discord {
+
+discord_manager::discord_manager() : _core{nullptr}, _initialized{false}
+{}
+
+discord_manager::~discord_manager()
+{}
+
+bool discord_manager::run_callbacks()
+{
+ return false;
+}
+
+bool discord_manager::set_rich_presence_in_menu()
+{
+ return false;
+}
+
+bool discord_manager::set_rich_presence_on_replay()
+{
+ return false;
+}
+
+bool discord_manager::set_rich_presence_in_game(
+ const std::string& level_info, const std::string& second_info, bool dead)
+{
+ return false;
+}
+
+} // namespace hg::Discord
+
+#endif
diff --git a/src/SSVOpenHexagon/Core/HGGraphics.cpp b/src/SSVOpenHexagon/Core/HGGraphics.cpp index ae1e085d..6c086cb3 100644 --- a/src/SSVOpenHexagon/Core/HGGraphics.cpp +++ b/src/SSVOpenHexagon/Core/HGGraphics.cpp @@ -4,16 +4,18 @@ #include "SSVOpenHexagon/Core/HexagonGame.hpp" +#include "SSVOpenHexagon/Components/CWall.hpp" + #include "SSVOpenHexagon/Global/Assert.hpp" #include "SSVOpenHexagon/Global/Config.hpp" +#include "SSVOpenHexagon/Global/Imgui.hpp" + #include "SSVOpenHexagon/Utils/String.hpp" #include "SSVOpenHexagon/Utils/Color.hpp" -#include "SSVOpenHexagon/Components/CWall.hpp" + #include "SSVStart/Utils/SFML.hpp" #include <SFML/Config.hpp> -#include <imgui.h> -#include <imgui-SFML.h> #include <SSVStart/Utils/Vector2.hpp> #include <SSVStart/Utils/SFML.hpp> @@ -293,7 +295,7 @@ void HexagonGame::drawImguiLuaConsole() SSVOH_ASSERT(overlayCamera.has_value()); overlayCamera->unapply(); - ImGui::SFML::Render(*window); + Imgui::render(*window); } void HexagonGame::initFlashEffect(int r, int g, int b) diff --git a/src/SSVOpenHexagon/Core/HGUpdate.cpp b/src/SSVOpenHexagon/Core/HGUpdate.cpp index bf742ffb..995e9e09 100644 --- a/src/SSVOpenHexagon/Core/HGUpdate.cpp +++ b/src/SSVOpenHexagon/Core/HGUpdate.cpp @@ -24,9 +24,11 @@ #include "SSVOpenHexagon/Core/LuaScripting.hpp" #include "SSVOpenHexagon/Core/Steam.hpp" +#ifndef SSVOH_ANDROID #include <imgui.h> #include <misc/cpp/imgui_stdlib.h> #include <imgui-SFML.h> +#endif #include <SSVStart/Utils/Vector2.hpp> @@ -1014,6 +1016,7 @@ static int Strnicmp(const char* s1, const char* s2, int n) int HexagonGame::ilcTextEditCallback(ImGuiInputTextCallbackData* data) { +#ifndef SSVOH_ANDROID switch(data->EventFlag) { case ImGuiInputTextFlags_CallbackCompletion: @@ -1144,12 +1147,14 @@ int HexagonGame::ilcTextEditCallback(ImGuiInputTextCallbackData* data) } } } +#endif return 0; } void HexagonGame::postUpdate_ImguiLuaConsole() { +#ifndef SSVOH_ANDROID if(window == nullptr) { return; @@ -1499,6 +1504,7 @@ void HexagonGame::postUpdate_ImguiLuaConsole() } ImGui::End(); +#endif } void HexagonGame::postUpdate() diff --git a/src/SSVOpenHexagon/Core/HexagonGame.cpp b/src/SSVOpenHexagon/Core/HexagonGame.cpp index f6d99a90..eb08cca6 100644 --- a/src/SSVOpenHexagon/Core/HexagonGame.cpp +++ b/src/SSVOpenHexagon/Core/HexagonGame.cpp @@ -5,24 +5,25 @@ #include "SSVOpenHexagon/Core/HexagonGame.hpp" #include "SSVOpenHexagon/Components/CWall.hpp" + #include "SSVOpenHexagon/Global/Assert.hpp" #include "SSVOpenHexagon/Global/Assets.hpp" #include "SSVOpenHexagon/Global/Audio.hpp" #include "SSVOpenHexagon/Global/Config.hpp" +#include "SSVOpenHexagon/Global/Imgui.hpp" + #include "SSVOpenHexagon/Core/HexagonClient.hpp" #include "SSVOpenHexagon/Core/Joystick.hpp" #include "SSVOpenHexagon/Core/Steam.hpp" #include "SSVOpenHexagon/Core/Discord.hpp" #include "SSVOpenHexagon/Core/Discord.hpp" + #include "SSVOpenHexagon/Utils/Utils.hpp" #include "SSVOpenHexagon/Utils/Concat.hpp" #include "SSVOpenHexagon/Utils/LevelValidator.hpp" #include "SSVOpenHexagon/Utils/LuaWrapper.hpp" #include "SSVOpenHexagon/Utils/String.hpp" -#include <imgui.h> -#include <imgui-SFML.h> - #include <SSVStart/Utils/Input.hpp> #include <SSVStart/Utils/Vector2.hpp> #include <SSVStart/Utils/SFML.hpp> @@ -260,8 +261,8 @@ void HexagonGame::nameFormat(std::string& name) [[nodiscard]] bool HexagonGame::imguiLuaConsoleHasInput() { - return ilcShowConsole && (ImGui::GetIO().WantCaptureKeyboard || - ImGui::GetIO().WantCaptureMouse); + return ilcShowConsole && + (Imgui::wantCaptureKeyboard() || Imgui::wantCaptureMouse()); } [[nodiscard]] static sf::Text initText( @@ -326,8 +327,7 @@ HexagonGame::HexagonGame(Steam::steam_manager* mSteamManager, game.onDraw += [this] { draw(); }; - game.onAnyEvent += - [](const sf::Event& event) { ImGui::SFML::ProcessEvent(event); }; + game.onAnyEvent += Imgui::processEvent; if(window != nullptr) { diff --git a/src/SSVOpenHexagon/Core/Steam.cpp b/src/SSVOpenHexagon/Core/Steam.cpp index 2ceb4fa2..7bff541f 100644 --- a/src/SSVOpenHexagon/Core/Steam.cpp +++ b/src/SSVOpenHexagon/Core/Steam.cpp @@ -11,9 +11,12 @@ #include <SSVUtils/Core/Log/Log.hpp> #include <stdint.h> // Steam API needs this. + +#ifndef SSVOH_ANDROID #include "steam/steam_api.h" #include "steam/steam_api_flat.h" #include "steam/steamencryptedappticket.h" +#endif #include <array> #include <charconv> @@ -25,6 +28,8 @@ #include <string> #include <unordered_set> +#ifndef SSVOH_ANDROID + namespace hg::Steam { [[nodiscard]] static std::optional<CSteamID> get_user_steam_id() @@ -840,7 +845,6 @@ steam_manager::steam_manager_impl::get_ticket_steam_id() const noexcept // ---------------------------------------------------------------------------- - [[nodiscard]] const steam_manager::steam_manager_impl& steam_manager::impl() const noexcept { @@ -947,3 +951,113 @@ steam_manager::get_ticket_steam_id() const noexcept } } // namespace hg::Steam + +#else + +namespace hg::Steam + + [[nodiscard]] const steam_manager::steam_manager_impl& + steam_manager::impl() const noexcept +{ + SSVOH_ASSERT(false); + return nullptr; +} + +[[nodiscard]] steam_manager::steam_manager_impl& steam_manager::impl() noexcept +{ + SSVOH_ASSERT(false); + return nullptr; +} + +steam_manager::steam_manager() : _impl{nullptr} +{} + +steam_manager::~steam_manager() = default; + +[[nodiscard]] bool steam_manager::is_initialized() const noexcept +{ + return false; +} + +bool steam_manager::request_stats_and_achievements() +{ + return false; +} + +bool steam_manager::run_callbacks() +{ + return false; +} + +bool steam_manager::store_stats() +{ + return false; +} + +bool steam_manager::unlock_achievement(std::string_view name) +{ + return false; +} + +bool steam_manager::set_rich_presence_in_menu() +{ + return false; +} + +bool steam_manager::set_rich_presence_in_game( + std::string_view level_name_format, std::string_view difficulty_mult_format, + std::string_view time_format) +{ + return false; +} + +bool steam_manager::set_and_store_stat(std::string_view name, int data) +{ + return false; +} + +[[nodiscard]] bool steam_manager::get_achievement( + bool* out, std::string_view name) +{ + return false; +} + +[[nodiscard]] bool steam_manager::get_stat(int* out, std::string_view name) +{ + return false; +} + +bool steam_manager::update_hardcoded_achievements() +{ + return false; +} + +void steam_manager::for_workshop_pack_folders( + const std::function<void(const std::string&)>& f) const +{} + +bool steam_manager::request_encrypted_app_ticket() +{ + return false; +} + +[[nodiscard]] bool +steam_manager::got_encrypted_app_ticket_response() const noexcept +{ + return false; +} + +[[nodiscard]] bool steam_manager::got_encrypted_app_ticket() const noexcept +{ + return false; +} + +[[nodiscard]] std::optional<std::uint64_t> +steam_manager::get_ticket_steam_id() const noexcept +{ + return std::nullopt; +} + +} // namespace hg::Steam + +#endif diff --git a/src/SSVOpenHexagon/Core/main.cpp b/src/SSVOpenHexagon/Core/main.cpp index 297193a1..b32f677f 100644 --- a/src/SSVOpenHexagon/Core/main.cpp +++ b/src/SSVOpenHexagon/Core/main.cpp @@ -9,20 +9,20 @@ #include "SSVOpenHexagon/Core/Steam.hpp" #include "SSVOpenHexagon/Core/Discord.hpp" #include "SSVOpenHexagon/Core/Replay.hpp" + #include "SSVOpenHexagon/Global/Assets.hpp" #include "SSVOpenHexagon/Global/Audio.hpp" #include "SSVOpenHexagon/Global/Assert.hpp" #include "SSVOpenHexagon/Global/Config.hpp" +#include "SSVOpenHexagon/Global/Imgui.hpp" #include "SSVOpenHexagon/Global/Version.hpp" + #include "SSVOpenHexagon/Utils/Concat.hpp" #include "SSVOpenHexagon/Utils/ScopeGuard.hpp" #include "SSVOpenHexagon/Utils/VectorToSet.hpp" #include <sodium.h> -#include <imgui.h> -#include <imgui-SFML.h> - #include <SSVStart/GameSystem/GameWindow.hpp> #include <SSVUtils/Core/Log/Log.hpp> @@ -344,7 +344,7 @@ getFirstCompressedReplayFilenameFromArgs(const std::vector<std::string>& args) if(!headless) { SSVOH_ASSERT(window.has_value()); - ImGui::SFML::Init(*window); + hg::Imgui::initialize(*window); } HG_SCOPE_GUARD({ @@ -352,7 +352,7 @@ getFirstCompressedReplayFilenameFromArgs(const std::vector<std::string>& args) if(!headless) { - ImGui::SFML::Shutdown(); + hg::Imgui::shutdown(); } ssvu::lo("::main") << "Done shutting down ImGui...\n"; diff --git a/src/SSVOpenHexagon/Global/Imgui.cpp b/src/SSVOpenHexagon/Global/Imgui.cpp new file mode 100644 index 00000000..2c6833f7 --- /dev/null +++ b/src/SSVOpenHexagon/Global/Imgui.cpp @@ -0,0 +1,64 @@ +// Copyright (c) 2013-2020 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: https://opensource.org/licenses/AFL-3.0 + +#include "SSVOpenHexagon/Global/Imgui.hpp" + +#ifndef SSVOH_ANDROID +#include <imgui.h> +#include <misc/cpp/imgui_stdlib.h> +#include <imgui-SFML.h> +#endif + +#include <SFML/Graphics.hpp> +#include <SFML/Window.hpp> + +namespace hg::Imgui { + +void initialize(sf::RenderWindow& window) +{ +#ifndef SSVOH_ANDROID + ImGui::SFML::Init(window); +#endif +} + +void shutdown() +{ +#ifndef SSVOH_ANDROID + ImGui::SFML::Shutdown(); +#endif +} + +[[nodiscard]] bool wantCaptureKeyboard() +{ +#ifndef SSVOH_ANDROID + return ImGui::GetIO().WantCaptureKeyboard; +#else + return false; +#endif +} + +[[nodiscard]] bool wantCaptureMouse() +{ +#ifndef SSVOH_ANDROID + return ImGui::GetIO().WantCaptureMouse; +#else + return false; +#endif +} + +void processEvent(const sf::Event& event) +{ +#ifndef SSVOH_ANDROID + ImGui::SFML::ProcessEvent(event); +#endif +} + +void render(sf::RenderTarget& renderTarget) +{ +#ifndef SSVOH_ANDROID + ImGui::SFML::Render(renderTarget); +#endif +} + +} // namespace hg::Imgui |