Basic DPI scaling hack.

This commit is contained in:
Henrik Rydgard 2012-05-14 22:07:40 +02:00
parent e8ccae2266
commit e7bf0303e2
4 changed files with 19 additions and 5 deletions

View file

@ -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];

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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);