From 2b99a488d3a253b40b1472145344028e61551a59 Mon Sep 17 00:00:00 2001 From: Jairo Luiz Date: Thu, 23 Jan 2014 18:44:06 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Expose=20Android=20Display=20Metrics=20to?= =?UTF-8?q?=20L=C3=B6ve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jni/love/Android.mk | 4 +- jni/love/src/common/config.h | 1 + jni/love/src/common/types.h | 6 ++ jni/love/src/modules/android/Android.cpp | 43 ++++++++ jni/love/src/modules/android/Android.h | 63 +++++++++++ .../src/modules/android/DisplayMetrics.cpp | 88 +++++++++++++++ jni/love/src/modules/android/DisplayMetrics.h | 98 +++++++++++++++++ jni/love/src/modules/android/wrap_Android.cpp | 75 +++++++++++++ jni/love/src/modules/android/wrap_Android.h | 40 +++++++ .../modules/android/wrap_DisplayMetrics.cpp | 100 ++++++++++++++++++ .../src/modules/android/wrap_DisplayMetrics.h | 45 ++++++++ jni/love/src/modules/love/love.cpp | 6 ++ jni/love/src/scripts/boot.lua | 2 + jni/love/src/scripts/boot.lua.h | 28 +---- src/org/love2d/android/GameActivity.java | 15 +++ 15 files changed, 588 insertions(+), 26 deletions(-) create mode 100644 jni/love/src/modules/android/Android.cpp create mode 100644 jni/love/src/modules/android/Android.h create mode 100644 jni/love/src/modules/android/DisplayMetrics.cpp create mode 100644 jni/love/src/modules/android/DisplayMetrics.h create mode 100644 jni/love/src/modules/android/wrap_Android.cpp create mode 100644 jni/love/src/modules/android/wrap_Android.h create mode 100644 jni/love/src/modules/android/wrap_DisplayMetrics.cpp create mode 100644 jni/love/src/modules/android/wrap_DisplayMetrics.h diff --git a/jni/love/Android.mk b/jni/love/Android.mk index 0df5896b..d392f10f 100644 --- a/jni/love/Android.mk +++ b/jni/love/Android.mk @@ -16,6 +16,7 @@ LOCAL_C_INCLUDES := \ ${LOCAL_PATH}/src/libraries/ \ ${LOCAL_PATH}/src/libraries/enet/libenet/include \ ${LOCAL_PATH}/../SDL2-2.0.1/include \ + ${LOCAL_PATH}/../SDL2-2.0.1/src \ ${LOCAL_PATH}/../devil-1.7.8/include \ ${LOCAL_PATH}/../devil-1.7.8/src-IL/include \ ${LOCAL_PATH}/../jasper-1.900.1/src/libjasper/include \ @@ -42,7 +43,8 @@ LOCAL_SRC_FILES := \ ,$(subst $(LOCAL_PATH)/,,\ $(wildcard ${LOCAL_PATH}/src/love.cpp) \ $(wildcard ${LOCAL_PATH}/src/common/*.cpp) \ - $(wildcard ${LOCAL_PATH}/src/modules/audio/*.cpp) \ + $(wildcard ${LOCAL_PATH}/src/modules/android/*.cpp) \ + $(wildcard ${LOCAL_PATH}/src/modules/audio/*.cpp) \ $(wildcard ${LOCAL_PATH}/src/modules/audio/null/*.cpp) \ $(wildcard ${LOCAL_PATH}/src/modules/audio/openal/*.cpp) \ $(wildcard ${LOCAL_PATH}/src/modules/event/*.cpp) \ diff --git a/jni/love/src/common/config.h b/jni/love/src/common/config.h index f4959831..7f946525 100644 --- a/jni/love/src/common/config.h +++ b/jni/love/src/common/config.h @@ -90,6 +90,7 @@ # define LOVE_LITTLE_ENDIAN 1 # endif #else +# define LOVE_ENABLE_ANDROID # define LOVE_ENABLE_AUDIO # define LOVE_ENABLE_AUDIO_NULL # define LOVE_ENABLE_AUDIO_OPENAL diff --git a/jni/love/src/common/types.h b/jni/love/src/common/types.h index e9319ea5..60292a41 100644 --- a/jni/love/src/common/types.h +++ b/jni/love/src/common/types.h @@ -35,6 +35,9 @@ enum Type DATA_ID, MODULE_ID, + // Android + ANDROID_DISPLAY_METRICS_ID, + // Filesystem. FILESYSTEM_FILE_ID, FILESYSTEM_FILE_DATA_ID, @@ -121,6 +124,9 @@ const bits OBJECT_T = bits(1) << OBJECT_ID; const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T; const bits MODULE_T = (bits(1) << MODULE_ID) | OBJECT_T; +// Android +const bits ANDROID_DISPLAY_METRICS_T = (bits(1) << ANDROID_DISPLAY_METRICS_ID) | OBJECT_T; + // Filesystem. const bits FILESYSTEM_FILE_T = (bits(1) << FILESYSTEM_FILE_ID) | OBJECT_T; const bits FILESYSTEM_FILE_DATA_T = (bits(1) << FILESYSTEM_FILE_DATA_ID) | DATA_T; diff --git a/jni/love/src/modules/android/Android.cpp b/jni/love/src/modules/android/Android.cpp new file mode 100644 index 00000000..8a046de8 --- /dev/null +++ b/jni/love/src/modules/android/Android.cpp @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#include "Android.h" + +namespace love +{ +namespace android +{ + +DisplayMetrics* Android::getDisplayMetrics() +{ + if (metrics == NULL) + { + metrics = new DisplayMetrics(); + } + return metrics; +} + +const char *Android::getName() const +{ + return "love.android"; +} + +} // android +} // love diff --git a/jni/love/src/modules/android/Android.h b/jni/love/src/modules/android/Android.h new file mode 100644 index 00000000..45170a41 --- /dev/null +++ b/jni/love/src/modules/android/Android.h @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#ifndef LOVE_ANDROID_ANDROID_H +#define LOVE_ANDROID_ANDROID_H + +// LOVE +#include "common/Module.h" +#include "DisplayMetrics.h" + +namespace love +{ +namespace android +{ + +/** + * The Android module provide access to some device features, like display metrics and camera. + **/ +class Android : public Module +{ +public: + + /** + * Destructor. + **/ + virtual ~Android() {} + + /** + * Gets display metrics that describe the size and density of this display. + * @return A DisplayMetrics object containing the metrics. + **/ + DisplayMetrics* getDisplayMetrics(); + + // Implements Module. + virtual const char *getName() const; + +private: + + DisplayMetrics *metrics; + +}; // Android + +} // android +} // love + +#endif // LOVE_ANDROID_ANDROID_H diff --git a/jni/love/src/modules/android/DisplayMetrics.cpp b/jni/love/src/modules/android/DisplayMetrics.cpp new file mode 100644 index 00000000..c38627c3 --- /dev/null +++ b/jni/love/src/modules/android/DisplayMetrics.cpp @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#include "DisplayMetrics.h" +#include "core/android/SDL_android.h" + +namespace love +{ +namespace android +{ + +DisplayMetrics::DisplayMetrics() +{ + JNIEnv *env = Android_JNI_GetEnv(); + + jclass activity = env->FindClass("org/love2d/android/GameActivity"); + jmethodID getMetrics = env->GetStaticMethodID(activity, "getMetrics", "()Landroid/util/DisplayMetrics;"); + jobject metrics = env->CallStaticObjectMethod(activity, getMetrics); + jclass metricsClass = env->GetObjectClass(metrics); + + // Density + density = env->GetFloatField(metrics, env->GetFieldID(metricsClass, "density", "F")); + scaledDensity = env->GetFloatField(metrics, env->GetFieldID(metricsClass, "scaledDensity", "F")); + densityDpi = env->GetIntField(metrics, env->GetFieldID(metricsClass, "densityDpi", "I")); + + // Size + widthPixels = env->GetIntField(metrics, env->GetFieldID(metricsClass, "widthPixels", "I")); + heightPixels = env->GetIntField(metrics, env->GetFieldID(metricsClass, "heightPixels", "I")); + + // DPI + xdpi = env->GetFloatField(metrics, env->GetFieldID(metricsClass, "xdpi", "F")); + ydpi = env->GetFloatField(metrics, env->GetFieldID(metricsClass, "ydpi", "F")); +} + +float DisplayMetrics::getDensity() +{ + return density; +} + +float DisplayMetrics::getScaledDensity() +{ + return scaledDensity; +} + +int DisplayMetrics::getDensityDpi() +{ + return densityDpi; +} + +int DisplayMetrics::getWidthPixels() +{ + return widthPixels; +} + +int DisplayMetrics::getHeightPixels() +{ + return heightPixels; +} + +float DisplayMetrics::getXdpi() +{ + return xdpi; +} + +float DisplayMetrics::getYdpi() +{ + return ydpi; +} + +} // android +} // love diff --git a/jni/love/src/modules/android/DisplayMetrics.h b/jni/love/src/modules/android/DisplayMetrics.h new file mode 100644 index 00000000..9a749b7b --- /dev/null +++ b/jni/love/src/modules/android/DisplayMetrics.h @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#ifndef LOVE_ANDROID_DISPLAY_METRICS_H +#define LOVE_ANDROID_DISPLAY_METRICS_H + +// LOVE +#include "common/Object.h" + +namespace love +{ +namespace android +{ + +/** + * A DisplayMetrics describe a general information about a display, such as its size, density, and font scaling. + **/ +class DisplayMetrics : public Object +{ +public: + + /** + * Constructor. + **/ + DisplayMetrics(); + + /** + * Destructor. + **/ + virtual ~DisplayMetrics() {} + + /** + * The logical density of the display. + **/ + float getDensity(); + + /** + * A scaling factor for fonts displayed on the display. + **/ + float getScaledDensity(); + + /** + * The screen density expressed as dots-per-inch. + **/ + int getDensityDpi(); + + /** + * The absolute width of the display in pixels. + **/ + int getWidthPixels(); + + /** + * The absolute height of the display in pixels. + **/ + int getHeightPixels(); + + /** + * The exact physical pixels per inch of the screen in the X dimension. + **/ + float getXdpi(); + + /** + * The exact physical pixels per inch of the screen in the X dimension. + **/ + float getYdpi(); + +private: + float density; + float scaledDensity; + int densityDpi; + int widthPixels; + int heightPixels; + float xdpi; + float ydpi; + +}; // DisplayMetrics + +} // android +} // love + +#endif // LOVE_ANDROID_DISPLAY_METRICS_H diff --git a/jni/love/src/modules/android/wrap_Android.cpp b/jni/love/src/modules/android/wrap_Android.cpp new file mode 100644 index 00000000..940d59f7 --- /dev/null +++ b/jni/love/src/modules/android/wrap_Android.cpp @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#include "wrap_Android.h" +#include "wrap_DisplayMetrics.h" + +namespace love +{ +namespace android +{ + +static Android *instance = nullptr; + +int w_getDisplayMetrics(lua_State *L) +{ + DisplayMetrics *metrics = 0; + EXCEPT_GUARD(metrics = instance->getDisplayMetrics();) + luax_pushtype(L, "DisplayMetrics", ANDROID_DISPLAY_METRICS_T, metrics); + return 1; +} + +// List of functions to wrap. +static const luaL_Reg functions[] = +{ + { "getDisplayMetrics", w_getDisplayMetrics }, + { 0, 0 } +}; + +// Types for this module. +static const lua_CFunction types[] = +{ + luaopen_displaymetrics, + 0 +}; + +extern "C" int luaopen_love_android(lua_State *L) +{ + if (instance == 0) + { + EXCEPT_GUARD(instance = new Android();) + } + else + instance->retain(); + + WrappedModule w; + w.module = instance; + w.name = "android"; + w.flags = MODULE_T; + w.functions = functions; + w.types = types; + + int n = luax_register_module(L, w); + + return n; +} + +} // android +} // love diff --git a/jni/love/src/modules/android/wrap_Android.h b/jni/love/src/modules/android/wrap_Android.h new file mode 100644 index 00000000..80dd6437 --- /dev/null +++ b/jni/love/src/modules/android/wrap_Android.h @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#ifndef LOVE_ANDROID_WRAP_ANDROID_H +#define LOVE_ANDROID_WRAP_ANDROID_H + +// LOVE +#include "common/config.h" +#include "common/runtime.h" +#include "Android.h" + +namespace love +{ +namespace android +{ + +int w_getDisplayMetrics(lua_State *L); +extern "C" LOVE_EXPORT int luaopen_love_android(lua_State *L); + +} // android +} // love + +#endif // LOVE_ANDROID_WRAP_ANDROID_H diff --git a/jni/love/src/modules/android/wrap_DisplayMetrics.cpp b/jni/love/src/modules/android/wrap_DisplayMetrics.cpp new file mode 100644 index 00000000..9631bd24 --- /dev/null +++ b/jni/love/src/modules/android/wrap_DisplayMetrics.cpp @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#include "wrap_DisplayMetrics.h" + +namespace love +{ +namespace android +{ + +DisplayMetrics *luax_checkdisplaymetrics(lua_State *L, int idx) +{ + return luax_checktype(L, idx, "DisplayMetrics", ANDROID_DISPLAY_METRICS_T); +} + +int w_getDensity(lua_State *L) +{ + DisplayMetrics *metrics = luax_checkdisplaymetrics(L, 1); + lua_pushnumber(L, metrics->getDensity()); + return 1; +} + +int w_getScaledDensity(lua_State *L) +{ + DisplayMetrics *metrics = luax_checkdisplaymetrics(L, 1); + lua_pushnumber(L, metrics->getScaledDensity()); + return 1; +} + +int w_getDensityDpi(lua_State *L) +{ + DisplayMetrics *metrics = luax_checkdisplaymetrics(L, 1); + lua_pushnumber(L, metrics->getDensityDpi()); + return 1; +} + +int w_getWidthPixels(lua_State *L) +{ + DisplayMetrics *metrics = luax_checkdisplaymetrics(L, 1); + lua_pushnumber(L, metrics->getWidthPixels()); + return 1; +} + +int w_getHeightPixels(lua_State *L) +{ + DisplayMetrics *metrics = luax_checkdisplaymetrics(L, 1); + lua_pushnumber(L, metrics->getHeightPixels()); + return 1; +} + +int w_getXdpi(lua_State *L) +{ + DisplayMetrics *metrics = luax_checkdisplaymetrics(L, 1); + lua_pushnumber(L, metrics->getXdpi()); + return 1; +} + +int w_getYdpi(lua_State *L) +{ + DisplayMetrics *metrics = luax_checkdisplaymetrics(L, 1); + lua_pushnumber(L, metrics->getYdpi()); + return 1; +} + +static const luaL_Reg functions[] = +{ + { "getDensity", w_getDensity }, + { "getScaledDensity", w_getScaledDensity }, + { "getDensityDpi", w_getDensityDpi }, + { "getWidthPixels", w_getWidthPixels }, + { "getHeightPixels", w_getHeightPixels }, + { "getXdpi", w_getXdpi }, + { "getYdpi", w_getYdpi }, + { 0, 0 }, +}; + +extern "C" int luaopen_displaymetrics(lua_State *L) +{ + return luax_register_type(L, "DisplayMetrics", functions); +} + +} // android +} // love diff --git a/jni/love/src/modules/android/wrap_DisplayMetrics.h b/jni/love/src/modules/android/wrap_DisplayMetrics.h new file mode 100644 index 00000000..5c69098f --- /dev/null +++ b/jni/love/src/modules/android/wrap_DisplayMetrics.h @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2006-2014 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#ifndef LOVE_ANDROID_WRAP_DISPLAY_METRICS_H +#define LOVE_ANDROID_WRAP_DISPLAY_METRICS_H + +#include "common/runtime.h" +#include "DisplayMetrics.h" + +namespace love +{ +namespace android +{ + +DisplayMetrics *luax_checkdisplaymetrics(lua_State *L, int idx); +int w_getDensity(lua_State *L); +int w_getScaledDensity(lua_State *L); +int w_getDensityDpi(lua_State *L); +int w_getWidthPixels(lua_State *L); +int w_getHeightPixels(lua_State *L); +int w_getXdpi(lua_State *L); +int w_getYdpi(lua_State *L); +extern "C" int luaopen_displaymetrics(lua_State *L); + +} // android +} // love + +#endif // LOVE_ANDROID_WRAP_DISPLAY_METRICS_H diff --git a/jni/love/src/modules/love/love.cpp b/jni/love/src/modules/love/love.cpp index 7200ee37..b27f96ab 100644 --- a/jni/love/src/modules/love/love.cpp +++ b/jni/love/src/modules/love/love.cpp @@ -52,6 +52,9 @@ // of addressing implementations directly. extern "C" { +#if defined(LOVE_ENABLE_ANDROID) + extern int luaopen_love_android(lua_State*); +#endif #if defined(LOVE_ENABLE_AUDIO) extern int luaopen_love_audio(lua_State*); #endif @@ -107,6 +110,9 @@ extern "C" } static const luaL_Reg modules[] = { +#if defined(LOVE_ENABLE_ANDROID) + { "love.android", luaopen_love_android }, +#endif #if defined(LOVE_ENABLE_AUDIO) { "love.audio", luaopen_love_audio }, #endif diff --git a/jni/love/src/scripts/boot.lua b/jni/love/src/scripts/boot.lua index 59964d15..3fed9eb3 100644 --- a/jni/love/src/scripts/boot.lua +++ b/jni/love/src/scripts/boot.lua @@ -312,6 +312,7 @@ function love.init() highdpi = false, }, modules = { + android = true, event = true, keyboard = true, mouse = true, @@ -355,6 +356,7 @@ function love.init() -- Gets desired modules. for k,v in ipairs{ + "android", "thread", "timer", "event", diff --git a/jni/love/src/scripts/boot.lua.h b/jni/love/src/scripts/boot.lua.h index 2a8bf28f..9f58c40c 100644 --- a/jni/love/src/scripts/boot.lua.h +++ b/jni/love/src/scripts/boot.lua.h @@ -319,27 +319,6 @@ const unsigned char boot_lua[] = 0x76, 0x65, 0x2e, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x28, 0x69, 0x64, 0x2c, 0x78, 0x2c, 0x79, 0x2c, 0x70, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a, - 0x09, 0x09, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x3d, 0x20, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x78, 0x2c, 0x79, 0x2c, 0x62, 0x29, 0x0a, - 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x70, - 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, - 0x64, 0x28, 0x78, 0x2c, 0x79, 0x2c, 0x62, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a, - 0x09, 0x09, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x20, 0x3d, - 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x78, 0x2c, 0x79, 0x2c, 0x62, 0x29, 0x0a, - 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x72, - 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x72, 0x65, 0x6c, 0x65, 0x61, - 0x73, 0x65, 0x64, 0x28, 0x78, 0x2c, 0x79, 0x2c, 0x62, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a, - 0x09, 0x09, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x6d, 0x6f, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x78, 0x2c, 0x79, 0x2c, 0x62, 0x29, 0x0a, - 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x6d, - 0x6f, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x6d, 0x6f, 0x74, 0x69, 0x6f, 0x6e, 0x28, - 0x78, 0x2c, 0x79, 0x2c, 0x62, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a, 0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x6a, 0x2c, 0x62, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, @@ -584,6 +563,7 @@ const unsigned char boot_lua[] = 0x2c, 0x0a, 0x09, 0x09, 0x7d, 0x2c, 0x0a, 0x09, 0x09, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x0a, + 0x09, 0x09, 0x09, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x6b, 0x65, 0x79, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, @@ -649,6 +629,7 @@ const unsigned char boot_lua[] = 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x2e, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73, 0x7b, 0x0a, + 0x09, 0x09, 0x22, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x74, 0x69, 0x6d, 0x65, 0x72, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x2c, 0x0a, @@ -4865,7 +4846,6 @@ const unsigned char boot_lua[] = 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x61, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x67, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x30, 0x0a, - 0x09, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x29, 0x0a, @@ -4960,7 +4940,6 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x74, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x61, 0x74, 0x63, 0x68, 0x20, 0x3d, 0x20, 0x72, 0x61, @@ -5013,7 +4992,7 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x62, 0x61, 0x74, 0x63, 0x68, 0x3a, 0x75, 0x6e, 0x62, 0x69, 0x6e, 0x64, 0x28, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x75, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x74, 0x29, 0x09, 0x09, 0x0a, + 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x72, 0x65, 0x73, @@ -5193,7 +5172,6 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x6f, 0x70, 0x28, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6b, 0x65, 0x79, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x28, 0x6b, 0x65, 0x79, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x65, 0x73, 0x63, 0x61, 0x70, diff --git a/src/org/love2d/android/GameActivity.java b/src/org/love2d/android/GameActivity.java index 6f76aa4e..ef9e9cb3 100644 --- a/src/org/love2d/android/GameActivity.java +++ b/src/org/love2d/android/GameActivity.java @@ -1,7 +1,22 @@ package org.love2d.android; import org.libsdl.app.SDLActivity; +import android.util.DisplayMetrics; +import android.os.Bundle; public class GameActivity extends SDLActivity { + private static DisplayMetrics metrics = new DisplayMetrics(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getWindowManager().getDefaultDisplay().getMetrics(metrics); + } + + public static DisplayMetrics getMetrics() { + return metrics; + } + } From 2b8c22872f580277568768fa3aac806e95b74733 Mon Sep 17 00:00:00 2001 From: Jairo Luiz Date: Thu, 23 Jan 2014 18:52:18 -0300 Subject: [PATCH 2/2] fix tab indentation :P --- jni/love/src/modules/android/Android.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jni/love/src/modules/android/Android.cpp b/jni/love/src/modules/android/Android.cpp index 8a046de8..70beba55 100644 --- a/jni/love/src/modules/android/Android.cpp +++ b/jni/love/src/modules/android/Android.cpp @@ -27,16 +27,16 @@ namespace android DisplayMetrics* Android::getDisplayMetrics() { - if (metrics == NULL) - { - metrics = new DisplayMetrics(); - } - return metrics; + if (metrics == NULL) + { + metrics = new DisplayMetrics(); + } + return metrics; } const char *Android::getName() const { - return "love.android"; + return "love.android"; } } // android