mirror of https://github.com/axmolengine/axmol.git
Merge pull request #2704 from simpliplant/develop
Hardware keyboard support
This commit is contained in:
commit
9404f3e0ce
|
@ -80,6 +80,7 @@ Device-Release/
|
||||||
|
|
||||||
# Ignore vim swaps
|
# Ignore vim swaps
|
||||||
*.swp
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
# Ignore config files in javascript bindings generator
|
# Ignore config files in javascript bindings generator
|
||||||
tools/tojs/user.cfg
|
tools/tojs/user.cfg
|
||||||
|
|
|
@ -64,7 +64,9 @@ THE SOFTWARE.
|
||||||
#include "platform/CCImage.h"
|
#include "platform/CCImage.h"
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
#include "CCConfiguration.h"
|
#include "CCConfiguration.h"
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,6 +157,11 @@ bool CCDirector::init(void)
|
||||||
m_pTouchDispatcher = new CCTouchDispatcher();
|
m_pTouchDispatcher = new CCTouchDispatcher();
|
||||||
m_pTouchDispatcher->init();
|
m_pTouchDispatcher->init();
|
||||||
|
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
// KeyboardDispatcher
|
||||||
|
m_pKeyboardDispatcher = new CCKeyboardDispatcher();
|
||||||
|
#endif
|
||||||
|
|
||||||
// KeypadDispatcher
|
// KeypadDispatcher
|
||||||
m_pKeypadDispatcher = new CCKeypadDispatcher();
|
m_pKeypadDispatcher = new CCKeypadDispatcher();
|
||||||
|
|
||||||
|
@ -181,6 +188,9 @@ CCDirector::~CCDirector(void)
|
||||||
CC_SAFE_RELEASE(m_pScheduler);
|
CC_SAFE_RELEASE(m_pScheduler);
|
||||||
CC_SAFE_RELEASE(m_pActionManager);
|
CC_SAFE_RELEASE(m_pActionManager);
|
||||||
CC_SAFE_RELEASE(m_pTouchDispatcher);
|
CC_SAFE_RELEASE(m_pTouchDispatcher);
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
CC_SAFE_RELEASE(m_pKeyboardDispatcher);
|
||||||
|
#endif
|
||||||
CC_SAFE_RELEASE(m_pKeypadDispatcher);
|
CC_SAFE_RELEASE(m_pKeypadDispatcher);
|
||||||
CC_SAFE_DELETE(m_pAccelerometer);
|
CC_SAFE_DELETE(m_pAccelerometer);
|
||||||
|
|
||||||
|
@ -961,6 +971,20 @@ CCTouchDispatcher* CCDirector::getTouchDispatcher()
|
||||||
return m_pTouchDispatcher;
|
return m_pTouchDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
void CCDirector::setKeyboardDispatcher(CCKeyboardDispatcher* pKeyboardDispatcher)
|
||||||
|
{
|
||||||
|
CC_SAFE_RETAIN(pKeyboardDispatcher);
|
||||||
|
CC_SAFE_RELEASE(m_pKeyboardDispatcher);
|
||||||
|
m_pKeyboardDispatcher = pKeyboardDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCKeyboardDispatcher* CCDirector::getKeyboardDispatcher()
|
||||||
|
{
|
||||||
|
return m_pKeyboardDispatcher;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void CCDirector::setKeypadDispatcher(CCKeypadDispatcher* pKeypadDispatcher)
|
void CCDirector::setKeypadDispatcher(CCKeypadDispatcher* pKeypadDispatcher)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(pKeypadDispatcher);
|
CC_SAFE_RETAIN(pKeypadDispatcher);
|
||||||
|
|
|
@ -71,6 +71,9 @@ class CCNode;
|
||||||
class CCScheduler;
|
class CCScheduler;
|
||||||
class CCActionManager;
|
class CCActionManager;
|
||||||
class CCTouchDispatcher;
|
class CCTouchDispatcher;
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
class CCKeyboardDispatcher;
|
||||||
|
#endif
|
||||||
class CCKeypadDispatcher;
|
class CCKeypadDispatcher;
|
||||||
class CCAccelerometer;
|
class CCAccelerometer;
|
||||||
|
|
||||||
|
@ -322,6 +325,12 @@ public:
|
||||||
*/
|
*/
|
||||||
CC_PROPERTY(CCTouchDispatcher*, m_pTouchDispatcher, TouchDispatcher);
|
CC_PROPERTY(CCTouchDispatcher*, m_pTouchDispatcher, TouchDispatcher);
|
||||||
|
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
/** CCKeyboardDispatcher associated with this director
|
||||||
|
@since v?.?
|
||||||
|
*/
|
||||||
|
CC_PROPERTY(CCKeyboardDispatcher*, m_pKeyboardDispatcher, KeyboardDispatcher);
|
||||||
|
#endif
|
||||||
/** CCKeypadDispatcher associated with this director
|
/** CCKeypadDispatcher associated with this director
|
||||||
@since v2.0
|
@since v2.0
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/****************************************************************************
|
||||||
|
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
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// CCKeyboardDispatcher
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
CCKeyboardDispatcher::CCKeyboardDispatcher()
|
||||||
|
: m_keyPressDelegate(NULL)
|
||||||
|
, m_keyReleaseDelegate(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CCKeyboardDispatcher::~CCKeyboardDispatcher()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCKeyboardDispatcher::setKeyPressDelegate(CCKeyboardDelegate delegate)
|
||||||
|
{
|
||||||
|
m_keyPressDelegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCKeyboardDispatcher::setKeyReleaseDelegate(CCKeyboardDelegate delegate)
|
||||||
|
{
|
||||||
|
m_keyReleaseDelegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCKeyboardDispatcher::dispatchKeyboardEvent(int keyCode, bool pressed)
|
||||||
|
{
|
||||||
|
if (m_keyPressDelegate != NULL && pressed)
|
||||||
|
{
|
||||||
|
m_keyPressDelegate(keyCode);
|
||||||
|
}
|
||||||
|
else if (m_keyReleaseDelegate != NULL)
|
||||||
|
{
|
||||||
|
m_keyReleaseDelegate(keyCode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -0,0 +1,76 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __CCKEYBOARD_DISPATCHER_H__
|
||||||
|
#define __CCKEYBOARD_DISPATCHER_H__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
|
#include "cocoa/CCArray.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup input
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef std::function<void(int)> CCKeyboardDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@class CCKeyboardDispatcher
|
||||||
|
@brief Dispatch the keypad message from the phone
|
||||||
|
*/
|
||||||
|
class CC_DLL CCKeyboardDispatcher : public CCObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCKeyboardDispatcher();
|
||||||
|
~CCKeyboardDispatcher();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief set delagate to key press event
|
||||||
|
*/
|
||||||
|
void setKeyPressDelegate(CCKeyboardDelegate delegate);
|
||||||
|
/**
|
||||||
|
@brief set delagate to key release event
|
||||||
|
*/
|
||||||
|
void setKeyReleaseDelegate(CCKeyboardDelegate delegate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief dispatch the key stroke event
|
||||||
|
*/
|
||||||
|
bool dispatchKeyboardEvent(int keyCode, bool pressed);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
CCKeyboardDelegate m_keyPressDelegate;
|
||||||
|
CCKeyboardDelegate m_keyReleaseDelegate;
|
||||||
|
};
|
||||||
|
|
||||||
|
// end of input group
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif //__CCKEYBOARD_DISPATCHER_H__
|
|
@ -38,6 +38,9 @@ THE SOFTWARE.
|
||||||
#include "support/TransformUtils.h"
|
#include "support/TransformUtils.h"
|
||||||
// extern
|
// extern
|
||||||
#include "kazmath/GL/matrix.h"
|
#include "kazmath/GL/matrix.h"
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -45,6 +48,9 @@ NS_CC_BEGIN
|
||||||
CCLayer::CCLayer()
|
CCLayer::CCLayer()
|
||||||
: m_bTouchEnabled(false)
|
: m_bTouchEnabled(false)
|
||||||
, m_bAccelerometerEnabled(false)
|
, m_bAccelerometerEnabled(false)
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
, m_bKeyboardEnabled(false)
|
||||||
|
#endif
|
||||||
, m_bKeypadEnabled(false)
|
, m_bKeypadEnabled(false)
|
||||||
, m_pScriptTouchHandlerEntry(NULL)
|
, m_pScriptTouchHandlerEntry(NULL)
|
||||||
, m_pScriptKeypadHandlerEntry(NULL)
|
, m_pScriptKeypadHandlerEntry(NULL)
|
||||||
|
@ -273,6 +279,34 @@ void CCLayer::unregisterScriptAccelerateHandler(void)
|
||||||
CC_SAFE_RELEASE_NULL(m_pScriptAccelerateHandlerEntry);
|
CC_SAFE_RELEASE_NULL(m_pScriptAccelerateHandlerEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
/// isKeyboardEnabled getter
|
||||||
|
bool CCLayer::isKeyboardEnabled()
|
||||||
|
{
|
||||||
|
return m_bKeyboardEnabled;
|
||||||
|
}
|
||||||
|
/// isKeyboardEnabled setter
|
||||||
|
void CCLayer::setKeyboardEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
if (enabled != m_bKeyboardEnabled)
|
||||||
|
{
|
||||||
|
m_bKeyboardEnabled = enabled;
|
||||||
|
|
||||||
|
CCDirector* pDirector = CCDirector::sharedDirector();
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
pDirector->getKeyboardDispatcher()->setKeyPressDelegate(std::bind(&CCLayer::keyPressed, this, std::placeholders::_1));
|
||||||
|
pDirector->getKeyboardDispatcher()->setKeyReleaseDelegate(std::bind(&CCLayer::keyReleased, this, std::placeholders::_1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pDirector->getKeyboardDispatcher()->setKeyPressDelegate(NULL);
|
||||||
|
pDirector->getKeyboardDispatcher()->setKeyReleaseDelegate(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// isKeypadEnabled getter
|
/// isKeypadEnabled getter
|
||||||
bool CCLayer::isKeypadEnabled()
|
bool CCLayer::isKeypadEnabled()
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,10 +130,16 @@ public:
|
||||||
virtual void setAccelerometerEnabled(bool value);
|
virtual void setAccelerometerEnabled(bool value);
|
||||||
virtual void setAccelerometerInterval(double interval);
|
virtual void setAccelerometerInterval(double interval);
|
||||||
|
|
||||||
/** whether or not it will receive keypad events
|
/** whether or not it will receive keyboard or keypad events
|
||||||
You can enable / disable accelerometer events with this property.
|
You can enable / disable accelerometer events with this property.
|
||||||
it's new in cocos2d-x
|
it's new in cocos2d-x
|
||||||
*/
|
*/
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
virtual bool isKeyboardEnabled();
|
||||||
|
virtual void setKeyboardEnabled(bool value);
|
||||||
|
virtual void keyPressed(int keyCode) {};
|
||||||
|
virtual void keyReleased(int keyCode) {};
|
||||||
|
#endif
|
||||||
virtual bool isKeypadEnabled();
|
virtual bool isKeypadEnabled();
|
||||||
virtual void setKeypadEnabled(bool value);
|
virtual void setKeypadEnabled(bool value);
|
||||||
|
|
||||||
|
@ -151,6 +157,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
bool m_bTouchEnabled;
|
bool m_bTouchEnabled;
|
||||||
bool m_bAccelerometerEnabled;
|
bool m_bAccelerometerEnabled;
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
bool m_bKeyboardEnabled;
|
||||||
|
#endif
|
||||||
bool m_bKeypadEnabled;
|
bool m_bKeypadEnabled;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
#include "touch_dispatcher/CCTouch.h"
|
#include "touch_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"
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT = NULL;
|
PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT = NULL;
|
||||||
PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT = NULL;
|
PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT = NULL;
|
||||||
|
@ -154,6 +157,23 @@ int closeEventHandle() {
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
void GLFWCALL keyboardEventHandle(int keyCode, int action)
|
||||||
|
{
|
||||||
|
CCKeyboardDispatcher *kbDisp = CCDirector::sharedDirector()->getKeyboardDispatcher();
|
||||||
|
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case GLFW_PRESS:
|
||||||
|
kbDisp->dispatchKeyboardEvent(keyCode, true);
|
||||||
|
break;
|
||||||
|
case GLFW_RELEASE:
|
||||||
|
kbDisp->dispatchKeyboardEvent(keyCode, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void CCEGLView::setFrameSize(float width, float height)
|
void CCEGLView::setFrameSize(float width, float height)
|
||||||
{
|
{
|
||||||
bool eResult = false;
|
bool eResult = false;
|
||||||
|
@ -228,6 +248,10 @@ void CCEGLView::setFrameSize(float width, float height)
|
||||||
glfwSetMouseButtonCallback(mouseButtonEventHandle);
|
glfwSetMouseButtonCallback(mouseButtonEventHandle);
|
||||||
//register the glfw mouse pos event
|
//register the glfw mouse pos event
|
||||||
glfwSetMousePosCallback(mousePosEventHandle);
|
glfwSetMousePosCallback(mousePosEventHandle);
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
//register the glfw keyboard event
|
||||||
|
glfwSetKeyCallback(keyboardEventHandle);
|
||||||
|
#endif
|
||||||
|
|
||||||
glfwSetWindowCloseCallback(closeEventHandle);
|
glfwSetWindowCloseCallback(closeEventHandle);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
#import "ccConfig.h"
|
#import "ccConfig.h"
|
||||||
#include "support/data_support/utlist.h"
|
#include "support/data_support/utlist.h"
|
||||||
|
|
||||||
|
#include "CCDirector.h"
|
||||||
|
#include "keyboard_dispatcher/CCKeyboardDispatcher.h"
|
||||||
|
|
||||||
//NS_CC_BEGIN;
|
//NS_CC_BEGIN;
|
||||||
static CCEventDispatcher *sharedDispatcher = nil;
|
static CCEventDispatcher *sharedDispatcher = nil;
|
||||||
|
|
||||||
|
@ -503,6 +506,8 @@ static int eventQueueCount;
|
||||||
if( dispatchEvents_ ) {
|
if( dispatchEvents_ ) {
|
||||||
tListEntry *entry, *tmp;
|
tListEntry *entry, *tmp;
|
||||||
|
|
||||||
|
cocos2d::CCKeyboardDispatcher *kbDisp = cocos2d::CCDirector::sharedDirector()->getKeyboardDispatcher();
|
||||||
|
kbDisp->dispatchKeyboardEvent(event.keyCode, true);
|
||||||
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
||||||
if ( entry->flags & kCCImplementsKeyDown ) {
|
if ( entry->flags & kCCImplementsKeyDown ) {
|
||||||
void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event];
|
void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event];
|
||||||
|
@ -518,6 +523,8 @@ static int eventQueueCount;
|
||||||
if( dispatchEvents_ ) {
|
if( dispatchEvents_ ) {
|
||||||
tListEntry *entry, *tmp;
|
tListEntry *entry, *tmp;
|
||||||
|
|
||||||
|
cocos2d::CCKeyboardDispatcher *kbDisp = cocos2d::CCDirector::sharedDirector()->getKeyboardDispatcher();
|
||||||
|
kbDisp->dispatchKeyboardEvent(event.keyCode, true);
|
||||||
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
||||||
if ( entry->flags & kCCImplementsKeyUp ) {
|
if ( entry->flags & kCCImplementsKeyUp ) {
|
||||||
void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event];
|
void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event];
|
||||||
|
|
|
@ -42,6 +42,7 @@ SOURCES = ../actions/CCAction.cpp \
|
||||||
../effects/CCGrid.cpp \
|
../effects/CCGrid.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDelegate.cpp \
|
../keypad_dispatcher/CCKeypadDelegate.cpp \
|
||||||
../keypad_dispatcher/CCKeypadDispatcher.cpp \
|
../keypad_dispatcher/CCKeypadDispatcher.cpp \
|
||||||
|
../keyboard_dispatcher/CCKeyboardDispatcher.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 \
|
||||||
|
|
|
@ -11,7 +11,7 @@ CCFLAGS += -MMD -Werror -Wno-deprecated-declarations -fPIC
|
||||||
CXXFLAGS += -MMD -Werror -Wno-deprecated-declarations -fPIC -std=gnu++0x
|
CXXFLAGS += -MMD -Werror -Wno-deprecated-declarations -fPIC -std=gnu++0x
|
||||||
ARFLAGS = cr
|
ARFLAGS = cr
|
||||||
|
|
||||||
DEFINES += -DLINUX
|
DEFINES += -DLINUX -DKEYBOARD_SUPPORT
|
||||||
|
|
||||||
ifdef USE_BOX2D
|
ifdef USE_BOX2D
|
||||||
DEFINES += -DCC_ENABLE_BOX2D_INTEGRATION=1
|
DEFINES += -DCC_ENABLE_BOX2D_INTEGRATION=1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
5b8ea64c349dcc515312773df1d8d0d5d20abfbe
|
4f421e1ed8425f53876db5971e3deac238edb4d3
|
|
@ -48,6 +48,10 @@
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
#ifndef OF
|
||||||
|
#define OF _Z_OF
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USE_FILE32API)
|
#if defined(USE_FILE32API)
|
||||||
#define fopen64 fopen
|
#define fopen64 fopen
|
||||||
#define ftello64 ftell
|
#define ftello64 ftell
|
||||||
|
|
|
@ -60,7 +60,7 @@ char* _readFile (const char* path, int* length) {
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
|
|
||||||
data = MALLOC(char, *length);
|
data = MALLOC(char, *length);
|
||||||
fread(data, 1, *length, file);
|
size_t ret = fread(data, 1, *length, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -180,8 +180,10 @@ void TestSearchPath::onEnter()
|
||||||
FILE* fp = fopen(fileName.c_str(), "wb");
|
FILE* fp = fopen(fileName.c_str(), "wb");
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
fwrite(szBuf, 1, strlen(szBuf), fp);
|
size_t ret = fwrite(szBuf, 1, strlen(szBuf), fp);
|
||||||
|
CCAssert(ret == 0, "fwrite function returned nonzero value");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
if (ret == 0)
|
||||||
CCLog("Writing file to writable path succeed.");
|
CCLog("Writing file to writable path succeed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include "KeyboardTest.h"
|
||||||
|
|
||||||
|
KeyboardTest::KeyboardTest()
|
||||||
|
{
|
||||||
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
CCLabelTTF* label = CCLabelTTF::create("Keyboard Test", "Arial", 28);
|
||||||
|
addChild(label, 0);
|
||||||
|
label->setPosition( ccp(s.width/2, s.height-50) );
|
||||||
|
|
||||||
|
setKeyboardEnabled(true);
|
||||||
|
|
||||||
|
// create a label to display the tip string
|
||||||
|
m_pLabel = CCLabelTTF::create("Please press any key and see console log...", "Arial", 22);
|
||||||
|
m_pLabel->setPosition(ccp(s.width / 2, s.height / 2));
|
||||||
|
addChild(m_pLabel, 0);
|
||||||
|
|
||||||
|
m_pLabel->retain();
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyboardTest::~KeyboardTest()
|
||||||
|
{
|
||||||
|
m_pLabel->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardTest::keyPressed(int keyCode)
|
||||||
|
{
|
||||||
|
CCLog("Key with keycode %d pressed", keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardTest::keyReleased(int keyCode)
|
||||||
|
{
|
||||||
|
CCLog("Key with keycode %d released", keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardTestScene::runThisTest()
|
||||||
|
{
|
||||||
|
CCLayer* pLayer = new KeyboardTest();
|
||||||
|
addChild(pLayer);
|
||||||
|
|
||||||
|
CCDirector::sharedDirector()->replaceScene(this);
|
||||||
|
pLayer->release();
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef _KEYBOARD_TEST_H_
|
||||||
|
#define _KEYBOARD_TEST_H_
|
||||||
|
|
||||||
|
#include "cocos2d.h"
|
||||||
|
#include "../testBasic.h"
|
||||||
|
|
||||||
|
class KeyboardTest : public CCLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KeyboardTest();
|
||||||
|
~KeyboardTest();
|
||||||
|
|
||||||
|
virtual void keyPressed(int keyCode);
|
||||||
|
virtual void keyReleased(int keyCode);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CCLabelTTF* m_pLabel;
|
||||||
|
};
|
||||||
|
|
||||||
|
class KeyboardTestScene : public TestScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void runThisTest();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -47,6 +47,9 @@ struct {
|
||||||
{ "FileUtilsTest", []() { return new FileUtilsTestScene(); } },
|
{ "FileUtilsTest", []() { return new FileUtilsTestScene(); } },
|
||||||
{ "FontTest", []() { return new FontTestScene(); } },
|
{ "FontTest", []() { return new FontTestScene(); } },
|
||||||
{ "IntervalTest", [](){return new IntervalTestScene(); } },
|
{ "IntervalTest", [](){return new IntervalTestScene(); } },
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
{ "KeyboardTest", []() { return new KeyboardTestScene(); } },
|
||||||
|
#endif
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
|
||||||
{ "KeypadTest", []() { return new KeypadTestScene(); } },
|
{ "KeypadTest", []() { return new KeypadTestScene(); } },
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#include "EffectsAdvancedTest/EffectsAdvancedTest.h"
|
#include "EffectsAdvancedTest/EffectsAdvancedTest.h"
|
||||||
#include "AccelerometerTest/AccelerometerTest.h"
|
#include "AccelerometerTest/AccelerometerTest.h"
|
||||||
#include "KeypadTest/KeypadTest.h"
|
#include "KeypadTest/KeypadTest.h"
|
||||||
|
#ifdef KEYBOARD_SUPPORT
|
||||||
|
#include "KeyboardTest/KeyboardTest.h"
|
||||||
|
#endif
|
||||||
#include "PerformanceTest/PerformanceTest.h"
|
#include "PerformanceTest/PerformanceTest.h"
|
||||||
#include "ZwoptexTest/ZwoptexTest.h"
|
#include "ZwoptexTest/ZwoptexTest.h"
|
||||||
#include "CocosDenshionTest/CocosDenshionTest.h"
|
#include "CocosDenshionTest/CocosDenshionTest.h"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
EXECUTABLE = TestCpp
|
EXECUTABLE = TestCpp
|
||||||
|
|
||||||
|
DEFINES += -DKEYBOARD_SUPPORT
|
||||||
|
|
||||||
SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \
|
SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \
|
||||||
../Classes/ActionManagerTest/ActionManagerTest.cpp \
|
../Classes/ActionManagerTest/ActionManagerTest.cpp \
|
||||||
../Classes/ActionsEaseTest/ActionsEaseTest.cpp \
|
../Classes/ActionsEaseTest/ActionsEaseTest.cpp \
|
||||||
|
@ -52,6 +54,7 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \
|
||||||
../Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \
|
../Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \
|
||||||
../Classes/FontTest/FontTest.cpp \
|
../Classes/FontTest/FontTest.cpp \
|
||||||
../Classes/IntervalTest/IntervalTest.cpp \
|
../Classes/IntervalTest/IntervalTest.cpp \
|
||||||
|
../Classes/KeyboardTest/KeyboardTest.cpp \
|
||||||
../Classes/KeypadTest/KeypadTest.cpp \
|
../Classes/KeypadTest/KeypadTest.cpp \
|
||||||
../Classes/LabelTest/LabelTest.cpp \
|
../Classes/LabelTest/LabelTest.cpp \
|
||||||
../Classes/LayerTest/LayerTest.cpp \
|
../Classes/LayerTest/LayerTest.cpp \
|
||||||
|
|
Loading…
Reference in New Issue