mirror of https://github.com/axmolengine/axmol.git
Merge remote branch 'upstream/master'
This commit is contained in:
commit
4c06cb853b
|
@ -168,7 +168,7 @@ namespace CocosDenshion
|
|||
s3eSoundSetInt(S3E_SOUND_VOLUME, volume);
|
||||
}
|
||||
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
|
||||
|
||||
|
|
|
@ -119,9 +119,9 @@ namespace CocosDenshion
|
|||
setEffectsVolumeJNI(volume);
|
||||
}
|
||||
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
return playEffectJNI(pszFilePath);
|
||||
return playEffectJNI(pszFilePath, bLoop);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
||||
|
|
|
@ -151,17 +151,17 @@ extern "C"
|
|||
}
|
||||
}
|
||||
|
||||
unsigned int playEffectJNI(const char* path)
|
||||
unsigned int playEffectJNI(const char* path, bool bLoop)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
// int playEffect(String)
|
||||
jmethodID playEffectMethodID = getMethodID("playEffect", "(Ljava/lang/String;)I");
|
||||
jmethodID playEffectMethodID = getMethodID("playEffect", "(Ljava/lang/String;Z)I");
|
||||
|
||||
if (playEffectMethodID)
|
||||
{
|
||||
jstring StringArg = env->NewStringUTF(path);
|
||||
ret = env->CallStaticIntMethod(classOfCocos2dxActivity, playEffectMethodID, StringArg);
|
||||
ret = env->CallStaticIntMethod(classOfCocos2dxActivity, playEffectMethodID, StringArg, bLoop);
|
||||
}
|
||||
|
||||
return (unsigned int)ret;
|
||||
|
|
|
@ -13,7 +13,7 @@ extern "C"
|
|||
extern bool isBackgroundMusicPlayingJNI();
|
||||
extern float getBackgroundMusicVolumeJNI();
|
||||
extern void setBackgroundMusicVolumeJNI(float volume);
|
||||
extern unsigned int playEffectJNI(const char* path);
|
||||
extern unsigned int playEffectJNI(const char* path, bool bLoop);
|
||||
extern void stopEffectJNI(unsigned int nSoundId);
|
||||
extern void endJNI();
|
||||
extern float getEffectsVolumeJNI();
|
||||
|
|
|
@ -127,8 +127,9 @@ public:
|
|||
/**
|
||||
@brief Play sound effect
|
||||
@param pszFilePath The path of the effect file,or the FileName of T_SoundResInfo
|
||||
@bLoop Whether to loop the effect playing, default value is false
|
||||
*/
|
||||
unsigned int playEffect(const char* pszFilePath);
|
||||
unsigned int playEffect(const char* pszFilePath, bool bLoop = false);
|
||||
|
||||
/**
|
||||
@brief Stop playing sound effect
|
||||
|
|
|
@ -90,9 +90,9 @@ static void static_setEffectsVolume(float volume)
|
|||
[SimpleAudioEngine sharedEngine].effectsVolume = volume;
|
||||
}
|
||||
|
||||
static unsigned int static_playEffect(const char* pszFilePath)
|
||||
static unsigned int static_playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
return [[SimpleAudioEngine sharedEngine] playEffect:[NSString stringWithUTF8String: pszFilePath]];
|
||||
return [[SimpleAudioEngine sharedEngine] playEffect:[NSString stringWithUTF8String: pszFilePath] loop:bLoop];
|
||||
}
|
||||
|
||||
static void static_stopEffect(int nSoundId)
|
||||
|
@ -210,9 +210,9 @@ namespace CocosDenshion
|
|||
static_setEffectsVolume(volume);
|
||||
}
|
||||
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
return static_playEffect(pszFilePath);
|
||||
return static_playEffect(pszFilePath, bLoop);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
||||
|
|
|
@ -72,11 +72,11 @@
|
|||
-(BOOL) isBackgroundMusicPlaying;
|
||||
|
||||
/** plays an audio effect with a file path*/
|
||||
-(ALuint) playEffect:(NSString*) filePath;
|
||||
-(ALuint) playEffect:(NSString*) filePath loop:(BOOL) loop;
|
||||
/** stop a sound that is playing, note you must pass in the soundId that is returned when you started playing the sound with playEffect */
|
||||
-(void) stopEffect:(ALuint) soundId;
|
||||
/** plays an audio effect with a file path, pitch, pan and gain */
|
||||
-(ALuint) playEffect:(NSString*) filePath pitch:(Float32) pitch pan:(Float32) pan gain:(Float32) gain;
|
||||
-(ALuint) playEffect:(NSString*) filePath loop:(BOOL)loop pitch:(Float32) pitch pan:(Float32) pan gain:(Float32) gain;
|
||||
/** preloads an audio effect */
|
||||
-(void) preloadEffect:(NSString*) filePath;
|
||||
/** unloads an audio effect from memory */
|
||||
|
|
|
@ -123,16 +123,16 @@ static CDBufferManager *bufferManager = nil;
|
|||
|
||||
#pragma mark SimpleAudioEngine - sound effects
|
||||
|
||||
-(ALuint) playEffect:(NSString*) filePath
|
||||
-(ALuint) playEffect:(NSString*) filePath loop:(BOOL) loop
|
||||
{
|
||||
return [self playEffect:filePath pitch:1.0f pan:0.0f gain:1.0f];
|
||||
return [self playEffect:filePath loop:loop pitch:1.0f pan:0.0f gain:1.0f];
|
||||
}
|
||||
|
||||
-(ALuint) playEffect:(NSString*) filePath pitch:(Float32) pitch pan:(Float32) pan gain:(Float32) gain
|
||||
-(ALuint) playEffect:(NSString*) filePath loop:(BOOL) loop pitch:(Float32) pitch pan:(Float32) pan gain:(Float32) gain
|
||||
{
|
||||
int soundId = [bufferManager bufferForFile:filePath create:YES];
|
||||
if (soundId != kCDNoBuffer) {
|
||||
return [soundEngine playSound:soundId sourceGroupId:0 pitch:pitch pan:pan gain:gain loop:false];
|
||||
return [soundEngine playSound:soundId sourceGroupId:0 pitch:pitch pan:pan gain:gain loop:loop];
|
||||
} else {
|
||||
return CD_MUTE;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ void MciPlayer::Play(UINT uTimes /* = 1 */)
|
|||
}
|
||||
MCI_PLAY_PARMS mciPlay = {0};
|
||||
mciPlay.dwCallback = (DWORD_PTR)m_hWnd;
|
||||
s_mciError = mciSendCommand(m_hDev,MCI_PLAY, MCI_NOTIFY,(DWORD)&mciPlay);
|
||||
s_mciError = mciSendCommand(m_hDev,MCI_PLAY, MCI_FROM|MCI_NOTIFY,(DWORD)&mciPlay);
|
||||
if (! s_mciError)
|
||||
{
|
||||
m_bPlaying = true;
|
||||
|
|
|
@ -9,8 +9,8 @@ using namespace std;
|
|||
|
||||
namespace CocosDenshion {
|
||||
|
||||
typedef map<unsigned int, MciPlayer> EffectList;
|
||||
typedef pair<unsigned int, MciPlayer> Effect;
|
||||
typedef map<unsigned int, MciPlayer *> EffectList;
|
||||
typedef pair<unsigned int, MciPlayer *> Effect;
|
||||
|
||||
static char s_szRootPath[MAX_PATH];
|
||||
static DWORD s_dwRootLen;
|
||||
|
@ -50,6 +50,14 @@ SimpleAudioEngine* SimpleAudioEngine::sharedEngine()
|
|||
void SimpleAudioEngine::end()
|
||||
{
|
||||
sharedMusic().Close();
|
||||
|
||||
EffectList::iterator p = sharedList().begin();
|
||||
while (p != sharedList().end())
|
||||
{
|
||||
delete p->second;
|
||||
p->second = NULL;
|
||||
p++;
|
||||
}
|
||||
sharedList().clear();
|
||||
return;
|
||||
}
|
||||
|
@ -114,7 +122,7 @@ bool SimpleAudioEngine::isBackgroundMusicPlaying()
|
|||
// effect function
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
unsigned int nRet = _Hash(pszFilePath);
|
||||
|
||||
|
@ -123,7 +131,7 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
|
|||
EffectList::iterator p = sharedList().find(nRet);
|
||||
if (p != sharedList().end())
|
||||
{
|
||||
p->second.Rewind();
|
||||
p->second->Play((bLoop) ? -1 : 1);
|
||||
}
|
||||
|
||||
return nRet;
|
||||
|
@ -134,7 +142,7 @@ void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
|||
EffectList::iterator p = sharedList().find(nSoundId);
|
||||
if (p != sharedList().end())
|
||||
{
|
||||
p->second.Stop();
|
||||
p->second->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,11 +157,11 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
|
|||
|
||||
BREAK_IF(sharedList().end() != sharedList().find(nRet));
|
||||
|
||||
sharedList().insert(Effect(nRet, MciPlayer()));
|
||||
MciPlayer& player = sharedList()[nRet];
|
||||
player.Open(_FullPath(pszFilePath), nRet);
|
||||
sharedList().insert(Effect(nRet, new MciPlayer()));
|
||||
MciPlayer * pPlayer = sharedList()[nRet];
|
||||
pPlayer->Open(_FullPath(pszFilePath), nRet);
|
||||
|
||||
BREAK_IF(nRet == player.GetSoundID());
|
||||
BREAK_IF(nRet == pPlayer->GetSoundID());
|
||||
|
||||
sharedList().erase(nRet);
|
||||
nRet = 0;
|
||||
|
@ -168,7 +176,14 @@ void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
|||
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
|
||||
{
|
||||
unsigned int nID = _Hash(pszFilePath);
|
||||
sharedList().erase(nID);
|
||||
|
||||
EffectList::iterator p = sharedList().find(nID);
|
||||
if (p != sharedList().end())
|
||||
{
|
||||
delete p->second;
|
||||
p->second = NULL;
|
||||
sharedList().erase(nID);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -204,7 +204,7 @@ void SimpleAudioEngine::setEffectsVolume(float volume)
|
|||
|
||||
|
||||
// for sound effects
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
preloadEffect(pszFilePath);
|
||||
int nRet = -1;
|
||||
|
@ -219,6 +219,12 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
|
|||
soundParam.dataLen = pElement->nDataSize;
|
||||
soundParam.dataType = SOUND_TYPE_WAVE;
|
||||
soundParam.volume = (int) (0xFFFF * s_fEffectsVolume);
|
||||
int nTimes = 0;
|
||||
if (bLoop)
|
||||
{
|
||||
nTimes = -1;
|
||||
}
|
||||
soundParam.loopTime = nTimes;
|
||||
|
||||
nRet = s_pEffectPlayer->Play(soundParam);
|
||||
} while (0);
|
||||
|
|
|
@ -149,8 +149,8 @@ public class Cocos2dxActivity extends Activity{
|
|||
backgroundMusicPlayer.setBackgroundVolume(volume);
|
||||
}
|
||||
|
||||
public static int playEffect(String path){
|
||||
return soundPlayer.playEffect(path);
|
||||
public static int playEffect(String path, boolean isLoop){
|
||||
return soundPlayer.playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
public static void stopEffect(int soundId){
|
||||
|
|
|
@ -28,11 +28,7 @@ public class Cocos2dxBitmap{
|
|||
public static void createTextBitmap(String content, String fontName,
|
||||
int fontSize, int alignment, int width, int height){
|
||||
|
||||
// Avoid error when content is ""
|
||||
if (content.compareTo("") == 0){
|
||||
content = " ";
|
||||
}
|
||||
|
||||
content = refactorString(content);
|
||||
Paint paint = newPaint(fontName, fontSize, alignment);
|
||||
|
||||
TextProperty textProperty = getTextWidthAndHeight(content, paint, width, height);
|
||||
|
@ -272,6 +268,40 @@ public class Cocos2dxBitmap{
|
|||
return paint;
|
||||
}
|
||||
|
||||
private static String refactorString(String str){
|
||||
// Avoid error when content is ""
|
||||
if (str.compareTo("") == 0){
|
||||
return " ";
|
||||
}
|
||||
|
||||
/*
|
||||
* If the font of "\n" is "" or "\n", insert " " in front of it.
|
||||
*
|
||||
* For example:
|
||||
* "\nabc" -> " \nabc"
|
||||
* "\nabc\n\n" -> " \nabc\n \n"
|
||||
*/
|
||||
StringBuilder strBuilder = new StringBuilder(str);
|
||||
int start = 0;
|
||||
int index = strBuilder.indexOf("\n");
|
||||
while (index != -1){
|
||||
if (index == 0 || strBuilder.charAt(index -1) == '\n'){
|
||||
strBuilder.insert(start, " ");
|
||||
start = index + 2;
|
||||
} else {
|
||||
start = index + 1;
|
||||
}
|
||||
|
||||
if (start > strBuilder.length() || index == strBuilder.length()){
|
||||
break;
|
||||
}
|
||||
|
||||
index = strBuilder.indexOf("\n", start);
|
||||
}
|
||||
|
||||
return strBuilder.toString();
|
||||
}
|
||||
|
||||
private static void initNativeObject(Bitmap bitmap){
|
||||
byte[] pixels = getPixels(bitmap);
|
||||
if (pixels == null){
|
||||
|
|
|
@ -81,9 +81,18 @@ class TextInputWraper implements TextWatcher, OnEditorActionListener {
|
|||
LogD("deleteBackward");
|
||||
}
|
||||
String text = v.getText().toString();
|
||||
|
||||
/*
|
||||
* If user input nothing, translate "\n" to engine.
|
||||
*/
|
||||
if (text.compareTo("") == 0){
|
||||
text = "\n";
|
||||
}
|
||||
|
||||
if ('\n' != text.charAt(text.length() - 1)) {
|
||||
text += '\n';
|
||||
}
|
||||
|
||||
final String insertText = text;
|
||||
mMainView.insertText(insertText);
|
||||
LogD("insertText(" + insertText + ")");
|
||||
|
|
|
@ -28,7 +28,6 @@ public class Cocos2dxSound {
|
|||
private static final int MAX_SIMULTANEOUS_STREAMS_DEFAULT = 5;
|
||||
private static final float SOUND_RATE = 1.0f;
|
||||
private static final int SOUND_PRIORITY = 1;
|
||||
private static final int SOUND_LOOP_TIME = 0;
|
||||
private static final int SOUND_QUALITY = 5;
|
||||
|
||||
private final int INVALID_SOUND_ID = -1;
|
||||
|
@ -75,15 +74,17 @@ public class Cocos2dxSound {
|
|||
}
|
||||
}
|
||||
|
||||
public int playEffect(String path){
|
||||
public int playEffect(String path, boolean isLoop){
|
||||
Integer soundId = this.mPathSoundIDMap.get(path);
|
||||
|
||||
if (soundId != null){
|
||||
// the sound is preloaded
|
||||
// the sound is preloaded, stop it first
|
||||
|
||||
this.mSoundPool.stop(soundId);
|
||||
|
||||
// play sound
|
||||
int streamId = this.mSoundPool.play(soundId.intValue(), this.mLeftVolume,
|
||||
this.mRightVolume, SOUND_PRIORITY, SOUND_LOOP_TIME, SOUND_RATE);
|
||||
this.mRightVolume, SOUND_PRIORITY, isLoop ? -1 : 0, SOUND_RATE);
|
||||
|
||||
// record sound id and stream id map
|
||||
this.mSoundIdStreamIdMap.put(soundId, streamId);
|
||||
|
@ -106,7 +107,7 @@ public class Cocos2dxSound {
|
|||
* Because the method is supported from 2.2, so I can't use
|
||||
* it here.
|
||||
*/
|
||||
playEffect(path);
|
||||
playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
return soundId.intValue();
|
||||
|
|
|
@ -149,8 +149,8 @@ public class Cocos2dxActivity extends Activity{
|
|||
backgroundMusicPlayer.setBackgroundVolume(volume);
|
||||
}
|
||||
|
||||
public static int playEffect(String path){
|
||||
return soundPlayer.playEffect(path);
|
||||
public static int playEffect(String path, boolean isLoop){
|
||||
return soundPlayer.playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
public static void stopEffect(int soundId){
|
||||
|
|
|
@ -28,11 +28,7 @@ public class Cocos2dxBitmap{
|
|||
public static void createTextBitmap(String content, String fontName,
|
||||
int fontSize, int alignment, int width, int height){
|
||||
|
||||
// Avoid error when content is ""
|
||||
if (content.compareTo("") == 0){
|
||||
content = " ";
|
||||
}
|
||||
|
||||
content = refactorString(content);
|
||||
Paint paint = newPaint(fontName, fontSize, alignment);
|
||||
|
||||
TextProperty textProperty = getTextWidthAndHeight(content, paint, width, height);
|
||||
|
@ -272,6 +268,40 @@ public class Cocos2dxBitmap{
|
|||
return paint;
|
||||
}
|
||||
|
||||
private static String refactorString(String str){
|
||||
// Avoid error when content is ""
|
||||
if (str.compareTo("") == 0){
|
||||
return " ";
|
||||
}
|
||||
|
||||
/*
|
||||
* If the font of "\n" is "" or "\n", insert " " in front of it.
|
||||
*
|
||||
* For example:
|
||||
* "\nabc" -> " \nabc"
|
||||
* "\nabc\n\n" -> " \nabc\n \n"
|
||||
*/
|
||||
StringBuilder strBuilder = new StringBuilder(str);
|
||||
int start = 0;
|
||||
int index = strBuilder.indexOf("\n");
|
||||
while (index != -1){
|
||||
if (index == 0 || strBuilder.charAt(index -1) == '\n'){
|
||||
strBuilder.insert(start, " ");
|
||||
start = index + 2;
|
||||
} else {
|
||||
start = index + 1;
|
||||
}
|
||||
|
||||
if (start > strBuilder.length() || index == strBuilder.length()){
|
||||
break;
|
||||
}
|
||||
|
||||
index = strBuilder.indexOf("\n", start);
|
||||
}
|
||||
|
||||
return strBuilder.toString();
|
||||
}
|
||||
|
||||
private static void initNativeObject(Bitmap bitmap){
|
||||
byte[] pixels = getPixels(bitmap);
|
||||
if (pixels == null){
|
||||
|
|
|
@ -81,9 +81,18 @@ class TextInputWraper implements TextWatcher, OnEditorActionListener {
|
|||
LogD("deleteBackward");
|
||||
}
|
||||
String text = v.getText().toString();
|
||||
|
||||
/*
|
||||
* If user input nothing, translate "\n" to engine.
|
||||
*/
|
||||
if (text.compareTo("") == 0){
|
||||
text = "\n";
|
||||
}
|
||||
|
||||
if ('\n' != text.charAt(text.length() - 1)) {
|
||||
text += '\n';
|
||||
}
|
||||
|
||||
final String insertText = text;
|
||||
mMainView.insertText(insertText);
|
||||
LogD("insertText(" + insertText + ")");
|
||||
|
|
|
@ -28,7 +28,6 @@ public class Cocos2dxSound {
|
|||
private static final int MAX_SIMULTANEOUS_STREAMS_DEFAULT = 5;
|
||||
private static final float SOUND_RATE = 1.0f;
|
||||
private static final int SOUND_PRIORITY = 1;
|
||||
private static final int SOUND_LOOP_TIME = 0;
|
||||
private static final int SOUND_QUALITY = 5;
|
||||
|
||||
private final int INVALID_SOUND_ID = -1;
|
||||
|
@ -75,15 +74,17 @@ public class Cocos2dxSound {
|
|||
}
|
||||
}
|
||||
|
||||
public int playEffect(String path){
|
||||
public int playEffect(String path, boolean isLoop){
|
||||
Integer soundId = this.mPathSoundIDMap.get(path);
|
||||
|
||||
if (soundId != null){
|
||||
// the sound is preloaded
|
||||
// the sound is preloaded, stop it first
|
||||
|
||||
this.mSoundPool.stop(soundId);
|
||||
|
||||
// play sound
|
||||
int streamId = this.mSoundPool.play(soundId.intValue(), this.mLeftVolume,
|
||||
this.mRightVolume, SOUND_PRIORITY, SOUND_LOOP_TIME, SOUND_RATE);
|
||||
this.mRightVolume, SOUND_PRIORITY, isLoop ? -1 : 0, SOUND_RATE);
|
||||
|
||||
// record sound id and stream id map
|
||||
this.mSoundIdStreamIdMap.put(soundId, streamId);
|
||||
|
@ -106,7 +107,7 @@ public class Cocos2dxSound {
|
|||
* Because the method is supported from 2.2, so I can't use
|
||||
* it here.
|
||||
*/
|
||||
playEffect(path);
|
||||
playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
return soundId.intValue();
|
||||
|
|
|
@ -65,7 +65,12 @@ platform/platform.cpp \
|
|||
platform/android/CCEGLView_android.cpp \
|
||||
platform/android/CCAccelerometer_android.cpp \
|
||||
platform/android/CCApplication_android.cpp \
|
||||
platform/android/Cocos2dJni.cpp \
|
||||
platform/android/jni/JniHelper.cpp \
|
||||
platform/android/jni/IMEJni.cpp \
|
||||
platform/android/jni/MessageJni.cpp \
|
||||
platform/android/jni/SensorJni.cpp \
|
||||
platform/android/jni/SystemInfoJni.cpp \
|
||||
platform/android/jni/TouchesJni.cpp \
|
||||
script_support/CCScriptSupport.cpp \
|
||||
sprite_nodes/CCAnimation.cpp \
|
||||
sprite_nodes/CCAnimationCache.cpp \
|
||||
|
@ -97,7 +102,7 @@ tileMap_parallax_nodes/CCTMXTiledMap.cpp \
|
|||
tileMap_parallax_nodes/CCTMXXMLParser.cpp \
|
||||
tileMap_parallax_nodes/CCTileMapAtlas.cpp \
|
||||
touch_dispatcher/CCTouchDispatcher.cpp \
|
||||
touch_dispatcher/CCTouchHandler.cpp \
|
||||
touch_dispatcher/CCTouchHandler.cpp
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
m_array.resize(uSize);
|
||||
}
|
||||
|
||||
~CCMutableArray(void)
|
||||
virtual ~CCMutableArray(void)
|
||||
{
|
||||
removeAllObjects();
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ public:
|
|||
|
||||
/* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */
|
||||
CCData *getUIImageAsDataFromBuffer(int format);
|
||||
|
||||
bool getUIImageFromBuffer(CCImage *pImage);
|
||||
|
||||
protected:
|
||||
GLuint m_uFBO;
|
||||
GLint m_nOldFBO;
|
||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
|||
#include "platform/platform.h"
|
||||
#include "CCImage.h"
|
||||
#include "support/ccUtils.h"
|
||||
|
||||
#include "CCFileUtils.h"
|
||||
#include "CCGL.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
@ -172,13 +172,13 @@ void CCRenderTexture::begin()
|
|||
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
|
||||
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);//Will direct drawing to the frame buffer created above
|
||||
|
||||
// Issue #1145
|
||||
// There is no need to enable the default GL states here
|
||||
// but since CCRenderTexture is mostly used outside the "render" loop
|
||||
// these states needs to be enabled.
|
||||
// Since this bug was discovered in API-freeze (very close of 1.0 release)
|
||||
// This bug won't be fixed to prevent incompatibilities with code.
|
||||
//
|
||||
// Issue #1145
|
||||
// There is no need to enable the default GL states here
|
||||
// but since CCRenderTexture is mostly used outside the "render" loop
|
||||
// these states needs to be enabled.
|
||||
// Since this bug was discovered in API-freeze (very close of 1.0 release)
|
||||
// This bug won't be fixed to prevent incompatibilities with code.
|
||||
//
|
||||
// If you understand the above mentioned message, then you can comment the following line
|
||||
// and enable the gl states manually, in case you need them.
|
||||
|
||||
|
@ -222,25 +222,67 @@ bool CCRenderTexture::saveBuffer(const char *name)
|
|||
}
|
||||
bool CCRenderTexture::saveBuffer(const char *fileName, int format)
|
||||
{
|
||||
CC_UNUSED_PARAM(fileName);
|
||||
CC_UNUSED_PARAM(format);
|
||||
bool bRet = false;
|
||||
//@ todo CCRenderTexture::saveBuffer
|
||||
// UIImage *myImage = this->getUIImageFromBuffer(format);
|
||||
// CCMutableArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
// CCString *documentsDirectory = [paths objectAtIndex:0];
|
||||
// CCString *fullPath = [documentsDirectory stringByAppendingPathComponent:fileName];
|
||||
|
||||
// CCData * data = this->getUIImageAsDataFromBuffer(format);
|
||||
// if (data)
|
||||
// {
|
||||
// bRet = data->writeToFile(path, true);
|
||||
// delete data;
|
||||
// bRet = true;
|
||||
// }
|
||||
bool bRet = false;
|
||||
CCAssert(format == kCCImageFormatJPG || format == kCCImageFormatPNG,
|
||||
"the image can only be saved as JPG or PNG format");
|
||||
|
||||
CCImage *pImage = new CCImage();
|
||||
if (pImage != NULL && getUIImageFromBuffer(pImage))
|
||||
{
|
||||
std::string fullpath = CCFileUtils::getWriteablePath() + fileName;
|
||||
if (kCCImageFormatPNG == format)
|
||||
{
|
||||
fullpath += ".png";
|
||||
}
|
||||
else
|
||||
{
|
||||
fullpath += ".jpg";
|
||||
}
|
||||
|
||||
bRet = pImage->saveToFile(fullpath.c_str());
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(pImage);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
/* get buffer as UIImage */
|
||||
bool CCRenderTexture::getUIImageFromBuffer(CCImage *pImage)
|
||||
{
|
||||
if (NULL == pImage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GLubyte * pBuffer = NULL;
|
||||
bool bRet = false;
|
||||
|
||||
do
|
||||
{
|
||||
CCAssert(m_ePixelFormat == kCCTexture2DPixelFormat_RGBA8888, "only RGBA8888 can be saved as image");
|
||||
|
||||
CCSize s = m_pTexture->getContentSizeInPixels();
|
||||
int tx = (int)s.width;
|
||||
int ty = (int)s.height;
|
||||
|
||||
CC_BREAK_IF(! (pBuffer = new GLubyte[tx * ty * 4]));
|
||||
|
||||
this->begin();
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, pBuffer);
|
||||
this->end();
|
||||
|
||||
bRet = pImage->initWithImageData(pBuffer, tx * ty * 4, CCImage::kFmtRawData, tx, ty, 8);
|
||||
} while (0);
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(pBuffer);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
||||
CCData * CCRenderTexture::getUIImageAsDataFromBuffer(int format)
|
||||
{
|
||||
CC_UNUSED_PARAM(format);
|
||||
|
|
|
@ -159,8 +159,9 @@ NS_CC_END;
|
|||
|
||||
#include <android/log.h>
|
||||
#include <stdio.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "android/Cocos2dJni.h"
|
||||
#include "android/jni/MessageJni.h"
|
||||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
|
|
|
@ -94,7 +94,12 @@ bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = e
|
|||
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
|
||||
}
|
||||
|
||||
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
||||
bool CCImage::initWithImageData(void * pData,
|
||||
int nDataLen,
|
||||
EImageFormat eFmt/* = eSrcFmtPng*/,
|
||||
int nWidth/* = 0*/,
|
||||
int nHeight/* = 0*/,
|
||||
int nBitsPerComponent/* = 8*/)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
|
@ -111,6 +116,11 @@ bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/*
|
|||
bRet = _initWithJpgData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
else if (kFmtRawData == eFmt)
|
||||
{
|
||||
bRet = _initWithRawData(pData, nDataLen, nWidth, nHeight, nBitsPerComponent);
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
|
@ -287,6 +297,283 @@ bool CCImage::_initWithPngData(void * pData, int nDatalen)
|
|||
return bRet;
|
||||
}
|
||||
|
||||
bool CCImage::_initWithRawData(void * pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(0 == nWidth || 0 == nHeight);
|
||||
|
||||
m_nBitsPerComponent = nBitsPerComponent;
|
||||
m_nHeight = (short)nHeight;
|
||||
m_nWidth = (short)nWidth;
|
||||
m_bHasAlpha = true;
|
||||
|
||||
// only RGBA8888 surported
|
||||
int nBytesPerComponent = 4;
|
||||
int nSize = nHeight * nWidth * nBytesPerComponent;
|
||||
m_pData = new unsigned char[nSize];
|
||||
CC_BREAK_IF(! m_pData);
|
||||
memcpy(m_pData, pData, nSize);
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CCImage::saveToFile(const char *pszFilePath, bool bIsToRGB)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(NULL == pszFilePath);
|
||||
|
||||
std::string strFilePath(pszFilePath);
|
||||
CC_BREAK_IF(strFilePath.size() <= 4);
|
||||
|
||||
std::string strLowerCasePath(strFilePath);
|
||||
for (unsigned int i = 0; i < strLowerCasePath.length(); ++i)
|
||||
{
|
||||
strLowerCasePath[i] = tolower(strFilePath[i]);
|
||||
}
|
||||
|
||||
if (std::string::npos != strLowerCasePath.find(".png"))
|
||||
{
|
||||
CC_BREAK_IF(!_saveImageToPNG(pszFilePath, bIsToRGB));
|
||||
}
|
||||
else if (std::string::npos != strLowerCasePath.find(".jpg"))
|
||||
{
|
||||
CC_BREAK_IF(!_saveImageToJPG(pszFilePath));
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CCImage::_saveImageToPNG(const char * pszFilePath, bool bIsToRGB)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(NULL == pszFilePath);
|
||||
|
||||
FILE *fp;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_colorp palette;
|
||||
png_bytep *row_pointers;
|
||||
|
||||
fp = fopen(pszFilePath, "wb");
|
||||
CC_BREAK_IF(NULL == fp);
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
||||
if (NULL == png_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
break;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (NULL == info_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
if (!bIsToRGB && m_bHasAlpha)
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, m_nWidth, m_nHeight, 8, PNG_COLOR_TYPE_RGB_ALPHA,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, m_nWidth, m_nHeight, 8, PNG_COLOR_TYPE_RGB,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
}
|
||||
|
||||
palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof (png_color));
|
||||
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
row_pointers = (png_bytep *)malloc(m_nHeight * sizeof(png_bytep));
|
||||
if(row_pointers == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!m_bHasAlpha)
|
||||
{
|
||||
for (int i = 0; i < (int)m_nHeight; i++)
|
||||
{
|
||||
row_pointers[i] = (png_bytep)m_pData + i * m_nWidth * 3;
|
||||
}
|
||||
|
||||
png_write_image(png_ptr, row_pointers);
|
||||
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bIsToRGB)
|
||||
{
|
||||
unsigned char *pTempData = new unsigned char[m_nWidth * m_nHeight * 3];
|
||||
if (NULL == pTempData)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_nHeight; ++i)
|
||||
{
|
||||
for (int j = 0; j < m_nWidth; ++j)
|
||||
{
|
||||
pTempData[(i * m_nWidth + j) * 3] = m_pData[(i * m_nWidth + j) * 4];
|
||||
pTempData[(i * m_nWidth + j) * 3 + 1] = m_pData[(i * m_nWidth + j) * 4 + 1];
|
||||
pTempData[(i * m_nWidth + j) * 3 + 2] = m_pData[(i * m_nWidth + j) * 4 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)m_nHeight; i++)
|
||||
{
|
||||
row_pointers[i] = (png_bytep)pTempData + i * m_nWidth * 3;
|
||||
}
|
||||
|
||||
png_write_image(png_ptr, row_pointers);
|
||||
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(pTempData);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < (int)m_nHeight; i++)
|
||||
{
|
||||
row_pointers[i] = (png_bytep)m_pData + i * m_nWidth * 4;
|
||||
}
|
||||
|
||||
png_write_image(png_ptr, row_pointers);
|
||||
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
png_free(png_ptr, palette);
|
||||
palette = NULL;
|
||||
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
bool CCImage::_saveImageToJPG(const char * pszFilePath)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(NULL == pszFilePath);
|
||||
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
FILE * outfile; /* target file */
|
||||
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
|
||||
int row_stride; /* physical row width in image buffer */
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
/* Now we can initialize the JPEG compression object. */
|
||||
jpeg_create_compress(&cinfo);
|
||||
|
||||
CC_BREAK_IF((outfile = fopen(pszFilePath, "wb")) == NULL);
|
||||
|
||||
jpeg_stdio_dest(&cinfo, outfile);
|
||||
|
||||
cinfo.image_width = m_nWidth; /* image width and height, in pixels */
|
||||
cinfo.image_height = m_nHeight;
|
||||
cinfo.input_components = 3; /* # of color components per pixel */
|
||||
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
|
||||
|
||||
jpeg_set_defaults(&cinfo);
|
||||
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
|
||||
row_stride = m_nWidth * 3; /* JSAMPLEs per row in image_buffer */
|
||||
|
||||
if (m_bHasAlpha)
|
||||
{
|
||||
unsigned char *pTempData = new unsigned char[m_nWidth * m_nHeight * 3];
|
||||
if (NULL == pTempData)
|
||||
{
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
fclose(outfile);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_nHeight; ++i)
|
||||
{
|
||||
for (int j = 0; j < m_nWidth; ++j)
|
||||
{
|
||||
pTempData[(i * m_nWidth + j) * 3] = m_pData[(i * m_nWidth + j) * 4];
|
||||
pTempData[(i * m_nWidth + j) * 3 + 1] = m_pData[(i * m_nWidth + j) * 4 + 1];
|
||||
pTempData[(i * m_nWidth + j) * 3 + 2] = m_pData[(i * m_nWidth + j) * 4 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
row_pointer[0] = & pTempData[cinfo.next_scanline * row_stride];
|
||||
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(pTempData);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
row_pointer[0] = & m_pData[cinfo.next_scanline * row_stride];
|
||||
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||
}
|
||||
}
|
||||
|
||||
jpeg_finish_compress(&cinfo);
|
||||
fclose(outfile);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
#endif // (CC_TARGET_PLATFORM != TARGET_OS_IPHONE)
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
{
|
||||
kFmtJpg = 0,
|
||||
kFmtPng,
|
||||
kFmtRawData,
|
||||
}EImageFormat;
|
||||
|
||||
typedef enum
|
||||
|
@ -65,12 +66,18 @@ public:
|
|||
/**
|
||||
@brief Load image from stream buffer.
|
||||
|
||||
@warning Only support png data now.
|
||||
@warning kFmtRawData only support RGBA8888
|
||||
@param pBuffer stream buffer that hold the image data
|
||||
@param nLength the length of data(managed in byte)
|
||||
@param nWidth, nHeight, nBitsPerComponent are used for kFmtRawData
|
||||
@return true if load correctly
|
||||
*/
|
||||
bool initWithImageData(void * pData, int nDataLen, EImageFormat eFmt = kFmtPng);
|
||||
bool initWithImageData(void * pData,
|
||||
int nDataLen,
|
||||
EImageFormat eFmt = kFmtPng,
|
||||
int nWidth = 0,
|
||||
int nHeight = 0,
|
||||
int nBitsPerComponent = 8);
|
||||
|
||||
/**
|
||||
@brief Create image with specified string.
|
||||
|
@ -99,18 +106,26 @@ public:
|
|||
|
||||
/**
|
||||
@brief Save the CCImage data to specified file with specified format.
|
||||
@param pszFilePath the file's absolute path, including file subfix
|
||||
@param bIsToRGB if the image is saved as RGB format
|
||||
*/
|
||||
bool saveToFile(const char * pszFilePath) { CC_UNUSED_PARAM(pszFilePath);return false; }
|
||||
bool saveToFile(const char *pszFilePath, bool bIsToRGB = true);
|
||||
|
||||
CC_SYNTHESIZE_READONLY(short, m_nWidth, Width);
|
||||
CC_SYNTHESIZE_READONLY(short, m_nHeight, Height);
|
||||
CC_SYNTHESIZE_READONLY(int, m_nBitsPerComponent, BitsPerComponent);
|
||||
CC_SYNTHESIZE_READONLY(int, m_nBitsPerComponent, BitsPerComponent);
|
||||
|
||||
protected:
|
||||
bool _initWithJpgData(void * pData, int nDatalen);
|
||||
bool _initWithPngData(void * pData, int nDatalen);
|
||||
bool _initWithJpgData(void *pData, int nDatalen);
|
||||
bool _initWithPngData(void *pData, int nDatalen);
|
||||
|
||||
unsigned char * m_pData;
|
||||
// @warning kFmtRawData only support RGBA8888
|
||||
bool _initWithRawData(void *pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent);
|
||||
|
||||
bool _saveImageToPNG(const char *pszFilePath, bool bIsToRGB = true);
|
||||
bool _saveImageToJPG(const char *pszFilePath);
|
||||
|
||||
unsigned char *m_pData;
|
||||
bool m_bHasAlpha;
|
||||
bool m_bPreMulti;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "CCAccelerometer_android.h"
|
||||
#include "jni/SensorJni.h"
|
||||
#include <stdio.h>
|
||||
#include <android/log.h>
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCCommon.h"
|
||||
#include "CCAccelerometerDelegate.h"
|
||||
#include "Cocos2dJni.h"
|
||||
#include <list>
|
||||
|
||||
namespace cocos2d {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "CCApplication.h"
|
||||
|
||||
#include "jni/JniHelper.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCEGLView.h"
|
||||
#include "Cocos2dJni.h"
|
||||
#include "android/jni/SystemInfoJni.h"
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
@ -41,44 +41,15 @@ int CCApplication::run()
|
|||
|
||||
void CCApplication::setAnimationInterval(double interval)
|
||||
{
|
||||
jmethodID ret = 0;
|
||||
JNIEnv *env = 0;
|
||||
jclass classOfCocos2dxRenderer = 0;
|
||||
|
||||
if (! gJavaVM)
|
||||
JniMethodInfo methodInfo;
|
||||
if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxRenderer", "setAnimationInterval",
|
||||
"(D)V"))
|
||||
{
|
||||
LOGD("have not java vm");
|
||||
return;
|
||||
CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
// get jni environment and java class for Cocos2dxActivity
|
||||
if (gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK)
|
||||
else
|
||||
{
|
||||
LOGD("Failed to get the environment using GetEnv()");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gJavaVM->AttachCurrentThread(&env, 0) < 0)
|
||||
{
|
||||
LOGD("Failed to get the environment using AttachCurrentThread()");
|
||||
return;
|
||||
}
|
||||
|
||||
classOfCocos2dxRenderer = env->FindClass("org/cocos2dx/lib/Cocos2dxRenderer");
|
||||
if (! classOfCocos2dxRenderer)
|
||||
{
|
||||
LOGD("Failed to find class of org/cocos2dx/lib/Cocos2dxRenderer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (env != 0 && classOfCocos2dxRenderer != 0)
|
||||
{
|
||||
ret = env->GetStaticMethodID(classOfCocos2dxRenderer, "setAnimationInterval", "(D)V");
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
env->CallStaticVoidMethod(classOfCocos2dxRenderer, ret, interval);
|
||||
}
|
||||
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, interval);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,12 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
#include "CCEGLView_android.h"
|
||||
#include "GLES/gl.h"
|
||||
|
||||
#include "CCSet.h"
|
||||
#include "CCDirector.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CCTouchDispatcher.h"
|
||||
#include "Cocos2dJni.h"
|
||||
#include "jni/IMEJni.h"
|
||||
#include "jni/MessageJni.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN;
|
||||
|
||||
#include "CCCommon.h"
|
||||
#include "Cocos2dJni.h"
|
||||
#include "jni/SystemInfoJni.h"
|
||||
|
||||
#define MAX_PATH 256
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ THE SOFTWARE.
|
|||
#include <jni.h>
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "Cocos2dJni.h"
|
||||
#include "CCImage.h"
|
||||
#include "jni/JniHelper.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN;
|
||||
|
@ -55,28 +55,11 @@ public:
|
|||
|
||||
bool getBitmapFromJava(const char *text, int nWidth, int nHeight, CCImage::ETextAlign eAlignMask, const char * pFontName, float fontSize)
|
||||
{
|
||||
// get env
|
||||
if (gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4) <0 )
|
||||
JniMethodInfo methodInfo;
|
||||
if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxBitmap", "createTextBitmap",
|
||||
"(Ljava/lang/String;Ljava/lang/String;IIII)V"))
|
||||
{
|
||||
if (gJavaVM->AttachCurrentThread(&env, NULL) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// get class
|
||||
jclass mClass = env->FindClass("org/cocos2dx/lib/Cocos2dxBitmap");
|
||||
if (! mClass)
|
||||
{
|
||||
CCLOG("can not find org.cocos2dx.Cocos2dJNI");
|
||||
return false;
|
||||
}
|
||||
|
||||
// get method of createBitmap
|
||||
jmethodID midCreateTextBitmap = env->GetStaticMethodID(mClass, "createTextBitmap", "(Ljava/lang/String;Ljava/lang/String;IIII)V");
|
||||
if (! midCreateTextBitmap)
|
||||
{
|
||||
CCLOG("can not find method createTextBitmap");
|
||||
CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -86,8 +69,8 @@ public:
|
|||
* and data.
|
||||
* use this appoach to decrease the jni call number
|
||||
*/
|
||||
env->CallStaticVoidMethod(mClass, midCreateTextBitmap, env->NewStringUTF(text), env->NewStringUTF(pFontName),
|
||||
(int)fontSize, eAlignMask, nWidth, nHeight);
|
||||
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, methodInfo.env->NewStringUTF(text),
|
||||
methodInfo.env->NewStringUTF(pFontName), (int)fontSize, eAlignMask, nWidth, nHeight);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -159,7 +142,7 @@ extern "C"
|
|||
cocos2d::sharedBitmapDC().m_nWidth = width;
|
||||
cocos2d::sharedBitmapDC().m_nHeight = height;
|
||||
cocos2d::sharedBitmapDC().m_pData = new unsigned char[size];
|
||||
cocos2d::sharedBitmapDC().env->GetByteArrayRegion(pixels, 0, size, (jbyte*)cocos2d::sharedBitmapDC().m_pData);
|
||||
env->GetByteArrayRegion(pixels, 0, size, (jbyte*)cocos2d::sharedBitmapDC().m_pData);
|
||||
|
||||
// swap data
|
||||
unsigned int *tempPtr = (unsigned int*)cocos2d::sharedBitmapDC().m_pData;
|
||||
|
|
|
@ -1,475 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 "Cocos2dJni.h"
|
||||
#include "CCSet.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCKeypadDispatcher.h"
|
||||
#include "CCTouch.h"
|
||||
#include "CCTouchDispatcher.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "CCAccelerometer.h"
|
||||
#include "CCApplication.h"
|
||||
#include "CCIMEDispatcher.h"
|
||||
#include "CCAccelerometer_android.h"
|
||||
#include <android/log.h>
|
||||
|
||||
#if 0
|
||||
#define LOG_TAG "Cocos2dJni"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// java vm helper function
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
JavaVM *gJavaVM = NULL;
|
||||
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
gJavaVM = vm;
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
struct TMethodJNI
|
||||
{
|
||||
JNIEnv * env;
|
||||
jclass classID;
|
||||
jmethodID methodID;
|
||||
};
|
||||
static bool getMethodID(struct TMethodJNI& t, const char *className, const char *methodName, const char *paramCode)
|
||||
{
|
||||
bool ret = 0;
|
||||
do
|
||||
{
|
||||
if (gJavaVM->GetEnv((void**)&t.env, JNI_VERSION_1_4) != JNI_OK)
|
||||
{
|
||||
LOGD("Failed to get the environment using GetEnv()");
|
||||
break;
|
||||
}
|
||||
|
||||
if (gJavaVM->AttachCurrentThread(&t.env, 0) < 0)
|
||||
{
|
||||
LOGD("Failed to get the environment using AttachCurrentThread()");
|
||||
break;
|
||||
}
|
||||
|
||||
t.classID = t.env->FindClass(className);
|
||||
if (! t.classID)
|
||||
{
|
||||
LOGD("Failed to find class of %s", className);
|
||||
break;
|
||||
}
|
||||
|
||||
t.methodID = t.env->GetStaticMethodID(t.classID, methodName, paramCode);
|
||||
if (! t.methodID)
|
||||
{
|
||||
LOGD("Failed to find method id of %s", methodName);
|
||||
break;
|
||||
}
|
||||
ret = true;
|
||||
} while (0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// native renderer
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MAX_TOUCHES 5
|
||||
static CCTouch *s_pTouches[MAX_TOUCHES] = { NULL };
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env)
|
||||
{
|
||||
cocos2d::CCDirector::sharedDirector()->mainLoop();
|
||||
}
|
||||
|
||||
// handle touch event
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesBegin(JNIEnv* env, jobject thiz, jint id, jfloat x, jfloat y)
|
||||
{
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
CCTouch *pTouch = s_pTouches[id];
|
||||
if (! pTouch)
|
||||
{
|
||||
LOGD("Beginning touches with id: %d, x=%f, y=%f", id, x, y);
|
||||
|
||||
pTouch = new CCTouch();
|
||||
pTouch->SetTouchInfo(0, (x - rcRect.origin.x) / fScreenScaleFactor, (y - rcRect.origin.y) / fScreenScaleFactor);
|
||||
s_pTouches[id] = pTouch;
|
||||
set.addObject(pTouch);
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesBegan(&set, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("Beginnig touches with id: %d error", id);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd(JNIEnv* env, jobject thiz, jint id, jfloat x, jfloat y)
|
||||
{
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
/* Add to the set to send to the director */
|
||||
CCTouch* pTouch = s_pTouches[id];
|
||||
if (pTouch)
|
||||
{
|
||||
LOGD("Ending touches with id: %d, x=%f, y=%f", id, x, y);
|
||||
|
||||
pTouch->SetTouchInfo(0, (x - rcRect.origin.x) / fScreenScaleFactor , (y - rcRect.origin.y) / fScreenScaleFactor);
|
||||
set.addObject(pTouch);
|
||||
|
||||
// release the object
|
||||
pTouch->release();
|
||||
s_pTouches[id] = NULL;
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesEnded(&set, NULL);
|
||||
} else {
|
||||
LOGD("Ending touches with id: %d error", id);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesMove(JNIEnv* env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
{
|
||||
int size = env->GetArrayLength(ids);
|
||||
jint id[size];
|
||||
jfloat x[size];
|
||||
jfloat y[size];
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
env->GetIntArrayRegion(ids, 0, size, id);
|
||||
env->GetFloatArrayRegion(xs, 0, size, x);
|
||||
env->GetFloatArrayRegion(ys, 0, size, y);
|
||||
|
||||
for( int i = 0 ; i < size ; i++ ) {
|
||||
LOGD("Moving touches with id: %d, x=%f, y=%f", id[i], x[i], y[i]);
|
||||
cocos2d::CCTouch* pTouch = s_pTouches[id[i]];
|
||||
if (pTouch)
|
||||
{
|
||||
pTouch->SetTouchInfo(0, (x[i] - rcRect.origin.x) / fScreenScaleFactor ,
|
||||
(y[i] - rcRect.origin.y) / fScreenScaleFactor);
|
||||
set.addObject(pTouch);
|
||||
}
|
||||
else
|
||||
{
|
||||
// It is error, should return.
|
||||
LOGD("Moving touches with id: %d error", id[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesMoved(&set, NULL);
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesCancel(JNIEnv* env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
{
|
||||
int size = env->GetArrayLength(ids);
|
||||
jint id[size];
|
||||
jfloat x[size];
|
||||
jfloat y[size];
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
env->GetIntArrayRegion(ids, 0, size, id);
|
||||
env->GetFloatArrayRegion(xs, 0, size, x);
|
||||
env->GetFloatArrayRegion(ys, 0, size, y);
|
||||
|
||||
for( int i = 0 ; i < size ; i++ ) {
|
||||
cocos2d::CCTouch* pTouch = s_pTouches[id[i]];
|
||||
if (pTouch)
|
||||
{
|
||||
pTouch->SetTouchInfo(0, (x[i] - rcRect.origin.x) / fScreenScaleFactor ,
|
||||
(y[i] - rcRect.origin.y) / fScreenScaleFactor);
|
||||
set.addObject(pTouch);
|
||||
s_pTouches[id[i]] = NULL;
|
||||
pTouch->release();
|
||||
}
|
||||
}
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesCancelled(&set, NULL);
|
||||
}
|
||||
|
||||
// handle onPause and onResume
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause()
|
||||
{
|
||||
CCApplication::sharedApplication().applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume()
|
||||
{
|
||||
// Shared OpenGL View instance doesn't exist yet when Activity.onResume is first called
|
||||
if (CCDirector::sharedDirector()->getOpenGLView())
|
||||
CCApplication::sharedApplication().applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
#define KEYCODE_BACK 0x04
|
||||
#define KEYCODE_MENU 0x52
|
||||
|
||||
// handle keydown event
|
||||
|
||||
jboolean Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyDown(JNIEnv* env, jobject thiz, jint keyCode)
|
||||
{
|
||||
switch (keyCode)
|
||||
{
|
||||
case KEYCODE_BACK:
|
||||
if (CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked))
|
||||
return JNI_TRUE;
|
||||
break;
|
||||
case KEYCODE_MENU:
|
||||
if (CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked))
|
||||
return JNI_TRUE;
|
||||
break;
|
||||
default:
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// handle accelerometer changes
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxAccelerometer_onSensorChanged(JNIEnv* env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp)
|
||||
{
|
||||
// We need to invert to make it compatible with iOS.
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
cocos2d::CCAccelerometer::sharedAccelerometer()->update((x - rcRect.origin.x) / fScreenScaleFactor,
|
||||
(y - rcRect.origin.y) / fScreenScaleFactor,
|
||||
z,
|
||||
timeStamp);
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxActivity_nativeSetPaths(JNIEnv* env, jobject thiz, jstring apkPath)
|
||||
{
|
||||
const char* str;
|
||||
jboolean isCopy;
|
||||
str = env->GetStringUTFChars(apkPath, &isCopy);
|
||||
if (isCopy) {
|
||||
cocos2d::CCFileUtils::setResourcePath(str);
|
||||
env->ReleaseStringUTFChars(apkPath, str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void enableAccelerometerJNI()
|
||||
{
|
||||
TMethodJNI t;
|
||||
if (getMethodID(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "enableAccelerometer"
|
||||
, "()V"))
|
||||
{
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
|
||||
void disableAccelerometerJNI()
|
||||
{
|
||||
TMethodJNI t;
|
||||
|
||||
if (getMethodID(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "disableAccelerometer"
|
||||
, "()V"))
|
||||
{
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
|
||||
void showMessageBoxJNI(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
if (! pszMsg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TMethodJNI t;
|
||||
if (getMethodID(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "showMessageBox"
|
||||
, "(Ljava/lang/String;Ljava/lang/String;)V"))
|
||||
{
|
||||
jstring StringArg1;
|
||||
|
||||
if (! pszTitle)
|
||||
{
|
||||
StringArg1 = t.env->NewStringUTF("");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringArg1 = t.env->NewStringUTF(pszTitle);
|
||||
}
|
||||
|
||||
jstring StringArg2 = t.env->NewStringUTF(pszMsg);
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, StringArg1, StringArg2);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// handle IME message
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setKeyboardStateJNI(int bOpen)
|
||||
{
|
||||
TMethodJNI t;
|
||||
//jint open = bOpen;
|
||||
if (getMethodID(t
|
||||
, "org/cocos2dx/lib/Cocos2dxGLSurfaceView"
|
||||
, (bOpen) ? "openIMEKeyboard" : "closeIMEKeyboard"
|
||||
, "()V"))
|
||||
{
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInsertText(JNIEnv* env, jobject thiz, jstring text)
|
||||
{
|
||||
jboolean isCopy = 0;
|
||||
const char* pszText = env->GetStringUTFChars(text, &isCopy);
|
||||
if (isCopy)
|
||||
{
|
||||
cocos2d::CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText));
|
||||
env->ReleaseStringUTFChars(text, pszText);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeDeleteBackward(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
cocos2d::CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
||||
}
|
||||
|
||||
jstring Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeGetContentText()
|
||||
{
|
||||
JNIEnv * env = 0;
|
||||
|
||||
if (gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK || ! env)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const char * pszText = cocos2d::CCIMEDispatcher::sharedDispatcher()->getContentText();
|
||||
return env->NewStringUTF(pszText);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// get package name
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static char* jstringTostring(JNIEnv* env, jstring jstr)
|
||||
{
|
||||
char* rtn = NULL;
|
||||
|
||||
// convert jstring to byte array
|
||||
jclass clsstring = env->FindClass("java/lang/String");
|
||||
jstring strencode = env->NewStringUTF("utf-8");
|
||||
jmethodID mid = env->GetMethodID(clsstring, "getBytes", "(Ljava/lang/String;)[B");
|
||||
jbyteArray barr= (jbyteArray)env->CallObjectMethod(jstr, mid, strencode);
|
||||
jsize alen = env->GetArrayLength(barr);
|
||||
jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE);
|
||||
|
||||
// copy byte array into char[]
|
||||
if (alen > 0)
|
||||
{
|
||||
rtn = new char[alen + 1];
|
||||
memcpy(rtn, ba, alen);
|
||||
rtn[alen] = 0;
|
||||
}
|
||||
env->ReleaseByteArrayElements(barr, ba, 0);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
char* getPackageNameJNI()
|
||||
{
|
||||
TMethodJNI t;
|
||||
char* ret = NULL;
|
||||
|
||||
if (getMethodID(t,
|
||||
"org/cocos2dx/lib/Cocos2dxActivity",
|
||||
"getCocos2dxPackageName",
|
||||
"()Ljava/lang/String;"))
|
||||
{
|
||||
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
ret = jstringTostring(t.env, str);
|
||||
|
||||
LOGD("package name %s", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// handle get current language
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
char* getCurrentLanguageJNI()
|
||||
{
|
||||
TMethodJNI t;
|
||||
char* ret = NULL;
|
||||
|
||||
if (getMethodID(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "getCurrentLanguage"
|
||||
, "()Ljava/lang/String;"))
|
||||
{
|
||||
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
ret = jstringTostring(t.env, str);
|
||||
|
||||
LOGD("language name %s", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// terminate the process
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void terminateProcessJNI()
|
||||
{
|
||||
TMethodJNI t;
|
||||
|
||||
if (getMethodID(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "terminateProcess"
|
||||
, "()V"))
|
||||
{
|
||||
t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 "IMEJni.h"
|
||||
#include "CCIMEDispatcher.h"
|
||||
#include "JniHelper.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
#if 0
|
||||
#define LOG_TAG "IMEJni"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// handle IME message
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setKeyboardStateJNI(int bOpen)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t,
|
||||
"org/cocos2dx/lib/Cocos2dxGLSurfaceView",
|
||||
(bOpen) ? "openIMEKeyboard" : "closeIMEKeyboard",
|
||||
"()V"))
|
||||
{
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInsertText(JNIEnv* env, jobject thiz, jstring text)
|
||||
{
|
||||
jboolean isCopy = 0;
|
||||
const char* pszText = env->GetStringUTFChars(text, &isCopy);
|
||||
if (isCopy)
|
||||
{
|
||||
cocos2d::CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText));
|
||||
env->ReleaseStringUTFChars(text, pszText);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeDeleteBackward(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
cocos2d::CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
||||
}
|
||||
|
||||
jstring Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeGetContentText()
|
||||
{
|
||||
JNIEnv * env = 0;
|
||||
|
||||
if (JniHelper::getJavaVM()->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK || ! env)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const char * pszText = cocos2d::CCIMEDispatcher::sharedDispatcher()->getContentText();
|
||||
return env->NewStringUTF(pszText);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 __ANDROID_IME_JNI_H__
|
||||
#define __ANDROID_IME_JNI_H__
|
||||
|
||||
extern "C"
|
||||
|
||||
{
|
||||
extern void setKeyboardStateJNI(int bOpen);
|
||||
}
|
||||
|
||||
#endif // __ANDROID_IME_JNI_H__
|
|
@ -0,0 +1,228 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 "JniHelper.h"
|
||||
#include <android/log.h>
|
||||
#include <string.h>
|
||||
|
||||
#if 1
|
||||
#define LOG_TAG "JniHelper"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
#define JAVAVM cocos2d::JniHelper::getJavaVM()
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// java vm helper function
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
cocos2d::JniHelper::setJavaVM(vm);
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
static bool getEnv(JNIEnv **env)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
do
|
||||
{
|
||||
if (JAVAVM->GetEnv((void**)env, JNI_VERSION_1_4) != JNI_OK)
|
||||
{
|
||||
LOGD("Failed to get the environment using GetEnv()");
|
||||
break;
|
||||
}
|
||||
|
||||
if (JAVAVM->AttachCurrentThread(env, 0) < 0)
|
||||
{
|
||||
LOGD("Failed to get the environment using AttachCurrentThread()");
|
||||
break;
|
||||
}
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
static jclass getClassID_(const char *className, JNIEnv *env)
|
||||
{
|
||||
JNIEnv *pEnv = env;
|
||||
jclass ret = 0;
|
||||
|
||||
do
|
||||
{
|
||||
if (! pEnv)
|
||||
{
|
||||
if (! getEnv(&pEnv))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pEnv->FindClass(className);
|
||||
if (! ret)
|
||||
{
|
||||
LOGD("Failed to find class of %s", className);
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool getStaticMethodInfo_(cocos2d::JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode)
|
||||
{
|
||||
jmethodID methodID = 0;
|
||||
JNIEnv *pEnv = 0;
|
||||
bool bRet = false;
|
||||
|
||||
do
|
||||
{
|
||||
if (! getEnv(&pEnv))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
jclass classID = getClassID_(className, pEnv);
|
||||
|
||||
methodID = pEnv->GetStaticMethodID(classID, methodName, paramCode);
|
||||
if (! methodID)
|
||||
{
|
||||
LOGD("Failed to find static method id of %s", methodName);
|
||||
break;
|
||||
}
|
||||
|
||||
methodinfo.classID = classID;
|
||||
methodinfo.env = pEnv;
|
||||
methodinfo.methodID = methodID;
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
static bool getMethodInfo_(cocos2d::JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode)
|
||||
{
|
||||
jmethodID methodID = 0;
|
||||
JNIEnv *pEnv = 0;
|
||||
bool bRet = false;
|
||||
|
||||
do
|
||||
{
|
||||
if (! getEnv(&pEnv))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
jclass classID = getClassID_(className, pEnv);
|
||||
|
||||
methodID = pEnv->GetMethodID(classID, methodName, paramCode);
|
||||
if (! methodID)
|
||||
{
|
||||
LOGD("Failed to find method id of %s", methodName);
|
||||
break;
|
||||
}
|
||||
|
||||
methodinfo.classID = classID;
|
||||
methodinfo.env = pEnv;
|
||||
methodinfo.methodID = methodID;
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
static char* jstringToChar_(jstring jstr)
|
||||
{
|
||||
char* rtn = 0;
|
||||
JNIEnv *env = 0;
|
||||
|
||||
if (! getEnv(&env))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// convert jstring to byte array
|
||||
jclass clsstring = env->FindClass("java/lang/String");
|
||||
jstring strencode = env->NewStringUTF("utf-8");
|
||||
jmethodID mid = env->GetMethodID(clsstring, "getBytes", "(Ljava/lang/String;)[B");
|
||||
jbyteArray barr= (jbyteArray)env->CallObjectMethod(jstr, mid, strencode);
|
||||
jsize alen = env->GetArrayLength(barr);
|
||||
jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE);
|
||||
|
||||
// copy byte array into char[]
|
||||
if (alen > 0)
|
||||
{
|
||||
rtn = new char[alen + 1];
|
||||
memcpy(rtn, ba, alen);
|
||||
rtn[alen] = 0;
|
||||
}
|
||||
env->ReleaseByteArrayElements(barr, ba, 0);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
}
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
JavaVM* JniHelper::m_psJavaVM = NULL;
|
||||
|
||||
JavaVM* JniHelper::getJavaVM()
|
||||
{
|
||||
return m_psJavaVM;
|
||||
}
|
||||
|
||||
void JniHelper::setJavaVM(JavaVM *javaVM)
|
||||
{
|
||||
m_psJavaVM = javaVM;
|
||||
}
|
||||
|
||||
jclass JniHelper::getClassID(const char *className, JNIEnv *env)
|
||||
{
|
||||
return getClassID_(className, env);
|
||||
}
|
||||
|
||||
bool JniHelper::getStaticMethodInfo(JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode)
|
||||
{
|
||||
return getStaticMethodInfo_(methodinfo, className, methodName, paramCode);
|
||||
}
|
||||
|
||||
bool JniHelper::getMethodInfo(JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode)
|
||||
{
|
||||
return getMethodInfo_(methodinfo, className, methodName, paramCode);
|
||||
}
|
||||
|
||||
char* JniHelper::jstringToChar(jstring str)
|
||||
{
|
||||
return jstringToChar_(str);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 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 __ANDROID_JNI_HELPER_H__
|
||||
#define __ANDROID_JNI_HELPER_H__
|
||||
|
||||
#include <jni.h>
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
typedef struct JniMethodInfo_
|
||||
{
|
||||
JNIEnv * env;
|
||||
jclass classID;
|
||||
jmethodID methodID;
|
||||
} JniMethodInfo;
|
||||
|
||||
class CC_DLL JniHelper
|
||||
{
|
||||
public:
|
||||
static JavaVM* getJavaVM();
|
||||
static void setJavaVM(JavaVM *javaVM);
|
||||
static jclass getClassID(const char *className, JNIEnv *env=0);
|
||||
static bool getStaticMethodInfo(JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode);
|
||||
static bool getMethodInfo(JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode);
|
||||
static char* jstringToChar(jstring str);
|
||||
|
||||
private:
|
||||
static JavaVM *m_psJavaVM;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __ANDROID_JNI_HELPER_H__
|
|
@ -0,0 +1,114 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 "MessageJni.h"
|
||||
#include "CCDirector.h"
|
||||
#include "JniHelper.h"
|
||||
#include "CCApplication.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
||||
#if 0
|
||||
#define LOG_TAG "MessageJni"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// native renderer
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env)
|
||||
{
|
||||
cocos2d::CCDirector::sharedDirector()->mainLoop();
|
||||
}
|
||||
|
||||
// handle onPause and onResume
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause()
|
||||
{
|
||||
CCApplication::sharedApplication().applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume()
|
||||
{
|
||||
// Shared OpenGL View instance doesn't exist yet when Activity.onResume is first called
|
||||
if (CCDirector::sharedDirector()->getOpenGLView())
|
||||
{
|
||||
CCApplication::sharedApplication().applicationWillEnterForeground();
|
||||
}
|
||||
}
|
||||
|
||||
void showMessageBoxJNI(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
if (! pszMsg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JniMethodInfo t;
|
||||
if (JniHelper::getStaticMethodInfo(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "showMessageBox"
|
||||
, "(Ljava/lang/String;Ljava/lang/String;)V"))
|
||||
{
|
||||
jstring StringArg1;
|
||||
|
||||
if (! pszTitle)
|
||||
{
|
||||
StringArg1 = t.env->NewStringUTF("");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringArg1 = t.env->NewStringUTF(pszTitle);
|
||||
}
|
||||
|
||||
jstring StringArg2 = t.env->NewStringUTF(pszMsg);
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, StringArg1, StringArg2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// terminate the process
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void terminateProcessJNI()
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "terminateProcess"
|
||||
, "()V"))
|
||||
{
|
||||
t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,22 +21,14 @@ 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 __ANDROID_COCOS2D_JNI_H__
|
||||
#define __ANDROID_COCOS2D_JNI_H__
|
||||
|
||||
#include <jni.h>
|
||||
#ifndef __ANDROID_MESSAGE_JNI_H__
|
||||
#define __ANDROID_MESSAGE_JNI_H__
|
||||
|
||||
extern "C"
|
||||
|
||||
{
|
||||
extern JavaVM *gJavaVM;
|
||||
extern void enableAccelerometerJNI();
|
||||
extern void disableAccelerometerJNI();
|
||||
extern void showMessageBoxJNI(const char * pszMsg, const char * pszTitle);
|
||||
extern void setKeyboardStateJNI(int bOpen);
|
||||
extern char* getCurrentLanguageJNI();
|
||||
extern char* getPackageNameJNI();
|
||||
extern void terminateProcessJNI();
|
||||
}
|
||||
|
||||
#endif // __ANDROID_COCOS2D_JNI_H__
|
||||
#endif // __ANDROID_MESSAGE_JNI_H__
|
|
@ -0,0 +1,99 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 "SensorJni.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "CCAccelerometer.h"
|
||||
#include "platform/android/CCAccelerometer_android.h"
|
||||
#include "CCEGLView.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include "JniHelper.h"
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
||||
#if 0
|
||||
#define LOG_TAG "SensorJni"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// handle accelerometer changes
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxAccelerometer_onSensorChanged(JNIEnv* env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp)
|
||||
{
|
||||
// We need to invert to make it compatible with iOS.
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
cocos2d::CCAccelerometer::sharedAccelerometer()->update((x - rcRect.origin.x) / fScreenScaleFactor,
|
||||
(y - rcRect.origin.y) / fScreenScaleFactor,
|
||||
z,
|
||||
timeStamp);
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxActivity_nativeSetPaths(JNIEnv* env, jobject thiz, jstring apkPath)
|
||||
{
|
||||
const char* str;
|
||||
jboolean isCopy;
|
||||
str = env->GetStringUTFChars(apkPath, &isCopy);
|
||||
if (isCopy) {
|
||||
cocos2d::CCFileUtils::setResourcePath(str);
|
||||
env->ReleaseStringUTFChars(apkPath, str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void enableAccelerometerJNI()
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t,
|
||||
"org/cocos2dx/lib/Cocos2dxActivity",
|
||||
"enableAccelerometer",
|
||||
"()V"))
|
||||
{
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
|
||||
void disableAccelerometerJNI()
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t,
|
||||
"org/cocos2dx/lib/Cocos2dxActivity",
|
||||
"disableAccelerometer",
|
||||
"()V"))
|
||||
{
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 __ANDROID_SENSOR_JNI_H__
|
||||
#define __ANDROID_SENSOR_JNI_H__
|
||||
|
||||
extern "C"
|
||||
|
||||
{
|
||||
extern void enableAccelerometerJNI();
|
||||
extern void disableAccelerometerJNI();
|
||||
}
|
||||
|
||||
#endif // __ANDROID_SENSOR_JNI_H__
|
|
@ -0,0 +1,82 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 "SystemInfoJni.h"
|
||||
#include "JniHelper.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
||||
#if 0
|
||||
#define LOG_TAG "SystemInfoJni"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
char* getPackageNameJNI()
|
||||
{
|
||||
JniMethodInfo t;
|
||||
char* ret = 0;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t,
|
||||
"org/cocos2dx/lib/Cocos2dxActivity",
|
||||
"getCocos2dxPackageName",
|
||||
"()Ljava/lang/String;"))
|
||||
{
|
||||
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
ret = JniHelper::jstringToChar(str);
|
||||
|
||||
LOGD("package name %s", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// handle get current language
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
char* getCurrentLanguageJNI()
|
||||
{
|
||||
JniMethodInfo t;
|
||||
char* ret = 0;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
, "getCurrentLanguage"
|
||||
, "()Ljava/lang/String;"))
|
||||
{
|
||||
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
ret = JniHelper::jstringToChar(str);
|
||||
|
||||
LOGD("language name %s", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 __ANDROID_SYSTEM_INFO_JNI_H__
|
||||
#define __ANDROID_SYSTEM_INFO_JNI_H__
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
extern "C"
|
||||
|
||||
{
|
||||
extern char* getCurrentLanguageJNI();
|
||||
extern char* getPackageNameJNI();
|
||||
}
|
||||
|
||||
#endif // __ANDROID_SYSTEM_INFO_JNI_H__
|
|
@ -0,0 +1,184 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 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 "CCSet.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCKeypadDispatcher.h"
|
||||
#include "CCTouch.h"
|
||||
#include "CCEGLView.h"
|
||||
#include "CCTouchDispatcher.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
#if 0
|
||||
#define LOG_TAG "NativeTouchesJni"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#define MAX_TOUCHES 5
|
||||
static CCTouch *s_pTouches[MAX_TOUCHES] = { NULL };
|
||||
|
||||
// handle touch event
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesBegin(JNIEnv* env, jobject thiz, jint id, jfloat x, jfloat y)
|
||||
{
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
CCTouch *pTouch = s_pTouches[id];
|
||||
if (! pTouch)
|
||||
{
|
||||
LOGD("Beginning touches with id: %d, x=%f, y=%f", id, x, y);
|
||||
|
||||
pTouch = new CCTouch();
|
||||
pTouch->SetTouchInfo(0, (x - rcRect.origin.x) / fScreenScaleFactor, (y - rcRect.origin.y) / fScreenScaleFactor);
|
||||
s_pTouches[id] = pTouch;
|
||||
set.addObject(pTouch);
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesBegan(&set, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("Beginnig touches with id: %d error", id);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd(JNIEnv* env, jobject thiz, jint id, jfloat x, jfloat y)
|
||||
{
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
/* Add to the set to send to the director */
|
||||
CCTouch* pTouch = s_pTouches[id];
|
||||
if (pTouch)
|
||||
{
|
||||
LOGD("Ending touches with id: %d, x=%f, y=%f", id, x, y);
|
||||
|
||||
pTouch->SetTouchInfo(0, (x - rcRect.origin.x) / fScreenScaleFactor , (y - rcRect.origin.y) / fScreenScaleFactor);
|
||||
set.addObject(pTouch);
|
||||
|
||||
// release the object
|
||||
pTouch->release();
|
||||
s_pTouches[id] = NULL;
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesEnded(&set, NULL);
|
||||
} else {
|
||||
LOGD("Ending touches with id: %d error", id);
|
||||
}
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesMove(JNIEnv* env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
{
|
||||
int size = env->GetArrayLength(ids);
|
||||
jint id[size];
|
||||
jfloat x[size];
|
||||
jfloat y[size];
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
env->GetIntArrayRegion(ids, 0, size, id);
|
||||
env->GetFloatArrayRegion(xs, 0, size, x);
|
||||
env->GetFloatArrayRegion(ys, 0, size, y);
|
||||
|
||||
for( int i = 0 ; i < size ; i++ ) {
|
||||
LOGD("Moving touches with id: %d, x=%f, y=%f", id[i], x[i], y[i]);
|
||||
cocos2d::CCTouch* pTouch = s_pTouches[id[i]];
|
||||
if (pTouch)
|
||||
{
|
||||
pTouch->SetTouchInfo(0, (x[i] - rcRect.origin.x) / fScreenScaleFactor ,
|
||||
(y[i] - rcRect.origin.y) / fScreenScaleFactor);
|
||||
set.addObject(pTouch);
|
||||
}
|
||||
else
|
||||
{
|
||||
// It is error, should return.
|
||||
LOGD("Moving touches with id: %d error", id[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesMoved(&set, NULL);
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesCancel(JNIEnv* env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
{
|
||||
int size = env->GetArrayLength(ids);
|
||||
jint id[size];
|
||||
jfloat x[size];
|
||||
jfloat y[size];
|
||||
CCRect rcRect = CCEGLView::sharedOpenGLView().getViewPort();
|
||||
float fScreenScaleFactor = CCEGLView::sharedOpenGLView().getScreenScaleFactor();
|
||||
CCSet set;
|
||||
|
||||
env->GetIntArrayRegion(ids, 0, size, id);
|
||||
env->GetFloatArrayRegion(xs, 0, size, x);
|
||||
env->GetFloatArrayRegion(ys, 0, size, y);
|
||||
|
||||
for( int i = 0 ; i < size ; i++ ) {
|
||||
cocos2d::CCTouch* pTouch = s_pTouches[id[i]];
|
||||
if (pTouch)
|
||||
{
|
||||
pTouch->SetTouchInfo(0, (x[i] - rcRect.origin.x) / fScreenScaleFactor ,
|
||||
(y[i] - rcRect.origin.y) / fScreenScaleFactor);
|
||||
set.addObject(pTouch);
|
||||
s_pTouches[id[i]] = NULL;
|
||||
pTouch->release();
|
||||
}
|
||||
}
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesCancelled(&set, NULL);
|
||||
}
|
||||
|
||||
#define KEYCODE_BACK 0x04
|
||||
#define KEYCODE_MENU 0x52
|
||||
|
||||
// handle keydown event
|
||||
|
||||
jboolean Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyDown(JNIEnv* env, jobject thiz, jint keyCode)
|
||||
{
|
||||
switch (keyCode)
|
||||
{
|
||||
case KEYCODE_BACK:
|
||||
if (CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked))
|
||||
return JNI_TRUE;
|
||||
break;
|
||||
case KEYCODE_MENU:
|
||||
if (CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked))
|
||||
return JNI_TRUE;
|
||||
break;
|
||||
default:
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
|
@ -844,6 +844,10 @@
|
|||
RelativePath="..\textures\CCTextureCache.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\textures\CCTexturePVR.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="tileMap_parallax_nodes"
|
||||
|
|
|
@ -101,7 +101,7 @@ int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out)
|
|||
|
||||
if (ret > 0 )
|
||||
{
|
||||
std::printf("Base64Utils: error decoding");
|
||||
printf("Base64Utils: error decoding");
|
||||
delete [] *out;
|
||||
*out = NULL;
|
||||
outLength = 0;
|
||||
|
|
|
@ -43,11 +43,11 @@ copy_cpp_h_from_helloworld(){
|
|||
|
||||
# copy resources
|
||||
copy_resouces(){
|
||||
mkdir $APP_DIR/Resource
|
||||
mkdir $APP_DIR/Resources
|
||||
|
||||
for file in $HELLOWORLD_ROOT/Resource/*
|
||||
do
|
||||
cp $file $APP_DIR/Resource
|
||||
cp $file $APP_DIR/Resources
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,34 @@
|
|||
RelativePath=".\Templates\1033\Classes\HelloWorldScene.h"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="cocos2dx_support"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\..\lua\cocos2dx_support\LuaCocos2d.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\lua\cocos2dx_support\LuaCocos2d.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\lua\cocos2dx_support\LuaEngine.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\lua\cocos2dx_support\LuaEngine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\lua\cocos2dx_support\LuaEngineImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\lua\cocos2dx_support\LuaEngineImpl.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
|
|
|
@ -234,7 +234,7 @@ function AddConfigurations(proj, strProjectName) {
|
|||
if (wizard.FindSymbol('CC_USE_LUA')) {
|
||||
strAddIncludeDir += ';..\\lua\\cocos2dx_support';
|
||||
strAddIncludeDir += ';..\\lua\\tolua';
|
||||
strAddIncludeDir += ';..\\lua\\src';
|
||||
strAddIncludeDir += ';..\\lua\\lua';
|
||||
}
|
||||
CLTool.AdditionalIncludeDirectories = strAddIncludeDir;
|
||||
|
||||
|
@ -391,6 +391,12 @@ function GetTargetName(strName, strProjectName) {
|
|||
strTarget = strName.substring(0, nIndex) + strProjectName + strName.substring(nIndex + 4, strName.length);
|
||||
}
|
||||
|
||||
var strTemp = "../../../../../lua";
|
||||
nIndex = strTarget.indexOf(strTemp);
|
||||
if (nIndex >= 0) {
|
||||
strTarget = "Classes" + strTarget.substring(nIndex + strTemp.length, strTarget.length);
|
||||
}
|
||||
|
||||
return strTarget;
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
@ -8,7 +8,14 @@ win32/main.cpp
|
|||
Classes/AppDelegate.h
|
||||
Classes/AppDelegate.cpp
|
||||
|
||||
[! if ! CC_USE_LUA]
|
||||
[! if CC_USE_LUA]
|
||||
../../../../../lua/cocos2dx_support/LuaCocos2d.cpp
|
||||
../../../../../lua/cocos2dx_support/LuaEngine.cpp
|
||||
../../../../../lua/cocos2dx_support/LuaEngineImpl.cpp
|
||||
../../../../../lua/cocos2dx_support/LuaCocos2d.h
|
||||
../../../../../lua/cocos2dx_support/LuaEngine.h
|
||||
../../../../../lua/cocos2dx_support/LuaEngineImpl.h
|
||||
[! else]
|
||||
Classes/HelloWorldScene.h
|
||||
Classes/HelloWorldScene.cpp
|
||||
[! endif]
|
||||
|
|
|
@ -1 +1 @@
|
|||
ef940d5753a60f54cba21c8c503248f75bd3ab98
|
||||
6616770f7d0487bf12f076293d27d5ef5f11af1e
|
|
@ -1 +1 @@
|
|||
dec21d9705b1a93bf01aac9fb46e3e65996adfba
|
||||
99f6132989ba063c7d343a1b0b27799df3d2f280
|
|
@ -22,6 +22,8 @@ do
|
|||
fi
|
||||
done
|
||||
|
||||
# remove test_image_rgba4444.pvr.gz
|
||||
rm -f $TESTS_ROOT/assets/Images/test_image_rgba4444.pvr.gz
|
||||
|
||||
# build
|
||||
pushd $ANDROID_NDK_ROOT
|
||||
|
|
|
@ -149,8 +149,8 @@ public class Cocos2dxActivity extends Activity{
|
|||
backgroundMusicPlayer.setBackgroundVolume(volume);
|
||||
}
|
||||
|
||||
public static int playEffect(String path){
|
||||
return soundPlayer.playEffect(path);
|
||||
public static int playEffect(String path, boolean isLoop){
|
||||
return soundPlayer.playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
public static void stopEffect(int soundId){
|
||||
|
|
|
@ -28,11 +28,7 @@ public class Cocos2dxBitmap{
|
|||
public static void createTextBitmap(String content, String fontName,
|
||||
int fontSize, int alignment, int width, int height){
|
||||
|
||||
// Avoid error when content is ""
|
||||
if (content.compareTo("") == 0){
|
||||
content = " ";
|
||||
}
|
||||
|
||||
content = refactorString(content);
|
||||
Paint paint = newPaint(fontName, fontSize, alignment);
|
||||
|
||||
TextProperty textProperty = getTextWidthAndHeight(content, paint, width, height);
|
||||
|
@ -272,6 +268,40 @@ public class Cocos2dxBitmap{
|
|||
return paint;
|
||||
}
|
||||
|
||||
private static String refactorString(String str){
|
||||
// Avoid error when content is ""
|
||||
if (str.compareTo("") == 0){
|
||||
return " ";
|
||||
}
|
||||
|
||||
/*
|
||||
* If the font of "\n" is "" or "\n", insert " " in front of it.
|
||||
*
|
||||
* For example:
|
||||
* "\nabc" -> " \nabc"
|
||||
* "\nabc\n\n" -> " \nabc\n \n"
|
||||
*/
|
||||
StringBuilder strBuilder = new StringBuilder(str);
|
||||
int start = 0;
|
||||
int index = strBuilder.indexOf("\n");
|
||||
while (index != -1){
|
||||
if (index == 0 || strBuilder.charAt(index -1) == '\n'){
|
||||
strBuilder.insert(start, " ");
|
||||
start = index + 2;
|
||||
} else {
|
||||
start = index + 1;
|
||||
}
|
||||
|
||||
if (start > strBuilder.length() || index == strBuilder.length()){
|
||||
break;
|
||||
}
|
||||
|
||||
index = strBuilder.indexOf("\n", start);
|
||||
}
|
||||
|
||||
return strBuilder.toString();
|
||||
}
|
||||
|
||||
private static void initNativeObject(Bitmap bitmap){
|
||||
byte[] pixels = getPixels(bitmap);
|
||||
if (pixels == null){
|
||||
|
|
|
@ -81,9 +81,18 @@ class TextInputWraper implements TextWatcher, OnEditorActionListener {
|
|||
LogD("deleteBackward");
|
||||
}
|
||||
String text = v.getText().toString();
|
||||
|
||||
/*
|
||||
* If user input nothing, translate "\n" to engine.
|
||||
*/
|
||||
if (text.compareTo("") == 0){
|
||||
text = "\n";
|
||||
}
|
||||
|
||||
if ('\n' != text.charAt(text.length() - 1)) {
|
||||
text += '\n';
|
||||
}
|
||||
|
||||
final String insertText = text;
|
||||
mMainView.insertText(insertText);
|
||||
LogD("insertText(" + insertText + ")");
|
||||
|
|
|
@ -28,7 +28,6 @@ public class Cocos2dxSound {
|
|||
private static final int MAX_SIMULTANEOUS_STREAMS_DEFAULT = 5;
|
||||
private static final float SOUND_RATE = 1.0f;
|
||||
private static final int SOUND_PRIORITY = 1;
|
||||
private static final int SOUND_LOOP_TIME = 0;
|
||||
private static final int SOUND_QUALITY = 5;
|
||||
|
||||
private final int INVALID_SOUND_ID = -1;
|
||||
|
@ -75,15 +74,17 @@ public class Cocos2dxSound {
|
|||
}
|
||||
}
|
||||
|
||||
public int playEffect(String path){
|
||||
public int playEffect(String path, boolean isLoop){
|
||||
Integer soundId = this.mPathSoundIDMap.get(path);
|
||||
|
||||
if (soundId != null){
|
||||
// the sound is preloaded
|
||||
// the sound is preloaded, stop it first
|
||||
|
||||
this.mSoundPool.stop(soundId);
|
||||
|
||||
// play sound
|
||||
int streamId = this.mSoundPool.play(soundId.intValue(), this.mLeftVolume,
|
||||
this.mRightVolume, SOUND_PRIORITY, SOUND_LOOP_TIME, SOUND_RATE);
|
||||
this.mRightVolume, SOUND_PRIORITY, isLoop ? -1 : 0, SOUND_RATE);
|
||||
|
||||
// record sound id and stream id map
|
||||
this.mSoundIdStreamIdMap.put(soundId, streamId);
|
||||
|
@ -106,7 +107,7 @@ public class Cocos2dxSound {
|
|||
* Because the method is supported from 2.2, so I can't use
|
||||
* it here.
|
||||
*/
|
||||
playEffect(path);
|
||||
playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
return soundId.intValue();
|
||||
|
|
|
@ -389,6 +389,10 @@ void RenderTextureZbuffer::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
|||
void RenderTextureZbuffer::renderScreenShot()
|
||||
{
|
||||
CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight(512, 512);
|
||||
if (NULL == texture)
|
||||
{
|
||||
return;
|
||||
}
|
||||
texture->setAnchorPoint(ccp(0, 0));
|
||||
texture->begin();
|
||||
|
||||
|
|
|
@ -609,7 +609,12 @@ void TexturePVRRGBA4444GZ::onEnter()
|
|||
TextureDemo::onEnter();
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
// android can not pack .gz file into apk file
|
||||
CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba4444.pvr");
|
||||
#else
|
||||
CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba4444.pvr.gz");
|
||||
#endif
|
||||
img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
|
||||
addChild(img);
|
||||
CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
|
||||
|
|
Loading…
Reference in New Issue