diff --git a/cocos2d-win32.vc2008.sln b/cocos2d-win32.vc2008.sln index dd1ab744ef..ca7149895b 100644 --- a/cocos2d-win32.vc2008.sln +++ b/cocos2d-win32.vc2008.sln @@ -41,6 +41,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestJavascript", "samples\T EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libExtensions", "extensions\proj.win32\libExtensions.vcproj", "{21B2C324-891F-48EA-AD1A-5AE13DE12E28}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestLua", "samples\TestLua\proj.win32\TestLua.win32.vcproj", "{B53D3C68-96DA-4806-BB26-94888B52191A}" + ProjectSection(ProjectDependencies) = postProject + {21B2C324-891F-48EA-AD1A-5AE13DE12E28} = {21B2C324-891F-48EA-AD1A-5AE13DE12E28} + {DDC3E27F-004D-4DD4-9DD3-931A013D2159} = {DDC3E27F-004D-4DD4-9DD3-931A013D2159} + {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} + {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} + {929480E7-23C0-4DF6-8456-096D71547116} = {929480E7-23C0-4DF6-8456-096D71547116} + {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} + EndProjectSection +EndProject Global GlobalSection(DPCodeReviewSolutionGUID) = preSolution DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} @@ -90,6 +100,10 @@ Global {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Debug|Win32.Build.0 = Debug|Win32 {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Release|Win32.ActiveCfg = Release|Win32 {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Release|Win32.Build.0 = Release|Win32 + {B53D3C68-96DA-4806-BB26-94888B52191A}.Debug|Win32.ActiveCfg = Debug|Win32 + {B53D3C68-96DA-4806-BB26-94888B52191A}.Debug|Win32.Build.0 = Debug|Win32 + {B53D3C68-96DA-4806-BB26-94888B52191A}.Release|Win32.ActiveCfg = Release|Win32 + {B53D3C68-96DA-4806-BB26-94888B52191A}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/cocos2d-win32.vc2010.sln b/cocos2d-win32.vc2010.sln index 46776c2f89..d9fa21faab 100644 --- a/cocos2d-win32.vc2010.sln +++ b/cocos2d-win32.vc2010.sln @@ -21,10 +21,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestJavascript", "samples\T EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libExtensions", "extensions\proj.win32\libExtensions.vcxproj", "{21B2C324-891F-48EA-AD1A-5AE13DE12E28}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestLua", "samples\TestLua\proj.win32\TestLua.win32.vcxproj", "{4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}" + ProjectSection(ProjectDependencies) = postProject + {21B2C324-891F-48EA-AD1A-5AE13DE12E28} = {21B2C324-891F-48EA-AD1A-5AE13DE12E28} + {DDC3E27F-004D-4DD4-9DD3-931A013D2159} = {DDC3E27F-004D-4DD4-9DD3-931A013D2159} + {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} + {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} + {929480E7-23C0-4DF6-8456-096D71547116} = {929480E7-23C0-4DF6-8456-096D71547116} + {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} + EndProjectSection +EndProject Global - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Release|Win32 = Release|Win32 @@ -70,8 +77,15 @@ Global {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Debug|Win32.Build.0 = Debug|Win32 {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Release|Win32.ActiveCfg = Release|Win32 {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Release|Win32.Build.0 = Release|Win32 + {4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Debug|Win32.ActiveCfg = Debug|Win32 + {4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Debug|Win32.Build.0 = Debug|Win32 + {4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Release|Win32.ActiveCfg = Release|Win32 + {4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection EndGlobal diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index 543985d848..84edeb5e43 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -82,6 +82,7 @@ platform/android/CCApplication.cpp \ platform/android/CCCommon.cpp \ platform/android/CCFileUtils.cpp \ platform/android/CCImage.cpp \ +platform/android/jni/EditBoxJni.cpp \ platform/android/jni/JniHelper.cpp \ platform/android/jni/IMEJni.cpp \ platform/android/jni/MessageJni.cpp \ diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index a9099c5897..9eb2ac492a 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -733,7 +733,7 @@ void CCDirector::showStats(void) sprintf(m_pszFPS, "%.1f", m_fFrameRate); m_pFPSLabel->setString(m_pszFPS); - sprintf(m_pszFPS, "%4d", g_uNumberOfDraws); + sprintf(m_pszFPS, "%4lu", (unsigned long)g_uNumberOfDraws); m_pDrawsLabel->setString(m_pszFPS); } @@ -953,7 +953,7 @@ void CCDisplayLinkDirector::startAnimation(void) } m_bInvalid = false; - CCApplication::sharedApplication().setAnimationInterval(m_dAnimationInterval); + CCApplication::sharedApplication()->setAnimationInterval(m_dAnimationInterval); } void CCDisplayLinkDirector::mainLoop(void) diff --git a/cocos2dx/actions/CCActionInstant.cpp b/cocos2dx/actions/CCActionInstant.cpp index 8a96c919d1..b4466420fa 100644 --- a/cocos2dx/actions/CCActionInstant.cpp +++ b/cocos2dx/actions/CCActionInstant.cpp @@ -27,6 +27,7 @@ #include "CCActionInstant.h" #include "base_nodes/CCNode.h" #include "sprite_nodes/CCSprite.h" +#include "script_support/CCScriptSupport.h" #include "cocoa/CCZone.h" NS_CC_BEGIN @@ -376,6 +377,20 @@ CCCallFunc * CCCallFunc::create(CCObject* pSelectorTarget, SEL_CallFunc selector return NULL; } +CCCallFunc * CCCallFunc::create(int nHandler) +{ + CCCallFunc *pRet = new CCCallFunc(); + + if (pRet) { + pRet->m_nScriptHandler = nHandler; + pRet->autorelease(); + } + else{ + CC_SAFE_DELETE(pRet); + } + return pRet; +} + bool CCCallFunc::initWithTarget(CCObject* pSelectorTarget) { if (pSelectorTarget) { @@ -419,6 +434,9 @@ void CCCallFunc::execute() { if (m_pCallFunc) { (m_pSelectorTarget->*m_pCallFunc)(); } + if (m_nScriptHandler) { + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionByHandler(m_nScriptHandler); + } } // @@ -428,6 +446,9 @@ void CCCallFuncN::execute() { if (m_pCallFuncN) { (m_pSelectorTarget->*m_pCallFuncN)(m_pTarget); } + if (m_nScriptHandler) { + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithCCObject(m_nScriptHandler, m_pTarget, "CCNode"); + } } CCCallFuncN * CCCallFuncN::actionWithTarget(CCObject* pSelectorTarget, SEL_CallFuncN selector) @@ -449,6 +470,20 @@ CCCallFuncN * CCCallFuncN::create(CCObject* pSelectorTarget, SEL_CallFuncN selec return NULL; } +CCCallFuncN * CCCallFuncN::create(int nHandler) +{ + CCCallFuncN *pRet = new CCCallFuncN(); + + if (pRet) { + pRet->m_nScriptHandler = nHandler; + pRet->autorelease(); + } + else{ + CC_SAFE_DELETE(pRet); + } + return pRet; +} + bool CCCallFuncN::initWithTarget(CCObject* pSelectorTarget, SEL_CallFuncN selector) { if (CCCallFunc::initWithTarget(pSelectorTarget)) { diff --git a/cocos2dx/actions/CCActionInstant.h b/cocos2dx/actions/CCActionInstant.h index 6b77ff69af..776c33e307 100644 --- a/cocos2dx/actions/CCActionInstant.h +++ b/cocos2dx/actions/CCActionInstant.h @@ -215,6 +215,7 @@ public: CCCallFunc() : m_pSelectorTarget(NULL) , m_pCallFunc(NULL) + , m_nScriptHandler(0) { } virtual ~CCCallFunc() @@ -233,7 +234,10 @@ public: */ static CCCallFunc * create(CCObject* pSelectorTarget, SEL_CallFunc selector); - /** initializes the action with the callback + /** creates the action with the handler script function */ + static CCCallFunc * create(int nHandler); + + /** initializes the action with the callback typedef void (CCObject::*SEL_CallFunc)(); */ @@ -263,6 +267,8 @@ protected: /** Target that will be called */ CCObject* m_pSelectorTarget; + int m_nScriptHandler; + union { SEL_CallFunc m_pCallFunc; @@ -292,6 +298,10 @@ public: typedef void (CCObject::*SEL_CallFuncN)(CCNode*); */ static CCCallFuncN * create(CCObject* pSelectorTarget, SEL_CallFuncN selector); + + /** creates the action with the handler script function */ + static CCCallFuncN * create(int nHandler); + /** initializes the action with the callback typedef void (CCObject::*SEL_CallFuncN)(CCNode*); diff --git a/cocos2dx/actions/CCActionInterval.cpp b/cocos2dx/actions/CCActionInterval.cpp index e7e97b33f0..2b86dcf7c3 100644 --- a/cocos2dx/actions/CCActionInterval.cpp +++ b/cocos2dx/actions/CCActionInterval.cpp @@ -335,6 +335,12 @@ void CCSequence::update(float t) } } + // Last action found and it is done. + if( found == m_last && m_pActions[found]->isDone() ) + { + return; + } + // New action. Start it. if( found != m_last ) { diff --git a/cocos2dx/cocos2d.cpp b/cocos2dx/cocos2d.cpp index 4a0ff0ce08..23bb23fb79 100644 --- a/cocos2dx/cocos2d.cpp +++ b/cocos2dx/cocos2d.cpp @@ -30,7 +30,7 @@ NS_CC_BEGIN const char* cocos2dVersion() { - return "cocos2d-2.0-rc2-x-2.0.1"; + return "cocos2d-2.0-x-2.0.2"; } NS_CC_END diff --git a/cocos2dx/include/ccConfig.h b/cocos2dx/include/ccConfig.h index 8e40900378..4b3c3ba753 100755 --- a/cocos2dx/include/ccConfig.h +++ b/cocos2dx/include/ccConfig.h @@ -165,7 +165,7 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios. */ #ifndef CC_TEXTURE_ATLAS_USE_VAO - #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) #define CC_TEXTURE_ATLAS_USE_VAO 1 #else /* Some android devices cannot support VAO very well, so we disable it by default for android platform. */ diff --git a/cocos2dx/label_nodes/CCLabelBMFont.cpp b/cocos2dx/label_nodes/CCLabelBMFont.cpp index a697e9ca4c..931a2682d3 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.cpp +++ b/cocos2dx/label_nodes/CCLabelBMFont.cpp @@ -251,7 +251,7 @@ static void cc_utf8_trim_ws(std::vector* str) * * Return value: the length of the string in characters **/ -static long +long cc_utf8_strlen (const char * p, int max) { long len = 0; diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index 6aad45fc42..9839d7e0a7 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -216,7 +216,7 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma //create and attach depth buffer glGenRenderbuffers(1, &m_uDepthRenderBufffer); glBindRenderbuffer(GL_RENDERBUFFER, m_uDepthRenderBufffer); - glRenderbufferStorage(GL_RENDERBUFFER, uDepthStencilFormat, powW, powH); + glRenderbufferStorage(GL_RENDERBUFFER, uDepthStencilFormat, (GLsizei)powW, (GLsizei)powH); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_uDepthRenderBufffer); // if depth format is the one with stencil part, bind same render buffer as stencil attachment diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index 57c161402a..f6b5e709a6 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -149,6 +149,7 @@ void CCEGLViewProtocol::setTouchDelegate(EGLTouchDelegate * pDelegate) bool CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor) { + m_fScaleX = m_fScaleY = contentScaleFactor; return false; } diff --git a/cocos2dx/platform/android/CCApplication.cpp b/cocos2dx/platform/android/CCApplication.cpp index 0702b144ac..d475346c4c 100644 --- a/cocos2dx/platform/android/CCApplication.cpp +++ b/cocos2dx/platform/android/CCApplication.cpp @@ -69,10 +69,10 @@ CCApplication::Orientation CCApplication::setOrientation(Orientation orientation ////////////////////////////////////////////////////////////////////////// // static member function ////////////////////////////////////////////////////////////////////////// -CCApplication& CCApplication::sharedApplication() +CCApplication* CCApplication::sharedApplication() { CC_ASSERT(sm_pSharedApplication); - return *sm_pSharedApplication; + return sm_pSharedApplication; } ccLanguageType CCApplication::getCurrentLanguage() diff --git a/cocos2dx/platform/android/CCApplication.h b/cocos2dx/platform/android/CCApplication.h index 8a6308fade..8e42f45b9b 100644 --- a/cocos2dx/platform/android/CCApplication.h +++ b/cocos2dx/platform/android/CCApplication.h @@ -48,7 +48,7 @@ public: @brief Get current applicaiton instance. @return Current application instance pointer. */ - static CCApplication& sharedApplication(); + static CCApplication* sharedApplication(); /** @brief Get current language config diff --git a/cocos2dx/platform/android/CCEGLView.cpp b/cocos2dx/platform/android/CCEGLView.cpp index 74bdc3ea81..21999b51f6 100644 --- a/cocos2dx/platform/android/CCEGLView.cpp +++ b/cocos2dx/platform/android/CCEGLView.cpp @@ -27,6 +27,7 @@ THE SOFTWARE. #include "ccMacros.h" #include "touch_dispatcher/CCTouchDispatcher.h" #include "jni/IMEJni.h" +#include "jni/EditBoxJni.h" #include "jni/MessageJni.h" #include "CCGL.h" @@ -76,15 +77,14 @@ void CCEGLView::swapBuffers() { } -CCEGLView& CCEGLView::sharedOpenGLView() +CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView instance; - return instance; + return &instance; } void CCEGLView::setIMEKeyboardState(bool bOpen) { - setKeyboardStateJNI((int)bOpen); } diff --git a/cocos2dx/platform/android/CCEGLView.h b/cocos2dx/platform/android/CCEGLView.h index 7a3b6360c7..a1ed6688d2 100644 --- a/cocos2dx/platform/android/CCEGLView.h +++ b/cocos2dx/platform/android/CCEGLView.h @@ -47,7 +47,7 @@ public: /** @brief get the shared main open gl window */ - static CCEGLView& sharedOpenGLView(); + static CCEGLView* sharedOpenGLView(); }; NS_CC_END diff --git a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java index 80a0e002ec..832a356748 100644 --- a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java @@ -28,6 +28,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; +import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -40,6 +41,8 @@ import android.util.DisplayMetrics; import android.util.Log; public class Cocos2dxActivity extends Activity{ + + protected Cocos2dxGLSurfaceView mGLView; private static Cocos2dxMusic backgroundMusicPlayer; private static Cocos2dxSound soundPlayer; private static Cocos2dxAccelerometer accelerometer; @@ -47,11 +50,18 @@ public class Cocos2dxActivity extends Activity{ private static boolean accelerometerEnabled = false; private static Handler handler; private final static int HANDLER_SHOW_DIALOG = 1; + private final static int HANDLER_SHOW_EDITBOX_DIALOG = 2; + private static String packageName; - + private static native void nativeSetPaths(String apkPath); + private static native void nativeSetEditboxText(byte[] text); + + public Cocos2dxGLSurfaceView getGLView() { + return mGLView; + } - @Override + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -76,6 +86,9 @@ public class Cocos2dxActivity extends Activity{ case HANDLER_SHOW_DIALOG: showDialog(((DialogMessage)msg.obj).title, ((DialogMessage)msg.obj).message); break; + case HANDLER_SHOW_EDITBOX_DIALOG: + onShowEditBoxDialog((EditBoxMessage)msg.obj); + break; } } }; @@ -254,6 +267,42 @@ public class Cocos2dxActivity extends Activity{ dialog.show(); } + + private static void showEditBoxDialog(String title, String content, int inputMode, int inputFlag, int returnType, int maxLength) + { + Message msg = new Message(); + msg.what = HANDLER_SHOW_EDITBOX_DIALOG; + msg.obj = new EditBoxMessage(title, content, inputMode, inputFlag, returnType, maxLength); + handler.sendMessage(msg); + } + + private void onShowEditBoxDialog(EditBoxMessage msg) + { + Dialog dialog = new Cocos2dxEditBoxDialog(this, msg); + dialog.show(); + } + + public void setEditBoxResult(String editResult) + { + Log.i("editbox_content", editResult); + + try + { + final byte[] bytesUTF8 = editResult.getBytes("UTF8"); + // pass utf8 string from editbox activity to native. + // Should invoke native method in GL thread. + mGLView.queueEvent(new Runnable() { + @Override + public void run() { + nativeSetEditboxText(bytesUTF8); + } + }); + } + catch (java.io.UnsupportedEncodingException e) + { + e.printStackTrace(); + } + } } class DialogMessage { @@ -265,3 +314,21 @@ class DialogMessage { this.title = title; } } + +class EditBoxMessage { + public String title; + public String content; + public int inputMode; + public int inputFlag; + public int returnType; + public int maxLength; + + public EditBoxMessage(String title, String content, int inputMode, int inputFlag, int returnType, int maxLength){ + this.content = content; + this.title = title; + this.inputMode = inputMode; + this.inputFlag = inputFlag; + this.returnType = returnType; + this.maxLength = maxLength; + } +} diff --git a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java index 4b3d0c6788..faf7d14db0 100644 --- a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java +++ b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java @@ -32,9 +32,15 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.Paint.Align; import android.graphics.Paint.FontMetricsInt; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.TextPaint; +import android.text.TextUtils; +import android.text.style.StyleSpan; import android.util.Log; public class Cocos2dxBitmap{ @@ -410,4 +416,43 @@ public class Cocos2dxBitmap{ } private static native void nativeInitBitmapDC(int width, int height, byte[] pixels); + + private static int getFontSizeAccordingHeight(int height) + { + Paint paint = new Paint(); + Rect bounds = new Rect(); + + paint.setTypeface(Typeface.DEFAULT); + int incr_text_size = 1; + boolean found_desired_size = false; + + while (!found_desired_size) { + + paint.setTextSize(incr_text_size); + String text = "SghMNy"; + paint.getTextBounds(text, 0, text.length(), bounds); + + incr_text_size++; + + if (height - bounds.height() <= 2) { + found_desired_size = true; + } + Log.d("font size", "incr size:" + incr_text_size); + } + return incr_text_size; + } + + private static String getStringWithEllipsis(String originalText, float width, float fontSize){ + if(TextUtils.isEmpty(originalText)){ + return ""; + } + + TextPaint paint = new TextPaint(); + paint.setTypeface(Typeface.DEFAULT); + paint.setTextSize(fontSize); + + return TextUtils.ellipsize(originalText, paint, width, + TextUtils.TruncateAt.valueOf("END")).toString(); + } + } diff --git a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java new file mode 100755 index 0000000000..3b187c6d42 --- /dev/null +++ b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java @@ -0,0 +1,318 @@ +package org.cocos2dx.lib; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.Handler; +import android.text.InputFilter; +import android.text.InputType; +import android.util.Log; +import android.util.TypedValue; +import android.view.KeyEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.TextView.OnEditorActionListener; + +public class Cocos2dxEditBoxDialog extends Dialog { + + /** + * The user is allowed to enter any text, including line breaks. + */ + private final int kEditBoxInputModeAny = 0; + + /** + * The user is allowed to enter an e-mail address. + */ + private final int kEditBoxInputModeEmailAddr = 1; + + /** + * The user is allowed to enter an integer value. + */ + private final int kEditBoxInputModeNumeric = 2; + + /** + * The user is allowed to enter a phone number. + */ + private final int kEditBoxInputModePhoneNumber = 3; + + /** + * The user is allowed to enter a URL. + */ + private final int kEditBoxInputModeUrl = 4; + + /** + * The user is allowed to enter a real number value. + * This extends kEditBoxInputModeNumeric by allowing a decimal point. + */ + private final int kEditBoxInputModeDecimal = 5; + + /** + * The user is allowed to enter any text, except for line breaks. + */ + private final int kEditBoxInputModeSingleLine = 6; + + + /** + * Indicates that the text entered is confidential data that should be + * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE. + */ + private final int kEditBoxInputFlagPassword = 0; + + /** + * Indicates that the text entered is sensitive data that the + * implementation must never store into a dictionary or table for use + * in predictive, auto-completing, or other accelerated input schemes. + * A credit card number is an example of sensitive data. + */ + private final int kEditBoxInputFlagSensitive = 1; + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each word should be capitalized. + */ + private final int kEditBoxInputFlagInitialCapsWord = 2; + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each sentence should be capitalized. + */ + private final int kEditBoxInputFlagInitialCapsSentence = 3; + + /** + * Capitalize all characters automatically. + */ + private final int kEditBoxInputFlagInitialCapsAllCharacters = 4; + + private final int kKeyboardReturnTypeDefault = 0; + private final int kKeyboardReturnTypeDone = 1; + private final int kKeyboardReturnTypeSend = 2; + private final int kKeyboardReturnTypeSearch = 3; + private final int kKeyboardReturnTypeGo = 4; + + // + private EditText mInputEditText = null; + private TextView mTextViewTitle = null; + private int mInputMode = 0; + private int mInputFlag = 0; + private int mReturnType = 0; + private int mMaxLength = -1; + + private int mInputFlagConstraints = 0x00000; + private int mInputModeContraints = 0x00000; + private boolean mIsMultiline = false; + private Cocos2dxActivity mParentActivity = null; + private EditBoxMessage mMsg = null; + + public Cocos2dxEditBoxDialog(Context context, EditBoxMessage msg) { + //super(context, R.style.Theme_Translucent); + super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); + // TODO Auto-generated constructor stub + mParentActivity = (Cocos2dxActivity)context; + mMsg = msg; + } + + // Converting dips to pixels + private int convertDipsToPixels(float dips) + { + float scale = getContext().getResources().getDisplayMetrics().density; + return Math.round(dips * scale); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + // TODO Auto-generated method stub + super.onCreate(savedInstanceState); + + getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000)); + + LinearLayout layout = new LinearLayout(mParentActivity); + layout.setOrientation(LinearLayout.VERTICAL); + + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup. + LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT); + + mTextViewTitle = new TextView(mParentActivity); + LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10); + mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); + layout.addView(mTextViewTitle, textviewParams); + + mInputEditText = new EditText(mParentActivity); + LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10); + + layout.addView(mInputEditText, editTextParams); + + setContentView(layout, layoutParams); + + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + + mInputMode = mMsg.inputMode; + mInputFlag = mMsg.inputFlag; + mReturnType = mMsg.returnType; + mMaxLength = mMsg.maxLength; + + mTextViewTitle.setText(mMsg.title); + mInputEditText.setText(mMsg.content); + + int oldImeOptions = mInputEditText.getImeOptions(); + mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI); + oldImeOptions = mInputEditText.getImeOptions(); + + switch (mInputMode) + { + case kEditBoxInputModeAny: + mInputModeContraints = + InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_FLAG_MULTI_LINE; + break; + case kEditBoxInputModeEmailAddr: + mInputModeContraints = + InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; + break; + case kEditBoxInputModeNumeric: + mInputModeContraints = + InputType.TYPE_CLASS_NUMBER | + InputType.TYPE_NUMBER_FLAG_SIGNED; + break; + case kEditBoxInputModePhoneNumber: + mInputModeContraints = InputType.TYPE_CLASS_PHONE; + break; + case kEditBoxInputModeUrl: + mInputModeContraints = + InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_URI; + break; + case kEditBoxInputModeDecimal: + mInputModeContraints = + InputType.TYPE_CLASS_NUMBER | + InputType.TYPE_NUMBER_FLAG_DECIMAL | + InputType.TYPE_NUMBER_FLAG_SIGNED; + break; + case kEditBoxInputModeSingleLine: + mInputModeContraints = InputType.TYPE_CLASS_TEXT; + break; + default: + + break; + } + + if ( mIsMultiline ) { + mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE; + } + + mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints); + + switch (mInputFlag) + { + case kEditBoxInputFlagPassword: + mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; + break; + case kEditBoxInputFlagSensitive: + mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; + break; + case kEditBoxInputFlagInitialCapsWord: + mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS; + break; + case kEditBoxInputFlagInitialCapsSentence: + mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; + break; + case kEditBoxInputFlagInitialCapsAllCharacters: + mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; + break; + default: + break; + } + mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints); + + switch (mReturnType) { + case kKeyboardReturnTypeDefault: + mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); + break; + case kKeyboardReturnTypeDone: + mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE); + break; + case kKeyboardReturnTypeSend: + mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND); + break; + case kKeyboardReturnTypeSearch: + mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH); + break; + case kKeyboardReturnTypeGo: + mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO); + break; + default: + mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); + break; + } + + if (mMaxLength > 0) { + mInputEditText.setFilters( + new InputFilter[] { + new InputFilter.LengthFilter(mMaxLength) + } + ); + } + + Handler initHandler = new Handler(); + initHandler.postDelayed(new Runnable() { + public void run() { + mInputEditText.requestFocus(); + mInputEditText.setSelection(mInputEditText.length()); + openKeyboard(); + } + }, 200); + + mInputEditText.setOnEditorActionListener(new OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + // if user didn't set keyboard type, + // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP' + if (actionId != EditorInfo.IME_NULL + || (actionId == EditorInfo.IME_NULL + && event != null + && event.getAction() == KeyEvent.ACTION_DOWN)) + { + //Log.d("EditBox", "actionId: "+actionId +",event: "+event); + mParentActivity.setEditBoxResult(mInputEditText.getText().toString()); + closeKeyboard(); + dismiss(); + return true; + } + return false; + } + }); + } + + private void openKeyboard() { + InputMethodManager imm = (InputMethodManager) mParentActivity.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mInputEditText, 0); + Log.d("Cocos2dxEditBox", "openKeyboard"); + } + + private void closeKeyboard() { + InputMethodManager imm = (InputMethodManager) mParentActivity.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(mInputEditText.getWindowToken(), 0); + Log.d("Cocos2dxEditBox", "closeKeyboard"); + } + + @Override + protected void onStop() { + // TODO Auto-generated method stub + super.onStop(); + Log.d("EditBox", "onStop..."); + } +} diff --git a/cocos2dx/platform/android/jni/EditBoxJni.cpp b/cocos2dx/platform/android/jni/EditBoxJni.cpp new file mode 100644 index 0000000000..6e34af184d --- /dev/null +++ b/cocos2dx/platform/android/jni/EditBoxJni.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +Copyright (c) 2012 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "EditBoxJni.h" +#include "text_input_node/CCIMEDispatcher.h" +#include "JniHelper.h" + +#include +#include +#include + +#if 0 +#define LOG_TAG "EditBoxJni" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) +#else +#define LOGD(...) +#endif + +using namespace cocos2d; + +static EditBoxCallback s_pfEditBoxCB = NULL; +static void* s_ctx = NULL; + +extern "C" +{ +////////////////////////////////////////////////////////////////////////// +// handle EditBox message +////////////////////////////////////////////////////////////////////////// + + + +void showEditBoxDialogJni(const char* pszTitle, + const char* pszContent, + int nInputMode, + int nInputFlag, + int nReturnType, + int nMaxLength, + EditBoxCallback pfEditBoxCB, + void* ctx) +{ + LOGD("showEditBoxDialogJni..."); + + if (pszContent == NULL) { + return; + } + + s_pfEditBoxCB = pfEditBoxCB; + s_ctx = ctx; + + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t + , "org/cocos2dx/lib/Cocos2dxActivity" + , "showEditBoxDialog" + , "(Ljava/lang/String;Ljava/lang/String;IIII)V")) + { + jstring stringArg1; + + if (!pszTitle) + { + stringArg1 = t.env->NewStringUTF(""); + } + else + { + stringArg1 = t.env->NewStringUTF(pszTitle); + } + + jstring stringArg2 = t.env->NewStringUTF(pszContent); + + t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2, nInputMode, nInputFlag, nReturnType, nMaxLength); + + t.env->DeleteLocalRef(stringArg1); + t.env->DeleteLocalRef(stringArg2); + t.env->DeleteLocalRef(t.classID); + } +} + +void JNICALL Java_org_cocos2dx_lib_Cocos2dxActivity_nativeSetEditboxText(JNIEnv * env, jobject obj, jbyteArray text) +{ + jsize size = env->GetArrayLength(text); + + if (size > 0) + { + jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0); + char* pBuf = (char*)malloc(size+1); + if (pBuf != NULL) + { + memcpy(pBuf, data, size); + pBuf[size] = '\0'; + // pass data to editbox's delegate + if (s_pfEditBoxCB) s_pfEditBoxCB(pBuf, s_ctx); + free(pBuf); + } + env->ReleaseByteArrayElements(text, data, 0); + } + else + { + if (s_pfEditBoxCB) s_pfEditBoxCB("", s_ctx); + } +} + +int getFontSizeAccordingHeightJni(int height) +{ + int ret = 0; + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t + , "org/cocos2dx/lib/Cocos2dxBitmap" + , "getFontSizeAccordingHeight" + , "(I)I")) + { + ret = t.env->CallStaticIntMethod(t.classID, t.methodID, height); + t.env->DeleteLocalRef(t.classID); + } + + return ret; +} + +std::string getStringWithEllipsisJni(const char* pszText, float width, float fontSize) +{ + std::string ret; + JniMethodInfo t; + + if (JniHelper::getStaticMethodInfo(t + , "org/cocos2dx/lib/Cocos2dxBitmap" + , "getStringWithEllipsis" + , "(Ljava/lang/String;FF)Ljava/lang/String;")) + { + jstring stringArg1; + + if (!pszText) + { + stringArg1 = t.env->NewStringUTF(""); + } + else + { + stringArg1 = t.env->NewStringUTF(pszText); + } + + jstring retFromJava = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, stringArg1, width, fontSize); + const char* str = t.env->GetStringUTFChars(retFromJava, 0); + ret = str; + + t.env->ReleaseStringUTFChars(retFromJava, str); + t.env->DeleteLocalRef(stringArg1); + t.env->DeleteLocalRef(t.classID); + } + LOGD("getStringWithEllipsisJni 07"); + return ret; +} + +} // end of extern "C" diff --git a/cocos2dx/platform/android/jni/EditBoxJni.h b/cocos2dx/platform/android/jni/EditBoxJni.h new file mode 100644 index 0000000000..38b3811809 --- /dev/null +++ b/cocos2dx/platform/android/jni/EditBoxJni.h @@ -0,0 +1,47 @@ +/**************************************************************************** +Copyright (c) 2012 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#ifndef __EDITBOX_JNI_H__ +#define __EDITBOX_JNI_H__ + +#include + +typedef void (*EditBoxCallback)(const char* pText, void* ctx); + +extern "C" +{ +void showEditBoxDialogJni(const char* pszTitle, + const char* pszContent, + int nInputMode, + int nInputFlag, + int nReturnType, + int nMaxLength, + EditBoxCallback pfEditBoxCB, + void* ctx); + +int getFontSizeAccordingHeightJni(int height); +std::string getStringWithEllipsisJni(const char* pszText, float width, float fontSize); + +} // end of extern "C" + +#endif // __EDITBOX_JNI_H__ diff --git a/cocos2dx/platform/android/jni/MessageJni.cpp b/cocos2dx/platform/android/jni/MessageJni.cpp index e7baa79eb7..36ef53fafb 100644 --- a/cocos2dx/platform/android/jni/MessageJni.cpp +++ b/cocos2dx/platform/android/jni/MessageJni.cpp @@ -59,7 +59,7 @@ extern "C" void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() { - CCApplication::sharedApplication().applicationDidEnterBackground(); + CCApplication::sharedApplication()->applicationDidEnterBackground(); CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_COME_TO_BACKGROUND, NULL); } @@ -69,7 +69,7 @@ extern "C" // Shared OpenGL View instance doesn't exist yet when Activity.onResume is first called if (CCDirector::sharedDirector()->getOpenGLView()) { - CCApplication::sharedApplication().applicationWillEnterForeground(); + CCApplication::sharedApplication()->applicationWillEnterForeground(); } } diff --git a/cocos2dx/platform/blackberry/CCApplication.cpp b/cocos2dx/platform/blackberry/CCApplication.cpp index 8306f4524b..cdd25eb557 100644 --- a/cocos2dx/platform/blackberry/CCApplication.cpp +++ b/cocos2dx/platform/blackberry/CCApplication.cpp @@ -51,7 +51,7 @@ int CCApplication::run() while (1) // or device wants to quit { - CCEGLView::sharedOpenGLView().handleEvents(); + CCEGLView::sharedOpenGLView()->handleEvents(); clock_gettime(CLOCK_REALTIME, &time_struct); current_time = time2millis(&time_struct); @@ -106,10 +106,10 @@ TargetPlatform CCApplication::getTargetPlatform() ////////////////////////////////////////////////////////////////////////// // static member function ////////////////////////////////////////////////////////////////////////// -CCApplication& CCApplication::sharedApplication() +CCApplication* CCApplication::sharedApplication() { CC_ASSERT(sm_pSharedApplication); - return *sm_pSharedApplication; + return sm_pSharedApplication; } ccLanguageType CCApplication::getCurrentLanguage() diff --git a/cocos2dx/platform/blackberry/CCApplication.h b/cocos2dx/platform/blackberry/CCApplication.h index f69b6ebe33..ef24c2f308 100644 --- a/cocos2dx/platform/blackberry/CCApplication.h +++ b/cocos2dx/platform/blackberry/CCApplication.h @@ -49,7 +49,7 @@ public: @brief Get current applicaiton instance. @return Current application instance pointer. */ - static CCApplication& sharedApplication(); + static CCApplication* sharedApplication(); /** @brief Get current language config diff --git a/cocos2dx/platform/blackberry/CCEGLView.cpp b/cocos2dx/platform/blackberry/CCEGLView.cpp index d71fb25085..58bb1df768 100644 --- a/cocos2dx/platform/blackberry/CCEGLView.cpp +++ b/cocos2dx/platform/blackberry/CCEGLView.cpp @@ -189,7 +189,7 @@ void CCEGLView::swapBuffers() eglSwapBuffers(m_eglDisplay, m_eglSurface); } -CCEGLView& CCEGLView::sharedOpenGLView() +CCEGLView* CCEGLView::sharedOpenGLView() { if (!s_pInstance) { @@ -197,7 +197,7 @@ CCEGLView& CCEGLView::sharedOpenGLView() } CCAssert(s_pInstance != NULL, "CCEGLView wasn't constructed yet"); - return *s_pInstance; + return s_pInstance; } void CCEGLView::showKeyboard() @@ -587,7 +587,7 @@ bool CCEGLView::handleEvents() case NAVIGATOR_WINDOW_INACTIVE: if (m_isWindowActive) { - CCApplication::sharedApplication().applicationDidEnterBackground(); + CCApplication::sharedApplication()->applicationDidEnterBackground(); m_isWindowActive = false; } break; @@ -595,7 +595,7 @@ bool CCEGLView::handleEvents() case NAVIGATOR_WINDOW_ACTIVE: if (!m_isWindowActive) { - CCApplication::sharedApplication().applicationWillEnterForeground(); + CCApplication::sharedApplication()->applicationWillEnterForeground(); m_isWindowActive = true; } break; @@ -607,14 +607,14 @@ bool CCEGLView::handleEvents() case NAVIGATOR_WINDOW_FULLSCREEN: if (!m_isWindowActive) { - CCApplication::sharedApplication().applicationWillEnterForeground(); + CCApplication::sharedApplication()->applicationWillEnterForeground(); m_isWindowActive = true; } break; case NAVIGATOR_WINDOW_THUMBNAIL: if (m_isWindowActive) { - CCApplication::sharedApplication().applicationDidEnterBackground(); + CCApplication::sharedApplication()->applicationDidEnterBackground(); m_isWindowActive = false; } break; @@ -673,96 +673,36 @@ bool CCEGLView::handleEvents() case SCREEN_EVENT_POINTER: { - int buttons; - int pair[2]; + int buttons = 0; + int pair_[2] = {0}; + float pair[2] = {0.0f}; static bool mouse_pressed = false; // this is a mouse move event, it is applicable to a device with a usb mouse or simulator screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); - screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, pair); - + screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, pair_); + pair[0] = (float)pair_[0]; + pair[1] = (float)pair_[1]; if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { if (mouse_pressed) { - handleTouchesMove(1, &touch_id, (float *)&pair[0], (float *)&pair[1]); - - /* - // Left mouse button was released - if (m_pDelegate && touch_id < MAX_TOUCHES) - { - CCTouch* touch = s_pTouches[touch_id]; - if (touch) - { - CCSet set; - touch->SetTouchInfo(((float)(pair[0]) - m_rcViewPort.origin.x) / m_fScreenScaleFactor, - ((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor); - set.addObject(touch); - m_pDelegate->touchesMoved(&set, NULL); - } - } - */ + handleTouchesMove(1, &touch_id, &pair[0], &pair[1]); } else { // Left mouse button is pressed mouse_pressed = true; - handleTouchesBegin(1, &touch_id, (float *)&pair[0], (float *)&pair[1]); - - /* - if (m_pDelegate && touch_id < MAX_TOUCHES) - { - CCTouch* touch = s_pTouches[touch_id]; - if (!touch) - touch = new CCTouch; - - touch->SetTouchInfo(((float)(pair[0]) - m_rcViewPort.origin.x) / m_fScreenScaleFactor, - ((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor); - s_pTouches[touch_id] = touch; - - CCSet set; - set.addObject(touch); - m_pDelegate->touchesBegan(&set, NULL); - } - */ + handleTouchesBegin(1, &touch_id, &pair[0], &pair[1]); } } else { if (mouse_pressed) { - handleTouchesEnd(1, &touch_id, (float *)&pair[0], (float *)&pair[1]); - - /* - if (m_pDelegate && touch_id < MAX_TOUCHES) - { - mouse_pressed = false; - - CCTouch* touch = s_pTouches[touch_id]; - if (touch) - { - CCSet set; - touch->SetTouchInfo(((float)(pair[0]) - m_rcViewPort.origin.x) / m_fScreenScaleFactor, - ((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor); - set.addObject(touch); - m_pDelegate->touchesEnded(&set, NULL); - - touch->release(); - for (int i = touch_id; i < MAX_TOUCHES; i++) - { - if (i != (MAX_TOUCHES - 1)) - { - s_pTouches[i] = s_pTouches[i + 1]; - } - else - { - s_pTouches[i] = NULL; - } - } - } - } - */ + mouse_pressed = false; + handleTouchesEnd(1, &touch_id, &pair[0], &pair[1]); } } } diff --git a/cocos2dx/platform/blackberry/CCEGLView.h b/cocos2dx/platform/blackberry/CCEGLView.h index 26be27f2db..27e07421f0 100644 --- a/cocos2dx/platform/blackberry/CCEGLView.h +++ b/cocos2dx/platform/blackberry/CCEGLView.h @@ -48,7 +48,7 @@ public: /** @brief get the shared main open gl window */ - static CCEGLView& sharedOpenGLView(); + static CCEGLView* sharedOpenGLView(); bool handleEvents(); diff --git a/cocos2dx/platform/blackberry/CCFileUtils.cpp b/cocos2dx/platform/blackberry/CCFileUtils.cpp index b67c9d1fd1..196fa5853c 100644 --- a/cocos2dx/platform/blackberry/CCFileUtils.cpp +++ b/cocos2dx/platform/blackberry/CCFileUtils.cpp @@ -58,10 +58,11 @@ void CCFileUtils::purgeCachedEntries() static std::string fullPathFromRelativePathThreadSafe(const char* pszRelativePath) { std::string ret(""); - const char* pszRootPath = CCApplication::sharedApplication().getResourceRootPath(); + const char* pszRootPath = CCApplication::sharedApplication()->getResourceRootPath(); CCAssert(pszRootPath != NULL, "The resource root path must be set in the main.cpp"); std::string pstrRelativePath = pszRelativePath; + // if the relative path contains root path, skip it. if (pstrRelativePath.find(pszRootPath) == std::string::npos) { ret += pszRootPath; @@ -71,7 +72,13 @@ static std::string fullPathFromRelativePathThreadSafe(const char* pszRelativePat if (resDir != NULL) { - ret += resDir; + std::string pstrRootPath = pszRootPath; + std::string pstrResourceFullPath = pstrRootPath + resDir; + // if the relative path contains root path and resource directory, skip it. + if (pstrRelativePath.find(pstrResourceFullPath.c_str()) == std::string::npos) + { + ret += resDir; + } } if (pszRelativePath != NULL) diff --git a/cocos2dx/platform/ios/CCApplication.h b/cocos2dx/platform/ios/CCApplication.h index 361a6f4f4c..8b7e383c8f 100644 --- a/cocos2dx/platform/ios/CCApplication.h +++ b/cocos2dx/platform/ios/CCApplication.h @@ -47,7 +47,7 @@ public: @brief Get current applicaiton instance. @return Current application instance pointer. */ - static CCApplication& sharedApplication(); + static CCApplication* sharedApplication(); /** @brief Callback by CCDirector for limit FPS. diff --git a/cocos2dx/platform/ios/CCApplication.mm b/cocos2dx/platform/ios/CCApplication.mm index ae3552d787..ff295f7ab5 100644 --- a/cocos2dx/platform/ios/CCApplication.mm +++ b/cocos2dx/platform/ios/CCApplication.mm @@ -63,10 +63,10 @@ void CCApplication::setAnimationInterval(double interval) // static member function ////////////////////////////////////////////////////////////////////////////////////////////////// -CCApplication& CCApplication::sharedApplication() +CCApplication* CCApplication::sharedApplication() { CC_ASSERT(sm_pSharedApplication); - return *sm_pSharedApplication; + return sm_pSharedApplication; } ccLanguageType CCApplication::getCurrentLanguage() diff --git a/cocos2dx/platform/ios/CCEGLView.h b/cocos2dx/platform/ios/CCEGLView.h index c3be9fc76e..de0251c3ac 100644 --- a/cocos2dx/platform/ios/CCEGLView.h +++ b/cocos2dx/platform/ios/CCEGLView.h @@ -48,7 +48,7 @@ public: virtual void setIMEKeyboardState(bool bOpen); - static CCEGLView& sharedOpenGLView(); + static CCEGLView* sharedOpenGLView(); }; diff --git a/cocos2dx/platform/ios/CCEGLView.mm b/cocos2dx/platform/ios/CCEGLView.mm index 4a4f8c7539..c672ad8ff4 100644 --- a/cocos2dx/platform/ios/CCEGLView.mm +++ b/cocos2dx/platform/ios/CCEGLView.mm @@ -106,10 +106,10 @@ void CCEGLView::setIMEKeyboardState(bool bOpen) } } -CCEGLView& CCEGLView::sharedOpenGLView() +CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView instance; - return instance; + return &instance; } NS_CC_END diff --git a/cocos2dx/platform/ios/CCFileUtils.mm b/cocos2dx/platform/ios/CCFileUtils.mm index 828068e8d8..68a9ad64fd 100644 --- a/cocos2dx/platform/ios/CCFileUtils.mm +++ b/cocos2dx/platform/ios/CCFileUtils.mm @@ -193,20 +193,20 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) if( ! [relPath isAbsolutePath] ) { // pathForResource also searches in .lproj directories. issue #1230 - NSString *file = [relPath lastPathComponent]; + NSString *lastPathComponent = [relPath lastPathComponent]; - NSMutableString *imageDirectory = [NSMutableString stringWithUTF8String:m_obDirectory.c_str()]; - NSMutableString *imageDirectoryWithDirectory = imageDirectory; - [imageDirectoryWithDirectory appendString:[relPath stringByDeletingLastPathComponent]]; + NSString *imageDirectory = [relPath stringByDeletingLastPathComponent]; + NSMutableString *imageDirectoryByAppendDirectory = [NSMutableString stringWithUTF8String:m_obDirectory.c_str()]; + [imageDirectoryByAppendDirectory appendString:imageDirectory]; // search path from directory set by setResourceDirectory - fullpath = [[NSBundle mainBundle] pathForResource:file + fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent ofType:nil - inDirectory:imageDirectoryWithDirectory]; + inDirectory:imageDirectoryByAppendDirectory]; if (fullpath == nil) { // search from root directory - fullpath = [[NSBundle mainBundle] pathForResource:file + fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent ofType:nil inDirectory:imageDirectory]; } diff --git a/cocos2dx/platform/ios/CCImage.mm b/cocos2dx/platform/ios/CCImage.mm index 597ce41f3f..34cfbc4940 100644 --- a/cocos2dx/platform/ios/CCImage.mm +++ b/cocos2dx/platform/ios/CCImage.mm @@ -228,32 +228,32 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl font = [UIFont fontWithName:fntName size:nSize]; if (font) { - dim = _calculateStringSizeWithFontOrZFont(str, font, &constrainSize, false); + dim = _calculateStringSizeWithFontOrZFont(str, font, &constrainSize, false); } if (! font) { - font = [[FontManager sharedManager] zFontWithName:fntName pointSize:nSize]; - if (font) - { - dim =_calculateStringSizeWithFontOrZFont(str, font, &constrainSize, true); - } + font = [[FontManager sharedManager] zFontWithName:fntName pointSize:nSize]; + if (font) + { + dim =_calculateStringSizeWithFontOrZFont(str, font, &constrainSize, true); + } } if (! font) { - fntName = _isValidFontName(pFontName) ? fntName : @"MarkerFelt-Wide"; - font = [UIFont fontWithName:fntName size:nSize]; + fntName = _isValidFontName(pFontName) ? fntName : @"MarkerFelt-Wide"; + font = [UIFont fontWithName:fntName size:nSize]; - if (! font) - { - font = [UIFont systemFontOfSize:nSize]; - } + if (! font) + { + font = [UIFont systemFontOfSize:nSize]; + } - if (font) - { - dim = _calculateStringSizeWithFontOrZFont(str, font, &constrainSize, false); - } + if (font) + { + dim = _calculateStringSizeWithFontOrZFont(str, font, &constrainSize, false); + } } CC_BREAK_IF(! font); diff --git a/cocos2dx/platform/ios/EAGLView.mm b/cocos2dx/platform/ios/EAGLView.mm index 52ddaac951..04b27fa72e 100755 --- a/cocos2dx/platform/ios/EAGLView.mm +++ b/cocos2dx/platform/ios/EAGLView.mm @@ -405,7 +405,7 @@ static EAGLView *view = 0; ys[i] = [touch locationInView: [touch view]].y; ++i; } - cocos2d::CCEGLView::sharedOpenGLView().handleTouchesBegin(i, ids, xs, ys); + cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesBegin(i, ids, xs, ys); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event @@ -425,7 +425,7 @@ static EAGLView *view = 0; ys[i] = [touch locationInView: [touch view]].y; ++i; } - cocos2d::CCEGLView::sharedOpenGLView().handleTouchesMove(i, ids, xs, ys); + cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesMove(i, ids, xs, ys); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event @@ -446,7 +446,7 @@ static EAGLView *view = 0; ys[i] = [touch locationInView: [touch view]].y; ++i; } - cocos2d::CCEGLView::sharedOpenGLView().handleTouchesEnd(i, ids, xs, ys); + cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesEnd(i, ids, xs, ys); } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event @@ -467,7 +467,7 @@ static EAGLView *view = 0; ys[i] = [touch locationInView: [touch view]].y; ++i; } - cocos2d::CCEGLView::sharedOpenGLView().handleTouchesCancel(i, ids, xs, ys); + cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesCancel(i, ids, xs, ys); } #pragma mark - @@ -797,7 +797,7 @@ static EAGLView *view = 0; end.size.height); notiInfo.duration = (float)aniDuration; - float offestY = cocos2d::CCEGLView::sharedOpenGLView().getViewPortRect().origin.y; + float offestY = cocos2d::CCEGLView::sharedOpenGLView()->getViewPortRect().origin.y; if (offestY > 0.0f) { @@ -806,10 +806,10 @@ static EAGLView *view = 0; notiInfo.end.size.height -= offestY; } - if (!cocos2d::CCEGLView::sharedOpenGLView().isRetinaEnabled()) + if (!cocos2d::CCEGLView::sharedOpenGLView()->isRetinaEnabled()) { - float scaleX = cocos2d::CCEGLView::sharedOpenGLView().getScaleX(); - float scaleY = cocos2d::CCEGLView::sharedOpenGLView().getScaleY(); + float scaleX = cocos2d::CCEGLView::sharedOpenGLView()->getScaleX(); + float scaleY = cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); notiInfo.begin.origin.x /= scaleX; notiInfo.begin.origin.y /= scaleY; @@ -860,9 +860,9 @@ static EAGLView *view = 0; if (dis < 0.0f) dis = 0.0f; - if (!cocos2d::CCEGLView::sharedOpenGLView().isRetinaEnabled()) + if (!cocos2d::CCEGLView::sharedOpenGLView()->isRetinaEnabled()) { - dis *= cocos2d::CCEGLView::sharedOpenGLView().getScaleY(); + dis *= cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); } switch ([[UIApplication sharedApplication] statusBarOrientation]) diff --git a/cocos2dx/platform/linux/CCApplication.cpp b/cocos2dx/platform/linux/CCApplication.cpp index cb9d434cdd..86c2352c02 100644 --- a/cocos2dx/platform/linux/CCApplication.cpp +++ b/cocos2dx/platform/linux/CCApplication.cpp @@ -92,10 +92,10 @@ TargetPlatform CCApplication::getTargetPlatform() ////////////////////////////////////////////////////////////////////////// // static member function ////////////////////////////////////////////////////////////////////////// -CCApplication& CCApplication::sharedApplication() +CCApplication* CCApplication::sharedApplication() { CC_ASSERT(sm_pSharedApplication); - return *sm_pSharedApplication; + return sm_pSharedApplication; } ccLanguageType CCApplication::getCurrentLanguage() diff --git a/cocos2dx/platform/linux/CCApplication.h b/cocos2dx/platform/linux/CCApplication.h index ae0dc58890..343ea2b292 100644 --- a/cocos2dx/platform/linux/CCApplication.h +++ b/cocos2dx/platform/linux/CCApplication.h @@ -35,7 +35,7 @@ public: @brief Get current applicaiton instance. @return Current application instance pointer. */ - static CCApplication& sharedApplication(); + static CCApplication* sharedApplication(); /* override functions */ virtual ccLanguageType getCurrentLanguage(); diff --git a/cocos2dx/platform/linux/CCEGLView.cpp b/cocos2dx/platform/linux/CCEGLView.cpp index d57d634279..ac2d390203 100644 --- a/cocos2dx/platform/linux/CCEGLView.cpp +++ b/cocos2dx/platform/linux/CCEGLView.cpp @@ -122,10 +122,10 @@ void mouseButtonEventHandle(int iMouseID,int iMouseState) { */ int id = 0; if (iMouseState == GLFW_PRESS) { - CCEGLView::sharedOpenGLView().handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y); + CCEGLView::sharedOpenGLView()->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y); } else if (iMouseState == GLFW_RELEASE) { - CCEGLView::sharedOpenGLView().handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y); + CCEGLView::sharedOpenGLView()->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y); } } } @@ -138,7 +138,7 @@ void mousePosEventHandle(int iPosX,int iPosY) { int id = 0; float x = (float)iPosX; float y = (float)iPosY; - CCEGLView::sharedOpenGLView().handleTouchesMove(1, &id, &x, &y); + CCEGLView::sharedOpenGLView()->handleTouchesMove(1, &id, &x, &y); } } @@ -292,14 +292,14 @@ void CCEGLView::destroyGL() */ } -CCEGLView& CCEGLView::sharedOpenGLView() +CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView* s_pEglView = NULL; if (s_pEglView == NULL) { s_pEglView = new CCEGLView(); } - return *s_pEglView; + return s_pEglView; } NS_CC_END diff --git a/cocos2dx/platform/linux/CCEGLView.h b/cocos2dx/platform/linux/CCEGLView.h index e22b7c622d..19a4b4f1dc 100644 --- a/cocos2dx/platform/linux/CCEGLView.h +++ b/cocos2dx/platform/linux/CCEGLView.h @@ -40,7 +40,7 @@ public: /** @brief get the shared main open gl window */ - static CCEGLView& sharedOpenGLView(); + static CCEGLView* sharedOpenGLView(); private: bool initGL(); void destroyGL(); diff --git a/cocos2dx/platform/linux/CCFileUtils.cpp b/cocos2dx/platform/linux/CCFileUtils.cpp index 024c6c97a8..389b667bbc 100644 --- a/cocos2dx/platform/linux/CCFileUtils.cpp +++ b/cocos2dx/platform/linux/CCFileUtils.cpp @@ -12,6 +12,9 @@ #include "CCApplication.h" #include "cocoa/CCString.h" #include +#include +#include +#include using namespace std; @@ -45,13 +48,17 @@ void CCFileUtils::purgeCachedEntries() const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { - const char* pszRootPath = CCApplication::sharedApplication().getResourceRootPath(); + if (pszRelativePath && pszRelativePath[0] == '/') + { + return pszRelativePath; + } + + const char* pszRootPath = CCApplication::sharedApplication()->getResourceRootPath(); CCString* pRet = CCString::create(pszRootPath); - const char* resDir = CCFileUtils::sharedFileUtils()->getResourceDirectory(); - if (resDir != NULL) + if (m_obDirectory.size() > 0) { - pRet->m_sString += resDir; + pRet->m_sString += m_obDirectory.c_str(); } if (pszRelativePath != NULL) @@ -59,6 +66,20 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) pRet->m_sString += pszRelativePath; } + // check if file or path exist + struct stat sts; + if (stat(pRet->getCString(), &sts) == -1 && errno == ENOENT) + { + // find from "Resources/" + pRet->m_sString.clear(); + pRet->m_sString = CCApplication::sharedApplication()->getResourceRootPath(); + pRet->m_sString += pszRelativePath; + if (stat(pRet->getCString(), &sts) == -1 && errno == ENOENT) + { + return pszRelativePath; + } + } + return pRet->getCString(); } @@ -104,7 +125,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz string CCFileUtils::getWriteablePath() { //return current resource path - return CCApplication::sharedApplication().getResourceRootPath(); + return CCApplication::sharedApplication()->getResourceRootPath(); } NS_CC_END diff --git a/cocos2dx/platform/mac/CCApplication.h b/cocos2dx/platform/mac/CCApplication.h index 7bfdf21583..5d18795a67 100755 --- a/cocos2dx/platform/mac/CCApplication.h +++ b/cocos2dx/platform/mac/CCApplication.h @@ -56,7 +56,7 @@ public: @brief Get current applicaiton instance. @return Current application instance pointer. */ - static CCApplication& sharedApplication(); + static CCApplication* sharedApplication(); /** @brief Get current language config diff --git a/cocos2dx/platform/mac/CCApplication.mm b/cocos2dx/platform/mac/CCApplication.mm index e16e6e8407..5ad820bc92 100755 --- a/cocos2dx/platform/mac/CCApplication.mm +++ b/cocos2dx/platform/mac/CCApplication.mm @@ -69,10 +69,10 @@ TargetPlatform CCApplication::getTargetPlatform() // static member function ////////////////////////////////////////////////////////////////////////////////////////////////// -CCApplication& CCApplication::sharedApplication() +CCApplication* CCApplication::sharedApplication() { CC_ASSERT(sm_pSharedApplication); - return *sm_pSharedApplication; + return sm_pSharedApplication; } ccLanguageType CCApplication::getCurrentLanguage() diff --git a/cocos2dx/platform/mac/CCEGLView.h b/cocos2dx/platform/mac/CCEGLView.h index 609247c6e8..b1a37d6088 100755 --- a/cocos2dx/platform/mac/CCEGLView.h +++ b/cocos2dx/platform/mac/CCEGLView.h @@ -48,7 +48,7 @@ public: void setMultiTouchMask(bool mask); - static CCEGLView& sharedOpenGLView(); + static CCEGLView* sharedOpenGLView(); }; diff --git a/cocos2dx/platform/mac/CCEGLView.mm b/cocos2dx/platform/mac/CCEGLView.mm index 52e3b896b1..0d1b96129e 100755 --- a/cocos2dx/platform/mac/CCEGLView.mm +++ b/cocos2dx/platform/mac/CCEGLView.mm @@ -83,10 +83,10 @@ void CCEGLView::setMultiTouchMask(bool mask) //glView.multipleTouchEnabled = mask ? YES : NO; } -CCEGLView& CCEGLView::sharedOpenGLView() +CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView instance; - return instance; + return &instance; } } // end of namespace cocos2d; diff --git a/cocos2dx/platform/mac/CCFileUtils.mm b/cocos2dx/platform/mac/CCFileUtils.mm index 3f2126da0e..cf564fa3dd 100755 --- a/cocos2dx/platform/mac/CCFileUtils.mm +++ b/cocos2dx/platform/mac/CCFileUtils.mm @@ -193,20 +193,20 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) if( ! [relPath isAbsolutePath] ) { // pathForResource also searches in .lproj directories. issue #1230 - NSString *file = [relPath lastPathComponent]; + NSString *lastPathComponent = [relPath lastPathComponent]; - NSMutableString *imageDirectory = [NSMutableString stringWithUTF8String:m_obDirectory.c_str()]; - NSMutableString *imageDirectoryWithDirectory = imageDirectory; - [imageDirectoryWithDirectory appendString:[relPath stringByDeletingLastPathComponent]]; + NSString *imageDirectory = [relPath stringByDeletingLastPathComponent]; + NSMutableString *imageDirectoryByAppendDirectory = [NSMutableString stringWithUTF8String:m_obDirectory.c_str()]; + [imageDirectoryByAppendDirectory appendString:imageDirectory]; // search path from directory set by setResourceDirectory - fullpath = [[NSBundle mainBundle] pathForResource:file + fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent ofType:nil - inDirectory:imageDirectoryWithDirectory]; + inDirectory:imageDirectoryByAppendDirectory]; if (fullpath == nil) { // search from root directory - fullpath = [[NSBundle mainBundle] pathForResource:file + fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent ofType:nil inDirectory:imageDirectory]; } diff --git a/cocos2dx/platform/mac/CCGL.h b/cocos2dx/platform/mac/CCGL.h index 29d1d03eb9..45e839e4bc 100644 --- a/cocos2dx/platform/mac/CCGL.h +++ b/cocos2dx/platform/mac/CCGL.h @@ -30,4 +30,10 @@ THE SOFTWARE. #define CC_GL_DEPTH24_STENCIL8 -1 + +#define glDeleteVertexArrays glDeleteVertexArraysAPPLE +#define glGenVertexArrays glGenVertexArraysAPPLE +#define glBindVertexArray glBindVertexArrayAPPLE + + #endif // __CCGL_H__ diff --git a/cocos2dx/platform/win32/CCAccelerometer.cpp b/cocos2dx/platform/win32/CCAccelerometer.cpp index 58bee51739..569d12cfcf 100644 --- a/cocos2dx/platform/win32/CCAccelerometer.cpp +++ b/cocos2dx/platform/win32/CCAccelerometer.cpp @@ -168,12 +168,12 @@ void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate) if (pDelegate) { // Register our handler - CCEGLView::sharedOpenGLView().setAccelerometerKeyHook( &myAccelerometerKeyHook ); + CCEGLView::sharedOpenGLView()->setAccelerometerKeyHook( &myAccelerometerKeyHook ); } else { // De-register our handler - CCEGLView::sharedOpenGLView().setAccelerometerKeyHook( NULL ); + CCEGLView::sharedOpenGLView()->setAccelerometerKeyHook( NULL ); resetAccelerometer(); } } diff --git a/cocos2dx/platform/win32/CCApplication.cpp b/cocos2dx/platform/win32/CCApplication.cpp index 0ab04ba7dd..d77a93a85b 100644 --- a/cocos2dx/platform/win32/CCApplication.cpp +++ b/cocos2dx/platform/win32/CCApplication.cpp @@ -48,9 +48,9 @@ int CCApplication::run() return 0; } - CCEGLView& mainWnd = CCEGLView::sharedOpenGLView(); - mainWnd.centerWindow(); - ShowWindow(mainWnd.getHWnd(), SW_SHOW); + CCEGLView* pMainWnd = CCEGLView::sharedOpenGLView(); + pMainWnd->centerWindow(); + ShowWindow(pMainWnd->getHWnd(), SW_SHOW); while (1) { @@ -99,10 +99,10 @@ void CCApplication::setAnimationInterval(double interval) ////////////////////////////////////////////////////////////////////////// // static member function ////////////////////////////////////////////////////////////////////////// -CCApplication& CCApplication::sharedApplication() +CCApplication* CCApplication::sharedApplication() { CC_ASSERT(sm_pSharedApplication); - return *sm_pSharedApplication; + return sm_pSharedApplication; } ccLanguageType CCApplication::getCurrentLanguage() diff --git a/cocos2dx/platform/win32/CCApplication.h b/cocos2dx/platform/win32/CCApplication.h index 1edb3bb607..8e05740002 100644 --- a/cocos2dx/platform/win32/CCApplication.h +++ b/cocos2dx/platform/win32/CCApplication.h @@ -24,7 +24,7 @@ public: @brief Get current applicaiton instance. @return Current application instance pointer. */ - static CCApplication& sharedApplication(); + static CCApplication* sharedApplication(); /* override functions */ virtual void setAnimationInterval(double interval); diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 42e36f95ec..aec45d999d 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -210,7 +210,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); + CCPoint pt(point.x, point.y); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { @@ -226,7 +226,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); + CCPoint pt(point.x, point.y); int id = 0; handleTouchesMove(1, &id, &pt.x, &pt.y); } @@ -236,7 +236,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); + CCPoint pt(point.x, point.y); int id = 0; handleTouchesEnd(1, &id, &pt.x, &pt.y); @@ -248,10 +248,10 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) switch (wParam) { case SIZE_RESTORED: - CCApplication::sharedApplication().applicationWillEnterForeground(); + CCApplication::sharedApplication()->applicationWillEnterForeground(); break; case SIZE_MINIMIZED: - CCApplication::sharedApplication().applicationDidEnterBackground(); + CCApplication::sharedApplication()->applicationDidEnterBackground(); break; } break; @@ -370,6 +370,11 @@ void CCEGLView::setIMEKeyboardState(bool /*bOpen*/) } +bool CCEGLView::enableRetina() +{ + return true; +} + HWND CCEGLView::getHWnd() { return m_hWnd; @@ -446,14 +451,14 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor) return true; } -CCEGLView& CCEGLView::sharedOpenGLView() +CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView* s_pEglView = NULL; if (s_pEglView == NULL) { s_pEglView = new CCEGLView(); } - return *s_pEglView; + return s_pEglView; } NS_CC_END diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 552ba9c99d..909a0639e7 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -47,7 +47,7 @@ public: virtual bool setContentScaleFactor(float contentScaleFactor); virtual void setFrameSize(float width, float height); virtual void setIMEKeyboardState(bool bOpen); - + virtual bool enableRetina(); private: virtual bool Create(LPCTSTR pTitle, int w, int h); bool initGL(); @@ -67,7 +67,7 @@ public: /** @brief get the shared main open gl window */ - static CCEGLView& sharedOpenGLView(); + static CCEGLView* sharedOpenGLView(); protected: diff --git a/cocos2dx/platform/win32/CCFileUtils.cpp b/cocos2dx/platform/win32/CCFileUtils.cpp index 7c4fb34583..4535c4e156 100644 --- a/cocos2dx/platform/win32/CCFileUtils.cpp +++ b/cocos2dx/platform/win32/CCFileUtils.cpp @@ -37,17 +37,11 @@ static void _CheckPath() { if (! s_pszResourcePath[0]) { - WCHAR wszPath[MAX_PATH]; + WCHAR wszPath[MAX_PATH] = {0}; int nNum = WideCharToMultiByte(CP_ACP, 0, wszPath, GetCurrentDirectoryW(sizeof(wszPath), wszPath), s_pszResourcePath, MAX_PATH, NULL, NULL); - s_pszResourcePath[nNum] = '\\'; - const char* resDir = CCFileUtils::sharedFileUtils()->getResourceDirectory(); - if (resDir != NULL) - { - strcat(s_pszResourcePath, resDir); - } - + s_pszResourcePath[nNum] = '\\'; } } @@ -58,6 +52,7 @@ CCFileUtils* CCFileUtils::sharedFileUtils() if (s_pFileUtils == NULL) { s_pFileUtils = new CCFileUtils(); + _CheckPath(); } return s_pFileUtils; } @@ -79,10 +74,10 @@ void CCFileUtils::purgeCachedEntries() const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { - _CheckPath(); + bool bFileExist = true; + const char* resDir = CCFileUtils::sharedFileUtils()->getResourceDirectory(); + CCString* pRet = CCString::create(""); - CCString * pRet = new CCString(); - pRet->autorelease(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { // path start with "x:", is absolute path @@ -99,19 +94,35 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) else { pRet->m_sString = s_pszResourcePath; + pRet->m_sString += resDir; pRet->m_sString += pszRelativePath; } + // If file or directory doesn't exist, try to find it in the root path. + if (GetFileAttributesA(pRet->m_sString.c_str()) == -1) + { + pRet->m_sString = s_pszResourcePath; + pRet->m_sString += pszRelativePath; + + if (GetFileAttributesA(pRet->m_sString.c_str()) == -1) + { + bFileExist = false; + } + } + + if (!bFileExist) + { // Can't find the file, return the relative path. + pRet->m_sString = pszRelativePath; + } + return pRet->m_sString.c_str(); } const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile) { - _CheckPath(); // std::string relativeFile = fullPathFromRelativePath(pszRelativeFile); std::string relativeFile = pszRelativeFile; - CCString *pRet = new CCString(); - pRet->autorelease(); + CCString *pRet = CCString::create(""); pRet->m_sString = relativeFile.substr(0, relativeFile.find_last_of("/\\") + 1); pRet->m_sString += pszFilename; return pRet->m_sString.c_str(); diff --git a/cocos2dx/proj.linux/Makefile b/cocos2dx/proj.linux/Makefile index cb43147482..4129383b12 100644 --- a/cocos2dx/proj.linux/Makefile +++ b/cocos2dx/proj.linux/Makefile @@ -189,14 +189,13 @@ STATICLIBS_DIR = ../platform/third_party/linux/libraries endif STATICLIBS = STATICLIBS = $(STATICLIBS_DIR)/libfreetype.a \ - $(STATICLIBS_DIR)/libcurl.a \ $(STATICLIBS_DIR)/libxml2.a \ $(STATICLIBS_DIR)/libpng.a \ $(STATICLIBS_DIR)/libjpeg.a \ $(STATICLIBS_DIR)/libtiff.a \ SHAREDLIBS = -SHAREDLIBS += -lglfw -lGL +SHAREDLIBS += -lglfw -lGL -lcurl SHAREDLIBS += -Wl,-rpath,../../cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib SHAREDLIBS += -L../../cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib -lGLEW diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 8005d001aa..7b0e0f4e31 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -1025,7 +1025,7 @@ CCSpriteFrame* CCSprite::displayFrame(void) return CCSpriteFrame::createWithTexture(m_pobTexture, CC_RECT_POINTS_TO_PIXELS(m_obRect), m_bRectRotated, - m_obUnflippedOffsetPositionFromCenter, + CC_POINT_POINTS_TO_PIXELS(m_obUnflippedOffsetPositionFromCenter), CC_SIZE_POINTS_TO_PIXELS(m_tContentSize)); } diff --git a/cocos2dx/textures/CCTexturePVR.cpp b/cocos2dx/textures/CCTexturePVR.cpp index 5449875e0d..5e1e10eb78 100755 --- a/cocos2dx/textures/CCTexturePVR.cpp +++ b/cocos2dx/textures/CCTexturePVR.cpp @@ -267,7 +267,7 @@ bool CCTexturePVR::unpackPVRData(unsigned char* data, unsigned int len) } dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8); - float packetLength = (dataLength - dataOffset); + unsigned int packetLength = (dataLength - dataOffset); packetLength = packetLength > dataSize ? dataSize : packetLength; //Make record to the mipmaps array and increment coutner diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp index 15fda27d90..41a43e057d 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp @@ -349,20 +349,17 @@ void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts) std::string externalTilesetFilename = valueForKey("source", attributeDict); if (externalTilesetFilename != "") { - if (m_sTMXFileName.length() == 0) + if (m_sTMXFileName.find_last_of("/") != string::npos) { - string pszFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(m_sResources.c_str()); - if (pszFullPath.find_last_of("/\\") != pszFullPath.length()-1) - { - pszFullPath.append("/"); - } - - externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(externalTilesetFilename.c_str(), pszFullPath.c_str() ); + string dir = m_sTMXFileName.substr(0, m_sTMXFileName.find_last_of("/") + 1); + externalTilesetFilename = dir + externalTilesetFilename; } - else + else { - externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(externalTilesetFilename.c_str(), pTMXMapInfo->getTMXFileName()); + externalTilesetFilename = m_sResources + "/" + externalTilesetFilename; } + externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(externalTilesetFilename.c_str()); + pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str()); } else @@ -448,19 +445,15 @@ void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts) // build full path std::string imagename = valueForKey("source", attributeDict); - if (m_sTMXFileName.length() == 0) - { - string pszFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(m_sResources.c_str()); - if (pszFullPath.find_last_of("/\\") != pszFullPath.length()-1) - { - pszFullPath.append("/"); - } - tileset->m_sSourceImage = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(imagename.c_str(), pszFullPath.c_str() ); - } - else + if (m_sTMXFileName.find_last_of("/") != string::npos) { - tileset->m_sSourceImage = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(imagename.c_str(), pTMXMapInfo->getTMXFileName()); + string dir = m_sTMXFileName.substr(0, m_sTMXFileName.find_last_of("/") + 1); + tileset->m_sSourceImage = dir + imagename; + } + else + { + tileset->m_sSourceImage = m_sResources + "/" + imagename; } } else if(elementName == "data") diff --git a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp index 2760737c98..8a1b885aae 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp @@ -157,7 +157,9 @@ void CCTileMapAtlas::setTile(const ccColor3B& tile, const ccGridSize& position) // XXX: this method consumes a lot of memory // XXX: a tree of something like that shall be impolemented - CCInteger *num = (CCInteger*)m_pPosToAtlasIndex->objectForKey(CCString::createWithFormat("%d,%d", position.x, position.y)->getCString()); + CCInteger *num = (CCInteger*)m_pPosToAtlasIndex->objectForKey(CCString::createWithFormat("%ld,%ld", + (long)position.x, + (long)position.y)->getCString()); this->updateAtlasValueAt(position, tile, num->getValue()); } } diff --git a/create-blackberry-project.sh b/create-blackberry-project.sh new file mode 100755 index 0000000000..2d973841a2 --- /dev/null +++ b/create-blackberry-project.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +HELLOWORLD_ROOT=`pwd`/template/blackberry + +# make directory qnx and copy all files and directories into it +copy_qnx_folder(){ + if [ -d $PROJECT_DIR/proj.blackberry ]; then + echo "The '$PROJECT_NAME' project exists, can't override! Please input again!" + create_qnx_project + exit + fi + mkdir $PROJECT_DIR/proj.blackberry + echo $HELLOWORLD_ROOT + for file in `ls -a $HELLOWORLD_ROOT/proj.blackberry | grep -E '\.(project|cproject|xml|png|cpp)' ` + do + file=$HELLOWORLD_ROOT/proj.blackberry/$file + if [ -f $file ];then + #echo $file + cp $file $PROJECT_DIR/proj.blackberry + fi + done +} + +copy_cpp_h_from_helloworld(){ + if [ -d $PROJECT_DIR/Classes ]; then + echo "Classes folder exists, skip copying Classes folder!" + else + mkdir $PROJECT_DIR/Classes + for file in `ls $HELLOWORLD_ROOT/Classes/* | grep -E '.(cpp|h|mk)' ` + do + if [ -f $file ];then + #echo $file + cp $file $PROJECT_DIR/Classes + fi + done + fi +} + +# copy resources +copy_resouces(){ + if [ -d $PROJECT_DIR/Resources ]; then + echo "Resources folder exists, skip copying Resources folder!" + else + mkdir $PROJECT_DIR/Resources + + for file in $HELLOWORLD_ROOT/Resources/* + do + #echo $file + cp $file $PROJECT_DIR/Resources + done + fi +} + +# replace string +modify_file_content(){ + # here should use # instead of /, why?? + sed "s#$2#$3#g" $PROJECT_DIR/proj.blackberry/$1 > $PROJECT_DIR/proj.blackberry/tmp.txt + rm $PROJECT_DIR/proj.blackberry/$1 + mv $PROJECT_DIR/proj.blackberry/tmp.txt $PROJECT_DIR/proj.blackberry/$1 +} + +create_qnx_project(){ + echo "Please input your project name:" + read PROJECT_NAME + PROJECT_DIR=`pwd`/$PROJECT_NAME + + # check if PROJECT_DIR is exist + if [ -d $PROJECT_DIR ]; then + echo "" + else + mkdir $PROJECT_DIR + fi + + copy_qnx_folder + modify_file_content .project BBTemplateProject $PROJECT_NAME + modify_file_content .cproject BBTemplateProject $PROJECT_NAME + modify_file_content bar-descriptor.xml BBTemplateProject $PROJECT_NAME + modify_file_content .cproject ../../../.. ../../.. + modify_file_content bar-descriptor.xml empty/../../../.. empty/../../.. + copy_cpp_h_from_helloworld + copy_resouces + echo "Congratulations, the '$PROJECT_NAME' project have been created successfully, please use QNX IDE to import the project!" +} + +create_qnx_project diff --git a/create-blackberry-project.vbs b/create-blackberry-project.vbs new file mode 100644 index 0000000000..523144c865 --- /dev/null +++ b/create-blackberry-project.vbs @@ -0,0 +1,81 @@ +set fso = Wscript.CreateObject("Scripting.FileSystemObject") + +dim szPrompt, msgRet +szPrompt = "Prompt" + +function ReplaceFileContent(fileName, oldStr, newStr) + set f = fso.opentextfile(fileName) + s = replace(f.readall, oldStr, newStr) + f.close + set r = fso.opentextfile(fileName, 2, true) + r.write s +end function + +function CopyFolder(srcFolder, desFolder) + if (fso.FolderExists(desFolder)) then + 'msgbox("none:"+srcFolder+":"+desFolder) + 'If the desFolder exist, do nothing. + else + CopyFolder = fso.CopyFolder(srcFolder, desFolder) + end if +end function + +function ConfigureProject() + dim szProjectName + szProjectName = Inputbox("Please Input Project Name:", szPrompt) + + if szProjectName = "" then + Wscript.quit + end if + + if (0 = strcomp(szProjectName, "HelloWorld", 1) or 0 = strcomp(szProjectName, "tests", 1)) then + msgRet = msgbox("Can not create a project named with "+szProjectName+", Please input again!", 1, szPrompt) + if (msgRet = 1) then + call ConfigureProject + end if + Wscript.quit + end if + + if (fso.FolderExists(szProjectName)) then + else + fso.CreateFolder(szProjectName) + end if + + dim qnxFolder + qnxFolder = szProjectName + "\proj.blackberry" + if (fso.FolderExists(qnxFolder)) then + msgRet = msgbox("The '"+szProjectName+"' project exists, can't override! Please input again!", 1, szPrompt) + if (msgRet = 1) then + call ConfigureProject + end if + Wcript.quit + end if + + dim szSrcClass, szSrcQnx, szSrcResource + dim szDesClass, szDesQnx, szDesResource + + szSrcClass = "template\blackberry\Classes" + szSrcQnx = "template\blackberry\proj.blackberry" + szSrcResource = "template\blackberry\Resources" + + szDesClass = szProjectName+"\Classes" + szDesQnx = szProjectName+"\proj.blackberry" + szDesResource = szProjectName+"\Resources" + + call CopyFolder(szSrcClass, szDesClass) + call CopyFolder(szSrcQnx, szDesQnx) + call CopyFolder(szSrcResource, szDesResource) + + call ReplaceFileContent(szProjectName+"\proj.blackberry\bar-descriptor.xml", "BBTemplateProject", szProjectName) + call ReplaceFileContent(szProjectName+"\proj.blackberry\bar-descriptor.xml", "../../../..", "../../..") + call ReplaceFileContent(szProjectName+"\proj.blackberry\.project", "BBTemplateProject", szProjectName) + call ReplaceFileContent(szProjectName+"\proj.blackberry\.cproject", "BBTemplateProject", szProjectName) + call ReplaceFileContent(szProjectName+"\proj.blackberry\.cproject", "../../../..", "../../..") + + + call msgbox("Congratulations, the '"+szProjectName+"' project have been created successfully, please use QNX IDE to import the project!", 0, szPrompt) + +end function + +call ConfigureProject +Wscript.quit \ No newline at end of file diff --git a/extensions/Android.mk b/extensions/Android.mk index 77ababacb1..5df1514fad 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -35,6 +35,8 @@ GUI/CCControlExtension/CCMenuPassive.cpp \ GUI/CCControlExtension/CCScale9Sprite.cpp \ GUI/CCControlExtension/CCSpacer.cpp \ GUI/CCScrollView/CCScrollView.cpp \ +GUI/CCEditBox/CCEditBox.cpp \ +GUI/CCEditBox/CCEditBoxImplAndroid.cpp \ network/HttpClient.cpp LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static diff --git a/extensions/CCBReader/CCBReader.cpp b/extensions/CCBReader/CCBReader.cpp index ed2defae0e..22b956d0df 100644 --- a/extensions/CCBReader/CCBReader.cpp +++ b/extensions/CCBReader/CCBReader.cpp @@ -113,7 +113,7 @@ CCNode * CCBReader::readNodeGraphFromFile(CCString * pCCBRootPath, CCString * pC this->mCurrentBit = 0; this->mOwner = pOwner; - this->mOwner->retain(); + CC_SAFE_RETAIN(this->mOwner); this->mRootContainerSize = pRootContainerSize; CCNode * node = NULL; diff --git a/extensions/GUI/CCEditBox/CCEditBox.cpp b/extensions/GUI/CCEditBox/CCEditBox.cpp index 11c4ed5f0c..df7354a48f 100644 --- a/extensions/GUI/CCEditBox/CCEditBox.cpp +++ b/extensions/GUI/CCEditBox/CCEditBox.cpp @@ -79,7 +79,6 @@ CCEditBox* CCEditBox::create(const CCSize& size, CCScale9Sprite* pNormal9SpriteB bool CCEditBox::initWithSizeAndBackgroundSprite(const CCSize& size, CCScale9Sprite* pPressed9SpriteBg) { -#if 0 if (CCControlButton::initWithBackgroundSprite(pPressed9SpriteBg)) { m_pEditBoxImpl = __createSystemEditBox(this); @@ -87,11 +86,10 @@ bool CCEditBox::initWithSizeAndBackgroundSprite(const CCSize& size, CCScale9Spri this->setPreferredSize(size); this->setPosition(ccp(0, 0)); - this->addTargetWithActionForControlEvent(this, cccontrol_selector(CCEditBox::touchDownAction), CCControlEventTouchDown); + this->addTargetWithActionForControlEvent(this, cccontrol_selector(CCEditBox::touchDownAction), CCControlEventTouchUpInside); return true; } -#endif return false; } diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp b/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp new file mode 100644 index 0000000000..a43d55a89e --- /dev/null +++ b/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp @@ -0,0 +1,237 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCEditBoxImplAndroid.h" +#include "CCEditBox.h" +#include "jni/EditBoxJni.h" + +// This function is implemented in CCLabelBMFont.cpp + +NS_CC_BEGIN +extern long cc_utf8_strlen (const char * p, int max); +NS_CC_END + +NS_CC_EXT_BEGIN + +CCEditBoxImpl* __createSystemEditBox(CCEditBox* pEditBox) +{ + return new CCEditBoxImplAndroid(pEditBox); +} + +CCEditBoxImplAndroid::CCEditBoxImplAndroid(CCEditBox* pEditText) +: CCEditBoxImpl(pEditText) +, m_pLabel(NULL) +, m_pLabelPlaceHolder(NULL) +, m_eEditBoxInputMode(kEditBoxInputModeSingleLine) +, m_eEditBoxInputFlag(kEditBoxInputFlagInitialCapsAllCharacters) +, m_eKeyboardReturnType(kKeyboardReturnTypeDefault) +, m_colText(ccWHITE) +, m_colPlaceHolder(ccGRAY) +, m_nMaxLength(-1) +{ + +} + +CCEditBoxImplAndroid::~CCEditBoxImplAndroid() +{ + +} + +void CCEditBoxImplAndroid::doAnimationWhenKeyboardMove(float duration, float distance) +{ // don't need to be implemented on android platform. + +} + +bool CCEditBoxImplAndroid::initWithSize(const CCSize& size) +{ + int fontSize = getFontSizeAccordingHeightJni(size.height-12); + m_pLabel = CCLabelTTF::create("", "", size.height-12); + m_pLabel->setAnchorPoint(ccp(0, 0)); + m_pLabel->setPosition(ccp(5, 2)); + m_pLabel->setColor(m_colText); + m_pEditBox->addChild(m_pLabel); + + m_pLabelPlaceHolder = CCLabelTTF::create("", "", size.height-12); + m_pLabelPlaceHolder->setAnchorPoint(ccp(0, 0)); + m_pLabelPlaceHolder->setPosition(ccp(5, 2)); + m_pLabelPlaceHolder->setVisible(false); + m_pLabelPlaceHolder->setColor(m_colPlaceHolder); + m_pEditBox->addChild(m_pLabelPlaceHolder); + + m_EditSize = size; + return true; +} + +void CCEditBoxImplAndroid::setFontColor(const ccColor3B& color) +{ + m_colText = color; + m_pLabel->setColor(color); +} + +void CCEditBoxImplAndroid::setPlaceholderFontColor(const ccColor3B& color) +{ + m_colPlaceHolder = color; + m_pLabelPlaceHolder->setColor(color); +} + +void CCEditBoxImplAndroid::setInputMode(EditBoxInputMode inputMode) +{ + m_eEditBoxInputMode = inputMode; +} + +void CCEditBoxImplAndroid::setMaxLength(int maxLength) +{ + m_nMaxLength = maxLength; +} + +int CCEditBoxImplAndroid::getMaxLength() +{ + return m_nMaxLength; +} + +void CCEditBoxImplAndroid::setInputFlag(EditBoxInputFlag inputFlag) +{ + m_eEditBoxInputFlag = inputFlag; +} + +void CCEditBoxImplAndroid::setReturnType(KeyboardReturnType returnType) +{ + m_eKeyboardReturnType = returnType; +} + +bool CCEditBoxImplAndroid::isEditing() +{ + return false; +} + +void CCEditBoxImplAndroid::setText(const char* pText) +{ + if (pText != NULL) + { + m_strText = pText; + + if (m_strText.length() > 0) + { + m_pLabelPlaceHolder->setVisible(false); + + std::string strToShow; + + if (kEditBoxInputFlagPassword == m_eEditBoxInputFlag) + { + long length = cc_utf8_strlen(m_strText.c_str(), -1); + for (long i = 0; i < length; i++) + { + strToShow.append("*"); + } + } + else + { + strToShow = m_strText; + } + + std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), m_EditSize.width, m_EditSize.height-12); + m_pLabel->setString(strWithEllipsis.c_str()); + } + else + { + m_pLabelPlaceHolder->setVisible(true); + m_pLabel->setString(""); + } + + } +} + +const char* CCEditBoxImplAndroid::getText(void) +{ + return m_strText.c_str(); +} + +void CCEditBoxImplAndroid::setPlaceHolder(const char* pText) +{ + if (pText != NULL) + { + m_strPlaceHolder = pText; + if (m_strPlaceHolder.length() > 0 && m_strText.length() == 0) + { + m_pLabelPlaceHolder->setVisible(true); + } + + m_pLabelPlaceHolder->setString(m_strPlaceHolder.c_str()); + } +} + +void CCEditBoxImplAndroid::setPosition(const CCPoint& pos) +{ // don't need to be implemented on android platform. + +} + +void CCEditBoxImplAndroid::setContentSize(const CCSize& size) +{ // don't need to be implemented on android platform. + +} + +void CCEditBoxImplAndroid::visit(void) +{ // don't need to be implemented on android platform. + +} + +static void editBoxCallbackFunc(const char* pText, void* ctx) +{ + CCEditBoxImplAndroid* thiz = (CCEditBoxImplAndroid*)ctx; + thiz->setText(pText); + + if (thiz->getDelegate() != NULL) + { + thiz->getDelegate()->editBoxTextChanged(thiz->getCCEditBox(), thiz->getText()); + thiz->getDelegate()->editBoxEditingDidEnd(thiz->getCCEditBox()); + thiz->getDelegate()->editBoxReturn(thiz->getCCEditBox()); + } +} + +void CCEditBoxImplAndroid::openKeyboard() +{ + if (m_pDelegate != NULL) + { + m_pDelegate->editBoxEditingDidBegin(m_pEditBox); + } + + showEditBoxDialogJni( m_strPlaceHolder.c_str(), + m_strText.c_str(), + m_eEditBoxInputMode, + m_eEditBoxInputFlag, + m_eKeyboardReturnType, + m_nMaxLength, + editBoxCallbackFunc, + (void*)this ); + +} + +void CCEditBoxImplAndroid::closeKeyboard() +{ + +} + +NS_CC_EXT_END + diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.h b/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.h new file mode 100644 index 0000000000..9edecf5a4c --- /dev/null +++ b/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.h @@ -0,0 +1,84 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CCEDITBOXIMPLANDROID_H__ +#define __CCEDITBOXIMPLANDROID_H__ + +#include "cocos2d.h" +#include "ExtensionMacros.h" +#include "CCEditBoxImpl.h" + +NS_CC_EXT_BEGIN + +class CCEditBox; + +class CCEditBoxImplAndroid : public CCEditBoxImpl +{ +public: + CCEditBoxImplAndroid(CCEditBox* pEditText); + virtual ~CCEditBoxImplAndroid(); + + virtual bool initWithSize(const CCSize& size); + virtual void setFontColor(const ccColor3B& color); + virtual void setPlaceholderFontColor(const ccColor3B& color); + virtual void setInputMode(EditBoxInputMode inputMode); + virtual void setInputFlag(EditBoxInputFlag inputFlag); + virtual void setMaxLength(int maxLength); + virtual int getMaxLength(); + virtual void setReturnType(KeyboardReturnType returnType); + virtual bool isEditing(); + + virtual void setText(const char* pText); + virtual const char* getText(void); + virtual void setPlaceHolder(const char* pText); + virtual void setPosition(const CCPoint& pos); + virtual void setContentSize(const CCSize& size); + virtual void visit(void); + virtual void doAnimationWhenKeyboardMove(float duration, float distance); + virtual void openKeyboard(); + virtual void closeKeyboard(); + +private: + CCLabelTTF* m_pLabel; + CCLabelTTF* m_pLabelPlaceHolder; + EditBoxInputMode m_eEditBoxInputMode; + EditBoxInputFlag m_eEditBoxInputFlag; + KeyboardReturnType m_eKeyboardReturnType; + + std::string m_strText; + std::string m_strPlaceHolder; + + ccColor3B m_colText; + ccColor3B m_colPlaceHolder; + + int m_nMaxLength; + CCSize m_EditSize; +}; + + +NS_CC_EXT_END + +#endif /* __CCEDITBOXIMPLANDROID_H__ */ + diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h index b73fe4a81a..8d5d9a340b 100644 --- a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h +++ b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h @@ -61,7 +61,6 @@ public: virtual void closeKeyboard(); private: - CCEditBox* m_pEditBox; CCSize m_tContentSize; void* m_pSysEdit; int m_nMaxTextLength; diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm index 665b9a05fd..576fda9233 100644 --- a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm +++ b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm @@ -62,16 +62,16 @@ bool CCEditBoxImplIOS::initWithSize(const CCSize& size) { do { - CCEGLViewProtocol& eglView = CCEGLView::sharedOpenGLView(); + CCEGLViewProtocol* eglView = CCEGLView::sharedOpenGLView(); CGRect rect; - if (eglView.isRetinaEnabled()) + if (eglView->isRetinaEnabled()) { rect = CGRectMake(0, 0, size.width,size.height); } else { - rect = CGRectMake(0, 0, size.width * eglView.getScaleX(),size.height * eglView.getScaleY()); + rect = CGRectMake(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); } m_pSysEdit = [[EditBoxImplIOS alloc] initWithFrame:rect editBox:this]; if (!m_pSysEdit) break; @@ -198,18 +198,18 @@ void CCEditBoxImplIOS::setPlaceHolder(const char* pText) static CGPoint convertDesignCoordToScreenCoord(const CCPoint& designCoord) { float viewH = (float)[[EAGLView sharedEGLView] getHeight]; - CCEGLViewProtocol& eglView = CCEGLView::sharedOpenGLView(); + CCEGLViewProtocol* eglView = CCEGLView::sharedOpenGLView(); CCPoint visiblePos; - if (eglView.isRetinaEnabled()) + if (eglView->isRetinaEnabled()) { visiblePos = ccp(designCoord.x, designCoord.y); } else { - visiblePos = ccp(designCoord.x * eglView.getScaleX(), designCoord.y * eglView.getScaleY()); + visiblePos = ccp(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY()); } - CCPoint screenGLPos = ccpAdd(visiblePos, eglView.getViewPortRect().origin); + CCPoint screenGLPos = ccpAdd(visiblePos, eglView->getViewPortRect().origin); CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y); return screenPos; } diff --git a/make-all-linux-project.sh b/make-all-linux-project.sh index 4fe277fc65..32500f679f 100755 --- a/make-all-linux-project.sh +++ b/make-all-linux-project.sh @@ -25,6 +25,7 @@ if ! test -d $DIR_GLEW170/glew-1.7.0/; then DEPENDS+=' libglfw-dev' DEPENDS+=' g++' DEPENDS+=' libzip-dev' + DEPENDS+=' libcurl4-gnutls-dev' for i in $DEPENDS; do echo -e $TXTCOLOR_GREEN"sudo apt-get install $i, please enter your password:"$TXTCOLOR_DEFAULT sudo apt-get install $i diff --git a/samples/HelloCpp/Classes/AppDelegate.cpp b/samples/HelloCpp/Classes/AppDelegate.cpp index 22f09f4c60..b2c80149f5 100644 --- a/samples/HelloCpp/Classes/AppDelegate.cpp +++ b/samples/HelloCpp/Classes/AppDelegate.cpp @@ -15,7 +15,7 @@ bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); - pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); + pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); TargetPlatform target = getTargetPlatform(); @@ -26,7 +26,7 @@ bool AppDelegate::applicationDidFinishLaunching() { CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); // don't enable retina because we don't have ipad hd resource - CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kResolutionNoBorder); + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionNoBorder); } else if (target == kTargetIphone) { @@ -47,7 +47,7 @@ bool AppDelegate::applicationDidFinishLaunching() { // android, windows, blackberry, linux or mac // use 960*640 resources as design resolution size CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); - CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kResolutionNoBorder); + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionNoBorder); } // turn on display FPS diff --git a/samples/HelloCpp/Classes/HelloWorldScene.cpp b/samples/HelloCpp/Classes/HelloWorldScene.cpp index a9ad685a7e..43117c740f 100644 --- a/samples/HelloCpp/Classes/HelloWorldScene.cpp +++ b/samples/HelloCpp/Classes/HelloWorldScene.cpp @@ -41,7 +41,7 @@ bool HelloWorld::init() this, menu_selector(HelloWorld::menuCloseCallback)); - if (CCApplication::sharedApplication().getTargetPlatform() == kTargetIphone) + if (CCApplication::sharedApplication()->getTargetPlatform() == kTargetIphone) { pCloseItem->setPosition(ccp(visibleSize.width - 20 + origin.x, 20 + origin.y)); } diff --git a/samples/HelloCpp/proj.android/build_native.sh b/samples/HelloCpp/proj.android/build_native.sh index e646bba6dd..e14fddce76 100755 --- a/samples/HelloCpp/proj.android/build_native.sh +++ b/samples/HelloCpp/proj.android/build_native.sh @@ -30,23 +30,16 @@ done # paths -if [ -z "${NDK_ROOT+aaa}" ]; then -# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk" - NDK_ROOT="$HOME/bin/android-ndk" +if [ -z "${NDK_ROOT+aaa}" ];then +echo "please define NDK_ROOT" +exit 1 fi -if [ -z "${COCOS2DX_ROOT+aaa}" ]; then -# ... if COCOS2DX_ROOT is not set -# ... find current working directory - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # ... use paths relative to current directory - COCOS2DX_ROOT="$DIR/../../.." - APP_ROOT="$DIR/.." - APP_ANDROID_ROOT="$DIR" -else - APP_ROOT="$COCOS2DX_ROOT"/samples/"$APPNAME" - APP_ANDROID_ROOT="$COCOS2DX_ROOT"/samples/"$APPNAME"/proj.android -fi +COCOS2DX_ROOT="$DIR/../../.." +APP_ROOT="$DIR/.." +APP_ANDROID_ROOT="$DIR" echo "NDK_ROOT = $NDK_ROOT" echo "COCOS2DX_ROOT = $COCOS2DX_ROOT" diff --git a/samples/HelloCpp/proj.android/jni/hellocpp/main.cpp b/samples/HelloCpp/proj.android/jni/hellocpp/main.cpp index 2c7455571d..035fb201c4 100644 --- a/samples/HelloCpp/proj.android/jni/hellocpp/main.cpp +++ b/samples/HelloCpp/proj.android/jni/hellocpp/main.cpp @@ -24,11 +24,11 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi { if (!CCDirector::sharedDirector()->getOpenGLView()) { - CCEGLView *view = &CCEGLView::sharedOpenGLView(); + CCEGLView *view = CCEGLView::sharedOpenGLView(); view->setFrameSize(w, h); AppDelegate *pAppDelegate = new AppDelegate(); - CCApplication::sharedApplication().run(); + CCApplication::sharedApplication()->run(); } else { diff --git a/samples/HelloCpp/proj.android/src/org/cocos2dx/hellocpp/HelloCpp.java b/samples/HelloCpp/proj.android/src/org/cocos2dx/hellocpp/HelloCpp.java index e5db3954b1..e283af1ad8 100644 --- a/samples/HelloCpp/proj.android/src/org/cocos2dx/hellocpp/HelloCpp.java +++ b/samples/HelloCpp/proj.android/src/org/cocos2dx/hellocpp/HelloCpp.java @@ -37,8 +37,7 @@ import android.widget.FrameLayout; import android.view.ViewGroup; public class HelloCpp extends Cocos2dxActivity{ - private Cocos2dxGLSurfaceView mGLView; - + protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); diff --git a/samples/HelloCpp/proj.blackberry/.cproject b/samples/HelloCpp/proj.blackberry/.cproject index e5c28e0fe2..f76600499b 100644 --- a/samples/HelloCpp/proj.blackberry/.cproject +++ b/samples/HelloCpp/proj.blackberry/.cproject @@ -68,7 +68,7 @@ @@ -166,14 +165,11 @@ @@ -220,13 +216,12 @@ - - - - - - - + + + + + + @@ -257,14 +252,11 @@ @@ -311,13 +303,12 @@ - - - - - - - + + + + + + @@ -327,7 +318,7 @@ @@ -436,15 +423,12 @@ @@ -490,13 +474,12 @@ - - - - - - - + + + + + + @@ -527,14 +510,11 @@ @@ -580,13 +560,12 @@ - - - - - - - + + + + + + @@ -596,7 +575,7 @@