Scale text overlay based on Android display DPI
This commit is contained in:
parent
82521aaafb
commit
8b6cdf4e95
3 changed files with 33 additions and 0 deletions
|
|
@ -22,6 +22,10 @@
|
||||||
#include "VulkanBuffer.hpp"
|
#include "VulkanBuffer.hpp"
|
||||||
#include "VulkanDevice.hpp"
|
#include "VulkanDevice.hpp"
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#include "vulkanandroid.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../external/stb/stb_font_consolas_24_latin1.inl"
|
#include "../external/stb/stb_font_consolas_24_latin1.inl"
|
||||||
|
|
||||||
// Defines for the STB font used
|
// Defines for the STB font used
|
||||||
|
|
@ -116,6 +120,23 @@ public:
|
||||||
this->frameBufferWidth = framebufferwidth;
|
this->frameBufferWidth = framebufferwidth;
|
||||||
this->frameBufferHeight = framebufferheight;
|
this->frameBufferHeight = framebufferheight;
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
// Scale text on Android devices with high DPI
|
||||||
|
int32_t screenDensity = vks::android::getScreenDensity();
|
||||||
|
if (screenDensity >= ACONFIGURATION_DENSITY_XXHIGH) {
|
||||||
|
LOGD("XXHIGH");
|
||||||
|
scale = 2.0f;
|
||||||
|
}
|
||||||
|
else if (screenDensity >= ACONFIGURATION_DENSITY_XHIGH) {
|
||||||
|
LOGD("XHIGH");
|
||||||
|
scale = 1.5f;
|
||||||
|
}
|
||||||
|
else if (screenDensity >= ACONFIGURATION_DENSITY_HIGH) {
|
||||||
|
LOGD("HIGH");
|
||||||
|
scale = 1.25f;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
cmdBuffers.resize(framebuffers.size());
|
cmdBuffers.resize(framebuffers.size());
|
||||||
prepareResources();
|
prepareResources();
|
||||||
prepareRenderPass();
|
prepareRenderPass();
|
||||||
|
|
|
||||||
|
|
@ -281,6 +281,15 @@ namespace vks
|
||||||
{
|
{
|
||||||
dlclose(libVulkan);
|
dlclose(libVulkan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t getScreenDensity()
|
||||||
|
{
|
||||||
|
AConfiguration* config = AConfiguration_new();
|
||||||
|
AConfiguration_fromAssetManager(config, androidApp->activity->assetManager);
|
||||||
|
int32_t density = AConfiguration_getDensity(config);
|
||||||
|
AConfiguration_delete(config);
|
||||||
|
return density;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <android_native_app_glue.h>
|
#include <android_native_app_glue.h>
|
||||||
|
#include <android/configuration.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// Missing from the NDK
|
// Missing from the NDK
|
||||||
|
|
@ -158,6 +159,8 @@ namespace vks
|
||||||
bool loadVulkanLibrary();
|
bool loadVulkanLibrary();
|
||||||
void loadVulkanFunctions(VkInstance instance);
|
void loadVulkanFunctions(VkInstance instance);
|
||||||
void freeVulkanLibrary();
|
void freeVulkanLibrary();
|
||||||
|
/** @brief Returns the density of the device screen (in DPI) */
|
||||||
|
int32_t getScreenDensity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue