Merge pull request #865 from dumganhar/iss1177_platform

fixed #1177: Refactor platform.
1. Added some common methods for CCPoint,CCSize,CCRect.
2. Added MutiTouchTest demo.
3. Added CCEGLViewProtocol and CCApplicationProtocol. Make them more convenient for porting cocos2d-x to a new platform.
This commit is contained in:
James Chen 2012-04-24 03:09:43 -07:00
commit ff38eda2fe
47 changed files with 1033 additions and 865 deletions

View File

@ -1,6 +1,6 @@
# set params
NDK_ROOT_LOCAL=/cygdrive/d/programe/android/ndk/android-ndk-r6b
COCOS2DX_ROOT_LOCAL=/cygdrive/e/cocos2d-x
NDK_ROOT_LOCAL=/cygdrive/e/android/android-ndk-r7b
COCOS2DX_ROOT_LOCAL=/cygdrive/f/Project/dumganhar/cocos2d-x
# try to get global variable
if [ $NDK_ROOT"aaa" != "aaa" ]; then
@ -14,7 +14,7 @@ if [ $COCOS2DX_ROOT"aaa" != "aaa" ]; then
fi
GAME_ROOT=$COCOS2DX_ROOT_LOCAL/HelloLua
GAME_ANDROID_ROOT=$GAME_ROOT/android
GAME_ANDROID_ROOT=$GAME_ROOT/proj.android
GAME_RESOURCE_ROOT=$GAME_ROOT/Resources
# make sure assets is exist

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
<true/>
</dict>
</plist>

View File

@ -25,6 +25,9 @@ bool AppDelegate::initInstance() {
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
//pMainWnd->setDesignResolutionSize(480, 320);
#endif // CC_PLATFORM_WIN32
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

View File

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

View File

@ -25,10 +25,10 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
{
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
{
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
view->setFrameWidthAndHeight(w, h);
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h);
// if you want to run in WVGA with HVGA resource, set it
// view->create(480, 320); Please change it to (320, 480) if you're in portrait mode.
// view->setDesignResolutionSize(480, 320); Please change it to (320, 480) if you're in portrait mode.
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
AppDelegate *pAppDelegate = new AppDelegate();

View File

@ -1 +1 @@
8241040b5b40344918b886a37a17003c74c0b3f0
97caf44d91d679d65cd39a8dfc4378df7694d735

View File

@ -61,7 +61,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libcocos2d.lib"
AdditionalDependencies="libcocos2d.lib libGLESv2.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir)"

View File

@ -12,10 +12,25 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liblua", "lua\proj.win32\liblua.vcproj", "{DDC3E27F-004D-4DD4-9DD3-931A013D2159}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloLua", "HelloLua\proj.win32\HelloLua.win32.vcproj", "{13E55395-94A2-4CD9-BFC2-1A051F80C17D}"
ProjectSection(ProjectDependencies) = postProject
{DDC3E27F-004D-4DD4-9DD3-931A013D2159} = {DDC3E27F-004D-4DD4-9DD3-931A013D2159}
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloWorld", "HelloWorld\proj.win32\HelloWorld.win32.vcproj", "{B8BF9E81-35FD-4582-BA1C-B85FA365BABB}"
ProjectSection(ProjectDependencies) = postProject
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests\proj.win32\test.win32.vcproj", "{76A39BB2-9B84-4C65-98A5-654D86B86F2A}"
ProjectSection(ProjectDependencies) = postProject
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
{207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}
{929480E7-23C0-4DF6-8456-096D71547116} = {929480E7-23C0-4DF6-8456-096D71547116}
{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
EndProjectSection
EndProject
Global
GlobalSection(DPCodeReviewSolutionGUID) = preSolution

View File

@ -92,6 +92,7 @@ platform/CCSAXParser.cpp \
platform/CCThread.cpp \
platform/CCCommon.cpp \
platform/platform.cpp \
platform/CCEGLViewProtocol.cpp \
platform/android/CCEGLView_android.cpp \
platform/android/CCAccelerometer_android.cpp \
platform/android/CCApplication_android.cpp \

View File

@ -73,15 +73,14 @@ bool CCConfiguration::init(void)
CCLOG("cocos2d: GL supports NPOT textures: %s", (m_bSupportsNPOT ? "YES" : "NO"));
CCLOG("cocos2d: GL supports discard_framebuffer: %s", (m_bSupportsDiscardFramebuffer ? "YES" : "NO"));
CCLOG("cocos2d: compiled with Profiling Support: %s",
bool bEnableProfilers = false;
#if CC_ENABLE_PROFILERS
"YES - *** Disable it when you finish profiling ***"
#else
"NO"
bEnableProfilers = true;
#endif
);
CCLOG("cocos2d: compiled with Profiling Support: %s",
bEnableProfilers ? "YES - *** Disable it when you finish profiling ***" : "NO");
#if CC_ENABLE_GL_STATE_CACHE == 0
CCLOG("");

View File

@ -45,7 +45,6 @@ THE SOFTWARE.
#include "CCConfiguration.h"
#include "CCKeypadDispatcher.h"
#include "CCAccelerometer.h"
#include "CCGL.h"
#include "CCAnimationCache.h"
#include "CCTouch.h"
#include "CCUserDefault.h"
@ -55,7 +54,7 @@ THE SOFTWARE.
#include "kazmath/kazmath.h"
#include "kazmath/GL/matrix.h"
#include "support/CCProfiling.h"
#include "CCEGLView.h"
#include <string>
using namespace std;
@ -331,12 +330,18 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
CCSize size = m_obWinSizeInPixels;
CCSize sizePoint = m_obWinSizeInPoints;
glViewport(0, 0, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
//glViewport(0, 0, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
if (m_pobOpenGLView)
{
m_pobOpenGLView->setViewPortInPoints(0, 0, size.width, size.height);
}
switch (kProjection)
{
case kCCDirectorProjection2D:
{
kmGLMatrixMode(KM_GL_PROJECTION);
kmGLLoadIdentity();
kmMat4 orthoMatrix;
@ -349,11 +354,12 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
case kCCDirectorProjection3D:
{
// reset the viewport if 3d proj & retina display
if( CC_CONTENT_SCALE_FACTOR() != 1 )
{
glViewport(-size.width/2, -size.height/2, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
// reset the viewport if 3d proj & retina display
if( CC_CONTENT_SCALE_FACTOR() != 1.0f )
{
glViewport(-size.width/2, -size.height/2, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
}
float zeye = this->getZEye();
kmMat4 matrixPerspective, matrixLookup;
@ -362,7 +368,15 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
kmGLLoadIdentity();
// issue #1334
kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, zeye*2);
if (m_pobOpenGLView && m_pobOpenGLView->isIpad() && m_pobOpenGLView->getMainScreenScale() > 1.0f)
{
kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, zeye-size.height/2, zeye+size.height/2);
}
else
{
kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.5f, 1500);
}
// kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, 1500);
kmGLMultMatrix(&matrixPerspective);
@ -370,8 +384,8 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
kmGLLoadIdentity();
kmVec3 eye, center, up;
kmVec3Fill( &eye, sizePoint.width/2, sizePoint.height/2, zeye );
kmVec3Fill( &center, sizePoint.width/2, sizePoint.height/2, 0 );
kmVec3Fill( &up, 0, 1, 0);
kmVec3Fill( &center, sizePoint.width/2, sizePoint.height/2, 0.0f );
kmVec3Fill( &up, 0.0f, 1.0f, 0.0f);
kmMat4LookAt(&matrixLookup, &eye, &center, &up);
kmGLMultMatrix(&matrixLookup);
}
@ -464,11 +478,15 @@ CCSize CCDirector::getWinSizeInPixels()
void CCDirector::reshapeProjection(const CCSize& newWindowSize)
{
CC_UNUSED_PARAM(newWindowSize);
m_obWinSizeInPoints = m_pobOpenGLView->getSize();
m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor,
if (m_pobOpenGLView)
{
m_obWinSizeInPoints = m_pobOpenGLView->getSize();
m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor,
m_obWinSizeInPoints.height * m_fContentScaleFactor);
setProjection(m_eProjection);
}
setProjection(m_eProjection);
}
// scene management
@ -574,7 +592,7 @@ void CCDirector::purgeDirector()
CHECK_GL_ERROR_DEBUG();
// OpenGL view
m_pobOpenGLView->release();
m_pobOpenGLView->end();
m_pobOpenGLView = NULL;
}

View File

@ -23,17 +23,33 @@ THE SOFTWARE.
****************************************************************************/
#include "CCGeometry.h"
#include "ccMacros.h"
// implementation of CCPoint
NS_CC_BEGIN
CCPoint::CCPoint(void)
{
x = 0;
y = 0;
setPoint(0.0f, 0.0f);
}
CCPoint::CCPoint(float x, float y)
{
setPoint(x, y);
}
CCPoint::CCPoint(const CCPoint& other)
{
setPoint(other.x, other.y);
}
CCPoint& CCPoint::operator= (const CCPoint& other)
{
setPoint(other.x, other.y);
return *this;
}
void CCPoint::setPoint(float x, float y)
{
this->x = x;
this->y = y;
@ -48,11 +64,26 @@ bool CCPoint::CCPointEqualToPoint(const CCPoint& point1, const CCPoint& point2)
CCSize::CCSize(void)
{
width = 0;
height = 0;
setSize(0.0f, 0.0f);
}
CCSize::CCSize(float width, float height)
{
setSize(width, height);
}
CCSize::CCSize(const CCSize& other)
{
setSize(other.width, other.height);
}
CCSize& CCSize::operator= (const CCSize& other)
{
setSize(other.width, other.height);
return *this;
}
void CCSize::setSize(float width, float height)
{
this->width = width;
this->height = height;
@ -67,17 +98,29 @@ bool CCSize::CCSizeEqualToSize(const CCSize& size1, const CCSize& size2)
CCRect::CCRect(void)
{
origin.x = 0;
origin.y = 0;
size.width = 0;
size.height = 0;
setRect(0.0f, 0.0f, 0.0f, 0.0f);
}
CCRect::CCRect(float x, float y, float width, float height)
{
setRect(x, y, width, height);
}
CCRect::CCRect(const CCRect& other)
{
setRect(other.origin.x, other.origin.y, other.size.width, other.size.height);
}
CCRect& CCRect::operator= (const CCRect& other)
{
setRect(other.origin.x, other.origin.y, other.size.width, other.size.height);
return *this;
}
void CCRect::setRect(float x, float y, float width, float height)
{
// Only support that, the width and height > 0
CC_ASSERT(width >= 0 && height >= 0);
CCAssert(width >= 0.0f && height >= 0.0f, "width and height of Rect must not less than 0.");
origin.x = x;
origin.y = y;

View File

@ -27,13 +27,11 @@ THE SOFTWARE.
#ifndef __CCDIRECTOR_H__
#define __CCDIRECTOR_H__
#include "platform/CCPlatformMacros.h"
#include "CCPlatformMacros.h"
#include "CCObject.h"
#include "ccTypes.h"
#include "CCGeometry.h"
#include "CCArray.h"
#include "CCGeometry.h"
#include "CCEGLView.h"
#include "CCGL.h"
#include "kazmath/mat4.h"

View File

@ -38,10 +38,11 @@ public:
float y;
public:
CCPoint();
CCPoint(float x, float y);
CCPoint(const CCPoint& other);
CCPoint& operator= (const CCPoint& other);
void setPoint(float x, float y);
public:
static bool CCPointEqualToPoint(const CCPoint& point1, const CCPoint& point2);
};
@ -55,7 +56,9 @@ public:
public:
CCSize();
CCSize(float width, float height);
CCSize(const CCSize& other);
CCSize& operator= (const CCSize& other);
void setSize(float width, float height);
public:
static bool CCSizeEqualToSize(const CCSize& size1, const CCSize& size2);
};
@ -69,7 +72,9 @@ public:
public:
CCRect();
CCRect(float x, float y, float width, float height);
CCRect(const CCRect& other);
CCRect& operator= (const CCRect& other);
void setRect(float x, float y, float width, float height);
public:
//! return the leftmost x-value of 'rect'
static CCFloat CCRectGetMinX(const CCRect& rect);

View File

@ -9,8 +9,17 @@ class CC_DLL CCInteger : public CCObject
{
public:
CCInteger(int v)
: value(v) {}
int value;
: m_nValue(v) {}
int getValue() const {return m_nValue;}
static CCInteger* integerWithInt(int v)
{
CCInteger* pRet = new CCInteger(v);
pRet->autorelease();
return pRet;
}
private:
int m_nValue;
};
NS_CC_END

View File

@ -33,22 +33,30 @@ NS_CC_BEGIN
class CCTouch : public CCObject
{
public:
CCTouch() {}
CCTouch(float x, float y) : m_point(x, y), m_prevPoint(x, y) {}
CCTouch()
: m_nId(0)
{}
CCPoint locationInView() { return m_point; }
CCPoint previousLocationInView() { return m_prevPoint; }
void SetTouchInfo(float x, float y)
void SetTouchInfo(int id, float x, float y)
{
m_nId = id;
m_prevPoint = m_point;
m_point.x = x;
m_point.y = y;
}
int getID() const
{
return m_nId;
}
private:
int m_nId;
CCPoint m_point;
CCPoint m_prevPoint;
CCPoint m_prevPoint;
};
class CCEvent : public CCObject

View File

@ -123,12 +123,6 @@ bool CCMenu::initWithArray(CCArray* pArrayOfItems)
setAnchorPoint(ccp(0.5f, 0.5f));
this->setContentSize(s);
// XXX: in v0.7, winSize should return the visible size
// XXX: so the bar calculation should be done there
CCRect r;
CCApplication::sharedApplication().statusBarFrame(&r);
s.height -= r.size.height;
setPosition(ccp(s.width/2, s.height/2));
if (pArrayOfItems != NULL)

View File

@ -222,7 +222,7 @@ void CCRenderTexture::end(bool bIsTOCacheTexture)
glViewport((GLsizei)(-size.width/2), (GLsizei)(-size.height/2), (GLsizei)(size.width * CC_CONTENT_SCALE_FACTOR()), (GLsizei)(size.height * CC_CONTENT_SCALE_FACTOR()));
}
//TODO: Does this line take effect? director->setProjection(director->getProjection());
director->setProjection(director->getProjection());
#if CC_ENABLE_CACHE_TEXTTURE_DATA
if (bIsTOCacheTexture)

View File

@ -0,0 +1,56 @@
#ifndef __CC_APPLICATION_PROTOCOL_H__
#define __CC_APPLICATION_PROTOCOL_H__
#include "ccTypes.h"
NS_CC_BEGIN
class CCRect;
class CC_DLL CCApplicationProtocol
{
public:
virtual ~CCApplicationProtocol() {}
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance() = 0;
/**
@brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching() = 0;
/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground() = 0;
/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground() = 0;
/**
@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) = 0;
/**
@brief Get current language config
@return Current language config
*/
virtual ccLanguageType getCurrentLanguage() = 0;
};
NS_CC_END
#endif // __CC_APPLICATION_PROTOCOL_H__

View File

@ -0,0 +1,339 @@
#include "CCEGLViewProtocol.h"
#include "CCTouchDispatcher.h"
#include "CCDirector.h"
#include "CCSet.h"
#include "CCTouch.h"
#include "CCDictionary.h"
#include "CCInteger.h"
NS_CC_BEGIN
static CCTouch* s_pTouches[CC_MAX_TOUCHES] = { NULL };
static unsigned int s_indexBitsUsed = 0;
static CCDictionary s_TouchesIntergerDict;
static int getUnUsedIndex()
{
int i;
int temp = s_indexBitsUsed;
for (i = 0; i < CC_MAX_TOUCHES; i++) {
if (! (temp & 0x00000001)) {
s_indexBitsUsed |= (1 << i);
return i;
}
temp >>= 1;
}
// all bits are used
return -1;
}
static void removeUsedIndexBit(int index)
{
if (index < 0 || index >= CC_MAX_TOUCHES)
{
return;
}
unsigned int temp = 1 << index;
temp = ~temp;
s_indexBitsUsed &= temp;
}
CCEGLViewProtocol::CCEGLViewProtocol()
: m_bNeedScale(false)
, m_pDelegate(NULL)
, m_fScreenScaleFactor(1.0f)
{
}
CCEGLViewProtocol::~CCEGLViewProtocol()
{
}
bool CCEGLViewProtocol::isIpad()
{
return false;
}
void CCEGLViewProtocol::setFrameSize(float width, float height)
{
m_sSizeInPixel.setSize(width, height);
m_rcViewPort.size.setSize(width, height);
}
void CCEGLViewProtocol::setDesignResolutionSize(float width, float height)
{
if (width == 0.0f || height == 0.0f)
{
return;
}
m_sSizeInPoint.setSize(width, height);
// calculate the factor and the rect of viewport
m_fScreenScaleFactor = MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width,
(float)m_sSizeInPixel.height / m_sSizeInPoint.height);
int viewPortW = (int)(m_sSizeInPoint.width * m_fScreenScaleFactor);
int viewPortH = (int)(m_sSizeInPoint.height * m_fScreenScaleFactor);
m_rcViewPort.origin.x = (m_sSizeInPixel.width - viewPortW) / 2;
m_rcViewPort.origin.y = (m_sSizeInPixel.height - viewPortH) / 2;
m_rcViewPort.size.width = viewPortW;
m_rcViewPort.size.height = viewPortH;
CCLOG("m_fScreenScaleFactor = %f", m_fScreenScaleFactor);
m_bNeedScale = true;
}
CCSize CCEGLViewProtocol::getSize()
{
CCSize size;
if (m_bNeedScale)
{
size.setSize(m_sSizeInPoint.width, m_sSizeInPoint.height);
}
else
{
size.setSize(m_sSizeInPixel.width, m_sSizeInPixel.height);
}
return size;
}
CCRect CCEGLViewProtocol::getViewPort()
{
return m_rcViewPort;
}
void CCEGLViewProtocol::setTouchDelegate(EGLTouchDelegate * pDelegate)
{
m_pDelegate = pDelegate;
}
float CCEGLViewProtocol::getScreenScaleFactor()
{
return m_fScreenScaleFactor;
}
bool CCEGLViewProtocol::canSetContentScaleFactor()
{
return false;
}
void CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor)
{
m_fScreenScaleFactor = contentScaleFactor;
}
void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h)
{
if (m_bNeedScale)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
(GLint)(y * factor) + m_rcViewPort.origin.y,
(GLsizei)(w * factor),
(GLsizei)(h * factor));
}
else
{
glViewport((GLint)x,
(GLint)y,
(GLsizei)w,
(GLsizei)h);
}
}
void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h)
{
if (m_bNeedScale)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
(GLint)(y * factor) + m_rcViewPort.origin.y,
(GLsizei)(w * factor),
(GLsizei)(h * factor));
}
else
{
glScissor((GLint)x,
(GLint)y,
(GLsizei)w,
(GLsizei)h);
}
}
float CCEGLViewProtocol::getMainScreenScale()
{
return -1.0f;
}
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
{
CCSet set;
for (int i = 0; i < num; ++i)
{
int id = ids[i];
float x = xs[i];
float y = ys[i];
CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id);
int nUnusedIndex = 0;
// it is a new touch
if (pIndex == NULL)
{
nUnusedIndex = getUnUsedIndex();
// The touches is more than MAX_TOUCHES ?
if (nUnusedIndex == -1) {
CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex);
return;
}
CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch();
if (m_bNeedScale)
{
pTouch->SetTouchInfo(nUnusedIndex, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
}
else
{
pTouch->SetTouchInfo(nUnusedIndex, x, y);
}
CCInteger* pInterObj = new CCInteger(nUnusedIndex);
s_TouchesIntergerDict.setObject(pInterObj, id);
set.addObject(pTouch);
pInterObj->release();
}
}
if (set.count() == 0)
{
CCLOG("touchesBegan: count = 0");
return;
}
m_pDelegate->touchesBegan(&set, NULL);
}
void CCEGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float ys[])
{
CCSet set;
for (int i = 0; i < num; ++i)
{
int id = ids[i];
float x = xs[i];
float y = ys[i];
CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id);
if (pIndex == NULL) {
CCLOG("if the index doesn't exist, it is an error");
return;
}
CCLOG("Moving touches with id: %d, x=%f, y=%f", id, x, y);
CCTouch* pTouch = s_pTouches[pIndex->getValue()];
if (pTouch)
{
if (m_bNeedScale)
{
pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
}
else
{
pTouch->SetTouchInfo(pIndex->getValue(), x, y);
}
set.addObject(pTouch);
}
else
{
// It is error, should return.
CCLOG("Moving touches with id: %d error", id);
return;
}
}
if (set.count() == 0)
{
CCLOG("touchesMoved: count = 0");
return;
}
m_pDelegate->touchesMoved(&set, NULL);
}
void CCEGLViewProtocol::getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[])
{
for (int i = 0; i < num; ++i)
{
int id = ids[i];
float x = xs[i];
float y = ys[i];
CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id);
if (pIndex == NULL)
{
CCLOG("if the index doesn't exist, it is an error");
return;
}
/* Add to the set to send to the director */
CCTouch* pTouch = s_pTouches[pIndex->getValue()];
if (pTouch)
{
CCLOG("Ending touches with id: %d, x=%f, y=%f", id, x, y);
if (m_bNeedScale)
{
pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
}
else
{
pTouch->SetTouchInfo(pIndex->getValue(), x, y);
}
set.addObject(pTouch);
// release the object
pTouch->release();
s_pTouches[pIndex->getValue()] = NULL;
removeUsedIndexBit(pIndex->getValue());
s_TouchesIntergerDict.removeObjectForKey(id);
}
else
{
CCLOG("Ending touches with id: %d error", id);
return;
}
}
if (set.count() == 0)
{
CCLOG("touchesEnded or touchesCancel: count = 0");
return;
}
}
void CCEGLViewProtocol::handleTouchesEnd(int num, int ids[], float xs[], float ys[])
{
CCSet set;
getSetOfTouchesEndOrCancel(set, num, ids, xs, ys);
m_pDelegate->touchesEnded(&set, NULL);
}
void CCEGLViewProtocol::handleTouchesCancel(int num, int ids[], float xs[], float ys[])
{
CCSet set;
getSetOfTouchesEndOrCancel(set, num, ids, xs, ys);
m_pDelegate->touchesCancelled(&set, NULL);
}
NS_CC_END

View File

@ -0,0 +1,56 @@
#ifndef __CCEGLVIEWPROTOCOL_H__
#define __CCEGLVIEWPROTOCOL_H__
#include "ccTypes.h"
NS_CC_BEGIN
#define CC_MAX_TOUCHES 5
class EGLTouchDelegate;
class CCSet;
class CC_DLL CCEGLViewProtocol
{
public:
CCEGLViewProtocol();
virtual ~CCEGLViewProtocol();
virtual void end() = 0;
virtual bool isOpenGLReady() = 0;
virtual void swapBuffers() = 0;
virtual void setIMEKeyboardState(bool bOpen) = 0;
virtual bool isIpad();
virtual CCRect getViewPort();
virtual CCSize getSize();
virtual void setFrameSize(float width, float height);
virtual void setDesignResolutionSize(float width, float height);
virtual void setTouchDelegate(EGLTouchDelegate * pDelegate);
virtual float getScreenScaleFactor();
virtual bool canSetContentScaleFactor();
virtual void setContentScaleFactor(float contentScaleFactor);
virtual void setViewPortInPoints(float x , float y , float w , float h);
virtual void setScissorInPoints(float x , float y , float w , float h);
virtual float getMainScreenScale();
/** handle touch events by default, if you want to custom your handles, please override these functions */
virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]);
virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]);
virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]);
virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]);
private:
void getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]);
protected:
bool m_bNeedScale;
EGLTouchDelegate* m_pDelegate;
float m_fScreenScaleFactor;
CCSize m_sSizeInPixel;
CCSize m_sSizeInPoint;
CCRect m_rcViewPort;
};
NS_CC_END
#endif /* __CCEGLVIEWPROTOCOL_H__ */

View File

@ -29,10 +29,9 @@ THE SOFTWARE.
// Common layer for OpenGL stuff
//
#include "CCEGLView.h"
#define CC_GLVIEW cocos2d::CCEGLView
#define glClearDepth glClearDepthf
#define glClearDepth glClearDepthf
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define glGenVertexArrays glGenVertexArraysOES
#define glBindVertexArray glBindVertexArrayOES

View File

@ -58,14 +58,14 @@ CCApplication::Orientation CCApplication::setOrientation(Orientation orientation
return orientation;
}
void CCApplication::statusBarFrame(CCRect * rect)
{
if (rect)
{
// android doesn't have status bar.
*rect = CCRectMake(0, 0, 0, 0);
}
}
//void CCApplication::statusBarFrame(CCRect * rect)
//{
// if (rect)
// {
// // android doesn't have status bar.
// *rect = CCRectMake(0, 0, 0, 0);
// }
//}
//////////////////////////////////////////////////////////////////////////
// static member function

View File

@ -2,43 +2,19 @@
#define __CC_APPLICATION_ANDROID_H__
#include "CCApplication.h"
#include "CCCommon.h"
#include "CCApplicationProtocol.h"
NS_CC_BEGIN
class CCRect;
class CC_DLL CCApplication
class CC_DLL CCApplication : public CCApplicationProtocol
{
public:
CCApplication();
virtual ~CCApplication();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance() = 0;
/**
@brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching() = 0;
/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground() = 0;
/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground() = 0;
/**
@brief Callback by CCDirector for limit FPS.
@interval The time, which expressed in second in second, between current frame and next.
@ -64,11 +40,6 @@ public:
*/
Orientation setOrientation(Orientation orientation);
/**
@brief Get status bar rectangle in EGLView window.
*/
void statusBarFrame(CCRect * rect);
/**
@brief Run the message loop.
*/
@ -84,7 +55,7 @@ public:
@brief Get current language config
@return Current language config
*/
static ccLanguageType getCurrentLanguage();
virtual ccLanguageType getCurrentLanguage();
protected:
static CCApplication * sm_pSharedApplication;
@ -92,4 +63,4 @@ protected:
NS_CC_END
#endif // __CCX_APPLICATION_ANDROID_H__
#endif // __CC_APPLICATION_ANDROID_H__

View File

@ -48,165 +48,35 @@ void initExtensions() {
NS_CC_BEGIN
CCEGLView::CCEGLView()
: m_bNotHVGA(false),
m_pDelegate(NULL),
m_fScreenScaleFactor(1.0)
{
initExtensions();
}
void CCEGLView::setFrameWidthAndHeight(int width, int height)
{
m_sSizeInPixel.width = width;
m_sSizeInPixel.height = height;
}
bool CCEGLView::isIpad()
{
return false;
}
void CCEGLView::create(int width, int height)
{
if (width == 0 || height == 0)
{
return;
}
m_sSizeInPoint.width = width;
m_sSizeInPoint.height = height;
// calculate the factor and the rect of viewport
m_fScreenScaleFactor = MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width,
(float)m_sSizeInPixel.height / m_sSizeInPoint.height);
int viewPortW = (int)(m_sSizeInPoint.width * m_fScreenScaleFactor);
int viewPortH = (int)(m_sSizeInPoint.height * m_fScreenScaleFactor);
m_rcViewPort.origin.x = (m_sSizeInPixel.width - viewPortW) / 2;
m_rcViewPort.origin.y = (m_sSizeInPixel.height - viewPortH) / 2;
m_rcViewPort.size.width = viewPortW;
m_rcViewPort.size.height = viewPortH;
m_bNotHVGA = true;
}
CCEGLView::~CCEGLView()
{
}
CCSize CCEGLView::getSize()
{
if (m_bNotHVGA)
{
CCSize size(m_sSizeInPoint.width, m_sSizeInPoint.height);
return size;
}
else
{
CCSize size(m_sSizeInPixel.width, m_sSizeInPixel.height);
return size;
}
}
bool CCEGLView::isOpenGLReady()
{
return (m_sSizeInPixel.width != 0 && m_sSizeInPixel.height != 0);
}
void CCEGLView::release()
void CCEGLView::end()
{
terminateProcessJNI();
}
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
{
m_pDelegate = pDelegate;
}
EGLTouchDelegate* CCEGLView::getDelegate(void)
{
return m_pDelegate;
}
void CCEGLView::swapBuffers()
{
}
bool CCEGLView::canSetContentScaleFactor()
{
// can scale content?
return false;
}
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
{
m_fScreenScaleFactor = contentScaleFactor;
}
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
{
if (m_bNotHVGA)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
(GLint)(y * factor) + m_rcViewPort.origin.y,
(GLint)(w * factor),
(GLint)(h * factor));
}
else
{
glViewport((GLint)x,
(GLint)y,
(GLint)w,
(GLint)h);
}
}
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
{
if (m_bNotHVGA)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
(GLint)(y * factor) + m_rcViewPort.origin.y,
(GLint)(w * factor),
(GLint)(h * factor));
}
else
{
glScissor((GLint)x,
(GLint)y,
(GLint)w,
(GLint)h);
}
}
CCEGLView& CCEGLView::sharedOpenGLView()
{
static CCEGLView instance;
return instance;
}
float CCEGLView::getScreenScaleFactor()
{
return m_fScreenScaleFactor;
}
CCRect CCEGLView::getViewPort()
{
if (m_bNotHVGA)
{
return m_rcViewPort;
}
else
{
CCRect rect(0, 0, 0, 0);
return rect;
}
}
void CCEGLView::setIMEKeyboardState(bool bOpen)
{

View File

@ -26,62 +26,30 @@ THE SOFTWARE.
#define __CC_EGLVIEW_ANDROID_H__
#include "CCGeometry.h"
#include "CCEGLViewProtocol.h"
namespace cocos2d {
class CCSet;
class CCTouch;
class EGLTouchDelegate;
NS_CC_BEGIN
class CC_DLL CCEGLView
class CC_DLL CCEGLView : public CCEGLViewProtocol
{
public:
CCEGLView();
virtual ~CCEGLView();
CCSize getSize();
bool isOpenGLReady();
bool isIpad();
/**
* the width and height is the real size of phone
*/
void setFrameWidthAndHeight(int width, int height);
/**
* create a drawing rect,
* the width and heiht is the resource size match best
*/
void create(int width, int height);
EGLTouchDelegate* getDelegate(void);
// keep compatible
void release();
void setTouchDelegate(EGLTouchDelegate * pDelegate);
void end();
void swapBuffers();
bool canSetContentScaleFactor();
void setContentScaleFactor(float contentScaleFactor);
void setViewPortInPoints(float x, float y, float w, float h);
void setScissorInPoints(float x, float y, float w, float h);
CCRect getViewPort();
float getScreenScaleFactor();
void setIMEKeyboardState(bool bOpen);
float getMainScreenScale() { return -1.0f; }
// static function
/**
@brief get the shared main open gl window
*/
static CCEGLView& sharedOpenGLView();
private:
CCSize m_sSizeInPixel;
CCSize m_sSizeInPoint;
CCRect m_rcViewPort;
bool m_bNotHVGA;
EGLTouchDelegate *m_pDelegate;
float m_fScreenScaleFactor;
};
} // end of namespace cocos2d
NS_CC_END
#endif // end of __CC_EGLVIEW_ANDROID_H__

View File

@ -43,143 +43,67 @@ 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)
{
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesBegin(1, &id, &x, &y);
}
// 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;
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd(JNIEnv* env, jobject thiz, jint id, jfloat x, jfloat y)
{
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesEnd(1, &id, &x, &y);
}
CCTouch *pTouch = s_pTouches[id];
if (! pTouch)
{
LOGD("Beginning touches with id: %d, x=%f, y=%f", id, x, y);
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];
pTouch = new CCTouch();
pTouch->SetTouchInfo((x - rcRect.origin.x) / fScreenScaleFactor, (y - rcRect.origin.y) / fScreenScaleFactor);
s_pTouches[id] = pTouch;
set.addObject(pTouch);
env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, x);
env->GetFloatArrayRegion(ys, 0, size, y);
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;
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesMove(size, id, x, y);
}
/* 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);
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];
pTouch->SetTouchInfo((x - rcRect.origin.x) / fScreenScaleFactor , (y - rcRect.origin.y) / fScreenScaleFactor);
set.addObject(pTouch);
env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, x);
env->GetFloatArrayRegion(ys, 0, size, y);
// 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((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((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);
}
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesCancel(size, id, x, y);
}
#define KEYCODE_BACK 0x04
#define KEYCODE_MENU 0x52
// handle keydown event
// handle keydown event
jboolean Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyDown(JNIEnv* env, jobject thiz, jint keyCode)
jboolean Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyDown(JNIEnv* env, jobject thiz, jint keyCode)
{
CCDirector* pDirector = CCDirector::sharedDirector();
switch (keyCode)
{
CCDirector* pDirector = CCDirector::sharedDirector();
switch (keyCode)
{
case KEYCODE_BACK:
if (pDirector->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked))
return JNI_TRUE;
break;
case KEYCODE_MENU:
if (pDirector->getKeypadDispatcher()->dispatchKeypadMSG(kTypeMenuClicked))
return JNI_TRUE;
break;
default:
return JNI_FALSE;
}
case KEYCODE_BACK:
if (pDirector->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked))
return JNI_TRUE;
break;
case KEYCODE_MENU:
if (pDirector->getKeypadDispatcher()->dispatchKeypadMSG(kTypeMenuClicked))
return JNI_TRUE;
break;
default:
return JNI_FALSE;
}
return JNI_FALSE;
}
}

View File

@ -26,41 +26,18 @@ THE SOFTWARE.
#define __CC_APPLICATION_IOS_H__
#include "CCCommon.h"
#include "CCApplicationProtocol.h"
NS_CC_BEGIN
class CCRect;
class CC_DLL CCApplication
class CC_DLL CCApplication : public CCApplicationProtocol
{
public:
CCApplication();
virtual ~CCApplication();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance() = 0;
/**
@brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching() = 0;
/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground() = 0;
/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground() = 0;
/**
@brief Callback by CCDirector for limit FPS.
@interval The time, which expressed in second in second, between current frame and next.
@ -86,11 +63,6 @@ public:
*/
Orientation setOrientation(Orientation orientation);
/**
@brief Get status bar rectangle in EGLView window.
*/
void statusBarFrame(CCRect * rect);
/**
@brief Run the message loop.
*/
@ -106,7 +78,7 @@ public:
@brief Get current language config
@return Current language config
*/
static ccLanguageType getCurrentLanguage();
virtual ccLanguageType getCurrentLanguage();
protected:
static CCApplication * sm_pSharedApplication;

View File

@ -88,13 +88,13 @@ CCApplication::Orientation CCApplication::setOrientation(Orientation eOritation)
return eOritation;
}
void CCApplication::statusBarFrame(cocos2d::CCRect * rect)
{
rect->origin.x = [[UIApplication sharedApplication] statusBarFrame].origin.x;
rect->origin.y = [[UIApplication sharedApplication] statusBarFrame].origin.y;
rect->size.width = [[UIApplication sharedApplication] statusBarFrame].size.width;
rect->size.height = [[UIApplication sharedApplication] statusBarFrame].size.height;
}
//void CCApplication::statusBarFrame(cocos2d::CCRect * rect)
//{
// rect->origin.x = [[UIApplication sharedApplication] statusBarFrame].origin.x;
// rect->origin.y = [[UIApplication sharedApplication] statusBarFrame].origin.y;
// rect->size.width = [[UIApplication sharedApplication] statusBarFrame].size.width;
// rect->size.height = [[UIApplication sharedApplication] statusBarFrame].size.height;
//}
/////////////////////////////////////////////////////////////////////////////////////////////////
// static member function

View File

@ -26,15 +26,13 @@ THE SOFTWARE.
#define __CC_EGLVIEW_IPHONE_H__
#include "CCCommon.h"
#include "CCEGLViewProtocol.h"
NS_CC_BEGIN
class CCSet;
class CCTouch;
class EGLTouchDelegate;
class CCSize;
class CC_DLL CCEGLView
class CC_DLL CCEGLView : public CCEGLViewProtocol
{
public:
CCEGLView();
@ -47,25 +45,16 @@ public:
void setContentScaleFactor(float contentScaleFactor);
// keep compatible
void release();
void setTouchDelegate(EGLTouchDelegate * pDelegate);
void end();
void swapBuffers();
void setViewPortInPoints(float x, float y, float w, float h);
void setScissorInPoints(float x, float y, float w, float h);
void touchesBegan(CCSet *set);
void touchesMoved(CCSet *set);
void touchesEnded(CCSet *set);
void touchesCancelled(CCSet *set);
float getMainScreenScale();
void setIMEKeyboardState(bool bOpen);
static CCEGLView& sharedOpenGLView();
private:
EGLTouchDelegate *m_pDelegate;
};
NS_CC_END

View File

@ -31,7 +31,6 @@ THE SOFTWARE.
NS_CC_BEGIN
CCEGLView::CCEGLView()
: m_pDelegate(0)
{
}
@ -41,9 +40,10 @@ CCEGLView::~CCEGLView()
}
cocos2d::CCSize CCEGLView::getSize()
CCSize CCEGLView::getSize()
{
cocos2d::CCSize size([[EAGLView sharedEGLView] getWidth], [[EAGLView sharedEGLView] getHeight]);
return size;
}
@ -57,19 +57,19 @@ bool CCEGLView::isOpenGLReady()
return [EAGLView sharedEGLView] != NULL;
}
bool CCEGLView::canSetContentScaleFactor()
{
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)];
}
bool CCEGLView::canSetContentScaleFactor()
{
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)];
}
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
{
UIView * view = [EAGLView sharedEGLView];
view.contentScaleFactor = contentScaleFactor;
[view setNeedsLayout];
}
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
{
UIView * view = [EAGLView sharedEGLView];
view.contentScaleFactor = contentScaleFactor;
[view setNeedsLayout];
}
void CCEGLView::release()
void CCEGLView::end()
{
[CCDirectorCaller destroy];
@ -77,53 +77,12 @@ void CCEGLView::release()
[[EAGLView sharedEGLView] removeFromSuperview];
}
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
{
m_pDelegate = pDelegate;
}
void CCEGLView::swapBuffers()
{
[[EAGLView sharedEGLView] swapBuffers];
}
void CCEGLView::touchesBegan(CCSet *set)
{
if (m_pDelegate) {
m_pDelegate->touchesBegan(set, NULL);
}
}
void CCEGLView::touchesMoved(CCSet *set)
{
if (m_pDelegate) {
m_pDelegate->touchesMoved(set, NULL);
}
}
void CCEGLView::touchesEnded(CCSet *set)
{
if (m_pDelegate) {
m_pDelegate->touchesEnded(set, NULL);
}
}
void CCEGLView::touchesCancelled(CCSet *set)
{
if (m_pDelegate) {
m_pDelegate->touchesCancelled(set, NULL);
}
}
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
{
glViewport((GLint)x, (GLint)y, (GLint)w, (GLint)h);
}
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
{
glScissor((GLint)x, (GLint)y, (GLint)w, (GLint)h);
}
void CCEGLView::setIMEKeyboardState(bool bOpen)
{

View File

@ -93,8 +93,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
BOOL multisampling_;
unsigned int requestedSamples_;
@private
CFMutableDictionaryRef touchesIntergerDict;
unsigned int indexBitsUsed;
NSString * markedText_;
CGRect caretRect_;
}
@ -139,8 +137,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
@property(nonatomic,readwrite) BOOL multiSampling;
@property(readonly) CFMutableDictionaryRef touchesIntergerDict;
@property(readwrite) unsigned int indexBitsUsed;
/** EAGLView uses double-buffer. This method swaps the buffers */
-(void) swapBuffers;
@ -150,7 +146,5 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
-(int) getWidth;
-(int) getHeight;
-(int) getUnUsedIndex;
-(void) removeUsedIndexBit:(int) index;
@end

View File

@ -62,7 +62,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
*/
#import <QuartzCore/QuartzCore.h>
#import "CCEGLView.h"
#import "EAGLView.h"
#import "CCES2Renderer.h"
#import "CCDirector.h"
@ -73,10 +73,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
//CLASS IMPLEMENTATIONS:
#define MAX_TOUCHES 11
static EAGLView *view;
static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
static EAGLView *view = 0;
@interface EAGLView (Private)
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
@ -88,8 +86,6 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
@synthesize surfaceSize=size_;
@synthesize pixelFormat=pixelformat_, depthFormat=depthFormat_;
@synthesize context=context_;
@synthesize touchesIntergerDict;
@synthesize indexBitsUsed;
@synthesize multiSampling=multiSampling_;
+ (Class) layerClass
@ -146,8 +142,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
[self release];
return nil;
}
touchesIntergerDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 4, NULL, NULL);
indexBitsUsed = 0x00000000;
view = self;
}
@ -208,34 +203,6 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
return bound.height;
}
-(int) getUnUsedIndex
{
int i;
int temp = indexBitsUsed;
for (i = 0; i < MAX_TOUCHES; i++) {
if (! (temp & 0x00000001)) {
indexBitsUsed |= (1 << i);
return i;
}
temp >>= 1;
}
// all bits are used
return -1;
}
-(void) removeUsedIndexBit:(int) index
{
if (index < 0 || index >= MAX_TOUCHES) {
return;
}
unsigned int temp = 1 << index;
temp = ~temp;
indexBitsUsed &= temp;
}
-(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
{
@ -269,7 +236,6 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (void) dealloc
{
CFRelease(touchesIntergerDict);
[renderer_ release];
[super dealloc];
}
@ -398,124 +364,66 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
cocos2d::CCSet set;
cocos2d::CCTouch *pTouch;
int ids[CC_MAX_TOUCHES] = {0};
float xs[CC_MAX_TOUCHES] = {0.0f};
float ys[CC_MAX_TOUCHES] = {0.0f};
int i = 0;
for (UITouch *touch in touches) {
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch);
int unUsedIndex = 0;
// it is a new touch
if (! index) {
unUsedIndex = [self getUnUsedIndex];
// The touches is more than MAX_TOUCHES ?
if (unUsedIndex == -1) {
return;
}
pTouch = s_pTouches[unUsedIndex] = new cocos2d::CCTouch();
float x = [touch locationInView: [touch view]].x;
float y = [touch locationInView: [touch view]].y;
pTouch->SetTouchInfo(x, y);
CFDictionaryAddValue(touchesIntergerDict, touch, [NSNumber numberWithInt:unUsedIndex]);
set.addObject(pTouch);
}
ids[i] = (int)touch;
xs[i] = [touch locationInView: [touch view]].x;
ys[i] = [touch locationInView: [touch view]].y;
++i;
}
if (set.count() == 0)
return;
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesBegan(&set);
cocos2d::CCEGLView::sharedOpenGLView().handleTouchesBegin(i, ids, xs, ys);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
cocos2d::CCSet set;
for (UITouch *touch in touches) {
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch);
if (! index) {
// if the index doesn't exist, it is an error
return;
}
cocos2d::CCTouch *pTouch = s_pTouches[[index intValue]];
if (! pTouch) {
// if the pTouch is null, it is an error
return;
}
float x = [touch locationInView: [touch view]].x;
float y = [touch locationInView: [touch view]].y;
pTouch->SetTouchInfo(x, y);
set.addObject(pTouch);
}
int ids[CC_MAX_TOUCHES] = {0};
float xs[CC_MAX_TOUCHES] = {0.0f};
float ys[CC_MAX_TOUCHES] = {0.0f};
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesMoved(&set);
int i = 0;
for (UITouch *touch in touches) {
ids[i] = (int)touch;
xs[i] = [touch locationInView: [touch view]].x;
ys[i] = [touch locationInView: [touch view]].y;
++i;
}
cocos2d::CCEGLView::sharedOpenGLView().handleTouchesMove(i, ids, xs, ys);
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
cocos2d::CCSet set;
for (UITouch *touch in touches) {
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch);
if (! index) {
// if the index doesn't exist, it is an error
return;
}
cocos2d::CCTouch *pTouch = s_pTouches[[index intValue]];
if (! pTouch) {
// if the pTouch is null, it is an error
return;
}
float x = [touch locationInView: [touch view]].x;
float y = [touch locationInView: [touch view]].y;
pTouch->SetTouchInfo(x, y);
set.addObject(pTouch);
CFDictionaryRemoveValue(touchesIntergerDict, touch);
pTouch->release();
s_pTouches[[index intValue]] = NULL;
[self removeUsedIndexBit:[index intValue]];
}
int ids[CC_MAX_TOUCHES] = {0};
float xs[CC_MAX_TOUCHES] = {0.0f};
float ys[CC_MAX_TOUCHES] = {0.0f};
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesEnded(&set);
int i = 0;
for (UITouch *touch in touches) {
ids[i] = (int)touch;
xs[i] = [touch locationInView: [touch view]].x;
ys[i] = [touch locationInView: [touch view]].y;
++i;
}
cocos2d::CCEGLView::sharedOpenGLView().handleTouchesEnd(i, ids, xs, ys);
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
cocos2d::CCSet set;
for (UITouch *touch in touches) {
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch);
if (! index) {
// if the index doesn't exist, it is an error
return;
}
cocos2d::CCTouch *pTouch = s_pTouches[[index intValue]];
if (! pTouch) {
// if the pTouch is null, it is an error
return;
}
float x = [touch locationInView: [touch view]].x;
float y = [touch locationInView: [touch view]].y;
pTouch->SetTouchInfo(x, y);
set.addObject(pTouch);
CFDictionaryRemoveValue(touchesIntergerDict, touch);
pTouch->release();
s_pTouches[[index intValue]] = NULL;
[self removeUsedIndexBit:[index intValue]];
}
int ids[CC_MAX_TOUCHES] = {0};
float xs[CC_MAX_TOUCHES] = {0.0f};
float ys[CC_MAX_TOUCHES] = {0.0f};
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesCancelled(&set);
int i = 0;
for (UITouch *touch in touches) {
ids[i] = (int)touch;
xs[i] = [touch locationInView: [touch view]].x;
ys[i] = [touch locationInView: [touch view]].y;
++i;
}
cocos2d::CCEGLView::sharedOpenGLView().handleTouchesCancel(i, ids, xs, ys);
}
#pragma mark -

View File

@ -1,5 +1,5 @@
#include "CCApplication.h"
#include "CCEGLView.h"
#include "CCDirector.h"
/**
@ -96,15 +96,6 @@ void CCApplication::setAnimationInterval(double interval)
m_nAnimationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);
}
void CCApplication::statusBarFrame(CCRect * rect)
{
if (rect)
{
// Windows doesn't have status bar.
*rect = CCRectMake(0, 0, 0, 0);
}
}
//////////////////////////////////////////////////////////////////////////
// static member function
//////////////////////////////////////////////////////////////////////////

View File

@ -2,54 +2,19 @@
#define __CC_APPLICATION_WIN32_H__
#include <Windows.h>
#include "CCCommon.h"
#include "CCApplicationProtocol.h"
NS_CC_BEGIN
class CCRect;
class CC_DLL CCApplication
class CC_DLL CCApplication : public CCApplicationProtocol
{
public:
CCApplication();
virtual ~CCApplication();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance() = 0;
/**
@brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching() = 0;
/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground() = 0;
/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground() = 0;
/**
@brief Callback by CCDirector for limit FPS.
@interval The time, which expressed in second in second, between current frame and next.
*/
void setAnimationInterval(double interval);
/**
@brief Get status bar rectangle in EGLView window.
*/
void statusBarFrame(CCRect * rect);
/**
@brief Run the message loop.
*/
@ -61,11 +26,9 @@ public:
*/
static CCApplication& sharedApplication();
/**
@brief Get current language config
@return Current language config
*/
static ccLanguageType getCurrentLanguage();
/* override functions */
virtual void setAnimationInterval(double interval);
virtual ccLanguageType getCurrentLanguage();
protected:
HINSTANCE m_hInstance;

View File

@ -182,16 +182,11 @@ static LRESULT CALLBACK _WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
CCEGLView::CCEGLView()
: m_bCaptured(false)
, m_pDelegate(NULL)
, m_pEGL(NULL)
, m_hWnd(NULL)
, m_fScreenScaleFactor(1.0f)
, m_lpfnAccelerometerKeyHook(NULL)
{
m_pTouch = new CCTouch;
m_pSet = new CCSet;
m_tSizeInPoints.cx = m_tSizeInPoints.cy = 0;
SetRectEmpty(&m_rcViewPort);
}
CCEGLView::~CCEGLView()
@ -242,8 +237,6 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
CC_BREAK_IF(! m_hWnd);
m_tSizeInPoints.cx = w;
m_tSizeInPoints.cy = h;
resize(w, h);
// init egl
@ -270,17 +263,16 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
switch (message)
{
case WM_LBUTTONDOWN:
if (m_pDelegate && m_pTouch && MK_LBUTTON == wParam)
if (m_pDelegate && MK_LBUTTON == wParam)
{
POINT pt = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
if (PtInRect(&m_rcViewPort, pt))
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
CCPoint pt(point.x, point.y);
if (CCRect::CCRectContainsPoint(m_rcViewPort, pt))
{
m_bCaptured = true;
SetCapture(m_hWnd);
m_pTouch->SetTouchInfo((float)(pt.x - m_rcViewPort.left) / m_fScreenScaleFactor,
(float)(pt.y - m_rcViewPort.top) / m_fScreenScaleFactor);
m_pSet->addObject(m_pTouch);
m_pDelegate->touchesBegan(m_pSet, NULL);
int id = 0;
handleTouchesBegin(1, &id, &pt.x, &pt.y);
}
}
break;
@ -288,19 +280,21 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
case WM_MOUSEMOVE:
if (MK_LBUTTON == wParam && m_bCaptured)
{
m_pTouch->SetTouchInfo((float)((short)LOWORD(lParam)- m_rcViewPort.left) / m_fScreenScaleFactor,
(float)((short)HIWORD(lParam) - m_rcViewPort.top) / m_fScreenScaleFactor);
m_pDelegate->touchesMoved(m_pSet, NULL);
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
CCPoint pt(point.x, point.y);
int id = 0;
handleTouchesMove(1, &id, &pt.x, &pt.y);
}
break;
case WM_LBUTTONUP:
if (m_bCaptured)
{
m_pTouch->SetTouchInfo((float)((short)LOWORD(lParam)- m_rcViewPort.left) / m_fScreenScaleFactor,
(float)((short)HIWORD(lParam) - m_rcViewPort.top) / m_fScreenScaleFactor);
m_pDelegate->touchesEnded(m_pSet, NULL);
m_pSet->removeObject(m_pTouch);
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
CCPoint pt(point.x, point.y);
int id = 0;
handleTouchesEnd(1, &id, &pt.x, &pt.y);
ReleaseCapture();
m_bCaptured = false;
}
@ -399,22 +393,13 @@ void CCEGLView::setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelero
m_lpfnAccelerometerKeyHook=lpfnAccelerometerKeyHook;
}
CCSize CCEGLView::getSize()
{
return CCSize((float)(m_tSizeInPoints.cx), (float)(m_tSizeInPoints.cy));
}
bool CCEGLView::isOpenGLReady()
{
return (NULL != m_pEGL);
}
bool CCEGLView::isIpad()
{
return false;
}
void CCEGLView::release()
void CCEGLView::end()
{
if (m_hWnd)
{
@ -424,17 +409,9 @@ void CCEGLView::release()
s_pMainWindow = NULL;
UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
CC_SAFE_DELETE(m_pSet);
CC_SAFE_DELETE(m_pTouch);
CC_SAFE_DELETE(m_pEGL);
delete this;
}
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
{
m_pDelegate = pDelegate;
}
void CCEGLView::swapBuffers()
{
if (m_pEGL)
@ -443,32 +420,10 @@ void CCEGLView::swapBuffers()
}
}
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
{
if (m_pEGL)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glViewport((GLint)(x * factor) + m_rcViewPort.left,
(GLint)(y * factor) + m_rcViewPort.top,
(GLint)(w * factor),
(GLint)(h * factor));
}
}
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
{
if (m_pEGL)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glScissor((GLint)(x * factor) + m_rcViewPort.left,
(GLint)(y * factor) + m_rcViewPort.top,
(GLint)(w * factor),
(GLint)(h * factor));
}
}
void CCEGLView::setIMEKeyboardState(bool /*bOpen*/)
{
}
HWND CCEGLView::getHWnd()
@ -504,21 +459,7 @@ void CCEGLView::resize(int width, int height)
m_pEGL->resizeSurface();
}
// calculate view port in pixels
int viewPortW = (int)(m_tSizeInPoints.cx * m_fScreenScaleFactor);
int viewPortH = (int)(m_tSizeInPoints.cy * m_fScreenScaleFactor);
GetClientRect(m_hWnd, &rcClient);
// calculate client new width and height
int newW = rcClient.right - rcClient.left;
int newH = rcClient.bottom - rcClient.top;
// calculate new view port
m_rcViewPort.left = rcClient.left + (newW - viewPortW) / 2;
m_rcViewPort.top = rcClient.top + (newH - viewPortH) / 2;
m_rcViewPort.right = m_rcViewPort.left + viewPortW;
m_rcViewPort.bottom = m_rcViewPort.top + viewPortH;
setFrameSize(width, height);
}
void CCEGLView::centerWindow()
@ -553,11 +494,6 @@ void CCEGLView::centerWindow()
SetWindowPos(m_hWnd, 0, offsetX, offsetY, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER);
}
void CCEGLView::setScreenScale(float factor)
{
m_fScreenScaleFactor = factor;
}
bool CCEGLView::canSetContentScaleFactor()
{
return true;
@ -565,8 +501,9 @@ bool CCEGLView::canSetContentScaleFactor()
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
{
m_fScreenScaleFactor = contentScaleFactor;
resize((int)(m_tSizeInPoints.cx * contentScaleFactor), (int)(m_tSizeInPoints.cy * contentScaleFactor));
CCEGLViewProtocol::setContentScaleFactor(contentScaleFactor);
resize((int)(m_sSizeInPixel.width * contentScaleFactor), (int)(m_sSizeInPixel.height * contentScaleFactor));
centerWindow();
}

View File

@ -26,41 +26,33 @@ THE SOFTWARE.
#define __CC_EGLVIEW_WIN32_H__
#include <Windows.h>
#include "CCCommon.h"
#include "CCGeometry.h"
#include "CCEGLViewProtocol.h"
NS_CC_BEGIN
class CCSet;
class CCTouch;
class EGLTouchDelegate;
class CCEGL;
class CC_DLL CCEGLView
class CC_DLL CCEGLView : public CCEGLViewProtocol
{
public:
CCEGLView();
virtual ~CCEGLView();
CCSize getSize();
bool isOpenGLReady();
bool isIpad();
void release();
void setTouchDelegate(EGLTouchDelegate * pDelegate);
void end();
void swapBuffers();
bool canSetContentScaleFactor();
void setContentScaleFactor(float contentScaleFactor);
float getMainScreenScale() { return -1.0f; }
virtual bool Create(LPCTSTR pTitle, int w, int h);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
void setViewPortInPoints(float x, float y, float w, float h);
void setScissorInPoints(float x, float y, float w, float h);
void setIMEKeyboardState(bool bOpen);
@ -68,7 +60,7 @@ public:
HWND getHWnd();
void resize(int width, int height);
void centerWindow();
void setScreenScale(float factor);
typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam );
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
@ -82,20 +74,9 @@ public:
protected:
private:
bool m_bCaptured;
CCSet * m_pSet;
CCTouch * m_pTouch;
EGLTouchDelegate * m_pDelegate;
CCEGL * m_pEGL;
HWND m_hWnd;
SIZE m_tSizeInPoints;
float m_fScreenScaleFactor;
RECT m_rcViewPort;
LPFN_ACCELEROMETER_KEYHOOK m_lpfnAccelerometerKeyHook;
};

View File

@ -431,6 +431,10 @@
RelativePath="..\include\CCEGLView.h"
>
</File>
<File
RelativePath="..\include\CCEventType.h"
>
</File>
<File
RelativePath="..\include\CCGeometry.h"
>
@ -771,6 +775,10 @@
RelativePath="..\platform\CCApplication_platform.h"
>
</File>
<File
RelativePath="..\platform\CCApplicationProtocol.h"
>
</File>
<File
RelativePath="..\platform\CCArchOptimalParticleSystem.h"
>
@ -787,6 +795,14 @@
RelativePath="..\platform\CCEGLView_platform.h"
>
</File>
<File
RelativePath="..\platform\CCEGLViewProtocol.cpp"
>
</File>
<File
RelativePath="..\platform\CCEGLViewProtocol.h"
>
</File>
<File
RelativePath="..\platform\CCFileUtils.cpp"
>

View File

@ -55,6 +55,7 @@ tests/NodeTest/NodeTest.cpp \
tests/TextInputTest/TextInputTest.cpp \
tests/MenuTest/MenuTest.cpp \
tests/MotionStreakTest/MotionStreakTest.cpp \
tests/MutiTouchTest/MutiTouchTest.cpp \
tests/ParallaxTest/ParallaxTest.cpp \
tests/ParticleTest/ParticleTest.cpp \
tests/PerformanceTest/PerformanceNodeChildrenTest.cpp \

View File

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

View File

@ -25,9 +25,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
{
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
view->setFrameWidthAndHeight(w, h);
view->setFrameSize(w, h);
// if you want to run in WVGA with HVGA resource, set it
// view->create(480, 320);
// view->setDesignResolutionSize(480, 320);
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
AppDelegate *pAppDelegate = new AppDelegate();

View File

@ -1 +1 @@
9626f4fb8d0744f491070885ee99b8cf28bb2889
5ba0d5201d4d8a46cb610cf9e9e0e3d8fcb5bb3c

View File

@ -1179,6 +1179,18 @@
>
</File>
</Filter>
<Filter
Name="MutiTouchTest"
>
<File
RelativePath="..\tests\MutiTouchTest\MutiTouchTest.cpp"
>
</File>
<File
RelativePath="..\tests\MutiTouchTest\MutiTouchTest.h"
>
</File>
</Filter>
</Filter>
</Filter>
</Files>

View File

@ -0,0 +1,129 @@
#include "MutiTouchTest.h"
static ccColor3B s_TouchColors[CC_MAX_TOUCHES] = {
ccYELLOW,
ccBLUE,
ccGREEN,
ccRED,
ccMAGENTA
};
class TouchPoint : public CCNode
{
public:
TouchPoint()
{
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
}
virtual void draw()
{
ccDrawColor4B(m_TouchColor.r, m_TouchColor.g, m_TouchColor.b, 255);
glLineWidth(10);
ccDrawLine( ccp(0, m_pTouchPoint.y), ccp(getContentSize().width, m_pTouchPoint.y) );
ccDrawLine( ccp(m_pTouchPoint.x, 0), ccp(m_pTouchPoint.x, getContentSize().height) );
glLineWidth(1);
ccPointSize(30);
ccDrawPoint(m_pTouchPoint);
}
void setTouchPos(const CCPoint& pt)
{
m_pTouchPoint = pt;
}
void setTouchColor(ccColor3B color)
{
m_TouchColor = color;
}
static TouchPoint* touchPointWithParent(CCNode* pParent)
{
TouchPoint* pRet = new TouchPoint();
pRet->setContentSize(pParent->getContentSize());
pRet->setAnchorPoint(ccp(0.0f, 0.0f));
pRet->autorelease();
return pRet;
}
private:
CCPoint m_pTouchPoint;
ccColor3B m_TouchColor;
};
bool MutiTouchTestLayer::init()
{
if (CCLayer::init())
{
setIsTouchEnabled(true);
return true;
}
return false;
}
static CCDictionary s_dic;
void MutiTouchTestLayer::registerWithTouchDispatcher(void)
{
CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);
}
void MutiTouchTestLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
{
CCTouch* pTouch = (CCTouch*)(*iter);
TouchPoint* pTouchPoint = TouchPoint::touchPointWithParent(this);
CCPoint location = pTouch->locationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
pTouchPoint->setTouchPos(location);
pTouchPoint->setTouchColor(s_TouchColors[pTouch->getID()]);
addChild(pTouchPoint);
s_dic.setObject(pTouchPoint, pTouch->getID());
}
}
void MutiTouchTestLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
{
CCTouch* pTouch = (CCTouch*)(*iter);
TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID());
CCPoint location = pTouch->locationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
pTP->setTouchPos(location);
}
}
void MutiTouchTestLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
{
CCTouch* pTouch = (CCTouch*)(*iter);
TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID());
removeChild(pTP, true);
s_dic.removeObjectForKey(pTouch->getID());
}
}
void MutiTouchTestLayer::ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent)
{
ccTouchesEnded(pTouches, pEvent);
}
void MutiTouchTestScene::runThisTest()
{
MutiTouchTestLayer* pLayer = MutiTouchTestLayer::node();
addChild(pLayer, 0);
CCDirector::sharedDirector()->replaceScene(this);
}

View File

@ -0,0 +1,26 @@
#ifndef __MUTITOUCHTEST_H__
#define __MUTITOUCHTEST_H__
#include "../testBasic.h"
class MutiTouchTestLayer : public CCLayer
{
public:
bool init();
virtual void registerWithTouchDispatcher(void);
virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
virtual void ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
LAYER_NODE_FUNC(MutiTouchTestLayer)
};
class MutiTouchTestScene : public TestScene
{
public:
virtual void runThisTest();
};
#endif /* __MUTITOUCHTEST_H__ */

View File

@ -123,6 +123,9 @@ static TestScene* CreateTestScene(int nIdx)
case TEST_SHADER:
pScene = new ShaderTestScene();
break;
case TEST_MUTITOUCH:
pScene = new MutiTouchTestScene();
break;
default:
break;
}

View File

@ -55,6 +55,7 @@
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
#include "ExtensionsTest/ExtensionsTest.h"
#include "MutiTouchTest/MutiTouchTest.h"
enum
{
@ -102,6 +103,7 @@ enum
TEST_TEXTURECACHE,
TEST_EXTENSIONS,
TEST_SHADER,
TEST_MUTITOUCH,
TESTS_COUNT,
};
@ -149,7 +151,8 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"CurrentLanguageTest",
"TextureCacheTest",
"ExtensionsTest",
"ShaderTest"
"ShaderTest",
"MutiTouchTest"
};
#endif