[android] issue #338:refactor platform_support

This commit is contained in:
minggo 2011-02-24 19:42:45 +08:00
parent b34b54a6c6
commit 0453eb0266
282 changed files with 569 additions and 1257 deletions

View File

@ -1,6 +1,7 @@
#include "AppDelegate.h"
#include "cocos2d.h"
USING_NS_CC;
#include "HelloWorldScene.h"

View File

@ -49,16 +49,16 @@ bool HelloWorld::init()
// add a label shows "Hello World"
// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("HelloWorld", "Thonburi", 34);
//CCLabelTTF* pLabel = CCLabelTTF::labelWithString("HelloWorld", "Thonburi", 34);
// ask director the window size
CGSize size = CCDirector::sharedDirector()->getWinSize();
// position the label on the center of the screen
pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
//pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
// add the label as a child to this layer
this->addChild(pLabel, 1);
//this->addChild(pLabel, 1);
// add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");

View File

@ -10,10 +10,7 @@ package org.cocos2dx.application;
public final class R {
public static final class attr {
}
public static final class layout {
public static final int main=0x7f020000;
}
public static final class string {
public static final int app_name=0x7f030000;
public static final int app_name=0x7f020000;
}
}

View File

@ -3,12 +3,14 @@ include $(CLEAR_VARS)
LOCAL_MODULE := helloworld
LOCAL_SRC_FILES := main.cpp \
Application.cpp \
../../../AppDelegate.cpp \
../../../HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
$(LOCAL_PATH)/../../../../cocos2dx/include \
$(LOCAL_PATH)/../../..
$(LOCAL_PATH)/../../.. \
$(LOCAL_PATH)/../../../../platform_support/include
LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../libs/armeabi -lcocos2d -llog

View File

@ -0,0 +1,102 @@
#include "Application.h"
#include "CCDirector.h"
#include <android/log.h>
#include <jni.h>
#define LOG_TAG "HelloWorld Debug"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
static JavaVM *gJavaVM = NULL;
jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
gJavaVM = vm;
return JNI_VERSION_1_4;
}
USING_NS_CC;
Application::Application()
{
}
Application::~Application()
{
}
int Application::run()
{
// Make sharedApplication work correctly.
setSharedApplication(*this);
// Initialize AppDelegate.
if (! m_Delegate.applicationDidFinishLaunching())
{
return 0;
}
}
bool Application::initInstance()
{
return true;
}
void Application::setAnimationInterval(double interval)
{
jmethodID ret = 0;
JNIEnv *env = 0;
jclass classOfCocos2dxRenderer = 0;
if (! gJavaVM)
{
LOGD("have not java vm");
return;
}
// get jni environment and java class for Cocos2dxActivity
if (gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK)
{
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);
}
}
}
Application::Orientation Application::setOrientation(Application::Orientation orientation)
{
return orientation;
}
void Application::statusBarFrame(cocos2d::CGRect * rect)
{
if (rect)
{
// Android doesn't have status bar.
*rect = CGRectMake(0, 0, 0, 0);
}
}

View File

@ -0,0 +1,48 @@
#ifndef __APPLICATION_H__
#define __APPLICATION_H__
#include "ccxApplication.h"
#include "AppDelegate.h"
#include "CCXEGLView.h"
class Application : public cocos2d::ccxApplication
{
public:
Application();
virtual ~Application();
/**
@brief Run the message loop.
*/
int run();
/**
@brief Call for init OpenGL instance, source path, etc...
*/
virtual bool initInstance();
/**
@brief Callback by CCDirector for limit FPS.
@interval The time, which expressed in second in second, between current frame and next.
*/
virtual void setAnimationInterval(double interval);
/**
@brief Callback by CCDirector for change device orientation.
@orientation The defination of orientation which CCDirector want change to.
@return The actual orientation of the application.
*/
virtual Orientation setOrientation(Orientation orientation);
/**
@brief Get status bar rectangle in EGLView window.
*/
virtual void statusBarFrame(cocos2d::CGRect * rect);
protected:
AppDelegate m_Delegate;
};
#endif // __APPLICATION_H__

View File

@ -1,8 +1,11 @@
#include "AppDelegate.h"
#include "Application.h"
#include "cocos2d.h"
#include <jni.h>
#include <android/log.h>
#define LOG_TAG "main"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
using namespace cocos2d;
#define IMG_PATH "assets"
@ -14,14 +17,14 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
{
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
{
cocos2d::CCXEGLView *view = new cocos2d::CCXEGLView();
cocos2d::CCXEGLView *view = &cocos2d::CCXEGLView::sharedOpenGLView();
view->setFrameWitdAndHeight(w, h);
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
CCFileUtils::setRelativePath(IMG_PATH);
AppDelegate app;
app.Run();
Application app;
app.run();
}
else
{

View File

@ -56,17 +56,12 @@ platform/CCMenu_mobile.cpp \
platform/CCNode_mobile.cpp \
platform/CCParticleSystemPoint_mobile.cpp \
platform/CCTransition_mobile.cpp \
platform/platform.cpp \
platform/android/CCNS_android.cpp \
platform/android/CCTime.cpp \
platform/android/CCXApplication_android.cpp \
platform/android/CCXBitmapDC.cpp \
platform/android/CCXEGLView_android.cpp \
platform/android/CCXFileUtils_android.cpp \
platform/android/CCXUIAccelerometer_android.cpp \
platform/android/CCXUIImage_android.cpp \
platform/android/Cocos2dJni.cpp \
platform/android/NSLock.cpp \
platform/android/ccxCommon_android.cpp \
sprite_nodes/CCAnimation.cpp \
sprite_nodes/CCAnimationCache.cpp \
sprite_nodes/CCSprite.cpp \
@ -81,7 +76,6 @@ support/base64.cpp \
support/ccUtils.cpp \
support/file_support/FileUtils.cpp \
support/image_support/TGAlib.cpp \
support/opengl_support/glu.cpp \
support/zip_support/ZipUtils.cpp \
support/zip_support/ioapi.cpp \
support/zip_support/unzip.cpp \
@ -97,27 +91,36 @@ tileMap_parallax_nodes/CCTileMapAtlas.cpp \
touch_dispatcher/CCTouchDispatcher.cpp \
touch_dispatcher/CCTouchHandler.cpp
# platform_support
LOCAL_SRC_FILES += ../platform_support/src/ccxApplication.cpp \
../platform_support/src/ccxGL.cpp \
../platform_support/src/ccxImage.cpp \
../platform_support/src/ccxStdC.cpp \
../platform_support/src/ccxThread.cpp \
../platform_support/src/ccxCommon.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/platform/android/third_party/iconv \
$(LOCAL_PATH)/platform/android/third_party/libpng \
$(LOCAL_PATH)/platform/android/third_party/libxml2 \
$(LOCAL_PATH)/platform/android/third_party/libjpeg \
$(LOCAL_PATH)/platform/android/third_party/skia/core \
$(LOCAL_PATH)/platform/android/third_party/skia/animator \
$(LOCAL_PATH)/platform/android/third_party/skia/config \
$(LOCAL_PATH)/platform/android/third_party/skia/effects \
$(LOCAL_PATH)/platform/android/third_party/skia/images \
$(LOCAL_PATH)/platform/android/third_party/skia/pdf \
$(LOCAL_PATH)/platform/android/third_party/skia/ports \
$(LOCAL_PATH)/platform/android/third_party/skia/svg \
$(LOCAL_PATH)/platform/android/third_party/skia/text \
$(LOCAL_PATH)/platform/android/third_party/skia/utils \
$(LOCAL_PATH)/platform/android/third_party/skia/views \
$(LOCAL_PATH)/platform/android/third_party/skia/ xml
$(LOCAL_PATH)/../platform_support/include \
$(LOCAL_PATH)/../platform_support/third_party/android/iconv \
$(LOCAL_PATH)/../platform_support/third_party/android/libpng \
$(LOCAL_PATH)/../platform_support/third_party/android/libxml2 \
$(LOCAL_PATH)/../platform_support/third_party/android/libjpeg \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/core \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/animator \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/config \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/effects \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/images \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/pdf \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/ports \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/svg \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/text \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/utils \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/views \
$(LOCAL_PATH)/../platform_support/third_party/android/skia/xml
#it is used for ndk-r4
LOCAL_LDLIBS := -L$(LOCAL_PATH)/platform/android/third_party/libs \
LOCAL_LDLIBS := -L$(LOCAL_PATH)/../platform_support/third_party/android/libs \
-lGLESv1_CM -llog -lz \
-lpng \
-lxml2 \
@ -127,7 +130,7 @@ LOCAL_LDLIBS := -L$(LOCAL_PATH)/platform/android/third_party/libs \
# it is used for ndk-r5
# because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/)
#LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/platform/android/third_party/libs) \
#LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../platform_support/third_party/android/libs) \
# -lGLESv1_CM -llog -lz \
# -lpng \
# -lxml2 \

View File

@ -1,50 +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 "CCTime.h"
#include <sys/time.h>
namespace cocos2d {
// although it is not the same as gettimeofday as unix
// but we only use the diffrences of tow values
int CCTime::gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp)
{
struct timeval androidTime;
gettimeofday(&androidTime, NULL);
tp->tv_sec = androidTime.tv_sec;
tp->tv_usec = androidTime.tv_usec;
return 0;
}
void CCTime::timersubCocos2d(struct cc_timeval *out, struct cc_timeval *start, struct cc_timeval *end)
{
out->tv_sec = end->tv_sec - start->tv_sec;
out->tv_usec = end->tv_usec - start->tv_usec;
}
}//namespace cocos2d

View File

@ -1,43 +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.
****************************************************************************/
#ifndef __PLATFORM_UPHONE_CCTIME_H__
#define __PLATFORM_UPHONE_CCTIME_H__
namespace cocos2d {
struct cc_timeval
{
long tv_sec; // seconds
long tv_usec; // microSeconds
};
class CCTime
{
public:
static int gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp);
static void timersubCocos2d(struct cc_timeval *out, struct cc_timeval *start, struct cc_timeval *end);
};
}//namespace cocos2d
#endif // __PLATFORM_UPHONE_NSTIME_H__

View File

@ -1,86 +0,0 @@
#include "CCXApplication_android.h"
#include "CCXUIImage_android.h"
#include "CCXEGLView_android.h"
#include "CCDirector.h"
#include "Cocos2dJni.h"
#include <GLES/glext.h>
#include <android/log.h>
#define LOG_TAG "Application android"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
namespace cocos2d {
static CCXApplication *s_pApplication;
CCXApplication::CCXApplication()
{
s_pApplication = this;
}
CCXApplication::~CCXApplication()
{
}
ccDeviceOrientation CCXApplication::setDeviceOrientation(ccDeviceOrientation eOritation)
{
return eOritation;
}
CGRect CCXApplication::statusBarFrame()
{
CGRect rc;
return rc;
}
void CCXApplication::Run()
{
applicationDidFinishLaunching();
}
void CCXApplication::setAnimationInterval(double interval)
{
jmethodID ret = 0;
JNIEnv *env = 0;
jclass classOfCocos2dxRenderer = 0;
// get jni environment and java class for Cocos2dxActivity
if (gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK)
{
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);
}
}
}
//////////////////////////////////////////////////////////////////////////
/// Implement static class member
//////////////////////////////////////////////////////////////////////////
CCXApplication * CCXApplication::sharedApplication()
{
return s_pApplication;
}
}

View File

@ -1,73 +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.
****************************************************************************/
#ifndef __CCX_APPLICATION_UPHONE_H__
#define __CCX_APPLICATION_UPHONE_H__
#include "CGGeometry.h"
#include "CCDirector.h"
#include <jni.h>
namespace cocos2d {
class CCX_DLL CCXApplication
{
public:
CCXApplication();
virtual ~CCXApplication();
/**
@brief rotate main window by device orientation.
@param nOritation device orientation enum value.
@see ccDeviceOrientation
*/
ccDeviceOrientation setDeviceOrientation(ccDeviceOrientation eOritation);
/**
@brief Implement CCDirector and sense init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching() = 0;
/**
@brief Get status bar rectangle in EGLView window.
*/
CGRect statusBarFrame();
void Run();
void setAnimationInterval(double interval);
/**
@brief Get current applicaiton instance.
@return Current application instance pointer.
*/
static CCXApplication * sharedApplication();
};
} // end of namespace cocos2d
#endif // end of __CCX_APPLICATION_UPHONE_H__

View File

@ -1,152 +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 <cstring>
#include "CCXBitmapDC.h"
#include "Cocos2dJni.h"
#include "CCDirector.h"
#include "platform/platform.h"
#include <android/log.h>
#include <string.h>
#include <math.h>
// undefine ANDROID to include skia headers
#ifdef ANDROID
#undef ANDROID
#endif
#include "SkBitmap.h"
#include "SkPaint.h"
#include "SkScalar.h"
#include "SkCanvas.h"
#include "SkTypeface.h"
namespace cocos2d {
CCXBitmapDC::CCXBitmapDC()
{
m_nWidth = 0;
m_nHeight = 0;
m_pData = NULL;
}
CCXBitmapDC::CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
{
m_nWidth = 0;
m_nHeight = 0;
m_pData = NULL;
drawText(text, fontName, fontSize);
}
CCXBitmapDC::~CCXBitmapDC()
{
if (m_pData)
{
delete[] m_pData;
}
}
int CCXBitmapDC::getWidth()
{
return m_nWidth;
}
int CCXBitmapDC::getHeight()
{
return m_nHeight;
}
unsigned char* CCXBitmapDC::getData()
{
return m_pData;
}
void CCXBitmapDC::drawText(const char *text, const char *fontName, float fontSize)
{
// init paint
SkPaint *paint = new SkPaint();
paint->setColor(SK_ColorWHITE);
paint->setTextSize(fontSize);
// create font
SkTypeface *pTypeFace = SkTypeface::CreateFromName(fontName, SkTypeface::kNormal);
paint->setTypeface( pTypeFace );
// get text width and height
SkPaint::FontMetrics font;
paint->getFontMetrics(&font);
int h = (int)ceil((font.fDescent - font.fAscent));
int w = (int)ceil((paint->measureText(text, strlen(text))));
// create and init bitmap
SkBitmap *bitmap = new SkBitmap();
bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h);
if (! bitmap->allocPixels())
{
CCLOG("alloc pixels error");
return;
}
// start with black/transparent pixels
bitmap->eraseColor(0);
// create canvas and draw text
SkCanvas canvas(*bitmap);
canvas.drawText(text, strlen(text), 0.0, -font.fAscent, *paint);
// get data
m_pData = new unsigned char[w * h * 4];
memcpy(m_pData, bitmap->getPixels(), w * h * 4);
// destrcut objects
// delete canvas;
delete bitmap;
delete paint;
m_nWidth = w;
m_nHeight = h;
// JNIEnv *env;
// if (gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4) <0 )
// {
// if (gJavaVM->AttachCurrentThread(&env, NULL) < 0)
// {
// return;
// }
// }
//
// //__android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "get env");
//
// jclass mClass = env->FindClass("org/cocos2dx/lib/Cocos2dxJNI");
// if (! mClass)
// {
// __android_log_write(ANDROID_LOG_DEBUG, "cocos2d::CCXBitmapDC", "can not find org.cocos2dx.Cocos2dJNI");
// return;
// }
//
// jmethodID mid = env->GetStaticMethodID(mClass, "createTextBitmap", "(Ljava/lang/String;I)Landroid/graphics/Bitmap;");
}
}

View File

@ -1,56 +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.
****************************************************************************/
#ifndef __CCXBITMAP_DC_H__
#define __CCXBITMAP_DC_H__
#include "ccTypes.h"
#include "CCXCocos2dDefine.h"
#include "CCXUIImage.h"
namespace cocos2d{
class CCX_DLL CCXBitmapDC
{
public:
CCXBitmapDC();
CCXBitmapDC(const char *text,
CGSize dimensions = CGSizeZero,
UITextAlignment alignment = UITextAlignmentCenter,
const char *fontName = NULL,
float fontSize = 0);
~CCXBitmapDC(void);
int getWidth();
int getHeight();
unsigned char* getData();
private:
void drawText(const char *text, const char *fontName, float fontSize);
private:
int m_nWidth;
int m_nHeight;
unsigned char *m_pData;
};
}
#endif //__CCXBITMAP_DC_H__

View File

@ -1,117 +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.
****************************************************************************/
#ifndef __PLATFORM_ANDROID_CCXCOCOS2D_DEFINE_H__
#define __PLATFORM_ANDROID_CCXCOCOS2D_DEFINE_H__
/** CCX_PROPERTY_READONLY is used to declare a protected variable.
We can use getter to read the variable.
@param varType : the type of variable.
@param varName : variable name.
@param funName : "get + funName" is the name of the getter.
@warning : The getter is a public virtual function, you should rewrite it first.
The variables and methods declared after CCX_PROPERTY_READONLY are all public.
If you need protected or private, please declare.
*/
#define CCX_PROPERTY_READONLY(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void);
/** CCX_PROPERTY is used to declare a protected variable.
We can use getter to read the variable, and use the setter to change the variable.
@param varType : the type of variable.
@param varName : variable name.
@param funName : "get + funName" is the name of the getter.
"set + funName" is the name of the setter.
@warning : The getter and setter are public virtual functions, you should rewrite them first.
The variables and methods declared after CCX_PROPERTY are all public.
If you need protected or private, please declare.
*/
#define CCX_PROPERTY(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void);\
public: virtual void set##funName(varType var);
/** CCX_SYNTHESIZE_READONLY is used to declare a protected variable.
We can use getter to read the variable.
@param varType : the type of variable.
@param varName : variable name.
@param funName : "get + funName" is the name of the getter.
@warning : The getter is a public inline function.
The variables and methods declared after CCX_SYNTHESIZE_READONLY are all public.
If you need protected or private, please declare.
*/
#define CCX_SYNTHESIZE_READONLY(varType, varName, funName)\
protected: varType varName;\
public: inline varType get##funName(void){ return varName; }
/** CCX_SYNTHESIZE is used to declare a protected variable.
We can use getter to read the variable, and use the setter to change the variable.
@param varType : the type of variable.
@param varName : variable name.
@param funName : "get + funName" is the name of the getter.
"set + funName" is the name of the setter.
@warning : The getter and setter are public inline functions.
The variables and methods declared after CCX_SYNTHESIZE are all public.
If you need protected or private, please declare.
*/
#define CCX_SYNTHESIZE(varType, varName, funName)\
protected: varType varName;\
public: inline varType get##funName(void){ return varName; }\
public: inline void set##funName(varType var){ varName = var; }
#define CCX_SAFE_DELETE(p) if(p) { delete p; p=NULL; }
#define CCX_SAFE_DELETE_ARRAY(p) if(p) { delete[] p; p=NULL; }
#define CCX_SAFE_FREE(p) if(p) { free(p); p=NULL; }
#define CCX_SAFE_RELEASE(p) if(p) { p->release(); }
#define CCX_SAFE_RELEASE_NULL(p) if(p) { p->release(); p = NULL; }
#define CCX_SAFE_RETAIN(p) if(p) { p->retain(); }
#define CCX_BREAK_IF(cond) if(cond) break;
#ifdef _DEBUG
#include <assert.h>
#include <stdio.h>
#define NSAssert(_CONDITION, _TXT)\
if(! (_CONDITION) ) \
{ \
assert( (_CONDITION) ); \
}
#else
#define NSAssert(_CONDITION, _TXT)
#endif // _DEBUG
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define self this
#define YES true
#define NO false
#define nil NULL
#endif // __PLATFORM_ANDROID_CCXCOCOS2D_DEFINE_H__

View File

@ -24,7 +24,6 @@ THE SOFTWARE.
#include "CCXEGLView_android.h"
#include "GLES/gl.h"
#include "CCXCocos2dDefine.h"
#include "NSSet.h"
#include "CCDirector.h"
#include "ccMacros.h"
@ -91,7 +90,19 @@ bool CCXEGLView::canSetContentScaleFactor()
void CCXEGLView::setContentScaleFactor(float contentScaleFactor)
{
// if it supports scaling content, set it
m_fScreenScaleFactor = contentScaleFactor;
}
void CCXEGLView::setViewPortInPoints(float x, float y, float w, float h)
{
///@todo
}
CCXEGLView& CCXEGLView::sharedOpenGLView()
{
static CCXEGLView instance;
return instance;
}
} // end of namespace cocos2d

View File

@ -49,11 +49,19 @@ public:
void swapBuffers();
bool canSetContentScaleFactor();
void setContentScaleFactor(float contentScaleFactor);
void setViewPortInPoints(float x, float y, float w, float h);
// static function
/**
@brief get the shared main open gl window
*/
static CCXEGLView& sharedOpenGLView();
private:
int m_nWidth;
int m_nHeight;
EGLTouchDelegate *m_pDelegate;
float m_fScreenScaleFactor;
};
} // end of namespace cocos2d

View File

@ -29,12 +29,13 @@ THE SOFTWARE.
#include <libxml/xmlmemory.h>
#include "NSString.h"
#include "CCXFileUtils_android.h"
#include "CCXCocos2dDefine.h"
#include "support/file_support/FileData.h"
#include "support/zip_support/unzip.h"
namespace cocos2d {
#define MAX_PATH 256
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
void plist_endElement(void *ctx, const xmlChar *name);
void plist_characters(void *ctx, const xmlChar *ch, int len);

View File

@ -1,312 +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 "CCXUIImage_android.h"
#include "CCXFileUtils.h"
#include "png.h"
#include "CCXBitmapDC.h"
#include "support/file_support/FileData.h"
#include "jpeglib.h"
#include <android/log.h>
//using namespace ImageToolKit;
using namespace std;
namespace cocos2d {
bool UIImage::s_bPopupNotify = false;
#define CCX_RGB_PREMULTIPLY_APLHA(vr, vg, vb, va) \
(unsigned int)(((unsigned int)((unsigned char)(vr) * ((unsigned char)(va) + 1)) >> 8) | \
((unsigned int)((unsigned char)(vg) * ((unsigned char)(va) + 1) >> 8) << 8) | \
((unsigned int)((unsigned char)(vb) * ((unsigned char)(va) + 1) >> 8) << 16) | \
((unsigned int)(unsigned char)(va) << 24))
typedef struct
{
unsigned char* data;
int size;
int offset;
}tImageSource;
// because we do not want to include "png.h" in CCXUIImage_uphone.h, so we implement
// the function as a static function
static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t length)
{
tImageSource* isource = (tImageSource*)png_get_io_ptr(png_ptr);
if((int)(isource->offset + length) <= isource->size)
{
memcpy(data, isource->data+isource->offset, length);
isource->offset += length;
}
else
{
png_error(png_ptr, "pngReaderCallback failed");
}
}
UIImage::UIImage(void)
{
m_imageInfo.hasAlpha = false;
m_imageInfo.isPremultipliedAlpha = false;
m_imageInfo.height = 0;
m_imageInfo.width = 0;
m_imageInfo.data = NULL;
m_imageInfo.bitsPerComponent = 0;
}
UIImage::UIImage(CCXBitmapDC * pBmpDC)
{
do
{
CCX_BREAK_IF(! pBmpDC);
// init imageinfo
int nWidth = pBmpDC->getWidth();
int nHeight = pBmpDC->getHeight();
CCX_BREAK_IF(nWidth <= 0 || nHeight <= 0);
int nLen = nWidth * nHeight * 4;
m_imageInfo.data = new unsigned char [nLen];
CCX_BREAK_IF(! m_imageInfo.data);
memcpy(m_imageInfo.data, pBmpDC->getData(), nLen);
m_imageInfo.height = nHeight;
m_imageInfo.width = nWidth;
m_imageInfo.hasAlpha = true;
m_imageInfo.isPremultipliedAlpha = true;
m_imageInfo.bitsPerComponent = 8;
} while (0);
}
UIImage::~UIImage(void)
{
if (m_imageInfo.data)
{
delete []m_imageInfo.data;
}
}
bool UIImage::initWithContentsOfFile(const string &strPath, eImageFormat imageType)
{
bool bRet = false;
FileData data;
unsigned long nSize = 0;
unsigned char* pBuffer = data.getFileData(strPath.c_str(), "rb", &nSize);
if (pBuffer)
{
switch (imageType)
{
case kCCImageFormatPNG:
// use libpng load image
bRet = loadPngFromStream(pBuffer, nSize);
break;
case kCCImageFormatJPG:
bRet = loadJpgFromStream(pBuffer, nSize);
break;
default:
// unsupported image type
bRet = false;
break;
}
}
return bRet;
}
unsigned int UIImage::width(void)
{
return m_imageInfo.width;
}
unsigned int UIImage::height(void)
{
return m_imageInfo.height;
}
bool UIImage::isAlphaPixelFormat(void)
{
return m_imageInfo.hasAlpha;
}
// now, uphone only support premultiplied data
// so, we only return true
bool UIImage::isPremultipliedAlpha(void)
{
return m_imageInfo.isPremultipliedAlpha;
}
// compute how many bits every color component
int UIImage::CGImageGetBitsPerComponent(void)
{
return m_imageInfo.bitsPerComponent;
}
// now we only support RGBA8888 or RGB888
// so it has color space
int UIImage::CGImageGetColorSpace(void)
{
return 1;
}
unsigned char* UIImage::getData(void)
{
return m_imageInfo.data;
}
bool UIImage::loadPngFromStream(unsigned char *data, int nLength)
{
char header[8];
png_structp png_ptr;
png_infop info_ptr;
png_bytep * rowPointers;
tImageSource imageSource;
int color_type;
// read 8 bytes from the beginning of stream
unsigned char *tmp = data;
memcpy(header, tmp, 8);
// close the file if it's not a png
if (png_sig_cmp((png_bytep)header, 0, 8))
{
return false;
}
// init png_struct
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
return false;
}
// init png_info
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, NULL, NULL);
return false;
}
// if something wrong,close file and return
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return false;
}
// set the read call back function
imageSource.data = data;
imageSource.size = nLength;
imageSource.offset = 0;
png_set_read_fn(png_ptr, &imageSource, pngReadCallback);
// read png
// PNG_TRANSFORM_EXPAND: perform set_expand()
// PNG_TRANSFORM_PACKING: expand 1, 2 and 4-bit samples to bytes
// PNG_TRANSFORM_STRIP_16: strip 16-bit samples to 8 bits
// PNG_TRANSFORM_GRAY_TO_RGB: expand grayscale samples to RGB (or GA to RGBA)
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_GRAY_TO_RGB, NULL);
png_get_IHDR(png_ptr, info_ptr, &m_imageInfo.width, &m_imageInfo.height, &m_imageInfo.bitsPerComponent, &color_type,
NULL, NULL, NULL);
// init image info
m_imageInfo.isPremultipliedAlpha = true;
m_imageInfo.hasAlpha = ( info_ptr->color_type & PNG_COLOR_MASK_ALPHA ) ? true : false;
// allocate memory and read data
int bytesPerComponent = 3;
if (m_imageInfo.hasAlpha)
{
bytesPerComponent = 4;
}
m_imageInfo.data = new unsigned char[m_imageInfo.height * m_imageInfo.width * bytesPerComponent];
rowPointers = png_get_rows(png_ptr, info_ptr);
// copy data to image info
int bytesPerRow = m_imageInfo.width * bytesPerComponent;
if(m_imageInfo.hasAlpha) {
unsigned int *tmp = (unsigned int *)m_imageInfo.data;
for(unsigned int i = 0; i < m_imageInfo.height; i++)
{
for(int j = 0; j < bytesPerRow; j += 4)
{
*tmp++ = CCX_RGB_PREMULTIPLY_APLHA( rowPointers[i][j], rowPointers[i][j + 1],
rowPointers[i][j + 2], rowPointers[i][j + 3] );
}
}
}
else
{
for (unsigned int j = 0; j < m_imageInfo.height; ++j)
{
memcpy(m_imageInfo.data + j * bytesPerRow, rowPointers[j], bytesPerRow);
}
}
// release
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return true;
}
bool UIImage::loadJpgFromStream(unsigned char *data, unsigned long nSize)
{
/// @todo: libjpeg of android not support jpeg_mem_src()
return false;
}
bool UIImage::save(const std::string &strFileName, int nFormat)
{
/// @todo uiimage::save
return false;
}
bool UIImage::initWithData(unsigned char *pBuffer, int nLength)
{
return loadPngFromStream(pBuffer, nLength);
}
bool UIImage::initWithBuffer(int tx, int ty, unsigned char *pBuffer)
{
/// @todo
return false;
}
void UIImage::setIsPopupNotify(bool bNotify)
{
s_bPopupNotify = bNotify;
}
bool UIImage::getIsPopupNotify()
{
return s_bPopupNotify;
}
}//namespace cocos2d

View File

@ -1,115 +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.
****************************************************************************/
#ifndef __PLATFORM_UPHONE_UIIMAGE_H__
#define __PLATFORM_UPHONE_UIIMAGE_H__
#include <string>
#include "ccxCommon.h"
#include "CCRenderTexture.h"
struct AppResourceEntry;
namespace cocos2d {
class CCXBitmapDC;
typedef struct
{
unsigned int height;
unsigned int width;
int bitsPerComponent;
bool hasAlpha;
bool isPremultipliedAlpha;
unsigned char *data;
} tImageInfo;
/**
@brief image toolkits
*/
class CCX_DLL UIImage
{
public:
UIImage(void);
UIImage(CCXBitmapDC * pBmpDC);
~UIImage(void);
/**
Load the image from the specified path.
@param strPath the absolute file path
@param imageType the type of image, now only support tow types:
- kImageFormatPNG -> png
- kImageFormatJPG -> jpeg
@return true if load correctly
*/
bool initWithContentsOfFile(const std::string &strPath, eImageFormat imageType = kCCImageFormatPNG);
/**
Load image from stream buffer.
@param pBuffer stream buffer that hold the image data
@param nLength the length of data(managed in byte)
@return true if load correctly
*/
bool initWithData(unsigned char *pBuffer, int nLength);
/// @cond
bool initWithBuffer(int tx, int ty, unsigned char *pBuffer);
bool save(const std::string &strFileName, int nFormat);
/// @endcond
/** get the image width */
unsigned int width(void);
/** get the image height */
unsigned int height(void);
/** whether or not the image has alpha channel */
bool isAlphaPixelFormat(void);
/** whether or not the r, g, b channels are premultiplied by alpha channel */
bool isPremultipliedAlpha(void);
/** get the bit depth of each color channel */
int CGImageGetBitsPerComponent(void);
/** the source color space for the image, or 0 if the image is an image mask */
int CGImageGetColorSpace(void);
/** get the image data */
unsigned char* getData(void);
/**
@brief Set/Get whether pop-up a message box when the image load failed
@todo not implement now
*/
static void setIsPopupNotify(bool bNotify);
static bool getIsPopupNotify();
private:
bool loadPngFromStream(unsigned char *data, int nLength);
bool loadJpgFromStream(unsigned char *data, unsigned long nSize);
private:
tImageInfo m_imageInfo;
static bool s_bPopupNotify;
};
}//namespace cocos2d
#endif // __PLATFORM_UPHONE_UIIMAGE_H__

View File

@ -1,39 +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.
****************************************************************************/
#ifndef __SUPPORT_COCOS2D_TYPES_H__
#define __SUPPORT_COCOS2D_TYPES_H__
namespace cocos2d {
typedef signed char INT8;
typedef unsigned char UINT8;
typedef signed short INT16;
typedef unsigned short UINT16;
typedef signed int INT32;
typedef unsigned int UINT32;
typedef long long INT64;
typedef unsigned long long UINT64;
}//namespace cocos2d
#endif // __SUPPORT_COCOS2D_TYPES_H__

View File

@ -1,41 +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.
****************************************************************************/
#ifndef __PLATFORM_UPHONE_PLATFORM_NSLOCK_H__
#define __PLATFORM_UPHONE_PLATFORM_NSLOCK_H__
namespace cocos2d {
class NSLock
{
public:
NSLock(void);
~NSLock(void);
void lock(void);
void unlock(void);
};
}//namespace cocos2d
#endif // __PLATFORM_UPHONE_PLATFORM_NSLOCK_H__

View File

@ -1,44 +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 "ccxCommon_android.h"
#include <android/log.h>
#include <stdio.h>
#define MAX_LEN 1024
namespace cocos2d{
void CCXLog(const char * pszFormat, ...)
{
char buf[MAX_LEN];
va_list args;
va_start(args, pszFormat);
vsprintf(buf, pszFormat, args);
va_end(args);
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", buf);
}
}//namespace cocos2d

View File

@ -1,55 +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.
****************************************************************************/
#ifndef __CCX_COMMON_UPHONE__
#define __CCX_COMMON_UPHONE__
#if defined(_WIN32)
#if defined(SS_MAKEDLL)
#define CCX_DLL __declspec(dllexport)
#elif defined(SS_IGNORE_EXPORT)
#define CCX_DLL
#else /* use a DLL library */
#define CCX_DLL __declspec(dllimport)
#endif
#else
#if defined(SS_SHARED)
#define CCX_DLL __attribute__((visibility("default")))
#elif defined(SS_IGNORE_EXPORT)
#define CCX_DLL
#else
#define CCX_DLL
#endif
#endif
namespace cocos2d{
/**
@brief Output Debug message to Application console.
*/
void CCX_DLL CCXLog(const char * pszFormat, ...);
}//namespace cocos2d
#endif // end of __CCX_COMMON_UPHONE__

View File

@ -1 +0,0 @@
017fff05a72479d95819cf89ac5cf6125d562960

View File

@ -1 +0,0 @@
362db1d6889070f3a653f3d15e245451a6214625

View File

@ -1 +0,0 @@
63b142a79d20576743534c38d9a35a4efd132b28

View File

@ -1 +0,0 @@
471a64ce0151f2d7c3f384323f8c43a903da39bf

View File

@ -1 +0,0 @@
c52d9a4845ee08c89ce4079d7d3feb2ae96e7178

View File

@ -46,15 +46,4 @@ class NSLock : public ccxLock{};
NS_CC_END;
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_UPHONE)
#elif (CCX_TARGET_PLATFORM == CCX_PLATFORM_WIN32)
#elif (CCX_TARGET_PLATFORM == CCX_PLATFORM_ANDROID)
#include "android/CCTime.h"
#include "android/NSLock.h"
#include "android/CCXBitmapDC.h"
#elif (CCX_TARGET_PLATFORM == CCX_PLATFORM_IOS)
#else
#error
#endif
#endif // __PLATFORM_H__

View File

@ -38,7 +38,8 @@ THE SOFTWARE.
#endif
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_ANDROID)
#error
#include <GLES/gl.h>
#include <GLES/glext.h>
#endif
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_UPHONE)

View File

@ -52,7 +52,7 @@ THE SOFTWARE.
#define isnan _isnan
#endif
#endif
#endif // CCX_TARGET_PLATFORM == CCX_PLATFORM_UPHONE && defined(_TRANZDA_VM_)
#include <math.h>
@ -87,7 +87,7 @@ int CCX_DLL_PS gettimeofday(struct timeval *, struct timezone *);
#endif // CCX_PLATFORM_UPHONE
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_IOS)
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_IOS || CCX_TARGET_PLATFORM == CCX_PLATFORM_ANDROID)
#include <sys/time.h>
@ -99,6 +99,6 @@ int CCX_DLL_PS gettimeofday(struct timeval *, struct timezone *);
#define MAX(x,y) (((x) < (y)) ? (y) : (x))
#endif // MAX
#endif // CCX_PLATFORM_IOS
#endif // CCX_TARGET_PLATFORM == CCX_PLATFORM_IOS || CCX_TARGET_PLATFORM == CCX_PLATFORM_ANDROID
#endif // __CCX_STD_C_H__

View File

@ -0,0 +1,252 @@
/****************************************************************************
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.
****************************************************************************/
// undefine ANDROID to include skia headers
#ifdef ANDROID
#undef ANDROID
#endif
/* used for SkRefCnt::unref(), it used to decrease the count */
static int sk_atomic_dec(int *value)
{
*value = *value - 1;
return *value;
}
#include "SkBitmap.h"
#include "SkPaint.h"
#include "SkScalar.h"
#include "SkCanvas.h"
#include "SkTypeface.h"
NS_CC_BEGIN;
// android not support
void ccxMessageBox(const ccxString& msg, const ccxString& title)
{
}
class BitmapDC
{
public:
BitmapDC()
: m_pBitmap(NULL),
m_pPaint(NULL)
{
}
~BitmapDC(void)
{
CCX_SAFE_DELETE(m_pPaint);
CCX_SAFE_DELETE(m_pBitmap);
}
bool setFont(const char * pFontName = NULL, int nSize = 0)
{
bool bRet = false;
if (m_pPaint)
{
delete m_pPaint;
m_pPaint = NULL;
}
do
{
/* init paint */
m_pPaint = new SkPaint();
CCX_BREAK_IF(! m_pPaint);
m_pPaint->setColor(SK_ColorWHITE);
m_pPaint->setTextSize(nSize);
/* create font */
SkTypeface *pTypeFace = SkTypeface::CreateFromName(pFontName, SkTypeface::kNormal);
if (! pTypeFace)
{
CCX_SAFE_DELETE(m_pPaint);
break;
}
m_pPaint->setTypeface( pTypeFace );
/* can not unref, I don't know why. It may be memory leak, but how to avoid? */
pTypeFace->unref();
bRet = true;
} while (0);
return bRet;
}
bool prepareBitmap(int nWidth, int nHeight)
{
// release bitmap
if (m_pBitmap)
{
delete m_pBitmap;
m_pBitmap = NULL;
}
if (nWidth > 0 && nHeight > 0)
{
/* create and init bitmap */
m_pBitmap = new SkBitmap();
if (! m_pBitmap)
{
return false;
}
/* use rgba8888 and alloc memory */
m_pBitmap->setConfig(SkBitmap::kARGB_8888_Config, nWidth, nHeight);
if (! m_pBitmap->allocPixels())
{
CCX_SAFE_DELETE(m_pBitmap);
return false;
}
/* start with black/transparent pixels */
m_pBitmap->eraseColor(0);
}
return true;
}
bool drawText(const char *pszText, int nWidth, int nHeight, ccxImage::ETextAlign eAlignMask)
{
bool bRet = false;
do
{
CCX_BREAK_IF(! pszText);
CCX_BREAK_IF(! prepareBitmap(nWidth, nHeight));
/* create canvas */
SkPaint::FontMetrics font;
m_pPaint->getFontMetrics(&font);
SkCanvas canvas(*m_pBitmap);
/*
* draw text
* @todo: alignment
*/
canvas.drawText(pszText, strlen(pszText), 0.0, -font.fAscent, *m_pPaint);
bRet = true;
} while (0);
return bRet;
}
bool getTextExtentPoint(const char * pszText, int *pWidth, int *pHeight)
{
bool bRet = false;
do
{
CCX_BREAK_IF(!pszText || !pWidth || !pHeight);
// get text width and height
if (m_pPaint)
{
SkPaint::FontMetrics font;
m_pPaint->getFontMetrics(&font);
*pWidth = (int)ceil((font.fDescent - font.fAscent));
*pHeight = (int)ceil((m_pPaint->measureText(pszText, strlen(pszText))));
bRet = true;
}
} while (0);
return bRet;
}
SkBitmap* getBitmap()
{
return m_pBitmap;
}
private:
SkPaint *m_pPaint;
SkBitmap *m_pBitmap;
};
static BitmapDC& sharedBitmapDC()
{
static BitmapDC s_BmpDC;
return s_BmpDC;
}
bool ccxImage::initWithString(
const char * pText,
int nWidth/* = 0*/,
int nHeight/* = 0*/,
ETextAlign eAlignMask/* = kAlignCenter*/,
const char * pFontName/* = nil*/,
int nSize/* = 0*/)
{
bool bRet = false;
do
{
CCX_BREAK_IF(! pText);
BitmapDC &dc = sharedBitmapDC();
/* init font with font name and size */
CCX_BREAK_IF(! dc.setFont(pFontName, nSize));
/* compute text width and height */
if (nWidth <= 0 || nHeight <= 0)
{
dc.getTextExtentPoint(pText, &nWidth, &nHeight);
}
CCX_BREAK_IF(nWidth <= 0 || nHeight <= 0);
bRet = dc.drawText(pText, nWidth, nHeight, eAlignMask);
/*init image information */
SkBitmap *pBitmap = dc.getBitmap();
CCX_BREAK_IF(! pBitmap);
int nWidth = pBitmap->width();
int nHeight = pBitmap->height();
CCX_BREAK_IF(nWidth <= 0 || nHeight <= 0);
int nDataLen = pBitmap->rowBytes() * pBitmap->height();
m_pData.reset(new ccxByte[nDataLen]);
CCX_BREAK_IF(! m_pData.get());
memcpy((void*) m_pData.get(), pBitmap->getPixels(), nDataLen);
m_nWidth = (ccxInt16)nWidth;
m_nHeight = (ccxInt16)nHeight;
m_bHasAlpha = true;
m_bPreMulti = true;
m_nBitsPerComponent = pBitmap->bytesPerPixel();
bRet = true;
} while (0);
return bRet;
}
NS_CC_END;

View File

@ -21,25 +21,59 @@ 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 "NSLock.h"
namespace cocos2d {
NSLock::NSLock(void)
#if CCX_SUPPORT_MULTITHREAD
#include <semaphore.h>
#include "ccxThread.h"
NS_CC_BEGIN;
class CCXLock::Impl
{
public:
Impl()
{
sem_init(&m_sMutex, 0, 0);
}
~Impl()
{
sem_destroy(&m_sMutex);
}
sem_t m_sMutex;
};
CCXLock::CCXLock()
: m_pImp(new CCXLock::Impl)
{
}
NSLock::~NSLock(void)
CCXLock::~CCXLock()
{
if (m_pImp)
{
delete m_pImp;
}
}
void NSLock::lock(void)
void CCXLock::lock()
{
if (m_pImp)
{
sem_wait(&m_pImp->m_sMutex);
}
}
void NSLock::unlock(void)
void CCXLock::unlock()
{
if (m_pImp)
{
sem_post(&m_pImp->m_sMutex);
}
}
}//namespace cocos2d
NS_CC_END;
#endif // CCX_SUPPORT_MULTITHREAD

View File

@ -24,13 +24,16 @@ THE SOFTWARE.
#include "ccxCommon.h"
#define MAX_LEN (cocos2d::kMaxLogLen + 1)
/****************************************************
* win32
***************************************************/
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_WIN32)
#include <Windows.h>
#include "ccxStdC.h"
#define MAX_LEN (cocos2d::kMaxLogLen + 1)
NS_CC_BEGIN;
void CCXLog(const char * pszFormat, ...)
@ -49,10 +52,12 @@ NS_CC_END;
#endif // CCX_PLATFORM_WIN32
/****************************************************
* uphone
***************************************************/
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_UPHONE)
#include "TG3.h"
#define MAX_LEN 256
#define LOG_FILE_PATH "/NEWPLUS/TDA_DATA/UserData/Cocos2dLog.txt"
NS_CC_BEGIN;
@ -90,8 +95,12 @@ void CCXLog(const char * pszFormat, ...)
}
NS_CC_END;
#endif // CCX_PLATFORM_UPHONE
/****************************************************
* ios
***************************************************/
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_IOS)
NS_CC_BEGIN;
@ -104,3 +113,30 @@ void CCXLog(const char * pszFormat, ...)
NS_CC_END;
#endif // CCX_PLATFORM_IOS
/****************************************************
* android
***************************************************/
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_ANDROID)
#include <android/log.h>
#include <stdio.h>
NS_CC_BEGIN;
void CCXLog(const char * pszFormat, ...)
{
char buf[MAX_LEN];
va_list args;
va_start(args, pszFormat);
vsprintf(buf, pszFormat, args);
va_end(args);
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", buf);
}
NS_CC_END;
#endif // CCX_PLATFORM_ANDROID

View File

@ -331,3 +331,7 @@ NS_CC_END;
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_UPHONE)
#include "uphone/ccxImage_uphone.cpp"
#endif
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_ANDROID)
#include "android/ccxImage_android.cpp"
#endif

View File

@ -28,10 +28,14 @@ THE SOFTWARE.
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_WIN32)
#include "win32/ccxThread_win32.cpp"
#endif
#endif // CCX_PLATFORM_WIN32
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_UPHONE)
#include "uphone/ccxThread_uphone.cpp"
#endif
#endif // CCX_PLATFORM_UPHONE
#if (CCX_TARGET_PLATFORM == CCX_PLATFORM_ANDROID)
#include "android/ccxThread_android.cpp"
#endif // CCX_PLATFORM_ANDROID
#endif // CCX_SUPPORT_MULTITHREAD

View File

@ -46,6 +46,10 @@ CCXLock::CCXLock()
CCXLock::~CCXLock()
{
if (m_pImp)
{
delete m_pImp;
}
}
void CCXLock::lock()

Some files were not shown because too many files have changed in this diff Show More