From 0ea2035ec60b64600f810d1c9ac0e15aba6e85bc Mon Sep 17 00:00:00 2001 From: Ming Date: Thu, 4 Nov 2010 09:33:31 +0000 Subject: [PATCH] --- .../android/CCXApplication_android.cpp | 2 +- cocos2dx/platform/android/CCXBitmapDC.cpp | 19 ++- .../platform/android/CCXEGLView_android.cpp | 37 +++++ .../platform/android/CCXUIImage_android.cpp | 136 +++++++++--------- 4 files changed, 123 insertions(+), 71 deletions(-) diff --git a/cocos2dx/platform/android/CCXApplication_android.cpp b/cocos2dx/platform/android/CCXApplication_android.cpp index f8b3d2e6a7..1e04395180 100644 --- a/cocos2dx/platform/android/CCXApplication_android.cpp +++ b/cocos2dx/platform/android/CCXApplication_android.cpp @@ -50,7 +50,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) return JNI_VERSION_1_4; } -void Java_org_cocos2dx_DemoRenderer_nativeRender(JNIEnv* env) +void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env) { cocos2d::CCDirector::getSharedDirector()->preMainLoop(); } diff --git a/cocos2dx/platform/android/CCXBitmapDC.cpp b/cocos2dx/platform/android/CCXBitmapDC.cpp index 3307c7bb1b..1629bf2e5a 100644 --- a/cocos2dx/platform/android/CCXBitmapDC.cpp +++ b/cocos2dx/platform/android/CCXBitmapDC.cpp @@ -86,7 +86,7 @@ namespace cocos2d { //__android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "get env"); - jclass mClass = env->FindClass("org/cocos2dx/Cocos2dJNI"); + jclass mClass = env->FindClass("org/cocos2dx/lib/Cocos2dxJNI"); if (! mClass) { __android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "can not find org.cocos2dx.Cocos2dJNI"); @@ -119,15 +119,30 @@ namespace cocos2d { data = new unsigned char[info.width * info.height * 4]; if (! data) { - AndroidBitmap_unlockPixels(evn, bitmap); + AndroidBitmap_unlockPixels(env, bitmap); __android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "failed to allocate memory"); return; } memcpy(data, pixels, info.width * info.height * 4); + AndroidBitmap_unlockPixels(env, bitmap); + + // swap data + unsigned int *tempPtr = (unsigned int*)data; + unsigned int tempdata = 0; + for (int i = 0; i < info.height; ++i) + { + for (int j = 0; j < info.width; ++j) + { + tempdata = *tempPtr; + *tempPtr++ = swapAlpha(tempdata); + } + } m_nWidth = info.width; m_nHeight =info.height; + + //__android_log_print(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "width: %d, height:%d", m_nWidth, m_nHeight); } unsigned int CCXBitmapDC::swapAlpha(unsigned int value) diff --git a/cocos2dx/platform/android/CCXEGLView_android.cpp b/cocos2dx/platform/android/CCXEGLView_android.cpp index 2851e9b4fc..ed92c14832 100644 --- a/cocos2dx/platform/android/CCXEGLView_android.cpp +++ b/cocos2dx/platform/android/CCXEGLView_android.cpp @@ -30,6 +30,39 @@ THE SOFTWARE. #include "CCTouch.h" #include "CCTouchDispatcher.h" +#include +#include + +extern "C" +{ + static cocos2d::EGLTouchDelegate *s_pDelegate; + static cocos2d::CCTouch s_touch; + static cocos2d::NSSet s_set; + + + void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesBegin(jfloat x, jfloat y) + { + s_touch.SetTouchInfo(0, x, y); + s_set.addObject(&s_touch); + s_pDelegate->touchesBegan(&s_set, NULL); + } + + void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesEnd(jfloat x, jfloat y) + { + s_touch.SetTouchInfo(0, x, y); + s_pDelegate->touchesEnded(&s_set, NULL); + s_set.removeObject(&s_touch); + } + + void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesMove(jfloat x, jfloat y) + { + } + + void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeTouchesCancel(jfloat x, jfloat y) + { + } +} + namespace cocos2d { @@ -47,6 +80,7 @@ void CCXEGLView::setFrameWitdAndHeight(int width, int height) CCXEGLView::~CCXEGLView() { + CCX_SAFE_DELETE(s_pDelegate); } CGSize CCXEGLView::getSize() @@ -62,10 +96,12 @@ bool CCXEGLView::isOpenGLReady() void CCXEGLView::release() { + exit(0); } void CCXEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate) { + s_pDelegate = pDelegate; } void CCXEGLView::swapBuffers() @@ -73,3 +109,4 @@ void CCXEGLView::swapBuffers() } } // end of namespace cocos2d + diff --git a/cocos2dx/platform/android/CCXUIImage_android.cpp b/cocos2dx/platform/android/CCXUIImage_android.cpp index 323b802385..849ccf6613 100644 --- a/cocos2dx/platform/android/CCXUIImage_android.cpp +++ b/cocos2dx/platform/android/CCXUIImage_android.cpp @@ -31,7 +31,7 @@ THE SOFTWARE. #include -/*#include "jpeglib.h"*/ +#include "jpeglib.h" //using namespace ImageToolKit; using namespace std; @@ -287,73 +287,73 @@ bool UIImage::loadPngFromStream(unsigned char *data, int nLength) bool UIImage::loadJpg(const char *strFileName) { -// /* these are standard libjpeg structures for reading(decompression) */ -// struct jpeg_decompress_struct cinfo; -// struct jpeg_error_mgr jerr; -// /* libjpeg data structure for storing one row, that is, scanline of an image */ -// JSAMPROW row_pointer[1]; -// -// FILE *infile = fopen( strFileName, "rb" ); -// unsigned long location = 0; -// unsigned int i = 0; -// -// if ( !infile ) -// { -// return false; -// } -// -// /* here we set up the standard libjpeg error handler */ -// cinfo.err = jpeg_std_error( &jerr ); -// -// /* setup decompression process and source, then read JPEG header */ -// jpeg_create_decompress( &cinfo ); -// -// /* this makes the library read from infile */ -// jpeg_stdio_src( &cinfo, infile ); -// -// /* reading the image header which contains image information */ -// jpeg_read_header( &cinfo, true ); -// -// // we only support RGB or grayscale -// if (cinfo.jpeg_color_space != JCS_RGB) -// { -// if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr) -// { -// cinfo.out_color_space = JCS_RGB; -// } -// } -// else -// { -// return false; -// } -// -// /* Start decompression jpeg here */ -// jpeg_start_decompress( &cinfo ); -// -// /* init image info */ -// m_imageInfo.width = cinfo.image_width; -// m_imageInfo.height = cinfo.image_height; -// m_imageInfo.hasAlpha = false; -// m_imageInfo.isPremultipliedAlpha = false; -// m_imageInfo.bitsPerComponent = 8; -// m_imageInfo.data = new unsigned char[cinfo.output_width*cinfo.output_height*cinfo.output_components]; -// -// /* now actually read the jpeg into the raw buffer */ -// row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components]; -// -// /* read one scan line at a time */ -// while( cinfo.output_scanline < cinfo.image_height ) -// { -// jpeg_read_scanlines( &cinfo, row_pointer, 1 ); -// for( i=0; i