issue #4861, add CCEventFocus and CCEventListener

This commit is contained in:
andyque 2014-05-04 11:44:51 +08:00
parent b35ddfe5b5
commit 47acbc24e0
7 changed files with 217 additions and 0 deletions

View File

@ -1093,6 +1093,14 @@
2905FA8D18CF08D100240AA3 /* UIWidget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA1318CF08D100240AA3 /* UIWidget.cpp */; };
2905FA8E18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
296CAD221915EC8000C64FBF /* CCEventFocus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 296CAD201915EC8000C64FBF /* CCEventFocus.cpp */; };
296CAD231915EC8000C64FBF /* CCEventFocus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 296CAD201915EC8000C64FBF /* CCEventFocus.cpp */; };
296CAD241915EC8000C64FBF /* CCEventFocus.h in Headers */ = {isa = PBXBuildFile; fileRef = 296CAD211915EC8000C64FBF /* CCEventFocus.h */; };
296CAD251915EC8000C64FBF /* CCEventFocus.h in Headers */ = {isa = PBXBuildFile; fileRef = 296CAD211915EC8000C64FBF /* CCEventFocus.h */; };
296CAD281915EC9900C64FBF /* CCEventListenerFocus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 296CAD261915EC9900C64FBF /* CCEventListenerFocus.cpp */; };
296CAD291915EC9900C64FBF /* CCEventListenerFocus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 296CAD261915EC9900C64FBF /* CCEventListenerFocus.cpp */; };
296CAD2A1915EC9900C64FBF /* CCEventListenerFocus.h in Headers */ = {isa = PBXBuildFile; fileRef = 296CAD271915EC9900C64FBF /* CCEventListenerFocus.h */; };
296CAD2B1915EC9900C64FBF /* CCEventListenerFocus.h in Headers */ = {isa = PBXBuildFile; fileRef = 296CAD271915EC9900C64FBF /* CCEventListenerFocus.h */; };
2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; };
2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; };
2AC795DC1862870F005EC8E1 /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D51862867D005EC8E1 /* Event.cpp */; };
@ -2279,6 +2287,10 @@
2905FA1218CF08D100240AA3 /* UITextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UITextField.h; sourceTree = "<group>"; };
2905FA1318CF08D100240AA3 /* UIWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidget.cpp; sourceTree = "<group>"; };
2905FA1418CF08D100240AA3 /* UIWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidget.h; sourceTree = "<group>"; };
296CAD201915EC8000C64FBF /* CCEventFocus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventFocus.cpp; path = ../base/CCEventFocus.cpp; sourceTree = "<group>"; };
296CAD211915EC8000C64FBF /* CCEventFocus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCEventFocus.h; path = ../base/CCEventFocus.h; sourceTree = "<group>"; };
296CAD261915EC9900C64FBF /* CCEventListenerFocus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventListenerFocus.cpp; path = ../base/CCEventListenerFocus.cpp; sourceTree = "<group>"; };
296CAD271915EC9900C64FBF /* CCEventListenerFocus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCEventListenerFocus.h; path = ../base/CCEventListenerFocus.h; sourceTree = "<group>"; };
2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = "<group>"; };
2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; };
2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = "<group>"; };
@ -3098,6 +3110,10 @@
500DC92719106300007B91BF /* s3tc.h */,
500DC92819106300007B91BF /* ZipUtils.cpp */,
500DC92919106300007B91BF /* ZipUtils.h */,
296CAD201915EC8000C64FBF /* CCEventFocus.cpp */,
296CAD211915EC8000C64FBF /* CCEventFocus.h */,
296CAD261915EC9900C64FBF /* CCEventListenerFocus.cpp */,
296CAD271915EC9900C64FBF /* CCEventListenerFocus.h */,
);
name = base;
path = ../cocos/2d;
@ -4928,6 +4944,7 @@
500DC94E19106300007B91BF /* CCEvent.h in Headers */,
1A57007F180BC5A10088DEC7 /* CCActionInterval.h in Headers */,
1A01C69A18F57BE800EFE3A6 /* CCSet.h in Headers */,
296CAD2A1915EC9900C64FBF /* CCEventListenerFocus.h in Headers */,
A023FA36185198C800E10CD1 /* ccShader_PositionTextureColor_noMVP_vert.h in Headers */,
1A570083180BC5A10088DEC7 /* CCActionManager.h in Headers */,
1A570087180BC5A10088DEC7 /* CCActionPageTurn3D.h in Headers */,
@ -5078,6 +5095,7 @@
1A570356180BD0B00088DEC7 /* ioapi.h in Headers */,
500DC99619106300007B91BF /* CCScheduler.h in Headers */,
1A57035A180BD0B00088DEC7 /* unzip.h in Headers */,
296CAD241915EC8000C64FBF /* CCEventFocus.h in Headers */,
1A570535180BD9500088DEC7 /* CCGLProgram.h in Headers */,
1AA95FE018EBB8EF00AE7485 /* ccShader_Label_frag_df.h in Headers */,
500DC98819106300007B91BF /* CCNS.h in Headers */,
@ -5463,6 +5481,7 @@
2905FA7B18CF08D100240AA3 /* UISlider.h in Headers */,
1AA95FE318EBB8EF00AE7485 /* ccShader_Label_frag_normal.h in Headers */,
1A5701CE180BCB5A0088DEC7 /* CCLabelTTF.h in Headers */,
296CAD251915EC8000C64FBF /* CCEventFocus.h in Headers */,
50FCEBCA18C72017004AD434 /* WidgetReader.h in Headers */,
1A5701E1180BCB8C0088DEC7 /* CCLayer.h in Headers */,
1A5701E5180BCB8C0088DEC7 /* CCScene.h in Headers */,
@ -5647,6 +5666,7 @@
1A9DCA3C180E6955007A3AD4 /* firePngData.h in Headers */,
1AA95FDF18EBB8EF00AE7485 /* ccShader_Label_frag_df_glow.h in Headers */,
1A01C69F18F57BE800EFE3A6 /* CCString.h in Headers */,
296CAD2B1915EC9900C64FBF /* CCEventListenerFocus.h in Headers */,
1A01C69118F57BE800EFE3A6 /* CCDictionary.h in Headers */,
500DC99B19106300007B91BF /* ccTypes.h in Headers */,
1A8C598E180E930E00EF57C3 /* CCActionFrame.h in Headers */,
@ -6110,6 +6130,7 @@
1A570081180BC5A10088DEC7 /* CCActionManager.cpp in Sources */,
1A570085180BC5A10088DEC7 /* CCActionPageTurn3D.cpp in Sources */,
1A570089180BC5A10088DEC7 /* CCActionProgressTimer.cpp in Sources */,
296CAD281915EC9900C64FBF /* CCEventListenerFocus.cpp in Sources */,
1A57008D180BC5A10088DEC7 /* CCActionTiledGrid.cpp in Sources */,
1A570091180BC5A10088DEC7 /* CCActionTween.cpp in Sources */,
B2AF2F9918EBAEAE00C5807C /* Matrix.cpp in Sources */,
@ -6278,6 +6299,7 @@
1AD71ECD180E26E600808F54 /* Skeleton.cpp in Sources */,
1AD71ED1180E26E600808F54 /* SkeletonData.cpp in Sources */,
1AD71ED5180E26E600808F54 /* SkeletonJson.cpp in Sources */,
296CAD221915EC8000C64FBF /* CCEventFocus.cpp in Sources */,
1AD71ED9180E26E600808F54 /* Skin.cpp in Sources */,
1AD71EDD180E26E600808F54 /* Slot.cpp in Sources */,
1AD71EE1180E26E600808F54 /* SlotData.cpp in Sources */,
@ -6484,6 +6506,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
296CAD291915EC9900C64FBF /* CCEventListenerFocus.cpp in Sources */,
1A01C69918F57BE800EFE3A6 /* CCSet.cpp in Sources */,
1A01C69D18F57BE800EFE3A6 /* CCString.cpp in Sources */,
2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */,
@ -6631,6 +6654,7 @@
1A570306180BCED90088DEC7 /* ccUtils.cpp in Sources */,
1A57030D180BCF190088DEC7 /* CCComponent.cpp in Sources */,
1A570311180BCF190088DEC7 /* CCComponentContainer.cpp in Sources */,
296CAD231915EC8000C64FBF /* CCEventFocus.cpp in Sources */,
1A57031A180BCF430088DEC7 /* ccCArray.cpp in Sources */,
B375107C1823ACA100B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp in Sources */,
50FCEBB418C72017004AD434 /* SliderReader.cpp in Sources */,

View File

@ -48,6 +48,7 @@ public:
KEYBOARD,
ACCELERATION,
MOUSE,
FOCUS,
CUSTOM
};

View File

@ -0,0 +1,25 @@
//
// CCEventFocus.cpp
// cocos2d_libs
//
// Created by guanghui on 5/4/14.
//
//
#include "CCEventFocus.h"
NS_CC_BEGIN
EventFocus::EventFocus(ui::Widget *widgetLoseFocus, ui::Widget* widgetGetFocus)
:Event(Type::FOCUS),
_widgetLoseFocus(widgetLoseFocus),
_widgetGetFocus(widgetGetFocus)
{
}
NS_CC_END

36
cocos/base/CCEventFocus.h Normal file
View File

@ -0,0 +1,36 @@
//
// CCEventFocus.h
// cocos2d_libs
//
// Created by guanghui on 5/4/14.
//
//
#ifndef __cocos2d_libs__CCEventFocus__
#define __cocos2d_libs__CCEventFocus__
#include "CCEvent.h"
NS_CC_BEGIN
namespace ui {
class Widget;
}
class EventFocus : public Event
{
public:
EventFocus(ui::Widget* widgetLoseFocus, ui::Widget* widgetGetFocus);
private:
ui::Widget *_widgetGetFocus;
ui::Widget *_widgetLoseFocus;
friend class EventListenerFocus;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCEventFocus__) */

View File

@ -54,6 +54,7 @@ public:
KEYBOARD,
MOUSE,
ACCELERATION,
FOCUS,
CUSTOM
};

View File

@ -0,0 +1,81 @@
//
// CCEventListenerFocus.cpp
// cocos2d_libs
//
// Created by guanghui on 5/4/14.
//
//
#include "CCEventListenerFocus.h"
#include "CCEventFocus.h"
#include "ccMacros.h"
NS_CC_BEGIN
const std::string EventListenerFocus::LISTENER_ID = "__cc_focus_event";
EventListenerFocus::EventListenerFocus()
:onFocusChanged(nullptr)
{
}
EventListenerFocus::~EventListenerFocus()
{
CCLOGINFO("In the destructor of EventListenerFocus, %p", this);
}
EventListenerFocus* EventListenerFocus::create()
{
EventListenerFocus* ret = new EventListenerFocus;
if (ret && ret->init()) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
EventListenerFocus* EventListenerFocus::clone()
{
EventListenerFocus* ret = new EventListenerFocus;
if (ret && ret->init()) {
ret->autorelease();
ret->onFocusChanged = onFocusChanged;
}
else
{
CC_SAFE_DELETE(ret);
}
return ret;
}
bool EventListenerFocus::init()
{
auto listener = [this](Event* event){
auto focusEvent = static_cast<EventFocus*>(event);
onFocusChanged(focusEvent->_widgetLoseFocus, focusEvent->_widgetGetFocus);
};
if (EventListener::init(Type::FOCUS, LISTENER_ID, listener)) {
return true;
}
return false;
}
bool EventListenerFocus::checkAvailable()
{
if (onFocusChanged == nullptr)
{
CCASSERT(false, "Invalid EventListenerFocus!");
return false;
}
return true;
}
NS_CC_END

View File

@ -0,0 +1,49 @@
//
// CCEventListenerFocus.h
// cocos2d_libs
//
// Created by guanghui on 5/4/14.
//
//
#ifndef __cocos2d_libs__CCEventListenerFocus__
#define __cocos2d_libs__CCEventListenerFocus__
#include "CCEventListener.h"
NS_CC_BEGIN
namespace ui {
class Widget;
}
class EventListenerFocus : public EventListener
{
public:
static const std::string LISTENER_ID;
static EventListenerFocus* create();
virtual ~EventListenerFocus();
/// Overrides
virtual EventListenerFocus* clone() override;
virtual bool checkAvailable() override;
//
public:
std::function<void(ui::Widget*, ui::Widget*)> onFocusChanged;
private:
EventListenerFocus();
bool init();
friend class EventDispatcher;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCEventListenerFocus__) */