Adding rudemntary support for Rotation in Android

This commit is contained in:
Rohan Kuruvilla 2013-04-23 16:48:09 -07:00
parent bb91f1eb30
commit f95b802866
5 changed files with 45 additions and 10 deletions

View File

@ -62,4 +62,7 @@ extern "C" {
const char *getCCBDirectoryPath() {
return "";
}
void resetCocosApp() {
}
}

View File

@ -31,6 +31,7 @@ extern "C" {
extern void cleanCacheDirJNI();
extern void setDeviceResolutionJNI(const char* res);
extern void sendLogMsg(const char* log);
extern void resetCocosApp();
}
#endif

View File

@ -21,6 +21,32 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
return JNI_VERSION_1_4;
}
static void initRotatedView(jint w, jint h) {
if (!CCDirector::sharedDirector()->getOpenGLView())
{
CCEGLView *view = CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h);
AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication()->run();
}
else
{
ccDrawInit();
ccGLInvalidateStateCache();
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
CCTextureCache::reloadAllTextures();
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
CCDirector::sharedDirector()->setGLDefaultValues();
bool isPortrait = (w < h) ? true: false;
handle_set_orient(isPortrait);
}
}
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
if (!CCDirector::sharedDirector()->getOpenGLView())
@ -31,20 +57,25 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication()->run();
}
/*
else
{
/*
ccDrawInit();
ccGLInvalidateStateCache();
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
CCTextureCache::reloadAllTextures();
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
CCDirector::sharedDirector()->setGLDefaultValues();
CCTextureCache::reloadAllTextures();
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
CCDirector::sharedDirector()->setGLDefaultValues();
*/
}
*/
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnScreenSizeChanged(JNIEnv* env, jobject thiz, jint w, jint h)
{
initRotatedView(w,h);
}
void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeRunCCB(JNIEnv* env, jobject thiz)
{

View File

@ -37,9 +37,9 @@ public class CocosPlayer extends Cocos2dxActivity{
public static Activity activity;
public static void setOrientation(int orient) {
activity.setRequestedOrientation(orient);
}
public static void setOrientation(int orient) {
activity.setRequestedOrientation(orient);
}
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

View File

@ -94,8 +94,8 @@ public class CocosPlayerSocket {
private static native void nativeRunScript(final String script);
private static void setOrientation(String isPortrait) {
// CocosPlayer.setOrientation(isPortrait.equalsIgnoreCase("true") ?
// ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
CocosPlayer.setOrientation(isPortrait.equalsIgnoreCase("true") ?
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//nativeSetOrientation(isPortrait.equalsIgnoreCase("true") ? true : false);
}