本文整理汇总了C++中setCallback函数的典型用法代码示例。如果您正苦于以下问题:C++ setCallback函数的具体用法?C++ setCallback怎么用?C++ setCallback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setCallback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getUniformValue
void GLProgramState::setUniformCallback(GLint uniformLocation, const std::function<void(GLProgram*, Uniform*)> &callback)
{
auto v = getUniformValue(uniformLocation);
if (v)
v->setCallback(callback);
else
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
示例2: setServer
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client)
{
this->_state = MQTT_DISCONNECTED;
setServer(ip, port);
setCallback(callback);
setClient(client);
this->stream = NULL;
}
示例3: setServer
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client, Stream& stream) {
this->_state = MQTT_DISCONNECTED;
setServer(ip,port);
setCallback(callback);
setClient(client);
setStream(stream);
setProtocol(MQTT_VERSION);
}
示例4: setServer
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client) {
this->_state = MQTT_DISCONNECTED;
setServer(addr, port);
setCallback(callback);
setClient(client);
this->stream = NULL;
setListener(NULL); // TOAST
}
示例5: TEST_P
TEST_P(TestDetailedBalanceWithKernels, FissionThatShouldBeRejected) {
auto &ctx = kernel->context();
abcFusionFissionContext(ctx, 1e-15, 1e15); // very high off rate
ctx.particle_types().add("D", 0.);
ctx.potentials().addHarmonicRepulsion("A", "D", 10., 2.);
ctx.potentials().addHarmonicRepulsion("B", "D", 10., 2.);
const auto idfus = ctx.reactions().idOf("fusion");
const auto idfis = ctx.reactions().idOf("fission");
auto countsObs = kernel->observe().reactionCounts(1);
countsObs->setCallback([&idfus, &idfis](const readdy::model::observables::ReactionCounts::result_type &result) {
if (result.empty()) {
readdy::log::trace("reaction counts is empty, no reaction handler ran so far, skip test");
return;
}
EXPECT_EQ(result.at(idfis), 0) << "fission shall not occur";
EXPECT_EQ(result.at(idfus), 0) << "fusion shall not occur";
});
auto countsConnection = kernel->connectObservable(countsObs.get());
std::vector<std::string> typesToCount = {"A", "B", "C", "D"};
auto numbersObs = kernel->observe().nParticles(1, typesToCount);
numbersObs->setCallback([](const readdy::model::observables::NParticles::result_type &result) {
EXPECT_EQ(result[0] + result[2], 1) << "conservation of A + C";
EXPECT_EQ(result[1] + result[2], 1) << "conservation of B + C";
EXPECT_EQ(result[3], 500) << "conservation of D";
if (result[0] + result[2] != 1) {
readdy::log::trace("A {} B {} C {}", result[0], result[1], result[2]);
}
});
auto numbersConnection = kernel->connectObservable(numbersObs.get());
const auto idc = ctx.particle_types().idOf("C");
const auto idd = ctx.particle_types().idOf("D");
kernel->stateModel().addParticle({{-0.1, -0.1, -0.1}, idc});
// induce rejection by many repulsing particles in the vicinity
for (std::size_t i = 0; i < 500; ++i) {
auto pos = m::rnd::normal3(0., 1.);
kernel->stateModel().addParticle({pos, idd});
}
readdy::scalar timeStep = 0.1;
perform(kernel.get(), 1, timeStep);
}
示例6: Vec2
Scene* Chapter7_1::createScene()
{
cocos2d::Rect visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// create a scene
auto scene = Scene::create();
// add title
auto label = LabelTTF::create("TileMap", "Marker Felt.ttf", 32);
label->setPosition(Vec2(visibleRect.origin.x+visibleRect.size.width/2, visibleRect.origin.y+visibleRect.size.height/2).x,
Vec2(visibleRect.origin.x+visibleRect.size.width/2, visibleRect.origin.y+visibleRect.size.height).y - 30);
scene->addChild(label, -1);
//add the menu item for back to main menu
label = LabelTTF::create("MainMenu", "Marker Felt.ttf", 32);
auto menuItem = MenuItemLabel::create(label);
menuItem->setCallback([&](cocos2d::Ref *sender) {
Director::getInstance()->replaceScene(Chapter7::createScene());
});
auto menu = Menu::create(menuItem, nullptr);
menu->setPosition(Vec2::ZERO);
menuItem->setPosition(Vec2(visibleRect.origin.x+visibleRect.size.width - 80, visibleRect.origin.y + 25));
scene->addChild(menu, 1);
// TileMap
auto map = TMXTiledMap::create("isometric_grass_and_water.tmx");
map->setPosition(Vec2(visibleSize.width/2 - map->getContentSize().width/2, 0));
auto listener1 = EventListenerTouchOneByOne::create();
listener1->onTouchBegan = [](Touch* touch, Event* event){
return true; // if you are consuming it
};
listener1->onTouchEnded = [=](Touch* touch, Event* event){
auto layer = map->getLayer("layer0");
Size viewSize = Director::getInstance()->getWinSize();
Vec2 mapCordinate = map->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
int tileX = mapCordinate.x / map->getTileSize().width;
int tileY = (viewSize.height - mapCordinate.y) / map->getTileSize().height;
int id = layer->getTileGIDAt(Vec2(tileX, tileY));
Sprite* tileSprite = layer->getTileAt(Vec2(tileX, tileY));
std::cout << "Tile GID: " << id << std::endl;
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener1, map);
scene->addChild(map, 0, 99); // with a tag of '99'
return scene;
}
示例7: setCallback
void Curl::reset() {
buffer = "";
http_response_code = 0;
response_headers.clear();
http_response_message.clear();
setCallback();
setUserPass();
setDefaultOptions();
}
示例8: mapFileType
libfalltergeist::MapFileType* ResourceManager::mapFileType(std::string filename)
{
auto item = dynamic_cast<libfalltergeist::MapFileType*>(datFileItem(filename));
if (item)
{
item->setCallback(&ResourceManager::proFileType);
}
return item;
}
示例9: init
bool MainMenuLayer::init()
{
if(!Layer::init())
{
return false;
}
MenuItemFont::setFontName("fonts/arial.ttf");
MenuItemFont::setFontSize(40);
auto menuItemSelectMap = MenuItemFont::create(std::string(LocalizedCStringByKey("start_game")));
menuItemSelectMap->setCallback(
[=](Ref*)
{
static_cast<LayerMultiplex*>(_parent)->switchTo(1);
}
);
auto menuItemMapMaker = MenuItemFont::create(std::string(LocalizedCStringByKey("map_maker")));
menuItemMapMaker->setCallback(
[](Ref*)
{
auto scene = Scene::create();
scene->addChild(MapMakerScene::create());
Director::getInstance()->replaceScene(TransitionFlipX::create(0.5, scene));
}
);
auto menu = Menu::create(menuItemSelectMap, menuItemMapMaker, nullptr);
menu->alignItemsVerticallyWithPadding(20);
auto s = Director::getInstance()->getWinSize();
addChild(menu);
menu->setPosition(Vec2(s.width / 2, s.height / 2));
return true;
}
示例10: initTitle
void InstanceLayer::initTitle()
{
Size size = Director::getInstance()->getVisibleSize();
//顶部的文字
title_custom_instance = Sprite::createWithSpriteFrameName("titlename_instance_custom.png");
title_custom_instance->setPosition(size.width/2, 690);
this->addChild(title_custom_instance, 4);
//精英按钮
auto button_left_normal = Sprite::createWithSpriteFrameName("button_left_0.png");
auto button_left_pressed = Sprite::createWithSpriteFrameName("button_left_1.png");
auto button_left_disable = Sprite::createWithSpriteFrameName("button_left_2.png");
auto menuItem = MenuItemSprite::create(button_left_normal, button_left_pressed, button_left_disable);
menuItem->setCallback([](Ref* pSender){
});
auto text_elite_install = Sprite::createWithSpriteFrameName("text_elite.png");
text_elite_install->setPosition(button_left_normal->getContentSize().width/2 - 15, button_left_normal->getContentSize().height/2);
menuItem->addChild(text_elite_install);
menu_left = Menu::create(menuItem, NULL);
menu_left->setPosition(menuItem->getContentSize().width/2 - 10, 687);
this->addChild(menu_left, 4);
//活动按钮
auto button_right_normal = Sprite::createWithSpriteFrameName("button_left_0.png");
auto button_right_pressed = Sprite::createWithSpriteFrameName("button_left_1.png");
auto button_right_disable = Sprite::createWithSpriteFrameName("button_left_2.png");
auto menu_rightItem = MenuItemSprite::create(button_right_normal, button_right_pressed, button_right_disable);
menu_rightItem->setCallback([](Ref* pSender){
});
auto text_activity = Sprite::createWithSpriteFrameName("text_activity.png");
text_activity->setPosition(button_right_normal->getContentSize().width/2 - 15, button_right_normal->getContentSize().height/2);
menu_rightItem->addChild(text_activity);
menu_right = Menu::create(menu_rightItem, NULL);
menu_right->setPosition(size.width - button_right_normal->getContentSize().width/2 + 30, 687);
this->addChild(menu_right);
}
示例11: createMenuItemImage
MenuItemImage* CustomTool::createMenuItemImage(const char* normal, const char* selected, ccMenuCallback callback)
{
auto item = MenuItemImage::create();
auto nsf = SpriteFrameCache::getInstance()->getSpriteFrameByName(normal);
auto ssf = SpriteFrameCache::getInstance()->getSpriteFrameByName(selected);
item->setNormalSpriteFrame(nsf);
item->setSelectedSpriteFrame(ssf);
item->setCallback(callback);
return item;
}
示例12: _drawAABB
OBBTest::OBBTest():
_drawAABB(nullptr),
_pick(false),
_camera(nullptr)
{
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(OBBTest::onTouchesBegan, this);
listener->onTouchesEnded = CC_CALLBACK_2(OBBTest::onTouchesEnded, this);
listener->onTouchesMoved = CC_CALLBACK_2(OBBTest::onTouchesMoved, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
auto s = Director::getInstance()->getWinSize();
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto winSize = Director::getInstance()->getWinSize();
// add title
auto label = LabelTTF::create("OBB", "Arial", 24);
label->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x,
Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - 30);
this->addChild(label, -1);
//add the menu item for back to main menu
label = LabelTTF::create("MainMenu", "Arial", 24);
auto menuItem = MenuItemLabel::create(label);
menuItem->setCallback([&](cocos2d::Ref *sender) {
Director::getInstance()->replaceScene(Chapter9::createScene());
});
auto menu = Menu::create(menuItem, nullptr);
menu->setPosition( Vec2::ZERO );
menuItem->setPosition( Vec2(origin.x+visibleSize.width - 80, origin.y + 25) );
this->addChild(menu, 1);
auto layer3D=Layer::create();
addChild(layer3D);
// add camera
_camera=Camera::createPerspective(60, (GLfloat)winSize.width/winSize.height, 1, 1000);
_camera->setCameraFlag(CameraFlag::USER1);// set camera flag
_camera->setPosition3D(Vec3(0, 50, 230));
_camera->lookAt(Vec3(0,0,0), Vec3(0,1,0));
layer3D->addChild(_camera);
_drawAABB = DrawNode3D::create();
Vec3 extents = Vec3(60, 30, 100);
AABB aabb = AABB(-extents, extents);
_obb = OBB(aabb);
layer3D->addChild(_drawAABB);
layer3D->setCameraMask(2);
scheduleUpdate();
}
示例13: Vec2
Scene* Chapter9_2::createScene()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// create a scene
// 'scene' is an autorelease object
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
auto scene = Scene::create();
// add title
auto label = LabelTTF::create("3D skeleton animation", "Arial", 24);
label->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x,
Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - 30);
scene->addChild(label, -1);
//add the menu item for back to main menu
label = LabelTTF::create("MainMenu", "Arial", 24);
auto menuItem = MenuItemLabel::create(label);
menuItem->setCallback([&](cocos2d::Ref *sender) {
Director::getInstance()->replaceScene(Chapter9::createScene());
});
auto menu = Menu::create(menuItem, nullptr);
menu->setPosition( Vec2::ZERO );
menuItem->setPosition( Vec2(origin.x+visibleSize.width - 80, origin.y + 25) );
scene->addChild(menu, 1);
std::string fileName = "orc.c3b";
auto sprite = Sprite3D::create(fileName);
sprite->setScale(8.f);
sprite->setRotation3D(Vec3(0,180,0));
sprite->setPosition( Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x,
Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).y );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// play skeleton animation
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
auto animation = Animation3D::create(fileName);
if (animation)
{
auto animate = Animate3D::create(animation);
animate->setSpeed(1);
sprite->runAction(RepeatForever::create(animate));
}
//add to scene
scene->addChild(sprite);
// return the scene
return scene;
}
示例14: removeControl
void cContextMenu::clear() {
// Iterate over all known controls and see how high this thing is
Iterator it;
for (it = entries.begin(); it != entries.end(); ++it) {
removeControl((*it));
delete *it;
}
entries.clear();
setCallback(0, 0); // Reset callback
}
示例15:
MenuSourceItem * MenuSourceButton::copy() {
auto ret = construct<MenuSourceButton>();
ret->setName(_name);
ret->setNameIcon(_nameIcon);
ret->setValue(_name);
ret->setValueIcon(_nameIcon);
ret->setSelected(_selected);
ret->setNextMenu(_nextMenu);
ret->setCallback(_callback);
ret->setCustomData(_customData);
return ret;
}