From e7bf0303e240c66780e455ec32a654301b53d0e1 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Mon, 14 May 2012 22:07:40 +0200 Subject: [PATCH] Basic DPI scaling hack. --- android/app-android.cpp | 15 +++++++++++---- .../src/com/turboviking/libnative/NativeApp.java | 2 +- base/colorutil.cpp | 6 ++++++ base/colorutil.h | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/android/app-android.cpp b/android/app-android.cpp index 5e7920d5fc..578a72fbef 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -22,8 +22,8 @@ #include "audio/mixer.h" #include "math/math_util.h" -#define coord_xres 800 -#define coord_yres 480 +#define coord_xres 480 +#define coord_yres 800 static JNIEnv *jniEnvUI; @@ -98,6 +98,13 @@ extern "C" void Java_com_turboviking_libnative_NativeApp_init yres = yyres; g_xres = xres; g_yres = yres; + + if (g_xres < g_yres) + { + // Portrait - let's force the imaginary resolution we want + g_xres = coord_xres; + g_yres = coord_yres; + } xscale = (float)coord_xres / xres; yscale = (float)coord_yres / yres; memset(&input_state, 0, sizeof(input_state)); @@ -211,8 +218,8 @@ extern "C" void JNICALL Java_com_turboviking_libnative_NativeApp_touch return; // We ignore 8+ pointers entirely. } - input_state.mouse_x[pointerId] = (int)x; - input_state.mouse_y[pointerId] = (int)y; + input_state.mouse_x[pointerId] = (int)(x * xscale); + input_state.mouse_y[pointerId] = (int)(y * yscale); if (code == 1) { //ILOG("Down: %i %f %f", pointerId, x, y); input_state.mouse_last[pointerId] = input_state.mouse_down[pointerId]; diff --git a/android/src/com/turboviking/libnative/NativeApp.java b/android/src/com/turboviking/libnative/NativeApp.java index b15e981451..8b5e81b097 100644 --- a/android/src/com/turboviking/libnative/NativeApp.java +++ b/android/src/com/turboviking/libnative/NativeApp.java @@ -16,4 +16,4 @@ public class NativeApp { // Sensor/input data. These are asynchronous, beware! public static native void touch(float x, float y, int data, int pointerId); public static native void accelerometer(float x, float y, float z); -} \ No newline at end of file +} \ No newline at end of file diff --git a/base/colorutil.cpp b/base/colorutil.cpp index 12e1d1755e..9152d78a3d 100644 --- a/base/colorutil.cpp +++ b/base/colorutil.cpp @@ -14,6 +14,12 @@ uint32_t blackAlpha(float alpha) { return (int)(alpha*255)<<24; } +uint32_t colorAlpha(uint32_t color, float alpha) { + if (alpha < 0.0f) alpha = 0.0f; + if (alpha > 1.0f) alpha = 1.0f; + return ((int)(alpha*255)<<24) | (color & 0xFFFFFF); +} + uint32_t rgba(float r, float g, float b, float alpha) { uint32_t color = (int)(alpha*255)<<24; color |= (int)(b*255)<<16; diff --git a/base/colorutil.h b/base/colorutil.h index 005b4190bd..41f5a94ba7 100644 --- a/base/colorutil.h +++ b/base/colorutil.h @@ -4,6 +4,7 @@ uint32_t whiteAlpha(float alpha); uint32_t blackAlpha(float alpha); +uint32_t colorAlpha(uint32_t color, float alpha); uint32_t rgba(float r, float g, float b, float alpha); uint32_t rgba_clamp(float r, float g, float b, float alpha); uint32_t hsva(float h, float s, float v, float alpha); \ No newline at end of file