fixed #14 impliment CCTouch and treate touch msg in CCXEGLView EventHandler.

This commit is contained in:
yangws 2010-07-29 04:12:11 +00:00
parent 28376fcd4d
commit f12d51f7ae
10 changed files with 103 additions and 37 deletions

View File

@ -921,16 +921,16 @@ CGPoint CCNode::convertToWindowSpace(CGPoint nodePoint)
return ccp(0,0);
}
// convenience methods which take a UITouch instead of CGPoint
// convenience methods which take a CCTouch instead of CGPoint
/** @todo
- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch
- (CGPoint)convertTouchToNodeSpace:(CCTouch *)touch
{
CGPoint point = [touch locationInView: [touch view]];
point = [[CCDirector sharedDirector] convertToGL: point];
return [self convertToNodeSpace:point];
}*/
/** @todo
- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch
- (CGPoint)convertTouchToNodeSpaceAR:(CCTouch *)touch
{
CGPoint point = [touch locationInView: [touch view]];
point = [[CCDirector sharedDirector] convertToGL: point];

View File

@ -465,12 +465,16 @@
<Filter
Name="touch_dispatcher"
>
<File
RelativePath=".\touch_dispatcher\CCTouch.h"
>
</File>
<File
RelativePath=".\touch_dispatcher\CCTouchDelegateProtocol.h"
>
</File>
<File
RelativePath=".\touch_dispatcher\CCTouchDispacher.cpp"
RelativePath=".\touch_dispatcher\CCTouchDispatcher.cpp"
>
</File>
<File

View File

@ -479,15 +479,15 @@ public:
@since v0.7.1
*/
CGPoint convertToWorldSpaceAR(CGPoint nodePoint);
/** convenience methods which take a UITouch instead of CGPoint
/** convenience methods which take a CCTouch instead of CGPoint
@since v0.7.1
*/
/// @todo CGPoint convertTouchToNodeSpace(UITouch * touch);
/// @todo CGPoint convertTouchToNodeSpace(CCTouch * touch);
/** converts a UITouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
/** converts a CCTouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
@since v0.7.1
*/
/// @todo CGPoint convertTouchToNodeSpaceAR:(UITouch * touch);
/// @todo CGPoint convertTouchToNodeSpaceAR:(CCTouch * touch);
};

View File

@ -144,8 +144,8 @@ void CCLayer::onExit()
[super onExit];*/
}
/** @todo UITouch
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
/** @todo CCTouch
-(BOOL) ccTouchBegan:(CCTouch *)touch withEvent:(UIEvent *)event
{
NSAssert(NO, @"Layer#ccTouchBegan override me");
return YES;

View File

@ -26,42 +26,73 @@ THE SOFTWARE.
#include "TG3.h"
#include "cocoa/NSSet.h"
#include "touch_dispatcher/CCTouch.h"
#include "touch_dispatcher/CCTouchDispatcher.h"
namespace cocos2d {
CCXEGLView::CCXEGLView(TApplication * pApp)
: TWindow(pApp)
, m_bOpenGLReady(false)
, m_bCaptured(false)
, m_pDelegate(NULL)
{
m_pTouch = new CCTouch;
m_pSet = new NSSet;
}
CCXEGLView::~CCXEGLView()
{
delete m_pSet;
delete m_pTouch;
}
Boolean CCXEGLView::EventHandler(TApplication * pApp, EventType * pEvent)
{
Boolean bHandled = FALSE;
switch(pEvent->eType)
if (m_pDelegate && m_pTouch && m_pSet)
{
case EVENT_PenDown:
switch(pEvent->eType)
{
bHandled = TRUE;
}
break;
case EVENT_PenDown:
if (SetCaptureEx(-1, TRUE))
{
m_bCaptured = true;
// SS_printf("Down %4d %4d\n", pEvent->sParam1, pEvent->sParam2);
m_pTouch->SetTouchInfo(0, (float)pEvent->sParam1, (float)pEvent->sParam2);
m_pSet->addObject(m_pTouch);
m_pDelegate->touchesBegan(m_pSet, NULL);
bHandled = TRUE;
}
break;
case EVENT_PenMove:
{
bHandled = TRUE;
}
break;
case EVENT_PenMove:
if (m_bCaptured)
{
TRectangle rc;
GetBounds(&rc);
if (rc.IsInRect(pEvent->sParam1, pEvent->sParam2))
{
// SS_printf("Move %4d %4d\n", pEvent->sParam1, pEvent->sParam2);
m_pTouch->SetTouchInfo(0, (float)pEvent->sParam1, (float)pEvent->sParam2);
m_pDelegate->touchesMoved(m_pSet, NULL);
bHandled = TRUE;
}
}
break;
case EVENT_PenUp:
{
case EVENT_PenUp:
if (m_bCaptured)
{
ReleaseCapture();
// SS_printf("Up %4d %4d\n", pEvent->sParam1, pEvent->sParam2);
m_pTouch->SetTouchInfo(0, (float)pEvent->sParam1, (float)pEvent->sParam2);
m_pDelegate->touchesEnded(m_pSet, NULL);
bHandled = TRUE;
}
break;
}
break;
}
if (bHandled)

View File

@ -30,6 +30,8 @@ THE SOFTWARE.
#include "cocoa/CGGeometry.h"
class NSSet;
class CCTouch;
class TApplication;
class EGLTouchDelegate;
@ -54,6 +56,9 @@ public:
private:
bool m_bOpenGLReady;
bool m_bCaptured;
NSSet * m_pSet;
CCTouch * m_pTouch;
EGLTouchDelegate * m_pDelegate;
};

View File

@ -22,17 +22,42 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLATFORM_TOUCH_H__
#define __PLATFORM_TOUCH_H__
#ifndef __CC_TOUCH_H__
#define __CC_TOUCH_H__
#include "cocoa/NSObject.h"
#include "cocoa/CGGeometry.h"
class UITouch : public NSObject
// namespace cocos2d {
class CCTouch : public NSObject
{
public:
CCTouch() {}
CCTouch(int nViewId, float x, float y) : m_nViewId(nViewId), m_point(x, y), m_prevPoint(x, y) {}
CGPoint locationInView(int nViewId) { return m_point; }
CGPoint previousLocationInView(int nViewId) { return m_prevPoint; }
int view() { return m_nViewId; }
void SetTouchInfo(int nViewId, float x, float y)
{
m_nViewId = nViewId;
m_prevPoint = m_point;
m_point.x = x;
m_point.y = y;
}
private:
int m_nViewId;
CGPoint m_point;
CGPoint m_prevPoint;
};
class UIEvent : public NSObject
{
};
#endif // __PLATFORM_TOUCH_H__
// } // end of namespace cocos2d
#endif // __PLATFORM_TOUCH_H__

View File

@ -27,7 +27,7 @@ THE SOFTWARE.
#include "cocoa/NSObject.h"
class UITouch;
class CCTouch;
class UIEvent;
typedef enum {
@ -49,12 +49,12 @@ public:
/** Return YES to claim the touch.
@since v0.8
*/
virtual bool ccTouchBegan(UITouch *pTouch, UIEvent *pEvent) { return false;};
virtual bool ccTouchBegan(CCTouch *pTouch, UIEvent *pEvent) { return false;};
// optional
virtual void ccTouchMoved(UITouch *pTouch, UIEvent *pEvent) {}
virtual void ccTouchEnded(UITouch *pTouch, UIEvent *pEvent) {}
virtual void ccTouchCancelled(UITouch *pTouch, UIEvent *pEvent) {}
virtual void ccTouchMoved(CCTouch *pTouch, UIEvent *pEvent) {}
virtual void ccTouchEnded(CCTouch *pTouch, UIEvent *pEvent) {}
virtual void ccTouchCancelled(CCTouch *pTouch, UIEvent *pEvent) {}
};
/**

View File

@ -26,7 +26,7 @@ THE SOFTWARE.
#include "CCTouchHandler.h"
#include "../cocoa/NSMutableArray.h"
#include "../cocoa/NSSet.h"
#include "platform/CCTouch_Platform.h"
#include "CCTouch.h"
#include "CCTexture2D.h"
#include <assert.h>
@ -249,11 +249,11 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, UINT32 uIndex)
//
if (uTargetedHandlersCount > 0)
{
UITouch *pTouch;
CCTouch *pTouch;
NSSetIterator setIter;
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
{
pTouch = static_cast<UITouch *>(*setIter);
pTouch = static_cast<CCTouch *>(*setIter);
CCTargetedTouchHandler *pHandler;
NSMutableArray<CCTouchHandler*>::NSMutableArrayIterator arrayIter;
for (arrayIter = m_pTargetedHandlers->begin(); arrayIter != m_pTargetedHandlers->end(); ++arrayIter)

View File

@ -38,6 +38,7 @@ Boolean TMainForm::EventHandler(TApplication * pApp, EventType * pEvent)
break;
case EVENT_WinPaint:
{
DrawWindow();
bHandled = TRUE;
}
break;