-
-
Save sinfere/d522542d285ee2e6ccb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MyWidget.h" | |
#include "ui/UIText.h" | |
USING_NS_CC; | |
using namespace std; | |
using namespace cocos2d::ui; | |
MyWidget::MyWidget(){} | |
Widget::ccWidgetTouchCallback MyWidget::onLocateTouchCallback(const string &callBackName) | |
{ | |
if (callBackName == "onTouch") | |
{ | |
return CC_CALLBACK_2(MyWidget::onTouch, this); | |
} | |
return nullptr; | |
} | |
Widget::ccWidgetClickCallback MyWidget::onLocateClickCallback(const string &callBackName) | |
{ | |
if (callBackName == "onClick") | |
{ | |
return CC_CALLBACK_1(MyWidget::onClick, this); | |
} | |
return nullptr; | |
} | |
Widget::ccWidgetEventCallback MyWidget::onLocateEventCallback(const string &callBackName) | |
{ | |
if (callBackName == "onEvent") | |
{ | |
return CC_CALLBACK_2(MyWidget::onEvent, this); | |
} | |
return nullptr; | |
} | |
void MyWidget::onTouch(cocos2d::Ref* object, cocos2d::ui::Widget::TouchEventType type) | |
{ | |
CCLOG("onTouch"); | |
} | |
void MyWidget::onClick(cocos2d::Ref* sender) | |
{ | |
CCLOG("onClick"); | |
} | |
void MyWidget::onEvent(cocos2d::Ref* sender, int eventType) | |
{ | |
CCLOG("onEvent"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cocos2d.h" | |
#include "cocostudio/CocoStudio.h" | |
#include "cocostudio/WidgetCallBackHandlerProtocol.h" | |
class MyWidget: public cocos2d::Node, public cocostudio::WidgetCallBackHandlerProtocol | |
{ | |
public: | |
CREATE_FUNC(MyWidget) | |
MyWidget(); | |
virtual cocos2d::ui::Widget::ccWidgetTouchCallback onLocateTouchCallback(const std::string &callBackName); | |
virtual cocos2d::ui::Widget::ccWidgetClickCallback onLocateClickCallback(const std::string &callBackName); | |
virtual cocos2d::ui::Widget::ccWidgetEventCallback onLocateEventCallback(const std::string &callBackName); | |
void onTouch(cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type); | |
void onClick(cocos2d::Ref* sender); | |
void onEvent(cocos2d::Ref* sender, int eventType); | |
private: | |
std::vector<std::string> _touchTypes; | |
std::string _click; | |
std::vector<std::string> _eventTypes; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MyWidgetReader.h" | |
#include "MyWidget.h" | |
USING_NS_CC; | |
static MyWidgetReader* _instanceMyWidgetReader = nullptr; | |
MyWidgetReader* MyWidgetReader::getInstance() | |
{ | |
if (!_instanceMyWidgetReader) | |
{ | |
_instanceMyWidgetReader = new MyWidgetReader(); | |
} | |
return _instanceMyWidgetReader; | |
} | |
void MyWidgetReader::purge() | |
{ | |
CC_SAFE_DELETE(_instanceMyWidgetReader); | |
} | |
Node* MyWidgetReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions) | |
{ | |
MyWidget* node = MyWidget::create(); | |
setPropsWithFlatBuffers(node, nodeOptions); | |
return node; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cocos2d.h" | |
#include "cocostudio/CocosStudioExport.h" | |
#include "cocostudio/WidgetReader/NodeReader/NodeReader.h" | |
class MyWidgetReader : public cocostudio::NodeReader | |
{ | |
public: | |
MyWidgetReader() {}; | |
~MyWidgetReader() {}; | |
static MyWidgetReader* getInstance(); | |
static void purge(); | |
cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CSLoader* instance = CSLoader::getInstance(); | |
instance->registReaderObject("MyWidgetReader ",(ObjectFactory::Instance)MyWidgetReader::getInstance); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment