当前位置: 首页>>代码示例>>C++>>正文


C++ EventDispatcher类代码示例

本文整理汇总了C++中EventDispatcher的典型用法代码示例。如果您正苦于以下问题:C++ EventDispatcher类的具体用法?C++ EventDispatcher怎么用?C++ EventDispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EventDispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: toucheventselector

bool FriendLayer::init()
{
    if ( !Layer::init() )
    {
        return false;
        
    }
    
    auto friendLayer=CSLoader::createNode("FriendLayer.csb");
    this->addChild(friendLayer);
    
    Button * closeButton = static_cast<Button*>(friendLayer->getChildByName("CloseButton"));
    
    Button * okButton = static_cast<Button*>(friendLayer->getChildByName("Button_OK"));
    
     fname = static_cast<TextField*>(friendLayer->getChildByName("TextField_Fname"));
    fshow = static_cast<Text*>(friendLayer->getChildByName("Text_show"));
    
    closeButton->addTouchEventListener(this, toucheventselector(FriendLayer::closeEvent));
    okButton->addTouchEventListener(this, toucheventselector(FriendLayer::okEvent));
    
    EventDispatcher* eventDispatcher = Director::getInstance()->getEventDispatcher();
    
    EventListenerTouchOneByOne* listener= EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    
    listener->onTouchBegan = [](Touch* touch, Event* event){return true;};
    listener->onTouchMoved = [](Touch* touch, Event* event){};
    listener->onTouchEnded = [](Touch* touch, Event* event){};
    listener->onTouchCancelled = [](Touch* touch , Event* event){};
    eventDispatcher->addEventListenerWithSceneGraphPriority(listener, friendLayer);   //代码为了设置模态窗口

    return true;
}
开发者ID:Sunjiawei58,项目名称:NEUPlanningIOS,代码行数:34,代码来源:FriendLayer.cpp

示例2: shiftOver

void MouseController::shiftOver(View * n)
{
    RefPtr<View> target;
    target.reset(n);
    if (over_ != target)
    {
        EventDispatcher dispatcher;
        EventDispatcher::Path old_path;
        EventDispatcher::GetPath(over_.get(), old_path);
        EventDispatcher::Path new_path;
        EventDispatcher::GetPath(n, new_path);
        if (over_)
        {
            Point empty;
            MouseEvent me(kET_MOUSE_LEAVE, kMB_NONE, over_.get(), empty, empty, 0);
            dispatcher.run(me, old_path);
        }
        over_ = target;
        root_->setCursor(::LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED));
        if (over_)
        {
            Point empty;
            MouseEvent me(kET_MOUSE_ENTER, kMB_NONE, over_.get(), empty, empty, 0);
            dispatcher.run(me, new_path);
        }
    }
}
开发者ID:91yuan,项目名称:bones,代码行数:27,代码来源:mouse_controller.cpp

示例3: if

void ActorHelper::fullLevelUp(unsigned int unitID)
{
    int product_id = 0;

    s_levelUpUnitID = unitID;
    if (unitID >= ID_Actor_Start && unitID <= ID_Actor_End) {
        //SdkManager::getInstance()->pay(ProductID_RoleFullLevel);
        product_id = ProductID_RoleFullLevel;
    }
    else if (unitID >= ID_Magic_Start && unitID <= ID_Magic_End) {
        //SdkManager::getInstance()->pay(ProductID_MagicFullLevel);
        product_id = ProductID_MagicFullLevel;
    }
    else {
        CCASSERT(false, "error!");
    }

    //test win32
#if DEBUG_ALWAYS_BUY_SUCCESS == 1
    EventDispatcher * eventDspc = Director::getInstance()->getEventDispatcher();
    EventCustom event(MSG_PayResult);
    MsgData data;
    data.value = product_id;
    data.errorCode = Rsp_Success;
    event.setUserData(&data);
    eventDspc->dispatchEvent(&event);
#endif
}
开发者ID:SongCF,项目名称:game-CoolRun,代码行数:28,代码来源:ActorHelper.cpp

示例4: registerEventHandlers

void GameLayer::registerEventHandlers() {
    Director* director = Director::getInstance();
    EventDispatcher* eventDispatcher = director->getEventDispatcher();
    
    EventListenerTouchOneByOne* eventListener = EventListenerTouchOneByOne::create();
    eventListener->setSwallowTouches(true);
    
    eventListener->onTouchEnded = [=](Touch* touch, Event* event){
        if (!getAcceptInput()) {
            return;
        }
        
        Vec2 position = m_tileLayer->convertTouchToNodeSpace(touch);
        for (auto iterator = m_tileLayer->getChildren().begin(); iterator != m_tileLayer->getChildren().end(); iterator++) {
            auto child = *iterator;
            GameTileView* gameTileView = dynamic_cast<GameTileView*>(child);
            if(gameTileView->getBoundingBox().containsPoint(position)) {
                if (gameTileView->getGameTile()->getCanMove()) {
                    doSelectGameTileView(gameTileView);
                }
                break;
            }
            
        }
    };
    
    eventListener->onTouchBegan = [](Touch* touch, Event* event){
        return true;
    };
    eventListener->onTouchMoved = [](Touch* touch, Event* event){};
    eventListener->onTouchCancelled = [](Touch* touch, Event* event){};
    eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, m_tileLayer);
}
开发者ID:newcl,项目名称:connect,代码行数:33,代码来源:game_layer.cpp

示例5: main

int main()
{
  EventDispatcher dispatcher;

  int my_var = 0;

  dispatcher.addHandler("event1", [&my_var](EventDispatcher& ev) -> bool {
    cout << "My event1 has been launched (first handler)" << endl;
    my_var++;
    return true;
  });

  dispatcher.addHandler("event1", [&my_var](EventDispatcher& ev) -> bool {
    cout << "My event1 has been launched (second handler)" << endl;
    my_var++;
    cout << "Trigger event2..." << endl;
    ev.dispatchEvent("event2");
    return false;
  });

  dispatcher.addHandler("event2", [&my_var](EventDispatcher& ev) -> bool {
    cout << "My event2 has been launched!" << endl;
    my_var++;
    return true;
  });

  cout << "Triggering event..." << endl;

  dispatcher.dispatchEvent("event1");

  cout << "My var is: " << my_var << endl;

  return 0;
}
开发者ID:freinn,项目名称:cplusplusclasses,代码行数:34,代码来源:main.cpp

示例6: checker

int EventDispatcherBinder::hasEventListener(lua_State* L)
{
	StackChecker checker(L, "EventDispatcherBinder::hasEventListener", 1);

	Binder binder(L);
	EventDispatcher* eventDispatcher = static_cast<EventDispatcher*>(binder.getInstance("EventDispatcher"));

	luaL_checktype(L, 2, LUA_TSTRING);

    if (eventDispatcher->data(&key_map) == NULL)
	{
		lua_pushboolean(L, 0);
	}
	else
	{
        EventBinderMap& map = *static_cast<EventBinderMap*>(eventDispatcher->data(&key_map));
		
		const char* event = lua_tostring(L, 2);
		int eventid = StringId::instance().id(event);
		
		const std::vector<CppLuaBridge*>& bridges = map[eventid]; 
		
		lua_pushboolean(L, bridges.empty() ? 0 : 1);
	}

	return 1;
}
开发者ID:popcade,项目名称:gideros,代码行数:27,代码来源:eventdispatcherbinder.cpp

示例7: main

/// \brief Define the main() for the point entry
int main(int argc, char *argv[])
{
    int returnCode;
    QApplication ultracopierApplication(argc, argv);
    ultracopierApplication.setApplicationVersion(ULTRACOPIER_VERSION);
    ultracopierApplication.setQuitOnLastWindowClosed(false);
    qRegisterMetaType<PluginsAvailable>("PluginsAvailable");
    qRegisterMetaType<Ultracopier::DebugLevel>("Ultracopier::DebugLevel");
    qRegisterMetaType<Ultracopier::CopyMode>("Ultracopier::CopyMode");
    qRegisterMetaType<Ultracopier::ItemOfCopyList>("Ultracopier::ItemOfCopyList");
    #ifdef ULTRACOPIER_DEBUG
    DebugEngine::getInstance();
    #endif // ULTRACOPIER_DEBUG
    //the main code, event loop of Qt and event dispatcher of ultracopier
    {
        EventDispatcher backgroundRunningInstance;
        if(backgroundRunningInstance.shouldBeClosed())
            returnCode=0;
        else
            returnCode=ultracopierApplication.exec();
    }
    #ifdef ULTRACOPIER_DEBUG
    DebugEngine::destroyInstanceAtTheLastCall();
    #endif // ULTRACOPIER_DEBUG
    return returnCode;
}
开发者ID:dsferruzza,项目名称:Ultracopier,代码行数:27,代码来源:main.cpp

示例8: if

void Stage::OnChar(wxKeyEvent &inEvent) {
    if (!ShouldSendEvents()) {
        inEvent.Skip();
    } else if (inEvent.GetKeyCode() == WXK_ESCAPE) {
        // The menu accelerator for StageFrame::OnStopMovies doesn't appear
        // to work in wxWidgets 2.9 (and maybe also 2.8).  If the
        // accelerator doesn't work, we currently receive the escape key
        // event here.  (We tried calling inEvent.Skip and passing this up
        // to a handle on the StageFrame, but the event never arrived,
        // possibly because StageFrame is not configured to receive key
        // events.)
        EndMediaElements();
    } else if (inEvent.GetKeyCode() == WXK_SPACE &&
               inEvent.ControlDown() && !inEvent.AltDown()) {
        inEvent.Skip(); // Always allow toggling into edit mode.
    } else {
        // NOTE - We process character events directed at the Stage here,
        // but the Stage isn't always focused.  Is this really a good idea?
        // Douglas tells me that Director works like this, so at least
        // there's precedent.
        EventDispatcher *dispatcher = GetEventDispatcher();
        if (!dispatcher->DoEventChar(inEvent))
            inEvent.Skip();
    }
}
开发者ID:colonelqubit,项目名称:halyard,代码行数:25,代码来源:Stage.cpp

示例9: main

int main()
{
    /*shared_ptr<Foobar> ptrShared(new Foobar);
	weak_ptr<Foobar> ptrWeak(ptrShared);
	cout<<"weak_ptr valid:"<<(!ptrWeak.expired() ? "true" : "false")<<endl;
	shared_ptr<Foobar> ptrShared1 = ptrWeak.lock();
	ptrShared = nullptr;
	cout<<"weak_ptr valid:"<<(!ptrWeak.expired() ? "true" : "false")<<endl;*/
	EventDispatcher *dispatcher = new EventDispatcher;
	//vector<EventConnectionHolder> eventConnHolderPool;
	//eventConnHolderPool.push_back(dispatcher->subscribeEvent());
	EventConnectionHolder connectionHolder;
	connectionHolder = dispatcher->subscribeEvent();
	EventSlot slot(std::move(connectionHolder));
	//dispatcher->subscribeEvent();
	//EventSlot slot = dispatcher->subscribeEvent();
	//EventConnectionHolder connectionHolder(dispatcher->subscribeEvent());
	/*for(auto &holder : eventConnHolderPool)
	{
		holder.disconnect();
	}*/
	//connectionHolder.disconnect();
	delete dispatcher;
	return 0;
}
开发者ID:nqtwilford,项目名称:Misc,代码行数:25,代码来源:weak_ptr.cpp

示例10: cancelEvent

bool WorkerEventQueue::cancelEvent(Event& event)
{
    EventDispatcher* task = m_eventDispatcherMap.take(&event);
    if (!task)
        return false;
    task->cancel();
    return true;
}
开发者ID:sailei1,项目名称:webkit,代码行数:8,代码来源:WorkerEventQueue.cpp

示例11: destruct

int EventDispatcherBinder::destruct(lua_State* L)
{
	void* ptr = *(void**)lua_touserdata(L, 1);
	EventDispatcher* eventDispatcher = static_cast<EventDispatcher*>(ptr);
	eventDispatcher->unref();

	return 0;
}
开发者ID:popcade,项目名称:gideros,代码行数:8,代码来源:eventdispatcherbinder.cpp

示例12:

void Widget::FocusNavigationController::removeKeyboardEventListener()
{
    if (nullptr != _keyboardListener)
    {
        EventDispatcher* dispatcher = Director::getInstance()->getEventDispatcher();
        dispatcher->removeEventListener(_keyboardListener);
        _keyboardListener = nullptr;
    }
}
开发者ID:dabingnn,项目名称:cocosVR,代码行数:9,代码来源:UIWidget.cpp

示例13:

/*static*/
status_t
EventDispatcher::_cursor_looper(void* _dispatcher)
{
	EventDispatcher* dispatcher = (EventDispatcher*)_dispatcher;

	ETRACE(("Start cursor loop\n"));
	dispatcher->_CursorLoop();
	return B_OK;
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:10,代码来源:EventDispatcher.cpp

示例14: CC_CALLBACK_2

void Widget::FocusNavigationController::addKeyboardEventListener()
{
    if (nullptr == _keyboardListener)
    {
        _keyboardListener = EventListenerKeyboard::create();
        _keyboardListener->onKeyReleased = CC_CALLBACK_2(Widget::FocusNavigationController::onKeypadKeyPressed, this);
        EventDispatcher* dispatcher = Director::getInstance()->getEventDispatcher();
        dispatcher->addEventListenerWithFixedPriority(_keyboardListener, _keyboardEventPriority);
    }
}
开发者ID:dabingnn,项目名称:cocosVR,代码行数:10,代码来源:UIWidget.cpp

示例15: TEST

TEST(EventDispatcher, Timer) {
    using namespace std::placeholders;
    EventDispatcher dispatcher;
    bool received = false;
    TimerEventWatcher watcher(&dispatcher, std::bind(OnTimer, &received, _1),
                              200);
    watcher.Start();
    dispatcher.Run();
    EXPECT_TRUE(received);
}
开发者ID:343829084,项目名称:toft,代码行数:10,代码来源:event_dispatcher_test.cpp


注:本文中的EventDispatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。