mirror of https://github.com/axmolengine/axmol.git
issue #1177: Added some common methods for CCPoint,CCSize,CCRect. Added MutiTouchTest demo.
This commit is contained in:
parent
0c6d21c0f9
commit
521155e9e2
|
@ -25,6 +25,9 @@ bool AppDelegate::initInstance() {
|
||||||
CC_BREAK_IF(! pMainWnd
|
CC_BREAK_IF(! pMainWnd
|
||||||
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
|
|| ! 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
|
#endif // CC_PLATFORM_WIN32
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
||||||
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
|
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
|
||||||
{
|
{
|
||||||
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
|
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
|
// 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);
|
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||||
|
|
||||||
AppDelegate *pAppDelegate = new AppDelegate();
|
AppDelegate *pAppDelegate = new AppDelegate();
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="libcocos2d.lib"
|
AdditionalDependencies="libcocos2d.lib libGLESv2.lib"
|
||||||
OutputFile="$(OutDir)\$(ProjectName).exe"
|
OutputFile="$(OutDir)\$(ProjectName).exe"
|
||||||
LinkIncremental="2"
|
LinkIncremental="2"
|
||||||
AdditionalLibraryDirectories="$(OutDir)"
|
AdditionalLibraryDirectories="$(OutDir)"
|
||||||
|
|
|
@ -73,15 +73,14 @@ bool CCConfiguration::init(void)
|
||||||
CCLOG("cocos2d: GL supports NPOT textures: %s", (m_bSupportsNPOT ? "YES" : "NO"));
|
CCLOG("cocos2d: GL supports NPOT textures: %s", (m_bSupportsNPOT ? "YES" : "NO"));
|
||||||
CCLOG("cocos2d: GL supports discard_framebuffer: %s", (m_bSupportsDiscardFramebuffer ? "YES" : "NO"));
|
CCLOG("cocos2d: GL supports discard_framebuffer: %s", (m_bSupportsDiscardFramebuffer ? "YES" : "NO"));
|
||||||
|
|
||||||
|
bool bEnableProfilers = false;
|
||||||
|
|
||||||
|
#if CC_ENABLE_PROFILERS
|
||||||
|
bEnableProfilers = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
CCLOG("cocos2d: compiled with Profiling Support: %s",
|
CCLOG("cocos2d: compiled with Profiling Support: %s",
|
||||||
#if CC_ENABLE_PROFILERS
|
bEnableProfilers ? "YES - *** Disable it when you finish profiling ***" : "NO");
|
||||||
|
|
||||||
"YES - *** Disable it when you finish profiling ***"
|
|
||||||
#else
|
|
||||||
"NO"
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
#if CC_ENABLE_GL_STATE_CACHE == 0
|
#if CC_ENABLE_GL_STATE_CACHE == 0
|
||||||
CCLOG("");
|
CCLOG("");
|
||||||
|
|
|
@ -23,17 +23,33 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
|
#include "ccMacros.h"
|
||||||
|
|
||||||
// implementation of CCPoint
|
// implementation of CCPoint
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
CCPoint::CCPoint(void)
|
CCPoint::CCPoint(void)
|
||||||
{
|
{
|
||||||
x = 0;
|
setPoint(0.0f, 0.0f);
|
||||||
y = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCPoint::CCPoint(float x, float y)
|
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->x = x;
|
||||||
this->y = y;
|
this->y = y;
|
||||||
|
@ -48,11 +64,26 @@ bool CCPoint::CCPointEqualToPoint(const CCPoint& point1, const CCPoint& point2)
|
||||||
|
|
||||||
CCSize::CCSize(void)
|
CCSize::CCSize(void)
|
||||||
{
|
{
|
||||||
width = 0;
|
setSize(0.0f, 0.0f);
|
||||||
height = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSize::CCSize(float width, float height)
|
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->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
|
@ -67,17 +98,29 @@ bool CCSize::CCSizeEqualToSize(const CCSize& size1, const CCSize& size2)
|
||||||
|
|
||||||
CCRect::CCRect(void)
|
CCRect::CCRect(void)
|
||||||
{
|
{
|
||||||
origin.x = 0;
|
setRect(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
origin.y = 0;
|
|
||||||
|
|
||||||
size.width = 0;
|
|
||||||
size.height = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCRect::CCRect(float x, float y, float width, float height)
|
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
|
// 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.x = x;
|
||||||
origin.y = y;
|
origin.y = y;
|
||||||
|
|
|
@ -38,10 +38,11 @@ public:
|
||||||
float y;
|
float y;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CCPoint();
|
CCPoint();
|
||||||
CCPoint(float x, float y);
|
CCPoint(float x, float y);
|
||||||
|
CCPoint(const CCPoint& other);
|
||||||
|
CCPoint& operator= (const CCPoint& other);
|
||||||
|
void setPoint(float x, float y);
|
||||||
public:
|
public:
|
||||||
static bool CCPointEqualToPoint(const CCPoint& point1, const CCPoint& point2);
|
static bool CCPointEqualToPoint(const CCPoint& point1, const CCPoint& point2);
|
||||||
};
|
};
|
||||||
|
@ -55,7 +56,9 @@ public:
|
||||||
public:
|
public:
|
||||||
CCSize();
|
CCSize();
|
||||||
CCSize(float width, float height);
|
CCSize(float width, float height);
|
||||||
|
CCSize(const CCSize& other);
|
||||||
|
CCSize& operator= (const CCSize& other);
|
||||||
|
void setSize(float width, float height);
|
||||||
public:
|
public:
|
||||||
static bool CCSizeEqualToSize(const CCSize& size1, const CCSize& size2);
|
static bool CCSizeEqualToSize(const CCSize& size1, const CCSize& size2);
|
||||||
};
|
};
|
||||||
|
@ -69,7 +72,9 @@ public:
|
||||||
public:
|
public:
|
||||||
CCRect();
|
CCRect();
|
||||||
CCRect(float x, float y, float width, float height);
|
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:
|
public:
|
||||||
//! return the leftmost x-value of 'rect'
|
//! return the leftmost x-value of 'rect'
|
||||||
static CCFloat CCRectGetMinX(const CCRect& rect);
|
static CCFloat CCRectGetMinX(const CCRect& rect);
|
||||||
|
|
|
@ -6,14 +6,9 @@
|
||||||
#include "CCDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCInteger.h"
|
#include "CCInteger.h"
|
||||||
|
|
||||||
#undef COCOS2D_DEBUG;
|
|
||||||
#define COCOS2D_DEBUG 1
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
#define MAX_TOUCHES 5
|
static CCTouch* s_pTouches[CC_MAX_TOUCHES] = { NULL };
|
||||||
|
|
||||||
static CCTouch* s_pTouches[MAX_TOUCHES] = { NULL };
|
|
||||||
static unsigned int s_indexBitsUsed = 0;
|
static unsigned int s_indexBitsUsed = 0;
|
||||||
static CCDictionary s_TouchesIntergerDict;
|
static CCDictionary s_TouchesIntergerDict;
|
||||||
|
|
||||||
|
@ -22,7 +17,7 @@ static int getUnUsedIndex()
|
||||||
int i;
|
int i;
|
||||||
int temp = s_indexBitsUsed;
|
int temp = s_indexBitsUsed;
|
||||||
|
|
||||||
for (i = 0; i < MAX_TOUCHES; i++) {
|
for (i = 0; i < CC_MAX_TOUCHES; i++) {
|
||||||
if (! (temp & 0x00000001)) {
|
if (! (temp & 0x00000001)) {
|
||||||
s_indexBitsUsed |= (1 << i);
|
s_indexBitsUsed |= (1 << i);
|
||||||
return i;
|
return i;
|
||||||
|
@ -37,7 +32,7 @@ static int getUnUsedIndex()
|
||||||
|
|
||||||
static void removeUsedIndexBit(int index)
|
static void removeUsedIndexBit(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= MAX_TOUCHES)
|
if (index < 0 || index >= CC_MAX_TOUCHES)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +43,9 @@ static void removeUsedIndexBit(int index)
|
||||||
}
|
}
|
||||||
|
|
||||||
CCEGLViewProtocol::CCEGLViewProtocol()
|
CCEGLViewProtocol::CCEGLViewProtocol()
|
||||||
: m_pDelegate(NULL)
|
: m_bNeedScale(false)
|
||||||
, m_fScreenScaleFactor(1.0f)
|
, m_pDelegate(NULL)
|
||||||
|
, m_fScreenScaleFactor(1.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,9 +60,46 @@ bool CCEGLViewProtocol::isIpad()
|
||||||
return false;
|
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 CCEGLViewProtocol::getSize()
|
||||||
{
|
{
|
||||||
CCSize size(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
CCSize size;
|
||||||
|
if (m_bNeedScale)
|
||||||
|
{
|
||||||
|
size.setSize(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size.setSize(m_sSizeInPixel.width, m_sSizeInPixel.height);
|
||||||
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,20 +130,40 @@ void CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor)
|
||||||
|
|
||||||
void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h)
|
void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
|
if (m_bNeedScale)
|
||||||
|
{
|
||||||
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
||||||
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
|
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
|
||||||
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
||||||
(GLsizei)(w * factor),
|
(GLsizei)(w * factor),
|
||||||
(GLsizei)(h * 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)
|
void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
|
if (m_bNeedScale)
|
||||||
|
{
|
||||||
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
||||||
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
|
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
|
||||||
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
||||||
(GLsizei)(w * factor),
|
(GLsizei)(w * factor),
|
||||||
(GLsizei)(h * factor));
|
(GLsizei)(h * factor));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glScissor((GLint)x,
|
||||||
|
(GLint)y,
|
||||||
|
(GLsizei)w,
|
||||||
|
(GLsizei)h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float CCEGLViewProtocol::getMainScreenScale()
|
float CCEGLViewProtocol::getMainScreenScale()
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
#define CC_MAX_TOUCHES 5
|
||||||
|
|
||||||
class EGLTouchDelegate;
|
class EGLTouchDelegate;
|
||||||
class CCSet;
|
class CCSet;
|
||||||
|
|
||||||
|
@ -22,6 +24,8 @@ public:
|
||||||
virtual bool isIpad();
|
virtual bool isIpad();
|
||||||
virtual CCRect getViewPort();
|
virtual CCRect getViewPort();
|
||||||
virtual CCSize getSize();
|
virtual CCSize getSize();
|
||||||
|
virtual void setFrameSize(float width, float height);
|
||||||
|
virtual void setDesignResolutionSize(float width, float height);
|
||||||
virtual void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
virtual void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
||||||
virtual float getScreenScaleFactor();
|
virtual float getScreenScaleFactor();
|
||||||
virtual bool canSetContentScaleFactor();
|
virtual bool canSetContentScaleFactor();
|
||||||
|
@ -39,6 +43,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]);
|
void getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]);
|
||||||
protected:
|
protected:
|
||||||
|
bool m_bNeedScale;
|
||||||
EGLTouchDelegate* m_pDelegate;
|
EGLTouchDelegate* m_pDelegate;
|
||||||
float m_fScreenScaleFactor;
|
float m_fScreenScaleFactor;
|
||||||
CCSize m_sSizeInPixel;
|
CCSize m_sSizeInPixel;
|
||||||
|
|
|
@ -48,48 +48,15 @@ void initExtensions() {
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
CCEGLView::CCEGLView()
|
CCEGLView::CCEGLView()
|
||||||
: m_bNotHVGA(false)
|
|
||||||
{
|
{
|
||||||
initExtensions();
|
initExtensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCEGLView::setFrameWidthAndHeight(int width, int height)
|
|
||||||
{
|
|
||||||
m_sSizeInPixel.width = width;
|
|
||||||
m_sSizeInPixel.height = height;
|
|
||||||
create(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
CCLog("m_fScreenScaleFactor = %f", m_fScreenScaleFactor);
|
|
||||||
m_bNotHVGA = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CCEGLView::~CCEGLView()
|
CCEGLView::~CCEGLView()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CCEGLView::isOpenGLReady()
|
bool CCEGLView::isOpenGLReady()
|
||||||
{
|
{
|
||||||
return (m_sSizeInPixel.width != 0 && m_sSizeInPixel.height != 0);
|
return (m_sSizeInPixel.width != 0 && m_sSizeInPixel.height != 0);
|
||||||
|
|
|
@ -37,23 +37,10 @@ public:
|
||||||
virtual ~CCEGLView();
|
virtual ~CCEGLView();
|
||||||
|
|
||||||
bool isOpenGLReady();
|
bool isOpenGLReady();
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
// keep compatible
|
// keep compatible
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setIMEKeyboardState(bool bOpen);
|
void setIMEKeyboardState(bool bOpen);
|
||||||
|
|
||||||
// static function
|
// static function
|
||||||
|
@ -61,10 +48,6 @@ public:
|
||||||
@brief get the shared main open gl window
|
@brief get the shared main open gl window
|
||||||
*/
|
*/
|
||||||
static CCEGLView& sharedOpenGLView();
|
static CCEGLView& sharedOpenGLView();
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool m_bNotHVGA;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -237,9 +237,6 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
|
||||||
|
|
||||||
CC_BREAK_IF(! m_hWnd);
|
CC_BREAK_IF(! m_hWnd);
|
||||||
|
|
||||||
m_sSizeInPoint.width = (float)w;
|
|
||||||
m_sSizeInPoint.height = (float)h;
|
|
||||||
|
|
||||||
resize(w, h);
|
resize(w, h);
|
||||||
|
|
||||||
// init egl
|
// init egl
|
||||||
|
@ -268,7 +265,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
if (m_pDelegate && MK_LBUTTON == wParam)
|
if (m_pDelegate && MK_LBUTTON == wParam)
|
||||||
{
|
{
|
||||||
CCPoint pt((float)LOWORD(lParam), (float)HIWORD(lParam));
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
||||||
|
CCPoint pt(point.x, point.y);
|
||||||
if (CCRect::CCRectContainsPoint(m_rcViewPort, pt))
|
if (CCRect::CCRectContainsPoint(m_rcViewPort, pt))
|
||||||
{
|
{
|
||||||
m_bCaptured = true;
|
m_bCaptured = true;
|
||||||
|
@ -282,7 +280,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
if (MK_LBUTTON == wParam && m_bCaptured)
|
if (MK_LBUTTON == wParam && m_bCaptured)
|
||||||
{
|
{
|
||||||
CCPoint pt((float)LOWORD(lParam), (float)HIWORD(lParam));
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
||||||
|
CCPoint pt(point.x, point.y);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
||||||
}
|
}
|
||||||
|
@ -291,7 +290,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
if (m_bCaptured)
|
if (m_bCaptured)
|
||||||
{
|
{
|
||||||
CCPoint pt((float)LOWORD(lParam), (float)HIWORD(lParam));
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
||||||
|
CCPoint pt(point.x, point.y);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
||||||
|
|
||||||
|
@ -459,21 +459,7 @@ void CCEGLView::resize(int width, int height)
|
||||||
m_pEGL->resizeSurface();
|
m_pEGL->resizeSurface();
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate view port in pixels
|
setFrameSize(width, height);
|
||||||
float viewPortW = m_sSizeInPoint.width * m_fScreenScaleFactor;
|
|
||||||
float viewPortH = m_sSizeInPoint.height * m_fScreenScaleFactor;
|
|
||||||
|
|
||||||
GetClientRect(m_hWnd, &rcClient);
|
|
||||||
|
|
||||||
// calculate client new width and height
|
|
||||||
float newW = rcClient.right - rcClient.left;
|
|
||||||
float newH = rcClient.bottom - rcClient.top;
|
|
||||||
|
|
||||||
// calculate new view port
|
|
||||||
m_rcViewPort.origin.x = rcClient.left + (newW - viewPortW) / 2;
|
|
||||||
m_rcViewPort.origin.y = rcClient.top + (newH - viewPortH) / 2;
|
|
||||||
m_rcViewPort.size.width = viewPortW;
|
|
||||||
m_rcViewPort.size.height = viewPortH;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCEGLView::centerWindow()
|
void CCEGLView::centerWindow()
|
||||||
|
|
|
@ -55,6 +55,7 @@ tests/NodeTest/NodeTest.cpp \
|
||||||
tests/TextInputTest/TextInputTest.cpp \
|
tests/TextInputTest/TextInputTest.cpp \
|
||||||
tests/MenuTest/MenuTest.cpp \
|
tests/MenuTest/MenuTest.cpp \
|
||||||
tests/MotionStreakTest/MotionStreakTest.cpp \
|
tests/MotionStreakTest/MotionStreakTest.cpp \
|
||||||
|
tests/MutiTouchTest/MutiTouchTest.cpp \
|
||||||
tests/ParallaxTest/ParallaxTest.cpp \
|
tests/ParallaxTest/ParallaxTest.cpp \
|
||||||
tests/ParticleTest/ParticleTest.cpp \
|
tests/ParticleTest/ParticleTest.cpp \
|
||||||
tests/PerformanceTest/PerformanceNodeChildrenTest.cpp \
|
tests/PerformanceTest/PerformanceNodeChildrenTest.cpp \
|
||||||
|
|
|
@ -24,9 +24,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
||||||
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
|
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
|
||||||
{
|
{
|
||||||
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
|
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
|
// 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);
|
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||||
|
|
||||||
AppDelegate *pAppDelegate = new AppDelegate();
|
AppDelegate *pAppDelegate = new AppDelegate();
|
||||||
|
|
|
@ -1179,6 +1179,18 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="MutiTouchTest"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\tests\MutiTouchTest\MutiTouchTest.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\tests\MutiTouchTest\MutiTouchTest.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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__ */
|
|
@ -123,6 +123,9 @@ static TestScene* CreateTestScene(int nIdx)
|
||||||
case TEST_SHADER:
|
case TEST_SHADER:
|
||||||
pScene = new ShaderTestScene();
|
pScene = new ShaderTestScene();
|
||||||
break;
|
break;
|
||||||
|
case TEST_MUTITOUCH:
|
||||||
|
pScene = new MutiTouchTestScene();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
||||||
|
|
||||||
#include "ExtensionsTest/ExtensionsTest.h"
|
#include "ExtensionsTest/ExtensionsTest.h"
|
||||||
|
#include "MutiTouchTest/MutiTouchTest.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
@ -102,6 +103,7 @@ enum
|
||||||
TEST_TEXTURECACHE,
|
TEST_TEXTURECACHE,
|
||||||
TEST_EXTENSIONS,
|
TEST_EXTENSIONS,
|
||||||
TEST_SHADER,
|
TEST_SHADER,
|
||||||
|
TEST_MUTITOUCH,
|
||||||
TESTS_COUNT,
|
TESTS_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,7 +151,8 @@ const std::string g_aTestNames[TESTS_COUNT] = {
|
||||||
"CurrentLanguageTest",
|
"CurrentLanguageTest",
|
||||||
"TextureCacheTest",
|
"TextureCacheTest",
|
||||||
"ExtensionsTest",
|
"ExtensionsTest",
|
||||||
"ShaderTest"
|
"ShaderTest",
|
||||||
|
"MutiTouchTest"
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue