From 95e9c270db785f64e3198c879d4ea94aaa6da243 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 4 Nov 2021 17:42:31 +0100 Subject: [PATCH] fix: changed android defines --- include/render/GL.h | 2 +- include/render/gui/imgui/imconfig.h | 2 +- src/TowerDefense.cpp | 2 +- src/render/gui/TowerGui.cpp | 5 ++++- src/render/gui/imgui/imgui_filebrowser.cpp | 21 ++++++++++++++++++++- src/render/shaders/EntityShader.cpp | 2 +- src/render/shaders/ShaderProgram.cpp | 4 ++-- src/render/shaders/WorldShader.cpp | 2 +- src/window/Display.cpp | 17 +++++++++++++++-- 9 files changed, 46 insertions(+), 11 deletions(-) diff --git a/include/render/GL.h b/include/render/GL.h index 9927b6d..cd5ece2 100644 --- a/include/render/GL.h +++ b/include/render/GL.h @@ -1,6 +1,6 @@ #pragma once -#ifdef ANDROID +#ifdef __ANDROID__ #include #else #include "glbinding/gl/gl.h" diff --git a/include/render/gui/imgui/imconfig.h b/include/render/gui/imgui/imconfig.h index 9504348..dcce46c 100755 --- a/include/render/gui/imgui/imconfig.h +++ b/include/render/gui/imgui/imconfig.h @@ -107,7 +107,7 @@ namespace ImGui } */ -#ifdef ANDROID +#ifdef __ANDROID__ #define IMGUI_IMPL_OPENGL_ES3 #else #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2 diff --git a/src/TowerDefense.cpp b/src/TowerDefense.cpp index b726b0d..0ed4722 100644 --- a/src/TowerDefense.cpp +++ b/src/TowerDefense.cpp @@ -21,7 +21,7 @@ int main(int argc, const char* args[]) { return 0; } -#ifdef ANDROID +#ifdef __ANDROID__ extern "C" { int SDL_main(int argc, const char* args[]) { return main(argc, args); diff --git a/src/render/gui/TowerGui.cpp b/src/render/gui/TowerGui.cpp index 29aa6b2..fb75713 100644 --- a/src/render/gui/TowerGui.cpp +++ b/src/render/gui/TowerGui.cpp @@ -29,7 +29,7 @@ static std::unique_ptr gameMenu; static std::unique_ptr frameMenu; -void initWidgets(){ +void initWidgets() { mainMenu = std::make_unique(client.get()); gameMenu = std::make_unique(client.get()); frameMenu = std::make_unique(client.get()); @@ -73,9 +73,11 @@ void tick() { lastTime = td::utils::getTime(); } + void render() { tick(); beginFrame(); + client->render(); if (client->isConnected()) gameMenu->render(); @@ -85,6 +87,7 @@ void render() { if (demo_open) ImGui::ShowDemoWindow(&demo_open); frameMenu->render(); + endFrame(); } diff --git a/src/render/gui/imgui/imgui_filebrowser.cpp b/src/render/gui/imgui/imgui_filebrowser.cpp index e575fdc..509a3be 100644 --- a/src/render/gui/imgui/imgui_filebrowser.cpp +++ b/src/render/gui/imgui/imgui_filebrowser.cpp @@ -21,7 +21,7 @@ #include "Dirent/dirent.h" #include #else -#include "dirent.h" +#include #endif // defined (WIN32) || defined (_WIN32) namespace imgui_addons @@ -1156,6 +1156,23 @@ namespace imgui_addons if(path_max_def) buffer = new char[PATH_MAX]; + #ifdef __ANDROID__ + + char* real_path = realpath("/storage/emulated/0/Download", buffer); + if (real_path == nullptr) + { + current_path = "/storage/emulated/0/Download"; + current_dirlist.push_back("/storage/emulated/0/Download"); + } + else + { + current_path = std::string(real_path); + current_path += "/"; + parsePathTabs(current_path); + } + + #else + char* real_path = realpath("./", buffer); if (real_path == nullptr) { @@ -1169,6 +1186,8 @@ namespace imgui_addons parsePathTabs(current_path); } + #endif + if(path_max_def) delete[] buffer; else diff --git a/src/render/shaders/EntityShader.cpp b/src/render/shaders/EntityShader.cpp index cb82ba9..841ec1f 100644 --- a/src/render/shaders/EntityShader.cpp +++ b/src/render/shaders/EntityShader.cpp @@ -7,7 +7,7 @@ #include "render/shaders/EntityShader.h" -#ifdef ANDROID +#ifdef __ANDROID__ static const char vertexSource[] = R"(#version 300 es diff --git a/src/render/shaders/ShaderProgram.cpp b/src/render/shaders/ShaderProgram.cpp index b9352e1..255eb8d 100755 --- a/src/render/shaders/ShaderProgram.cpp +++ b/src/render/shaders/ShaderProgram.cpp @@ -12,7 +12,7 @@ #include -#ifdef ANDROID +#ifdef __ANDROID__ #include #endif @@ -116,7 +116,7 @@ int ShaderProgram::loadShader(const std::string& source, GLenum type) { char error[size]; glGetShaderInfoLog(shaderID, size, &size, error); std::cout << error << std::endl; - #ifdef ANDROID + #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_ERROR, "TRACKERS", "Could not compile shader !\n %s", error); #endif } diff --git a/src/render/shaders/WorldShader.cpp b/src/render/shaders/WorldShader.cpp index add7e23..25d6f50 100644 --- a/src/render/shaders/WorldShader.cpp +++ b/src/render/shaders/WorldShader.cpp @@ -7,7 +7,7 @@ #include "render/shaders/WorldShader.h" -#ifdef ANDROID +#ifdef __ANDROID__ static const char vertexSource[] = R"(#version 300 es diff --git a/src/window/Display.cpp b/src/window/Display.cpp index bc8e06c..ebca0d7 100644 --- a/src/window/Display.cpp +++ b/src/window/Display.cpp @@ -22,7 +22,7 @@ #include -#ifdef ANDROID +#ifdef __ANDROID__ #include #include #endif @@ -49,7 +49,7 @@ void windowResizeEvent(int width, int height) { bool create() { window = SDL_CreateWindow(WINDOW_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); // Prepare and create context -#ifdef ANDROID +#ifdef __ANDROID__ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); @@ -151,6 +151,19 @@ void pollEvents() { } ImGui_ImplSDL2_ProcessEvent(&event); } + +// activating screen keyboard for Android devices +#ifdef __ANDROID__ + static bool keyboardShown = false; + if(ImGui::GetIO().WantTextInput != keyboardShown){ + if(ImGui::GetIO().WantTextInput){ + SDL_StartTextInput(); + }else{ + SDL_StopTextInput(); + } + keyboardShown = ImGui::GetIO().WantTextInput; + } +#endif } bool isCloseRequested() {