Merge pull request #881 from dumganhar/iss1204_initInstance

fixed #1204: Removed CCApplication::initInstance.
If users want to custom some features of CCEGLView, e.g. set the design resolution, they should add the following code in "HelloWorld/proj.win32/main.cpp" (on win32) or "HelloWorld/proj.android/jni/helloworld/main.cpp" (on android).

CCEGLView::sharedOpenGLView().setDesignResolutionSize(480, 320);
You should look into main.cpp files for detail infomations.

This commit also update something as follows:
1. Modified some project configuations for win32, we used MultiByte rather than Unicode as CharacterSet for all win32 projects, and removed some unused codes for win32 platform.
2. Made CCEGLView::Create(on win32) as a private function.
3. Updated ExtensionsTest.
4. Updated the format of source files(changed linebreak symbol to UNIX format ('\n'),replaced 'tab' with four spaces).
This commit is contained in:
James Chen 2012-05-02 19:38:34 -07:00
commit ec433b46cd
54 changed files with 3374 additions and 3689 deletions

View File

@ -21,7 +21,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="4" ConfigurationType="4"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
@ -85,7 +85,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="4" ConfigurationType="4"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"

View File

@ -17,18 +17,18 @@ typedef struct JniMethodInfo_
extern "C" extern "C"
{ {
// get env and cache it // get env and cache it
static JNIEnv* getJNIEnv(void) static JNIEnv* getJNIEnv(void)
{ {
JavaVM* jvm = cocos2d::JniHelper::getJavaVM(); JavaVM* jvm = cocos2d::JniHelper::getJavaVM();
if (NULL == jvm) { if (NULL == jvm) {
LOGD("Failed to get JNIEnv. JniHelper::getJavaVM() is NULL"); LOGD("Failed to get JNIEnv. JniHelper::getJavaVM() is NULL");
return NULL; return NULL;
} }
JNIEnv *env = NULL; JNIEnv *env = NULL;
// get jni environment // get jni environment
jint ret = jvm->GetEnv((void**)&env, JNI_VERSION_1_4); jint ret = jvm->GetEnv((void**)&env, JNI_VERSION_1_4);
switch (ret) { switch (ret) {
@ -59,33 +59,33 @@ extern "C"
LOGD("Failed to get the environment using GetEnv()"); LOGD("Failed to get the environment using GetEnv()");
return NULL; return NULL;
} }
} }
// get class and make it a global reference, release it at endJni(). // get class and make it a global reference, release it at endJni().
static jclass getClassID(JNIEnv *pEnv) static jclass getClassID(JNIEnv *pEnv)
{
jclass ret = pEnv->FindClass(CLASS_NAME);
if (! ret)
{
LOGD("Failed to find class of %s", CLASS_NAME);
}
return ret;
}
static bool getStaticMethodInfo(JniMethodInfo &methodinfo, const char *methodName, const char *paramCode)
{ {
jmethodID methodID = 0; jclass ret = pEnv->FindClass(CLASS_NAME);
JNIEnv *pEnv = 0; if (! ret)
bool bRet = false; {
LOGD("Failed to find class of %s", CLASS_NAME);
}
return ret;
}
static bool getStaticMethodInfo(JniMethodInfo &methodinfo, const char *methodName, const char *paramCode)
{
jmethodID methodID = 0;
JNIEnv *pEnv = 0;
bool bRet = false;
do do
{ {
pEnv = getJNIEnv(); pEnv = getJNIEnv();
if (! pEnv) if (! pEnv)
{ {
break; break;
} }
jclass classID = getClassID(pEnv); jclass classID = getClassID(pEnv);
@ -96,348 +96,348 @@ extern "C"
break; break;
} }
methodinfo.classID = classID; methodinfo.classID = classID;
methodinfo.env = pEnv; methodinfo.env = pEnv;
methodinfo.methodID = methodID; methodinfo.methodID = methodID;
bRet = true; bRet = true;
} while (0); } while (0);
return bRet; return bRet;
} }
void preloadBackgroundMusicJNI(const char *path) void preloadBackgroundMusicJNI(const char *path)
{ {
// void playBackgroundMusic(String,boolean) // void playBackgroundMusic(String,boolean)
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "preloadBackgroundMusic", "(Ljava/lang/String;)V")) if (! getStaticMethodInfo(methodInfo, "preloadBackgroundMusic", "(Ljava/lang/String;)V"))
{ {
return; return;
} }
jstring stringArg = methodInfo.env->NewStringUTF(path); jstring stringArg = methodInfo.env->NewStringUTF(path);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg);
methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void playBackgroundMusicJNI(const char *path, bool isLoop)
{
// void playBackgroundMusic(String,boolean)
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "playBackgroundMusic", "(Ljava/lang/String;Z)V"))
{
return;
}
jstring stringArg = methodInfo.env->NewStringUTF(path);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg, isLoop);
methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void stopBackgroundMusicJNI()
{
// void stopBackgroundMusic()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "stopBackgroundMusic", "()V"))
{
return;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void pauseBackgroundMusicJNI()
{
// void pauseBackgroundMusic()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "pauseBackgroundMusic", "()V"))
{
return;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void resumeBackgroundMusicJNI()
{
// void resumeBackgroundMusic()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "resumeBackgroundMusic", "()V"))
{
return;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void rewindBackgroundMusicJNI()
{
// void rewindBackgroundMusic()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "rewindBackgroundMusic", "()V"))
{
return;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
bool isBackgroundMusicPlayingJNI()
{
// boolean rewindBackgroundMusic()
JniMethodInfo methodInfo;
jboolean ret = false;
if (! getStaticMethodInfo(methodInfo, "isBackgroundMusicPlaying", "()Z"))
{
return ret;
}
ret = methodInfo.env->CallStaticBooleanMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
return ret;
}
float getBackgroundMusicVolumeJNI()
{
// float getBackgroundMusicVolume()
JniMethodInfo methodInfo;
jfloat ret = -1.0;
if (! getStaticMethodInfo(methodInfo, "getBackgroundMusicVolume", "()F"))
{
return ret;
}
ret = methodInfo.env->CallStaticFloatMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
return ret;
}
void setBackgroundMusicVolumeJNI(float volume)
{
// void setBackgroundMusicVolume()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "setBackgroundMusicVolume", "(F)V"))
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, volume);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
unsigned int playEffectJNI(const char* path, bool bLoop)
{
// int playEffect(String)
JniMethodInfo methodInfo;
int ret = 0;
if (! getStaticMethodInfo(methodInfo, "playEffect", "(Ljava/lang/String;Z)I"))
{
return ret;
}
jstring stringArg = methodInfo.env->NewStringUTF(path);
ret = methodInfo.env->CallStaticIntMethod(methodInfo.classID, methodInfo.methodID, stringArg, bLoop);
methodInfo.env->DeleteLocalRef(stringArg); methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
return (unsigned int)ret;
}
void stopEffectJNI(unsigned int nSoundId) void playBackgroundMusicJNI(const char *path, bool isLoop)
{ {
// void stopEffect(int) // void playBackgroundMusic(String,boolean)
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "stopEffect", "(I)V")) if (! getStaticMethodInfo(methodInfo, "playBackgroundMusic", "(Ljava/lang/String;Z)V"))
{ {
return ; return;
} }
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, (int)nSoundId); jstring stringArg = methodInfo.env->NewStringUTF(path);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg, isLoop);
} methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void endJNI() void stopBackgroundMusicJNI()
{ {
// void end() // void stopBackgroundMusic()
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "end", "()V")) if (! getStaticMethodInfo(methodInfo, "stopBackgroundMusic", "()V"))
{ {
return ; return;
} }
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->DeleteLocalRef(methodInfo.classID);
} }
float getEffectsVolumeJNI() void pauseBackgroundMusicJNI()
{ {
// float getEffectsVolume() // void pauseBackgroundMusic()
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
jfloat ret = -1.0;
if (! getStaticMethodInfo(methodInfo, "getEffectsVolume", "()F")) if (! getStaticMethodInfo(methodInfo, "pauseBackgroundMusic", "()V"))
{ {
return ret; return;
} }
ret = methodInfo.env->CallStaticFloatMethod(methodInfo.classID, methodInfo.methodID); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
return ret;
}
void setEffectsVolumeJNI(float volume) void resumeBackgroundMusicJNI()
{ {
// void setEffectsVolume(float) // void resumeBackgroundMusic()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "setEffectsVolume", "(F)V")) JniMethodInfo methodInfo;
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, volume); if (! getStaticMethodInfo(methodInfo, "resumeBackgroundMusic", "()V"))
methodInfo.env->DeleteLocalRef(methodInfo.classID); {
} return;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void preloadEffectJNI(const char *path) void rewindBackgroundMusicJNI()
{ {
// void preloadEffect(String) // void rewindBackgroundMusic()
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "preloadEffect", "(Ljava/lang/String;)V")) if (! getStaticMethodInfo(methodInfo, "rewindBackgroundMusic", "()V"))
{ {
return ; return;
} }
jstring stringArg = methodInfo.env->NewStringUTF(path); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg); methodInfo.env->DeleteLocalRef(methodInfo.classID);
methodInfo.env->DeleteLocalRef(stringArg); }
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void unloadEffectJNI(const char* path) bool isBackgroundMusicPlayingJNI()
{ {
// void unloadEffect(String) // boolean rewindBackgroundMusic()
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
jboolean ret = false;
if (! getStaticMethodInfo(methodInfo, "unloadEffect", "(Ljava/lang/String;)V")) if (! getStaticMethodInfo(methodInfo, "isBackgroundMusicPlaying", "()Z"))
{ {
return ; return ret;
} }
jstring stringArg = methodInfo.env->NewStringUTF(path); ret = methodInfo.env->CallStaticBooleanMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg); methodInfo.env->DeleteLocalRef(methodInfo.classID);
methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID); return ret;
} }
void pauseEffectJNI(unsigned int nSoundId) float getBackgroundMusicVolumeJNI()
{ {
// void pauseEffect(int) // float getBackgroundMusicVolume()
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
jfloat ret = -1.0;
if (! getStaticMethodInfo(methodInfo, "pauseEffect", "(I)V")) if (! getStaticMethodInfo(methodInfo, "getBackgroundMusicVolume", "()F"))
{ {
return ; return ret;
} }
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, (int)nSoundId); ret = methodInfo.env->CallStaticFloatMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
return ret;
}
void pauseAllEffectsJNI() void setBackgroundMusicVolumeJNI(float volume)
{ {
// void pauseAllEffects() // void setBackgroundMusicVolume()
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "pauseAllEffects", "()V")) if (! getStaticMethodInfo(methodInfo, "setBackgroundMusicVolume", "(F)V"))
{ {
return ; return ;
} }
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, volume);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->DeleteLocalRef(methodInfo.classID);
} }
void resumeEffectJNI(unsigned int nSoundId) unsigned int playEffectJNI(const char* path, bool bLoop)
{ {
// void resumeEffect(int) // int playEffect(String)
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
int ret = 0;
if (! getStaticMethodInfo(methodInfo, "resumeEffect", "(I)V")) if (! getStaticMethodInfo(methodInfo, "playEffect", "(Ljava/lang/String;Z)I"))
{ {
return ; return ret;
} }
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, (int)nSoundId); jstring stringArg = methodInfo.env->NewStringUTF(path);
methodInfo.env->DeleteLocalRef(methodInfo.classID); ret = methodInfo.env->CallStaticIntMethod(methodInfo.classID, methodInfo.methodID, stringArg, bLoop);
} methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
return (unsigned int)ret;
}
void resumeAllEffectsJNI() void stopEffectJNI(unsigned int nSoundId)
{ {
// void resumeAllEffects() // void stopEffect(int)
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "resumeAllEffects", "()V")) if (! getStaticMethodInfo(methodInfo, "stopEffect", "(I)V"))
{ {
return ; return ;
} }
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, (int)nSoundId);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->DeleteLocalRef(methodInfo.classID);
} }
void stopAllEffectsJNI() void endJNI()
{ {
// void stopAllEffects() // void end()
JniMethodInfo methodInfo; JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "stopAllEffects", "()V")) if (! getStaticMethodInfo(methodInfo, "end", "()V"))
{ {
return ; return ;
} }
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID); methodInfo.env->DeleteLocalRef(methodInfo.classID);
} }
float getEffectsVolumeJNI()
{
// float getEffectsVolume()
JniMethodInfo methodInfo;
jfloat ret = -1.0;
if (! getStaticMethodInfo(methodInfo, "getEffectsVolume", "()F"))
{
return ret;
}
ret = methodInfo.env->CallStaticFloatMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
return ret;
}
void setEffectsVolumeJNI(float volume)
{
// void setEffectsVolume(float)
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "setEffectsVolume", "(F)V"))
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, volume);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void preloadEffectJNI(const char *path)
{
// void preloadEffect(String)
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "preloadEffect", "(Ljava/lang/String;)V"))
{
return ;
}
jstring stringArg = methodInfo.env->NewStringUTF(path);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg);
methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void unloadEffectJNI(const char* path)
{
// void unloadEffect(String)
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "unloadEffect", "(Ljava/lang/String;)V"))
{
return ;
}
jstring stringArg = methodInfo.env->NewStringUTF(path);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg);
methodInfo.env->DeleteLocalRef(stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void pauseEffectJNI(unsigned int nSoundId)
{
// void pauseEffect(int)
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "pauseEffect", "(I)V"))
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, (int)nSoundId);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void pauseAllEffectsJNI()
{
// void pauseAllEffects()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "pauseAllEffects", "()V"))
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void resumeEffectJNI(unsigned int nSoundId)
{
// void resumeEffect(int)
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "resumeEffect", "(I)V"))
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, (int)nSoundId);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void resumeAllEffectsJNI()
{
// void resumeAllEffects()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "resumeAllEffects", "()V"))
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
void stopAllEffectsJNI()
{
// void stopAllEffects()
JniMethodInfo methodInfo;
if (! getStaticMethodInfo(methodInfo, "stopAllEffects", "()V"))
{
return ;
}
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
} }

View File

@ -34,44 +34,6 @@ AppDelegate::~AppDelegate()
//CCScriptEngineManager::purgeSharedManager(); //CCScriptEngineManager::purgeSharedManager();
} }
bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), CC_WIDTH, CC_HEIGHT));
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
#endif // CC_PLATFORM_IOS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
#endif // CC_PLATFORM_ANDROID
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif
bRet = true;
} while (0);
return bRet;
}
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director

View File

@ -14,11 +14,6 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -26,9 +26,8 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
{ {
CCEGLView *view = &CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h); view->setFrameSize(w, h);
// if you want to run in WVGA with HVGA resource, set it // set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// view->create(480, 320); // view.setDesignResolutionSize(480, 320);
CCDirector::sharedDirector()->setOpenGLView(view);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1" ConfigurationType="1"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
@ -107,7 +107,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1" ConfigurationType="1"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"

View File

@ -1,33 +1,40 @@
#include "main.h" #include "main.h"
#include "AppDelegate.h" #include "AppDelegate.h"
#include "CCEGLView.h"
// uncomment below line, open debug console USING_NS_CC;
#define USE_WIN32_CONSOLE
// uncomment below line, open debug console
int APIENTRY _tWinMain(HINSTANCE hInstance, #define USE_WIN32_CONSOLE
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int APIENTRY _tWinMain(HINSTANCE hInstance,
int nCmdShow) HINSTANCE hPrevInstance,
{ LPTSTR lpCmdLine,
UNREFERENCED_PARAMETER(hPrevInstance); int nCmdShow)
UNREFERENCED_PARAMETER(lpCmdLine); {
UNREFERENCED_PARAMETER(hPrevInstance);
#ifdef USE_WIN32_CONSOLE UNREFERENCED_PARAMETER(lpCmdLine);
AllocConsole();
freopen("CONIN$", "r", stdin); #ifdef USE_WIN32_CONSOLE
freopen("CONOUT$", "w", stdout); AllocConsole();
freopen("CONOUT$", "w", stderr); freopen("CONIN$", "r", stdin);
#endif freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
// create the application instance #endif
AppDelegate app;
// create the application instance
int ret = cocos2d::CCApplication::sharedApplication().run(); AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView();
#ifdef USE_WIN32_CONSOLE eglView.setViewName("Hello Lua");
FreeConsole(); eglView.setFrameSize(480, 320);
#endif // set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320);
return ret;
int ret = CCApplication::sharedApplication().run();
#ifdef USE_WIN32_CONSOLE
FreeConsole();
#endif
return ret;
} }

View File

@ -11,73 +11,8 @@ AppDelegate::AppDelegate() {
} }
AppDelegate::~AppDelegate() { AppDelegate::~AppDelegate()
} {
bool AppDelegate::initInstance() {
bool bRet = false;
do {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
//pMainWnd->setDesignResolutionSize(480, 320);
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
#endif // CC_PLATFORM_IOS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
// if the resources under '/sdcard" or other writeable path, set it.
// warning: the audio source should in assets/
// cocos2d::CCFileUtils::setResourcePath("/sdcard");
#endif // CC_PLATFORM_ANDROID
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create("cocos2d: Hello World", 480, 320 ,480, 320));
CCFileUtils::setResourcePath("../Resources/");
#endif // CC_PLATFORM_LINUX
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320));
pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE);
CCFileUtils::setResourcePath("/Res/");
#endif // CC_PLATFORM_BADA
#if (CC_TARGET_PLATFORM == CC_PLATFORM_QNX)
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(1024, 600));
CCFileUtils::setResourcePath("app/native/Resources");
#endif // CC_PLATFORM_QNX
bRet = true;
} while (0);
return bRet;
} }
bool AppDelegate::applicationDidFinishLaunching() { bool AppDelegate::applicationDidFinishLaunching() {

View File

@ -14,11 +14,6 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -1,26 +1,26 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY. /* AUTO-GENERATED FILE. DO NOT MODIFY.
* *
* This class was automatically generated by the * This class was automatically generated by the
* aapt tool from the resource data it found. It * aapt tool from the resource data it found. It
* should not be modified by hand. * should not be modified by hand.
*/ */
package org.cocos2dx.application; package org.cocos2dx.application;
public final class R { public final class R {
public static final class attr { public static final class attr {
} }
public static final class drawable { public static final class drawable {
public static final int icon=0x7f020000; public static final int icon=0x7f020000;
} }
public static final class id { public static final class id {
public static final int helloworld_gl_surfaceview=0x7f050001; public static final int helloworld_gl_surfaceview=0x7f050001;
public static final int textField=0x7f050000; public static final int textField=0x7f050000;
} }
public static final class layout { public static final class layout {
public static final int helloworld_demo=0x7f030000; public static final int helloworld_demo=0x7f030000;
} }
public static final class string { public static final class string {
public static final int app_name=0x7f040000; public static final int app_name=0x7f040000;
} }
} }

View File

@ -29,9 +29,8 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
{ {
CCEGLView *view = &CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h); view->setFrameSize(w, h);
// if you want to run in WVGA with HVGA resource, set it // set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// view->setDesignResolutionSize(480, 320); Please change it to (320, 480) if you're in portrait mode. // view.setDesignResolutionSize(480, 320);
CCDirector::sharedDirector()->setOpenGLView(view);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();

View File

@ -21,7 +21,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1" ConfigurationType="1"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
@ -97,7 +97,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1" ConfigurationType="1"
CharacterSet="1" CharacterSet="2"
WholeProgramOptimization="1" WholeProgramOptimization="1"
> >
<Tool <Tool

View File

@ -1,6 +1,8 @@
#include "main.h" #include "main.h"
#include "../Classes/AppDelegate.h" #include "../Classes/AppDelegate.h"
#include "CCEGLView.h"
USING_NS_CC;
int APIENTRY _tWinMain(HINSTANCE hInstance, int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
@ -12,6 +14,10 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView();
return cocos2d::CCApplication::sharedApplication().run(); eglView.setViewName("Hello World");
eglView.setFrameSize(480, 320);
// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320);
return CCApplication::sharedApplication().run();
} }

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="4" ConfigurationType="4"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
@ -87,7 +87,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="4" ConfigurationType="4"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"

View File

@ -131,8 +131,8 @@ bool CCDirector::init(void)
m_fContentScaleFactor = 1; m_fContentScaleFactor = 1;
m_bIsContentScaleSupported = false; m_bIsContentScaleSupported = false;
m_pWatcherFun = NULL; m_pWatcherFun = NULL;
m_pWatcherSender = NULL; m_pWatcherSender = NULL;
// scheduler // scheduler
m_pScheduler = new CCScheduler(); m_pScheduler = new CCScheduler();
@ -235,9 +235,9 @@ void CCDirector::drawScene(void)
showStats(); showStats();
} }
if (m_pWatcherFun && m_pWatcherSender) if (m_pWatcherFun && m_pWatcherSender)
{ {
(*m_pWatcherFun)(m_pWatcherSender); (*m_pWatcherFun)(m_pWatcherSender);
} }
kmGLPopMatrix(); kmGLPopMatrix();
@ -941,11 +941,11 @@ void CCDisplayLinkDirector::setAnimationInterval(double dValue)
} }
} }
void CCDirector::setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun) void CCDirector::setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun)
{ {
m_pWatcherFun = fun; m_pWatcherFun = fun;
m_pWatcherSender = pSender; m_pWatcherSender = pSender;
} }
NS_CC_END NS_CC_END

View File

@ -273,7 +273,7 @@ public:
void setContentScaleFactor(CCFloat scaleFactor); void setContentScaleFactor(CCFloat scaleFactor);
CCFloat getContentScaleFactor(void); CCFloat getContentScaleFactor(void);
typedef void(*WatcherCallbackFun)(void *pSender); typedef void(*WatcherCallbackFun)(void *pSender);
void setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun); void setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun);
public: public:
@ -391,9 +391,9 @@ protected:
/* contentScaleFactor could be simulated */ /* contentScaleFactor could be simulated */
bool m_bIsContentScaleSupported; bool m_bIsContentScaleSupported;
WatcherCallbackFun m_pWatcherFun; WatcherCallbackFun m_pWatcherFun;
void *m_pWatcherSender; void *m_pWatcherSender;
}; };

View File

@ -179,10 +179,10 @@ void CCTimer::update(ccTime dt)
{ {
(m_pTarget->*m_pfnSelector)(m_fElapsed); (m_pTarget->*m_pfnSelector)(m_fElapsed);
} }
if (m_nScriptHandler) if (m_nScriptHandler)
{ {
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed); CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed);
} }
m_fElapsed = m_fElapsed - m_fDelay; m_fElapsed = m_fElapsed - m_fDelay;
m_nTimesExecuted+=1; m_nTimesExecuted+=1;
m_bUseDelay = false; m_bUseDelay = false;
@ -196,10 +196,10 @@ void CCTimer::update(ccTime dt)
{ {
(m_pTarget->*m_pfnSelector)(m_fElapsed); (m_pTarget->*m_pfnSelector)(m_fElapsed);
} }
if (m_nScriptHandler) if (m_nScriptHandler)
{ {
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed); CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed);
} }
m_fElapsed = 0; m_fElapsed = 0;
m_nTimesExecuted += 1; m_nTimesExecuted += 1;

View File

@ -1,42 +1,42 @@
#ifndef __CCCONTROL_DEFINE_H__ #ifndef __CCCONTROL_DEFINE_H__
#define __CCCONTROL_DEFINE_H__ #define __CCCONTROL_DEFINE_H__
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
typedef enum typedef enum
{ {
PARENT_CENTER, PARENT_CENTER,
VERTICAL_TOP, VERTICAL_TOP,
VERTICAL_BOTTOM, VERTICAL_BOTTOM,
HORIZONTAL_LEFT, HORIZONTAL_LEFT,
HORIZONTAL_RIGHT, HORIZONTAL_RIGHT,
ABS_WITH_PIXEL, ABS_WITH_PIXEL,
ABS_WITH_PERCENT, ABS_WITH_PERCENT,
REF_PREV_X_INC, REF_PREV_X_INC,
REF_PREV_X_DEC, REF_PREV_X_DEC,
REF_PREV_Y_INC, REF_PREV_Y_INC,
REF_PREV_Y_DEC, REF_PREV_Y_DEC,
REL_FLOW REL_FLOW
} LAYOUT_TYPE; } LAYOUT_TYPE;
typedef struct typedef struct
{ {
LAYOUT_TYPE t; LAYOUT_TYPE t;
union union
{ {
float pixel_val; float pixel_val;
float percent_val; float percent_val;
} val; } val;
} LayoutParamVal; } LayoutParamVal;
typedef struct typedef struct
{ {
LayoutParamVal val_x; LayoutParamVal val_x;
LayoutParamVal val_y; LayoutParamVal val_y;
float padding; float padding;
bool wrap; bool wrap;
} LayoutParam; } LayoutParam;
NS_CC_EXT_END NS_CC_EXT_END
#endif /* __CCCONTROL_DEFINE_H__ */ #endif /* __CCCONTROL_DEFINE_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,188 +1,191 @@
#ifndef __CC_LIST_VIEW_H__ #ifndef __CC_LIST_VIEW_H__
#define __CC_LIST_VIEW_H__ #define __CC_LIST_VIEW_H__
#include <time.h> #include <time.h>
#include "platform.h" #include "platform.h"
#include <vector> #include <vector>
#include <string> #include <string>
//#include "../lua/cocos2dx_support/CCLuaEngine.h" //#include "../lua/cocos2dx_support/CCLuaEngine.h"
#include "CCListViewCell.h" #include "CCListViewCell.h"
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
class CC_DLL CCRange class CC_DLL CCRange
{ {
public: public:
CCRange() CCRange()
{ {
this->location = 0; this->location = 0;
this->length = 0; this->length = 0;
} }
CCRange(unsigned int loc, unsigned int len) CCRange(unsigned int loc, unsigned int len)
{ {
this->location = loc; this->location = loc;
this->length = len; this->length = len;
} }
static unsigned int CCMaxRange(CCRange range) static unsigned int CCMaxRange(CCRange range)
{ {
return (range.location + range.length-1); return (range.location + range.length-1);
} }
static bool CCLocationInRange(unsigned int loc, CCRange range) static bool CCLocationInRange(unsigned int loc, CCRange range)
{ {
return (loc - range.location <= range.length); return (loc - range.location <= range.length);
} }
static bool CCEqualRanges(CCRange range1, CCRange range2) { return (range1.location == range2.location && range1.length == range2.length); } static bool CCEqualRanges(CCRange range1, CCRange range2)
{
unsigned int length; return (range1.location == range2.location && range1.length == range2.length);
unsigned int location; }
};
unsigned int length;
#define CCRangeMake(__min__, __max__) CCRange((__min__), (__max__)) unsigned int location;
};
typedef enum
{ #define CCRangeMake(__min__, __max__) CCRange((__min__), (__max__))
CCListViewSlideDirNone,
CCListViewSlideDirUp, typedef enum
CCListViewSlideDirDown, {
CCListViewSlideDirLeft, CCListViewSlideDirNone,
CCListViewSlideDirRight, CCListViewSlideDirUp,
} CCListViewSlideDir; CCListViewSlideDirDown,
CCListViewSlideDirLeft,
typedef enum CCListViewSlideDirRight,
{ } CCListViewSlideDir;
CCListViewStateWatting,
CCListViewStateTrackingTouch, typedef enum
CCListViewStateEaseOut, {
CCListViewStateFix, CCListViewStateWatting,
CCListViewStateScroll, CCListViewStateTrackingTouch,
} CCListViewState; CCListViewStateEaseOut,
CCListViewStateFix,
typedef enum CCListViewStateScroll,
{ } CCListViewState;
CCListViewModeHorizontal,
CCListViewModeVertical, typedef enum
} CCListViewMode; {
CCListViewModeHorizontal,
typedef struct _CCListViewProtrolData CCListViewModeVertical,
{ } CCListViewMode;
unsigned int nNumberOfRows;
unsigned int nRow; typedef struct _CCListViewProtrolData
CCListViewCell *cell; {
} CCListViewProtrolData; unsigned int nNumberOfRows;
unsigned int nRow;
class CC_DLL CCListViewDelegate CCListViewCell *cell;
{ } CCListViewProtrolData;
public :
CCListViewDelegate(){}; class CC_DLL CCListViewDelegate
virtual ~CCListViewDelegate(){}; {
public :
virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data)=0; CCListViewDelegate(){};
virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)=0; virtual ~CCListViewDelegate(){};
virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data)=0;
virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data)=0; virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data)=0;
}; virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)=0;
virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data)=0;
virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data)=0;
class CC_DLL CCListView : public CCLayerColor };
{
public:
virtual ~CCListView(void); class CC_DLL CCListView : public CCLayerColor
CCListView(void); {
public:
static CCListView* viewWithMode(CCListViewMode mode); virtual ~CCListView(void);
bool initWithMode(CCListViewMode mode); CCListView(void);
void setDelegateName(const char* pszName); static CCListView* viewWithMode(CCListViewMode mode);
void selectCellAtRow(unsigned int nRow); bool initWithMode(CCListViewMode mode);
void unselectCellAtRow(unsigned int nRow);
void scrollCellToFront(unsigned int nRow, bool bAnimated); void setDelegateName(const char* pszName);
void scrollCellToBack(unsigned int nRow, bool bAnimated); void selectCellAtRow(unsigned int nRow);
void reload(void); void unselectCellAtRow(unsigned int nRow);
void insertCellsAtRow(unsigned int nRow, unsigned int nCount); void scrollCellToFront(unsigned int nRow, bool bAnimated);
void deleteCellsAtRow(unsigned int nRow, unsigned int nCount); void scrollCellToBack(unsigned int nRow, bool bAnimated);
CCListViewCell *cellAtRow(unsigned int nRow); void reload(void);
void insertCellsAtRow(unsigned int nRow, unsigned int nCount);
CCListViewSlideDir getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd); void deleteCellsAtRow(unsigned int nRow, unsigned int nCount);
inline CCListViewSlideDir getSlideDir(void) { return m_nSlideDir; } CCListViewCell *cellAtRow(unsigned int nRow);
inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } CCListViewSlideDir getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd);
inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } inline CCListViewSlideDir getSlideDir(void) { return m_nSlideDir; }
inline CCListViewMode getMode(void) { return m_nMode; }
inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; }
inline void setListViewParent(CCListView *pParent) { m_pListViewParent = pParent; } inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; }
inline CCListView *getListViewParent(void) { return m_pListViewParent; } inline CCListViewMode getMode(void) { return m_nMode; }
inline void setIsEnabled(bool bEnabled) { m_bIsEnabled = bEnabled; } inline void setListViewParent(CCListView *pParent) { m_pListViewParent = pParent; }
inline bool getIsEnabled(void) { return m_bIsEnabled; } inline CCListView *getListViewParent(void) { return m_pListViewParent; }
// un inline void setIsEnabled(bool bEnabled) { m_bIsEnabled = bEnabled; }
void setDelegate(const CCListViewDelegate *pDelegate) { m_pDelegate = const_cast<CCListViewDelegate*>(pDelegate);} inline bool getIsEnabled(void) { return m_bIsEnabled; }
void finishFix(void);
void finishScroll(void); // un
void finishEaseOut(void); void setDelegate(const CCListViewDelegate *pDelegate) { m_pDelegate = const_cast<CCListViewDelegate*>(pDelegate);}
void finishFix(void);
public: void finishScroll(void);
virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); void finishEaseOut(void);
virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event); public:
virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
virtual void onEnter(void); virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event);
virtual void onExit(void); virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
virtual void registerWithTouchDispatcher(void); virtual void onEnter(void);
virtual void visit(void); virtual void onExit(void);
protected: virtual void registerWithTouchDispatcher(void);
void displayVisibleRows(void); virtual void visit(void);
CCListViewCell* appendRowToBack(unsigned int nRow);
CCListViewCell* appendRowToFront(unsigned int nRow); protected:
void fixFirstRow(void); void displayVisibleRows(void);
void fixLastRow(void); CCListViewCell* appendRowToBack(unsigned int nRow);
void easeOutWithDistance(float dis); CCListViewCell* appendRowToFront(unsigned int nRow);
void clearUnvisibleRows(void); void fixFirstRow(void);
void fixLastRow(void);
int rowForTouch(cocos2d::CCTouch *touch); void easeOutWithDistance(float dis);
bool isTouchInside(CCTouch *touch); void clearUnvisibleRows(void);
bool isFullFill(void);
int rowForTouch(cocos2d::CCTouch *touch);
void stopActionImmediately(void); bool isTouchInside(CCTouch *touch);
bool isFullFill(void);
unsigned int triggerNumberOfCells(void);
CCListViewCell *triggerCellForRow(unsigned int nRow); void stopActionImmediately(void);
void triggerDidClickCellAtRow(unsigned int nRow);
void triggerDidScrollToRow(unsigned int nRow); unsigned int triggerNumberOfCells(void);
bool isMenuTouch(CCTouch *touch, CCNode *parent); CCListViewCell *triggerCellForRow(unsigned int nRow);
void triggerDidClickCellAtRow(unsigned int nRow);
private: void triggerDidScrollToRow(unsigned int nRow);
CCListViewState m_nState; bool isMenuTouch(CCTouch *touch, CCNode *parent);
CCListViewMode m_nMode;
CCListViewSlideDir m_nSlideDir; private:
CCListViewCellSeparatorStyle m_nSeparatorStyle; CCListViewState m_nState;
unsigned int m_nNumberOfRows; CCListViewMode m_nMode;
float m_fActionDuration; CCListViewSlideDir m_nSlideDir;
clock_t m_timeTouchBegan; CCListViewCellSeparatorStyle m_nSeparatorStyle;
CCRange m_drawedRows; //所有已绘制的cell unsigned int m_nNumberOfRows;
CCRange m_visibleRows; //所有可见的cell float m_fActionDuration;
CCPoint m_ptTouchBegan; clock_t m_timeTouchBegan;
CCPoint m_ptTouchEnd; CCRange m_drawedRows; //所有已绘制的cell
CCPoint m_ptPanelOffset; CCRange m_visibleRows; //所有可见的cell
CCPoint m_ptDestination; CCPoint m_ptTouchBegan;
std::string m_strDeletegate; CCPoint m_ptTouchEnd;
CCListViewDelegate* m_pDelegate; CCPoint m_ptPanelOffset;
CCLayer* m_layerPanel; CCPoint m_ptDestination;
CCListView* m_pListViewParent; std::string m_strDeletegate;
int m_nSelectedRow; CCListViewDelegate* m_pDelegate;
int m_nCurrentRow; CCLayer* m_layerPanel;
bool m_bIsEnabled; CCListView* m_pListViewParent;
bool m_bIsOnTouch; int m_nSelectedRow;
}; int m_nCurrentRow;
bool m_bIsEnabled;
NS_CC_EXT_END bool m_bIsOnTouch;
};
NS_CC_EXT_END
#endif // __CC_LIST_VIEW_H__ #endif // __CC_LIST_VIEW_H__

View File

@ -1,96 +1,96 @@
#include "CCListView.h" #include "CCListView.h"
#include "CCListViewCell.h" #include "CCListViewCell.h"
#include "cocos2d.h" #include "cocos2d.h"
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
const int TOUCHBEGIN = 1; const int TOUCHBEGIN = 1;
const int TOUCHEND = 2; const int TOUCHEND = 2;
const int TOUCHMOVING = 3; const int TOUCHMOVING = 3;
const int TOUCHCANCELLED= 4; const int TOUCHCANCELLED= 4;
/****************************************** /******************************************
**************Public Functions************* **************Public Functions*************
*******************************************/ *******************************************/
CCListViewCell::CCListViewCell(void) CCListViewCell::CCListViewCell(void)
:m_nSeparatorStyle(CCListViewCellSeparatorStyleNone) :m_nSeparatorStyle(CCListViewCellSeparatorStyleNone)
,m_bIsSelected(false) ,m_bIsSelected(false)
{ {
setIsTouchEnabled(true); setIsTouchEnabled(true);
m_selectionColor = ccc4(0, 0, 255, 255); m_selectionColor = ccc4(0, 0, 255, 255);
m_separatorLineColor = ccc3(128, 128, 128); m_separatorLineColor = ccc3(128, 128, 128);
} }
CCListViewCell::~CCListViewCell(void) CCListViewCell::~CCListViewCell(void)
{ {
} }
CCListViewCell *CCListViewCell::node(void) CCListViewCell *CCListViewCell::node(void)
{ {
CCListViewCell *pRet = new CCListViewCell(); CCListViewCell *pRet = new CCListViewCell();
pRet->initWithColorWidthHeight(ccc4(255, 255, 255, 255), 0, 0); pRet->initWithColorWidthHeight(ccc4(255, 255, 255, 255), 0, 0);
pRet->autorelease(); pRet->autorelease();
return pRet; return pRet;
} }
void CCListViewCell::selected(void) void CCListViewCell::selected(void)
{ {
m_bIsSelected = true; m_bIsSelected = true;
CCLayerColor::setColor(ccc3(m_selectionColor.r, m_selectionColor.g, m_selectionColor.b)); CCLayerColor::setColor(ccc3(m_selectionColor.r, m_selectionColor.g, m_selectionColor.b));
CCLayerColor::setOpacity(m_selectionColor.a); CCLayerColor::setOpacity(m_selectionColor.a);
} }
void CCListViewCell::unselected(void) void CCListViewCell::unselected(void)
{ {
m_bIsSelected = false; m_bIsSelected = false;
CCLayerColor::setColor(ccc3(m_normalColor.r, m_normalColor.g, m_normalColor.b)); CCLayerColor::setColor(ccc3(m_normalColor.r, m_normalColor.g, m_normalColor.b));
CCLayerColor::setOpacity(m_normalColor.a); CCLayerColor::setOpacity(m_normalColor.a);
} }
/****************************************** /******************************************
**************Virturl Functions************ **************Virturl Functions************
*******************************************/ *******************************************/
bool CCListViewCell::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) bool CCListViewCell::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height)
{ {
this->m_normalColor = color; this->m_normalColor = color;
return CCLayerColor::initWithColor(color, width, height); return CCLayerColor::initWithColor(color, width, height);
} }
void CCListViewCell::draw(void) void CCListViewCell::draw(void)
{ {
CCLayerColor::draw(); CCLayerColor::draw();
CCSize size = this->getContentSize(); CCSize size = this->getContentSize();
CCListView *owner = this->getOwner(); CCListView *owner = this->getOwner();
if (CCListViewCellSeparatorStyleSingleLine == m_nSeparatorStyle) if (CCListViewCellSeparatorStyleSingleLine == m_nSeparatorStyle)
{ {
glLineWidth(1.0f); glLineWidth(1.0f);
ccDrawColor4B(m_separatorLineColor.r, m_separatorLineColor.g, m_separatorLineColor.b, 255); ccDrawColor4B(m_separatorLineColor.r, m_separatorLineColor.g, m_separatorLineColor.b, 255);
if (CCListViewModeHorizontal == owner->getMode()) if (CCListViewModeHorizontal == owner->getMode())
{ {
ccDrawLine(CCPointMake(size.width, 0), CCPointMake(size.width, size.height)); ccDrawLine(CCPointMake(size.width, 0), CCPointMake(size.width, size.height));
} }
else if (CCListViewModeVertical == owner->getMode()) else if (CCListViewModeVertical == owner->getMode())
{ {
ccDrawLine(CCPointMake(0, 0), CCPointMake(size.width, 0)); ccDrawLine(CCPointMake(0, 0), CCPointMake(size.width, 0));
} }
} }
} }
void CCListViewCell::setColor(ccColor3B var) void CCListViewCell::setColor(ccColor3B var)
{ {
m_normalColor.r = var.r; m_normalColor.r = var.r;
m_normalColor.g = var.g; m_normalColor.g = var.g;
m_normalColor.b = var.b; m_normalColor.b = var.b;
CCLayerColor::setColor(var); CCLayerColor::setColor(var);
} }
void CCListViewCell::setOpacity(GLubyte var) void CCListViewCell::setOpacity(GLubyte var)
{ {
m_normalColor.a = var; m_normalColor.a = var;
CCLayerColor::setOpacity(var); CCLayerColor::setOpacity(var);
} }
NS_CC_EXT_END NS_CC_EXT_END

View File

@ -1,55 +1,55 @@
#ifndef __CC_LIST_VIEW_CELL_H_ #ifndef __CC_LIST_VIEW_CELL_H_
#define __CC_LIST_VIEW_CELL_H_ #define __CC_LIST_VIEW_CELL_H_
#include "CCControlDefine.h" #include "CCControlDefine.h"
#include "CCLayer.h" #include "CCLayer.h"
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
class CCListView; class CCListView;
typedef enum typedef enum
{ {
CCListViewCellSeparatorStyleNone, CCListViewCellSeparatorStyleNone,
CCListViewCellSeparatorStyleSingleLine, CCListViewCellSeparatorStyleSingleLine,
}CCListViewCellSeparatorStyle; }CCListViewCellSeparatorStyle;
class CC_DLL CCListViewCell : public CCLayerColor class CC_DLL CCListViewCell : public CCLayerColor
{ {
public: public:
CCListViewCell(void); CCListViewCell(void);
virtual ~CCListViewCell(void); virtual ~CCListViewCell(void);
static CCListViewCell *node(void); static CCListViewCell *node(void);
void selected(void); void selected(void);
void unselected(void); void unselected(void);
inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; }
inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; }
inline ccColor4B getSelectionColor(void) { return m_selectionColor; } inline ccColor4B getSelectionColor(void) { return m_selectionColor; }
inline void setSelectionColor(ccColor4B color) { m_selectionColor = color; } inline void setSelectionColor(ccColor4B color) { m_selectionColor = color; }
inline ccColor3B getSeparatorLineColor(void) { return m_separatorLineColor; } inline ccColor3B getSeparatorLineColor(void) { return m_separatorLineColor; }
inline void setSeparatorLineColor(ccColor3B color) { m_separatorLineColor = color; } inline void setSeparatorLineColor(ccColor3B color) { m_separatorLineColor = color; }
public: public:
virtual bool initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height); virtual bool initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height);
virtual void draw(void); virtual void draw(void);
virtual void setColor(ccColor3B color); virtual void setColor(ccColor3B color);
virtual void setOpacity(GLubyte var); virtual void setOpacity(GLubyte var);
private: private:
inline CCListView *getOwner(void) { return (CCListView*)(this->getParent()->getParent()); } inline CCListView *getOwner(void) { return (CCListView*)(this->getParent()->getParent()); }
private: private:
CCListViewCellSeparatorStyle m_nSeparatorStyle; CCListViewCellSeparatorStyle m_nSeparatorStyle;
bool m_bIsSelected; bool m_bIsSelected;
ccColor4B m_selectionColor; ccColor4B m_selectionColor;
ccColor4B m_normalColor; ccColor4B m_normalColor;
ccColor3B m_separatorLineColor; ccColor3B m_separatorLineColor;
}; };
NS_CC_EXT_END NS_CC_EXT_END
#endif // __CC_LIST_VIEW_CELL_H_ #endif // __CC_LIST_VIEW_CELL_H_

View File

@ -5,82 +5,82 @@ using namespace std;
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
#define NUM_PER_PAGE 4 #define NUM_PER_PAGE 4
CCTextureWatcher::CCTextureWatcher() CCTextureWatcher::CCTextureWatcher()
{ {
m_bHide = false; m_bHide = false;
m_nCurrnetPage = 1; m_nCurrnetPage = 1;
m_nTotalPage = 0; m_nTotalPage = 0;
m_bFresh = true; m_bFresh = true;
m_pTextures = NULL; m_pTextures = NULL;
m_pszString = NULL; m_pszString = NULL;
m_pLayer = CCLayerColor::layerWithColor(ccc4(128, 128, 128, 128)); m_pLayer = CCLayerColor::layerWithColor(ccc4(128, 128, 128, 128));
m_pLayer->retain(); m_pLayer->retain();
// layer // layer
CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSize size = CCDirector::sharedDirector()->getWinSize();
size.height *= 0.6; size.height *= 0.6;
m_pLayer->setContentSize(size); m_pLayer->setContentSize(size);
// 屏蔽点击事件的menu // 屏蔽点击事件的menu
//* //*
CCLabelTTF *label = CCLabelTTF::labelWithString(" ", size, CCTextAlignmentLeft, "Arial", 12); CCLabelTTF *label = CCLabelTTF::labelWithString(" ", size, CCTextAlignmentLeft, "Arial", 12);
CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label); CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label);
menuItem->setAnchorPoint(CCPoint(0, 0)); menuItem->setAnchorPoint(CCPoint(0, 0));
menuItem->setPosition(CCPoint(0, 0)); menuItem->setPosition(CCPoint(0, 0));
CCMenu *menu = CCMenu::menuWithItem(menuItem); CCMenu *menu = CCMenu::menuWithItem(menuItem);
menu->setAnchorPoint(CCPoint(0, 0)); menu->setAnchorPoint(CCPoint(0, 0));
menu->setPosition(CCPoint(0, 0)); menu->setPosition(CCPoint(0, 0));
m_pLayer->addChild(menu); m_pLayer->addChild(menu);
//*/ //*/
// list // list
CCListView *list = CCListView::viewWithMode(CCListViewModeHorizontal); CCListView *list = CCListView::viewWithMode(CCListViewModeHorizontal);
list->setContentSize(size); list->setContentSize(size);
list->setDelegate(this); list->setDelegate(this);
list->setSeparatorStyle(CCListViewCellSeparatorStyleNone); list->setSeparatorStyle(CCListViewCellSeparatorStyleNone);
m_pLayer->addChild(list); m_pLayer->addChild(list);
m_pList = list; m_pList = list;
// 隐藏按钮 // 隐藏按钮
CCLabelTTF *labelHide = CCLabelTTF::labelWithString("Hide ", "Arial", 24); CCLabelTTF *labelHide = CCLabelTTF::labelWithString("Hide ", "Arial", 24);
labelHide->setColor(ccc3(255, 0, 0)); labelHide->setColor(ccc3(255, 0, 0));
CCMenuItemLabel *menuItem2 = CCMenuItemLabel::itemWithLabel(labelHide, this, menu_selector(CCTextureWatcher::actionHide)); CCMenuItemLabel *menuItem2 = CCMenuItemLabel::itemWithLabel(labelHide, this, menu_selector(CCTextureWatcher::actionHide));
menuItem2->setAnchorPoint(CCPoint(0, 0)); menuItem2->setAnchorPoint(CCPoint(0, 0));
menuItem2->setPosition(CCPoint(0, 0)); menuItem2->setPosition(CCPoint(0, 0));
CCMenu *menu2 = CCMenu::menuWithItem(menuItem2); CCMenu *menu2 = CCMenu::menuWithItem(menuItem2);
menu2->setAnchorPoint(CCPoint(0, 0)); menu2->setAnchorPoint(CCPoint(0, 0));
menu2->setPosition(CCPoint(size.width - menuItem2->getContentSize().width, 0)); menu2->setPosition(CCPoint(size.width - menuItem2->getContentSize().width, 0));
m_labelHide = labelHide; m_labelHide = labelHide;
m_menuHide = menu2; m_menuHide = menu2;
m_menuHide->retain(); m_menuHide->retain();
// 更新按钮 // 更新按钮
CCLabelTTF *labelFresh = CCLabelTTF::labelWithString("Fresh", "Arial", 24); CCLabelTTF *labelFresh = CCLabelTTF::labelWithString("Fresh", "Arial", 24);
labelFresh->setColor(ccc3(255, 0, 0)); labelFresh->setColor(ccc3(255, 0, 0));
CCMenuItemLabel *menuItem1 = CCMenuItemLabel::itemWithLabel(labelFresh, this, menu_selector(CCTextureWatcher::actionFresh)); CCMenuItemLabel *menuItem1 = CCMenuItemLabel::itemWithLabel(labelFresh, this, menu_selector(CCTextureWatcher::actionFresh));
menuItem1->setAnchorPoint(CCPoint(0, 0)); menuItem1->setAnchorPoint(CCPoint(0, 0));
menuItem1->setPosition(CCPoint(0, 0)); menuItem1->setPosition(CCPoint(0, 0));
CCMenu *menu1 = CCMenu::menuWithItem(menuItem1); CCMenu *menu1 = CCMenu::menuWithItem(menuItem1);
menu1->setAnchorPoint(CCPoint(0, 0)); menu1->setAnchorPoint(CCPoint(0, 0));
menu1->setPosition(CCPoint(size.width - menuItem1->getContentSize().width - menuItem2->getContentSize().width * 1.5, 0)); menu1->setPosition(CCPoint(size.width - menuItem1->getContentSize().width - menuItem2->getContentSize().width * 1.5, 0));
m_pLayer->addChild(menu1); m_pLayer->addChild(menu1);
// label page // label page
m_labelPage = CCLabelTTF::labelWithString(" ", CCSizeMake(size.width * 0.1, labelFresh->getContentSize().height), CCTextAlignmentCenter, "Arial", 16); m_labelPage = CCLabelTTF::labelWithString(" ", CCSizeMake(size.width * 0.1, labelFresh->getContentSize().height), CCTextAlignmentCenter, "Arial", 16);
m_labelPage->setAnchorPoint(CCPoint(0.5, 0)); m_labelPage->setAnchorPoint(CCPoint(0.5, 0));
m_labelPage->setPosition(CCPoint(size.width/2.0, 0)); m_labelPage->setPosition(CCPoint(size.width/2.0, 0));
m_pLayer->addChild(m_labelPage, 0); m_pLayer->addChild(m_labelPage, 0);
} }
CCTextureWatcher::~CCTextureWatcher() CCTextureWatcher::~CCTextureWatcher()
{ {
if (m_menuHide) if (m_menuHide)
{ {
m_menuHide->removeFromParentAndCleanup(true); m_menuHide->removeFromParentAndCleanup(true);
m_menuHide->release(); m_menuHide->release();
@ -92,101 +92,101 @@ CCTextureWatcher::~CCTextureWatcher()
} }
if (m_pTextures) m_pTextures->release(); if (m_pTextures) m_pTextures->release();
if (m_pszString) delete []m_pszString; if (m_pszString) delete []m_pszString;
} }
void CCTextureWatcher::actionFresh(CCObject* object) void CCTextureWatcher::actionFresh(CCObject* object)
{ {
CCTextureWatcher::sharedTextureWatcher()->fresh(); CCTextureWatcher::sharedTextureWatcher()->fresh();
} }
void CCTextureWatcher::actionHide(CCObject *object) void CCTextureWatcher::actionHide(CCObject *object)
{ {
CCTextureWatcher::sharedTextureWatcher()->hide(); CCTextureWatcher::sharedTextureWatcher()->hide();
} }
void CCTextureWatcher::fresh() void CCTextureWatcher::fresh()
{ {
m_nCurrnetPage = 1; m_nCurrnetPage = 1;
m_bFresh = true; m_bFresh = true;
} }
void CCTextureWatcher::hide() void CCTextureWatcher::hide()
{ {
m_bHide = !m_bHide; m_bHide = !m_bHide;
if (m_bHide) if (m_bHide)
{ {
m_labelHide->setString("Show"); m_labelHide->setString("Show");
m_pLayer->setPosition(CCPoint(0, -m_pLayer->getContentSize().height)); m_pLayer->setPosition(CCPoint(0, -m_pLayer->getContentSize().height));
} }
else else
{ {
m_labelHide->setString("Hide"); m_labelHide->setString("Hide");
m_pLayer->setPosition(CCPoint(0, 0)); m_pLayer->setPosition(CCPoint(0, 0));
} }
} }
void CCTextureWatcher::dovisit() void CCTextureWatcher::dovisit()
{ {
if (m_bFresh) if (m_bFresh)
{ {
if (m_pTextures) if (m_pTextures)
{ {
m_pTextures->removeAllObjects(); m_pTextures->removeAllObjects();
m_pTextures->release(); m_pTextures->release();
} }
CCTextureCache::sharedTextureCache()->removeUnusedTextures(); CCTextureCache::sharedTextureCache()->removeUnusedTextures();
m_pTextures = CCTextureCache::sharedTextureCache()->snapshotTextures(); m_pTextures = CCTextureCache::sharedTextureCache()->snapshotTextures();
m_nTotalPage = (m_pTextures->count() + NUM_PER_PAGE - 1) / NUM_PER_PAGE; m_nTotalPage = (m_pTextures->count() + NUM_PER_PAGE - 1) / NUM_PER_PAGE;
if (m_pTextures->count() > 0) if (m_pTextures->count() > 0)
{ {
m_bFresh = false; m_bFresh = false;
m_pList->reload(); m_pList->reload();
} }
} }
CCNode *pParent = m_pLayer->getParent(); CCNode *pParent = m_pLayer->getParent();
if (pParent) if (pParent)
{ {
if (pParent != CCDirector::sharedDirector()->getRunningScene()) if (pParent != CCDirector::sharedDirector()->getRunningScene())
{ {
pParent->removeChild(m_pLayer, true); pParent->removeChild(m_pLayer, true);
CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998); CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998);
m_bFresh = true; m_bFresh = true;
} }
} }
else else
{ {
CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998); CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998);
} }
pParent = m_menuHide->getParent(); pParent = m_menuHide->getParent();
if (pParent) if (pParent)
{ {
if (pParent != CCDirector::sharedDirector()->getRunningScene()) if (pParent != CCDirector::sharedDirector()->getRunningScene())
{ {
pParent->removeChild(m_menuHide, true); pParent->removeChild(m_menuHide, true);
CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999); CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999);
} }
} }
else else
{ {
CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999); CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999);
} }
} }
void CCTextureWatcher::visit(void* pSender) void CCTextureWatcher::visit(void* pSender)
{ {
CCTextureWatcher *wartcher = (CCTextureWatcher*)pSender; CCTextureWatcher *wartcher = (CCTextureWatcher*)pSender;
wartcher->dovisit(); wartcher->dovisit();
} }
static CCTextureWatcher *g_sharedTextureWatcher = NULL; static CCTextureWatcher *g_sharedTextureWatcher = NULL;
CCTextureWatcher* CCTextureWatcher::sharedTextureWatcher() CCTextureWatcher* CCTextureWatcher::sharedTextureWatcher()
{ {
if (!g_sharedTextureWatcher) if (!g_sharedTextureWatcher)
{ {
g_sharedTextureWatcher = new CCTextureWatcher(); g_sharedTextureWatcher = new CCTextureWatcher();
} }
return g_sharedTextureWatcher; return g_sharedTextureWatcher;
} }
void CCTextureWatcher::purgeTextureWatcher() void CCTextureWatcher::purgeTextureWatcher()
@ -199,141 +199,141 @@ void CCTextureWatcher::purgeTextureWatcher()
void CCTextureWatcher::setDisplayWatcher(bool bDisplayWatcher) void CCTextureWatcher::setDisplayWatcher(bool bDisplayWatcher)
{ {
m_bDisplayWatcher = bDisplayWatcher; m_bDisplayWatcher = bDisplayWatcher;
if (m_bDisplayWatcher) if (m_bDisplayWatcher)
{ {
if (m_pszString == NULL) if (m_pszString == NULL)
{ {
m_pszString = new char[64]; m_pszString = new char[64];
} }
CCDirector::sharedDirector()->setWatcherCallbackFun(this, &CCTextureWatcher::visit); CCDirector::sharedDirector()->setWatcherCallbackFun(this, &CCTextureWatcher::visit);
} }
else else
{ {
CCDirector::sharedDirector()->setWatcherCallbackFun(NULL, NULL); CCDirector::sharedDirector()->setWatcherCallbackFun(NULL, NULL);
purgeTextureWatcher(); purgeTextureWatcher();
} }
} }
void CCTextureWatcher::CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data) void CCTextureWatcher::CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data)
{
data->nNumberOfRows = m_nTotalPage;
}
void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)
{ {
m_nCurrnetPage = data->nRow + 1; data->nNumberOfRows = m_nTotalPage;
CCListViewCell *cell = CCListViewCell::node(); }
cell->setOpacity(0);
cell->setContentSize(m_pList->getContentSize());
cell->setSelectionColor(ccc4(0, 0, 0, 0));
data->cell = cell;
CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height); void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)
{
m_nCurrnetPage = data->nRow + 1;
CCListViewCell *cell = CCListViewCell::node();
cell->setOpacity(0);
cell->setContentSize(m_pList->getContentSize());
cell->setSelectionColor(ccc4(0, 0, 0, 0));
data->cell = cell;
CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6); CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height);
sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage); CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6);
m_labelPage->setString(m_pszString);
float offX = 0, offY = 0, offsetX = 0, offsetY = 0; sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage);
CC_UNUSED_PARAM(offsetY); m_labelPage->setString(m_pszString);
int nCount = 0;
int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE; float offX = 0, offY = 0, offsetX = 0, offsetY = 0;
int nEnd = nStart + NUM_PER_PAGE; CC_UNUSED_PARAM(offsetY);
int nCount = 0;
int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE;
int nEnd = nStart + NUM_PER_PAGE;
CCDictElement* pElement = NULL; CCDictElement* pElement = NULL;
CCDICT_FOREACH(m_pTextures, pElement) CCDICT_FOREACH(m_pTextures, pElement)
{ {
if (nCount >= nStart && nCount < nEnd) if (nCount >= nStart && nCount < nEnd)
{ {
string key = pElement->getStrKey(); string key = pElement->getStrKey();
CCTexture2D* textrue = (CCTexture2D*)pElement->getObject(); CCTexture2D* textrue = (CCTexture2D*)pElement->getObject();
//textrue = m_pTextures->objectForKey(*it); //textrue = m_pTextures->objectForKey(*it);
if (textrue) if (textrue)
{ {
// 引用数 // 引用数
sprintf(m_pszString, "[%d]", textrue->retainCount() - 2); sprintf(m_pszString, "[%d]", textrue->retainCount() - 2);
CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16);
if (textrue->retainCount() - 2 > 0) if (textrue->retainCount() - 2 > 0)
{ {
labelCount->setColor(ccc3(0, 255, 0)); labelCount->setColor(ccc3(0, 255, 0));
} }
else else
{ {
labelCount->setColor(ccc3(255, 0, 0)); labelCount->setColor(ccc3(255, 0, 0));
} }
offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5; offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5;
offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height; offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height;
labelCount->setPosition(CCPoint(offX, offY)); labelCount->setPosition(CCPoint(offX, offY));
labelCount->setAnchorPoint(CCPoint(0, 0)); labelCount->setAnchorPoint(CCPoint(0, 0));
cell->addChild(labelCount); cell->addChild(labelCount);
// 大小 // 大小
sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height); sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height);
CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16);
offX = offsetX + listItemSize.width * 0.5; offX = offsetX + listItemSize.width * 0.5;
offY = (listItemSize.height - size.height) * 0.5 + size.height; offY = (listItemSize.height - size.height) * 0.5 + size.height;
labelSize->setPosition(CCPoint(offX, offY)); labelSize->setPosition(CCPoint(offX, offY));
labelSize->setAnchorPoint(CCPoint(0.5, 0)); labelSize->setAnchorPoint(CCPoint(0.5, 0));
cell->addChild(labelSize); cell->addChild(labelSize);
// 名称 // 名称
int len = key.length(); int len = key.length();
int pos = 0; int pos = 0;
#if defined(ND_MAC) || defined(ND_IPHONE) #if defined(ND_MAC) || defined(ND_IPHONE)
pos = key.rfind('/') + 1; pos = key.rfind('/') + 1;
#else #else
pos = key.rfind('\\') + 1; pos = key.rfind('\\') + 1;
int pos2 = key.rfind('/') + 1; int pos2 = key.rfind('/') + 1;
pos = pos > pos2 ? pos : pos2; pos = pos > pos2 ? pos : pos2;
#endif #endif
string name = key.substr(pos, len - pos); string name = key.substr(pos, len - pos);
sprintf(m_pszString, "%s", name.c_str()); sprintf(m_pszString, "%s", name.c_str());
CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height); CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height);
CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16); CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16);
offX = offsetX + listItemSize.width * 0.5; offX = offsetX + listItemSize.width * 0.5;
offY = offY + labelName->getContentSize().height; offY = offY + labelName->getContentSize().height;
labelName->setPosition(CCPoint(offX, offY)); labelName->setPosition(CCPoint(offX, offY));
labelName->setAnchorPoint(CCPoint(0.5, 0)); labelName->setAnchorPoint(CCPoint(0.5, 0));
cell->addChild(labelName); cell->addChild(labelName);
CCSprite *sprite = CCSprite::spriteWithTexture(textrue); CCSprite *sprite = CCSprite::spriteWithTexture(textrue);
sprite->setAnchorPoint(CCPoint(0, 0)); sprite->setAnchorPoint(CCPoint(0, 0));
CCSize spriteSize = sprite->getContentSize();
float scale;
if (spriteSize.width < size.width && spriteSize.height < size.height)
{
scale = 1;
}
else if (spriteSize.width * size.height >= spriteSize.height * size.width)
{
scale = size.width / spriteSize.width;
}
else
{
scale = size.height / spriteSize.height;
}
sprite->setScale(scale);
spriteSize.width *= scale;
spriteSize.height *= scale;
offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5;
offY = (listItemSize.height - spriteSize.height) * 0.5;
sprite->setPosition(CCPoint(offX, offY));
cell->addChild(sprite);
offsetX += listItemSize.width;
}
}
++nCount;
}
}
void CCTextureWatcher::CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data)
{
}
CCSize spriteSize = sprite->getContentSize();
float scale;
if (spriteSize.width < size.width && spriteSize.height < size.height)
{
scale = 1;
}
else if (spriteSize.width * size.height >= spriteSize.height * size.width)
{
scale = size.width / spriteSize.width;
}
else
{
scale = size.height / spriteSize.height;
}
sprite->setScale(scale);
spriteSize.width *= scale;
spriteSize.height *= scale;
offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5;
offY = (listItemSize.height - spriteSize.height) * 0.5;
sprite->setPosition(CCPoint(offX, offY));
cell->addChild(sprite);
offsetX += listItemSize.width;
}
}
++nCount;
}
}
void CCTextureWatcher::CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data)
{
}
void CCTextureWatcher::CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data) void CCTextureWatcher::CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data)
{ {

View File

@ -1,53 +1,53 @@
#ifndef __CCMEMLAYER_H__ #ifndef __CCMEMLAYER_H__
#define __CCMEMLAYER_H__ #define __CCMEMLAYER_H__
#include "extensions/CCListView/CCListView.h" #include "extensions/CCListView/CCListView.h"
namespace cocos2d { class CCDictionary; } namespace cocos2d { class CCDictionary; }
namespace cocos2d { class CCLabelTTF; } namespace cocos2d { class CCLabelTTF; }
namespace cocos2d { class CCMenu; } namespace cocos2d { class CCMenu; }
namespace cocos2d { class CCLayerColor; } namespace cocos2d { class CCLayerColor; }
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
class CC_DLL CCTextureWatcher :public CCObject, public CCListViewDelegate class CC_DLL CCTextureWatcher :public CCObject, public CCListViewDelegate
{ {
private: private:
CCTextureWatcher(); CCTextureWatcher();
public: public:
virtual ~CCTextureWatcher(); virtual ~CCTextureWatcher();
static CCTextureWatcher* sharedTextureWatcher(); static CCTextureWatcher* sharedTextureWatcher();
static void purgeTextureWatcher(); static void purgeTextureWatcher();
void setDisplayWatcher(bool bDisplayWatcher); void setDisplayWatcher(bool bDisplayWatcher);
void fresh(void); void fresh(void);
protected: protected:
void actionFresh(CCObject* object); void actionFresh(CCObject* object);
void actionHide(CCObject* object); void actionHide(CCObject* object);
void hide(void); void hide(void);
void dovisit(void); void dovisit(void);
static void visit(void* pSender); static void visit(void* pSender);
protected: protected:
virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data); virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data);
virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data); virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data);
virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data); virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data);
virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data); virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data);
private: private:
bool m_bDisplayWatcher; bool m_bDisplayWatcher;
bool m_bFresh; bool m_bFresh;
bool m_bHide; bool m_bHide;
CCDictionary *m_pTextures; CCDictionary *m_pTextures;
char *m_pszString; char *m_pszString;
int m_nCurrnetPage; int m_nCurrnetPage;
int m_nTotalPage; int m_nTotalPage;
CCLabelTTF *m_labelHide; CCLabelTTF *m_labelHide;
CCLabelTTF *m_labelPage; CCLabelTTF *m_labelPage;
CCMenu *m_menuHide; CCMenu *m_menuHide;
CCLayerColor *m_pLayer; CCLayerColor *m_pLayer;
CCListView *m_pList; CCListView *m_pList;
}; };
NS_CC_EXT_END NS_CC_EXT_END
#endif #endif

View File

@ -13,11 +13,6 @@ public:
virtual ~CCApplicationProtocol() {} virtual ~CCApplicationProtocol() {}
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance() = 0;
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -47,7 +47,7 @@ CCEGLViewProtocol::CCEGLViewProtocol()
, m_pDelegate(NULL) , m_pDelegate(NULL)
, m_fScreenScaleFactor(1.0f) , m_fScreenScaleFactor(1.0f)
{ {
strncpy(m_szViewName, "Cocos2d-x Game", sizeof(m_szViewName));
} }
CCEGLViewProtocol::~CCEGLViewProtocol() CCEGLViewProtocol::~CCEGLViewProtocol()
@ -171,6 +171,19 @@ float CCEGLViewProtocol::getMainScreenScale()
return -1.0f; return -1.0f;
} }
void CCEGLViewProtocol::setViewName(const char* pszViewName)
{
if (pszViewName != NULL && strlen(pszViewName) > 0)
{
strncpy(m_szViewName, pszViewName, sizeof(m_szViewName));
}
}
const char* CCEGLViewProtocol::getViewName()
{
return m_szViewName;
}
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[]) void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
{ {
CCSet set; CCSet set;

View File

@ -33,7 +33,9 @@ public:
virtual void setViewPortInPoints(float x , float y , float w , float h); virtual void setViewPortInPoints(float x , float y , float w , float h);
virtual void setScissorInPoints(float x , float y , float w , float h); virtual void setScissorInPoints(float x , float y , float w , float h);
virtual float getMainScreenScale(); virtual float getMainScreenScale();
virtual void setViewName(const char* pszViewName);
const char* getViewName();
/** handle touch events by default, if you want to custom your handles, please override these functions */ /** handle touch events by default, if you want to custom your handles, please override these functions */
virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]);
virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]);
@ -49,6 +51,7 @@ protected:
CCSize m_sSizeInPixel; CCSize m_sSizeInPixel;
CCSize m_sSizeInPoint; CCSize m_sSizeInPoint;
CCRect m_rcViewPort; CCRect m_rcViewPort;
char m_szViewName[50];
}; };
NS_CC_END NS_CC_END

View File

@ -30,11 +30,11 @@ CCApplication::~CCApplication()
int CCApplication::run() int CCApplication::run()
{ {
// Initialize instance and cocos2d. // Initialize instance and cocos2d.
if (! initInstance() || ! applicationDidFinishLaunching()) if (! applicationDidFinishLaunching())
{ {
return 0; return 0;
} }
return -1; return -1;
} }

View File

@ -52,7 +52,7 @@ void CCMessageBox(const char * pszMsg, const char * pszTitle)
void CCLuaLog(const char * pszFormat) void CCLuaLog(const char * pszFormat)
{ {
CCLog(pszFormat); CCLog(pszFormat);
} }
NS_CC_END NS_CC_END

View File

@ -47,7 +47,7 @@ CCApplication::~CCApplication()
int CCApplication::run() int CCApplication::run()
{ {
if (initInstance() && applicationDidFinishLaunching()) if (applicationDidFinishLaunching())
{ {
[[CCDirectorCaller sharedDirectorCaller] startMainLoop]; [[CCDirectorCaller sharedDirectorCaller] startMainLoop];
} }

View File

@ -60,7 +60,7 @@ void CCMessageBox(const char * pszMsg, const char * pszTitle)
void CCLuaLog(const char * pszFormat) void CCLuaLog(const char * pszFormat)
{ {
CCLog(pszFormat); CCLog(pszFormat);
} }
NS_CC_END NS_CC_END

View File

@ -43,7 +43,7 @@ int CCApplication::run()
QueryPerformanceCounter(&nLast); QueryPerformanceCounter(&nLast);
// Initialize instance and cocos2d. // Initialize instance and cocos2d.
if (! initInstance() || ! applicationDidFinishLaunching()) if (!applicationDidFinishLaunching())
{ {
return 0; return 0;
} }
@ -160,17 +160,17 @@ static void PVRFrameEnableControlWindow(bool bEnable)
return; return;
} }
const wchar_t * wszValue = L"hide_gui"; const char * szValue = "hide_gui";
const wchar_t * wszNewData = (bEnable) ? L"NO" : L"YES"; const char * szNewData = (bEnable) ? "NO" : "YES";
wchar_t wszOldData[256] = {0}; char szOldData[256] = {0};
DWORD dwSize = sizeof(wszOldData); DWORD dwSize = sizeof(szOldData);
LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, NULL, (LPBYTE)wszOldData, &dwSize); LSTATUS status = RegQueryValueEx(hKey, szValue, 0, NULL, (LPBYTE)szOldData, &dwSize);
if (ERROR_FILE_NOT_FOUND == status // the key not exist if (ERROR_FILE_NOT_FOUND == status // the key not exist
|| (ERROR_SUCCESS == status // or the hide_gui value is exist || (ERROR_SUCCESS == status // or the hide_gui value is exist
&& 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal && 0 != strcmp(szNewData, szOldData))) // but new data and old data not equal
{ {
dwSize = sizeof(wchar_t) * (wcslen(wszNewData) + 1); dwSize = sizeof(wchar_t) * (strlen(szNewData) + 1);
RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE *)wszNewData, dwSize); RegSetValueEx(hKey, szValue, 0, REG_SZ, (const BYTE *)szNewData, dwSize);
} }
RegCloseKey(hKey); RegCloseKey(hKey);

View File

@ -51,9 +51,9 @@ void CCMessageBox(const char * pszMsg, const char * pszTitle)
MessageBoxA(NULL, pszMsg, pszTitle, MB_OK); MessageBoxA(NULL, pszMsg, pszTitle, MB_OK);
} }
void CCLuaLog(const char * pszFormat) void CCLuaLog(const char * pszFormat)
{ {
CCLog(pszFormat); CCLog(pszFormat);
} }
NS_CC_END NS_CC_END

View File

@ -165,8 +165,8 @@ private:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// impliment CCEGLView // impliment CCEGLView
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
static CCEGLView * s_pMainWindow; static CCEGLView* s_pMainWindow = NULL;
static const WCHAR * kWindowClassName = L"Cocos2dxWin32"; static const char* kWindowClassName = "Cocos2dxWin32";
static LRESULT CALLBACK _WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK _WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
@ -225,7 +225,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
m_hWnd = CreateWindowEx( m_hWnd = CreateWindowEx(
WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
kWindowClassName, // Class Name kWindowClassName, // Class Name
pTitle, // Window Title m_szViewName, // Window Title
WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style
0, 0, // Window Position 0, 0, // Window Position
0, // Window Width 0, // Window Width
@ -408,7 +408,6 @@ void CCEGLView::end()
} }
s_pMainWindow = NULL; s_pMainWindow = NULL;
UnregisterClass(kWindowClassName, GetModuleHandle(NULL)); UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
delete this; delete this;
} }
@ -459,7 +458,12 @@ void CCEGLView::resize(int width, int height)
m_pEGL->resizeSurface(); m_pEGL->resizeSurface();
} }
setFrameSize(width, height); CCEGLViewProtocol::setFrameSize(width, height);
}
void CCEGLView::setFrameSize(float width, float height)
{
Create((LPCTSTR)m_szViewName, width, height);
} }
void CCEGLView::centerWindow() void CCEGLView::centerWindow()
@ -509,8 +513,12 @@ void CCEGLView::setContentScaleFactor(float contentScaleFactor)
CCEGLView& CCEGLView::sharedOpenGLView() CCEGLView& CCEGLView::sharedOpenGLView()
{ {
CC_ASSERT(s_pMainWindow); static CCEGLView* s_pEglView = NULL;
return *s_pMainWindow; if (s_pEglView == NULL)
{
s_pEglView = new CCEGLView();
}
return *s_pEglView;
} }
NS_CC_END NS_CC_END

View File

@ -37,25 +37,23 @@ class CCEGL;
class CC_DLL CCEGLView : public CCEGLViewProtocol class CC_DLL CCEGLView : public CCEGLViewProtocol
{ {
public: public:
CCEGLView(); CCEGLView();
virtual ~CCEGLView(); virtual ~CCEGLView();
bool isOpenGLReady(); /* override functions */
void end(); virtual bool isOpenGLReady();
virtual void end();
void swapBuffers(); virtual void swapBuffers();
virtual bool canSetContentScaleFactor();
bool canSetContentScaleFactor(); virtual void setContentScaleFactor(float contentScaleFactor);
void setContentScaleFactor(float contentScaleFactor); virtual void setFrameSize(float width, float height);
virtual void setIMEKeyboardState(bool bOpen);
private:
virtual bool Create(LPCTSTR pTitle, int w, int h); virtual bool Create(LPCTSTR pTitle, int w, int h);
public:
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
void setIMEKeyboardState(bool bOpen);
// win32 platform function // win32 platform function
HWND getHWnd(); HWND getHWnd();
void resize(int width, int height); void resize(int width, int height);
@ -65,7 +63,6 @@ public:
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook ); void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
// static function // static function
/** /**
@brief get the shared main open gl window @brief get the shared main open gl window
*/ */

View File

@ -60,39 +60,11 @@ public:
// release temp font resource // release temp font resource
if (m_curFontPath.size() > 0) if (m_curFontPath.size() > 0)
{ {
wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath); RemoveFontResource(m_curFontPath.c_str());
if (pwszBuffer) SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
{
RemoveFontResource(pwszBuffer);
SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
delete [] pwszBuffer;
pwszBuffer = NULL;
}
} }
} }
wchar_t * utf8ToUtf16(std::string nString)
{
wchar_t * pwszBuffer = NULL;
do
{
if (nString.size() < 0)
{
break;
}
// utf-8 to utf-16
int nLen = nString.size();
int nBufLen = nLen + 1;
pwszBuffer = new wchar_t[nBufLen];
CC_BREAK_IF(! pwszBuffer);
memset(pwszBuffer,0,nBufLen);
nLen = MultiByteToWideChar(CP_UTF8, 0, nString.c_str(), nLen, pwszBuffer, nBufLen);
pwszBuffer[nLen] = '\0';
} while (0);
return pwszBuffer;
}
bool setFont(const char * pFontName = NULL, int nSize = 0) bool setFont(const char * pFontName = NULL, int nSize = 0)
{ {
bool bRet = false; bool bRet = false;
@ -141,31 +113,20 @@ public:
// release old font register // release old font register
if (m_curFontPath.size() > 0) if (m_curFontPath.size() > 0)
{ {
wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath); if(RemoveFontResource(m_curFontPath.c_str()))
if (pwszBuffer)
{ {
if(RemoveFontResource(pwszBuffer)) SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
{ }
SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
}
delete [] pwszBuffer;
pwszBuffer = NULL;
}
} }
fontPath.size()>0?(m_curFontPath = fontPath):(m_curFontPath.clear()); fontPath.size()>0?(m_curFontPath = fontPath):(m_curFontPath.clear());
// register temp font // register temp font
if (m_curFontPath.size() > 0) if (m_curFontPath.size() > 0)
{ {
wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath); if(AddFontResource(m_curFontPath.c_str()))
if (pwszBuffer)
{ {
if(AddFontResource(pwszBuffer)) SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
{ }
SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
}
delete [] pwszBuffer;
pwszBuffer = NULL;
}
} }
} }
m_hFont = NULL; m_hFont = NULL;

View File

@ -21,7 +21,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="2" ConfigurationType="2"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
@ -104,7 +104,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="2" ConfigurationType="2"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"

View File

@ -1 +1 @@
99a350af562498cb7fcbaec3063f86f9d05889fe 215941887bb3ecde65ca64e6e1b5ddaacded6a7c

View File

@ -21,7 +21,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="4" ConfigurationType="4"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
@ -87,7 +87,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="4" ConfigurationType="4"
CharacterSet="1" CharacterSet="2"
WholeProgramOptimization="1" WholeProgramOptimization="1"
> >
<Tool <Tool

View File

@ -22,36 +22,6 @@ AppDelegate::~AppDelegate()
{ {
} }
bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// OpenGLView is initialized in AppDelegate.mm on ios platform, nothing need to do here.
#endif // CC_PLATFORM_IOS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// OpenGLView is initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
#endif // CC_PLATFORM_ANDROID
bRet = true;
} while (0);
return bRet;
}
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director

View File

@ -22,11 +22,6 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -22,36 +22,6 @@ AppDelegate::~AppDelegate()
{ {
} }
bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// OpenGLView is initialized in AppDelegate.mm on ios platform, nothing need to do here.
#endif // CC_PLATFORM_IOS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// OpenGLView is initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
#endif // CC_PLATFORM_ANDROID
bRet = true;
} while (0);
return bRet;
}
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director

View File

@ -22,10 +22,6 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.

View File

@ -22,36 +22,6 @@ AppDelegate::~AppDelegate()
{ {
} }
bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// OpenGLView is initialized in AppDelegate.mm on ios platform, nothing need to do here.
#endif // CC_PLATFORM_IOS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// OpenGLView is initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
#endif // CC_PLATFORM_ANDROID
bRet = true;
} while (0);
return bRet;
}
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director

View File

@ -22,11 +22,6 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -35,40 +35,6 @@ AppDelegate::~AppDelegate()
CCScriptEngineManager::purgeSharedManager(); CCScriptEngineManager::purgeSharedManager();
} }
bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), CC_WIDTH, CC_HEIGHT));
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
#endif // CC_PLATFORM_IOS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
#endif // CC_PLATFORM_ANDROID
bRet = true;
} while (0);
return bRet;
}
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director

View File

@ -14,11 +14,6 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -16,70 +16,6 @@ AppDelegate::~AppDelegate()
// SimpleAudioEngine::end(); // SimpleAudioEngine::end();
} }
bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The tests is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: tests"), 480, 320));
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
#endif // CC_PLATFORM_IOS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// Android doesn't need to do anything.
#endif // CC_PLATFORM_ANDROID
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationLandscapeLeft);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create("cocos2d: tests", 480, 320, 480, 320));
//set the base resource folder pay attention to add "/"
CCFileUtils::setResourcePath("../Resources/");
#endif // CC_PLATFORM_LINUX
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320));
pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE);
CCFileUtils::setResourcePath("/Res/");
#endif // CC_PLATFORM_BADA
#if (CC_TARGET_PLATFORM == CC_PLATFORM_QNX)
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(1024, 600));
CCFileUtils::setResourcePath("app/native/Resources");
#endif // CC_PLATFORM_QNX
bRet = true;
} while (0);
return bRet;
}
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director

View File

@ -14,11 +14,6 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -27,9 +27,8 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
{ {
CCEGLView *view = &CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h); view->setFrameSize(w, h);
// if you want to run in WVGA with HVGA resource, set it // set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// view->setDesignResolutionSize(480, 320); // view.setDesignResolutionSize(480, 320);
CCDirector::sharedDirector()->setOpenGLView(view);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();

View File

@ -1,6 +1,8 @@
#include "main.h" #include "main.h"
#include "AppDelegate.h" #include "AppDelegate.h"
#include "CCEGLView.h"
USING_NS_CC;
int APIENTRY _tWinMain(HINSTANCE hInstance, int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
@ -12,6 +14,11 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setViewName("Hello Tests");
eglView.setFrameSize(480, 320);
// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320);
return cocos2d::CCApplication::sharedApplication().run(); return CCApplication::sharedApplication().run();
} }

View File

@ -21,7 +21,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1" ConfigurationType="1"
CharacterSet="1" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
@ -98,7 +98,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32" OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32" IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1" ConfigurationType="1"
CharacterSet="1" CharacterSet="2"
WholeProgramOptimization="1" WholeProgramOptimization="1"
> >
<Tool <Tool

View File

@ -5,12 +5,19 @@
enum enum
{ {
MAX_COUNT = 3,
LINE_SPACE = 40, LINE_SPACE = 40,
kItemTagBasic = 1000, kItemTagBasic = 1000,
}; };
static const std::string testsName[MAX_COUNT] = enum
{
TEST_NOTIFICATIONCENTER = 0,
TEST_CCCONTROLBUTTON,
TEST_TEXTUREWATCHER,
TEST_MAX_COUNT
};
static const std::string testsName[TEST_MAX_COUNT] =
{ {
"NotificationCenterTest", "NotificationCenterTest",
"CCControlButtonTest", "CCControlButtonTest",
@ -32,7 +39,7 @@ void ExtensionsMainLayer::onEnter()
pMenu->setPosition( CCPointZero ); pMenu->setPosition( CCPointZero );
CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
for (int i = 0; i < MAX_COUNT; ++i) for (int i = 0; i < TEST_MAX_COUNT; ++i)
{ {
CCMenuItemFont* pItem = CCMenuItemFont::itemWithString(testsName[i].c_str(), this, CCMenuItemFont* pItem = CCMenuItemFont::itemWithString(testsName[i].c_str(), this,
menu_selector(ExtensionsMainLayer::menuCallback)); menu_selector(ExtensionsMainLayer::menuCallback));
@ -50,17 +57,19 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender)
switch (nIndex) switch (nIndex)
{ {
case 0: case TEST_NOTIFICATIONCENTER:
runNotificationCenterTest(); {
runNotificationCenterTest();
}
break; break;
case 1: case TEST_CCCONTROLBUTTON:
{ {
CCControlSceneManager* pManager = CCControlSceneManager::sharedControlSceneManager(); CCControlSceneManager* pManager = CCControlSceneManager::sharedControlSceneManager();
CCScene* pScene = pManager->currentControlScene(); CCScene* pScene = pManager->currentControlScene();
CCDirector::sharedDirector()->replaceScene(pScene); CCDirector::sharedDirector()->replaceScene(pScene);
} }
break; break;
case 2: case TEST_TEXTUREWATCHER:
{ {
static bool s_bOpened = false; static bool s_bOpened = false;
s_bOpened = !s_bOpened; s_bOpened = !s_bOpened;

View File

@ -7,28 +7,32 @@
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
using namespace cocos2d; using namespace cocos2d;
using namespace cocos2d::extension;
extern "C" extern "C"
{ {
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{ {
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView()) if (!CCDirector::sharedDirector()->getOpenGLView())
{ {
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setFrameWidthAndHeight(w, h); view->setFrameSize(w, h);
// if you want to run in WVGA with HVGA resource, set it // set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
view->create(480, 320); // view.setDesignResolutionSize(480, 320);
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
cocos2d::CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();
} }
else else
{ {
cocos2d::CCTextureCache::reloadAllTextures(); CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
cocos2d::CCDirector::sharedDirector()->setGLDefaultValues(); CCTextureCache::reloadAllTextures();
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
CCDirector::sharedDirector()->setGLDefaultValues();
} }
} }
} }