mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into developTest
Conflicts: samples/Cpp/SimpleGame/Classes/HelloWorldScene.cpp
This commit is contained in:
commit
cf5e04ad63
|
@ -1 +1 @@
|
||||||
cee239faffacb79c42a315cc01d4bce887435f5b
|
a511bc3eca93bdbec49803fde5da4a61bd404020
|
|
@ -45,6 +45,16 @@ draw_nodes/CCDrawingPrimitives.cpp \
|
||||||
draw_nodes/CCDrawNode.cpp \
|
draw_nodes/CCDrawNode.cpp \
|
||||||
effects/CCGrabber.cpp \
|
effects/CCGrabber.cpp \
|
||||||
effects/CCGrid.cpp \
|
effects/CCGrid.cpp \
|
||||||
|
event_dispatcher/CCAccelerationEvent.cpp \
|
||||||
|
event_dispatcher/CCAccelerationEventListener.cpp \
|
||||||
|
event_dispatcher/CCEvent.cpp \
|
||||||
|
event_dispatcher/CCEventDispatcher.cpp \
|
||||||
|
event_dispatcher/CCEventListener.cpp \
|
||||||
|
event_dispatcher/CCKeyboardEvent.cpp \
|
||||||
|
event_dispatcher/CCKeyboardEventListener.cpp \
|
||||||
|
event_dispatcher/CCTouch.cpp \
|
||||||
|
event_dispatcher/CCTouchEvent.cpp \
|
||||||
|
event_dispatcher/CCTouchEventListener.cpp \
|
||||||
kazmath/src/aabb.c \
|
kazmath/src/aabb.c \
|
||||||
kazmath/src/mat3.c \
|
kazmath/src/mat3.c \
|
||||||
kazmath/src/mat4.c \
|
kazmath/src/mat4.c \
|
||||||
|
@ -58,9 +68,6 @@ kazmath/src/vec3.c \
|
||||||
kazmath/src/vec4.c \
|
kazmath/src/vec4.c \
|
||||||
kazmath/src/GL/mat4stack.c \
|
kazmath/src/GL/mat4stack.c \
|
||||||
kazmath/src/GL/matrix.c \
|
kazmath/src/GL/matrix.c \
|
||||||
keyboard_dispatcher/CCKeyboardDispatcher.cpp \
|
|
||||||
keypad_dispatcher/CCKeypadDelegate.cpp \
|
|
||||||
keypad_dispatcher/CCKeypadDispatcher.cpp \
|
|
||||||
label_nodes/CCFont.cpp \
|
label_nodes/CCFont.cpp \
|
||||||
label_nodes/CCFontAtlas.cpp \
|
label_nodes/CCFontAtlas.cpp \
|
||||||
label_nodes/CCFontAtlasCache.cpp \
|
label_nodes/CCFontAtlasCache.cpp \
|
||||||
|
@ -133,10 +140,8 @@ tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
||||||
tilemap_parallax_nodes/CCTMXLayer.cpp \
|
tilemap_parallax_nodes/CCTMXLayer.cpp \
|
||||||
tilemap_parallax_nodes/CCTMXObjectGroup.cpp \
|
tilemap_parallax_nodes/CCTMXObjectGroup.cpp \
|
||||||
tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
||||||
tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
tilemap_parallax_nodes/CCTMXXMLParser.cpp
|
||||||
touch_dispatcher/CCTouch.cpp \
|
|
||||||
touch_dispatcher/CCTouchDispatcher.cpp \
|
|
||||||
touch_dispatcher/CCTouchHandler.cpp
|
|
||||||
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
||||||
$(LOCAL_PATH)/include \
|
$(LOCAL_PATH)/include \
|
||||||
|
|
|
@ -32,13 +32,11 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "ccFPSImages.h"
|
#include "ccFPSImages.h"
|
||||||
#include "draw_nodes/CCDrawingPrimitives.h"
|
#include "draw_nodes/CCDrawingPrimitives.h"
|
||||||
#include "CCConfiguration.h"
|
|
||||||
#include "cocoa/CCNS.h"
|
#include "cocoa/CCNS.h"
|
||||||
#include "layers_scenes_transitions_nodes/CCScene.h"
|
#include "layers_scenes_transitions_nodes/CCScene.h"
|
||||||
#include "cocoa/CCArray.h"
|
#include "cocoa/CCArray.h"
|
||||||
#include "CCScheduler.h"
|
#include "CCScheduler.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
||||||
#include "support/CCNotificationCenter.h"
|
#include "support/CCNotificationCenter.h"
|
||||||
#include "layers_scenes_transitions_nodes/CCTransition.h"
|
#include "layers_scenes_transitions_nodes/CCTransition.h"
|
||||||
#include "textures/CCTextureCache.h"
|
#include "textures/CCTextureCache.h"
|
||||||
|
@ -49,11 +47,8 @@ THE SOFTWARE.
|
||||||
#include "label_nodes/CCLabelBMFont.h"
|
#include "label_nodes/CCLabelBMFont.h"
|
||||||
#include "label_nodes/CCLabelAtlas.h"
|
#include "label_nodes/CCLabelAtlas.h"
|
||||||
#include "actions/CCActionManager.h"
|
#include "actions/CCActionManager.h"
|
||||||
#include "CCConfiguration.h"
|
|
||||||
#include "keypad_dispatcher/CCKeypadDispatcher.h"
|
|
||||||
#include "CCAccelerometer.h"
|
|
||||||
#include "sprite_nodes/CCAnimationCache.h"
|
#include "sprite_nodes/CCAnimationCache.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "support/user_default/CCUserDefault.h"
|
#include "support/user_default/CCUserDefault.h"
|
||||||
#include "shaders/ccGLStateCache.h"
|
#include "shaders/ccGLStateCache.h"
|
||||||
#include "shaders/CCShaderCache.h"
|
#include "shaders/CCShaderCache.h"
|
||||||
|
@ -63,7 +58,6 @@ THE SOFTWARE.
|
||||||
#include "platform/CCImage.h"
|
#include "platform/CCImage.h"
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
#include "CCConfiguration.h"
|
#include "CCConfiguration.h"
|
||||||
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,18 +141,6 @@ bool Director::init(void)
|
||||||
// action manager
|
// action manager
|
||||||
_actionManager = new ActionManager();
|
_actionManager = new ActionManager();
|
||||||
_scheduler->scheduleUpdateForTarget(_actionManager, Scheduler::PRIORITY_SYSTEM, false);
|
_scheduler->scheduleUpdateForTarget(_actionManager, Scheduler::PRIORITY_SYSTEM, false);
|
||||||
// touchDispatcher
|
|
||||||
_touchDispatcher = new TouchDispatcher();
|
|
||||||
_touchDispatcher->init();
|
|
||||||
|
|
||||||
// KeyboardDispatcher
|
|
||||||
_keyboardDispatcher = new KeyboardDispatcher();
|
|
||||||
|
|
||||||
// KeypadDispatcher
|
|
||||||
_keypadDispatcher = new KeypadDispatcher();
|
|
||||||
|
|
||||||
// Accelerometer
|
|
||||||
_accelerometer = new Accelerometer();
|
|
||||||
|
|
||||||
// create autorelease pool
|
// create autorelease pool
|
||||||
PoolManager::sharedPoolManager()->push();
|
PoolManager::sharedPoolManager()->push();
|
||||||
|
@ -179,10 +161,6 @@ Director::~Director(void)
|
||||||
CC_SAFE_RELEASE(_scenesStack);
|
CC_SAFE_RELEASE(_scenesStack);
|
||||||
CC_SAFE_RELEASE(_scheduler);
|
CC_SAFE_RELEASE(_scheduler);
|
||||||
CC_SAFE_RELEASE(_actionManager);
|
CC_SAFE_RELEASE(_actionManager);
|
||||||
CC_SAFE_RELEASE(_touchDispatcher);
|
|
||||||
CC_SAFE_RELEASE(_keyboardDispatcher);
|
|
||||||
CC_SAFE_RELEASE(_keypadDispatcher);
|
|
||||||
CC_SAFE_DELETE(_accelerometer);
|
|
||||||
|
|
||||||
// pop the autorelease pool
|
// pop the autorelease pool
|
||||||
PoolManager::sharedPoolManager()->pop();
|
PoolManager::sharedPoolManager()->pop();
|
||||||
|
@ -250,6 +228,8 @@ void Director::setGLDefaultValues()
|
||||||
// Draw the Scene
|
// Draw the Scene
|
||||||
void Director::drawScene()
|
void Director::drawScene()
|
||||||
{
|
{
|
||||||
|
Node::resetEventPriorityIndex();
|
||||||
|
|
||||||
// calculate "global" dt
|
// calculate "global" dt
|
||||||
calculateDeltaTime();
|
calculateDeltaTime();
|
||||||
|
|
||||||
|
@ -372,8 +352,7 @@ void Director::setOpenGLView(EGLView *pobOpenGLView)
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
_openGLView->setTouchDelegate(_touchDispatcher);
|
// _touchDispatcher->setDispatchEvents(true);
|
||||||
_touchDispatcher->setDispatchEvents(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,7 +658,7 @@ void Director::purgeDirector()
|
||||||
|
|
||||||
// don't release the event handlers
|
// don't release the event handlers
|
||||||
// They are needed in case the director is run again
|
// They are needed in case the director is run again
|
||||||
_touchDispatcher->removeAllDelegates();
|
// _touchDispatcher->removeAllDelegates();
|
||||||
|
|
||||||
if (_runningScene)
|
if (_runningScene)
|
||||||
{
|
{
|
||||||
|
@ -984,59 +963,6 @@ ActionManager* Director::getActionManager() const
|
||||||
return _actionManager;
|
return _actionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::setTouchDispatcher(TouchDispatcher* touchDispatcher)
|
|
||||||
{
|
|
||||||
if (_touchDispatcher != touchDispatcher)
|
|
||||||
{
|
|
||||||
CC_SAFE_RETAIN(touchDispatcher);
|
|
||||||
CC_SAFE_RELEASE(_touchDispatcher);
|
|
||||||
_touchDispatcher = touchDispatcher;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchDispatcher* Director::getTouchDispatcher() const
|
|
||||||
{
|
|
||||||
return _touchDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Director::setKeyboardDispatcher(KeyboardDispatcher* keyboardDispatcher)
|
|
||||||
{
|
|
||||||
CC_SAFE_RETAIN(keyboardDispatcher);
|
|
||||||
CC_SAFE_RELEASE(_keyboardDispatcher);
|
|
||||||
_keyboardDispatcher = keyboardDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyboardDispatcher* Director::getKeyboardDispatcher() const
|
|
||||||
{
|
|
||||||
return _keyboardDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Director::setKeypadDispatcher(KeypadDispatcher* keyboardDispatcher)
|
|
||||||
{
|
|
||||||
CC_SAFE_RETAIN(keyboardDispatcher);
|
|
||||||
CC_SAFE_RELEASE(_keypadDispatcher);
|
|
||||||
_keypadDispatcher = keyboardDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
KeypadDispatcher* Director::getKeypadDispatcher() const
|
|
||||||
{
|
|
||||||
return _keypadDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Director::setAccelerometer(Accelerometer* accelerometer)
|
|
||||||
{
|
|
||||||
if (_accelerometer != accelerometer)
|
|
||||||
{
|
|
||||||
CC_SAFE_DELETE(_accelerometer);
|
|
||||||
_accelerometer = accelerometer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Accelerometer* Director::getAccelerometer() const
|
|
||||||
{
|
|
||||||
return _accelerometer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
* implementation of DisplayLinkDirector
|
* implementation of DisplayLinkDirector
|
||||||
**************************************************/
|
**************************************************/
|
||||||
|
|
|
@ -351,63 +351,6 @@ public:
|
||||||
@since v2.0
|
@since v2.0
|
||||||
*/
|
*/
|
||||||
void setActionManager(ActionManager* actionManager);
|
void setActionManager(ActionManager* actionManager);
|
||||||
|
|
||||||
/** Gets the TouchDispatcher associated with this director
|
|
||||||
@since v2.0
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
TouchDispatcher* getTouchDispatcher() const;
|
|
||||||
|
|
||||||
/** Sets the TouchDispatcher associated with this director
|
|
||||||
@since v2.0
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
void setTouchDispatcher(TouchDispatcher* touchDispatcher);
|
|
||||||
|
|
||||||
/** Gets the KeyboardDispatcher associated with this director
|
|
||||||
@note Supported on Mac and Linux only now.
|
|
||||||
@since v3.0
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
KeyboardDispatcher* getKeyboardDispatcher() const;
|
|
||||||
|
|
||||||
/** Sets the KeyboardDispatcher associated with this director
|
|
||||||
@note Supported on Mac and Linux only now.
|
|
||||||
@since v3.0
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
void setKeyboardDispatcher(KeyboardDispatcher* keyboardDispatcher);
|
|
||||||
|
|
||||||
/** Gets the KeypadDispatcher associated with this director
|
|
||||||
@since v2.0
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
KeypadDispatcher* getKeypadDispatcher() const;
|
|
||||||
|
|
||||||
/** Sets the KeypadDispatcher associated with this director
|
|
||||||
@since v2.0
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
void setKeypadDispatcher(KeypadDispatcher* keypadDispatcher);
|
|
||||||
|
|
||||||
/** Gets Accelerometer associated with this director
|
|
||||||
@since v2.0
|
|
||||||
*@js NA
|
|
||||||
*@lua NA
|
|
||||||
*/
|
|
||||||
Accelerometer* getAccelerometer() const;
|
|
||||||
|
|
||||||
/** Sets Accelerometer associated with this director
|
|
||||||
@since v2.0
|
|
||||||
*/
|
|
||||||
void setAccelerometer(Accelerometer* acc);
|
|
||||||
|
|
||||||
/* Gets delta time since last tick to main loop */
|
/* Gets delta time since last tick to main loop */
|
||||||
float getDeltaTime() const;
|
float getDeltaTime() const;
|
||||||
|
|
||||||
|
@ -436,27 +379,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
ActionManager* _actionManager;
|
ActionManager* _actionManager;
|
||||||
|
|
||||||
/** TouchDispatcher associated with this director
|
|
||||||
@since v2.0
|
|
||||||
*/
|
|
||||||
TouchDispatcher* _touchDispatcher;
|
|
||||||
|
|
||||||
/** KeyboardDispatcher associated with this director
|
|
||||||
@note Supported on Mac and Linux only now.
|
|
||||||
@since v3.0
|
|
||||||
*/
|
|
||||||
KeyboardDispatcher* _keyboardDispatcher;
|
|
||||||
|
|
||||||
/** KeypadDispatcher associated with this director
|
|
||||||
@since v2.0
|
|
||||||
*/
|
|
||||||
KeypadDispatcher* _keypadDispatcher;
|
|
||||||
|
|
||||||
/** Accelerometer associated with this director
|
|
||||||
@since v2.0
|
|
||||||
*/
|
|
||||||
Accelerometer* _accelerometer;
|
|
||||||
|
|
||||||
/* delta time since last tick to main loop */
|
/* delta time since last tick to main loop */
|
||||||
float _deltaTime;
|
float _deltaTime;
|
||||||
|
|
||||||
|
|
|
@ -36,16 +36,21 @@ THE SOFTWARE.
|
||||||
#include "effects/CCGrid.h"
|
#include "effects/CCGrid.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCScheduler.h"
|
#include "CCScheduler.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "actions/CCActionManager.h"
|
#include "actions/CCActionManager.h"
|
||||||
#include "script_support/CCScriptSupport.h"
|
#include "script_support/CCScriptSupport.h"
|
||||||
#include "shaders/CCGLProgram.h"
|
#include "shaders/CCGLProgram.h"
|
||||||
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCEvent.h"
|
||||||
|
#include "event_dispatcher/CCTouchEvent.h"
|
||||||
|
|
||||||
// externals
|
// externals
|
||||||
#include "kazmath/GL/matrix.h"
|
#include "kazmath/GL/matrix.h"
|
||||||
#include "support/component/CCComponent.h"
|
#include "support/component/CCComponent.h"
|
||||||
#include "support/component/CCComponentContainer.h"
|
#include "support/component/CCComponentContainer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if CC_NODE_RENDER_SUBPIXEL
|
#if CC_NODE_RENDER_SUBPIXEL
|
||||||
#define RENDER_IN_SUBPIXEL
|
#define RENDER_IN_SUBPIXEL
|
||||||
#else
|
#else
|
||||||
|
@ -80,6 +85,7 @@ bool nodeComparisonLess(Object* p1, Object* p2)
|
||||||
|
|
||||||
// XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered.
|
// XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered.
|
||||||
static int s_globalOrderOfArrival = 1;
|
static int s_globalOrderOfArrival = 1;
|
||||||
|
int Node::_globalEventPriorityIndex = 0;
|
||||||
|
|
||||||
Node::Node(void)
|
Node::Node(void)
|
||||||
: _rotationX(0.0f)
|
: _rotationX(0.0f)
|
||||||
|
@ -166,7 +172,14 @@ Node::~Node()
|
||||||
// children
|
// children
|
||||||
CC_SAFE_RELEASE(_children);
|
CC_SAFE_RELEASE(_children);
|
||||||
|
|
||||||
|
removeAllComponents();
|
||||||
|
|
||||||
CC_SAFE_DELETE(_componentContainer);
|
CC_SAFE_DELETE(_componentContainer);
|
||||||
|
|
||||||
|
for (auto iter = _eventlisteners.begin(); iter != _eventlisteners.end(); ++iter)
|
||||||
|
{
|
||||||
|
EventDispatcher::getInstance()->removeEventListener(*iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::init()
|
bool Node::init()
|
||||||
|
@ -813,6 +826,7 @@ void Node::visit()
|
||||||
}
|
}
|
||||||
// self draw
|
// self draw
|
||||||
this->draw();
|
this->draw();
|
||||||
|
_eventPriority = ++_globalEventPriorityIndex;
|
||||||
|
|
||||||
for( ; i < _children->count(); i++ )
|
for( ; i < _children->count(); i++ )
|
||||||
{
|
{
|
||||||
|
@ -824,6 +838,7 @@ void Node::visit()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->draw();
|
this->draw();
|
||||||
|
_eventPriority = ++_globalEventPriorityIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset for next frame
|
// reset for next frame
|
||||||
|
@ -1276,6 +1291,21 @@ void Node::removeAllComponents()
|
||||||
_componentContainer->removeAll();
|
_componentContainer->removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::resetEventPriorityIndex()
|
||||||
|
{
|
||||||
|
_globalEventPriorityIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::associateEventListener(EventListener* listener)
|
||||||
|
{
|
||||||
|
_eventlisteners.insert(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::dissociateEventListener(EventListener* listener)
|
||||||
|
{
|
||||||
|
_eventlisteners.erase(listener);
|
||||||
|
}
|
||||||
|
|
||||||
// NodeRGBA
|
// NodeRGBA
|
||||||
NodeRGBA::NodeRGBA()
|
NodeRGBA::NodeRGBA()
|
||||||
: _displayedOpacity(255)
|
: _displayedOpacity(255)
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
#include "kazmath/kazmath.h"
|
#include "kazmath/kazmath.h"
|
||||||
#include "script_support/CCScriptSupport.h"
|
#include "script_support/CCScriptSupport.h"
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -52,6 +55,7 @@ class ActionManager;
|
||||||
class Component;
|
class Component;
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
class ComponentContainer;
|
class ComponentContainer;
|
||||||
|
class EventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup base_nodes
|
* @addtogroup base_nodes
|
||||||
|
@ -72,6 +76,8 @@ bool nodeComparisonLess(const RCPtr<Object>& pp1, const RCPtr<Object>& pp2);
|
||||||
bool nodeComparisonLess(Object* p1, Object* p2);
|
bool nodeComparisonLess(Object* p1, Object* p2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class EventListener;
|
||||||
|
|
||||||
/** @brief Node is the main element. Anything that gets drawn or contains things that get drawn is a Node.
|
/** @brief Node is the main element. Anything that gets drawn or contains things that get drawn is a Node.
|
||||||
The most popular Nodes are: Scene, Layer, Sprite, Menu.
|
The most popular Nodes are: Scene, Layer, Sprite, Menu.
|
||||||
|
|
||||||
|
@ -134,7 +140,7 @@ public:
|
||||||
static const int INVALID_TAG = -1;
|
static const int INVALID_TAG = -1;
|
||||||
|
|
||||||
/// @{
|
/// @{
|
||||||
/// @name Constructor, Distructor and Initializers
|
/// @name Constructor, Destructor and Initializers
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates and initializes a node.
|
* Allocates and initializes a node.
|
||||||
|
@ -205,7 +211,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int getZOrder() const;
|
virtual int getZOrder() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the real OpenGL Z vertex.
|
* Sets the real OpenGL Z vertex.
|
||||||
*
|
*
|
||||||
|
@ -1361,7 +1366,23 @@ public:
|
||||||
virtual void removeAllComponents();
|
virtual void removeAllComponents();
|
||||||
/// @} end of component functions
|
/// @} end of component functions
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Director;
|
||||||
|
friend class EventDispatcher;
|
||||||
|
|
||||||
|
int getEventPriority() const { return _eventPriority; };
|
||||||
|
|
||||||
|
void associateEventListener(EventListener* listener);
|
||||||
|
void dissociateEventListener(EventListener* listener);
|
||||||
|
|
||||||
|
static void resetEventPriorityIndex();
|
||||||
|
std::set<EventListener*> _eventlisteners;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
inline void updateEventPriorityIndex() { _eventPriority = ++_globalEventPriorityIndex; };
|
||||||
|
|
||||||
/// lazy allocs
|
/// lazy allocs
|
||||||
void childrenAlloc(void);
|
void childrenAlloc(void);
|
||||||
|
|
||||||
|
@ -1439,6 +1460,8 @@ protected:
|
||||||
|
|
||||||
ComponentContainer *_componentContainer; ///< Dictionary of components
|
ComponentContainer *_componentContainer; ///< Dictionary of components
|
||||||
|
|
||||||
|
int _eventPriority;
|
||||||
|
static int _globalEventPriorityIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
//#pragma mark - NodeRGBA
|
//#pragma mark - NodeRGBA
|
||||||
|
|
|
@ -369,12 +369,12 @@ bool Rect::equals(const Rect& rect) const
|
||||||
|
|
||||||
float Rect::getMaxX() const
|
float Rect::getMaxX() const
|
||||||
{
|
{
|
||||||
return (float)(origin.x + size.width);
|
return origin.x + size.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Rect::getMidX() const
|
float Rect::getMidX() const
|
||||||
{
|
{
|
||||||
return (float)(origin.x + size.width / 2.0);
|
return origin.x + size.width / 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Rect::getMinX() const
|
float Rect::getMinX() const
|
||||||
|
@ -389,7 +389,7 @@ float Rect::getMaxY() const
|
||||||
|
|
||||||
float Rect::getMidY() const
|
float Rect::getMidY() const
|
||||||
{
|
{
|
||||||
return (float)(origin.y + size.height / 2.0);
|
return origin.y + size.height / 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Rect::getMinY() const
|
float Rect::getMinY() const
|
||||||
|
|
|
@ -41,7 +41,6 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
class Object;
|
class Object;
|
||||||
class Node;
|
class Node;
|
||||||
class Event;
|
|
||||||
|
|
||||||
/** Interface that defines how to clone an object */
|
/** Interface that defines how to clone an object */
|
||||||
class CC_DLL Clonable
|
class CC_DLL Clonable
|
||||||
|
@ -193,7 +192,6 @@ typedef void (Object::*SEL_CallFuncN)(Node*);
|
||||||
typedef void (Object::*SEL_CallFuncND)(Node*, void*);
|
typedef void (Object::*SEL_CallFuncND)(Node*, void*);
|
||||||
typedef void (Object::*SEL_CallFuncO)(Object*);
|
typedef void (Object::*SEL_CallFuncO)(Object*);
|
||||||
typedef void (Object::*SEL_MenuHandler)(Object*);
|
typedef void (Object::*SEL_MenuHandler)(Object*);
|
||||||
typedef void (Object::*SEL_EventHandler)(Event*);
|
|
||||||
typedef int (Object::*SEL_Compare)(Object*);
|
typedef int (Object::*SEL_Compare)(Object*);
|
||||||
|
|
||||||
#define schedule_selector(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)
|
#define schedule_selector(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCAccelerationEvent.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
const char* AccelerationEvent::EVENT_TYPE = "AccelerometerEvent";
|
||||||
|
|
||||||
|
AccelerationEvent::AccelerationEvent()
|
||||||
|
: Event(EVENT_TYPE)
|
||||||
|
{}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,44 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __cocos2d_libs__CCAccelerometerEvent__
|
||||||
|
#define __cocos2d_libs__CCAccelerometerEvent__
|
||||||
|
|
||||||
|
#include "CCEvent.h"
|
||||||
|
#include "ccTypes.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class AccelerationEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const char* EVENT_TYPE;
|
||||||
|
|
||||||
|
AccelerationEvent();
|
||||||
|
Acceleration acc;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* defined(__cocos2d_libs__CCAccelerometerEvent__) */
|
|
@ -0,0 +1,94 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCAccelerationEventListener.h"
|
||||||
|
#include "CCAccelerationEvent.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
AccelerationEventListener::AccelerationEventListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AccelerationEventListener::~AccelerationEventListener()
|
||||||
|
{
|
||||||
|
CCLOGINFO("In the destructor of AccelerationEventListener. %p", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
AccelerationEventListener* AccelerationEventListener::create(std::function<void(Acceleration*, Event* event)> callback)
|
||||||
|
{
|
||||||
|
AccelerationEventListener* ret = new AccelerationEventListener();
|
||||||
|
if (ret && ret->init(callback))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AccelerationEventListener::init(std::function<void(Acceleration*, Event* event)> callback)
|
||||||
|
{
|
||||||
|
auto listener = [this](Event* event){
|
||||||
|
auto accEvent = static_cast<AccelerationEvent*>(event);
|
||||||
|
this->onAccelerationEvent(&accEvent->acc, event);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (EventListener::init(AccelerationEvent::EVENT_TYPE, listener))
|
||||||
|
{
|
||||||
|
onAccelerationEvent = callback;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccelerationEventListener* AccelerationEventListener::clone()
|
||||||
|
{
|
||||||
|
auto ret = new AccelerationEventListener();
|
||||||
|
|
||||||
|
if (ret && ret->init(onAccelerationEvent))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AccelerationEventListener::checkAvaiable()
|
||||||
|
{
|
||||||
|
CCASSERT(onAccelerationEvent, "");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,50 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __cocos2d_libs__CCAccelerometerListener__
|
||||||
|
#define __cocos2d_libs__CCAccelerometerListener__
|
||||||
|
|
||||||
|
#include "CCEventListener.h"
|
||||||
|
#include "ccTypes.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class AccelerationEventListener : public EventListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static AccelerationEventListener* create(std::function<void(Acceleration*, Event* event)> callback);
|
||||||
|
virtual AccelerationEventListener* clone() override;
|
||||||
|
|
||||||
|
~AccelerationEventListener();
|
||||||
|
private:
|
||||||
|
AccelerationEventListener();
|
||||||
|
virtual bool checkAvaiable() override;
|
||||||
|
|
||||||
|
bool init(std::function<void(Acceleration*, Event* event)> callback);
|
||||||
|
std::function<void(Acceleration*, Event*)> onAccelerationEvent;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* defined(__cocos2d_libs__CCAccelerometerListener__) */
|
|
@ -0,0 +1,50 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCEvent.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
Event::Event(const std::string& type)
|
||||||
|
: _type(type)
|
||||||
|
, _isStopped(false)
|
||||||
|
, _currentTarget(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Event::~Event()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Node* Event::getCurrentTarget()
|
||||||
|
{
|
||||||
|
return _currentTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Event::setCurrentTarget(Node* target)
|
||||||
|
{
|
||||||
|
_currentTarget = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,80 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __CCEVENT_H__
|
||||||
|
#define __CCEVENT_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "platform/CCPlatformMacros.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class of all kinds of events.
|
||||||
|
*/
|
||||||
|
class Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Constructor */
|
||||||
|
Event(const std::string& type);
|
||||||
|
|
||||||
|
/** Destructor */
|
||||||
|
virtual ~Event();
|
||||||
|
|
||||||
|
/** Gets the event type */
|
||||||
|
const std::string& getType() const { return _type; };
|
||||||
|
|
||||||
|
/** Stops propagation for current event */
|
||||||
|
void stopPropagation() { _isStopped = true; };
|
||||||
|
|
||||||
|
/** Checks whether the event has been stopped */
|
||||||
|
bool isStopped() const { return _isStopped; };
|
||||||
|
|
||||||
|
/** @brief Gets current target of the event
|
||||||
|
* @return The target with which the event associates.
|
||||||
|
* @note It onlys be available when the event listener is associated with node.
|
||||||
|
* It returns 0 when the listener is associated with fixed priority.
|
||||||
|
*/
|
||||||
|
Node* getCurrentTarget();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Sets current target */
|
||||||
|
void setCurrentTarget(Node* target);
|
||||||
|
|
||||||
|
std::string _type; /// Event type
|
||||||
|
bool _isStopped; /// whether the event has been stopped.
|
||||||
|
Node* _currentTarget; /// Current target
|
||||||
|
|
||||||
|
friend class EventDispatcher;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __CCEVENT_H__
|
|
@ -0,0 +1,610 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "CCEventDispatcher.h"
|
||||||
|
#include "CCEvent.h"
|
||||||
|
#include "CCTouchEvent.h"
|
||||||
|
#include "CCTouchEventListener.h"
|
||||||
|
#include "base_nodes/CCNode.h"
|
||||||
|
#include "CCDirector.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
#define DUMP_LISTENER_ITEM_PRIORITY_INFO 0
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
class DispatchGuard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DispatchGuard(int& count):
|
||||||
|
_count(count)
|
||||||
|
{
|
||||||
|
++_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
~DispatchGuard()
|
||||||
|
{
|
||||||
|
--_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int& _count;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
EventDispatcher::EventDispatcher()
|
||||||
|
: _inDispatch(0)
|
||||||
|
, _listeners(nullptr)
|
||||||
|
, _isEnabled(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EventDispatcher::~EventDispatcher()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EventDispatcher* EventDispatcher::getInstance()
|
||||||
|
{
|
||||||
|
static EventDispatcher _instance;
|
||||||
|
return &_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::addEventListenerWithItem(EventListenerItem* item)
|
||||||
|
{
|
||||||
|
if (!_listeners)
|
||||||
|
{
|
||||||
|
_listeners = new std::map<std::string, std::vector<EventListenerItem*>*>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<EventListenerItem*>* listenerList = nullptr;
|
||||||
|
|
||||||
|
auto itr = _listeners->find(item->listener->type);
|
||||||
|
if (itr == _listeners->end())
|
||||||
|
{
|
||||||
|
listenerList = new std::vector<EventListenerItem*>();
|
||||||
|
listenerList->reserve(100);
|
||||||
|
_listeners->insert(std::make_pair(item->listener->type, listenerList));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listenerList = itr->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
listenerList->insert(listenerList->begin(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* listener, Node* node)
|
||||||
|
{
|
||||||
|
CCASSERT(!listener->_isRegistered, "The listener has been registered.");
|
||||||
|
|
||||||
|
if (!listener->checkAvaiable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto item = new EventListenerItem();
|
||||||
|
item->node = node;
|
||||||
|
item->fixedPriority = 0;
|
||||||
|
item->listener = listener;
|
||||||
|
item->listener->retain();
|
||||||
|
item->listener->_isRegistered = true;
|
||||||
|
|
||||||
|
addEventListenerWithItem(item);
|
||||||
|
|
||||||
|
_eventNodes.push_back(node);
|
||||||
|
node->associateEventListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener, int fixedPriority)
|
||||||
|
{
|
||||||
|
CCASSERT(!listener->_isRegistered, "The listener has been registered.");
|
||||||
|
|
||||||
|
if (!listener->checkAvaiable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto item = new EventListenerItem();
|
||||||
|
item->node = nullptr;
|
||||||
|
item->fixedPriority = fixedPriority;
|
||||||
|
item->listener = listener;
|
||||||
|
item->listener->retain();
|
||||||
|
item->listener->_isRegistered = true;
|
||||||
|
|
||||||
|
addEventListenerWithItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::removeEventListener(EventListener* listener)
|
||||||
|
{
|
||||||
|
if (_listeners == nullptr || listener == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto iter = _listeners->begin(); iter != _listeners->end();)
|
||||||
|
{
|
||||||
|
for (auto itemIter = iter->second->begin(); itemIter != iter->second->end(); ++itemIter)
|
||||||
|
{
|
||||||
|
if ((*itemIter)->listener == listener)
|
||||||
|
{
|
||||||
|
if (_inDispatch == 0)
|
||||||
|
{
|
||||||
|
(*itemIter)->listener->release();
|
||||||
|
delete (*itemIter);
|
||||||
|
iter->second->erase(itemIter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*itemIter)->listener = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iter->second->empty())
|
||||||
|
{
|
||||||
|
auto list = iter->second;
|
||||||
|
iter = _listeners->erase(iter);
|
||||||
|
CC_SAFE_DELETE(list);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_listeners->empty())
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(_listeners);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::setPriorityWithSceneGraph(EventListener* listener, Node* node)
|
||||||
|
{
|
||||||
|
if (_listeners == nullptr || listener == nullptr || node == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto iter = _listeners->begin(); iter != _listeners->end(); ++iter)
|
||||||
|
{
|
||||||
|
for (auto itemIter = iter->second->begin(); itemIter != iter->second->end(); ++itemIter)
|
||||||
|
{
|
||||||
|
auto item = *itemIter;
|
||||||
|
if (item->listener == listener)
|
||||||
|
{
|
||||||
|
item->fixedPriority = 0;
|
||||||
|
item->node = node;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::setPriorityWithFixedValue(EventListener* listener, int fixedPriority)
|
||||||
|
{
|
||||||
|
if (_listeners == nullptr || listener == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto iter = _listeners->begin(); iter != _listeners->end(); ++iter)
|
||||||
|
{
|
||||||
|
for (auto itemIter = iter->second->begin(); itemIter != iter->second->end(); ++itemIter)
|
||||||
|
{
|
||||||
|
auto item = *itemIter;
|
||||||
|
if (item->listener == listener)
|
||||||
|
{
|
||||||
|
item->fixedPriority = fixedPriority;
|
||||||
|
if (item->node != nullptr)
|
||||||
|
{
|
||||||
|
item->node->dissociateEventListener(listener);
|
||||||
|
item->node = nullptr;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::dispatchEvent(Event* event, bool toSortListeners)
|
||||||
|
{
|
||||||
|
if (_listeners == nullptr || !_isEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (toSortListeners)
|
||||||
|
sortAllEventListenerItemsForType(event->_type);
|
||||||
|
|
||||||
|
DispatchGuard guard(_inDispatch);
|
||||||
|
|
||||||
|
if (event->_type == TouchEvent::EVENT_TYPE)
|
||||||
|
{
|
||||||
|
dispatchTouchEvent(static_cast<TouchEvent*>(event));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_listeners)
|
||||||
|
{
|
||||||
|
auto iter = _listeners->find(event->getType());
|
||||||
|
if (iter != _listeners->end())
|
||||||
|
{
|
||||||
|
auto listenerList = iter->second;
|
||||||
|
for (auto& item : *listenerList)
|
||||||
|
{
|
||||||
|
CCASSERT(item, "listener item is invalid.");
|
||||||
|
|
||||||
|
event->setCurrentTarget(item->node);
|
||||||
|
item->listener->onEvent(event);
|
||||||
|
|
||||||
|
if (event->isStopped())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeUnregisteredListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::dispatchTouchEvent(TouchEvent* event)
|
||||||
|
{
|
||||||
|
auto touchListeners = getListenerItemsForType(TouchEvent::EVENT_TYPE);
|
||||||
|
if (touchListeners == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::vector<EventDispatcher::EventListenerItem*> oneByOnelisteners;
|
||||||
|
oneByOnelisteners.reserve(touchListeners->size());
|
||||||
|
|
||||||
|
std::vector<EventDispatcher::EventListenerItem*> allInOnelisteners;
|
||||||
|
allInOnelisteners.reserve(touchListeners->size());
|
||||||
|
|
||||||
|
TouchEventListener* touchEventListener = nullptr;
|
||||||
|
|
||||||
|
std::for_each(touchListeners->begin(), touchListeners->end(), [&](EventListenerItem*& item){
|
||||||
|
|
||||||
|
touchEventListener = static_cast<TouchEventListener*>(item->listener);
|
||||||
|
|
||||||
|
if (touchEventListener->_dispatchMode == Touch::DispatchMode::ONE_BY_ONE)
|
||||||
|
{
|
||||||
|
oneByOnelisteners.push_back(item);
|
||||||
|
}
|
||||||
|
else if (touchEventListener->_dispatchMode == Touch::DispatchMode::ALL_AT_ONCE)
|
||||||
|
{
|
||||||
|
allInOnelisteners.push_back(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCASSERT(false, "Not supported touch listener type.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bool isNeedsMutableSet = (oneByOnelisteners.size() > 0 && allInOnelisteners.size() > 0);
|
||||||
|
|
||||||
|
std::vector<Touch*> orignalTouches = event->getTouches();
|
||||||
|
std::vector<Touch*> mutableTouches(orignalTouches.size());
|
||||||
|
std::copy(orignalTouches.begin(), orignalTouches.end(), mutableTouches.begin());
|
||||||
|
|
||||||
|
//
|
||||||
|
// process the target handlers 1st
|
||||||
|
//
|
||||||
|
if (oneByOnelisteners.size() > 0)
|
||||||
|
{
|
||||||
|
auto mutableTouchesIter = mutableTouches.begin();
|
||||||
|
auto touchesIter = orignalTouches.begin();
|
||||||
|
|
||||||
|
for (; touchesIter != orignalTouches.end(); ++touchesIter)
|
||||||
|
{
|
||||||
|
bool isSwallowed = false;
|
||||||
|
|
||||||
|
for (auto& item : oneByOnelisteners)
|
||||||
|
{
|
||||||
|
// Skip if the listener was removed.
|
||||||
|
if (item->listener == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
event->setCurrentTarget(item->node);
|
||||||
|
|
||||||
|
bool isClaimed = false;
|
||||||
|
std::vector<Touch*>::iterator removedIter;
|
||||||
|
|
||||||
|
auto touchEventListener = static_cast<TouchEventListener*>(item->listener);
|
||||||
|
TouchEvent::EventCode eventCode = event->getEventCode();
|
||||||
|
|
||||||
|
if (eventCode == TouchEvent::EventCode::BEGAN)
|
||||||
|
{
|
||||||
|
if (touchEventListener->onTouchBegan)
|
||||||
|
{
|
||||||
|
isClaimed = touchEventListener->onTouchBegan(*touchesIter, event);
|
||||||
|
if (isClaimed)
|
||||||
|
{
|
||||||
|
touchEventListener->_claimedTouches.push_back(*touchesIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (touchEventListener->_claimedTouches.size() > 0
|
||||||
|
&& ((removedIter = std::find(touchEventListener->_claimedTouches.begin(), touchEventListener->_claimedTouches.end(), *touchesIter)) != touchEventListener->_claimedTouches.end()))
|
||||||
|
{
|
||||||
|
isClaimed = true;
|
||||||
|
|
||||||
|
switch (eventCode)
|
||||||
|
{
|
||||||
|
case TouchEvent::EventCode::MOVED:
|
||||||
|
if (touchEventListener->onTouchMoved)
|
||||||
|
{
|
||||||
|
touchEventListener->onTouchMoved(*touchesIter, event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TouchEvent::EventCode::ENDED:
|
||||||
|
if (touchEventListener->onTouchEnded)
|
||||||
|
{
|
||||||
|
touchEventListener->onTouchEnded(*touchesIter, event);
|
||||||
|
}
|
||||||
|
touchEventListener->_claimedTouches.erase(removedIter);
|
||||||
|
break;
|
||||||
|
case TouchEvent::EventCode::CANCELLED:
|
||||||
|
if (touchEventListener->onTouchCancelled)
|
||||||
|
{
|
||||||
|
touchEventListener->onTouchCancelled(*touchesIter, event);
|
||||||
|
}
|
||||||
|
touchEventListener->_claimedTouches.erase(removedIter);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CCASSERT(false, "The eventcode is invalid.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the event was stopped, return directly.
|
||||||
|
if (event->isStopped())
|
||||||
|
{
|
||||||
|
removeUnregisteredListeners();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCASSERT((*touchesIter)->getID() == (*mutableTouchesIter)->getID(), "");
|
||||||
|
|
||||||
|
if (isClaimed && touchEventListener->_needSwallow)
|
||||||
|
{
|
||||||
|
if (isNeedsMutableSet)
|
||||||
|
{
|
||||||
|
mutableTouchesIter = mutableTouches.erase(mutableTouchesIter);
|
||||||
|
isSwallowed = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSwallowed)
|
||||||
|
++mutableTouchesIter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// process standard handlers 2nd
|
||||||
|
//
|
||||||
|
if (allInOnelisteners.size() > 0 && mutableTouches.size() > 0)
|
||||||
|
{
|
||||||
|
for (auto& item : allInOnelisteners)
|
||||||
|
{
|
||||||
|
// Skip if the listener was removed.
|
||||||
|
if (item->listener == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
event->setCurrentTarget(item->node);
|
||||||
|
|
||||||
|
auto touchEventListener = static_cast<TouchEventListener*>(item->listener);
|
||||||
|
|
||||||
|
switch (event->getEventCode())
|
||||||
|
{
|
||||||
|
case TouchEvent::EventCode::BEGAN:
|
||||||
|
if (touchEventListener->onTouchesBegan)
|
||||||
|
{
|
||||||
|
touchEventListener->onTouchesBegan(mutableTouches, event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TouchEvent::EventCode::MOVED:
|
||||||
|
if (touchEventListener->onTouchesMoved)
|
||||||
|
{
|
||||||
|
touchEventListener->onTouchesMoved(mutableTouches, event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TouchEvent::EventCode::ENDED:
|
||||||
|
if (touchEventListener->onTouchesEnded)
|
||||||
|
{
|
||||||
|
touchEventListener->onTouchesEnded(mutableTouches, event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TouchEvent::EventCode::CANCELLED:
|
||||||
|
if (touchEventListener->onTouchesCancelled)
|
||||||
|
{
|
||||||
|
touchEventListener->onTouchesCancelled(mutableTouches, event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CCASSERT(false, "The eventcode is invalid.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the event was stopped, return directly.
|
||||||
|
if (event->isStopped())
|
||||||
|
{
|
||||||
|
removeUnregisteredListeners();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeUnregisteredListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::removeUnregisteredListeners()
|
||||||
|
{
|
||||||
|
if (!_listeners)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto listenerItemIter = _listeners->begin();
|
||||||
|
while (listenerItemIter != _listeners->end())
|
||||||
|
{
|
||||||
|
auto removeIterBegin = std::remove_if(listenerItemIter->second->begin(), listenerItemIter->second->end(), [](const EventListenerItem* item){
|
||||||
|
return item->listener == nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (auto iter = removeIterBegin; iter != listenerItemIter->second->end(); ++iter)
|
||||||
|
{
|
||||||
|
delete (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
listenerItemIter->second->erase(removeIterBegin, listenerItemIter->second->end());
|
||||||
|
|
||||||
|
if (listenerItemIter->second->empty())
|
||||||
|
{
|
||||||
|
delete listenerItemIter->second;
|
||||||
|
listenerItemIter = _listeners->erase(listenerItemIter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++listenerItemIter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_listeners->empty())
|
||||||
|
{
|
||||||
|
delete _listeners;
|
||||||
|
_listeners = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventType)
|
||||||
|
{
|
||||||
|
if (_listeners == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto listenerList = getListenerItemsForType(eventType);
|
||||||
|
|
||||||
|
if (listenerList == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// After sort: priority < 0, = 0, scene graph, > 0
|
||||||
|
std::sort(listenerList->begin(), listenerList->end(), [](const EventListenerItem* item1, const EventListenerItem* item2) {
|
||||||
|
|
||||||
|
// item1 and item2 are both using fixed priority.
|
||||||
|
if (nullptr == item1->node && nullptr == item2->node)
|
||||||
|
{
|
||||||
|
return item1->fixedPriority < item2->fixedPriority;
|
||||||
|
}
|
||||||
|
// item1 and item2 are both using scene graph based priority.
|
||||||
|
else if (nullptr != item1->node && nullptr != item2->node)
|
||||||
|
{
|
||||||
|
return item1->node->getEventPriority() > item2->node->getEventPriority();
|
||||||
|
}
|
||||||
|
else if (nullptr != item1->node && nullptr == item2->node)
|
||||||
|
{
|
||||||
|
return 0 < item2->fixedPriority;
|
||||||
|
}
|
||||||
|
else if (nullptr == item1->node && nullptr != item2->node)
|
||||||
|
{
|
||||||
|
return item1->fixedPriority <= 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCASSERT(false, "sort event node error...");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
#if DUMP_LISTENER_ITEM_PRIORITY_INFO
|
||||||
|
log("-----------------------------------");
|
||||||
|
for (auto& item : *listenerList)
|
||||||
|
{
|
||||||
|
log("listener item priority: node (%p), fixed (%d)", item->node, item->fixedPriority);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<EventDispatcher::EventListenerItem*>* EventDispatcher::getListenerItemsForType(const std::string &eventType)
|
||||||
|
{
|
||||||
|
if (_listeners != nullptr)
|
||||||
|
{
|
||||||
|
auto iter = _listeners->find(eventType);
|
||||||
|
if (iter != _listeners->end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::removeListenersForEventType(const std::string& eventType)
|
||||||
|
{
|
||||||
|
if (_listeners == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto listenerItemIter = _listeners->find(eventType);
|
||||||
|
if (listenerItemIter != _listeners->end())
|
||||||
|
{
|
||||||
|
for (auto iter = listenerItemIter->second->begin(); iter != listenerItemIter->second->end(); ++iter)
|
||||||
|
{
|
||||||
|
(*iter)->listener->release();
|
||||||
|
delete (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
listenerItemIter->second->clear();
|
||||||
|
|
||||||
|
delete listenerItemIter->second;
|
||||||
|
|
||||||
|
_listeners->erase(listenerItemIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::removeAllListeners()
|
||||||
|
{
|
||||||
|
if (_listeners == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto listenerItemIter = _listeners->begin(); listenerItemIter != _listeners->end(); ++listenerItemIter)
|
||||||
|
{
|
||||||
|
for (auto iter = listenerItemIter->second->begin(); iter != listenerItemIter->second->end(); ++iter)
|
||||||
|
{
|
||||||
|
(*iter)->listener->release();
|
||||||
|
delete (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
listenerItemIter->second->clear();
|
||||||
|
|
||||||
|
delete listenerItemIter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete _listeners;
|
||||||
|
_listeners = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDispatcher::setEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
_isEnabled = isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool EventDispatcher::isEnabled() const
|
||||||
|
{
|
||||||
|
return _isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,147 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __CC_EVENT_DISPATCHER_H__
|
||||||
|
#define __CC_EVENT_DISPATCHER_H__
|
||||||
|
|
||||||
|
#include "platform/CCPlatformMacros.h"
|
||||||
|
#include "CCEventListener.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class Event;
|
||||||
|
class TouchEvent;
|
||||||
|
class Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
This class manages event listener subscriptions
|
||||||
|
and event dispatching.
|
||||||
|
|
||||||
|
The EventListener list is managed in such a way that
|
||||||
|
event listeners can be added and removed even
|
||||||
|
from within an EventListener, while events are being
|
||||||
|
dispatched.
|
||||||
|
*/
|
||||||
|
class EventDispatcher
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Gets the singleton of EventDispatcher */
|
||||||
|
static EventDispatcher* getInstance();
|
||||||
|
|
||||||
|
/** Adds a event listener for a specified event with the priority of scene graph.
|
||||||
|
* @param listener The listener of a specified event.
|
||||||
|
* @param node The priority of the listener is based on the draw order of this node.
|
||||||
|
* @note The priority of scene graph will be fixed value 0. So the order of listener item
|
||||||
|
* in the vector will be ' <0, =0, scene graph, >0'.
|
||||||
|
*/
|
||||||
|
void addEventListenerWithSceneGraphPriority(EventListener* listener, Node* node);
|
||||||
|
|
||||||
|
/** Adds a event listener for a specified event with the fixed priority.
|
||||||
|
* @param listener The listener of a specified event.
|
||||||
|
* @param fixedPriority The fixed priority of the listener.
|
||||||
|
* @note A lower priority will be called before the ones that have a higher value.
|
||||||
|
*/
|
||||||
|
void addEventListenerWithFixedPriority(EventListener* listener, int fixedPriority);
|
||||||
|
|
||||||
|
/** Remove a listener
|
||||||
|
* @param listener The specified event listener which needs to be removed.
|
||||||
|
*/
|
||||||
|
void removeEventListener(EventListener* listener);
|
||||||
|
|
||||||
|
/** Removes all listeners with the same event type */
|
||||||
|
void removeListenersForEventType(const std::string& eventType);
|
||||||
|
|
||||||
|
/** Removes all listeners */
|
||||||
|
void removeAllListeners();
|
||||||
|
|
||||||
|
/** Sets listener's priority with node's draw order. */
|
||||||
|
void setPriorityWithSceneGraph(EventListener* listener, Node* node);
|
||||||
|
|
||||||
|
/** Sets listener's priority with fixed value. */
|
||||||
|
void setPriorityWithFixedValue(EventListener* listener, int fixedPriority);
|
||||||
|
|
||||||
|
/** Whether to enable dispatching events */
|
||||||
|
void setEnabled(bool isEnabled);
|
||||||
|
|
||||||
|
/** Checks whether dispatching events is enabled */
|
||||||
|
bool isEnabled() const;
|
||||||
|
|
||||||
|
/** Dispatches the event
|
||||||
|
* Also removes all EventListeners marked for deletion from the
|
||||||
|
* event dispatcher list.
|
||||||
|
*/
|
||||||
|
void dispatchEvent(Event* event, bool toSortListeners = true);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** Destructor of EventDispatcher */
|
||||||
|
~EventDispatcher();
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct EventListenerItem
|
||||||
|
{
|
||||||
|
int fixedPriority; // The higher the number, the higher the priority
|
||||||
|
Node* node; // Weak reference.
|
||||||
|
EventListener* listener;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Constructor of EventDispatcher */
|
||||||
|
EventDispatcher();
|
||||||
|
|
||||||
|
/** Adds event listener with item */
|
||||||
|
void addEventListenerWithItem(EventListenerItem* item);
|
||||||
|
|
||||||
|
/** Touch event needs to be processed different with other events since it needs support ALL_AT_ONCE and ONE_BY_NONE mode. */
|
||||||
|
void dispatchTouchEvent(TouchEvent* event);
|
||||||
|
|
||||||
|
/** Gets event the listener list for the event type. */
|
||||||
|
std::vector<EventListenerItem*>* getListenerItemsForType(const std::string& eventType);
|
||||||
|
|
||||||
|
/** Sorts the listeners of specified type by priority */
|
||||||
|
void sortAllEventListenerItemsForType(const std::string& eventType);
|
||||||
|
|
||||||
|
/** Removes all listeners that have been unregistered. */
|
||||||
|
void removeUnregisteredListeners();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Listeners map.
|
||||||
|
*/
|
||||||
|
std::map<std::string, std::vector<EventListenerItem*>*>* _listeners;
|
||||||
|
|
||||||
|
int _inDispatch;
|
||||||
|
std::list<Node*> _eventNodes;
|
||||||
|
bool _isEnabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __CC_EVENT_DISPATCHER_H__
|
|
@ -0,0 +1,80 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCEventListener.h"
|
||||||
|
#include "platform/CCCommon.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
EventListener* EventListener::create(const std::string& eventType, std::function<void(Event*)> callback)
|
||||||
|
{
|
||||||
|
EventListener* ret = new EventListener();
|
||||||
|
if (ret && ret->init(eventType, callback))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventListener::EventListener()
|
||||||
|
{}
|
||||||
|
|
||||||
|
EventListener::~EventListener()
|
||||||
|
{
|
||||||
|
CCLOGINFO("In the destructor of EventListener. %p", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EventListener::init(const std::string& t, std::function<void(Event*)>callback)
|
||||||
|
{
|
||||||
|
onEvent = callback;
|
||||||
|
type = t;
|
||||||
|
_isRegistered = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EventListener::checkAvaiable()
|
||||||
|
{
|
||||||
|
return (onEvent != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventListener* EventListener::clone()
|
||||||
|
{
|
||||||
|
EventListener* ret = new EventListener();
|
||||||
|
if (ret && ret->init(type, onEvent))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,94 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef cocos2d_libs_EventListener_h
|
||||||
|
#define cocos2d_libs_EventListener_h
|
||||||
|
|
||||||
|
#include "platform/CCPlatformMacros.h"
|
||||||
|
#include "cocoa/CCObject.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base class of event listener.
|
||||||
|
* If you need custom listener which with different callback, you need to inherit this class.
|
||||||
|
* For instance, you could refer to AccelerationEventListener, KeyboardEventListener or TouchEventListener.
|
||||||
|
* Usage:
|
||||||
|
* auto dispatcher = EventDispatcher::getInstance();
|
||||||
|
* Adds a listener:
|
||||||
|
*
|
||||||
|
* auto callback = [](Event* event){ do_some_thing(); };
|
||||||
|
* auto listener = EventListener::create("your_event_type", callback);
|
||||||
|
* dispatcher->addEventListenerWithSceneGraphPriority(listener, one_node);
|
||||||
|
*
|
||||||
|
* Dispatchs a custom event:
|
||||||
|
*
|
||||||
|
* Event event("your_event_type");
|
||||||
|
* dispatcher->dispatchEvent(&event);
|
||||||
|
*
|
||||||
|
* Removes a listener
|
||||||
|
*
|
||||||
|
* dispatcher->removeListener(listener);
|
||||||
|
*/
|
||||||
|
class EventListener : public Object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Creates an event listener with type and callback.
|
||||||
|
* @param eventType The type of the event.
|
||||||
|
* @param callback The callback function when the specified event was emitted.
|
||||||
|
*/
|
||||||
|
static EventListener* create(const std::string& eventType, std::function<void(Event*)> callback);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Constructor */
|
||||||
|
EventListener();
|
||||||
|
|
||||||
|
/** Initializes event with type and callback function */
|
||||||
|
bool init(const std::string& t, std::function<void(Event*)>callback);
|
||||||
|
public:
|
||||||
|
/** Destructor */
|
||||||
|
virtual ~EventListener();
|
||||||
|
|
||||||
|
/** Checks whether the listener is available. */
|
||||||
|
virtual bool checkAvaiable();
|
||||||
|
|
||||||
|
/** Clones the listener, its subclasses have to override this method. */
|
||||||
|
virtual EventListener* clone();
|
||||||
|
protected:
|
||||||
|
std::function<void(Event*)> onEvent; /// Event callback function
|
||||||
|
std::string type; /// Event type
|
||||||
|
bool _isRegistered; /// Whether the listener has been added to dispatcher.
|
||||||
|
|
||||||
|
friend class EventDispatcher;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,32 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCKeyboardEvent.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
const char* KeyboardEvent::EVENT_TYPE = "KeyboardEvent";
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,208 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __cocos2d_libs__CCKeyboardEvent__
|
||||||
|
#define __cocos2d_libs__CCKeyboardEvent__
|
||||||
|
|
||||||
|
#include "CCEvent.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class KeyboardEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* The key (code).
|
||||||
|
*/
|
||||||
|
enum class KeyCode
|
||||||
|
{
|
||||||
|
KEY_NONE = 0,
|
||||||
|
KEY_PAUSE = 0x0013,
|
||||||
|
KEY_SCROLL_LOCK = 0x1014,
|
||||||
|
KEY_PRINT = 0x1061,
|
||||||
|
KEY_SYSREQ = 0x106A,
|
||||||
|
KEY_BREAK = 0x106B,
|
||||||
|
KEY_ESCAPE = 0x001B,
|
||||||
|
KEY_BACKSPACE = 0x0008,
|
||||||
|
KEY_TAB = 0x0009,
|
||||||
|
KEY_BACK_TAB = 0x0089,
|
||||||
|
KEY_RETURN = 0x000D,
|
||||||
|
KEY_CAPS_LOCK = 0x00E5,
|
||||||
|
KEY_SHIFT = 0x00E1,
|
||||||
|
KEY_CTRL = 0x00E3,
|
||||||
|
KEY_ALT = 0x00E9,
|
||||||
|
KEY_MENU = 0x1067,
|
||||||
|
KEY_HYPER = 0x10ED,
|
||||||
|
KEY_INSERT = 0x1063,
|
||||||
|
KEY_HOME = 0x1050,
|
||||||
|
KEY_PG_UP = 0x1055,
|
||||||
|
KEY_DELETE = 0x10FF,
|
||||||
|
KEY_END = 0x1057,
|
||||||
|
KEY_PG_DOWN = 0x1056,
|
||||||
|
KEY_LEFT_ARROW = 0x1051,
|
||||||
|
KEY_RIGHT_ARROW = 0x1053,
|
||||||
|
KEY_UP_ARROW = 0x1052,
|
||||||
|
KEY_DOWN_ARROW = 0x1054,
|
||||||
|
KEY_NUM_LOCK = 0x107F,
|
||||||
|
KEY_KP_PLUS = 0x10AB,
|
||||||
|
KEY_KP_MINUS = 0x10AD,
|
||||||
|
KEY_KP_MULTIPLY = 0x10AA,
|
||||||
|
KEY_KP_DIVIDE = 0x10AF,
|
||||||
|
KEY_KP_ENTER = 0x108D,
|
||||||
|
KEY_KP_HOME = 0x10B7,
|
||||||
|
KEY_KP_UP = 0x10B8,
|
||||||
|
KEY_KP_PG_UP = 0x10B9,
|
||||||
|
KEY_KP_LEFT = 0x10B4,
|
||||||
|
KEY_KP_FIVE = 0x10B5,
|
||||||
|
KEY_KP_RIGHT = 0x10B6,
|
||||||
|
KEY_KP_END = 0x10B1,
|
||||||
|
KEY_KP_DOWN = 0x10B2,
|
||||||
|
KEY_KP_PG_DOWN = 0x10B3,
|
||||||
|
KEY_KP_INSERT = 0x10B0,
|
||||||
|
KEY_KP_DELETE = 0x10AE,
|
||||||
|
KEY_F1 = 0x00BE,
|
||||||
|
KEY_F2 = 0x00BF,
|
||||||
|
KEY_F3 = 0x00C0,
|
||||||
|
KEY_F4 = 0x00C1,
|
||||||
|
KEY_F5 = 0x00C2,
|
||||||
|
KEY_F6 = 0x00C3,
|
||||||
|
KEY_F7 = 0x00C4,
|
||||||
|
KEY_F8 = 0x00C5,
|
||||||
|
KEY_F9 = 0x00C6,
|
||||||
|
KEY_F10 = 0x00C7,
|
||||||
|
KEY_F11 = 0x00C8,
|
||||||
|
KEY_F12 = 0x00C9,
|
||||||
|
KEY_SPACE = ' ',
|
||||||
|
KEY_EXCLAM = '!',
|
||||||
|
KEY_QUOTE = '"',
|
||||||
|
KEY_NUMBER = '#',
|
||||||
|
KEY_DOLLAR = '$',
|
||||||
|
KEY_PERCENT = '%',
|
||||||
|
KEY_CIRCUMFLEX = '^',
|
||||||
|
KEY_AMPERSAND = '&',
|
||||||
|
KEY_APOSTROPHE = '\'',
|
||||||
|
KEY_LEFT_PARENTHESIS = '(',
|
||||||
|
KEY_RIGHT_PARENTHESIS = ')',
|
||||||
|
KEY_ASTERISK = '*',
|
||||||
|
KEY_PLUS = '+',
|
||||||
|
KEY_COMMA = ',',
|
||||||
|
KEY_MINUS = '-',
|
||||||
|
KEY_PERIOD = '.',
|
||||||
|
KEY_SLASH = '/',
|
||||||
|
KEY_0 = '0',
|
||||||
|
KEY_1 = '1',
|
||||||
|
KEY_2 = '2',
|
||||||
|
KEY_3 = '3',
|
||||||
|
KEY_4 = '4',
|
||||||
|
KEY_5 = '5',
|
||||||
|
KEY_6 = '6',
|
||||||
|
KEY_7 = '7',
|
||||||
|
KEY_8 = '8',
|
||||||
|
KEY_9 = '9',
|
||||||
|
KEY_COLON = ':',
|
||||||
|
KEY_SEMICOLON = ';',
|
||||||
|
KEY_LESS_THAN = '<',
|
||||||
|
KEY_EQUAL = '=',
|
||||||
|
KEY_GREATER_THAN = '>',
|
||||||
|
KEY_QUESTION = '?',
|
||||||
|
KEY_AT = '@',
|
||||||
|
KEY_CAPITAL_A = 'A',
|
||||||
|
KEY_CAPITAL_B = 'B',
|
||||||
|
KEY_CAPITAL_C = 'C',
|
||||||
|
KEY_CAPITAL_D = 'D',
|
||||||
|
KEY_CAPITAL_E = 'E',
|
||||||
|
KEY_CAPITAL_F = 'F',
|
||||||
|
KEY_CAPITAL_G = 'G',
|
||||||
|
KEY_CAPITAL_H = 'H',
|
||||||
|
KEY_CAPITAL_I = 'I',
|
||||||
|
KEY_CAPITAL_J = 'J',
|
||||||
|
KEY_CAPITAL_K = 'K',
|
||||||
|
KEY_CAPITAL_L = 'L',
|
||||||
|
KEY_CAPITAL_M = 'M',
|
||||||
|
KEY_CAPITAL_N = 'N',
|
||||||
|
KEY_CAPITAL_O = 'O',
|
||||||
|
KEY_CAPITAL_P = 'P',
|
||||||
|
KEY_CAPITAL_Q = 'Q',
|
||||||
|
KEY_CAPITAL_R = 'R',
|
||||||
|
KEY_CAPITAL_S = 'S',
|
||||||
|
KEY_CAPITAL_T = 'T',
|
||||||
|
KEY_CAPITAL_U = 'U',
|
||||||
|
KEY_CAPITAL_V = 'V',
|
||||||
|
KEY_CAPITAL_W = 'W',
|
||||||
|
KEY_CAPITAL_X = 'X',
|
||||||
|
KEY_CAPITAL_Y = 'Y',
|
||||||
|
KEY_CAPITAL_Z = 'Z',
|
||||||
|
KEY_LEFT_BRACKET = '[',
|
||||||
|
KEY_BACK_SLASH = '\\',
|
||||||
|
KEY_RIGHT_BRACKET = ']',
|
||||||
|
KEY_UNDERSCORE = '_',
|
||||||
|
KEY_GRAVE = '`',
|
||||||
|
KEY_A = 'a',
|
||||||
|
KEY_B = 'b',
|
||||||
|
KEY_C = 'c',
|
||||||
|
KEY_D = 'd',
|
||||||
|
KEY_E = 'e',
|
||||||
|
KEY_F = 'f',
|
||||||
|
KEY_G = 'g',
|
||||||
|
KEY_H = 'h',
|
||||||
|
KEY_I = 'i',
|
||||||
|
KEY_J = 'j',
|
||||||
|
KEY_K = 'k',
|
||||||
|
KEY_L = 'l',
|
||||||
|
KEY_M = 'm',
|
||||||
|
KEY_N = 'n',
|
||||||
|
KEY_O = 'o',
|
||||||
|
KEY_P = 'p',
|
||||||
|
KEY_Q = 'q',
|
||||||
|
KEY_R = 'r',
|
||||||
|
KEY_S = 's',
|
||||||
|
KEY_T = 't',
|
||||||
|
KEY_U = 'u',
|
||||||
|
KEY_V = 'v',
|
||||||
|
KEY_W = 'w',
|
||||||
|
KEY_X = 'x',
|
||||||
|
KEY_Y = 'y',
|
||||||
|
KEY_Z = 'z',
|
||||||
|
KEY_LEFT_BRACE = '{',
|
||||||
|
KEY_BAR = '|',
|
||||||
|
KEY_RIGHT_BRACE = '}',
|
||||||
|
KEY_TILDE = '~',
|
||||||
|
KEY_EURO = 0x20AC,
|
||||||
|
KEY_POUND = 0x00A3,
|
||||||
|
KEY_YEN = 0x00A5,
|
||||||
|
KEY_MIDDLE_DOT = 0x0095,
|
||||||
|
KEY_SEARCH = 0xFFAA
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* EVENT_TYPE;
|
||||||
|
|
||||||
|
KeyboardEvent() : Event(EVENT_TYPE) {};
|
||||||
|
KeyCode _keyCode;
|
||||||
|
bool _isPressed;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* defined(__cocos2d_libs__CCKeyboardEvent__) */
|
|
@ -0,0 +1,99 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCKeyboardEventListener.h"
|
||||||
|
#include "CCKeyboardEvent.h"
|
||||||
|
#include "ccMacros.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
bool KeyboardEventListener::checkAvaiable()
|
||||||
|
{
|
||||||
|
CCASSERT(onKeyPressed && onKeyReleased, "");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyboardEventListener* KeyboardEventListener::create()
|
||||||
|
{
|
||||||
|
auto ret = new KeyboardEventListener();
|
||||||
|
if (ret && ret->init())
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyboardEventListener* KeyboardEventListener::clone()
|
||||||
|
{
|
||||||
|
auto ret = new KeyboardEventListener();
|
||||||
|
if (ret && ret->init())
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
ret->onKeyPressed = onKeyPressed;
|
||||||
|
ret->onKeyReleased = onKeyReleased;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyboardEventListener::KeyboardEventListener()
|
||||||
|
: onKeyPressed(nullptr)
|
||||||
|
, onKeyReleased(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KeyboardEventListener::init()
|
||||||
|
{
|
||||||
|
auto listener = [this](Event* event){
|
||||||
|
auto keyboardEvent = static_cast<KeyboardEvent*>(event);
|
||||||
|
if (keyboardEvent->_isPressed)
|
||||||
|
{
|
||||||
|
if (onKeyPressed != nullptr)
|
||||||
|
onKeyPressed(keyboardEvent->_keyCode, event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (onKeyReleased != nullptr)
|
||||||
|
onKeyReleased(keyboardEvent->_keyCode, event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (EventListener::init(KeyboardEvent::EVENT_TYPE, listener))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,53 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __cocos2d_libs__CCKeyboardEventListener__
|
||||||
|
#define __cocos2d_libs__CCKeyboardEventListener__
|
||||||
|
|
||||||
|
#include "CCEventListener.h"
|
||||||
|
#include "CCKeyboardEvent.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class Event;
|
||||||
|
|
||||||
|
class KeyboardEventListener : public EventListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static KeyboardEventListener* create();
|
||||||
|
virtual KeyboardEventListener* clone() override;
|
||||||
|
|
||||||
|
std::function<void(KeyboardEvent::KeyCode, Event* event)> onKeyPressed;
|
||||||
|
std::function<void(KeyboardEvent::KeyCode, Event* event)> onKeyReleased;
|
||||||
|
private:
|
||||||
|
KeyboardEventListener();
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
virtual bool checkAvaiable() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* defined(__cocos2d_libs__CCKeyboardEventListener__) */
|
|
@ -95,10 +95,6 @@ private:
|
||||||
Point _prevPoint;
|
Point _prevPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CC_DLL Event : public Object
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
// end of input group
|
// end of input group
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCTouchEvent.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
const char* TouchEvent::EVENT_TYPE = "TouchEvent";
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,74 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __cocos2d_libs__TouchEvent__
|
||||||
|
#define __cocos2d_libs__TouchEvent__
|
||||||
|
|
||||||
|
#include "CCEvent.h"
|
||||||
|
#include "event_dispatcher/CCTouch.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
#define TOUCH_PERF_DEBUG 1
|
||||||
|
|
||||||
|
class TouchEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const char* EVENT_TYPE;
|
||||||
|
static const int MAX_TOUCHES = 5;
|
||||||
|
|
||||||
|
enum class EventCode
|
||||||
|
{
|
||||||
|
BEGAN,
|
||||||
|
MOVED,
|
||||||
|
ENDED,
|
||||||
|
CANCELLED
|
||||||
|
};
|
||||||
|
|
||||||
|
TouchEvent()
|
||||||
|
: Event(EVENT_TYPE)
|
||||||
|
{
|
||||||
|
_touches.reserve(MAX_TOUCHES);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventCode getEventCode() { return _eventCode; };
|
||||||
|
std::vector<Touch*> getTouches() { return _touches; };
|
||||||
|
|
||||||
|
#if TOUCH_PERF_DEBUG
|
||||||
|
void setEventCode(EventCode eventCode) { _eventCode = eventCode; };
|
||||||
|
void setTouches(const std::vector<Touch*>& touches) { _touches = touches; };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventCode _eventCode;
|
||||||
|
std::vector<Touch*> _touches;
|
||||||
|
|
||||||
|
friend class EGLViewProtocol;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* defined(__cocos2d_libs__TouchEvent__) */
|
|
@ -0,0 +1,138 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "CCTouchEventListener.h"
|
||||||
|
#include "CCEventDispatcher.h"
|
||||||
|
#include "CCTouchEvent.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
TouchEventListener::TouchEventListener()
|
||||||
|
: onTouchBegan(nullptr)
|
||||||
|
, onTouchMoved(nullptr)
|
||||||
|
, onTouchEnded(nullptr)
|
||||||
|
, onTouchCancelled(nullptr)
|
||||||
|
, onTouchesBegan(nullptr)
|
||||||
|
, onTouchesMoved(nullptr)
|
||||||
|
, onTouchesEnded(nullptr)
|
||||||
|
, onTouchesCancelled(nullptr)
|
||||||
|
, _needSwallow(false)
|
||||||
|
, _dispatchMode(Touch::DispatchMode::ALL_AT_ONCE)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchEventListener::~TouchEventListener()
|
||||||
|
{
|
||||||
|
CCLOGINFO("In the destructor of TouchEventListener, %p", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchEventListener::init(Touch::DispatchMode mode)
|
||||||
|
{
|
||||||
|
if (EventListener::init(TouchEvent::EVENT_TYPE, nullptr))
|
||||||
|
{
|
||||||
|
_dispatchMode = mode;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchEventListener::setSwallowTouches(bool needSwallow)
|
||||||
|
{
|
||||||
|
CCASSERT(_dispatchMode == Touch::DispatchMode::ONE_BY_ONE, "Swallow touches only available in OneByOne mode.");
|
||||||
|
_needSwallow = needSwallow;
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchEventListener* TouchEventListener::create(Touch::DispatchMode mode)
|
||||||
|
{
|
||||||
|
auto ret = new TouchEventListener();
|
||||||
|
if (ret && ret->init(mode))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchEventListener::checkAvaiable()
|
||||||
|
{
|
||||||
|
if (_dispatchMode == Touch::DispatchMode::ALL_AT_ONCE)
|
||||||
|
{
|
||||||
|
if (onTouchesBegan == nullptr && onTouchesMoved == nullptr
|
||||||
|
&& onTouchesEnded == nullptr && onTouchesCancelled == nullptr)
|
||||||
|
{
|
||||||
|
CCASSERT(false, "Invalid TouchEventListener.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_dispatchMode == Touch::DispatchMode::ONE_BY_ONE)
|
||||||
|
{
|
||||||
|
if (onTouchBegan == nullptr && onTouchMoved == nullptr
|
||||||
|
&& onTouchEnded == nullptr && onTouchCancelled == nullptr)
|
||||||
|
{
|
||||||
|
CCASSERT(false, "Invalid TouchEventListener.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCASSERT(false, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchEventListener* TouchEventListener::clone()
|
||||||
|
{
|
||||||
|
auto ret = new TouchEventListener();
|
||||||
|
if (ret && ret->init(_dispatchMode))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
|
||||||
|
ret->onTouchBegan = onTouchBegan;
|
||||||
|
ret->onTouchMoved = onTouchMoved;
|
||||||
|
ret->onTouchEnded = onTouchEnded;
|
||||||
|
ret->onTouchCancelled = onTouchCancelled;
|
||||||
|
ret->onTouchesBegan = onTouchesBegan;
|
||||||
|
ret->onTouchesMoved = onTouchesMoved;
|
||||||
|
ret->onTouchesEnded = onTouchesEnded;
|
||||||
|
ret->onTouchesCancelled = onTouchesCancelled;
|
||||||
|
|
||||||
|
ret->_claimedTouches = _claimedTouches;
|
||||||
|
ret->_dispatchMode = _dispatchMode;
|
||||||
|
ret->_needSwallow = _needSwallow;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,72 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2013 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __cocos2d_libs__CCTouchEventListener__
|
||||||
|
#define __cocos2d_libs__CCTouchEventListener__
|
||||||
|
|
||||||
|
#include "CCEventListener.h"
|
||||||
|
#include "event_dispatcher/CCTouch.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class TouchEventListener : public EventListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static TouchEventListener* create(Touch::DispatchMode mode);
|
||||||
|
virtual TouchEventListener* clone() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TouchEventListener();
|
||||||
|
bool init(Touch::DispatchMode mode);
|
||||||
|
|
||||||
|
virtual ~TouchEventListener();
|
||||||
|
virtual bool checkAvaiable() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::function<bool(Touch*, Event*)> onTouchBegan;
|
||||||
|
std::function<void(Touch*, Event*)> onTouchMoved;
|
||||||
|
std::function<void(Touch*, Event*)> onTouchEnded;
|
||||||
|
std::function<void(Touch*, Event*)> onTouchCancelled;
|
||||||
|
|
||||||
|
std::function<void(const std::vector<Touch*>&, Event*)> onTouchesBegan;
|
||||||
|
std::function<void(const std::vector<Touch*>&, Event*)> onTouchesMoved;
|
||||||
|
std::function<void(const std::vector<Touch*>&, Event*)> onTouchesEnded;
|
||||||
|
std::function<void(const std::vector<Touch*>&, Event*)> onTouchesCancelled;
|
||||||
|
|
||||||
|
void setSwallowTouches(bool needSwallow);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Touch*> _claimedTouches;
|
||||||
|
bool _needSwallow;
|
||||||
|
Touch::DispatchMode _dispatchMode;
|
||||||
|
|
||||||
|
friend class EventDispatcher;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* defined(__cocos2d_libs__CCTouchEventListener__) */
|
|
@ -556,9 +556,9 @@ CC_DEPRECATED_ATTRIBUTE typedef IMEKeyboardNotificationInfo CCIMEKeyboardNotific
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef TextFieldDelegate CCTextFieldDelegate;
|
CC_DEPRECATED_ATTRIBUTE typedef TextFieldDelegate CCTextFieldDelegate;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef TextFieldTTF CCTextFieldTTF;
|
CC_DEPRECATED_ATTRIBUTE typedef TextFieldTTF CCTextFieldTTF;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef NotificationCenter CCNotificationCenter;
|
CC_DEPRECATED_ATTRIBUTE typedef NotificationCenter CCNotificationCenter;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef TargetedTouchDelegate CCTargetedTouchDelegate;
|
//CC_DEPRECATED_ATTRIBUTE typedef TargetedTouchDelegate CCTargetedTouchDelegate;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef StandardTouchDelegate CCStandardTouchDelegate;
|
//CC_DEPRECATED_ATTRIBUTE typedef StandardTouchDelegate CCStandardTouchDelegate;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef TouchDelegate CCTouchDelegate;
|
//CC_DEPRECATED_ATTRIBUTE typedef TouchDelegate CCTouchDelegate;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Image CCImage;
|
CC_DEPRECATED_ATTRIBUTE typedef Image CCImage;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef UserDefault CCUserDefault;
|
CC_DEPRECATED_ATTRIBUTE typedef UserDefault CCUserDefault;
|
||||||
|
|
||||||
|
@ -688,8 +688,7 @@ CC_DEPRECATED_ATTRIBUTE typedef LabelTTF CCLabelTTF;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef SpriteBatchNode CCSpriteBatchNode;
|
CC_DEPRECATED_ATTRIBUTE typedef SpriteBatchNode CCSpriteBatchNode;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef LabelBMFont CCLabelBMFont;
|
CC_DEPRECATED_ATTRIBUTE typedef LabelBMFont CCLabelBMFont;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Layer CCLayer;
|
CC_DEPRECATED_ATTRIBUTE typedef Layer CCLayer;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef TouchDelegate CCTouchDelegate;
|
//CC_DEPRECATED_ATTRIBUTE typedef KeypadDelegate CCKeypadDelegate;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef KeypadDelegate CCKeypadDelegate;
|
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef LayerRGBA CCLayerRGBA;
|
CC_DEPRECATED_ATTRIBUTE typedef LayerRGBA CCLayerRGBA;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef LayerColor CCLayerColor;
|
CC_DEPRECATED_ATTRIBUTE typedef LayerColor CCLayerColor;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef LayerGradient CCLayerGradient;
|
CC_DEPRECATED_ATTRIBUTE typedef LayerGradient CCLayerGradient;
|
||||||
|
|
|
@ -458,6 +458,20 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief The device accelerometer reports values for each axis in units of g-force
|
||||||
|
*/
|
||||||
|
class Acceleration
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
double z;
|
||||||
|
|
||||||
|
double timestamp;
|
||||||
|
|
||||||
|
Acceleration(): x(0), y(0), z(0), timestamp(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -91,10 +91,6 @@ THE SOFTWARE.
|
||||||
#include "kazmath/include/kazmath/kazmath.h"
|
#include "kazmath/include/kazmath/kazmath.h"
|
||||||
#include "kazmath/include/kazmath/GL/matrix.h"
|
#include "kazmath/include/kazmath/GL/matrix.h"
|
||||||
|
|
||||||
// keypad_dispatcher
|
|
||||||
#include "keypad_dispatcher/CCKeypadDelegate.h"
|
|
||||||
#include "keypad_dispatcher/CCKeypadDispatcher.h"
|
|
||||||
|
|
||||||
// label_nodes
|
// label_nodes
|
||||||
#include "label_nodes/CCLabelAtlas.h"
|
#include "label_nodes/CCLabelAtlas.h"
|
||||||
#include "label_nodes/CCLabelTTF.h"
|
#include "label_nodes/CCLabelTTF.h"
|
||||||
|
@ -135,7 +131,6 @@ THE SOFTWARE.
|
||||||
#include "platform/CCPlatformMacros.h"
|
#include "platform/CCPlatformMacros.h"
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
#include "platform/ios/CCAccelerometer.h"
|
|
||||||
#include "platform/ios/CCApplication.h"
|
#include "platform/ios/CCApplication.h"
|
||||||
#include "platform/ios/CCEGLView.h"
|
#include "platform/ios/CCEGLView.h"
|
||||||
#include "platform/ios/CCGL.h"
|
#include "platform/ios/CCGL.h"
|
||||||
|
@ -143,7 +138,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
#include "platform/android/CCAccelerometer.h"
|
|
||||||
#include "platform/android/CCApplication.h"
|
#include "platform/android/CCApplication.h"
|
||||||
#include "platform/android/CCEGLView.h"
|
#include "platform/android/CCEGLView.h"
|
||||||
#include "platform/android/CCGL.h"
|
#include "platform/android/CCGL.h"
|
||||||
|
@ -151,7 +145,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY)
|
||||||
#include "platform/blackberry/CCAccelerometer.h"
|
|
||||||
#include "platform/blackberry/CCApplication.h"
|
#include "platform/blackberry/CCApplication.h"
|
||||||
#include "platform/blackberry/CCEGLView.h"
|
#include "platform/blackberry/CCEGLView.h"
|
||||||
#include "platform/blackberry/CCGL.h"
|
#include "platform/blackberry/CCGL.h"
|
||||||
|
@ -159,7 +152,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||||
#include "platform/win32/CCAccelerometer.h"
|
|
||||||
#include "platform/win32/CCApplication.h"
|
#include "platform/win32/CCApplication.h"
|
||||||
#include "platform/win32/CCEGLView.h"
|
#include "platform/win32/CCEGLView.h"
|
||||||
#include "platform/win32/CCGL.h"
|
#include "platform/win32/CCGL.h"
|
||||||
|
@ -167,7 +159,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||||
#include "platform/mac/CCAccelerometer.h"
|
|
||||||
#include "platform/mac/CCApplication.h"
|
#include "platform/mac/CCApplication.h"
|
||||||
#include "platform/mac/CCEGLView.h"
|
#include "platform/mac/CCEGLView.h"
|
||||||
#include "platform/mac/CCGL.h"
|
#include "platform/mac/CCGL.h"
|
||||||
|
@ -175,7 +166,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_MAC
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_MAC
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||||
#include "platform/linux/CCAccelerometer.h"
|
|
||||||
#include "platform/linux/CCApplication.h"
|
#include "platform/linux/CCApplication.h"
|
||||||
#include "platform/linux/CCEGLView.h"
|
#include "platform/linux/CCEGLView.h"
|
||||||
#include "platform/linux/CCGL.h"
|
#include "platform/linux/CCGL.h"
|
||||||
|
@ -185,7 +175,6 @@ THE SOFTWARE.
|
||||||
// MARMALADE CHANGE
|
// MARMALADE CHANGE
|
||||||
// Added for Marmalade support
|
// Added for Marmalade support
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
||||||
#include "platform/Marmalade/CCAccelerometer.h"
|
|
||||||
#include "platform/Marmalade/CCApplication.h"
|
#include "platform/Marmalade/CCApplication.h"
|
||||||
#include "platform/Marmalade/CCEGLView.h"
|
#include "platform/Marmalade/CCEGLView.h"
|
||||||
#include "platform/Marmalade/CCGL.h"
|
#include "platform/Marmalade/CCGL.h"
|
||||||
|
@ -193,7 +182,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_NACL)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_NACL)
|
||||||
#include "platform/nacl/CCAccelerometer.h"
|
|
||||||
#include "platform/nacl/CCApplication.h"
|
#include "platform/nacl/CCApplication.h"
|
||||||
#include "platform/nacl/CCEGLView.h"
|
#include "platform/nacl/CCEGLView.h"
|
||||||
#include "platform/nacl/CCGL.h"
|
#include "platform/nacl/CCGL.h"
|
||||||
|
@ -209,7 +197,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
||||||
#include "platform/tizen/CCAccelerometer.h"
|
|
||||||
#include "platform/tizen/CCApplication.h"
|
#include "platform/tizen/CCApplication.h"
|
||||||
#include "platform/tizen/CCEGLView.h"
|
#include "platform/tizen/CCEGLView.h"
|
||||||
#include "platform/tizen/CCGL.h"
|
#include "platform/tizen/CCGL.h"
|
||||||
|
@ -217,7 +204,6 @@ THE SOFTWARE.
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_QT5)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_QT5)
|
||||||
#include "platform/qt5/CCAccelerometer.h"
|
|
||||||
#include "platform/qt5/CCApplication.h"
|
#include "platform/qt5/CCApplication.h"
|
||||||
#include "platform/qt5/CCEGLView.h"
|
#include "platform/qt5/CCEGLView.h"
|
||||||
#include "platform/qt5/CCGL.h"
|
#include "platform/qt5/CCGL.h"
|
||||||
|
@ -267,11 +253,14 @@ THE SOFTWARE.
|
||||||
#include "tilemap_parallax_nodes/CCTMXXMLParser.h"
|
#include "tilemap_parallax_nodes/CCTMXXMLParser.h"
|
||||||
#include "tilemap_parallax_nodes/CCTileMapAtlas.h"
|
#include "tilemap_parallax_nodes/CCTileMapAtlas.h"
|
||||||
|
|
||||||
// touch_dispatcher
|
// EventDispatcher
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
#include "touch_dispatcher/CCTouchDelegateProtocol.h"
|
#include "event_dispatcher/CCTouchEventListener.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
#include "event_dispatcher/CCTouchEvent.h"
|
||||||
#include "touch_dispatcher/CCTouchHandler.h"
|
#include "event_dispatcher/CCKeyboardEventListener.h"
|
||||||
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
|
#include "event_dispatcher/CCAccelerationEvent.h"
|
||||||
|
#include "event_dispatcher/CCAccelerationEventListener.h"
|
||||||
|
|
||||||
// root
|
// root
|
||||||
#include "CCCamera.h"
|
#include "CCCamera.h"
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "CCKeyboardDispatcher.h"
|
|
||||||
#include "support/data_support/ccCArray.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// KeyboardDispatcher
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
KeyboardDispatcher::KeyboardDispatcher()
|
|
||||||
: _keyPressDelegate(nullptr)
|
|
||||||
, _keyReleaseDelegate(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyboardDispatcher::~KeyboardDispatcher()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeyboardDispatcher::setKeyPressDelegate(KeyboardDelegate delegate)
|
|
||||||
{
|
|
||||||
_keyPressDelegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeyboardDispatcher::setKeyReleaseDelegate(KeyboardDelegate delegate)
|
|
||||||
{
|
|
||||||
_keyReleaseDelegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeyboardDispatcher::dispatchKeyboardEvent(int keyCode, bool pressed)
|
|
||||||
{
|
|
||||||
if (_keyPressDelegate != nullptr && pressed)
|
|
||||||
{
|
|
||||||
_keyPressDelegate(keyCode);
|
|
||||||
}
|
|
||||||
else if (_keyReleaseDelegate != nullptr )
|
|
||||||
{
|
|
||||||
_keyReleaseDelegate(keyCode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
|
@ -1,91 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "CCKeypadDelegate.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// KeypadHandler
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
KeypadDelegate* KeypadHandler::getDelegate()
|
|
||||||
{
|
|
||||||
return _delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
KeypadHandler::~KeypadHandler()
|
|
||||||
{
|
|
||||||
if (_delegate)
|
|
||||||
{
|
|
||||||
dynamic_cast<Object*>(_delegate)->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeypadHandler::setDelegate(KeypadDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
if (pDelegate)
|
|
||||||
{
|
|
||||||
dynamic_cast<Object*>(pDelegate)->retain();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_delegate)
|
|
||||||
{
|
|
||||||
dynamic_cast<Object*>(_delegate)->release();
|
|
||||||
}
|
|
||||||
_delegate = pDelegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeypadHandler::initWithDelegate(KeypadDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
CCASSERT(pDelegate != NULL, "It's a wrong delegate!");
|
|
||||||
|
|
||||||
_delegate = pDelegate;
|
|
||||||
dynamic_cast<Object*>(pDelegate)->retain();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
KeypadHandler* KeypadHandler::handlerWithDelegate(KeypadDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
KeypadHandler* pHandler = new KeypadHandler;
|
|
||||||
|
|
||||||
if (pHandler)
|
|
||||||
{
|
|
||||||
if (pHandler->initWithDelegate(pDelegate))
|
|
||||||
{
|
|
||||||
pHandler->autorelease();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(pHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
|
@ -1,176 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "CCKeypadDispatcher.h"
|
|
||||||
#include "support/data_support/ccCArray.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// KeypadDispatcher
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
KeypadDispatcher::KeypadDispatcher()
|
|
||||||
: _locked(false)
|
|
||||||
, _toAdd(false)
|
|
||||||
, _toRemove(false)
|
|
||||||
{
|
|
||||||
_delegates = Array::create();
|
|
||||||
_delegates->retain();
|
|
||||||
|
|
||||||
_handlersToAdd = ccCArrayNew(8);
|
|
||||||
_handlersToRemove = ccCArrayNew(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
KeypadDispatcher::~KeypadDispatcher()
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE(_delegates);
|
|
||||||
if (_handlersToAdd)
|
|
||||||
{
|
|
||||||
ccCArrayFree(_handlersToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_handlersToRemove)
|
|
||||||
{
|
|
||||||
ccCArrayFree(_handlersToRemove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeypadDispatcher::removeDelegate(KeypadDelegate* pDelegate)
|
|
||||||
{
|
|
||||||
if (!pDelegate)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (! _locked)
|
|
||||||
{
|
|
||||||
forceRemoveDelegate(pDelegate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ccCArrayAppendValue(_handlersToRemove, pDelegate);
|
|
||||||
_toRemove = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeypadDispatcher::addDelegate(KeypadDelegate* pDelegate)
|
|
||||||
{
|
|
||||||
if (!pDelegate)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! _locked)
|
|
||||||
{
|
|
||||||
forceAddDelegate(pDelegate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ccCArrayAppendValue(_handlersToAdd, pDelegate);
|
|
||||||
_toAdd = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeypadDispatcher::forceAddDelegate(KeypadDelegate* pDelegate)
|
|
||||||
{
|
|
||||||
KeypadHandler* pHandler = KeypadHandler::handlerWithDelegate(pDelegate);
|
|
||||||
|
|
||||||
if (pHandler)
|
|
||||||
{
|
|
||||||
_delegates->addObject(pHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeypadDispatcher::forceRemoveDelegate(KeypadDelegate* pDelegate)
|
|
||||||
{
|
|
||||||
KeypadHandler* pHandler = NULL;
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(_delegates, pObj)
|
|
||||||
{
|
|
||||||
pHandler = static_cast<KeypadHandler*>(pObj);
|
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
|
||||||
{
|
|
||||||
_delegates->removeObject(pHandler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeypadDispatcher::dispatchKeypadMSG(ccKeypadMSGType nMsgType)
|
|
||||||
{
|
|
||||||
KeypadHandler* pHandler = NULL;
|
|
||||||
KeypadDelegate* pDelegate = NULL;
|
|
||||||
|
|
||||||
_locked = true;
|
|
||||||
|
|
||||||
if (_delegates->count() > 0)
|
|
||||||
{
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(_delegates, pObj)
|
|
||||||
{
|
|
||||||
CC_BREAK_IF(!pObj);
|
|
||||||
|
|
||||||
pHandler = static_cast<KeypadHandler*>(pObj);
|
|
||||||
pDelegate = pHandler->getDelegate();
|
|
||||||
|
|
||||||
switch (nMsgType)
|
|
||||||
{
|
|
||||||
case kTypeBackClicked:
|
|
||||||
pDelegate->keyBackClicked();
|
|
||||||
break;
|
|
||||||
case kTypeMenuClicked:
|
|
||||||
pDelegate->keyMenuClicked();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_locked = false;
|
|
||||||
if (_toRemove)
|
|
||||||
{
|
|
||||||
_toRemove = false;
|
|
||||||
for (int i = 0; i < _handlersToRemove->num; ++i)
|
|
||||||
{
|
|
||||||
forceRemoveDelegate((KeypadDelegate*)_handlersToRemove->arr[i]);
|
|
||||||
}
|
|
||||||
ccCArrayRemoveAllValues(_handlersToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_toAdd)
|
|
||||||
{
|
|
||||||
_toAdd = false;
|
|
||||||
for (int i = 0; i < _handlersToAdd->num; ++i)
|
|
||||||
{
|
|
||||||
forceAddDelegate((KeypadDelegate*)_handlersToAdd->arr[i]);
|
|
||||||
}
|
|
||||||
ccCArrayRemoveAllValues(_handlersToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
|
@ -26,9 +26,6 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "CCLayer.h"
|
#include "CCLayer.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
||||||
#include "keypad_dispatcher/CCKeypadDispatcher.h"
|
|
||||||
#include "CCAccelerometer.h"
|
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "script_support/CCScriptSupport.h"
|
#include "script_support/CCScriptSupport.h"
|
||||||
#include "shaders/CCShaderCache.h"
|
#include "shaders/CCShaderCache.h"
|
||||||
|
@ -37,7 +34,14 @@ THE SOFTWARE.
|
||||||
#include "support/TransformUtils.h"
|
#include "support/TransformUtils.h"
|
||||||
// extern
|
// extern
|
||||||
#include "kazmath/GL/matrix.h"
|
#include "kazmath/GL/matrix.h"
|
||||||
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCTouchEventListener.h"
|
||||||
|
#include "event_dispatcher/CCTouchEvent.h"
|
||||||
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
|
#include "event_dispatcher/CCKeyboardEventListener.h"
|
||||||
|
#include "event_dispatcher/CCAccelerationEvent.h"
|
||||||
|
#include "event_dispatcher/CCAccelerationEventListener.h"
|
||||||
|
#include "platform/CCDevice.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -46,10 +50,11 @@ Layer::Layer()
|
||||||
: _touchEnabled(false)
|
: _touchEnabled(false)
|
||||||
, _accelerometerEnabled(false)
|
, _accelerometerEnabled(false)
|
||||||
, _keyboardEnabled(false)
|
, _keyboardEnabled(false)
|
||||||
, _keypadEnabled(false)
|
|
||||||
, _touchPriority(0)
|
|
||||||
, _touchMode(Touch::DispatchMode::ALL_AT_ONCE)
|
, _touchMode(Touch::DispatchMode::ALL_AT_ONCE)
|
||||||
, _swallowsTouches(true)
|
, _swallowsTouches(true)
|
||||||
|
, _touchListener(nullptr)
|
||||||
|
, _keyboardListener(nullptr)
|
||||||
|
, _accelerationListener(nullptr)
|
||||||
{
|
{
|
||||||
_ignoreAnchorPointForPosition = true;
|
_ignoreAnchorPointForPosition = true;
|
||||||
setAnchorPoint(Point(0.5f, 0.5f));
|
setAnchorPoint(Point(0.5f, 0.5f));
|
||||||
|
@ -93,18 +98,35 @@ Layer *Layer::create()
|
||||||
|
|
||||||
/// Touch and Accelerometer related
|
/// Touch and Accelerometer related
|
||||||
|
|
||||||
void Layer::registerWithTouchDispatcher()
|
void Layer::onRegisterTouchListener()
|
||||||
{
|
{
|
||||||
TouchDispatcher* pDispatcher = Director::getInstance()->getTouchDispatcher();
|
|
||||||
|
|
||||||
if( _touchMode == Touch::DispatchMode::ALL_AT_ONCE ) {
|
if( _touchMode == Touch::DispatchMode::ALL_AT_ONCE ) {
|
||||||
pDispatcher->addStandardDelegate(this, 0);
|
// Register Touch Event
|
||||||
|
auto listener = TouchEventListener::create(Touch::DispatchMode::ALL_AT_ONCE);
|
||||||
|
|
||||||
|
listener->onTouchesBegan = CC_CALLBACK_2(Layer::onTouchesBegan, this);
|
||||||
|
listener->onTouchesMoved = CC_CALLBACK_2(Layer::onTouchesMoved, this);
|
||||||
|
listener->onTouchesEnded = CC_CALLBACK_2(Layer::onTouchesEnded, this);
|
||||||
|
listener->onTouchesCancelled = CC_CALLBACK_2(Layer::onTouchesCancelled, this);
|
||||||
|
|
||||||
|
EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
|
_touchListener = listener;
|
||||||
} else {
|
} else {
|
||||||
pDispatcher->addTargetedDelegate(this, _touchPriority, _swallowsTouches);
|
// Register Touch Event
|
||||||
|
auto listener = TouchEventListener::create(Touch::DispatchMode::ONE_BY_ONE);
|
||||||
|
listener->setSwallowTouches(_swallowsTouches);
|
||||||
|
|
||||||
|
listener->onTouchBegan = CC_CALLBACK_2(Layer::onTouchBegan, this);
|
||||||
|
listener->onTouchMoved = CC_CALLBACK_2(Layer::onTouchMoved, this);
|
||||||
|
listener->onTouchEnded = CC_CALLBACK_2(Layer::onTouchEnded, this);
|
||||||
|
listener->onTouchCancelled = CC_CALLBACK_2(Layer::onTouchCancelled, this);
|
||||||
|
|
||||||
|
EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
|
_touchListener = listener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Layer::executeScriptTouchHandler(int eventType, Touch* touch)
|
int Layer::executeScriptTouchHandler(TouchEvent::EventCode eventType, Touch* touch)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
|
@ -117,7 +139,7 @@ int Layer::executeScriptTouchHandler(int eventType, Touch* touch)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Layer::executeScriptTouchesHandler(int eventType, Set* touches)
|
int Layer::executeScriptTouchesHandler(TouchEvent::EventCode eventType, const std::vector<Touch*>& touches)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
|
@ -145,12 +167,12 @@ void Layer::setTouchEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
this->registerWithTouchDispatcher();
|
this->onRegisterTouchListener();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// have problems?
|
EventDispatcher::getInstance()->removeEventListener(_touchListener);
|
||||||
Director::getInstance()->getTouchDispatcher()->removeDelegate(this);
|
_touchListener = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,20 +192,6 @@ void Layer::setTouchMode(Touch::DispatchMode mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::setTouchPriority(int priority)
|
|
||||||
{
|
|
||||||
if (_touchPriority != priority)
|
|
||||||
{
|
|
||||||
_touchPriority = priority;
|
|
||||||
|
|
||||||
if( _touchEnabled)
|
|
||||||
{
|
|
||||||
setTouchEnabled(false);
|
|
||||||
setTouchEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layer::setSwallowsTouches(bool swallowsTouches)
|
void Layer::setSwallowsTouches(bool swallowsTouches)
|
||||||
{
|
{
|
||||||
if (_swallowsTouches != swallowsTouches)
|
if (_swallowsTouches != swallowsTouches)
|
||||||
|
@ -198,12 +206,6 @@ void Layer::setSwallowsTouches(bool swallowsTouches)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Layer::getTouchPriority() const
|
|
||||||
{
|
|
||||||
return _touchPriority;
|
|
||||||
}
|
|
||||||
|
|
||||||
Touch::DispatchMode Layer::getTouchMode() const
|
Touch::DispatchMode Layer::getTouchMode() const
|
||||||
{
|
{
|
||||||
return _touchMode;
|
return _touchMode;
|
||||||
|
@ -228,16 +230,18 @@ void Layer::setAccelerometerEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
_accelerometerEnabled = enabled;
|
_accelerometerEnabled = enabled;
|
||||||
|
|
||||||
|
Device::setAccelerometerEnabled(enabled);
|
||||||
|
|
||||||
if (_running)
|
if (_running)
|
||||||
{
|
{
|
||||||
Director* pDirector = Director::getInstance();
|
auto dispatcher = EventDispatcher::getInstance();
|
||||||
|
dispatcher->removeEventListener(_accelerationListener);
|
||||||
|
_accelerationListener = nullptr;
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(Layer::didAccelerate, this));
|
_accelerationListener = AccelerationEventListener::create(CC_CALLBACK_2(Layer::onAcceleration, this));
|
||||||
}
|
dispatcher->addEventListenerWithSceneGraphPriority(_accelerationListener, this);
|
||||||
else
|
|
||||||
{
|
|
||||||
pDirector->getAccelerometer()->setDelegate(nullptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,14 +253,13 @@ void Layer::setAccelerometerInterval(double interval) {
|
||||||
{
|
{
|
||||||
if (_running)
|
if (_running)
|
||||||
{
|
{
|
||||||
Director* pDirector = Director::getInstance();
|
Device::setAccelerometerInterval(interval);
|
||||||
pDirector->getAccelerometer()->setAccelerometerInterval(interval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Layer::didAccelerate(Acceleration* pAccelerationValue)
|
void Layer::onAcceleration(Acceleration* pAccelerationValue, Event* event)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pAccelerationValue);
|
CC_UNUSED_PARAM(pAccelerationValue);
|
||||||
|
|
||||||
|
@ -280,76 +283,30 @@ void Layer::setKeyboardEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
_keyboardEnabled = enabled;
|
_keyboardEnabled = enabled;
|
||||||
|
|
||||||
Director* pDirector = Director::getInstance();
|
auto dispatcher = EventDispatcher::getInstance();
|
||||||
|
dispatcher->removeEventListener(_keyboardListener);
|
||||||
|
_keyboardListener = nullptr;
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
pDirector->getKeyboardDispatcher()->setKeyPressDelegate( CC_CALLBACK_1(Layer::keyPressed, this) );
|
auto listener = KeyboardEventListener::create();
|
||||||
pDirector->getKeyboardDispatcher()->setKeyReleaseDelegate( CC_CALLBACK_1(Layer::keyReleased, this) );
|
listener->onKeyPressed = CC_CALLBACK_2(Layer::onKeyPressed, this);
|
||||||
|
listener->onKeyReleased = CC_CALLBACK_2(Layer::onKeyReleased, this);
|
||||||
|
|
||||||
|
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
|
_keyboardListener = listener;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
pDirector->getKeyboardDispatcher()->setKeyPressDelegate(nullptr);
|
|
||||||
pDirector->getKeyboardDispatcher()->setKeyReleaseDelegate(nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// isKeypadEnabled getter
|
|
||||||
bool Layer::isKeypadEnabled() const
|
|
||||||
{
|
|
||||||
return _keypadEnabled;
|
|
||||||
}
|
|
||||||
/// isKeypadEnabled setter
|
|
||||||
void Layer::setKeypadEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
if (enabled != _keypadEnabled)
|
|
||||||
{
|
|
||||||
_keypadEnabled = enabled;
|
|
||||||
|
|
||||||
if (_running)
|
|
||||||
{
|
|
||||||
Director* pDirector = Director::getInstance();
|
|
||||||
if (enabled)
|
|
||||||
{
|
|
||||||
pDirector->getKeypadDispatcher()->addDelegate(this);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pDirector->getKeypadDispatcher()->removeDelegate(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layer::keyBackClicked(void)
|
|
||||||
{
|
|
||||||
if (kScriptTypeNone != _scriptType)
|
|
||||||
{
|
|
||||||
KeypadScriptData data(kTypeBackClicked, this);
|
|
||||||
ScriptEvent event(kKeypadEvent,(void*)&data);
|
|
||||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layer::keyMenuClicked(void)
|
|
||||||
{
|
|
||||||
if (kScriptTypeLua == _scriptType)
|
|
||||||
{
|
|
||||||
KeypadScriptData data(kTypeMenuClicked, this);
|
|
||||||
ScriptEvent event(kKeypadEvent,(void*)&data);
|
|
||||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Callbacks
|
/// Callbacks
|
||||||
void Layer::onEnter()
|
void Layer::onEnter()
|
||||||
{
|
{
|
||||||
Director* pDirector = Director::getInstance();
|
|
||||||
// register 'parent' nodes first
|
// register 'parent' nodes first
|
||||||
// since events are propagated in reverse order
|
// since events are propagated in reverse order
|
||||||
if (_touchEnabled)
|
if (_touchEnabled)
|
||||||
{
|
{
|
||||||
this->registerWithTouchDispatcher();
|
this->onRegisterTouchListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
// then iterate over all the children
|
// then iterate over all the children
|
||||||
|
@ -358,35 +315,27 @@ void Layer::onEnter()
|
||||||
// add this layer to concern the Accelerometer Sensor
|
// add this layer to concern the Accelerometer Sensor
|
||||||
if (_accelerometerEnabled)
|
if (_accelerometerEnabled)
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(Layer::didAccelerate, this));
|
auto dispatcher = EventDispatcher::getInstance();
|
||||||
}
|
dispatcher->removeEventListener(_accelerationListener);
|
||||||
|
auto listener = AccelerationEventListener::create(CC_CALLBACK_2(Layer::onAcceleration, this));
|
||||||
// add this layer to concern the keypad msg
|
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
if (_keypadEnabled)
|
|
||||||
{
|
|
||||||
pDirector->getKeypadDispatcher()->addDelegate(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::onExit()
|
void Layer::onExit()
|
||||||
{
|
{
|
||||||
Director* pDirector = Director::getInstance();
|
auto dispatcher = EventDispatcher::getInstance();
|
||||||
if( _touchEnabled )
|
|
||||||
{
|
dispatcher->removeEventListener(_touchListener);
|
||||||
pDirector->getTouchDispatcher()->removeDelegate(this);
|
_touchListener = nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
// remove this layer from the delegates who concern Accelerometer Sensor
|
// remove this layer from the delegates who concern Accelerometer Sensor
|
||||||
if (_accelerometerEnabled)
|
dispatcher->removeEventListener(_accelerationListener);
|
||||||
{
|
_accelerationListener = nullptr;
|
||||||
pDirector->getAccelerometer()->setDelegate(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove this layer from the delegates who concern the keypad msg
|
// remove this layer from the delegates who concern the keypad msg
|
||||||
if (_keypadEnabled)
|
dispatcher->removeEventListener(_keyboardListener);
|
||||||
{
|
_keyboardListener = nullptr;
|
||||||
pDirector->getKeypadDispatcher()->removeDelegate(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Node::onExit();
|
Node::onExit();
|
||||||
}
|
}
|
||||||
|
@ -395,18 +344,19 @@ void Layer::onEnterTransitionDidFinish()
|
||||||
{
|
{
|
||||||
if (_accelerometerEnabled)
|
if (_accelerometerEnabled)
|
||||||
{
|
{
|
||||||
Director* pDirector = Director::getInstance();
|
auto dispatcher = EventDispatcher::getInstance();
|
||||||
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(Layer::didAccelerate, this));
|
_accelerationListener = AccelerationEventListener::create(CC_CALLBACK_2(Layer::onAcceleration, this));
|
||||||
|
dispatcher->addEventListenerWithSceneGraphPriority(_accelerationListener, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::onEnterTransitionDidFinish();
|
Node::onEnterTransitionDidFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Layer::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
bool Layer::onTouchBegan(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
return executeScriptTouchHandler(CCTOUCHBEGAN, pTouch) == 0 ? false : true;
|
return executeScriptTouchHandler(TouchEvent::EventCode::BEGAN, pTouch) == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CC_UNUSED_PARAM(pTouch);
|
CC_UNUSED_PARAM(pTouch);
|
||||||
|
@ -415,11 +365,11 @@ bool Layer::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ccTouchMoved(Touch *pTouch, Event *pEvent)
|
void Layer::onTouchMoved(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
executeScriptTouchHandler(CCTOUCHMOVED, pTouch);
|
executeScriptTouchHandler(TouchEvent::EventCode::MOVED, pTouch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,11 +377,11 @@ void Layer::ccTouchMoved(Touch *pTouch, Event *pEvent)
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ccTouchEnded(Touch *pTouch, Event *pEvent)
|
void Layer::onTouchEnded(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
executeScriptTouchHandler(CCTOUCHENDED, pTouch);
|
executeScriptTouchHandler(TouchEvent::EventCode::ENDED, pTouch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,11 +389,11 @@ void Layer::ccTouchEnded(Touch *pTouch, Event *pEvent)
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ccTouchCancelled(Touch *pTouch, Event *pEvent)
|
void Layer::onTouchCancelled(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
executeScriptTouchHandler(CCTOUCHCANCELLED, pTouch);
|
executeScriptTouchHandler(TouchEvent::EventCode::CANCELLED, pTouch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,11 +401,11 @@ void Layer::ccTouchCancelled(Touch *pTouch, Event *pEvent)
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ccTouchesBegan(Set *pTouches, Event *pEvent)
|
void Layer::onTouchesBegan(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
executeScriptTouchesHandler(CCTOUCHBEGAN, pTouches);
|
executeScriptTouchesHandler(TouchEvent::EventCode::BEGAN, pTouches);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,11 +413,11 @@ void Layer::ccTouchesBegan(Set *pTouches, Event *pEvent)
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ccTouchesMoved(Set *pTouches, Event *pEvent)
|
void Layer::onTouchesMoved(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
executeScriptTouchesHandler(CCTOUCHMOVED, pTouches);
|
executeScriptTouchesHandler(TouchEvent::EventCode::MOVED, pTouches);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,11 +425,11 @@ void Layer::ccTouchesMoved(Set *pTouches, Event *pEvent)
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ccTouchesEnded(Set *pTouches, Event *pEvent)
|
void Layer::onTouchesEnded(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
executeScriptTouchesHandler(CCTOUCHENDED, pTouches);
|
executeScriptTouchesHandler(TouchEvent::EventCode::ENDED, pTouches);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,11 +437,11 @@ void Layer::ccTouchesEnded(Set *pTouches, Event *pEvent)
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ccTouchesCancelled(Set *pTouches, Event *pEvent)
|
void Layer::onTouchesCancelled(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (kScriptTypeNone != _scriptType)
|
if (kScriptTypeNone != _scriptType)
|
||||||
{
|
{
|
||||||
executeScriptTouchesHandler(CCTOUCHCANCELLED, pTouches);
|
executeScriptTouchesHandler(TouchEvent::EventCode::CANCELLED, pTouches);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,13 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "base_nodes/CCNode.h"
|
#include "base_nodes/CCNode.h"
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "touch_dispatcher/CCTouchDelegateProtocol.h"
|
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
|
||||||
#include "keypad_dispatcher/CCKeypadDelegate.h"
|
|
||||||
#include "cocoa/CCArray.h"
|
#include "cocoa/CCArray.h"
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
#include "base_nodes/CCGLBufferedNode.h"
|
#include "base_nodes/CCGLBufferedNode.h"
|
||||||
#endif // EMSCRIPTEN
|
#endif // EMSCRIPTEN
|
||||||
|
|
||||||
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +45,10 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
class TouchScriptHandlerEntry;
|
class TouchScriptHandlerEntry;
|
||||||
|
|
||||||
|
class TouchEventListener;
|
||||||
|
class KeyboardEventListener;
|
||||||
|
class AccelerationEventListener;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Layer
|
// Layer
|
||||||
//
|
//
|
||||||
|
@ -55,7 +58,7 @@ All features from Node are valid, plus the following new features:
|
||||||
- It can receive iPhone Touches
|
- It can receive iPhone Touches
|
||||||
- It can receive Accelerometer input
|
- It can receive Accelerometer input
|
||||||
*/
|
*/
|
||||||
class CC_DLL Layer : public Node, public TouchDelegate, public KeypadDelegate
|
class CC_DLL Layer : public Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** creates a fullscreen black layer */
|
/** creates a fullscreen black layer */
|
||||||
|
@ -71,22 +74,33 @@ public:
|
||||||
virtual ~Layer();
|
virtual ~Layer();
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
|
|
||||||
// default implements are used to call script callback if exist
|
// Deprecated touch callbacks.
|
||||||
virtual bool ccTouchBegan(Touch *touch, Event *event);
|
CC_DEPRECATED_ATTRIBUTE virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent); return false;};
|
||||||
virtual void ccTouchMoved(Touch *touch, Event *event);
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
virtual void ccTouchEnded(Touch *touch, Event *event);
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
virtual void ccTouchCancelled(Touch *touch, Event *event);
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesBegan(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesMoved(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesEnded(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesCancelled(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
|
||||||
// default implements are used to call script callback if exist
|
// default implements are used to call script callback if exist
|
||||||
virtual void ccTouchesBegan(Set *touches, Event *event);
|
virtual bool onTouchBegan(Touch *touch, Event *event);
|
||||||
virtual void ccTouchesMoved(Set *touches, Event *event);
|
virtual void onTouchMoved(Touch *touch, Event *event);
|
||||||
virtual void ccTouchesEnded(Set *touches, Event *event);
|
virtual void onTouchEnded(Touch *touch, Event *event);
|
||||||
virtual void ccTouchesCancelled(Set *touches, Event *event);
|
virtual void onTouchCancelled(Touch *touch, Event *event);
|
||||||
/**
|
|
||||||
* @js NA
|
// // default implements are used to call script callback if exist
|
||||||
* @lua NA
|
virtual void onTouchesBegan(const std::vector<Touch*>& touches, Event *event);
|
||||||
*/
|
virtual void onTouchesMoved(const std::vector<Touch*>& touches, Event *event);
|
||||||
virtual void didAccelerate(Acceleration* accelerationValue);
|
virtual void onTouchesEnded(const std::vector<Touch*>& touches, Event *event);
|
||||||
|
virtual void onTouchesCancelled(const std::vector<Touch*>&touches, Event *event);
|
||||||
|
|
||||||
|
/** @deprecated Please override onAcceleration */
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void didAccelerate(Acceleration* accelerationValue) final {};
|
||||||
|
|
||||||
|
virtual void onAcceleration(Acceleration* acc, Event* event);
|
||||||
|
|
||||||
/** If isTouchEnabled, this method is called onEnter. Override it to change the
|
/** If isTouchEnabled, this method is called onEnter. Override it to change the
|
||||||
way Layer receives touch events.
|
way Layer receives touch events.
|
||||||
|
@ -98,7 +112,8 @@ public:
|
||||||
}
|
}
|
||||||
@since v0.8.0
|
@since v0.8.0
|
||||||
*/
|
*/
|
||||||
virtual void registerWithTouchDispatcher(void);
|
CC_DEPRECATED_ATTRIBUTE virtual void registerWithTouchDispatcher() final {};
|
||||||
|
virtual void onRegisterTouchListener();
|
||||||
|
|
||||||
/** whether or not it will receive Touch events.
|
/** whether or not it will receive Touch events.
|
||||||
You can enable / disable touch events with this property.
|
You can enable / disable touch events with this property.
|
||||||
|
@ -111,10 +126,6 @@ public:
|
||||||
virtual void setTouchMode(Touch::DispatchMode mode);
|
virtual void setTouchMode(Touch::DispatchMode mode);
|
||||||
virtual Touch::DispatchMode getTouchMode() const;
|
virtual Touch::DispatchMode getTouchMode() const;
|
||||||
|
|
||||||
/** priority of the touch events. Default is 0 */
|
|
||||||
virtual void setTouchPriority(int priority);
|
|
||||||
virtual int getTouchPriority() const;
|
|
||||||
|
|
||||||
/** swallowsTouches of the touch events. Default is true */
|
/** swallowsTouches of the touch events. Default is true */
|
||||||
virtual void setSwallowsTouches(bool swallowsTouches);
|
virtual void setSwallowsTouches(bool swallowsTouches);
|
||||||
virtual bool isSwallowsTouches() const;
|
virtual bool isSwallowsTouches() const;
|
||||||
|
@ -134,22 +145,21 @@ public:
|
||||||
|
|
||||||
virtual bool isKeyboardEnabled() const;
|
virtual bool isKeyboardEnabled() const;
|
||||||
virtual void setKeyboardEnabled(bool value);
|
virtual void setKeyboardEnabled(bool value);
|
||||||
/**
|
/** Please use onKeyPressed instead. */
|
||||||
* @js NA
|
virtual void keyPressed(int keyCode) final {};
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual void keyPressed(int keyCode) {};
|
|
||||||
/**
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual void keyReleased(int keyCode) {};
|
|
||||||
|
|
||||||
virtual bool isKeypadEnabled() const;
|
/** Please use onKeyRelease instead. */
|
||||||
virtual void setKeypadEnabled(bool value);
|
virtual void keyReleased(int keyCode) final {};
|
||||||
|
|
||||||
virtual void keyBackClicked(void);
|
virtual void onKeyPressed(KeyboardEvent::KeyCode keyCode, Event* event) {};
|
||||||
virtual void keyMenuClicked(void);
|
virtual void onKeyReleased(KeyboardEvent::KeyCode keyCode, Event* event) {};
|
||||||
|
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual bool isKeypadEnabled() const final { return false; };
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void setKeypadEnabled(bool value) final {};
|
||||||
|
|
||||||
|
/** @deprecated Please override onKeyReleased and check the keycode of KeyboardEvent::KeyCode::Menu(KEY_BACKSPACE) instead. */
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void keyBackClicked() final {};
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void keyMenuClicked() final {};
|
||||||
//
|
//
|
||||||
// Overrides
|
// Overrides
|
||||||
//
|
//
|
||||||
|
@ -173,15 +183,15 @@ protected:
|
||||||
bool _touchEnabled;
|
bool _touchEnabled;
|
||||||
bool _accelerometerEnabled;
|
bool _accelerometerEnabled;
|
||||||
bool _keyboardEnabled;
|
bool _keyboardEnabled;
|
||||||
bool _keypadEnabled;
|
TouchEventListener* _touchListener;
|
||||||
|
KeyboardEventListener* _keyboardListener;
|
||||||
|
AccelerationEventListener* _accelerationListener;
|
||||||
private:
|
private:
|
||||||
int _touchPriority;
|
|
||||||
Touch::DispatchMode _touchMode;
|
Touch::DispatchMode _touchMode;
|
||||||
bool _swallowsTouches;
|
bool _swallowsTouches;
|
||||||
|
|
||||||
int executeScriptTouchHandler(int eventType, Touch* touch);
|
int executeScriptTouchHandler(TouchEvent::EventCode eventType, Touch* touch);
|
||||||
int executeScriptTouchesHandler(int eventType, Set* touches);
|
int executeScriptTouchesHandler(TouchEvent::EventCode eventType, const std::vector<Touch*>& touches);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __apple__
|
#ifdef __apple__
|
||||||
|
|
|
@ -27,7 +27,6 @@ THE SOFTWARE.
|
||||||
#include "CCTransition.h"
|
#include "CCTransition.h"
|
||||||
#include "CCCamera.h"
|
#include "CCCamera.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
||||||
#include "actions/CCActionInterval.h"
|
#include "actions/CCActionInterval.h"
|
||||||
#include "actions/CCActionInstant.h"
|
#include "actions/CCActionInstant.h"
|
||||||
#include "actions/CCActionEase.h"
|
#include "actions/CCActionEase.h"
|
||||||
|
@ -161,7 +160,9 @@ void TransitionScene::onEnter()
|
||||||
Scene::onEnter();
|
Scene::onEnter();
|
||||||
|
|
||||||
// disable events while transitions
|
// disable events while transitions
|
||||||
Director::getInstance()->getTouchDispatcher()->setDispatchEvents(false);
|
// Director::getInstance()->getTouchDispatcher()->setDispatchEvents(false);
|
||||||
|
|
||||||
|
EventDispatcher::getInstance()->setEnabled(false);
|
||||||
|
|
||||||
// outScene should not receive the onEnter callback
|
// outScene should not receive the onEnter callback
|
||||||
// only the onExitTransitionDidStart
|
// only the onExitTransitionDidStart
|
||||||
|
@ -176,8 +177,9 @@ void TransitionScene::onExit()
|
||||||
Scene::onExit();
|
Scene::onExit();
|
||||||
|
|
||||||
// enable events while transitions
|
// enable events while transitions
|
||||||
Director::getInstance()->getTouchDispatcher()->setDispatchEvents(true);
|
// Director::getInstance()->getTouchDispatcher()->setDispatchEvents(true);
|
||||||
|
|
||||||
|
EventDispatcher::getInstance()->setEnabled(true);
|
||||||
_outScene->onExit();
|
_outScene->onExit();
|
||||||
|
|
||||||
// _inScene should not receive the onEnter callback
|
// _inScene should not receive the onEnter callback
|
||||||
|
|
|
@ -25,10 +25,11 @@ THE SOFTWARE.
|
||||||
#include "CCMenu.h"
|
#include "CCMenu.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCApplication.h"
|
#include "CCApplication.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
|
||||||
#include "CCStdC.h"
|
#include "CCStdC.h"
|
||||||
#include "cocoa/CCInteger.h"
|
#include "cocoa/CCInteger.h"
|
||||||
|
#include "event_dispatcher/CCTouchEventListener.h"
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
@ -58,6 +59,11 @@ enum
|
||||||
//CCMenu
|
//CCMenu
|
||||||
//
|
//
|
||||||
|
|
||||||
|
Menu::~Menu()
|
||||||
|
{
|
||||||
|
CCLOGINFO("In the destructor of Menu. %p", this);
|
||||||
|
}
|
||||||
|
|
||||||
Menu* Menu::create()
|
Menu* Menu::create()
|
||||||
{
|
{
|
||||||
return Menu::create(NULL, NULL);
|
return Menu::create(NULL, NULL);
|
||||||
|
@ -121,7 +127,6 @@ bool Menu::initWithArray(Array* pArrayOfItems)
|
||||||
{
|
{
|
||||||
if (Layer::init())
|
if (Layer::init())
|
||||||
{
|
{
|
||||||
setTouchPriority(Menu::HANDLER_PRIORITY);
|
|
||||||
setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
|
setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
|
||||||
setTouchEnabled(true);
|
setTouchEnabled(true);
|
||||||
|
|
||||||
|
@ -179,6 +184,14 @@ void Menu::addChild(Node * child, int zOrder, int tag)
|
||||||
Layer::addChild(child, zOrder, tag);
|
Layer::addChild(child, zOrder, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Menu::onEnter()
|
||||||
|
{
|
||||||
|
Layer::onEnter();
|
||||||
|
|
||||||
|
setTouchEnabled(true);
|
||||||
|
setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
|
||||||
|
}
|
||||||
|
|
||||||
void Menu::onExit()
|
void Menu::onExit()
|
||||||
{
|
{
|
||||||
if (_state == Menu::State::TRACKING_TOUCH)
|
if (_state == Menu::State::TRACKING_TOUCH)
|
||||||
|
@ -212,19 +225,19 @@ void Menu::removeChild(Node* child, bool cleanup)
|
||||||
|
|
||||||
void Menu::setHandlerPriority(int newPriority)
|
void Menu::setHandlerPriority(int newPriority)
|
||||||
{
|
{
|
||||||
TouchDispatcher* pDispatcher = Director::getInstance()->getTouchDispatcher();
|
CCASSERT(false, "Not needed since we're using new ");
|
||||||
pDispatcher->setPriority(newPriority, this);
|
// TouchDispatcher* pDispatcher = Director::getInstance()->getTouchDispatcher();
|
||||||
|
// pDispatcher->setPriority(newPriority, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::registerWithTouchDispatcher()
|
//void Menu::registerWithTouchDispatcher()
|
||||||
{
|
//{
|
||||||
Director* pDirector = Director::getInstance();
|
// Director* pDirector = Director::getInstance();
|
||||||
pDirector->getTouchDispatcher()->addTargetedDelegate(this, this->getTouchPriority(), true);
|
// pDirector->getTouchDispatcher()->addTargetedDelegate(this, this->getTouchPriority(), true);
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool Menu::ccTouchBegan(Touch* touch, Event* event)
|
bool Menu::onTouchBegan(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(event);
|
|
||||||
if (_state != Menu::State::WAITING || ! _visible || !_enabled)
|
if (_state != Menu::State::WAITING || ! _visible || !_enabled)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -243,15 +256,15 @@ bool Menu::ccTouchBegan(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
_state = Menu::State::TRACKING_TOUCH;
|
_state = Menu::State::TRACKING_TOUCH;
|
||||||
_selectedItem->selected();
|
_selectedItem->selected();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::ccTouchEnded(Touch *touch, Event* event)
|
void Menu::onTouchEnded(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(touch);
|
|
||||||
CC_UNUSED_PARAM(event);
|
|
||||||
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchEnded] -- invalid state");
|
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchEnded] -- invalid state");
|
||||||
if (_selectedItem)
|
if (_selectedItem)
|
||||||
{
|
{
|
||||||
|
@ -261,10 +274,8 @@ void Menu::ccTouchEnded(Touch *touch, Event* event)
|
||||||
_state = Menu::State::WAITING;
|
_state = Menu::State::WAITING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::ccTouchCancelled(Touch *touch, Event* event)
|
void Menu::onTouchCancelled(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(touch);
|
|
||||||
CC_UNUSED_PARAM(event);
|
|
||||||
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchCancelled] -- invalid state");
|
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchCancelled] -- invalid state");
|
||||||
if (_selectedItem)
|
if (_selectedItem)
|
||||||
{
|
{
|
||||||
|
@ -273,9 +284,8 @@ void Menu::ccTouchCancelled(Touch *touch, Event* event)
|
||||||
_state = Menu::State::WAITING;
|
_state = Menu::State::WAITING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::ccTouchMoved(Touch* touch, Event* event)
|
void Menu::onTouchMoved(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(event);
|
|
||||||
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchMoved] -- invalid state");
|
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchMoved] -- invalid state");
|
||||||
MenuItem *currentItem = this->itemForTouch(touch);
|
MenuItem *currentItem = this->itemForTouch(touch);
|
||||||
if (currentItem != _selectedItem)
|
if (currentItem != _selectedItem)
|
||||||
|
@ -607,7 +617,7 @@ MenuItem* Menu::itemForTouch(Touch *touch)
|
||||||
if (_children && _children->count() > 0)
|
if (_children && _children->count() > 0)
|
||||||
{
|
{
|
||||||
Object* pObject = NULL;
|
Object* pObject = NULL;
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
CCARRAY_FOREACH_REVERSE(_children, pObject)
|
||||||
{
|
{
|
||||||
MenuItem* child = dynamic_cast<MenuItem*>(pObject);
|
MenuItem* child = dynamic_cast<MenuItem*>(pObject);
|
||||||
if (child && child->isVisible() && child->isEnabled())
|
if (child && child->isVisible() && child->isEnabled())
|
||||||
|
|
|
@ -28,6 +28,8 @@ THE SOFTWARE.
|
||||||
#include "CCMenuItem.h"
|
#include "CCMenuItem.h"
|
||||||
#include "layers_scenes_transitions_nodes/CCLayer.h"
|
#include "layers_scenes_transitions_nodes/CCLayer.h"
|
||||||
|
|
||||||
|
#include "event_dispatcher/CCTouchEvent.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,11 +82,7 @@ public:
|
||||||
* @js ctor
|
* @js ctor
|
||||||
*/
|
*/
|
||||||
Menu() : _selectedItem(NULL) {}
|
Menu() : _selectedItem(NULL) {}
|
||||||
/**
|
virtual ~Menu();
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual ~Menu(){}
|
|
||||||
|
|
||||||
/** initializes an empty Menu */
|
/** initializes an empty Menu */
|
||||||
bool init();
|
bool init();
|
||||||
|
@ -119,20 +117,29 @@ public:
|
||||||
/** set event handler priority. By default it is: kMenuTouchPriority */
|
/** set event handler priority. By default it is: kMenuTouchPriority */
|
||||||
void setHandlerPriority(int newPriority);
|
void setHandlerPriority(int newPriority);
|
||||||
|
|
||||||
virtual void registerWithTouchDispatcher();
|
// virtual void registerWithTouchDispatcher();
|
||||||
virtual void removeChild(Node* child, bool cleanup);
|
virtual void removeChild(Node* child, bool cleanup);
|
||||||
|
|
||||||
virtual bool isEnabled() const { return _enabled; }
|
virtual bool isEnabled() const { return _enabled; }
|
||||||
virtual void setEnabled(bool value) { _enabled = value; };
|
virtual void setEnabled(bool value) { _enabled = value; };
|
||||||
|
|
||||||
// overrides
|
// overrides
|
||||||
|
|
||||||
|
|
||||||
virtual void addChild(Node * child) override;
|
virtual void addChild(Node * child) override;
|
||||||
virtual void addChild(Node * child, int zOrder) override;
|
virtual void addChild(Node * child, int zOrder) override;
|
||||||
virtual void addChild(Node * child, int zOrder, int tag) override;
|
virtual void addChild(Node * child, int zOrder, int tag) override;
|
||||||
virtual bool ccTouchBegan(Touch* touch, Event* event) override;
|
// virtual bool ccTouchBegan(Touch* touch, Event* event) override;
|
||||||
virtual void ccTouchEnded(Touch* touch, Event* event) override;
|
// virtual void ccTouchEnded(Touch* touch, Event* event) override;
|
||||||
virtual void ccTouchCancelled(Touch *touch, Event* event) override;
|
// virtual void ccTouchCancelled(Touch *touch, Event* event) override;
|
||||||
virtual void ccTouchMoved(Touch* touch, Event* event) override;
|
// virtual void ccTouchMoved(Touch* touch, Event* event) override;
|
||||||
|
|
||||||
|
bool onTouchBegan(Touch* touch, Event* event);
|
||||||
|
void onTouchEnded(Touch* touch, Event* event);
|
||||||
|
void onTouchCancelled(Touch* touch, Event* event);
|
||||||
|
void onTouchMoved(Touch* touch, Event* event);
|
||||||
|
|
||||||
|
virtual void onEnter() override;
|
||||||
virtual void onExit() override;
|
virtual void onExit() override;
|
||||||
virtual void setOpacityModifyRGB(bool bValue) override {CC_UNUSED_PARAM(bValue);}
|
virtual void setOpacityModifyRGB(bool bValue) override {CC_UNUSED_PARAM(bValue);}
|
||||||
virtual bool isOpacityModifyRGB(void) const override { return false;}
|
virtual bool isOpacityModifyRGB(void) const override { return false;}
|
||||||
|
|
|
@ -465,6 +465,7 @@ void RenderTexture::visit()
|
||||||
transform();
|
transform();
|
||||||
_sprite->visit();
|
_sprite->visit();
|
||||||
draw();
|
draw();
|
||||||
|
updateEventPriorityIndex();
|
||||||
|
|
||||||
if (_grid && _grid->isActive())
|
if (_grid && _grid->isActive())
|
||||||
{
|
{
|
||||||
|
|
|
@ -144,6 +144,7 @@ void ParticleBatchNode::visit()
|
||||||
transform();
|
transform();
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
|
updateEventPriorityIndex();
|
||||||
|
|
||||||
if ( _grid && _grid->isActive())
|
if ( _grid && _grid->isActive())
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,15 @@ public:
|
||||||
* @return The DPI of device.
|
* @return The DPI of device.
|
||||||
*/
|
*/
|
||||||
static int getDPI();
|
static int getDPI();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To enable or disable accelerometer.
|
||||||
|
*/
|
||||||
|
static void setAccelerometerEnabled(bool isEnabled);
|
||||||
|
/**
|
||||||
|
* Sets the interval of accelerometer.
|
||||||
|
*/
|
||||||
|
static void setAccelerometerInterval(float interval);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,49 @@
|
||||||
#include "CCEGLViewProtocol.h"
|
#include "CCEGLViewProtocol.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "cocoa/CCSet.h"
|
#include "cocoa/CCSet.h"
|
||||||
#include "cocoa/CCDictionary.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
#include "cocoa/CCInteger.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static Touch* s_pTouches[CC_MAX_TOUCHES] = { NULL };
|
namespace {
|
||||||
static unsigned int s_indexBitsUsed = 0;
|
|
||||||
static Dictionary s_TouchesIntergerDict;
|
|
||||||
|
|
||||||
static int getUnUsedIndex()
|
static Touch* g_touches[TouchEvent::MAX_TOUCHES] = { NULL };
|
||||||
{
|
static unsigned int g_indexBitsUsed = 0;
|
||||||
int i;
|
// System touch pointer ID (It may not be ascending order number) <-> Ascending order number from 0
|
||||||
int temp = s_indexBitsUsed;
|
static std::map<int, int> g_touchIdReorderMap;
|
||||||
|
|
||||||
for (i = 0; i < CC_MAX_TOUCHES; i++) {
|
static int getUnUsedIndex()
|
||||||
if (! (temp & 0x00000001)) {
|
{
|
||||||
s_indexBitsUsed |= (1 << i);
|
int i;
|
||||||
return i;
|
int temp = g_indexBitsUsed;
|
||||||
|
|
||||||
|
for (i = 0; i < TouchEvent::MAX_TOUCHES; i++) {
|
||||||
|
if (! (temp & 0x00000001)) {
|
||||||
|
g_indexBitsUsed |= (1 << i);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp >>= 1;
|
// all bits are used
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// all bits are used
|
static void removeUsedIndexBit(int index)
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void removeUsedIndexBit(int index)
|
|
||||||
{
|
|
||||||
if (index < 0 || index >= CC_MAX_TOUCHES)
|
|
||||||
{
|
{
|
||||||
return;
|
if (index < 0 || index >= TouchEvent::MAX_TOUCHES)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int temp = 1 << index;
|
||||||
|
temp = ~temp;
|
||||||
|
g_indexBitsUsed &= temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int temp = 1 << index;
|
|
||||||
temp = ~temp;
|
|
||||||
s_indexBitsUsed &= temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLViewProtocol::EGLViewProtocol()
|
EGLViewProtocol::EGLViewProtocol()
|
||||||
|
@ -199,18 +203,23 @@ const char* EGLViewProtocol::getViewName()
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
Set set;
|
int id = 0;
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
int nUnusedIndex = 0;
|
||||||
|
TouchEvent touchEvent;
|
||||||
|
|
||||||
for (int i = 0; i < num; ++i)
|
for (int i = 0; i < num; ++i)
|
||||||
{
|
{
|
||||||
int id = ids[i];
|
id = ids[i];
|
||||||
float x = xs[i];
|
x = xs[i];
|
||||||
float y = ys[i];
|
y = ys[i];
|
||||||
|
|
||||||
Integer* pIndex = (Integer*)s_TouchesIntergerDict.objectForKey(id);
|
auto iter = g_touchIdReorderMap.find(id);
|
||||||
int nUnusedIndex = 0;
|
nUnusedIndex = 0;
|
||||||
|
|
||||||
// it is a new touch
|
// it is a new touch
|
||||||
if (pIndex == NULL)
|
if (iter == g_touchIdReorderMap.end())
|
||||||
{
|
{
|
||||||
nUnusedIndex = getUnUsedIndex();
|
nUnusedIndex = getUnUsedIndex();
|
||||||
|
|
||||||
|
@ -220,51 +229,55 @@ void EGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float y
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Touch* pTouch = s_pTouches[nUnusedIndex] = new Touch();
|
Touch* touch = g_touches[nUnusedIndex] = new Touch();
|
||||||
pTouch->setTouchInfo(nUnusedIndex, (x - _viewPortRect.origin.x) / _scaleX,
|
touch->setTouchInfo(nUnusedIndex, (x - _viewPortRect.origin.x) / _scaleX,
|
||||||
(y - _viewPortRect.origin.y) / _scaleY);
|
(y - _viewPortRect.origin.y) / _scaleY);
|
||||||
|
|
||||||
//CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y);
|
CCLOGINFO("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y);
|
||||||
|
|
||||||
Integer* pInterObj = new Integer(nUnusedIndex);
|
g_touchIdReorderMap.insert(std::make_pair(id, nUnusedIndex));
|
||||||
s_TouchesIntergerDict.setObject(pInterObj, id);
|
touchEvent._touches.push_back(touch);
|
||||||
set.addObject(pTouch);
|
|
||||||
pInterObj->release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set.count() == 0)
|
if (touchEvent._touches.size() == 0)
|
||||||
{
|
{
|
||||||
CCLOG("touchesBegan: count = 0");
|
CCLOG("touchesBegan: size = 0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_delegate->touchesBegan(&set, NULL);
|
touchEvent._eventCode = TouchEvent::EventCode::BEGAN;
|
||||||
|
EventDispatcher::getInstance()->dispatchEvent(&touchEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
Set set;
|
int id = 0;
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
TouchEvent touchEvent;
|
||||||
|
|
||||||
for (int i = 0; i < num; ++i)
|
for (int i = 0; i < num; ++i)
|
||||||
{
|
{
|
||||||
int id = ids[i];
|
id = ids[i];
|
||||||
float x = xs[i];
|
x = xs[i];
|
||||||
float y = ys[i];
|
y = ys[i];
|
||||||
|
|
||||||
Integer* pIndex = (Integer*)s_TouchesIntergerDict.objectForKey(id);
|
auto iter = g_touchIdReorderMap.find(id);
|
||||||
if (pIndex == NULL) {
|
if (iter == g_touchIdReorderMap.end())
|
||||||
|
{
|
||||||
CCLOG("if the index doesn't exist, it is an error");
|
CCLOG("if the index doesn't exist, it is an error");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCLOGINFO("Moving touches with id: %d, x=%f, y=%f", id, x, y);
|
CCLOGINFO("Moving touches with id: %d, x=%f, y=%f", id, x, y);
|
||||||
Touch* pTouch = s_pTouches[pIndex->getValue()];
|
Touch* touch = g_touches[iter->second];
|
||||||
if (pTouch)
|
if (touch)
|
||||||
{
|
{
|
||||||
pTouch->setTouchInfo(pIndex->getValue(), (x - _viewPortRect.origin.x) / _scaleX,
|
touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
|
||||||
(y - _viewPortRect.origin.y) / _scaleY);
|
(y - _viewPortRect.origin.y) / _scaleY);
|
||||||
|
|
||||||
set.addObject(pTouch);
|
touchEvent._touches.push_back(touch);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -274,46 +287,50 @@ void EGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float ys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set.count() == 0)
|
if (touchEvent._touches.size() == 0)
|
||||||
{
|
{
|
||||||
CCLOG("touchesMoved: count = 0");
|
CCLOG("touchesMoved: size = 0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_delegate->touchesMoved(&set, NULL);
|
touchEvent._eventCode = TouchEvent::EventCode::MOVED;
|
||||||
|
EventDispatcher::getInstance()->dispatchEvent(&touchEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::getSetOfTouchesEndOrCancel(Set& set, int num, int ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesOfEndOrCancel(TouchEvent::EventCode eventCode, int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
|
int id = 0;
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
TouchEvent touchEvent;
|
||||||
|
|
||||||
for (int i = 0; i < num; ++i)
|
for (int i = 0; i < num; ++i)
|
||||||
{
|
{
|
||||||
int id = ids[i];
|
id = ids[i];
|
||||||
float x = xs[i];
|
x = xs[i];
|
||||||
float y = ys[i];
|
y = ys[i];
|
||||||
|
|
||||||
Integer* pIndex = (Integer*)s_TouchesIntergerDict.objectForKey(id);
|
auto iter = g_touchIdReorderMap.find(id);
|
||||||
if (pIndex == NULL)
|
if (iter == g_touchIdReorderMap.end())
|
||||||
{
|
{
|
||||||
CCLOG("if the index doesn't exist, it is an error");
|
CCLOG("if the index doesn't exist, it is an error");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add to the set to send to the director */
|
/* Add to the set to send to the director */
|
||||||
Touch* pTouch = s_pTouches[pIndex->getValue()];
|
Touch* touch = g_touches[iter->second];
|
||||||
if (pTouch)
|
if (touch)
|
||||||
{
|
{
|
||||||
CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y);
|
CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y);
|
||||||
pTouch->setTouchInfo(pIndex->getValue(), (x - _viewPortRect.origin.x) / _scaleX,
|
touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
|
||||||
(y - _viewPortRect.origin.y) / _scaleY);
|
(y - _viewPortRect.origin.y) / _scaleY);
|
||||||
|
|
||||||
set.addObject(pTouch);
|
touchEvent._touches.push_back(touch);
|
||||||
|
|
||||||
// release the object
|
g_touches[iter->second] = NULL;
|
||||||
pTouch->release();
|
removeUsedIndexBit(iter->second);
|
||||||
s_pTouches[pIndex->getValue()] = NULL;
|
|
||||||
removeUsedIndexBit(pIndex->getValue());
|
|
||||||
|
|
||||||
s_TouchesIntergerDict.removeObjectForKey(id);
|
|
||||||
|
|
||||||
|
g_touchIdReorderMap.erase(id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -323,25 +340,30 @@ void EGLViewProtocol::getSetOfTouchesEndOrCancel(Set& set, int num, int ids[], f
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set.count() == 0)
|
if (touchEvent._touches.size() == 0)
|
||||||
{
|
{
|
||||||
CCLOG("touchesEnded or touchesCancel: count = 0");
|
CCLOG("touchesEnded or touchesCancel: size = 0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
touchEvent._eventCode = eventCode;
|
||||||
|
EventDispatcher::getInstance()->dispatchEvent(&touchEvent);
|
||||||
|
|
||||||
|
for (auto& touch : touchEvent._touches)
|
||||||
|
{
|
||||||
|
// delete the touch object.
|
||||||
|
delete touch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesEnd(int num, int ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesEnd(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
Set set;
|
handleTouchesOfEndOrCancel(TouchEvent::EventCode::ENDED, num, ids, xs, ys);
|
||||||
getSetOfTouchesEndOrCancel(set, num, ids, xs, ys);
|
|
||||||
_delegate->touchesEnded(&set, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesCancel(int num, int ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesCancel(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
Set set;
|
handleTouchesOfEndOrCancel(TouchEvent::EventCode::CANCELLED, num, ids, xs, ys);
|
||||||
getSetOfTouchesEndOrCancel(set, num, ids, xs, ys);
|
|
||||||
_delegate->touchesCancelled(&set, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Rect& EGLViewProtocol::getViewPortRect() const
|
const Rect& EGLViewProtocol::getViewPortRect() const
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#define __CCEGLVIEWPROTOCOL_H__
|
#define __CCEGLVIEWPROTOCOL_H__
|
||||||
|
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
|
#include "event_dispatcher/CCTouchEvent.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
enum class ResolutionPolicy
|
enum class ResolutionPolicy
|
||||||
{
|
{
|
||||||
|
@ -30,10 +33,7 @@ enum class ResolutionPolicy
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
#define CC_MAX_TOUCHES 5
|
|
||||||
|
|
||||||
class EGLTouchDelegate;
|
class EGLTouchDelegate;
|
||||||
class Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup platform
|
* @addtogroup platform
|
||||||
|
@ -156,7 +156,7 @@ public:
|
||||||
*/
|
*/
|
||||||
float getScaleY() const;
|
float getScaleY() const;
|
||||||
private:
|
private:
|
||||||
void getSetOfTouchesEndOrCancel(Set& set, int num, int ids[], float xs[], float ys[]);
|
void handleTouchesOfEndOrCancel(TouchEvent::EventCode eventCode, int num, int ids[], float xs[], float ys[]);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EGLTouchDelegate* _delegate;
|
EGLTouchDelegate* _delegate;
|
||||||
|
|
|
@ -7,7 +7,6 @@ LOCAL_MODULE := cocos2dxandroid_static
|
||||||
LOCAL_MODULE_FILENAME := libcocos2dandroid
|
LOCAL_MODULE_FILENAME := libcocos2dandroid
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
CCAccelerometer.cpp \
|
|
||||||
CCApplication.cpp \
|
CCApplication.cpp \
|
||||||
CCCommon.cpp \
|
CCCommon.cpp \
|
||||||
CCDevice.cpp \
|
CCDevice.cpp \
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
#include "CCAccelerometer.h"
|
|
||||||
#include "nativeactivity.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <android/log.h>
|
|
||||||
|
|
||||||
#define TG3_GRAVITY_EARTH (9.80665f)
|
|
||||||
#define LOG_TAG "CCAccelerometer_android"
|
|
||||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
|
||||||
|
|
||||||
namespace cocos2d
|
|
||||||
{
|
|
||||||
Accelerometer::Accelerometer() : _function(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Accelerometer::~Accelerometer()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Accelerometer::setDelegate(std::function<void(Acceleration*)> function)
|
|
||||||
{
|
|
||||||
_function = function;
|
|
||||||
|
|
||||||
if (_function) {
|
|
||||||
enableAccelerometer();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
disableAccelerometer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Accelerometer::setAccelerometerInterval(float interval)
|
|
||||||
{
|
|
||||||
setAccelerometerInterval(interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Accelerometer::update(float x, float y, float z, long sensorTimeStamp)
|
|
||||||
{
|
|
||||||
if (_function)
|
|
||||||
{
|
|
||||||
_accelerationValue.x = -((double)x / TG3_GRAVITY_EARTH);
|
|
||||||
_accelerationValue.y = -((double)y / TG3_GRAVITY_EARTH);
|
|
||||||
_accelerationValue.z = -((double)z / TG3_GRAVITY_EARTH);
|
|
||||||
_accelerationValue.timestamp = (double)sensorTimeStamp;
|
|
||||||
|
|
||||||
_function(&_accelerationValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // end of namespace cococs2d
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "platform/CCDevice.h"
|
#include "platform/CCDevice.h"
|
||||||
#include "jni/DPIJni.h"
|
#include "jni/DPIJni.h"
|
||||||
|
#include "nativeactivity.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -13,4 +14,21 @@ int Device::getDPI()
|
||||||
return dpi;
|
return dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
if (isEnabled)
|
||||||
|
{
|
||||||
|
enableAccelerometer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
disableAccelerometer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{
|
||||||
|
setAccelerometerInterval(interval);
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -25,7 +25,6 @@ THE SOFTWARE.
|
||||||
#include "cocoa/CCSet.h"
|
#include "cocoa/CCSet.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
||||||
#include "jni/IMEJni.h"
|
#include "jni/IMEJni.h"
|
||||||
#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
|
#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
|
|
|
@ -18,13 +18,14 @@
|
||||||
#include "CCEventType.h"
|
#include "CCEventType.h"
|
||||||
#include "support/CCNotificationCenter.h"
|
#include "support/CCNotificationCenter.h"
|
||||||
#include "CCFileUtilsAndroid.h"
|
#include "CCFileUtilsAndroid.h"
|
||||||
#include "CCAccelerometer.h"
|
|
||||||
#include "jni/JniHelper.h"
|
#include "jni/JniHelper.h"
|
||||||
|
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
#include "draw_nodes/CCDrawingPrimitives.h"
|
#include "draw_nodes/CCDrawingPrimitives.h"
|
||||||
#include "shaders/CCShaderCache.h"
|
#include "shaders/CCShaderCache.h"
|
||||||
#include "textures/CCTextureCache.h"
|
#include "textures/CCTextureCache.h"
|
||||||
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCAccelerationEvent.h"
|
||||||
|
|
||||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "cocos2dx/nativeactivity.cpp", __VA_ARGS__))
|
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "cocos2dx/nativeactivity.cpp", __VA_ARGS__))
|
||||||
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "cocos2dx/nativeactivity.cpp", __VA_ARGS__))
|
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "cocos2dx/nativeactivity.cpp", __VA_ARGS__))
|
||||||
|
@ -525,17 +526,22 @@ void android_main(struct android_app* state) {
|
||||||
// ACONFIGURATION_ORIENTATION_ANY
|
// ACONFIGURATION_ORIENTATION_ANY
|
||||||
// ACONFIGURATION_ORIENTATION_PORT
|
// ACONFIGURATION_ORIENTATION_PORT
|
||||||
// ACONFIGURATION_ORIENTATION_SQUARE
|
// ACONFIGURATION_ORIENTATION_SQUARE
|
||||||
cocos2d::Director::getInstance()->getAccelerometer()->update(event.acceleration.x,
|
cocos2d::AccelerationEvent accEvent;
|
||||||
-event.acceleration.y,
|
accEvent.acc.x = event.acceleration.x;
|
||||||
event.acceleration.z,
|
accEvent.acc.y = -event.acceleration.y;
|
||||||
0);
|
accEvent.acc.z = event.acceleration.z;
|
||||||
|
accEvent.acc.timestamp = 0;
|
||||||
|
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&accEvent);
|
||||||
} else {
|
} else {
|
||||||
// ACONFIGURATION_ORIENTATION_LAND
|
// ACONFIGURATION_ORIENTATION_LAND
|
||||||
// swap x and y parameters
|
// swap x and y parameters
|
||||||
cocos2d::Director::getInstance()->getAccelerometer()->update(-event.acceleration.y,
|
|
||||||
event.acceleration.x,
|
cocos2d::AccelerationEvent accEvent;
|
||||||
event.acceleration.z,
|
accEvent.acc.x = -event.acceleration.y;
|
||||||
0);
|
accEvent.acc.y = event.acceleration.x;
|
||||||
|
accEvent.acc.z = event.acceleration.z;
|
||||||
|
accEvent.acc.timestamp = 0;
|
||||||
|
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&accEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,14 @@ int Device::getDPI()
|
||||||
return 160;
|
return 160;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -26,10 +26,10 @@ THE SOFTWARE.
|
||||||
#include "cocoa/CCSet.h"
|
#include "cocoa/CCSet.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
#include "text_input_node/CCIMEDispatcher.h"
|
#include "text_input_node/CCIMEDispatcher.h"
|
||||||
#include "keypad_dispatcher/CCKeypadDispatcher.h"
|
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "CCAccelerometer.h"
|
#include "CCAccelerometer.h"
|
||||||
#include "CCApplication.h"
|
#include "CCApplication.h"
|
||||||
|
|
|
@ -89,33 +89,58 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool divideString(TTF_Font *face, const char* sText, int iMaxWidth, int iMaxHeight) {
|
bool divideString(TTF_Font *face, const char* sText, int iMaxWidth, int iMaxHeight) {
|
||||||
const char* pText = sText;
|
|
||||||
|
|
||||||
//init stringstream
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
int w, h;
|
int w, h;
|
||||||
|
|
||||||
while (*pText != '\0') {
|
// if there is no maximum width specified, just slam the whole input
|
||||||
if (*pText == '\n') {
|
// string into a single line, thereby avoiding many expensive calls to
|
||||||
buildLine(ss, face);
|
// compute font metrics.
|
||||||
|
if(iMaxWidth == 0)
|
||||||
|
{
|
||||||
|
std::string text = sText;
|
||||||
|
ss << text;
|
||||||
|
buildLine(ss, face);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
pText++;
|
std::vector<std::string> words;
|
||||||
|
std::string text = sText;
|
||||||
|
std::istringstream iss(text);
|
||||||
|
copy(std::istream_iterator<std::string>(iss),
|
||||||
|
std::istream_iterator<std::string>(),
|
||||||
|
std::back_inserter< vector<string> >(words));
|
||||||
|
|
||||||
|
for(std::vector<string>::iterator i = words.begin(); i != words.end(); ++i)
|
||||||
|
{
|
||||||
|
// Specially handle the case where a single word exceeds the
|
||||||
|
// available width.
|
||||||
|
TTF_SizeText(face, i->c_str(), &w, &h);
|
||||||
|
if(w > iMaxWidth)
|
||||||
|
{
|
||||||
|
buildLine(ss, face);
|
||||||
|
for(std::string::iterator c = i->begin(); c != i->end(); ++c)
|
||||||
|
{
|
||||||
|
ss << *c;
|
||||||
|
TTF_SizeText(face, ss.str().c_str(), &w, &h);
|
||||||
|
if(w > iMaxWidth)
|
||||||
|
{
|
||||||
|
buildLine(ss, face);
|
||||||
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check its width
|
std::string tmp = ss.str() + std::string(" ") + *i;
|
||||||
//divide it when exceeding
|
TTF_SizeText(face, tmp.c_str(), &w, &h);
|
||||||
std::string s = ss.str();
|
if(w > iMaxWidth)
|
||||||
s.push_back(*pText);
|
{
|
||||||
TTF_SizeText(face, s.c_str(), &w, &h);
|
|
||||||
|
|
||||||
if (iMaxWidth > 0 && (w > iMaxWidth)) {
|
|
||||||
buildLine(ss, face);
|
buildLine(ss, face);
|
||||||
|
ss << *i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ss << " " << *i;
|
||||||
}
|
}
|
||||||
|
|
||||||
ss << *pText;
|
|
||||||
pText++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildLine(ss, face);
|
buildLine(ss, face);
|
||||||
|
@ -130,53 +155,54 @@ public:
|
||||||
* while -1 means fail
|
* while -1 means fail
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int computeLineStart(TTF_Font *face, Image::TextAlign eAlignMask, char cText,
|
int computeLineStart(Image::TextAlign eAlignMask, int lineWidth, int maxLineWidth)
|
||||||
int iLineIndex) {
|
{
|
||||||
return 0;
|
int result = 0;
|
||||||
/*
|
if( eAlignMask == Image::TextAlign::CENTER ||
|
||||||
int iRet;
|
eAlignMask == Image::TextAlign::TOP ||
|
||||||
int iError = FT_Load_Glyph(face, FT_Get_Char_Index(face, cText),
|
eAlignMask == Image::TextAlign::BOTTOM)
|
||||||
FT_LOAD_DEFAULT);
|
{
|
||||||
if (iError) {
|
result = (maxLineWidth / 2) - (lineWidth / 2);
|
||||||
return -1;
|
}
|
||||||
}
|
else if(eAlignMask == Image::TextAlign::RIGHT ||
|
||||||
|
eAlignMask == Image::TextAlign::TOP_RIGHT ||
|
||||||
|
eAlignMask == Image::TextAlign::BOTTOM_RIGHT)
|
||||||
|
{
|
||||||
|
result = maxLineWidth - lineWidth;
|
||||||
|
}
|
||||||
|
// In all other cases (left alignment, most likely), return 0.
|
||||||
|
|
||||||
if (eAlignMask == Image::kAlignCenter) {
|
// Attempt to ensure that we don't produce any completely invalid reslts.
|
||||||
iRet = (iMaxLineWidth - vLines[iLineIndex].iLineWidth) / 2
|
if(result < 0)
|
||||||
- RSHIFT6(face->glyph->metrics.horiBearingX );
|
{
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (eAlignMask == Image::kAlignRight) {
|
int computeLineStartY(Image::TextAlign eAlignMask, int lineHeight, int maxLineHeight)
|
||||||
iRet = (iMaxLineWidth - vLines[iLineIndex].iLineWidth)
|
{
|
||||||
- RSHIFT6(face->glyph->metrics.horiBearingX );
|
int result = 0;
|
||||||
} else {
|
if( eAlignMask == Image::TextAlign::CENTER ||
|
||||||
// left or other situation
|
eAlignMask == Image::TextAlign::RIGHT ||
|
||||||
iRet = -RSHIFT6(face->glyph->metrics.horiBearingX );
|
eAlignMask == Image::TextAlign::LEFT)
|
||||||
}
|
{
|
||||||
return iRet;
|
result = (maxLineHeight / 2) - (lineHeight / 2);
|
||||||
*/
|
}
|
||||||
}
|
else if(eAlignMask == Image::TextAlign::BOTTOM ||
|
||||||
|
eAlignMask == Image::TextAlign::BOTTOM_RIGHT ||
|
||||||
|
eAlignMask == Image::TextAlign::BOTTOM_LEFT)
|
||||||
|
{
|
||||||
|
result = maxLineHeight - lineHeight;
|
||||||
|
}
|
||||||
|
// In all other cases (top alignment, most likely), return 0;
|
||||||
|
|
||||||
int computeLineStartY( TTF_Font *face, Image::TextAlign eAlignMask, int txtHeight, int borderHeight ){
|
if(result < 0)
|
||||||
return 0;
|
{
|
||||||
/*
|
result = 0;
|
||||||
int iRet;
|
}
|
||||||
if (eAlignMask == Image::kAlignCenter || eAlignMask == Image::kAlignLeft ||
|
return result;
|
||||||
eAlignMask == Image::kAlignRight ) {
|
}
|
||||||
//vertical center
|
|
||||||
iRet = (borderHeight - txtHeight)/2 + RSHIFT6(face->size->metrics.ascender);
|
|
||||||
|
|
||||||
} else if (eAlignMask == Image::kAlignBottomRight ||
|
|
||||||
eAlignMask == Image::kAlignBottom ||
|
|
||||||
eAlignMask == Image::kAlignBottomLeft ) {
|
|
||||||
//vertical bottom
|
|
||||||
iRet = borderHeight - txtHeight + RSHIFT6(face->size->metrics.ascender);
|
|
||||||
} else {
|
|
||||||
// left or other situation
|
|
||||||
iRet = RSHIFT6(face->size->metrics.ascender);
|
|
||||||
}
|
|
||||||
return iRet;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getBitmap(const char *text, int nWidth, int nHeight, Image::TextAlign eAlignMask, const char * pFontName, float fontSize) {
|
bool getBitmap(const char *text, int nWidth, int nHeight, Image::TextAlign eAlignMask, const char * pFontName, float fontSize) {
|
||||||
const char* pText = text;
|
const char* pText = text;
|
||||||
|
@ -213,7 +239,10 @@ public:
|
||||||
// pass back SDL's buffer then, though would need additional logic to
|
// pass back SDL's buffer then, though would need additional logic to
|
||||||
// call SDL_FreeSurface appropriately.
|
// call SDL_FreeSurface appropriately.
|
||||||
|
|
||||||
// FIXME: handle alignment, etc.
|
// Y offset for vertical alignment remains constant throughout, as it
|
||||||
|
// is the entire block of text that must be vertically aligned.
|
||||||
|
int yOffset = computeLineStartY(eAlignMask, vLines.size() * pxSize, iMaxLineHeight);
|
||||||
|
|
||||||
for (size_t l = 0; l < vLines.size(); l++) {
|
for (size_t l = 0; l < vLines.size(); l++) {
|
||||||
pText = vLines[l].sLineStr.c_str();
|
pText = vLines[l].sLineStr.c_str();
|
||||||
if(!strlen(pText))
|
if(!strlen(pText))
|
||||||
|
@ -229,6 +258,10 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The lock/unlock pair is required since Emscripten's SDL
|
||||||
|
// implementation copies pixel data from its off-screen canvas to
|
||||||
|
// the pixels array in the unlock operation. Without this, we would
|
||||||
|
// be reading uninitialized memory.
|
||||||
SDL_LockSurface(tSurf);
|
SDL_LockSurface(tSurf);
|
||||||
SDL_UnlockSurface(tSurf);
|
SDL_UnlockSurface(tSurf);
|
||||||
|
|
||||||
|
@ -237,17 +270,20 @@ public:
|
||||||
int *pixels = (int*)tSurf->pixels;
|
int *pixels = (int*)tSurf->pixels;
|
||||||
int *out = (int*)_data;
|
int *out = (int*)_data;
|
||||||
|
|
||||||
|
// Compute offset to produce horizontal alignment.
|
||||||
|
int xOffset = computeLineStart(eAlignMask, tSurf->w, iMaxLineWidth);
|
||||||
|
|
||||||
// (i, j) should be treated as (x, y) coordinates in the source
|
// (i, j) should be treated as (x, y) coordinates in the source
|
||||||
// bitmap. This loop maps those locations to the target bitmap.
|
// bitmap. This loop maps those locations to the target bitmap.
|
||||||
// Need to ensure that those values do not exceed the allocated
|
// Need to ensure that those values do not exceed the allocated
|
||||||
// memory.
|
// memory.
|
||||||
int minWidth = MIN(tSurf->w, iMaxLineWidth);
|
int minWidth = MIN(tSurf->w, iMaxLineWidth);
|
||||||
for(int i = 0; i < tSurf->h && (i + l * pxSize) < iMaxLineHeight; ++i)
|
for(int j = 0; j < tSurf->h && (j + l * pxSize) < iMaxLineHeight; ++j)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < minWidth; ++j)
|
for(int i = 0; i < minWidth; ++i)
|
||||||
{
|
{
|
||||||
int sourceOffset = i * tSurf->w + j;
|
int sourceOffset = j * tSurf->w + i;
|
||||||
int targetOffset = (l * pxSize + i) * iMaxLineWidth + j;
|
int targetOffset = (l * pxSize + j + yOffset) * iMaxLineWidth + i + xOffset;
|
||||||
|
|
||||||
// HTML5 canvas is non-pre-alpha-multiplied, so alpha-multiply here.
|
// HTML5 canvas is non-pre-alpha-multiplied, so alpha-multiply here.
|
||||||
unsigned char *p = (unsigned char*) &pixels[sourceOffset];
|
unsigned char *p = (unsigned char*) &pixels[sourceOffset];
|
||||||
|
@ -257,7 +293,7 @@ public:
|
||||||
SDL_FreeSurface(tSurf);
|
SDL_FreeSurface(tSurf);
|
||||||
}
|
}
|
||||||
|
|
||||||
//clear all lines
|
// clear all lines
|
||||||
vLines.clear();
|
vLines.clear();
|
||||||
|
|
||||||
TTF_CloseFont(face);
|
TTF_CloseFont(face);
|
||||||
|
|
|
@ -1,151 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "CCAccelerometer.h"
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import "CCAccelerometerDelegate.h"
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#import <functional>
|
|
||||||
|
|
||||||
@interface CCAccelerometerDispatcher : NSObject<UIAccelerometerDelegate>
|
|
||||||
{
|
|
||||||
std::function<void(cocos2d::Acceleration*)> _function;
|
|
||||||
cocos2d::Acceleration *_acceleration;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (id) sharedAccelerometerDispather;
|
|
||||||
- (id) init;
|
|
||||||
- (void) addDelegate: (std::function<void(cocos2d::Acceleration*)>) function;
|
|
||||||
- (void) setAccelerometerInterval:(float)interval;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation CCAccelerometerDispatcher
|
|
||||||
|
|
||||||
static CCAccelerometerDispatcher* s_pAccelerometerDispatcher;
|
|
||||||
|
|
||||||
+ (id) sharedAccelerometerDispather
|
|
||||||
{
|
|
||||||
if (s_pAccelerometerDispatcher == nil) {
|
|
||||||
s_pAccelerometerDispatcher = [[self alloc] init];
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_pAccelerometerDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) init
|
|
||||||
{
|
|
||||||
_acceleration = new cocos2d::Acceleration();
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
s_pAccelerometerDispatcher = nullptr;
|
|
||||||
_function = nullptr;
|
|
||||||
delete _acceleration;
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) addDelegate: (std::function<void(cocos2d::Acceleration*)>) function
|
|
||||||
{
|
|
||||||
_function = function;
|
|
||||||
|
|
||||||
if (_function)
|
|
||||||
{
|
|
||||||
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) setAccelerometerInterval:(float)interval
|
|
||||||
{
|
|
||||||
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:interval];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
|
|
||||||
{
|
|
||||||
if (! _function)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_acceleration->x = acceleration.x;
|
|
||||||
_acceleration->y = acceleration.y;
|
|
||||||
_acceleration->z = acceleration.z;
|
|
||||||
_acceleration->timestamp = acceleration.timestamp;
|
|
||||||
|
|
||||||
double tmp = _acceleration->x;
|
|
||||||
|
|
||||||
switch ([[UIApplication sharedApplication] statusBarOrientation])
|
|
||||||
{
|
|
||||||
case UIInterfaceOrientationLandscapeRight:
|
|
||||||
_acceleration->x = -_acceleration->y;
|
|
||||||
_acceleration->y = tmp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UIInterfaceOrientationLandscapeLeft:
|
|
||||||
_acceleration->x = _acceleration->y;
|
|
||||||
_acceleration->y = -tmp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UIInterfaceOrientationPortraitUpsideDown:
|
|
||||||
_acceleration->x = -_acceleration->y;
|
|
||||||
_acceleration->y = -tmp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UIInterfaceOrientationPortrait:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
_function(_acceleration);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
/** Implementation of Accelerometer
|
|
||||||
*/
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
|
|
||||||
Accelerometer::Accelerometer() {}
|
|
||||||
|
|
||||||
Accelerometer::~Accelerometer() {}
|
|
||||||
|
|
||||||
void Accelerometer::setDelegate(std::function<void (Acceleration *)> function)
|
|
||||||
{
|
|
||||||
[[CCAccelerometerDispatcher sharedAccelerometerDispather] addDelegate:function];
|
|
||||||
}
|
|
||||||
|
|
||||||
void Accelerometer::setAccelerometerInterval(float interval)
|
|
||||||
{
|
|
||||||
[[CCAccelerometerDispatcher sharedAccelerometerDispather] setAccelerometerInterval:interval];
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
|
@ -1,6 +1,109 @@
|
||||||
#include "CCDevice.h"
|
#include "CCDevice.h"
|
||||||
|
#include "ccTypes.h"
|
||||||
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCAccelerationEvent.h"
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
// Accelerometer
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <functional>
|
||||||
|
|
||||||
|
@interface CCAccelerometerDispatcher : NSObject<UIAccelerometerDelegate>
|
||||||
|
{
|
||||||
|
cocos2d::Acceleration *_acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (id) sharedAccelerometerDispather;
|
||||||
|
- (id) init;
|
||||||
|
- (void) setAccelerometerEnabled: (bool) isEnabled;
|
||||||
|
- (void) setAccelerometerInterval:(float) interval;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation CCAccelerometerDispatcher
|
||||||
|
|
||||||
|
static CCAccelerometerDispatcher* s_pAccelerometerDispatcher;
|
||||||
|
|
||||||
|
+ (id) sharedAccelerometerDispather
|
||||||
|
{
|
||||||
|
if (s_pAccelerometerDispatcher == nil) {
|
||||||
|
s_pAccelerometerDispatcher = [[self alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
return s_pAccelerometerDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) init
|
||||||
|
{
|
||||||
|
_acceleration = new cocos2d::Acceleration();
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
s_pAccelerometerDispatcher = nullptr;
|
||||||
|
delete _acceleration;
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setAccelerometerEnabled: (bool) isEnabled
|
||||||
|
{
|
||||||
|
if (isEnabled)
|
||||||
|
{
|
||||||
|
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) setAccelerometerInterval:(float)interval
|
||||||
|
{
|
||||||
|
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:interval];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
|
||||||
|
{
|
||||||
|
_acceleration->x = acceleration.x;
|
||||||
|
_acceleration->y = acceleration.y;
|
||||||
|
_acceleration->z = acceleration.z;
|
||||||
|
_acceleration->timestamp = acceleration.timestamp;
|
||||||
|
|
||||||
|
double tmp = _acceleration->x;
|
||||||
|
|
||||||
|
switch ([[UIApplication sharedApplication] statusBarOrientation])
|
||||||
|
{
|
||||||
|
case UIInterfaceOrientationLandscapeRight:
|
||||||
|
_acceleration->x = -_acceleration->y;
|
||||||
|
_acceleration->y = tmp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UIInterfaceOrientationLandscapeLeft:
|
||||||
|
_acceleration->x = _acceleration->y;
|
||||||
|
_acceleration->y = -tmp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UIInterfaceOrientationPortraitUpsideDown:
|
||||||
|
_acceleration->x = -_acceleration->y;
|
||||||
|
_acceleration->y = -tmp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UIInterfaceOrientationPortrait:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cocos2d::AccelerationEvent event;
|
||||||
|
event.acc = *_acceleration;
|
||||||
|
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
int Device::getDPI()
|
int Device::getDPI()
|
||||||
|
@ -26,4 +129,18 @@ int Device::getDPI()
|
||||||
return dpi;
|
return dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
[[CCAccelerometerDispatcher sharedAccelerometerDispather] setAccelerometerEnabled:isEnabled];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{
|
||||||
|
[[CCAccelerometerDispatcher sharedAccelerometerDispather] setAccelerometerInterval:interval];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -26,7 +26,6 @@ THE SOFTWARE.
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
#include "CCSet.h"
|
#include "CCSet.h"
|
||||||
#include "CCTouch.h"
|
#include "CCTouch.h"
|
||||||
#include "CCTouchDispatcher.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
|
|
@ -28,4 +28,14 @@ int Device::getDPI()
|
||||||
return dpi;
|
return dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -9,13 +9,145 @@
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
||||||
#include "text_input_node/CCIMEDispatcher.h"
|
#include "text_input_node/CCIMEDispatcher.h"
|
||||||
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
|
||||||
|
static std::map<int, KeyboardEvent::KeyCode> g_keyCodeMap = {
|
||||||
|
/* The unknown key */
|
||||||
|
{ GLFW_KEY_UNKNOWN , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
|
||||||
|
/* Printable keys */
|
||||||
|
{ GLFW_KEY_SPACE , KeyboardEvent::KeyCode::KEY_SPACE },
|
||||||
|
{ GLFW_KEY_APOSTROPHE , KeyboardEvent::KeyCode::KEY_APOSTROPHE },
|
||||||
|
{ GLFW_KEY_COMMA , KeyboardEvent::KeyCode::KEY_COMMA },
|
||||||
|
{ GLFW_KEY_MINUS , KeyboardEvent::KeyCode::KEY_MINUS },
|
||||||
|
{ GLFW_KEY_PERIOD , KeyboardEvent::KeyCode::KEY_PERIOD },
|
||||||
|
{ GLFW_KEY_SLASH , KeyboardEvent::KeyCode::KEY_SLASH },
|
||||||
|
{ GLFW_KEY_0 , KeyboardEvent::KeyCode::KEY_0 },
|
||||||
|
{ GLFW_KEY_1 , KeyboardEvent::KeyCode::KEY_1 },
|
||||||
|
{ GLFW_KEY_2 , KeyboardEvent::KeyCode::KEY_2 },
|
||||||
|
{ GLFW_KEY_3 , KeyboardEvent::KeyCode::KEY_3 },
|
||||||
|
{ GLFW_KEY_4 , KeyboardEvent::KeyCode::KEY_4 },
|
||||||
|
{ GLFW_KEY_5 , KeyboardEvent::KeyCode::KEY_5 },
|
||||||
|
{ GLFW_KEY_6 , KeyboardEvent::KeyCode::KEY_6 },
|
||||||
|
{ GLFW_KEY_7 , KeyboardEvent::KeyCode::KEY_7 },
|
||||||
|
{ GLFW_KEY_8 , KeyboardEvent::KeyCode::KEY_8 },
|
||||||
|
{ GLFW_KEY_9 , KeyboardEvent::KeyCode::KEY_9 },
|
||||||
|
{ GLFW_KEY_SEMICOLON , KeyboardEvent::KeyCode::KEY_SEMICOLON },
|
||||||
|
{ GLFW_KEY_EQUAL , KeyboardEvent::KeyCode::KEY_EQUAL },
|
||||||
|
{ GLFW_KEY_A , KeyboardEvent::KeyCode::KEY_A },
|
||||||
|
{ GLFW_KEY_B , KeyboardEvent::KeyCode::KEY_B },
|
||||||
|
{ GLFW_KEY_C , KeyboardEvent::KeyCode::KEY_C },
|
||||||
|
{ GLFW_KEY_D , KeyboardEvent::KeyCode::KEY_D },
|
||||||
|
{ GLFW_KEY_E , KeyboardEvent::KeyCode::KEY_E },
|
||||||
|
{ GLFW_KEY_F , KeyboardEvent::KeyCode::KEY_F },
|
||||||
|
{ GLFW_KEY_G , KeyboardEvent::KeyCode::KEY_G },
|
||||||
|
{ GLFW_KEY_H , KeyboardEvent::KeyCode::KEY_H },
|
||||||
|
{ GLFW_KEY_I , KeyboardEvent::KeyCode::KEY_I },
|
||||||
|
{ GLFW_KEY_J , KeyboardEvent::KeyCode::KEY_J },
|
||||||
|
{ GLFW_KEY_K , KeyboardEvent::KeyCode::KEY_K },
|
||||||
|
{ GLFW_KEY_L , KeyboardEvent::KeyCode::KEY_L },
|
||||||
|
{ GLFW_KEY_M , KeyboardEvent::KeyCode::KEY_M },
|
||||||
|
{ GLFW_KEY_N , KeyboardEvent::KeyCode::KEY_N },
|
||||||
|
{ GLFW_KEY_O , KeyboardEvent::KeyCode::KEY_O },
|
||||||
|
{ GLFW_KEY_P , KeyboardEvent::KeyCode::KEY_P },
|
||||||
|
{ GLFW_KEY_Q , KeyboardEvent::KeyCode::KEY_Q },
|
||||||
|
{ GLFW_KEY_R , KeyboardEvent::KeyCode::KEY_R },
|
||||||
|
{ GLFW_KEY_S , KeyboardEvent::KeyCode::KEY_S },
|
||||||
|
{ GLFW_KEY_T , KeyboardEvent::KeyCode::KEY_T },
|
||||||
|
{ GLFW_KEY_U , KeyboardEvent::KeyCode::KEY_U },
|
||||||
|
{ GLFW_KEY_V , KeyboardEvent::KeyCode::KEY_V },
|
||||||
|
{ GLFW_KEY_W , KeyboardEvent::KeyCode::KEY_W },
|
||||||
|
{ GLFW_KEY_X , KeyboardEvent::KeyCode::KEY_X },
|
||||||
|
{ GLFW_KEY_Y , KeyboardEvent::KeyCode::KEY_Y },
|
||||||
|
{ GLFW_KEY_Z , KeyboardEvent::KeyCode::KEY_Z },
|
||||||
|
{ GLFW_KEY_LEFT_BRACKET , KeyboardEvent::KeyCode::KEY_LEFT_BRACKET },
|
||||||
|
{ GLFW_KEY_BACKSLASH , KeyboardEvent::KeyCode::KEY_BACK_SLASH },
|
||||||
|
{ GLFW_KEY_RIGHT_BRACKET , KeyboardEvent::KeyCode::KEY_RIGHT_BRACKET },
|
||||||
|
{ GLFW_KEY_GRAVE_ACCENT , KeyboardEvent::KeyCode::KEY_GRAVE },
|
||||||
|
{ GLFW_KEY_WORLD_1 , KeyboardEvent::KeyCode::KEY_GRAVE },
|
||||||
|
{ GLFW_KEY_WORLD_2 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
|
||||||
|
/* Function keys */
|
||||||
|
{ GLFW_KEY_ESCAPE , KeyboardEvent::KeyCode::KEY_ESCAPE },
|
||||||
|
{ GLFW_KEY_ENTER , KeyboardEvent::KeyCode::KEY_KP_ENTER },
|
||||||
|
{ GLFW_KEY_TAB , KeyboardEvent::KeyCode::KEY_TAB },
|
||||||
|
{ GLFW_KEY_BACKSPACE , KeyboardEvent::KeyCode::KEY_BACKSPACE },
|
||||||
|
{ GLFW_KEY_INSERT , KeyboardEvent::KeyCode::KEY_INSERT },
|
||||||
|
{ GLFW_KEY_DELETE , KeyboardEvent::KeyCode::KEY_DELETE },
|
||||||
|
{ GLFW_KEY_RIGHT , KeyboardEvent::KeyCode::KEY_RIGHT_ARROW },
|
||||||
|
{ GLFW_KEY_LEFT , KeyboardEvent::KeyCode::KEY_LEFT_ARROW },
|
||||||
|
{ GLFW_KEY_DOWN , KeyboardEvent::KeyCode::KEY_DOWN_ARROW },
|
||||||
|
{ GLFW_KEY_UP , KeyboardEvent::KeyCode::KEY_UP_ARROW },
|
||||||
|
{ GLFW_KEY_PAGE_UP , KeyboardEvent::KeyCode::KEY_KP_PG_UP },
|
||||||
|
{ GLFW_KEY_PAGE_DOWN , KeyboardEvent::KeyCode::KEY_KP_PG_DOWN },
|
||||||
|
{ GLFW_KEY_HOME , KeyboardEvent::KeyCode::KEY_KP_HOME },
|
||||||
|
{ GLFW_KEY_END , KeyboardEvent::KeyCode::KEY_END },
|
||||||
|
{ GLFW_KEY_CAPS_LOCK , KeyboardEvent::KeyCode::KEY_CAPS_LOCK },
|
||||||
|
{ GLFW_KEY_SCROLL_LOCK , KeyboardEvent::KeyCode::KEY_SCROLL_LOCK },
|
||||||
|
{ GLFW_KEY_NUM_LOCK , KeyboardEvent::KeyCode::KEY_NUM_LOCK },
|
||||||
|
{ GLFW_KEY_PRINT_SCREEN , KeyboardEvent::KeyCode::KEY_PRINT },
|
||||||
|
{ GLFW_KEY_PAUSE , KeyboardEvent::KeyCode::KEY_PAUSE },
|
||||||
|
{ GLFW_KEY_F1 , KeyboardEvent::KeyCode::KEY_F1 },
|
||||||
|
{ GLFW_KEY_F2 , KeyboardEvent::KeyCode::KEY_F2 },
|
||||||
|
{ GLFW_KEY_F3 , KeyboardEvent::KeyCode::KEY_F3 },
|
||||||
|
{ GLFW_KEY_F4 , KeyboardEvent::KeyCode::KEY_F4 },
|
||||||
|
{ GLFW_KEY_F5 , KeyboardEvent::KeyCode::KEY_F5 },
|
||||||
|
{ GLFW_KEY_F6 , KeyboardEvent::KeyCode::KEY_F6 },
|
||||||
|
{ GLFW_KEY_F7 , KeyboardEvent::KeyCode::KEY_F7 },
|
||||||
|
{ GLFW_KEY_F8 , KeyboardEvent::KeyCode::KEY_F8 },
|
||||||
|
{ GLFW_KEY_F9 , KeyboardEvent::KeyCode::KEY_F9 },
|
||||||
|
{ GLFW_KEY_F10 , KeyboardEvent::KeyCode::KEY_F10 },
|
||||||
|
{ GLFW_KEY_F11 , KeyboardEvent::KeyCode::KEY_F11 },
|
||||||
|
{ GLFW_KEY_F12 , KeyboardEvent::KeyCode::KEY_F12 },
|
||||||
|
{ GLFW_KEY_F13 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F14 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F15 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F16 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F17 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F18 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F19 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F20 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F21 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F22 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F23 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F24 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F25 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_KP_0 , KeyboardEvent::KeyCode::KEY_0 },
|
||||||
|
{ GLFW_KEY_KP_1 , KeyboardEvent::KeyCode::KEY_1 },
|
||||||
|
{ GLFW_KEY_KP_2 , KeyboardEvent::KeyCode::KEY_2 },
|
||||||
|
{ GLFW_KEY_KP_3 , KeyboardEvent::KeyCode::KEY_3 },
|
||||||
|
{ GLFW_KEY_KP_4 , KeyboardEvent::KeyCode::KEY_4 },
|
||||||
|
{ GLFW_KEY_KP_5 , KeyboardEvent::KeyCode::KEY_5 },
|
||||||
|
{ GLFW_KEY_KP_6 , KeyboardEvent::KeyCode::KEY_6 },
|
||||||
|
{ GLFW_KEY_KP_7 , KeyboardEvent::KeyCode::KEY_7 },
|
||||||
|
{ GLFW_KEY_KP_8 , KeyboardEvent::KeyCode::KEY_8 },
|
||||||
|
{ GLFW_KEY_KP_9 , KeyboardEvent::KeyCode::KEY_9 },
|
||||||
|
{ GLFW_KEY_KP_DECIMAL , KeyboardEvent::KeyCode::KEY_PERIOD },
|
||||||
|
{ GLFW_KEY_KP_DIVIDE , KeyboardEvent::KeyCode::KEY_KP_DIVIDE },
|
||||||
|
{ GLFW_KEY_KP_MULTIPLY , KeyboardEvent::KeyCode::KEY_KP_MULTIPLY },
|
||||||
|
{ GLFW_KEY_KP_SUBTRACT , KeyboardEvent::KeyCode::KEY_KP_MINUS },
|
||||||
|
{ GLFW_KEY_KP_ADD , KeyboardEvent::KeyCode::KEY_KP_PLUS },
|
||||||
|
{ GLFW_KEY_KP_ENTER , KeyboardEvent::KeyCode::KEY_KP_ENTER },
|
||||||
|
{ GLFW_KEY_KP_EQUAL , KeyboardEvent::KeyCode::KEY_EQUAL },
|
||||||
|
{ GLFW_KEY_LEFT_SHIFT , KeyboardEvent::KeyCode::KEY_SHIFT },
|
||||||
|
{ GLFW_KEY_LEFT_CONTROL , KeyboardEvent::KeyCode::KEY_CTRL },
|
||||||
|
{ GLFW_KEY_LEFT_ALT , KeyboardEvent::KeyCode::KEY_ALT },
|
||||||
|
{ GLFW_KEY_LEFT_SUPER , KeyboardEvent::KeyCode::KEY_HYPER },
|
||||||
|
{ GLFW_KEY_RIGHT_SHIFT , KeyboardEvent::KeyCode::KEY_SHIFT },
|
||||||
|
{ GLFW_KEY_RIGHT_CONTROL , KeyboardEvent::KeyCode::KEY_CTRL },
|
||||||
|
{ GLFW_KEY_RIGHT_ALT , KeyboardEvent::KeyCode::KEY_ALT },
|
||||||
|
{ GLFW_KEY_RIGHT_SUPER , KeyboardEvent::KeyCode::KEY_HYPER },
|
||||||
|
{ GLFW_KEY_MENU , KeyboardEvent::KeyCode::KEY_MENU },
|
||||||
|
{ GLFW_KEY_LAST , KeyboardEvent::KeyCode::KEY_NONE }
|
||||||
|
};
|
||||||
|
|
||||||
//begin EGLViewEventHandler
|
//begin EGLViewEventHandler
|
||||||
class EGLViewEventHandler
|
class EGLViewEventHandler
|
||||||
{
|
{
|
||||||
|
@ -29,6 +161,7 @@ public:
|
||||||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||||
|
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool EGLViewEventHandler::s_captured = false;
|
bool EGLViewEventHandler::s_captured = false;
|
||||||
|
@ -89,14 +222,10 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
if(GLFW_PRESS == action)
|
KeyboardEvent event;
|
||||||
{
|
event._keyCode = g_keyCodeMap[key];
|
||||||
Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(key, true);
|
event._isPressed = (GLFW_PRESS == action);
|
||||||
}
|
EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||||
else if(GLFW_RELEASE == action)
|
|
||||||
{
|
|
||||||
Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(key,false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||||
|
@ -104,6 +233,13 @@ void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int ch
|
||||||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||||
|
{
|
||||||
|
if(Director::getInstance())
|
||||||
|
{
|
||||||
|
Director::getInstance()->setViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
//end EGLViewEventHandler
|
//end EGLViewEventHandler
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,20 +268,25 @@ EGLView::~EGLView()
|
||||||
s_pEglView = nullptr;
|
s_pEglView = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EGLView::init(const char* viewName, float width, float height)
|
bool EGLView::init(const char* viewName, float width, float height, float frameZoomFactor)
|
||||||
{
|
{
|
||||||
if(nullptr != _mainWindow) return true;
|
if(nullptr != _mainWindow) return true;
|
||||||
|
|
||||||
setViewName(viewName);
|
setViewName(viewName);
|
||||||
setFrameSize(width, height);
|
setFrameSize(width, height);
|
||||||
|
setFrameZoomFactor(frameZoomFactor);
|
||||||
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||||
_mainWindow = glfwCreateWindow(_screenSize.width, _screenSize.height, _viewName, nullptr, nullptr);
|
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
|
||||||
glfwMakeContextCurrent(_mainWindow);
|
glfwMakeContextCurrent(_mainWindow);
|
||||||
|
|
||||||
|
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||||
|
|
||||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||||
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
||||||
|
glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback);
|
||||||
|
|
||||||
// check OpenGL version at first
|
// check OpenGL version at first
|
||||||
const GLubyte* glVersion = glGetString(GL_VERSION);
|
const GLubyte* glVersion = glGetString(GL_VERSION);
|
||||||
|
@ -251,18 +392,22 @@ void EGLView::setFrameSize(float width, float height)
|
||||||
|
|
||||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||||
|
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||||
|
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||||
|
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||||
|
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLView* EGLView::getInstance()
|
EGLView* EGLView::getInstance()
|
||||||
|
|
|
@ -38,15 +38,13 @@ public:
|
||||||
virtual void swapBuffers();
|
virtual void swapBuffers();
|
||||||
virtual void setFrameSize(float width, float height);
|
virtual void setFrameSize(float width, float height);
|
||||||
virtual void setIMEKeyboardState(bool bOpen);
|
virtual void setIMEKeyboardState(bool bOpen);
|
||||||
|
/*
|
||||||
bool init(const char* viewName, float width, float height);
|
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//void resize(int width, int height);
|
//void resize(int width, int height);
|
||||||
/*
|
|
||||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
|
||||||
*/
|
|
||||||
void setFrameZoomFactor(float fZoomFactor);
|
|
||||||
float getFrameZoomFactor();
|
float getFrameZoomFactor();
|
||||||
//void centerWindow();
|
//void centerWindow();
|
||||||
|
|
||||||
|
@ -63,11 +61,15 @@ public:
|
||||||
/** @deprecated Use getInstance() instead */
|
/** @deprecated Use getInstance() instead */
|
||||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||||
protected:
|
protected:
|
||||||
|
/*
|
||||||
|
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
void setFrameZoomFactor(float fZoomFactor);
|
||||||
private:
|
private:
|
||||||
bool _captured;
|
bool _captured;
|
||||||
bool _supportTouch;
|
bool _supportTouch;
|
||||||
|
|
||||||
|
int _frameBufferSize[2];
|
||||||
float _frameZoomFactor;
|
float _frameZoomFactor;
|
||||||
static EGLView* s_pEglView;
|
static EGLView* s_pEglView;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -8,4 +8,14 @@ int Device::getDPI()
|
||||||
return 160;
|
return 160;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -50,15 +50,14 @@ public:
|
||||||
virtual void swapBuffers();
|
virtual void swapBuffers();
|
||||||
virtual void setFrameSize(float width, float height);
|
virtual void setFrameSize(float width, float height);
|
||||||
virtual void setIMEKeyboardState(bool bOpen);
|
virtual void setIMEKeyboardState(bool bOpen);
|
||||||
|
/*
|
||||||
bool init(const char* viewName, float width, float height);
|
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//void resize(int width, int height);
|
//void resize(int width, int height);
|
||||||
/*
|
|
||||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
|
||||||
*/
|
|
||||||
void setFrameZoomFactor(float fZoomFactor);
|
|
||||||
float getFrameZoomFactor();
|
float getFrameZoomFactor();
|
||||||
//void centerWindow();
|
//void centerWindow();
|
||||||
|
|
||||||
|
@ -75,11 +74,15 @@ public:
|
||||||
/** @deprecated Use getInstance() instead */
|
/** @deprecated Use getInstance() instead */
|
||||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||||
protected:
|
protected:
|
||||||
|
/*
|
||||||
|
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
void setFrameZoomFactor(float fZoomFactor);
|
||||||
private:
|
private:
|
||||||
bool _captured;
|
bool _captured;
|
||||||
bool _supportTouch;
|
bool _supportTouch;
|
||||||
|
|
||||||
|
int _frameBufferSize[2];
|
||||||
float _frameZoomFactor;
|
float _frameZoomFactor;
|
||||||
static EGLView* s_pEglView;
|
static EGLView* s_pEglView;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -25,13 +25,145 @@
|
||||||
#include "EAGLView.h"
|
#include "EAGLView.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCSet.h"
|
#include "CCSet.h"
|
||||||
#include "CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "CCTouchDispatcher.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
#include "CCKeyboardDispatcher.h"
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
#include "CCIMEDispatcher.h"
|
#include "CCIMEDispatcher.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
|
||||||
|
static std::map<int, KeyboardEvent::KeyCode> g_keyCodeMap = {
|
||||||
|
/* The unknown key */
|
||||||
|
{ GLFW_KEY_UNKNOWN , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
|
||||||
|
/* Printable keys */
|
||||||
|
{ GLFW_KEY_SPACE , KeyboardEvent::KeyCode::KEY_SPACE },
|
||||||
|
{ GLFW_KEY_APOSTROPHE , KeyboardEvent::KeyCode::KEY_APOSTROPHE },
|
||||||
|
{ GLFW_KEY_COMMA , KeyboardEvent::KeyCode::KEY_COMMA },
|
||||||
|
{ GLFW_KEY_MINUS , KeyboardEvent::KeyCode::KEY_MINUS },
|
||||||
|
{ GLFW_KEY_PERIOD , KeyboardEvent::KeyCode::KEY_PERIOD },
|
||||||
|
{ GLFW_KEY_SLASH , KeyboardEvent::KeyCode::KEY_SLASH },
|
||||||
|
{ GLFW_KEY_0 , KeyboardEvent::KeyCode::KEY_0 },
|
||||||
|
{ GLFW_KEY_1 , KeyboardEvent::KeyCode::KEY_1 },
|
||||||
|
{ GLFW_KEY_2 , KeyboardEvent::KeyCode::KEY_2 },
|
||||||
|
{ GLFW_KEY_3 , KeyboardEvent::KeyCode::KEY_3 },
|
||||||
|
{ GLFW_KEY_4 , KeyboardEvent::KeyCode::KEY_4 },
|
||||||
|
{ GLFW_KEY_5 , KeyboardEvent::KeyCode::KEY_5 },
|
||||||
|
{ GLFW_KEY_6 , KeyboardEvent::KeyCode::KEY_6 },
|
||||||
|
{ GLFW_KEY_7 , KeyboardEvent::KeyCode::KEY_7 },
|
||||||
|
{ GLFW_KEY_8 , KeyboardEvent::KeyCode::KEY_8 },
|
||||||
|
{ GLFW_KEY_9 , KeyboardEvent::KeyCode::KEY_9 },
|
||||||
|
{ GLFW_KEY_SEMICOLON , KeyboardEvent::KeyCode::KEY_SEMICOLON },
|
||||||
|
{ GLFW_KEY_EQUAL , KeyboardEvent::KeyCode::KEY_EQUAL },
|
||||||
|
{ GLFW_KEY_A , KeyboardEvent::KeyCode::KEY_A },
|
||||||
|
{ GLFW_KEY_B , KeyboardEvent::KeyCode::KEY_B },
|
||||||
|
{ GLFW_KEY_C , KeyboardEvent::KeyCode::KEY_C },
|
||||||
|
{ GLFW_KEY_D , KeyboardEvent::KeyCode::KEY_D },
|
||||||
|
{ GLFW_KEY_E , KeyboardEvent::KeyCode::KEY_E },
|
||||||
|
{ GLFW_KEY_F , KeyboardEvent::KeyCode::KEY_F },
|
||||||
|
{ GLFW_KEY_G , KeyboardEvent::KeyCode::KEY_G },
|
||||||
|
{ GLFW_KEY_H , KeyboardEvent::KeyCode::KEY_H },
|
||||||
|
{ GLFW_KEY_I , KeyboardEvent::KeyCode::KEY_I },
|
||||||
|
{ GLFW_KEY_J , KeyboardEvent::KeyCode::KEY_J },
|
||||||
|
{ GLFW_KEY_K , KeyboardEvent::KeyCode::KEY_K },
|
||||||
|
{ GLFW_KEY_L , KeyboardEvent::KeyCode::KEY_L },
|
||||||
|
{ GLFW_KEY_M , KeyboardEvent::KeyCode::KEY_M },
|
||||||
|
{ GLFW_KEY_N , KeyboardEvent::KeyCode::KEY_N },
|
||||||
|
{ GLFW_KEY_O , KeyboardEvent::KeyCode::KEY_O },
|
||||||
|
{ GLFW_KEY_P , KeyboardEvent::KeyCode::KEY_P },
|
||||||
|
{ GLFW_KEY_Q , KeyboardEvent::KeyCode::KEY_Q },
|
||||||
|
{ GLFW_KEY_R , KeyboardEvent::KeyCode::KEY_R },
|
||||||
|
{ GLFW_KEY_S , KeyboardEvent::KeyCode::KEY_S },
|
||||||
|
{ GLFW_KEY_T , KeyboardEvent::KeyCode::KEY_T },
|
||||||
|
{ GLFW_KEY_U , KeyboardEvent::KeyCode::KEY_U },
|
||||||
|
{ GLFW_KEY_V , KeyboardEvent::KeyCode::KEY_V },
|
||||||
|
{ GLFW_KEY_W , KeyboardEvent::KeyCode::KEY_W },
|
||||||
|
{ GLFW_KEY_X , KeyboardEvent::KeyCode::KEY_X },
|
||||||
|
{ GLFW_KEY_Y , KeyboardEvent::KeyCode::KEY_Y },
|
||||||
|
{ GLFW_KEY_Z , KeyboardEvent::KeyCode::KEY_Z },
|
||||||
|
{ GLFW_KEY_LEFT_BRACKET , KeyboardEvent::KeyCode::KEY_LEFT_BRACKET },
|
||||||
|
{ GLFW_KEY_BACKSLASH , KeyboardEvent::KeyCode::KEY_BACK_SLASH },
|
||||||
|
{ GLFW_KEY_RIGHT_BRACKET , KeyboardEvent::KeyCode::KEY_RIGHT_BRACKET },
|
||||||
|
{ GLFW_KEY_GRAVE_ACCENT , KeyboardEvent::KeyCode::KEY_GRAVE },
|
||||||
|
{ GLFW_KEY_WORLD_1 , KeyboardEvent::KeyCode::KEY_GRAVE },
|
||||||
|
{ GLFW_KEY_WORLD_2 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
|
||||||
|
/* Function keys */
|
||||||
|
{ GLFW_KEY_ESCAPE , KeyboardEvent::KeyCode::KEY_ESCAPE },
|
||||||
|
{ GLFW_KEY_ENTER , KeyboardEvent::KeyCode::KEY_KP_ENTER },
|
||||||
|
{ GLFW_KEY_TAB , KeyboardEvent::KeyCode::KEY_TAB },
|
||||||
|
{ GLFW_KEY_BACKSPACE , KeyboardEvent::KeyCode::KEY_BACKSPACE },
|
||||||
|
{ GLFW_KEY_INSERT , KeyboardEvent::KeyCode::KEY_INSERT },
|
||||||
|
{ GLFW_KEY_DELETE , KeyboardEvent::KeyCode::KEY_DELETE },
|
||||||
|
{ GLFW_KEY_RIGHT , KeyboardEvent::KeyCode::KEY_RIGHT_ARROW },
|
||||||
|
{ GLFW_KEY_LEFT , KeyboardEvent::KeyCode::KEY_LEFT_ARROW },
|
||||||
|
{ GLFW_KEY_DOWN , KeyboardEvent::KeyCode::KEY_DOWN_ARROW },
|
||||||
|
{ GLFW_KEY_UP , KeyboardEvent::KeyCode::KEY_UP_ARROW },
|
||||||
|
{ GLFW_KEY_PAGE_UP , KeyboardEvent::KeyCode::KEY_KP_PG_UP },
|
||||||
|
{ GLFW_KEY_PAGE_DOWN , KeyboardEvent::KeyCode::KEY_KP_PG_DOWN },
|
||||||
|
{ GLFW_KEY_HOME , KeyboardEvent::KeyCode::KEY_KP_HOME },
|
||||||
|
{ GLFW_KEY_END , KeyboardEvent::KeyCode::KEY_END },
|
||||||
|
{ GLFW_KEY_CAPS_LOCK , KeyboardEvent::KeyCode::KEY_CAPS_LOCK },
|
||||||
|
{ GLFW_KEY_SCROLL_LOCK , KeyboardEvent::KeyCode::KEY_SCROLL_LOCK },
|
||||||
|
{ GLFW_KEY_NUM_LOCK , KeyboardEvent::KeyCode::KEY_NUM_LOCK },
|
||||||
|
{ GLFW_KEY_PRINT_SCREEN , KeyboardEvent::KeyCode::KEY_PRINT },
|
||||||
|
{ GLFW_KEY_PAUSE , KeyboardEvent::KeyCode::KEY_PAUSE },
|
||||||
|
{ GLFW_KEY_F1 , KeyboardEvent::KeyCode::KEY_F1 },
|
||||||
|
{ GLFW_KEY_F2 , KeyboardEvent::KeyCode::KEY_F2 },
|
||||||
|
{ GLFW_KEY_F3 , KeyboardEvent::KeyCode::KEY_F3 },
|
||||||
|
{ GLFW_KEY_F4 , KeyboardEvent::KeyCode::KEY_F4 },
|
||||||
|
{ GLFW_KEY_F5 , KeyboardEvent::KeyCode::KEY_F5 },
|
||||||
|
{ GLFW_KEY_F6 , KeyboardEvent::KeyCode::KEY_F6 },
|
||||||
|
{ GLFW_KEY_F7 , KeyboardEvent::KeyCode::KEY_F7 },
|
||||||
|
{ GLFW_KEY_F8 , KeyboardEvent::KeyCode::KEY_F8 },
|
||||||
|
{ GLFW_KEY_F9 , KeyboardEvent::KeyCode::KEY_F9 },
|
||||||
|
{ GLFW_KEY_F10 , KeyboardEvent::KeyCode::KEY_F10 },
|
||||||
|
{ GLFW_KEY_F11 , KeyboardEvent::KeyCode::KEY_F11 },
|
||||||
|
{ GLFW_KEY_F12 , KeyboardEvent::KeyCode::KEY_F12 },
|
||||||
|
{ GLFW_KEY_F13 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F14 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F15 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F16 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F17 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F18 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F19 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F20 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F21 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F22 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F23 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F24 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F25 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_KP_0 , KeyboardEvent::KeyCode::KEY_0 },
|
||||||
|
{ GLFW_KEY_KP_1 , KeyboardEvent::KeyCode::KEY_1 },
|
||||||
|
{ GLFW_KEY_KP_2 , KeyboardEvent::KeyCode::KEY_2 },
|
||||||
|
{ GLFW_KEY_KP_3 , KeyboardEvent::KeyCode::KEY_3 },
|
||||||
|
{ GLFW_KEY_KP_4 , KeyboardEvent::KeyCode::KEY_4 },
|
||||||
|
{ GLFW_KEY_KP_5 , KeyboardEvent::KeyCode::KEY_5 },
|
||||||
|
{ GLFW_KEY_KP_6 , KeyboardEvent::KeyCode::KEY_6 },
|
||||||
|
{ GLFW_KEY_KP_7 , KeyboardEvent::KeyCode::KEY_7 },
|
||||||
|
{ GLFW_KEY_KP_8 , KeyboardEvent::KeyCode::KEY_8 },
|
||||||
|
{ GLFW_KEY_KP_9 , KeyboardEvent::KeyCode::KEY_9 },
|
||||||
|
{ GLFW_KEY_KP_DECIMAL , KeyboardEvent::KeyCode::KEY_PERIOD },
|
||||||
|
{ GLFW_KEY_KP_DIVIDE , KeyboardEvent::KeyCode::KEY_KP_DIVIDE },
|
||||||
|
{ GLFW_KEY_KP_MULTIPLY , KeyboardEvent::KeyCode::KEY_KP_MULTIPLY },
|
||||||
|
{ GLFW_KEY_KP_SUBTRACT , KeyboardEvent::KeyCode::KEY_KP_MINUS },
|
||||||
|
{ GLFW_KEY_KP_ADD , KeyboardEvent::KeyCode::KEY_KP_PLUS },
|
||||||
|
{ GLFW_KEY_KP_ENTER , KeyboardEvent::KeyCode::KEY_KP_ENTER },
|
||||||
|
{ GLFW_KEY_KP_EQUAL , KeyboardEvent::KeyCode::KEY_EQUAL },
|
||||||
|
{ GLFW_KEY_LEFT_SHIFT , KeyboardEvent::KeyCode::KEY_SHIFT },
|
||||||
|
{ GLFW_KEY_LEFT_CONTROL , KeyboardEvent::KeyCode::KEY_CTRL },
|
||||||
|
{ GLFW_KEY_LEFT_ALT , KeyboardEvent::KeyCode::KEY_ALT },
|
||||||
|
{ GLFW_KEY_LEFT_SUPER , KeyboardEvent::KeyCode::KEY_HYPER },
|
||||||
|
{ GLFW_KEY_RIGHT_SHIFT , KeyboardEvent::KeyCode::KEY_SHIFT },
|
||||||
|
{ GLFW_KEY_RIGHT_CONTROL , KeyboardEvent::KeyCode::KEY_CTRL },
|
||||||
|
{ GLFW_KEY_RIGHT_ALT , KeyboardEvent::KeyCode::KEY_ALT },
|
||||||
|
{ GLFW_KEY_RIGHT_SUPER , KeyboardEvent::KeyCode::KEY_HYPER },
|
||||||
|
{ GLFW_KEY_MENU , KeyboardEvent::KeyCode::KEY_MENU },
|
||||||
|
{ GLFW_KEY_LAST , KeyboardEvent::KeyCode::KEY_NONE }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//begin EGLViewEventHandler
|
//begin EGLViewEventHandler
|
||||||
class EGLViewEventHandler
|
class EGLViewEventHandler
|
||||||
{
|
{
|
||||||
|
@ -45,6 +177,7 @@ public:
|
||||||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||||
|
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool EGLViewEventHandler::s_captured = false;
|
bool EGLViewEventHandler::s_captured = false;
|
||||||
|
@ -105,14 +238,10 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
if(GLFW_PRESS == action)
|
KeyboardEvent event;
|
||||||
{
|
event._keyCode = g_keyCodeMap[key];
|
||||||
Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(key, true);
|
event._isPressed = (GLFW_PRESS == action);
|
||||||
}
|
EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||||
else if(GLFW_RELEASE == action)
|
|
||||||
{
|
|
||||||
Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(key,false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||||
|
@ -120,6 +249,14 @@ void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int ch
|
||||||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||||
|
{
|
||||||
|
if(Director::getInstance())
|
||||||
|
{
|
||||||
|
Director::getInstance()->setViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//end EGLViewEventHandler
|
//end EGLViewEventHandler
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,20 +286,25 @@ EGLView::~EGLView()
|
||||||
s_pEglView = nullptr;
|
s_pEglView = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EGLView::init(const char *viewName, float width, float height)
|
bool EGLView::init(const char *viewName, float width, float height, float frameZoomFactor)
|
||||||
{
|
{
|
||||||
if(nullptr != _mainWindow) return true;
|
if(nullptr != _mainWindow) return true;
|
||||||
|
|
||||||
setViewName(viewName);
|
setViewName(viewName);
|
||||||
setFrameSize(width, height);
|
setFrameSize(width, height);
|
||||||
|
setFrameZoomFactor(frameZoomFactor);
|
||||||
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||||
_mainWindow = glfwCreateWindow(_screenSize.width, _screenSize.height, _viewName, nullptr, nullptr);
|
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
|
||||||
glfwMakeContextCurrent(_mainWindow);
|
glfwMakeContextCurrent(_mainWindow);
|
||||||
|
|
||||||
|
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||||
|
|
||||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||||
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
||||||
|
glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback);
|
||||||
|
|
||||||
// check OpenGL version at first
|
// check OpenGL version at first
|
||||||
const GLubyte* glVersion = glGetString(GL_VERSION);
|
const GLubyte* glVersion = glGetString(GL_VERSION);
|
||||||
|
@ -268,18 +410,22 @@ void EGLView::setFrameSize(float width, float height)
|
||||||
|
|
||||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||||
|
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||||
|
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||||
|
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||||
|
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLView* EGLView::getInstance()
|
EGLView* EGLView::getInstance()
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
// Only compile this code on Mac. These files should not be included on your iOS project.
|
// Only compile this code on Mac. These files should not be included on your iOS project.
|
||||||
// But in case they are included, it won't be compiled.
|
// But in case they are included, it won't be compiled.
|
||||||
#import <Availability.h>
|
#import <Availability.h>
|
||||||
#ifndef __CC_EVENT_DISPATCHER_H__
|
#ifndef __CC_EVENT_DISPATCHER_MAC_H__
|
||||||
#define __CC_EVENT_DISPATCHER_H__
|
#define __CC_EVENT_DISPATCHER_MAC_H__
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
@ -275,4 +275,4 @@ struct _listEntry;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
//NS_CC_END;
|
//NS_CC_END;
|
||||||
#endif // __CC_EVENT_DISPATCHER_H__
|
#endif // __CC_EVENT_DISPATCHER_MAC_H__
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "support/data_support/utlist.h"
|
#include "support/data_support/utlist.h"
|
||||||
|
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
#include "platform/mac/CCEventDispatcher.h"
|
||||||
|
|
||||||
//NS_CC_BEGIN;
|
//NS_CC_BEGIN;
|
||||||
static CCEventDispatcher *sharedDispatcher = nil;
|
static CCEventDispatcher *sharedDispatcher = nil;
|
||||||
|
@ -505,7 +505,7 @@ static int eventQueueCount;
|
||||||
{
|
{
|
||||||
if( dispatchEvents_ ) {
|
if( dispatchEvents_ ) {
|
||||||
tListEntry *entry, *tmp;
|
tListEntry *entry, *tmp;
|
||||||
cocos2d::Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, true);
|
// cocos2d::Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, true);
|
||||||
|
|
||||||
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
||||||
if ( entry->flags & kImplementsKeyDown ) {
|
if ( entry->flags & kImplementsKeyDown ) {
|
||||||
|
@ -521,7 +521,7 @@ static int eventQueueCount;
|
||||||
{
|
{
|
||||||
if( dispatchEvents_ ) {
|
if( dispatchEvents_ ) {
|
||||||
tListEntry *entry, *tmp;
|
tListEntry *entry, *tmp;
|
||||||
cocos2d::Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, false);
|
// cocos2d::Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, false);
|
||||||
|
|
||||||
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
||||||
if ( entry->flags & kImplementsKeyUp ) {
|
if ( entry->flags & kImplementsKeyUp ) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCInstance.h"
|
#include "CCInstance.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
#include "touch_dispatcher/CCTouchDispatcher.h"
|
||||||
#include "text_input_node/CCIMEDispatcher.h"
|
#include "text_input_node/CCIMEDispatcher.h"
|
||||||
|
|
||||||
|
|
|
@ -40,4 +40,14 @@ int Device::getDPI()
|
||||||
return screen->physicalDotsPerInch();
|
return screen->physicalDotsPerInch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -32,8 +32,9 @@
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
|
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
#include "text_input_node/CCIMEDispatcher.h"
|
#include "text_input_node/CCIMEDispatcher.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
|
@ -40,4 +40,14 @@ int Device::getDPI()
|
||||||
return dpi;
|
return dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -1,201 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
|
||||||
Copyright (c) 2012 Rocco Loscalzo (Wartortle)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "CCAccelerometer.h"
|
|
||||||
#include "CCEGLView.h"
|
|
||||||
#include "CCDirector.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
|
|
||||||
double g_accelX=0.0;
|
|
||||||
double g_accelY=0.0;
|
|
||||||
double g_accelZ=0.0;
|
|
||||||
const double g_accelerationStep=0.2f;
|
|
||||||
const double g_minAcceleration=-1.0f;
|
|
||||||
const double g_maxAcceleration=1.0f;
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
T CLAMP( const T val,const T minVal,const T maxVal )
|
|
||||||
{
|
|
||||||
CC_ASSERT( minVal<=maxVal );
|
|
||||||
T result=val;
|
|
||||||
if ( result<minVal )
|
|
||||||
result=minVal;
|
|
||||||
else if ( result>maxVal )
|
|
||||||
result=maxVal;
|
|
||||||
|
|
||||||
CC_ASSERT( minVal<=result && result<=maxVal );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool handleKeyDown( WPARAM wParam )
|
|
||||||
{
|
|
||||||
bool sendUpdate=false;
|
|
||||||
switch( wParam )
|
|
||||||
{
|
|
||||||
case VK_LEFT:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelX=CLAMP( g_accelX-g_accelerationStep,g_minAcceleration,g_maxAcceleration );
|
|
||||||
break;
|
|
||||||
case VK_RIGHT:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelX=CLAMP( g_accelX+g_accelerationStep,g_minAcceleration,g_maxAcceleration );
|
|
||||||
break;
|
|
||||||
case VK_UP:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelY=CLAMP( g_accelY+g_accelerationStep,g_minAcceleration,g_maxAcceleration );
|
|
||||||
break;
|
|
||||||
case VK_DOWN:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelY=CLAMP( g_accelY-g_accelerationStep,g_minAcceleration,g_maxAcceleration );
|
|
||||||
break;
|
|
||||||
case VK_OEM_COMMA:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelZ=CLAMP( g_accelZ+g_accelerationStep,g_minAcceleration,g_maxAcceleration );
|
|
||||||
break;
|
|
||||||
case VK_OEM_PERIOD:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelZ=CLAMP( g_accelZ-g_accelerationStep,g_minAcceleration,g_maxAcceleration );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return sendUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool handleKeyUp( WPARAM wParam )
|
|
||||||
{
|
|
||||||
bool sendUpdate=false;
|
|
||||||
switch( wParam )
|
|
||||||
{
|
|
||||||
case VK_LEFT:
|
|
||||||
case VK_RIGHT:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelX=0.0;
|
|
||||||
break;
|
|
||||||
case VK_UP:
|
|
||||||
case VK_DOWN:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelY=0.0;
|
|
||||||
break;
|
|
||||||
case VK_OEM_COMMA:
|
|
||||||
case VK_OEM_PERIOD:
|
|
||||||
sendUpdate=true;
|
|
||||||
g_accelZ=0.0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return sendUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void myAccelerometerKeyHook( UINT message,WPARAM wParam,LPARAM lParam )
|
|
||||||
{
|
|
||||||
cocos2d::Accelerometer *pAccelerometer = cocos2d::Director::getInstance()->getAccelerometer();
|
|
||||||
bool sendUpdate=false;
|
|
||||||
switch( message )
|
|
||||||
{
|
|
||||||
case WM_KEYDOWN:
|
|
||||||
sendUpdate=handleKeyDown( wParam );
|
|
||||||
break;
|
|
||||||
case WM_KEYUP:
|
|
||||||
sendUpdate=handleKeyUp( wParam );
|
|
||||||
break;
|
|
||||||
case WM_CHAR:
|
|
||||||
// Deliberately empty - all handled through key up and down events
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Not expected to get here!!
|
|
||||||
CC_ASSERT( false );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sendUpdate )
|
|
||||||
{
|
|
||||||
const time_t theTime=time(NULL);
|
|
||||||
const double timestamp=(double)theTime / 100.0;
|
|
||||||
pAccelerometer->update( g_accelX,g_accelY,g_accelZ,timestamp );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetAccelerometer()
|
|
||||||
{
|
|
||||||
g_accelX=0.0;
|
|
||||||
g_accelY=0.0;
|
|
||||||
g_accelZ=0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
Accelerometer::Accelerometer() :
|
|
||||||
_function(nullptr)
|
|
||||||
{
|
|
||||||
memset(&_accelerationValue, 0, sizeof(_accelerationValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
Accelerometer::~Accelerometer()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Accelerometer::setDelegate(std::function<void(Acceleration*)> function)
|
|
||||||
{
|
|
||||||
_function = function;
|
|
||||||
|
|
||||||
// Enable/disable the accelerometer.
|
|
||||||
// Well, there isn't one on Win32 so we don't do anything other than register
|
|
||||||
// and deregister ourselves from the Windows Key handler.
|
|
||||||
if (_function)
|
|
||||||
{
|
|
||||||
// Register our handler
|
|
||||||
EGLView::getInstance()->setAccelerometerKeyHook( &myAccelerometerKeyHook );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// De-register our handler
|
|
||||||
EGLView::getInstance()->setAccelerometerKeyHook( NULL );
|
|
||||||
resetAccelerometer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Accelerometer::setAccelerometerInterval(float interval)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Accelerometer::update( double x,double y,double z,double timestamp )
|
|
||||||
{
|
|
||||||
if (_function)
|
|
||||||
{
|
|
||||||
_accelerationValue.x = x;
|
|
||||||
_accelerationValue.y = y;
|
|
||||||
_accelerationValue.z = z;
|
|
||||||
_accelerationValue.timestamp = timestamp;
|
|
||||||
|
|
||||||
// Delegate
|
|
||||||
_function(&_accelerationValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
||||||
|
|
|
@ -17,4 +17,10 @@ int Device::getDPI()
|
||||||
return dpi;
|
return dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setAccelerometerEnabled(bool isEnabled)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void Device::setAccelerometerInterval(float interval)
|
||||||
|
{}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
|
@ -26,17 +26,146 @@ THE SOFTWARE.
|
||||||
#include "cocoa/CCSet.h"
|
#include "cocoa/CCSet.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
||||||
#include "text_input_node/CCIMEDispatcher.h"
|
#include "text_input_node/CCIMEDispatcher.h"
|
||||||
#include "keypad_dispatcher/CCKeypadDispatcher.h"
|
|
||||||
#include "CCApplication.h"
|
#include "CCApplication.h"
|
||||||
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "text_input_node/CCIMEDispatcher.h"
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||||
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
static std::map<int, KeyboardEvent::KeyCode> g_keyCodeMap;// = {
|
||||||
|
/* The unknown key */
|
||||||
|
// make_pair( GLFW_KEY_UNKNOWN , KeyboardEvent::KeyCode::KEY_NONE ),
|
||||||
|
|
||||||
|
/* Printable keys */
|
||||||
|
/*
|
||||||
|
{ GLFW_KEY_SPACE , KeyboardEvent::KeyCode::KEY_SPACE },
|
||||||
|
{ GLFW_KEY_APOSTROPHE , KeyboardEvent::KeyCode::KEY_APOSTROPHE },
|
||||||
|
{ GLFW_KEY_COMMA , KeyboardEvent::KeyCode::KEY_COMMA },
|
||||||
|
{ GLFW_KEY_MINUS , KeyboardEvent::KeyCode::KEY_MINUS },
|
||||||
|
{ GLFW_KEY_PERIOD , KeyboardEvent::KeyCode::KEY_PERIOD },
|
||||||
|
{ GLFW_KEY_SLASH , KeyboardEvent::KeyCode::KEY_SLASH },
|
||||||
|
{ GLFW_KEY_0 , KeyboardEvent::KeyCode::KEY_0 },
|
||||||
|
{ GLFW_KEY_1 , KeyboardEvent::KeyCode::KEY_1 },
|
||||||
|
{ GLFW_KEY_2 , KeyboardEvent::KeyCode::KEY_2 },
|
||||||
|
{ GLFW_KEY_3 , KeyboardEvent::KeyCode::KEY_3 },
|
||||||
|
{ GLFW_KEY_4 , KeyboardEvent::KeyCode::KEY_4 },
|
||||||
|
{ GLFW_KEY_5 , KeyboardEvent::KeyCode::KEY_5 },
|
||||||
|
{ GLFW_KEY_6 , KeyboardEvent::KeyCode::KEY_6 },
|
||||||
|
{ GLFW_KEY_7 , KeyboardEvent::KeyCode::KEY_7 },
|
||||||
|
{ GLFW_KEY_8 , KeyboardEvent::KeyCode::KEY_8 },
|
||||||
|
{ GLFW_KEY_9 , KeyboardEvent::KeyCode::KEY_9 },
|
||||||
|
{ GLFW_KEY_SEMICOLON , KeyboardEvent::KeyCode::KEY_SEMICOLON },
|
||||||
|
{ GLFW_KEY_EQUAL , KeyboardEvent::KeyCode::KEY_EQUAL },
|
||||||
|
{ GLFW_KEY_A , KeyboardEvent::KeyCode::KEY_A },
|
||||||
|
{ GLFW_KEY_B , KeyboardEvent::KeyCode::KEY_B },
|
||||||
|
{ GLFW_KEY_C , KeyboardEvent::KeyCode::KEY_C },
|
||||||
|
{ GLFW_KEY_D , KeyboardEvent::KeyCode::KEY_D },
|
||||||
|
{ GLFW_KEY_E , KeyboardEvent::KeyCode::KEY_E },
|
||||||
|
{ GLFW_KEY_F , KeyboardEvent::KeyCode::KEY_F },
|
||||||
|
{ GLFW_KEY_G , KeyboardEvent::KeyCode::KEY_G },
|
||||||
|
{ GLFW_KEY_H , KeyboardEvent::KeyCode::KEY_H },
|
||||||
|
{ GLFW_KEY_I , KeyboardEvent::KeyCode::KEY_I },
|
||||||
|
{ GLFW_KEY_J , KeyboardEvent::KeyCode::KEY_J },
|
||||||
|
{ GLFW_KEY_K , KeyboardEvent::KeyCode::KEY_K },
|
||||||
|
{ GLFW_KEY_L , KeyboardEvent::KeyCode::KEY_L },
|
||||||
|
{ GLFW_KEY_M , KeyboardEvent::KeyCode::KEY_M },
|
||||||
|
{ GLFW_KEY_N , KeyboardEvent::KeyCode::KEY_N },
|
||||||
|
{ GLFW_KEY_O , KeyboardEvent::KeyCode::KEY_O },
|
||||||
|
{ GLFW_KEY_P , KeyboardEvent::KeyCode::KEY_P },
|
||||||
|
{ GLFW_KEY_Q , KeyboardEvent::KeyCode::KEY_Q },
|
||||||
|
{ GLFW_KEY_R , KeyboardEvent::KeyCode::KEY_R },
|
||||||
|
{ GLFW_KEY_S , KeyboardEvent::KeyCode::KEY_S },
|
||||||
|
{ GLFW_KEY_T , KeyboardEvent::KeyCode::KEY_T },
|
||||||
|
{ GLFW_KEY_U , KeyboardEvent::KeyCode::KEY_U },
|
||||||
|
{ GLFW_KEY_V , KeyboardEvent::KeyCode::KEY_V },
|
||||||
|
{ GLFW_KEY_W , KeyboardEvent::KeyCode::KEY_W },
|
||||||
|
{ GLFW_KEY_X , KeyboardEvent::KeyCode::KEY_X },
|
||||||
|
{ GLFW_KEY_Y , KeyboardEvent::KeyCode::KEY_Y },
|
||||||
|
{ GLFW_KEY_Z , KeyboardEvent::KeyCode::KEY_Z },
|
||||||
|
{ GLFW_KEY_LEFT_BRACKET , KeyboardEvent::KeyCode::KEY_LEFT_BRACKET },
|
||||||
|
{ GLFW_KEY_BACKSLASH , KeyboardEvent::KeyCode::KEY_BACK_SLASH },
|
||||||
|
{ GLFW_KEY_RIGHT_BRACKET , KeyboardEvent::KeyCode::KEY_RIGHT_BRACKET },
|
||||||
|
{ GLFW_KEY_GRAVE_ACCENT , KeyboardEvent::KeyCode::KEY_GRAVE },
|
||||||
|
{ GLFW_KEY_WORLD_1 , KeyboardEvent::KeyCode::KEY_GRAVE },
|
||||||
|
{ GLFW_KEY_WORLD_2 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
|
||||||
|
/* Function keys *//*
|
||||||
|
{ GLFW_KEY_ESCAPE , KeyboardEvent::KeyCode::KEY_ESCAPE },
|
||||||
|
{ GLFW_KEY_ENTER , KeyboardEvent::KeyCode::KEY_KP_ENTER },
|
||||||
|
{ GLFW_KEY_TAB , KeyboardEvent::KeyCode::KEY_TAB },
|
||||||
|
{ GLFW_KEY_BACKSPACE , KeyboardEvent::KeyCode::KEY_BACKSPACE },
|
||||||
|
{ GLFW_KEY_INSERT , KeyboardEvent::KeyCode::KEY_INSERT },
|
||||||
|
{ GLFW_KEY_DELETE , KeyboardEvent::KeyCode::KEY_DELETE },
|
||||||
|
{ GLFW_KEY_RIGHT , KeyboardEvent::KeyCode::KEY_RIGHT_ARROW },
|
||||||
|
{ GLFW_KEY_LEFT , KeyboardEvent::KeyCode::KEY_LEFT_ARROW },
|
||||||
|
{ GLFW_KEY_DOWN , KeyboardEvent::KeyCode::KEY_DOWN_ARROW },
|
||||||
|
{ GLFW_KEY_UP , KeyboardEvent::KeyCode::KEY_UP_ARROW },
|
||||||
|
{ GLFW_KEY_PAGE_UP , KeyboardEvent::KeyCode::KEY_KP_PG_UP },
|
||||||
|
{ GLFW_KEY_PAGE_DOWN , KeyboardEvent::KeyCode::KEY_KP_PG_DOWN },
|
||||||
|
{ GLFW_KEY_HOME , KeyboardEvent::KeyCode::KEY_KP_HOME },
|
||||||
|
{ GLFW_KEY_END , KeyboardEvent::KeyCode::KEY_END },
|
||||||
|
{ GLFW_KEY_CAPS_LOCK , KeyboardEvent::KeyCode::KEY_CAPS_LOCK },
|
||||||
|
{ GLFW_KEY_SCROLL_LOCK , KeyboardEvent::KeyCode::KEY_SCROLL_LOCK },
|
||||||
|
{ GLFW_KEY_NUM_LOCK , KeyboardEvent::KeyCode::KEY_NUM_LOCK },
|
||||||
|
{ GLFW_KEY_PRINT_SCREEN , KeyboardEvent::KeyCode::KEY_PRINT },
|
||||||
|
{ GLFW_KEY_PAUSE , KeyboardEvent::KeyCode::KEY_PAUSE },
|
||||||
|
{ GLFW_KEY_F1 , KeyboardEvent::KeyCode::KEY_F1 },
|
||||||
|
{ GLFW_KEY_F2 , KeyboardEvent::KeyCode::KEY_F2 },
|
||||||
|
{ GLFW_KEY_F3 , KeyboardEvent::KeyCode::KEY_F3 },
|
||||||
|
{ GLFW_KEY_F4 , KeyboardEvent::KeyCode::KEY_F4 },
|
||||||
|
{ GLFW_KEY_F5 , KeyboardEvent::KeyCode::KEY_F5 },
|
||||||
|
{ GLFW_KEY_F6 , KeyboardEvent::KeyCode::KEY_F6 },
|
||||||
|
{ GLFW_KEY_F7 , KeyboardEvent::KeyCode::KEY_F7 },
|
||||||
|
{ GLFW_KEY_F8 , KeyboardEvent::KeyCode::KEY_F8 },
|
||||||
|
{ GLFW_KEY_F9 , KeyboardEvent::KeyCode::KEY_F9 },
|
||||||
|
{ GLFW_KEY_F10 , KeyboardEvent::KeyCode::KEY_F10 },
|
||||||
|
{ GLFW_KEY_F11 , KeyboardEvent::KeyCode::KEY_F11 },
|
||||||
|
{ GLFW_KEY_F12 , KeyboardEvent::KeyCode::KEY_F12 },
|
||||||
|
{ GLFW_KEY_F13 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F14 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F15 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F16 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F17 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F18 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F19 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F20 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F21 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F22 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F23 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F24 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_F25 , KeyboardEvent::KeyCode::KEY_NONE },
|
||||||
|
{ GLFW_KEY_KP_0 , KeyboardEvent::KeyCode::KEY_0 },
|
||||||
|
{ GLFW_KEY_KP_1 , KeyboardEvent::KeyCode::KEY_1 },
|
||||||
|
{ GLFW_KEY_KP_2 , KeyboardEvent::KeyCode::KEY_2 },
|
||||||
|
{ GLFW_KEY_KP_3 , KeyboardEvent::KeyCode::KEY_3 },
|
||||||
|
{ GLFW_KEY_KP_4 , KeyboardEvent::KeyCode::KEY_4 },
|
||||||
|
{ GLFW_KEY_KP_5 , KeyboardEvent::KeyCode::KEY_5 },
|
||||||
|
{ GLFW_KEY_KP_6 , KeyboardEvent::KeyCode::KEY_6 },
|
||||||
|
{ GLFW_KEY_KP_7 , KeyboardEvent::KeyCode::KEY_7 },
|
||||||
|
{ GLFW_KEY_KP_8 , KeyboardEvent::KeyCode::KEY_8 },
|
||||||
|
{ GLFW_KEY_KP_9 , KeyboardEvent::KeyCode::KEY_9 },
|
||||||
|
{ GLFW_KEY_KP_DECIMAL , KeyboardEvent::KeyCode::KEY_PERIOD },
|
||||||
|
{ GLFW_KEY_KP_DIVIDE , KeyboardEvent::KeyCode::KEY_KP_DIVIDE },
|
||||||
|
{ GLFW_KEY_KP_MULTIPLY , KeyboardEvent::KeyCode::KEY_KP_MULTIPLY },
|
||||||
|
{ GLFW_KEY_KP_SUBTRACT , KeyboardEvent::KeyCode::KEY_KP_MINUS },
|
||||||
|
{ GLFW_KEY_KP_ADD , KeyboardEvent::KeyCode::KEY_KP_PLUS },
|
||||||
|
{ GLFW_KEY_KP_ENTER , KeyboardEvent::KeyCode::KEY_KP_ENTER },
|
||||||
|
{ GLFW_KEY_KP_EQUAL , KeyboardEvent::KeyCode::KEY_EQUAL },
|
||||||
|
{ GLFW_KEY_LEFT_SHIFT , KeyboardEvent::KeyCode::KEY_SHIFT },
|
||||||
|
{ GLFW_KEY_LEFT_CONTROL , KeyboardEvent::KeyCode::KEY_CTRL },
|
||||||
|
{ GLFW_KEY_LEFT_ALT , KeyboardEvent::KeyCode::KEY_ALT },
|
||||||
|
{ GLFW_KEY_LEFT_SUPER , KeyboardEvent::KeyCode::KEY_HYPER },
|
||||||
|
{ GLFW_KEY_RIGHT_SHIFT , KeyboardEvent::KeyCode::KEY_SHIFT },
|
||||||
|
{ GLFW_KEY_RIGHT_CONTROL , KeyboardEvent::KeyCode::KEY_CTRL },
|
||||||
|
{ GLFW_KEY_RIGHT_ALT , KeyboardEvent::KeyCode::KEY_ALT },
|
||||||
|
{ GLFW_KEY_RIGHT_SUPER , KeyboardEvent::KeyCode::KEY_HYPER },
|
||||||
|
{ GLFW_KEY_MENU , KeyboardEvent::KeyCode::KEY_MENU },
|
||||||
|
{ GLFW_KEY_LAST , KeyboardEvent::KeyCode::KEY_NONE }*/
|
||||||
|
//};
|
||||||
|
|
||||||
#if(_MSC_VER >= 1600) // Visual Studio 2010 or higher version.
|
#if(_MSC_VER >= 1600) // Visual Studio 2010 or higher version.
|
||||||
// Windows Touch define
|
// Windows Touch define
|
||||||
#define MOUSEEVENTF_FROMTOUCH 0xFF515700
|
#define MOUSEEVENTF_FROMTOUCH 0xFF515700
|
||||||
|
@ -142,6 +271,7 @@ public:
|
||||||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||||
|
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool EGLViewEventHandler::s_captured = false;
|
bool EGLViewEventHandler::s_captured = false;
|
||||||
|
@ -155,6 +285,8 @@ void EGLViewEventHandler::OnGLFWError(int errorID, const char* errorDesc)
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
|
void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
|
||||||
{
|
{
|
||||||
|
static int countxxx = 0;
|
||||||
|
CCLOG("OnGLFWMouseCallBack = %d", ++countxxx);
|
||||||
EGLView* eglView = EGLView::getInstance();
|
EGLView* eglView = EGLView::getInstance();
|
||||||
if(nullptr == eglView) return;
|
if(nullptr == eglView) return;
|
||||||
if(GLFW_MOUSE_BUTTON_LEFT == button)
|
if(GLFW_MOUSE_BUTTON_LEFT == button)
|
||||||
|
@ -182,13 +314,15 @@ void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, in
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
||||||
{
|
{
|
||||||
|
static int countxxx = 0;
|
||||||
|
CCLOG("OnGLFWMouseMoveCallBack = %d, %lf, %lf", ++countxxx, x, y);
|
||||||
s_mouseX = (float)x;
|
s_mouseX = (float)x;
|
||||||
s_mouseY = (float)y;
|
s_mouseY = (float)y;
|
||||||
EGLView* eglView = EGLView::getInstance();
|
EGLView* eglView = EGLView::getInstance();
|
||||||
if(nullptr == eglView) return;
|
if(nullptr == eglView) return;
|
||||||
|
|
||||||
s_mouseX *= eglView->getFrameZoomFactor();
|
s_mouseX /= eglView->getFrameZoomFactor();
|
||||||
s_mouseY *= eglView->getFrameZoomFactor();
|
s_mouseY /= eglView->getFrameZoomFactor();
|
||||||
|
|
||||||
if(s_captured)
|
if(s_captured)
|
||||||
{
|
{
|
||||||
|
@ -202,14 +336,10 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
if(GLFW_PRESS == action)
|
KeyboardEvent event;
|
||||||
{
|
event._keyCode = g_keyCodeMap[key];
|
||||||
Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(key, true);
|
event._isPressed = (GLFW_PRESS == action);
|
||||||
}
|
EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||||
else if(GLFW_RELEASE == action)
|
|
||||||
{
|
|
||||||
Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(key,false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||||
|
@ -217,6 +347,14 @@ void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int ch
|
||||||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||||
|
{
|
||||||
|
if(Director::getInstance())
|
||||||
|
{
|
||||||
|
Director::getInstance()->setViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//end EGLViewEventHandler
|
//end EGLViewEventHandler
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -245,16 +383,19 @@ EGLView::~EGLView()
|
||||||
s_pEglView = nullptr;
|
s_pEglView = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EGLView::init(const char* viewName, float width, float height)
|
bool EGLView::init(const char* viewName, float width, float height, float frameZoomFactor)
|
||||||
{
|
{
|
||||||
if(nullptr != _mainWindow) return true;
|
if(nullptr != _mainWindow) return true;
|
||||||
|
|
||||||
setViewName(viewName);
|
setViewName(viewName);
|
||||||
setFrameSize(width, height);
|
setFrameSize(width, height);
|
||||||
|
setFrameZoomFactor(frameZoomFactor);
|
||||||
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||||
_mainWindow = glfwCreateWindow(_screenSize.width, _screenSize.height, _viewName, nullptr, nullptr);
|
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
|
||||||
glfwMakeContextCurrent(_mainWindow);
|
glfwMakeContextCurrent(_mainWindow);
|
||||||
|
|
||||||
|
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||||
|
@ -370,18 +511,22 @@ void EGLView::setFrameSize(float width, float height)
|
||||||
|
|
||||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||||
|
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||||
|
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||||
|
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||||
|
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLView* EGLView::getInstance()
|
EGLView* EGLView::getInstance()
|
||||||
|
|
|
@ -55,15 +55,13 @@ public:
|
||||||
virtual void swapBuffers();
|
virtual void swapBuffers();
|
||||||
virtual void setFrameSize(float width, float height);
|
virtual void setFrameSize(float width, float height);
|
||||||
virtual void setIMEKeyboardState(bool bOpen);
|
virtual void setIMEKeyboardState(bool bOpen);
|
||||||
|
/*
|
||||||
bool init(const char* viewName, float width, float height);
|
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//void resize(int width, int height);
|
//void resize(int width, int height);
|
||||||
/*
|
|
||||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
|
||||||
*/
|
|
||||||
void setFrameZoomFactor(float fZoomFactor);
|
|
||||||
float getFrameZoomFactor();
|
float getFrameZoomFactor();
|
||||||
//void centerWindow();
|
//void centerWindow();
|
||||||
|
|
||||||
|
@ -82,12 +80,16 @@ public:
|
||||||
/** @deprecated Use getInstance() instead */
|
/** @deprecated Use getInstance() instead */
|
||||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||||
protected:
|
protected:
|
||||||
|
/*
|
||||||
|
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
void setFrameZoomFactor(float fZoomFactor);
|
||||||
private:
|
private:
|
||||||
bool _captured;
|
bool _captured;
|
||||||
LPFN_ACCELEROMETER_KEYHOOK _lpfnAccelerometerKeyHook;
|
LPFN_ACCELEROMETER_KEYHOOK _lpfnAccelerometerKeyHook;
|
||||||
bool _supportTouch;
|
bool _supportTouch;
|
||||||
|
|
||||||
|
int _frameBufferSize[2];
|
||||||
float _frameZoomFactor;
|
float _frameZoomFactor;
|
||||||
static EGLView* s_pEglView;
|
static EGLView* s_pEglView;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -45,9 +45,16 @@ SOURCES = ../actions/CCAction.cpp \
|
||||||
../draw_nodes/CCDrawNode.cpp \
|
../draw_nodes/CCDrawNode.cpp \
|
||||||
../effects/CCGrabber.cpp \
|
../effects/CCGrabber.cpp \
|
||||||
../effects/CCGrid.cpp \
|
../effects/CCGrid.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDelegate.cpp \
|
../event_dispatcher/CCAccelerationEvent.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDispatcher.cpp \
|
../event_dispatcher/CCAccelerationEventListener.cpp \
|
||||||
../keyboard_dispatcher/CCKeyboardDispatcher.cpp \
|
../event_dispatcher/CCEvent.cpp \
|
||||||
|
../event_dispatcher/CCEventDispatcher.cpp \
|
||||||
|
../event_dispatcher/CCEventListener.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEvent.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEventListener.cpp \
|
||||||
|
../event_dispatcher/CCTouch.cpp \
|
||||||
|
../event_dispatcher/CCTouchEvent.cpp \
|
||||||
|
../event_dispatcher/CCTouchEventListener.cpp \
|
||||||
../label_nodes/CCFont.cpp \
|
../label_nodes/CCFont.cpp \
|
||||||
../label_nodes/CCFontAtlas.cpp \
|
../label_nodes/CCFontAtlas.cpp \
|
||||||
../label_nodes/CCFontAtlasCache.cpp \
|
../label_nodes/CCFontAtlasCache.cpp \
|
||||||
|
@ -122,9 +129,6 @@ SOURCES = ../actions/CCAction.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
||||||
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
||||||
../touch_dispatcher/CCTouchDispatcher.cpp \
|
|
||||||
../touch_dispatcher/CCTouchHandler.cpp \
|
|
||||||
../touch_dispatcher/CCTouch.cpp \
|
|
||||||
../shaders/CCGLProgram.cpp \
|
../shaders/CCGLProgram.cpp \
|
||||||
../shaders/ccGLStateCache.cpp \
|
../shaders/ccGLStateCache.cpp \
|
||||||
../shaders/CCShaderCache.cpp \
|
../shaders/CCShaderCache.cpp \
|
||||||
|
|
|
@ -39,13 +39,20 @@ SOURCES = ../actions/CCAction.cpp \
|
||||||
../cocoa/CCString.cpp \
|
../cocoa/CCString.cpp \
|
||||||
../cocoa/CCDataVisitor.cpp \
|
../cocoa/CCDataVisitor.cpp \
|
||||||
../cocoa/CCData.cpp \
|
../cocoa/CCData.cpp \
|
||||||
|
../event_dispatcher/CCAccelerationEvent.cpp \
|
||||||
|
../event_dispatcher/CCAccelerationEventListener.cpp \
|
||||||
|
../event_dispatcher/CCEvent.cpp \
|
||||||
|
../event_dispatcher/CCEventDispatcher.cpp \
|
||||||
|
../event_dispatcher/CCEventListener.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEvent.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEventListener.cpp \
|
||||||
|
../event_dispatcher/CCTouch.cpp \
|
||||||
|
../event_dispatcher/CCTouchEvent.cpp \
|
||||||
|
../event_dispatcher/CCTouchEventListener.cpp \
|
||||||
../draw_nodes/CCDrawingPrimitives.cpp \
|
../draw_nodes/CCDrawingPrimitives.cpp \
|
||||||
../draw_nodes/CCDrawNode.cpp \
|
../draw_nodes/CCDrawNode.cpp \
|
||||||
../effects/CCGrabber.cpp \
|
../effects/CCGrabber.cpp \
|
||||||
../effects/CCGrid.cpp \
|
../effects/CCGrid.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDelegate.cpp \
|
|
||||||
../keypad_dispatcher/CCKeypadDispatcher.cpp \
|
|
||||||
../keyboard_dispatcher/CCKeyboardDispatcher.cpp \
|
|
||||||
../label_nodes/CCFont.cpp \
|
../label_nodes/CCFont.cpp \
|
||||||
../label_nodes/CCFontAtlas.cpp \
|
../label_nodes/CCFontAtlas.cpp \
|
||||||
../label_nodes/CCFontAtlasCache.cpp \
|
../label_nodes/CCFontAtlasCache.cpp \
|
||||||
|
@ -122,9 +129,6 @@ SOURCES = ../actions/CCAction.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
||||||
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
||||||
../touch_dispatcher/CCTouchDispatcher.cpp \
|
|
||||||
../touch_dispatcher/CCTouchHandler.cpp \
|
|
||||||
../touch_dispatcher/CCTouch.cpp \
|
|
||||||
../shaders/CCGLProgram.cpp \
|
../shaders/CCGLProgram.cpp \
|
||||||
../shaders/ccGLStateCache.cpp \
|
../shaders/ccGLStateCache.cpp \
|
||||||
../shaders/CCShaderCache.cpp \
|
../shaders/CCShaderCache.cpp \
|
||||||
|
|
|
@ -34,9 +34,16 @@ SOURCES = ../actions/CCAction.cpp \
|
||||||
../draw_nodes/CCDrawNode.cpp \
|
../draw_nodes/CCDrawNode.cpp \
|
||||||
../effects/CCGrabber.cpp \
|
../effects/CCGrabber.cpp \
|
||||||
../effects/CCGrid.cpp \
|
../effects/CCGrid.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDelegate.cpp \
|
../event_dispatcher/CCAccelerationEvent.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDispatcher.cpp \
|
../event_dispatcher/CCAccelerationEventListener.cpp \
|
||||||
../keyboard_dispatcher/CCKeyboardDispatcher.cpp \
|
../event_dispatcher/CCEvent.cpp \
|
||||||
|
../event_dispatcher/CCEventDispatcher.cpp \
|
||||||
|
../event_dispatcher/CCEventListener.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEvent.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEventListener.cpp \
|
||||||
|
../event_dispatcher/CCTouch.cpp \
|
||||||
|
../event_dispatcher/CCTouchEvent.cpp \
|
||||||
|
../event_dispatcher/CCTouchEventListener.cpp \
|
||||||
../label_nodes/CCLabelAtlas.cpp \
|
../label_nodes/CCLabelAtlas.cpp \
|
||||||
../label_nodes/CCLabelBMFont.cpp \
|
../label_nodes/CCLabelBMFont.cpp \
|
||||||
../label_nodes/CCLabelTTF.cpp \
|
../label_nodes/CCLabelTTF.cpp \
|
||||||
|
@ -104,9 +111,6 @@ SOURCES = ../actions/CCAction.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
||||||
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
||||||
../touch_dispatcher/CCTouchDispatcher.cpp \
|
|
||||||
../touch_dispatcher/CCTouchHandler.cpp \
|
|
||||||
../touch_dispatcher/CCTouch.cpp \
|
|
||||||
../shaders/CCGLProgram.cpp \
|
../shaders/CCGLProgram.cpp \
|
||||||
../shaders/ccGLStateCache.cpp \
|
../shaders/ccGLStateCache.cpp \
|
||||||
../shaders/CCShaderCache.cpp \
|
../shaders/CCShaderCache.cpp \
|
||||||
|
|
|
@ -40,9 +40,16 @@ SOURCES += ../actions/CCAction.cpp \
|
||||||
../draw_nodes/CCDrawNode.cpp \
|
../draw_nodes/CCDrawNode.cpp \
|
||||||
../effects/CCGrabber.cpp \
|
../effects/CCGrabber.cpp \
|
||||||
../effects/CCGrid.cpp \
|
../effects/CCGrid.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDelegate.cpp \
|
../event_dispatcher/CCAccelerationEvent.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDispatcher.cpp \
|
../event_dispatcher/CCAccelerationEventListener.cpp \
|
||||||
../keyboard_dispatcher/CCKeyboardDispatcher.cpp \
|
../event_dispatcher/CCEvent.cpp \
|
||||||
|
../event_dispatcher/CCEventDispatcher.cpp \
|
||||||
|
../event_dispatcher/CCEventListener.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEvent.cpp \
|
||||||
|
../event_dispatcher/CCKeyboardEventListener.cpp \
|
||||||
|
../event_dispatcher/CCTouch.cpp \
|
||||||
|
../event_dispatcher/CCTouchEvent.cpp \
|
||||||
|
../event_dispatcher/CCTouchEventListener.cpp \
|
||||||
../label_nodes/CCLabelAtlas.cpp \
|
../label_nodes/CCLabelAtlas.cpp \
|
||||||
../label_nodes/CCLabelBMFont.cpp \
|
../label_nodes/CCLabelBMFont.cpp \
|
||||||
../label_nodes/CCLabelTTF.cpp \
|
../label_nodes/CCLabelTTF.cpp \
|
||||||
|
@ -108,9 +115,6 @@ SOURCES += ../actions/CCAction.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
../tilemap_parallax_nodes/CCTMXTiledMap.cpp \
|
||||||
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
../tilemap_parallax_nodes/CCTMXXMLParser.cpp \
|
||||||
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
../tilemap_parallax_nodes/CCTileMapAtlas.cpp \
|
||||||
../touch_dispatcher/CCTouchDispatcher.cpp \
|
|
||||||
../touch_dispatcher/CCTouchHandler.cpp \
|
|
||||||
../touch_dispatcher/CCTouch.cpp \
|
|
||||||
../shaders/CCGLProgram.cpp \
|
../shaders/CCGLProgram.cpp \
|
||||||
../shaders/ccGLStateCache.cpp \
|
../shaders/ccGLStateCache.cpp \
|
||||||
../shaders/CCShaderCache.cpp \
|
../shaders/CCShaderCache.cpp \
|
||||||
|
|
|
@ -173,7 +173,16 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClCompile Include="..\actions\CCActionProgressTimer.cpp" />
|
<ClCompile Include="..\actions\CCActionProgressTimer.cpp" />
|
||||||
<ClCompile Include="..\actions\CCActionTiledGrid.cpp" />
|
<ClCompile Include="..\actions\CCActionTiledGrid.cpp" />
|
||||||
<ClCompile Include="..\actions\CCActionTween.cpp" />
|
<ClCompile Include="..\actions\CCActionTween.cpp" />
|
||||||
<ClCompile Include="..\keyboard_dispatcher\CCKeyboardDispatcher.cpp" />
|
<ClCompile Include="..\event_dispatcher\CCAccelerationEvent.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCAccelerationEventListener.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCEvent.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCEventDispatcher.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCEventListener.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCKeyboardEvent.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCKeyboardEventListener.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCTouch.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCTouchEvent.cpp" />
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCTouchEventListener.cpp" />
|
||||||
<ClCompile Include="..\label_nodes\CCFont.cpp" />
|
<ClCompile Include="..\label_nodes\CCFont.cpp" />
|
||||||
<ClCompile Include="..\label_nodes\CCFontAtlas.cpp" />
|
<ClCompile Include="..\label_nodes\CCFontAtlas.cpp" />
|
||||||
<ClCompile Include="..\label_nodes\CCFontAtlasCache.cpp" />
|
<ClCompile Include="..\label_nodes\CCFontAtlasCache.cpp" />
|
||||||
|
@ -209,7 +218,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClCompile Include="..\platform\third_party\common\atitc\atitc.cpp" />
|
<ClCompile Include="..\platform\third_party\common\atitc\atitc.cpp" />
|
||||||
<ClCompile Include="..\platform\third_party\common\etc\etc1.cpp" />
|
<ClCompile Include="..\platform\third_party\common\etc\etc1.cpp" />
|
||||||
<ClCompile Include="..\platform\third_party\common\s3tc\s3tc.cpp" />
|
<ClCompile Include="..\platform\third_party\common\s3tc\s3tc.cpp" />
|
||||||
<ClCompile Include="..\platform\win32\CCAccelerometer.cpp" />
|
|
||||||
<ClCompile Include="..\platform\win32\CCApplication.cpp" />
|
<ClCompile Include="..\platform\win32\CCApplication.cpp" />
|
||||||
<ClCompile Include="..\platform\win32\CCCommon.cpp" />
|
<ClCompile Include="..\platform\win32\CCCommon.cpp" />
|
||||||
<ClCompile Include="..\platform\win32\CCDevice.cpp" />
|
<ClCompile Include="..\platform\win32\CCDevice.cpp" />
|
||||||
|
@ -252,11 +260,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXObjectGroup.cpp" />
|
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXObjectGroup.cpp" />
|
||||||
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXTiledMap.cpp" />
|
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXTiledMap.cpp" />
|
||||||
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXXMLParser.cpp" />
|
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXXMLParser.cpp" />
|
||||||
<ClCompile Include="..\touch_dispatcher\CCTouch.cpp" />
|
|
||||||
<ClCompile Include="..\touch_dispatcher\CCTouchDispatcher.cpp" />
|
|
||||||
<ClCompile Include="..\touch_dispatcher\CCTouchHandler.cpp" />
|
|
||||||
<ClCompile Include="..\keypad_dispatcher\CCKeypadDelegate.cpp" />
|
|
||||||
<ClCompile Include="..\keypad_dispatcher\CCKeypadDispatcher.cpp" />
|
|
||||||
<ClCompile Include="..\text_input_node\CCIMEDispatcher.cpp" />
|
<ClCompile Include="..\text_input_node\CCIMEDispatcher.cpp" />
|
||||||
<ClCompile Include="..\text_input_node\CCTextFieldTTF.cpp" />
|
<ClCompile Include="..\text_input_node\CCTextFieldTTF.cpp" />
|
||||||
<ClCompile Include="..\script_support\CCScriptSupport.cpp" />
|
<ClCompile Include="..\script_support\CCScriptSupport.cpp" />
|
||||||
|
@ -315,6 +318,16 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClInclude Include="..\actions\CCActionProgressTimer.h" />
|
<ClInclude Include="..\actions\CCActionProgressTimer.h" />
|
||||||
<ClInclude Include="..\actions\CCActionTiledGrid.h" />
|
<ClInclude Include="..\actions\CCActionTiledGrid.h" />
|
||||||
<ClInclude Include="..\actions\CCActionTween.h" />
|
<ClInclude Include="..\actions\CCActionTween.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCAccelerationEvent.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCAccelerationEventListener.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCEvent.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCEventDispatcher.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCEventListener.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCKeyboardEvent.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCKeyboardEventListener.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCTouch.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCTouchEvent.h" />
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCTouchEventListener.h" />
|
||||||
<ClInclude Include="..\include\ccConfig.h" />
|
<ClInclude Include="..\include\ccConfig.h" />
|
||||||
<ClInclude Include="..\include\CCDeprecated.h" />
|
<ClInclude Include="..\include\CCDeprecated.h" />
|
||||||
<ClInclude Include="..\include\CCEventType.h" />
|
<ClInclude Include="..\include\CCEventType.h" />
|
||||||
|
@ -322,7 +335,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClInclude Include="..\include\CCProtocols.h" />
|
<ClInclude Include="..\include\CCProtocols.h" />
|
||||||
<ClInclude Include="..\include\ccTypes.h" />
|
<ClInclude Include="..\include\ccTypes.h" />
|
||||||
<ClInclude Include="..\include\cocos2d.h" />
|
<ClInclude Include="..\include\cocos2d.h" />
|
||||||
<ClInclude Include="..\keyboard_dispatcher\CCKeyboardDispatcher.h" />
|
|
||||||
<ClInclude Include="..\label_nodes\CCFont.h" />
|
<ClInclude Include="..\label_nodes\CCFont.h" />
|
||||||
<ClInclude Include="..\label_nodes\CCFontAtlas.h" />
|
<ClInclude Include="..\label_nodes\CCFontAtlas.h" />
|
||||||
<ClInclude Include="..\label_nodes\CCFontAtlasCache.h" />
|
<ClInclude Include="..\label_nodes\CCFontAtlasCache.h" />
|
||||||
|
@ -353,9 +365,9 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClInclude Include="..\particle_nodes\CCParticleExamples.h" />
|
<ClInclude Include="..\particle_nodes\CCParticleExamples.h" />
|
||||||
<ClInclude Include="..\particle_nodes\CCParticleSystem.h" />
|
<ClInclude Include="..\particle_nodes\CCParticleSystem.h" />
|
||||||
<ClInclude Include="..\particle_nodes\CCParticleSystemQuad.h" />
|
<ClInclude Include="..\particle_nodes\CCParticleSystemQuad.h" />
|
||||||
<ClInclude Include="..\platform\CCAccelerometerDelegate.h" />
|
|
||||||
<ClInclude Include="..\platform\CCApplicationProtocol.h" />
|
<ClInclude Include="..\platform\CCApplicationProtocol.h" />
|
||||||
<ClInclude Include="..\platform\CCCommon.h" />
|
<ClInclude Include="..\platform\CCCommon.h" />
|
||||||
|
<ClInclude Include="..\platform\CCDevice.h" />
|
||||||
<ClInclude Include="..\platform\CCEGLViewProtocol.h" />
|
<ClInclude Include="..\platform\CCEGLViewProtocol.h" />
|
||||||
<ClInclude Include="..\platform\CCFileUtils.h" />
|
<ClInclude Include="..\platform\CCFileUtils.h" />
|
||||||
<ClInclude Include="..\platform\CCImage.h" />
|
<ClInclude Include="..\platform\CCImage.h" />
|
||||||
|
@ -364,11 +376,9 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClInclude Include="..\platform\CCPlatformMacros.h" />
|
<ClInclude Include="..\platform\CCPlatformMacros.h" />
|
||||||
<ClInclude Include="..\platform\CCSAXParser.h" />
|
<ClInclude Include="..\platform\CCSAXParser.h" />
|
||||||
<ClInclude Include="..\platform\CCThread.h" />
|
<ClInclude Include="..\platform\CCThread.h" />
|
||||||
<ClInclude Include="..\platform\platform.h" />
|
|
||||||
<ClInclude Include="..\platform\third_party\common\atitc\atitc.h" />
|
<ClInclude Include="..\platform\third_party\common\atitc\atitc.h" />
|
||||||
<ClInclude Include="..\platform\third_party\common\etc\etc1.h" />
|
<ClInclude Include="..\platform\third_party\common\etc\etc1.h" />
|
||||||
<ClInclude Include="..\platform\third_party\common\s3tc\s3tc.h" />
|
<ClInclude Include="..\platform\third_party\common\s3tc\s3tc.h" />
|
||||||
<ClInclude Include="..\platform\win32\CCAccelerometer.h" />
|
|
||||||
<ClInclude Include="..\platform\win32\CCApplication.h" />
|
<ClInclude Include="..\platform\win32\CCApplication.h" />
|
||||||
<ClInclude Include="..\platform\win32\CCEGLView.h" />
|
<ClInclude Include="..\platform\win32\CCEGLView.h" />
|
||||||
<ClInclude Include="..\platform\win32\CCFileUtilsWin32.h" />
|
<ClInclude Include="..\platform\win32\CCFileUtilsWin32.h" />
|
||||||
|
@ -428,12 +438,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
||||||
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXObjectGroup.h" />
|
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXObjectGroup.h" />
|
||||||
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXTiledMap.h" />
|
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXTiledMap.h" />
|
||||||
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXXMLParser.h" />
|
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXXMLParser.h" />
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouch.h" />
|
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouchDelegateProtocol.h" />
|
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouchDispatcher.h" />
|
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouchHandler.h" />
|
|
||||||
<ClInclude Include="..\keypad_dispatcher\CCKeypadDelegate.h" />
|
|
||||||
<ClInclude Include="..\keypad_dispatcher\CCKeypadDispatcher.h" />
|
|
||||||
<ClInclude Include="..\text_input_node\CCIMEDelegate.h" />
|
<ClInclude Include="..\text_input_node\CCIMEDelegate.h" />
|
||||||
<ClInclude Include="..\text_input_node\CCIMEDispatcher.h" />
|
<ClInclude Include="..\text_input_node\CCIMEDispatcher.h" />
|
||||||
<ClInclude Include="..\text_input_node\CCTextFieldTTF.h" />
|
<ClInclude Include="..\text_input_node\CCTextFieldTTF.h" />
|
||||||
|
|
|
@ -58,12 +58,6 @@
|
||||||
<Filter Include="tilemap_parallax_nodes">
|
<Filter Include="tilemap_parallax_nodes">
|
||||||
<UniqueIdentifier>{f2671200-b2d8-4d2e-9728-06719cf6f835}</UniqueIdentifier>
|
<UniqueIdentifier>{f2671200-b2d8-4d2e-9728-06719cf6f835}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="touch_dispatcher">
|
|
||||||
<UniqueIdentifier>{eaa16c9b-dfbc-4a37-8e3e-e961d9ca1d1a}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="keypad_dispatcher">
|
|
||||||
<UniqueIdentifier>{3c91932f-7667-4049-b9bd-caac4c8eab15}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="text_input_node">
|
<Filter Include="text_input_node">
|
||||||
<UniqueIdentifier>{535c04b0-fe2b-44c9-9a8c-9029e2b6de5c}</UniqueIdentifier>
|
<UniqueIdentifier>{535c04b0-fe2b-44c9-9a8c-9029e2b6de5c}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
@ -103,12 +97,12 @@
|
||||||
<Filter Include="support\component">
|
<Filter Include="support\component">
|
||||||
<UniqueIdentifier>{caa78ce0-9b58-4314-b117-1acae278691e}</UniqueIdentifier>
|
<UniqueIdentifier>{caa78ce0-9b58-4314-b117-1acae278691e}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="keyboard_dispatcher">
|
|
||||||
<UniqueIdentifier>{e7134ba0-4220-4dd1-b120-3533883394ac}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="platform\etc">
|
<Filter Include="platform\etc">
|
||||||
<UniqueIdentifier>{47fda93e-6eb4-4abc-b5bc-725bf667a395}</UniqueIdentifier>
|
<UniqueIdentifier>{47fda93e-6eb4-4abc-b5bc-725bf667a395}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="event_dispatcher">
|
||||||
|
<UniqueIdentifier>{3ff2746c-a91b-4b86-93b7-43a9ec14825b}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\base_nodes\CCAtlasNode.cpp">
|
<ClCompile Include="..\base_nodes\CCAtlasNode.cpp">
|
||||||
|
@ -252,9 +246,6 @@
|
||||||
<ClCompile Include="..\platform\CCThread.cpp">
|
<ClCompile Include="..\platform\CCThread.cpp">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\platform\win32\CCAccelerometer.cpp">
|
|
||||||
<Filter>platform\win32</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\platform\win32\CCApplication.cpp">
|
<ClCompile Include="..\platform\win32\CCApplication.cpp">
|
||||||
<Filter>platform\win32</Filter>
|
<Filter>platform\win32</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -348,21 +339,6 @@
|
||||||
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXXMLParser.cpp">
|
<ClCompile Include="..\tileMap_parallax_nodes\CCTMXXMLParser.cpp">
|
||||||
<Filter>tilemap_parallax_nodes</Filter>
|
<Filter>tilemap_parallax_nodes</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\touch_dispatcher\CCTouch.cpp">
|
|
||||||
<Filter>touch_dispatcher</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\touch_dispatcher\CCTouchDispatcher.cpp">
|
|
||||||
<Filter>touch_dispatcher</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\touch_dispatcher\CCTouchHandler.cpp">
|
|
||||||
<Filter>touch_dispatcher</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\keypad_dispatcher\CCKeypadDelegate.cpp">
|
|
||||||
<Filter>keypad_dispatcher</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\keypad_dispatcher\CCKeypadDispatcher.cpp">
|
|
||||||
<Filter>keypad_dispatcher</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\text_input_node\CCIMEDispatcher.cpp">
|
<ClCompile Include="..\text_input_node\CCIMEDispatcher.cpp">
|
||||||
<Filter>text_input_node</Filter>
|
<Filter>text_input_node</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -465,9 +441,6 @@
|
||||||
<ClCompile Include="..\support\component\CCComponentContainer.cpp">
|
<ClCompile Include="..\support\component\CCComponentContainer.cpp">
|
||||||
<Filter>support\component</Filter>
|
<Filter>support\component</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\keyboard_dispatcher\CCKeyboardDispatcher.cpp">
|
|
||||||
<Filter>keyboard_dispatcher</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\ccTypes.cpp" />
|
<ClCompile Include="..\ccTypes.cpp" />
|
||||||
<ClCompile Include="..\platform\third_party\common\etc\etc1.cpp">
|
<ClCompile Include="..\platform\third_party\common\etc\etc1.cpp">
|
||||||
<Filter>platform\etc</Filter>
|
<Filter>platform\etc</Filter>
|
||||||
|
@ -509,6 +482,36 @@
|
||||||
<ClCompile Include="..\platform\third_party\common\atitc\atitc.cpp">
|
<ClCompile Include="..\platform\third_party\common\atitc\atitc.cpp">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCAccelerationEvent.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCAccelerationEventListener.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCEvent.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCEventDispatcher.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCEventListener.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCKeyboardEvent.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCKeyboardEventListener.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCTouch.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCTouchEvent.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\event_dispatcher\CCTouchEventListener.cpp">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\base_nodes\CCAtlasNode.h">
|
<ClInclude Include="..\base_nodes\CCAtlasNode.h">
|
||||||
|
@ -664,9 +667,6 @@
|
||||||
<ClInclude Include="..\particle_nodes\CCParticleSystemQuad.h">
|
<ClInclude Include="..\particle_nodes\CCParticleSystemQuad.h">
|
||||||
<Filter>particle_nodes</Filter>
|
<Filter>particle_nodes</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\platform\CCAccelerometerDelegate.h">
|
|
||||||
<Filter>platform</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\platform\CCApplicationProtocol.h">
|
<ClInclude Include="..\platform\CCApplicationProtocol.h">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -697,9 +697,6 @@
|
||||||
<ClInclude Include="..\platform\CCThread.h">
|
<ClInclude Include="..\platform\CCThread.h">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\platform\win32\CCAccelerometer.h">
|
|
||||||
<Filter>platform\win32</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\platform\win32\CCApplication.h">
|
<ClInclude Include="..\platform\win32\CCApplication.h">
|
||||||
<Filter>platform\win32</Filter>
|
<Filter>platform\win32</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -799,24 +796,6 @@
|
||||||
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXXMLParser.h">
|
<ClInclude Include="..\tileMap_parallax_nodes\CCTMXXMLParser.h">
|
||||||
<Filter>tilemap_parallax_nodes</Filter>
|
<Filter>tilemap_parallax_nodes</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouch.h">
|
|
||||||
<Filter>touch_dispatcher</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouchDelegateProtocol.h">
|
|
||||||
<Filter>touch_dispatcher</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouchDispatcher.h">
|
|
||||||
<Filter>touch_dispatcher</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\touch_dispatcher\CCTouchHandler.h">
|
|
||||||
<Filter>touch_dispatcher</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\keypad_dispatcher\CCKeypadDelegate.h">
|
|
||||||
<Filter>keypad_dispatcher</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\keypad_dispatcher\CCKeypadDispatcher.h">
|
|
||||||
<Filter>keypad_dispatcher</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\text_input_node\CCIMEDelegate.h">
|
<ClInclude Include="..\text_input_node\CCIMEDelegate.h">
|
||||||
<Filter>text_input_node</Filter>
|
<Filter>text_input_node</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -975,16 +954,12 @@
|
||||||
<ClInclude Include="..\support\component\CCComponent.h">
|
<ClInclude Include="..\support\component\CCComponent.h">
|
||||||
<Filter>support\component</Filter>
|
<Filter>support\component</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\keyboard_dispatcher\CCKeyboardDispatcher.h">
|
|
||||||
<Filter>keyboard_dispatcher</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\include\CCDeprecated.h">
|
<ClInclude Include="..\include\CCDeprecated.h">
|
||||||
<Filter>include</Filter>
|
<Filter>include</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\platform\third_party\common\etc\etc1.h">
|
<ClInclude Include="..\platform\third_party\common\etc\etc1.h">
|
||||||
<Filter>platform\etc</Filter>
|
<Filter>platform\etc</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\platform\platform.h" />
|
|
||||||
<ClInclude Include="..\label_nodes\CCFont.h">
|
<ClInclude Include="..\label_nodes\CCFont.h">
|
||||||
<Filter>label_nodes</Filter>
|
<Filter>label_nodes</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -1027,5 +1002,38 @@
|
||||||
<ClInclude Include="..\platform\third_party\common\atitc\atitc.h">
|
<ClInclude Include="..\platform\third_party\common\atitc\atitc.h">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\platform\CCDevice.h">
|
||||||
|
<Filter>platform</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCAccelerationEvent.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCAccelerationEventListener.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCEvent.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCEventDispatcher.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCEventListener.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCKeyboardEvent.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCKeyboardEventListener.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCTouch.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCTouchEvent.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\event_dispatcher\CCTouchEventListener.h">
|
||||||
|
<Filter>event_dispatcher</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -26,10 +26,9 @@
|
||||||
#define __SCRIPT_SUPPORT_H__
|
#define __SCRIPT_SUPPORT_H__
|
||||||
|
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
#include "CCAccelerometer.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouchEvent.h"
|
||||||
#include "cocoa/CCSet.h"
|
#include "cocoa/CCSet.h"
|
||||||
#include "CCAccelerometer.h"
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -254,16 +253,16 @@ struct SchedulerScriptData
|
||||||
|
|
||||||
struct TouchesScriptData
|
struct TouchesScriptData
|
||||||
{
|
{
|
||||||
int actionType;
|
TouchEvent::EventCode actionType;
|
||||||
void* nativeObject;
|
void* nativeObject;
|
||||||
Set* touches;
|
const std::vector<Touch*>& touches;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
TouchesScriptData(int inActionType, void* inNativeObject, Set* inTouches)
|
TouchesScriptData(TouchEvent::EventCode inActionType, void* inNativeObject, const std::vector<Touch*>& inTouches)
|
||||||
: actionType(inActionType),
|
: actionType(inActionType),
|
||||||
nativeObject(inNativeObject),
|
nativeObject(inNativeObject),
|
||||||
touches(inTouches)
|
touches(inTouches)
|
||||||
|
@ -273,7 +272,7 @@ struct TouchesScriptData
|
||||||
|
|
||||||
struct TouchScriptData
|
struct TouchScriptData
|
||||||
{
|
{
|
||||||
int actionType;
|
TouchEvent::EventCode actionType;
|
||||||
void* nativeObject;
|
void* nativeObject;
|
||||||
Touch* touch;
|
Touch* touch;
|
||||||
|
|
||||||
|
@ -282,7 +281,7 @@ struct TouchScriptData
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
TouchScriptData(int inActionType, void* inNativeObject, Touch* inTouch)
|
TouchScriptData(TouchEvent::EventCode inActionType, void* inNativeObject, Touch* inTouch)
|
||||||
: actionType(inActionType),
|
: actionType(inActionType),
|
||||||
nativeObject(inNativeObject),
|
nativeObject(inNativeObject),
|
||||||
touch(inTouch)
|
touch(inTouch)
|
||||||
|
|
|
@ -1101,7 +1101,7 @@ void Sprite::setTexture(Texture2D *texture)
|
||||||
if (NULL == texture)
|
if (NULL == texture)
|
||||||
{
|
{
|
||||||
// Gets the texture by key firstly.
|
// Gets the texture by key firstly.
|
||||||
texture = TextureCache::getInstance()->textureForKey(CC_2x2_WHITE_IMAGE_KEY);
|
texture = TextureCache::getInstance()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY);
|
||||||
|
|
||||||
// If texture wasn't in cache, create it from RAW data.
|
// If texture wasn't in cache, create it from RAW data.
|
||||||
if (NULL == texture)
|
if (NULL == texture)
|
||||||
|
|
|
@ -156,6 +156,7 @@ void SpriteBatchNode::visit(void)
|
||||||
transform();
|
transform();
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
|
updateEventPriorityIndex();
|
||||||
|
|
||||||
if (_grid && _grid->isActive())
|
if (_grid && _grid->isActive())
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,6 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "label_nodes/CCLabelTTF.h"
|
#include "label_nodes/CCLabelTTF.h"
|
||||||
#include "text_input_node/CCIMEDelegate.h"
|
#include "text_input_node/CCIMEDelegate.h"
|
||||||
#include "touch_dispatcher/CCTouchDelegateProtocol.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
|
|
@ -669,9 +669,55 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
else if (elementName == "polyline")
|
else if (elementName == "polyline")
|
||||||
{
|
{
|
||||||
// find parent object's dict and add polyline-points to it
|
// find parent object's dict and add polyline-points to it
|
||||||
// TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->lastObject();
|
TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->getLastObject();
|
||||||
// Dictionary* dict = (Dictionary*)objectGroup->getObjects()->lastObject();
|
Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject();
|
||||||
// TODO: dict->setObject:[attributeDict objectForKey:@"points"] forKey:@"polylinePoints"];
|
|
||||||
|
// get points value string
|
||||||
|
const char* value = valueForKey("points", attributeDict);
|
||||||
|
if(value)
|
||||||
|
{
|
||||||
|
Array* pointsArray = Array::createWithCapacity(10);
|
||||||
|
|
||||||
|
// parse points string into a space-separated set of points
|
||||||
|
stringstream pointsStream(value);
|
||||||
|
string pointPair;
|
||||||
|
while(std::getline(pointsStream, pointPair, ' '))
|
||||||
|
{
|
||||||
|
// parse each point combo into a comma-separated x,y point
|
||||||
|
stringstream pointStream(pointPair);
|
||||||
|
string xStr,yStr;
|
||||||
|
char buffer[32] = {0};
|
||||||
|
|
||||||
|
Dictionary* pointDict = new Dictionary;
|
||||||
|
pointDict->init();
|
||||||
|
|
||||||
|
// set x
|
||||||
|
if(std::getline(pointStream, xStr, ','))
|
||||||
|
{
|
||||||
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||||
|
sprintf(buffer, "%d", x);
|
||||||
|
String* pStr = new String(buffer);
|
||||||
|
pStr->autorelease();
|
||||||
|
pointDict->setObject(pStr, "x");
|
||||||
|
}
|
||||||
|
|
||||||
|
// set y
|
||||||
|
if(std::getline(pointStream, yStr, ','))
|
||||||
|
{
|
||||||
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||||
|
sprintf(buffer, "%d", y);
|
||||||
|
String* pStr = new String(buffer);
|
||||||
|
pStr->autorelease();
|
||||||
|
pointDict->setObject(pStr, "y");
|
||||||
|
}
|
||||||
|
|
||||||
|
// add to points array
|
||||||
|
pointsArray->addObject(pointDict);
|
||||||
|
pointDict->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
dict->setObject(pointsArray, "polylinePoints");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributeDict)
|
if (attributeDict)
|
||||||
|
|
|
@ -1,535 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010-2012 cocos2d-x.org
|
|
||||||
Copyright (c) 2009 Valentin Milea
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "CCTouchDispatcher.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include "CCTouchHandler.h"
|
|
||||||
#include "cocoa/CCArray.h"
|
|
||||||
#include "cocoa/CCSet.h"
|
|
||||||
#include "CCTouch.h"
|
|
||||||
#include "textures/CCTexture2D.h"
|
|
||||||
#include "support/data_support/ccCArray.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used for sort
|
|
||||||
*/
|
|
||||||
#if CC_USE_ARRAY_VECTOR
|
|
||||||
static int less(const RCPtr<Object>& p1, const RCPtr<Object>& p2)
|
|
||||||
{
|
|
||||||
Object *o1, *o2;
|
|
||||||
o1 = static_cast<Object*>(p1);
|
|
||||||
o2 = static_cast<Object*>(p2);
|
|
||||||
|
|
||||||
TouchHandler *h1, *h2;
|
|
||||||
h1 = static_cast<TouchHandler*>( o1 );
|
|
||||||
h2 = static_cast<TouchHandler*>( o2 );
|
|
||||||
return ( h1->getPriority() < h2->getPriority() );
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static int less(const Object* p1, const Object* p2)
|
|
||||||
{
|
|
||||||
return ((TouchHandler*)p1)->getPriority() < ((TouchHandler*)p2)->getPriority();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool TouchDispatcher::isDispatchEvents(void)
|
|
||||||
{
|
|
||||||
return _dispatchEvents;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::setDispatchEvents(bool bDispatchEvents)
|
|
||||||
{
|
|
||||||
_dispatchEvents = bDispatchEvents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
+(id) allocWithZone:(Zone *)zone
|
|
||||||
{
|
|
||||||
@synchronized(self) {
|
|
||||||
CCASSERT(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton.");
|
|
||||||
return [super allocWithZone:zone];
|
|
||||||
}
|
|
||||||
return nil; // on subsequent allocation attempts return nil
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool TouchDispatcher::init(void)
|
|
||||||
{
|
|
||||||
_dispatchEvents = true;
|
|
||||||
_targetedHandlers = Array::createWithCapacity(8);
|
|
||||||
_targetedHandlers->retain();
|
|
||||||
_standardHandlers = Array::createWithCapacity(4);
|
|
||||||
_standardHandlers->retain();
|
|
||||||
_handlersToAdd = Array::createWithCapacity(8);
|
|
||||||
_handlersToAdd->retain();
|
|
||||||
_handlersToRemove = ccCArrayNew(8);
|
|
||||||
|
|
||||||
_toRemove = false;
|
|
||||||
_toAdd = false;
|
|
||||||
_toQuit = false;
|
|
||||||
_locked = false;
|
|
||||||
|
|
||||||
_handlerHelperData[CCTOUCHBEGAN]._type = CCTOUCHBEGAN;
|
|
||||||
_handlerHelperData[CCTOUCHMOVED]._type = CCTOUCHMOVED;
|
|
||||||
_handlerHelperData[CCTOUCHENDED]._type = CCTOUCHENDED;
|
|
||||||
_handlerHelperData[CCTOUCHCANCELLED]._type = CCTOUCHCANCELLED;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchDispatcher::~TouchDispatcher(void)
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE(_targetedHandlers);
|
|
||||||
CC_SAFE_RELEASE(_standardHandlers);
|
|
||||||
CC_SAFE_RELEASE(_handlersToAdd);
|
|
||||||
|
|
||||||
ccCArrayFree(_handlersToRemove);
|
|
||||||
_handlersToRemove = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// handlers management
|
|
||||||
//
|
|
||||||
void TouchDispatcher::forceAddHandler(TouchHandler *pHandler, Array *pArray)
|
|
||||||
{
|
|
||||||
unsigned int u = 0;
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(pArray, pObj)
|
|
||||||
{
|
|
||||||
TouchHandler *h = static_cast<TouchHandler *>(pObj);
|
|
||||||
if (h)
|
|
||||||
{
|
|
||||||
if (h->getPriority() < pHandler->getPriority())
|
|
||||||
{
|
|
||||||
++u;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (h->getDelegate() == pHandler->getDelegate())
|
|
||||||
{
|
|
||||||
CCASSERT(0, "");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pArray->insertObject(pHandler, u);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::addStandardDelegate(TouchDelegate *pDelegate, int nPriority)
|
|
||||||
{
|
|
||||||
TouchHandler *pHandler = StandardTouchHandler::handlerWithDelegate(pDelegate, nPriority);
|
|
||||||
if (! _locked)
|
|
||||||
{
|
|
||||||
forceAddHandler(pHandler, _standardHandlers);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* If pHandler is contained in _handlersToRemove, if so remove it from _handlersToRemove and return.
|
|
||||||
* Refer issue #752(cocos2d-x)
|
|
||||||
*/
|
|
||||||
if (ccCArrayContainsValue(_handlersToRemove, pDelegate))
|
|
||||||
{
|
|
||||||
ccCArrayRemoveValue(_handlersToRemove, pDelegate);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_handlersToAdd->addObject(pHandler);
|
|
||||||
_toAdd = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::addTargetedDelegate(TouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches)
|
|
||||||
{
|
|
||||||
TouchHandler *pHandler = TargetedTouchHandler::handlerWithDelegate(pDelegate, nPriority, bSwallowsTouches);
|
|
||||||
if (! _locked)
|
|
||||||
{
|
|
||||||
forceAddHandler(pHandler, _targetedHandlers);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* If pHandler is contained in _handlersToRemove, if so remove it from _handlersToRemove and return.
|
|
||||||
* Refer issue #752(cocos2d-x)
|
|
||||||
*/
|
|
||||||
if (ccCArrayContainsValue(_handlersToRemove, pDelegate))
|
|
||||||
{
|
|
||||||
ccCArrayRemoveValue(_handlersToRemove, pDelegate);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_handlersToAdd->addObject(pHandler);
|
|
||||||
_toAdd = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::forceRemoveDelegate(TouchDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
TouchHandler *pHandler;
|
|
||||||
|
|
||||||
// XXX: remove it from both handlers ???
|
|
||||||
|
|
||||||
// remove handler from _standardHandlers
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(_standardHandlers, pObj)
|
|
||||||
{
|
|
||||||
pHandler = static_cast<TouchHandler*>(pObj);
|
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
|
||||||
{
|
|
||||||
_standardHandlers->removeObject(pHandler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove handler from _targetedHandlers
|
|
||||||
CCARRAY_FOREACH(_targetedHandlers, pObj)
|
|
||||||
{
|
|
||||||
pHandler = static_cast<TouchHandler*>(pObj);
|
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
|
||||||
{
|
|
||||||
_targetedHandlers->removeObject(pHandler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::removeDelegate(TouchDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
if (pDelegate == NULL)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! _locked)
|
|
||||||
{
|
|
||||||
forceRemoveDelegate(pDelegate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* If pHandler is contained in _handlersToAdd, if so remove it from _handlersToAdd and return.
|
|
||||||
* Refer issue #752(cocos2d-x)
|
|
||||||
*/
|
|
||||||
TouchHandler *pHandler = findHandler(_handlersToAdd, pDelegate);
|
|
||||||
if (pHandler)
|
|
||||||
{
|
|
||||||
_handlersToAdd->removeObject(pHandler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ccCArrayAppendValue(_handlersToRemove, pDelegate);
|
|
||||||
_toRemove = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::forceRemoveAllDelegates(void)
|
|
||||||
{
|
|
||||||
_standardHandlers->removeAllObjects();
|
|
||||||
_targetedHandlers->removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::removeAllDelegates(void)
|
|
||||||
{
|
|
||||||
if (! _locked)
|
|
||||||
{
|
|
||||||
forceRemoveAllDelegates();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_toQuit = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchHandler* TouchDispatcher::findHandler(TouchDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(_targetedHandlers, pObj)
|
|
||||||
{
|
|
||||||
TouchHandler* pHandler = static_cast<TouchHandler*>(pObj);
|
|
||||||
if (pHandler->getDelegate() == pDelegate)
|
|
||||||
{
|
|
||||||
return pHandler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CCARRAY_FOREACH(_standardHandlers, pObj)
|
|
||||||
{
|
|
||||||
TouchHandler* pHandler = static_cast<TouchHandler*>(pObj);
|
|
||||||
if (pHandler->getDelegate() == pDelegate)
|
|
||||||
{
|
|
||||||
return pHandler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchHandler* TouchDispatcher::findHandler(Array* pArray, TouchDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
CCASSERT(pArray != NULL && pDelegate != NULL, "");
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(pArray, pObj)
|
|
||||||
{
|
|
||||||
TouchHandler* pHandle = static_cast<TouchHandler*>(pObj);
|
|
||||||
if (pHandle->getDelegate() == pDelegate)
|
|
||||||
{
|
|
||||||
return pHandle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::rearrangeHandlers(Array *array)
|
|
||||||
{
|
|
||||||
// std::sort(array->data->arr, array->data->arr + array->data->num, less);
|
|
||||||
std::sort( std::begin(*array), std::end(*array), less);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::setPriority(int nPriority, TouchDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
CCASSERT(pDelegate != NULL, "");
|
|
||||||
|
|
||||||
TouchHandler *handler = NULL;
|
|
||||||
|
|
||||||
handler = this->findHandler(pDelegate);
|
|
||||||
|
|
||||||
CCASSERT(handler != NULL, "");
|
|
||||||
|
|
||||||
if (handler->getPriority() != nPriority)
|
|
||||||
{
|
|
||||||
handler->setPriority(nPriority);
|
|
||||||
this->rearrangeHandlers(_targetedHandlers);
|
|
||||||
this->rearrangeHandlers(_standardHandlers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// dispatch events
|
|
||||||
//
|
|
||||||
void TouchDispatcher::touches(Set *pTouches, Event *pEvent, unsigned int uIndex)
|
|
||||||
{
|
|
||||||
CCASSERT(uIndex >= 0 && uIndex < 4, "");
|
|
||||||
|
|
||||||
Set *pMutableTouches;
|
|
||||||
_locked = true;
|
|
||||||
|
|
||||||
// optimization to prevent a mutable copy when it is not necessary
|
|
||||||
unsigned int uTargetedHandlersCount = _targetedHandlers->count();
|
|
||||||
unsigned int uStandardHandlersCount = _standardHandlers->count();
|
|
||||||
bool bNeedsMutableSet = (uTargetedHandlersCount && uStandardHandlersCount);
|
|
||||||
|
|
||||||
pMutableTouches = (bNeedsMutableSet ? pTouches->mutableCopy() : pTouches);
|
|
||||||
|
|
||||||
struct ccTouchHandlerHelperData sHelper = _handlerHelperData[uIndex];
|
|
||||||
//
|
|
||||||
// process the target handlers 1st
|
|
||||||
//
|
|
||||||
if (uTargetedHandlersCount > 0)
|
|
||||||
{
|
|
||||||
Touch *pTouch;
|
|
||||||
SetIterator setIter;
|
|
||||||
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
|
|
||||||
{
|
|
||||||
pTouch = (Touch *)(*setIter);
|
|
||||||
|
|
||||||
TargetedTouchHandler *pHandler = NULL;
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(_targetedHandlers, pObj)
|
|
||||||
{
|
|
||||||
pHandler = static_cast<TargetedTouchHandler*>(pObj);
|
|
||||||
|
|
||||||
if (! pHandler)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bClaimed = false;
|
|
||||||
if (uIndex == CCTOUCHBEGAN)
|
|
||||||
{
|
|
||||||
bClaimed = pHandler->getDelegate()->ccTouchBegan(pTouch, pEvent);
|
|
||||||
|
|
||||||
if (bClaimed)
|
|
||||||
{
|
|
||||||
pHandler->getClaimedTouches()->addObject(pTouch);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
if (pHandler->getClaimedTouches()->containsObject(pTouch))
|
|
||||||
{
|
|
||||||
// moved ended canceled
|
|
||||||
bClaimed = true;
|
|
||||||
|
|
||||||
switch (sHelper._type)
|
|
||||||
{
|
|
||||||
case CCTOUCHMOVED:
|
|
||||||
pHandler->getDelegate()->ccTouchMoved(pTouch, pEvent);
|
|
||||||
break;
|
|
||||||
case CCTOUCHENDED:
|
|
||||||
pHandler->getDelegate()->ccTouchEnded(pTouch, pEvent);
|
|
||||||
pHandler->getClaimedTouches()->removeObject(pTouch);
|
|
||||||
break;
|
|
||||||
case CCTOUCHCANCELLED:
|
|
||||||
pHandler->getDelegate()->ccTouchCancelled(pTouch, pEvent);
|
|
||||||
pHandler->getClaimedTouches()->removeObject(pTouch);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bClaimed && pHandler->isSwallowsTouches())
|
|
||||||
{
|
|
||||||
if (bNeedsMutableSet)
|
|
||||||
{
|
|
||||||
pMutableTouches->removeObject(pTouch);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// process standard handlers 2nd
|
|
||||||
//
|
|
||||||
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
|
||||||
{
|
|
||||||
StandardTouchHandler *pHandler = NULL;
|
|
||||||
Object* pObj = nullptr;
|
|
||||||
CCARRAY_FOREACH(_standardHandlers, pObj)
|
|
||||||
{
|
|
||||||
pHandler = static_cast<StandardTouchHandler*>(pObj);
|
|
||||||
|
|
||||||
if (! pHandler)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (sHelper._type)
|
|
||||||
{
|
|
||||||
case CCTOUCHBEGAN:
|
|
||||||
pHandler->getDelegate()->ccTouchesBegan(pMutableTouches, pEvent);
|
|
||||||
break;
|
|
||||||
case CCTOUCHMOVED:
|
|
||||||
pHandler->getDelegate()->ccTouchesMoved(pMutableTouches, pEvent);
|
|
||||||
break;
|
|
||||||
case CCTOUCHENDED:
|
|
||||||
pHandler->getDelegate()->ccTouchesEnded(pMutableTouches, pEvent);
|
|
||||||
break;
|
|
||||||
case CCTOUCHCANCELLED:
|
|
||||||
pHandler->getDelegate()->ccTouchesCancelled(pMutableTouches, pEvent);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bNeedsMutableSet)
|
|
||||||
{
|
|
||||||
pMutableTouches->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Optimization. To prevent a [handlers copy] which is expensive
|
|
||||||
// the add/removes/quit is done after the iterations
|
|
||||||
//
|
|
||||||
_locked = false;
|
|
||||||
if (_toRemove)
|
|
||||||
{
|
|
||||||
_toRemove = false;
|
|
||||||
for (int i = 0; i < _handlersToRemove->num; ++i)
|
|
||||||
{
|
|
||||||
forceRemoveDelegate((TouchDelegate*)_handlersToRemove->arr[i]);
|
|
||||||
}
|
|
||||||
ccCArrayRemoveAllValues(_handlersToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_toAdd)
|
|
||||||
{
|
|
||||||
_toAdd = false;
|
|
||||||
TouchHandler* pHandler = NULL;
|
|
||||||
Object* pObj = nullptr;
|
|
||||||
CCARRAY_FOREACH(_handlersToAdd, pObj)
|
|
||||||
{
|
|
||||||
pHandler = static_cast<TouchHandler*>(pObj);
|
|
||||||
if (! pHandler)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dynamic_cast<TargetedTouchHandler*>(pHandler) != NULL)
|
|
||||||
{
|
|
||||||
forceAddHandler(pHandler, _targetedHandlers);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
forceAddHandler(pHandler, _standardHandlers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_handlersToAdd->removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_toQuit)
|
|
||||||
{
|
|
||||||
_toQuit = false;
|
|
||||||
forceRemoveAllDelegates();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::touchesBegan(Set *touches, Event *pEvent)
|
|
||||||
{
|
|
||||||
if (_dispatchEvents)
|
|
||||||
{
|
|
||||||
this->touches(touches, pEvent, CCTOUCHBEGAN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::touchesMoved(Set *touches, Event *pEvent)
|
|
||||||
{
|
|
||||||
if (_dispatchEvents)
|
|
||||||
{
|
|
||||||
this->touches(touches, pEvent, CCTOUCHMOVED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::touchesEnded(Set *touches, Event *pEvent)
|
|
||||||
{
|
|
||||||
if (_dispatchEvents)
|
|
||||||
{
|
|
||||||
this->touches(touches, pEvent, CCTOUCHENDED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchDispatcher::touchesCancelled(Set *touches, Event *pEvent)
|
|
||||||
{
|
|
||||||
if (_dispatchEvents)
|
|
||||||
{
|
|
||||||
this->touches(touches, pEvent, CCTOUCHCANCELLED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
|
@ -1,195 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010-2012 cocos2d-x.org
|
|
||||||
Copyright (c) 2009 Valentin Milea
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "CCTouchHandler.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
TouchDelegate* TouchHandler::getDelegate(void)
|
|
||||||
{
|
|
||||||
return _delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchHandler::setDelegate(TouchDelegate *pDelegate)
|
|
||||||
{
|
|
||||||
if (pDelegate)
|
|
||||||
{
|
|
||||||
dynamic_cast<Object*>(pDelegate)->retain();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_delegate)
|
|
||||||
{
|
|
||||||
dynamic_cast<Object*>(_delegate)->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
_delegate = pDelegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TouchHandler::getPriority(void)
|
|
||||||
{
|
|
||||||
return _priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchHandler::setPriority(int nPriority)
|
|
||||||
{
|
|
||||||
_priority = nPriority;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TouchHandler::getEnabledSelectors(void)
|
|
||||||
{
|
|
||||||
return _enabledSelectors;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchHandler::setEnalbedSelectors(int nValue)
|
|
||||||
{
|
|
||||||
_enabledSelectors = nValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchHandler* TouchHandler::handlerWithDelegate(TouchDelegate *pDelegate, int nPriority)
|
|
||||||
{
|
|
||||||
TouchHandler *pHandler = new TouchHandler();
|
|
||||||
|
|
||||||
if (pHandler)
|
|
||||||
{
|
|
||||||
if (pHandler->initWithDelegate(pDelegate, nPriority))
|
|
||||||
{
|
|
||||||
pHandler->autorelease();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(pHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TouchHandler::initWithDelegate(TouchDelegate *pDelegate, int nPriority)
|
|
||||||
{
|
|
||||||
CCASSERT(pDelegate != NULL, "touch delegate should not be null");
|
|
||||||
|
|
||||||
_delegate = pDelegate;
|
|
||||||
|
|
||||||
dynamic_cast<Object*>(pDelegate)->retain();
|
|
||||||
|
|
||||||
_priority = nPriority;
|
|
||||||
_enabledSelectors = 0;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchHandler::~TouchHandler(void)
|
|
||||||
{
|
|
||||||
if (_delegate)
|
|
||||||
{
|
|
||||||
dynamic_cast<Object*>(_delegate)->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// implementation of StandardTouchHandler
|
|
||||||
bool StandardTouchHandler::initWithDelegate(TouchDelegate *pDelegate, int nPriority)
|
|
||||||
{
|
|
||||||
if (TouchHandler::initWithDelegate(pDelegate, nPriority))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
StandardTouchHandler* StandardTouchHandler::handlerWithDelegate(TouchDelegate *pDelegate, int nPriority)
|
|
||||||
{
|
|
||||||
StandardTouchHandler* pHandler = new StandardTouchHandler();
|
|
||||||
|
|
||||||
if (pHandler)
|
|
||||||
{
|
|
||||||
if (pHandler->initWithDelegate(pDelegate, nPriority))
|
|
||||||
{
|
|
||||||
pHandler->autorelease();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(pHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
// implementation of TargetedTouchHandler
|
|
||||||
|
|
||||||
bool TargetedTouchHandler::isSwallowsTouches(void)
|
|
||||||
{
|
|
||||||
return _swallowsTouches;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TargetedTouchHandler::setSwallowsTouches(bool bSwallowsTouches)
|
|
||||||
{
|
|
||||||
_swallowsTouches = bSwallowsTouches;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set* TargetedTouchHandler::getClaimedTouches(void)
|
|
||||||
{
|
|
||||||
return _claimedTouches;
|
|
||||||
}
|
|
||||||
|
|
||||||
TargetedTouchHandler* TargetedTouchHandler::handlerWithDelegate(TouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
|
||||||
{
|
|
||||||
TargetedTouchHandler *pHandler = new TargetedTouchHandler();
|
|
||||||
if (pHandler)
|
|
||||||
{
|
|
||||||
if (pHandler->initWithDelegate(pDelegate, nPriority, bSwallow))
|
|
||||||
{
|
|
||||||
pHandler->autorelease();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(pHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TargetedTouchHandler::initWithDelegate(TouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
|
||||||
{
|
|
||||||
if (TouchHandler::initWithDelegate(pDelegate, nPriority))
|
|
||||||
{
|
|
||||||
_claimedTouches = new Set();
|
|
||||||
_swallowsTouches = bSwallow;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TargetedTouchHandler::~TargetedTouchHandler(void)
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE(_claimedTouches);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
|
@ -31,34 +31,6 @@ CCBReader/CCParticleSystemQuadLoader.cpp \
|
||||||
CCBReader/CCScale9SpriteLoader.cpp \
|
CCBReader/CCScale9SpriteLoader.cpp \
|
||||||
CCBReader/CCScrollViewLoader.cpp \
|
CCBReader/CCScrollViewLoader.cpp \
|
||||||
CCBReader/CCSpriteLoader.cpp \
|
CCBReader/CCSpriteLoader.cpp \
|
||||||
GUI/CCControlExtension/CCControl.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlButton.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlColourPicker.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlHuePicker.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlPotentiometer.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlSaturationBrightnessPicker.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlSlider.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlStepper.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlSwitch.cpp \
|
|
||||||
GUI/CCControlExtension/CCControlUtils.cpp \
|
|
||||||
GUI/CCControlExtension/CCInvocation.cpp \
|
|
||||||
GUI/CCControlExtension/CCScale9Sprite.cpp \
|
|
||||||
GUI/CCEditBox/CCEditBox.cpp \
|
|
||||||
GUI/CCEditBox/CCEditBoxImplAndroid.cpp \
|
|
||||||
GUI/CCEditBox/CCEditBoxImplNone.cpp \
|
|
||||||
GUI/CCEditBox/CCEditBoxImplTizen.cpp \
|
|
||||||
GUI/CCEditBox/CCEditBoxImplWin.cpp \
|
|
||||||
GUI/CCScrollView/CCScrollView.cpp \
|
|
||||||
GUI/CCScrollView/CCSorting.cpp \
|
|
||||||
GUI/CCScrollView/CCTableView.cpp \
|
|
||||||
GUI/CCScrollView/CCTableViewCell.cpp \
|
|
||||||
LocalStorage/LocalStorage.cpp \
|
|
||||||
LocalStorage/LocalStorageAndroid.cpp \
|
|
||||||
network/HttpClient.cpp \
|
|
||||||
network/SocketIO.cpp \
|
|
||||||
network/WebSocket.cpp \
|
|
||||||
physics_nodes/CCPhysicsDebugNode.cpp \
|
|
||||||
physics_nodes/CCPhysicsSprite.cpp \
|
|
||||||
CocoStudio/Armature/CCArmature.cpp \
|
CocoStudio/Armature/CCArmature.cpp \
|
||||||
CocoStudio/Armature/CCBone.cpp \
|
CocoStudio/Armature/CCBone.cpp \
|
||||||
CocoStudio/Armature/animation/CCArmatureAnimation.cpp \
|
CocoStudio/Armature/animation/CCArmatureAnimation.cpp \
|
||||||
|
@ -88,10 +60,38 @@ CocoStudio/Components/CCComRender.cpp \
|
||||||
CocoStudio/Components/CCInputDelegate.cpp \
|
CocoStudio/Components/CCInputDelegate.cpp \
|
||||||
CocoStudio/Json/CSContentJsonDictionary.cpp \
|
CocoStudio/Json/CSContentJsonDictionary.cpp \
|
||||||
CocoStudio/Json/DictionaryHelper.cpp \
|
CocoStudio/Json/DictionaryHelper.cpp \
|
||||||
CocoStudio/Json/lib_json/json_value.cpp \
|
|
||||||
CocoStudio/Json/lib_json/json_reader.cpp \
|
CocoStudio/Json/lib_json/json_reader.cpp \
|
||||||
|
CocoStudio/Json/lib_json/json_value.cpp \
|
||||||
CocoStudio/Json/lib_json/json_writer.cpp \
|
CocoStudio/Json/lib_json/json_writer.cpp \
|
||||||
CocoStudio/Reader/CCSSceneReader.cpp \
|
CocoStudio/Reader/CCSSceneReader.cpp \
|
||||||
|
GUI/CCControlExtension/CCControl.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlButton.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlColourPicker.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlHuePicker.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlPotentiometer.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlSaturationBrightnessPicker.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlSlider.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlStepper.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlSwitch.cpp \
|
||||||
|
GUI/CCControlExtension/CCControlUtils.cpp \
|
||||||
|
GUI/CCControlExtension/CCInvocation.cpp \
|
||||||
|
GUI/CCControlExtension/CCScale9Sprite.cpp \
|
||||||
|
GUI/CCEditBox/CCEditBox.cpp \
|
||||||
|
GUI/CCEditBox/CCEditBoxImplAndroid.cpp \
|
||||||
|
GUI/CCEditBox/CCEditBoxImplNone.cpp \
|
||||||
|
GUI/CCEditBox/CCEditBoxImplTizen.cpp \
|
||||||
|
GUI/CCEditBox/CCEditBoxImplWin.cpp \
|
||||||
|
GUI/CCScrollView/CCScrollView.cpp \
|
||||||
|
GUI/CCScrollView/CCSorting.cpp \
|
||||||
|
GUI/CCScrollView/CCTableView.cpp \
|
||||||
|
GUI/CCScrollView/CCTableViewCell.cpp \
|
||||||
|
LocalStorage/LocalStorage.cpp \
|
||||||
|
LocalStorage/LocalStorageAndroid.cpp \
|
||||||
|
network/HttpClient.cpp \
|
||||||
|
network/SocketIO.cpp \
|
||||||
|
network/WebSocket.cpp \
|
||||||
|
physics_nodes/CCPhysicsDebugNode.cpp \
|
||||||
|
physics_nodes/CCPhysicsSprite.cpp \
|
||||||
spine/Animation.cpp \
|
spine/Animation.cpp \
|
||||||
spine/AnimationState.cpp \
|
spine/AnimationState.cpp \
|
||||||
spine/AnimationStateData.cpp \
|
spine/AnimationStateData.cpp \
|
||||||
|
|
|
@ -511,6 +511,7 @@ void Armature::visit()
|
||||||
transform();
|
transform();
|
||||||
sortAllChildren();
|
sortAllChildren();
|
||||||
draw();
|
draw();
|
||||||
|
updateEventPriorityIndex();
|
||||||
|
|
||||||
// reset for next frame
|
// reset for next frame
|
||||||
_orderOfArrival = 0;
|
_orderOfArrival = 0;
|
||||||
|
|
|
@ -79,6 +79,7 @@ void BatchNode::visit()
|
||||||
transform();
|
transform();
|
||||||
sortAllChildren();
|
sortAllChildren();
|
||||||
draw();
|
draw();
|
||||||
|
updateEventPriorityIndex();
|
||||||
|
|
||||||
// reset for next frame
|
// reset for next frame
|
||||||
_orderOfArrival = 0;
|
_orderOfArrival = 0;
|
||||||
|
|
|
@ -28,8 +28,11 @@ NS_CC_EXT_BEGIN
|
||||||
|
|
||||||
InputDelegate::InputDelegate(void)
|
InputDelegate::InputDelegate(void)
|
||||||
: _touchEnabled(false)
|
: _touchEnabled(false)
|
||||||
|
, _touchListener(nullptr)
|
||||||
, _accelerometerEnabled(false)
|
, _accelerometerEnabled(false)
|
||||||
|
, _accelerometerListener(nullptr)
|
||||||
, _keypadEnabled(false)
|
, _keypadEnabled(false)
|
||||||
|
, _keyboardListener(nullptr)
|
||||||
, _touchPriority(0)
|
, _touchPriority(0)
|
||||||
, _touchMode(Touch::DispatchMode::ALL_AT_ONCE)
|
, _touchMode(Touch::DispatchMode::ALL_AT_ONCE)
|
||||||
{
|
{
|
||||||
|
@ -38,62 +41,61 @@ InputDelegate::InputDelegate(void)
|
||||||
|
|
||||||
InputDelegate::~InputDelegate(void)
|
InputDelegate::~InputDelegate(void)
|
||||||
{
|
{
|
||||||
|
auto dispatcher = EventDispatcher::getInstance();
|
||||||
|
dispatcher->removeEventListener(_touchListener);
|
||||||
|
dispatcher->removeEventListener(_keyboardListener);
|
||||||
|
dispatcher->removeEventListener(_accelerometerListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputDelegate::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
bool InputDelegate::onTouchBegan(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouch);
|
CC_UNUSED_PARAM(pTouch);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::ccTouchMoved(Touch *pTouch, Event *pEvent)
|
void InputDelegate::onTouchMoved(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouch);
|
CC_UNUSED_PARAM(pTouch);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::ccTouchEnded(Touch *pTouch, Event *pEvent)
|
void InputDelegate::onTouchEnded(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouch);
|
CC_UNUSED_PARAM(pTouch);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::ccTouchCancelled(Touch *pTouch, Event *pEvent)
|
void InputDelegate::onTouchCancelled(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouch);
|
CC_UNUSED_PARAM(pTouch);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::ccTouchesBegan(Set *pTouches, Event *pEvent)
|
void InputDelegate::onTouchesBegan(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouches);
|
CC_UNUSED_PARAM(pTouches);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::ccTouchesMoved(Set *pTouches, Event *pEvent)
|
void InputDelegate::onTouchesMoved(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouches);
|
CC_UNUSED_PARAM(pTouches);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::ccTouchesEnded(Set *pTouches, Event *pEvent)
|
void InputDelegate::onTouchesEnded(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouches);
|
CC_UNUSED_PARAM(pTouches);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::ccTouchesCancelled(Set *pTouches, Event *pEvent)
|
void InputDelegate::onTouchesCancelled(const std::vector<Touch*>& pTouches, Event *pEvent)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(pTouches);
|
CC_UNUSED_PARAM(pTouches);
|
||||||
CC_UNUSED_PARAM(pEvent);
|
CC_UNUSED_PARAM(pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDelegate::didAccelerate(Acceleration* pAccelerationValue)
|
|
||||||
{
|
|
||||||
CC_UNUSED_PARAM(pAccelerationValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool InputDelegate::isTouchEnabled() const
|
bool InputDelegate::isTouchEnabled() const
|
||||||
{
|
{
|
||||||
return _touchEnabled;
|
return _touchEnabled;
|
||||||
|
@ -106,18 +108,34 @@ void InputDelegate::setTouchEnabled(bool enabled)
|
||||||
_touchEnabled = enabled;
|
_touchEnabled = enabled;
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
if( _touchMode == Touch::DispatchMode::ALL_AT_ONCE )
|
if( _touchMode == Touch::DispatchMode::ALL_AT_ONCE ) {
|
||||||
{
|
// Register Touch Event
|
||||||
Director::getInstance()->getTouchDispatcher()->addStandardDelegate(this, 0);
|
auto listener = TouchEventListener::create(Touch::DispatchMode::ALL_AT_ONCE);
|
||||||
}
|
|
||||||
else
|
listener->onTouchesBegan = CC_CALLBACK_2(InputDelegate::onTouchesBegan, this);
|
||||||
{
|
listener->onTouchesMoved = CC_CALLBACK_2(InputDelegate::onTouchesMoved, this);
|
||||||
Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, _touchPriority, true);
|
listener->onTouchesEnded = CC_CALLBACK_2(InputDelegate::onTouchesEnded, this);
|
||||||
|
listener->onTouchesCancelled = CC_CALLBACK_2(InputDelegate::onTouchesCancelled, this);
|
||||||
|
|
||||||
|
EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 0);
|
||||||
|
_touchListener = listener;
|
||||||
|
} else {
|
||||||
|
// Register Touch Event
|
||||||
|
auto listener = TouchEventListener::create(Touch::DispatchMode::ONE_BY_ONE);
|
||||||
|
listener->setSwallowTouches(true);
|
||||||
|
|
||||||
|
listener->onTouchBegan = CC_CALLBACK_2(InputDelegate::onTouchBegan, this);
|
||||||
|
listener->onTouchMoved = CC_CALLBACK_2(InputDelegate::onTouchMoved, this);
|
||||||
|
listener->onTouchEnded = CC_CALLBACK_2(InputDelegate::onTouchEnded, this);
|
||||||
|
listener->onTouchCancelled = CC_CALLBACK_2(InputDelegate::onTouchCancelled, this);
|
||||||
|
|
||||||
|
EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, _touchPriority);
|
||||||
|
_touchListener = listener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Director::getInstance()->getTouchDispatcher()->removeDelegate(this);
|
EventDispatcher::getInstance()->removeEventListener(_touchListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,14 +189,15 @@ void InputDelegate::setAccelerometerEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
_accelerometerEnabled = enabled;
|
_accelerometerEnabled = enabled;
|
||||||
|
|
||||||
Director* pDirector = Director::getInstance();
|
auto dispatcher = EventDispatcher::getInstance();
|
||||||
|
dispatcher->removeEventListener(_accelerometerListener);
|
||||||
|
_accelerometerListener = nullptr;
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(InputDelegate::didAccelerate, this));
|
auto listener = AccelerationEventListener::create(CC_CALLBACK_2(InputDelegate::onAcceleration, this));
|
||||||
}
|
dispatcher->addEventListenerWithFixedPriority(listener, 0);
|
||||||
else
|
_accelerometerListener = listener;
|
||||||
{
|
|
||||||
pDirector->getAccelerometer()->setDelegate(nullptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,14 +213,16 @@ void InputDelegate::setKeypadEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
_keypadEnabled = enabled;
|
_keypadEnabled = enabled;
|
||||||
|
|
||||||
Director* pDirector = Director::getInstance();
|
EventDispatcher::getInstance()->removeEventListener(_keyboardListener);
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
pDirector->getKeypadDispatcher()->addDelegate(this);
|
auto listener = KeyboardEventListener::create();
|
||||||
}
|
listener->onKeyPressed = CC_CALLBACK_2(InputDelegate::onKeyPressed, this);
|
||||||
else
|
listener->onKeyReleased = CC_CALLBACK_2(InputDelegate::onKeyReleased, this);
|
||||||
{
|
|
||||||
pDirector->getKeypadDispatcher()->removeDelegate(this);
|
EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 0);
|
||||||
|
_keyboardListener = listener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
NS_CC_EXT_BEGIN
|
||||||
|
|
||||||
class InputDelegate : public TouchDelegate, public KeypadDelegate
|
class InputDelegate
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
@ -95,59 +95,40 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual int getTouchPriority() const;
|
virtual int getTouchPriority() const;
|
||||||
/**
|
/** @deprecated Please override onAcceleration */
|
||||||
* @js NA
|
CC_DEPRECATED_ATTRIBUTE virtual void didAccelerate(Acceleration* accelerationValue) final { CC_UNUSED_PARAM(accelerationValue); };
|
||||||
* @lua NA
|
// Deprecated touch callbacks.
|
||||||
*/
|
CC_DEPRECATED_ATTRIBUTE virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent); return false;};
|
||||||
virtual void didAccelerate(Acceleration* accelerationValue);
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
|
||||||
// Overrides
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesBegan(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
/**
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesMoved(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
* @js NA
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesEnded(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
* @lua NA
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesCancelled(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
*/
|
|
||||||
virtual bool ccTouchBegan(Touch *touch, Event *event) override;
|
virtual void onAcceleration(Acceleration* acc, Event* event) {};
|
||||||
/**
|
|
||||||
* @js NA
|
virtual void onKeyPressed(KeyboardEvent::KeyCode keyCode, Event* event) {};
|
||||||
* @lua NA
|
virtual void onKeyReleased(KeyboardEvent::KeyCode keyCode, Event* event) {};
|
||||||
*/
|
|
||||||
virtual void ccTouchMoved(Touch *touch, Event *event) override;
|
virtual bool onTouchBegan(Touch *touch, Event *event);
|
||||||
/**
|
virtual void onTouchMoved(Touch *touch, Event *event);
|
||||||
* @js NA
|
virtual void onTouchEnded(Touch *touch, Event *event);
|
||||||
* @lua NA
|
virtual void onTouchCancelled(Touch *touch, Event *event);
|
||||||
*/
|
virtual void onTouchesBegan(const std::vector<Touch*>& touches, Event *event);
|
||||||
virtual void ccTouchEnded(Touch *touch, Event *event) override;
|
virtual void onTouchesMoved(const std::vector<Touch*>& touches, Event *event);
|
||||||
/**
|
virtual void onTouchesEnded(const std::vector<Touch*>& touches, Event *event);
|
||||||
* @js NA
|
virtual void onTouchesCancelled(const std::vector<Touch*>& touches, Event *event);
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual void ccTouchCancelled(Touch *touch, Event *event) override;
|
|
||||||
/**
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual void ccTouchesBegan(Set *touches, Event *event) override;
|
|
||||||
/**
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual void ccTouchesMoved(Set *touches, Event *event) override;
|
|
||||||
/**
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual void ccTouchesEnded(Set *touches, Event *event) override;
|
|
||||||
/**
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual void ccTouchesCancelled(Set *touches, Event *event) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _touchEnabled;
|
bool _touchEnabled;
|
||||||
|
EventListener* _touchListener;
|
||||||
bool _accelerometerEnabled;
|
bool _accelerometerEnabled;
|
||||||
|
EventListener* _accelerometerListener;
|
||||||
bool _keypadEnabled;
|
bool _keypadEnabled;
|
||||||
|
EventListener* _keyboardListener;
|
||||||
private:
|
private:
|
||||||
int _touchPriority;
|
int _touchPriority;
|
||||||
Touch::DispatchMode _touchMode;
|
Touch::DispatchMode _touchMode;
|
||||||
|
|
|
@ -49,13 +49,7 @@ NS_CC_EXT_BEGIN
|
||||||
cocos2d::Node *pNode = NULL;
|
cocos2d::Node *pNode = NULL;
|
||||||
do {
|
do {
|
||||||
CC_BREAK_IF(pszFileName == NULL);
|
CC_BREAK_IF(pszFileName == NULL);
|
||||||
std::string strFileName(pszFileName);
|
pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pszFileName, "r", &size));
|
||||||
if (std::string::npos != strFileName.find_last_of('/'))
|
|
||||||
{
|
|
||||||
strFileName = strFileName.substr(0, strFileName.find_last_of('/') + 1);
|
|
||||||
cocos2d::CCFileUtils::getInstance()->addSearchPath(strFileName.c_str());
|
|
||||||
}
|
|
||||||
pData = (char*)(cocos2d::CCFileUtils::getInstance()->getFileData(pszFileName, "r", &size));
|
|
||||||
CC_BREAK_IF(pData == NULL || strcmp(pData, "") == 0);
|
CC_BREAK_IF(pData == NULL || strcmp(pData, "") == 0);
|
||||||
cs::JsonDictionary *jsonDict = new cs::JsonDictionary();
|
cs::JsonDictionary *jsonDict = new cs::JsonDictionary();
|
||||||
jsonDict->initWithDescription(pData);
|
jsonDict->initWithDescription(pData);
|
||||||
|
@ -107,12 +101,12 @@ NS_CC_EXT_BEGIN
|
||||||
const char *plistFile = fileData->getItemStringValue("plistFile");
|
const char *plistFile = fileData->getItemStringValue("plistFile");
|
||||||
if (file != NULL)
|
if (file != NULL)
|
||||||
{
|
{
|
||||||
pPath.append(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(file));
|
pPath.append(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plistFile != NULL)
|
if (plistFile != NULL)
|
||||||
{
|
{
|
||||||
pPlistFile.append(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(plistFile));
|
pPlistFile.append(cocos2d::FileUtils::getInstance()->fullPathForFilename(plistFile));
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(fileData);
|
CC_SAFE_DELETE(fileData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ public:
|
||||||
void purgeSceneReader();
|
void purgeSceneReader();
|
||||||
static const char* sceneReaderVersion();
|
static const char* sceneReaderVersion();
|
||||||
cocos2d::Node* createNodeWithSceneFile(const char *pszFileName);
|
cocos2d::Node* createNodeWithSceneFile(const char *pszFileName);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
cocos2d::Node* createObject(cs::JsonDictionary * inputFiles, cocos2d::Node* parent);
|
cocos2d::Node* createObject(cs::JsonDictionary * inputFiles, cocos2d::Node* parent);
|
||||||
void setPropertyFromJsonDict(cocos2d::Node *node, cs::JsonDictionary* dict);
|
void setPropertyFromJsonDict(cocos2d::Node *node, cs::JsonDictionary* dict);
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,11 @@
|
||||||
|
|
||||||
#include "CCControl.h"
|
#include "CCControl.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
||||||
#include "menu_nodes/CCMenu.h"
|
#include "menu_nodes/CCMenu.h"
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "event_dispatcher/CCTouch.h"
|
||||||
#include "CCInvocation.h"
|
#include "CCInvocation.h"
|
||||||
|
#include "event_dispatcher/CCEventDispatcher.h"
|
||||||
|
#include "event_dispatcher/CCTouchEventListener.h"
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
NS_CC_EXT_BEGIN
|
||||||
|
|
||||||
|
@ -75,8 +76,6 @@ bool Control::init()
|
||||||
setSelected(false);
|
setSelected(false);
|
||||||
setHighlighted(false);
|
setHighlighted(false);
|
||||||
|
|
||||||
// Set the touch dispatcher priority by default to 1
|
|
||||||
this->setTouchPriority(1);
|
|
||||||
// Initialise the tables
|
// Initialise the tables
|
||||||
_dispatchTable = new Dictionary();
|
_dispatchTable = new Dictionary();
|
||||||
_dispatchTable->init();
|
_dispatchTable->init();
|
||||||
|
@ -94,15 +93,17 @@ Control::~Control()
|
||||||
CC_SAFE_RELEASE(_dispatchTable);
|
CC_SAFE_RELEASE(_dispatchTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Menu - Events
|
////Menu - Events
|
||||||
void Control::registerWithTouchDispatcher()
|
//void Control::registerWithTouchDispatcher()
|
||||||
{
|
//{
|
||||||
Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), true);
|
// Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), true);
|
||||||
}
|
//}
|
||||||
|
|
||||||
void Control::onEnter()
|
void Control::onEnter()
|
||||||
{
|
{
|
||||||
Layer::onEnter();
|
Layer::onEnter();
|
||||||
|
|
||||||
|
this->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::onExit()
|
void Control::onExit()
|
||||||
|
|
|
@ -164,6 +164,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual Point getTouchLocation(Touch* touch);
|
virtual Point getTouchLocation(Touch* touch);
|
||||||
|
|
||||||
|
virtual bool onTouchBegan(Touch *touch, Event *event) { return false; };
|
||||||
|
virtual void onTouchMoved(Touch *touch, Event *event) {};
|
||||||
|
virtual void onTouchEnded(Touch *touch, Event *event) {};
|
||||||
|
virtual void onTouchCancelled(Touch *touch, Event *event) {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a boolean value that indicates whether a touch is inside the bounds
|
* Returns a boolean value that indicates whether a touch is inside the bounds
|
||||||
* of the receiver. The given touch must be relative to the world.
|
* of the receiver. The given touch must be relative to the world.
|
||||||
|
@ -187,7 +192,7 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual void onExit() override;
|
virtual void onExit() override;
|
||||||
virtual void registerWithTouchDispatcher() override;
|
// virtual void registerWithTouchDispatcher() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -630,7 +630,7 @@ void ControlButton::needsLayout()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ControlButton::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
bool ControlButton::onTouchBegan(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (!isTouchInside(pTouch) || !isEnabled() || !isVisible() || !hasVisibleParents() )
|
if (!isTouchInside(pTouch) || !isEnabled() || !isVisible() || !hasVisibleParents() )
|
||||||
{
|
{
|
||||||
|
@ -651,7 +651,7 @@ bool ControlButton::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlButton::ccTouchMoved(Touch *pTouch, Event *pEvent)
|
void ControlButton::onTouchMoved(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (!isEnabled() || !isPushed() || isSelected())
|
if (!isEnabled() || !isPushed() || isSelected())
|
||||||
{
|
{
|
||||||
|
@ -683,7 +683,7 @@ void ControlButton::ccTouchMoved(Touch *pTouch, Event *pEvent)
|
||||||
sendActionsForControlEvents(Control::EventType::DRAG_OUTSIDE);
|
sendActionsForControlEvents(Control::EventType::DRAG_OUTSIDE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ControlButton::ccTouchEnded(Touch *pTouch, Event *pEvent)
|
void ControlButton::onTouchEnded(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
_isPushed = false;
|
_isPushed = false;
|
||||||
setHighlighted(false);
|
setHighlighted(false);
|
||||||
|
@ -745,7 +745,7 @@ const Color3B& ControlButton::getColor() const
|
||||||
return _realColor;
|
return _realColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlButton::ccTouchCancelled(Touch *pTouch, Event *pEvent)
|
void ControlButton::onTouchCancelled(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
_isPushed = false;
|
_isPushed = false;
|
||||||
setHighlighted(false);
|
setHighlighted(false);
|
||||||
|
|
|
@ -184,11 +184,16 @@ public:
|
||||||
//set the margins at once (so we only have to do one call of needsLayout)
|
//set the margins at once (so we only have to do one call of needsLayout)
|
||||||
virtual void setMargins(int marginH, int marginV);
|
virtual void setMargins(int marginH, int marginV);
|
||||||
|
|
||||||
|
virtual bool onTouchBegan(Touch *touch, Event *event) override;
|
||||||
|
virtual void onTouchMoved(Touch *touch, Event *event) override;
|
||||||
|
virtual void onTouchEnded(Touch *touch, Event *event) override;
|
||||||
|
virtual void onTouchCancelled(Touch *touch, Event *event) override;
|
||||||
|
|
||||||
// Overrides
|
// Overrides
|
||||||
virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent) override;
|
// virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent) override;
|
||||||
virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) override;
|
// virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) override;
|
||||||
virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) override;
|
// virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) override;
|
||||||
virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) override;
|
// virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) override;
|
||||||
virtual GLubyte getOpacity(void) const override;
|
virtual GLubyte getOpacity(void) const override;
|
||||||
virtual void setOpacity(GLubyte var) override;
|
virtual void setOpacity(GLubyte var) override;
|
||||||
virtual const Color3B& getColor(void) const override;
|
virtual const Color3B& getColor(void) const override;
|
||||||
|
|
|
@ -191,7 +191,7 @@ void ControlColourPicker::colourSliderValueChanged(Object * sender, Control::Eve
|
||||||
}
|
}
|
||||||
|
|
||||||
//ignore all touches, handled by children
|
//ignore all touches, handled by children
|
||||||
bool ControlColourPicker::ccTouchBegan(Touch* touch, Event* pEvent)
|
bool ControlColourPicker::onTouchBegan(Touch* touch, Event* pEvent)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void updateControlPicker();
|
void updateControlPicker();
|
||||||
void updateHueAndControlPicker();
|
void updateHueAndControlPicker();
|
||||||
virtual bool ccTouchBegan(Touch* touch, Event* pEvent);
|
virtual bool onTouchBegan(Touch* touch, Event* pEvent);
|
||||||
|
|
||||||
HSV _hsv;
|
HSV _hsv;
|
||||||
CC_SYNTHESIZE_RETAIN(ControlSaturationBrightnessPicker*, _colourPicker, colourPicker)
|
CC_SYNTHESIZE_RETAIN(ControlSaturationBrightnessPicker*, _colourPicker, colourPicker)
|
||||||
|
|
|
@ -164,7 +164,7 @@ bool ControlHuePicker::checkSliderPosition(Point location)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ControlHuePicker::ccTouchBegan(Touch* touch, Event* event)
|
bool ControlHuePicker::onTouchBegan(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
if (!isEnabled() || !isVisible())
|
if (!isEnabled() || !isVisible())
|
||||||
{
|
{
|
||||||
|
@ -179,7 +179,7 @@ bool ControlHuePicker::ccTouchBegan(Touch* touch, Event* event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ControlHuePicker::ccTouchMoved(Touch* touch, Event* event)
|
void ControlHuePicker::onTouchMoved(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
// Get the touch location
|
// Get the touch location
|
||||||
Point touchLocation=getTouchLocation(touch);
|
Point touchLocation=getTouchLocation(touch);
|
||||||
|
|
|
@ -63,8 +63,8 @@ public:
|
||||||
virtual void setEnabled(bool enabled);
|
virtual void setEnabled(bool enabled);
|
||||||
|
|
||||||
// overrides
|
// overrides
|
||||||
virtual bool ccTouchBegan(Touch* touch, Event* pEvent) override;
|
virtual bool onTouchBegan(Touch* touch, Event* pEvent) override;
|
||||||
virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) override;
|
virtual void onTouchMoved(Touch *pTouch, Event *pEvent) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateSliderPosition(Point location);
|
void updateSliderPosition(Point location);
|
||||||
|
|
|
@ -177,7 +177,7 @@ bool ControlPotentiometer::isTouchInside(Touch * touch)
|
||||||
return distance < MIN(getContentSize().width / 2, getContentSize().height / 2);
|
return distance < MIN(getContentSize().width / 2, getContentSize().height / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ControlPotentiometer::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
bool ControlPotentiometer::onTouchBegan(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
if (!this->isTouchInside(pTouch) || !this->isEnabled() || !isVisible())
|
if (!this->isTouchInside(pTouch) || !this->isEnabled() || !isVisible())
|
||||||
{
|
{
|
||||||
|
@ -191,14 +191,14 @@ bool ControlPotentiometer::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlPotentiometer::ccTouchMoved(Touch *pTouch, Event *pEvent)
|
void ControlPotentiometer::onTouchMoved(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
Point location = this->getTouchLocation(pTouch);
|
Point location = this->getTouchLocation(pTouch);
|
||||||
|
|
||||||
this->potentiometerMoved(location);
|
this->potentiometerMoved(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlPotentiometer::ccTouchEnded(Touch *pTouch, Event *pEvent)
|
void ControlPotentiometer::onTouchEnded(Touch *pTouch, Event *pEvent)
|
||||||
{
|
{
|
||||||
this->potentiometerEnded(Point::ZERO);
|
this->potentiometerEnded(Point::ZERO);
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue