Fix compiling deprecated issues (#2154)

This commit is contained in:
halx99 2024-09-15 23:37:42 +08:00 committed by GitHub
parent 6ce78c0913
commit 2d16634072
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 95 additions and 103 deletions

View File

@ -294,7 +294,7 @@ public:
}
}
curl_easy_getinfo(_curl, CURLINFO_SPEED_DOWNLOAD, &_speed);
curl_easy_getinfo(_curl, CURLINFO_SPEED_DOWNLOAD_T, &_speed);
return ret;
}
@ -309,7 +309,7 @@ private:
bool _acceptRanges;
int64_t _totalBytesExpected;
double _speed;
curl_off_t _speed;
CURL* _curl;
curl_socket_t _sockfd = -1; // store the sockfd to support cancel download manually
bool _cancelled = false;

View File

@ -71,7 +71,7 @@ public:
int64_t bytesReceived = 0;
int64_t totalBytesReceived = 0;
// speed
double speedInBytes = 0;
int64_t speedInBytes = 0;
} mutable progressInfo;
DownloadTask();

View File

@ -198,10 +198,7 @@ void TriggerObj::serialize(const rapidjson::Value& val)
continue;
}
char buf[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);
std::string custom_event_name = fmt::to_string(event);
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [this](EventCustom* /*evt*/) {
if (detect())
{
@ -290,9 +287,8 @@ void TriggerObj::serialize(cocostudio::CocoLoader* pCocoLoader, cocostudio::stEx
{
continue;
}
char buf[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);
std::string custom_event_name = fmt::to_string(event);
EventListenerCustom* listener =
EventListenerCustom::create(custom_event_name, [this](EventCustom* /*evt*/) {

View File

@ -529,7 +529,7 @@ void InputProcessor::onMouseDown(ax::EventMouse * event)
return;
auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
Vec2 pt = event->getLocation();
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;
@ -559,7 +559,7 @@ void InputProcessor::onMouseUp(ax::EventMouse * event)
return;
auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
Vec2 pt = event->getLocation();
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;
@ -620,13 +620,13 @@ void InputProcessor::onMouseUp(ax::EventMouse * event)
void InputProcessor::onMouseMove(ax::EventMouse * event)
{
TouchInfo* ti = getTouch(0);
Vec2 npos = UIRoot->worldToRoot(Vec2(event->getCursorX(), event->getCursorY()));
auto pt = event->getLocation();
Vec2 npos = UIRoot->worldToRoot(pt);
if (std::abs(ti->pos.x - npos.x) < 1
&& std::abs(ti->pos.y - npos.y) < 1)
return;
auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;
@ -669,7 +669,7 @@ void InputProcessor::onMouseMove(ax::EventMouse * event)
void InputProcessor::onMouseScroll(ax::EventMouse * event)
{
auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
Vec2 pt = event->getLocation();
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;

View File

@ -190,11 +190,11 @@ void Box2DTestBed::onKeyReleased(EventKeyboard::KeyCode code, Event* event)
void Box2DTestBed::onMouseDown(Event* event)
{
EventMouse* e = (EventMouse*)event;
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
switch (e->getMouseButton())
{
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
case EventMouse::MouseButton::BUTTON_LEFT:
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = true;
break;
@ -217,7 +217,8 @@ void Box2DTestBed::onMouseUp(Event* event)
void Box2DTestBed::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;
pos = {e->getCursorX() / g_debugDraw.mRatio, e->getCursorY() / g_debugDraw.mRatio};
auto pt = e->getLocation();
pos = {pt.x / g_debugDraw.mRatio, pt.y / g_debugDraw.mRatio};
if (button[(int)EventMouse::MouseButton::BUTTON_RIGHT])
{

View File

@ -73,7 +73,7 @@ public:
prevBody = body;
}
b2Vec2 anchor(-15.0f + 1.0f * e_count, 5.0f);
b2Vec2 anchor(-15.0f + 1.0f * static_cast<float>(e_count), 5.0f);
jd.Initialize(prevBody, ground, anchor);
m_world->CreateJoint(&jd);
}

View File

@ -481,9 +481,9 @@ void ChipmunkTestBed::onMouseUp(Event* event)
void ChipmunkTestBed::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;
ChipmunkDemoMouse.x = e->getCursorX() - physicsDebugNodeOffset.x;
ChipmunkDemoMouse.y = e->getCursorY() - physicsDebugNodeOffset.y;
auto pt = e->getLocation();
ChipmunkDemoMouse.x = pt.x - physicsDebugNodeOffset.x;
ChipmunkDemoMouse.y = pt.y - physicsDebugNodeOffset.y;
cpBodySetPosition(mouse_body, ChipmunkDemoMouse);
}

View File

@ -991,7 +991,7 @@ void ClippingNodePerformanceTest::setup()
countLabel->setPosition(Vec2(s.width / 2, s.height - 120));
addChild(countLabel, 1);
auto addClippingNode = [=] (int count) -> void {
auto addClippingNode = [this, s, countLabel] (int count) -> void {
for (int i = 0; i < count; i++) {
Vec2 pos = Vec2(random(0, (int) s.width), random(0, (int) s.height));
auto stencil = Sprite::create("Images/stars2.png");

View File

@ -92,16 +92,15 @@ void MouseEventTest::onMouseUp(Event* event)
void MouseEventTest::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;
std::string str = "MousePosition X:";
str = str + tostr(e->getCursorX()) + " Y:" + tostr(e->getCursorY());
_labelPosition->setString(str.c_str());
auto loc = e->getLocation();
std::string str = fmt::format("MousePosition:({},{})", loc.x, loc.y);
_labelPosition->setString(str);
}
void MouseEventTest::onMouseScroll(Event* event)
{
EventMouse* e = (EventMouse*)event;
std::string str = "Mouse Scroll detected, X: ";
str = str + tostr(e->getScrollX()) + " Y: " + tostr(e->getScrollY());
std::string str = fmt::format("Mouse Scroll detected, X:{} Y:{}", e->getScrollX(), e->getScrollY());
_labelAction->setString(str.c_str());
}

View File

@ -2323,7 +2323,7 @@ void LabelLayoutBaseTest::initWrapOption(const ax::Size& size)
checkBox->setSelected(true);
checkBox->setName("toggleWrap");
checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->enableWrap(true);
@ -2354,7 +2354,7 @@ void LabelLayoutBaseTest::initToggleLabelTypeOption(const ax::Size& size)
auto stepper = (ControlStepper*)this->getChildByName("stepper");
checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this, stepper](Object* /*sender*/, CheckBox::EventType event) {
float fontSize = stepper->getValue();
if (event == CheckBox::EventType::SELECTED)
@ -2419,7 +2419,7 @@ void LabelLayoutBaseTest::initSliders(const ax::Size& size)
addChild(slider2);
auto winSize = Director::getInstance()->getVisibleSize();
slider->addEventListener([=](Object* ref, Slider::EventType event) {
slider->addEventListener([this, slider, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider->getPercent();
auto labelSize = _label->getContentSize();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, labelSize.height);
@ -2431,7 +2431,7 @@ void LabelLayoutBaseTest::initSliders(const ax::Size& size)
this->updateDrawNodeSize(drawNodeSize);
});
slider2->addEventListener([=](Object* ref, Slider::EventType event) {
slider2->addEventListener([this, slider2, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider2->getPercent();
auto labelSize = _label->getContentSize();
auto drawNodeSize = Size(labelSize.width, percent / 100.0 * winSize.height);
@ -2663,7 +2663,7 @@ LabelResizeTest::LabelResizeTest()
slider2->setVisible(false);
auto winSize = Director::getInstance()->getVisibleSize();
slider1->addEventListener([=](Object* ref, Slider::EventType event) {
slider1->addEventListener([this, slider1, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider1->getPercent();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
if (drawNodeSize.height <= 0)
@ -2690,7 +2690,7 @@ LabelResizeTest::LabelResizeTest()
checkBox->setSelected(false);
checkBox->setName("LineBreak");
checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->setLineBreakWithoutSpace(true);
@ -2729,7 +2729,7 @@ LabelToggleTypeTest::LabelToggleTypeTest()
slider2->setVisible(false);
auto winSize = Director::getInstance()->getVisibleSize();
slider1->addEventListener([=](Object* ref, Slider::EventType event) {
slider1->addEventListener([this, slider1, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider1->getPercent();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
if (drawNodeSize.height <= 0)
@ -2756,7 +2756,7 @@ LabelToggleTypeTest::LabelToggleTypeTest()
checkBox->setSelected(false);
checkBox->setName("LineBreak");
checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->setLineBreakWithoutSpace(true);
@ -2875,7 +2875,7 @@ LabelSystemFontTest::LabelSystemFontTest()
auto slider1 = (ui::Slider*)this->getChildByTag(1);
auto winSize = Director::getInstance()->getVisibleSize();
slider1->addEventListener([=](Object* ref, Slider::EventType event) {
slider1->addEventListener([this, slider1, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider1->getPercent();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
if (drawNodeSize.height <= 0)
@ -2899,7 +2899,7 @@ LabelSystemFontTest::LabelSystemFontTest()
checkBox->setSelected(false);
checkBox->setName("LineBreak");
checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->setLineBreakWithoutSpace(true);

View File

@ -204,7 +204,7 @@ void Issue12226::onEnter()
const uint32_t length = (radius * 0.95);
std::function<void(float)> updateMotionStreak = [=](float dt) {
std::function<void(float)> updateMotionStreak = [outer, length, this](float dt) {
Vec2 position =
Vec2(outer->getPositionX() + length * cosf(-1 * AX_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)),
outer->getPositionY() + length * sinf(-1 * AX_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)));

View File

@ -308,7 +308,7 @@ bool NavMeshBasicTestDemo::init()
TTFConfig ttfConfig("fonts/arial.ttf", 15);
_debugLabel = Label::createWithTTF(ttfConfig, "Debug Draw ON");
_debugLabel->retain();
auto menuItem1 = MenuItemLabel::create(_debugLabel, [=](Object*) {
auto menuItem1 = MenuItemLabel::create(_debugLabel, [this](Object*) {
bool enabledDebug = !getNavMesh()->isDebugDrawEnabled();
getNavMesh()->setDebugDrawEnable(enabledDebug);
if (enabledDebug)
@ -355,7 +355,7 @@ bool NavMeshAdvanceTestDemo::init()
_debugLabel = Label::createWithTTF(ttfConfig, "Debug Draw ON");
_debugLabel->retain();
auto menuItem0 = MenuItemLabel::create(_obstacleLabel, [=](Object*) {
auto menuItem0 = MenuItemLabel::create(_obstacleLabel, [this](Object*) {
float x = ax::random(-50.0f, 50.0f);
float z = ax::random(-50.0f, 50.0f);
Physics3DWorld::HitResult result;
@ -365,7 +365,7 @@ bool NavMeshAdvanceTestDemo::init()
menuItem0->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
menuItem0->setPosition(Vec2(VisibleRect::left().x, VisibleRect::top().y - 50));
auto menuItem1 = MenuItemLabel::create(_agentLabel, [=](Object*) {
auto menuItem1 = MenuItemLabel::create(_agentLabel, [this](Object*) {
float x = ax::random(-50.0f, 50.0f);
float z = ax::random(-50.0f, 50.0f);
Physics3DWorld::HitResult result;
@ -375,7 +375,7 @@ bool NavMeshAdvanceTestDemo::init()
menuItem1->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
menuItem1->setPosition(Vec2(VisibleRect::left().x, VisibleRect::top().y - 100));
auto menuItem2 = MenuItemLabel::create(_debugLabel, [=](Object*) {
auto menuItem2 = MenuItemLabel::create(_debugLabel, [this](Object*) {
bool enabledDebug = !getNavMesh()->isDebugDrawEnabled();
getNavMesh()->setDebugDrawEnable(enabledDebug);
if (enabledDebug)

View File

@ -478,7 +478,7 @@ bool AudioWavTest::init()
_stateLabel->setPosition(layerSize.width / 2, layerSize.height * 0.7f);
addChild(_stateLabel);
auto playPrev = TextButton::create("Play Prev", [=](TextButton* button) {
auto playPrev = TextButton::create("Play Prev", [this](TextButton* button) {
if (_curIndex > 0)
{
AudioEngine::stop(_audioID);
@ -490,7 +490,7 @@ bool AudioWavTest::init()
playPrev->setPosition(layerSize.width * 0.35f, layerSize.height * 0.5f);
addChild(playPrev);
auto playNext = TextButton::create("Play Next", [=](TextButton* button) {
auto playNext = TextButton::create("Play Next", [this](TextButton* button) {
if (_curIndex != -1 && _curIndex < (_wavFiles.size() - 1))
{
AudioEngine::stop(_audioID);
@ -736,7 +736,7 @@ bool AudioIssue18597Test::init()
// test case for https://github.com/cocos2d/cocos2d-x/issues/18597
this->schedule(
[=](float dt) {
[this](float dt) {
AXLOGD("issues 18597 audio crash test");
for (int i = 0; i < 2; ++i)
{
@ -754,7 +754,7 @@ bool AudioIssue18597Test::init()
this->addChild(labelTime);
// update label quickly
this->schedule(
[=](float dt) {
[this](float dt) {
_time += dt;
char timeString[20] = {0};
sprintf(timeString, "Time %2.2f", _time);

View File

@ -222,7 +222,7 @@ void TouchableSpriteTest::onEnter()
_eventDispatcher->removeEventListenersForType(EventListener::Type::TOUCH_ONE_BY_ONE);
auto nextItem = MenuItemFont::create("Next", [=](Object* sender) { getTestSuite()->enterNextTest(); });
auto nextItem = MenuItemFont::create("Next", [this](Object* sender) { getTestSuite()->enterNextTest(); });
nextItem->setFontSizeObj(16);
nextItem->setPosition(VisibleRect::right() + Vec2(-100.0f, -30.0f));
@ -416,7 +416,7 @@ void RemoveListenerWhenDispatching::onEnter()
std::shared_ptr<bool> enable(new bool(true));
// Enable/Disable item
auto toggleItem = MenuItemToggle::createWithCallback(
[=](Object* sender) {
[this, enable, listener1, statusLabel, sprite1](Object* sender) {
if (*enable)
{
_eventDispatcher->removeEventListener(listener1);
@ -465,25 +465,23 @@ void CustomEventTest::onEnter()
statusLabel->setPosition(origin + Vec2(size.width / 2, size.height - 90));
addChild(statusLabel);
_listener = EventListenerCustom::create("game_custom_event1", [=](EventCustom* event) {
_listener = EventListenerCustom::create("game_custom_event1", [statusLabel](EventCustom* event) {
std::string str("Custom event 1 received, ");
char* buf = static_cast<char*>(event->getUserData());
auto& buf = *static_cast<std::string*>(event->getUserData());
str += buf;
str += " times";
statusLabel->setString(str.c_str());
statusLabel->setString(str);
});
_eventDispatcher->addEventListenerWithFixedPriority(_listener, 1);
auto sendItem = MenuItemFont::create("Send Custom Event 1", [=](Object* sender) {
auto sendItem = MenuItemFont::create("Send Custom Event 1", [this](Object* /*sender*/) {
static int count = 0;
++count;
char* buf = new char[10];
sprintf(buf, "%d", count);
auto str = fmt::to_string(count);
EventCustom event("game_custom_event1");
event.setUserData(buf);
event.setUserData(&str);
_eventDispatcher->dispatchEvent(&event);
AX_SAFE_DELETE_ARRAY(buf);
});
sendItem->setPosition(origin + Vec2(size.width / 2, size.height / 2));
@ -493,7 +491,7 @@ void CustomEventTest::onEnter()
_listener2 = EventListenerCustom::create("game_custom_event2", [=](EventCustom* event) {
std::string str("Custom event 2 received, ");
char* buf = static_cast<char*>(event->getUserData());
auto& buf = *static_cast<std::string*>(event->getUserData());
str += buf;
str += " times";
statusLabel2->setString(str.c_str());
@ -501,15 +499,13 @@ void CustomEventTest::onEnter()
_eventDispatcher->addEventListenerWithFixedPriority(_listener2, 1);
auto sendItem2 = MenuItemFont::create("Send Custom Event 2", [=](Object* sender) {
auto sendItem2 = MenuItemFont::create("Send Custom Event 2", [this](Object* /*sender*/) {
static int count = 0;
++count;
char* buf = new char[10];
sprintf(buf, "%d", count);
auto buf = fmt::to_string(count);
EventCustom event("game_custom_event2");
event.setUserData(buf);
event.setUserData(&buf);
_eventDispatcher->dispatchEvent(&event);
AX_SAFE_DELETE_ARRAY(buf);
});
sendItem2->setPosition(origin + Vec2(size.width / 2, size.height / 2 - 40));
@ -803,7 +799,7 @@ void RemoveListenerAfterAddingTest::onEnter()
this->addChild(menu);
};
auto item2 = MenuItemFont::create("Click Me 2", [=](Object* sender) {
auto item2 = MenuItemFont::create("Click Me 2", [this, addNextButton](Object* sender) {
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event* event) -> bool {
AXASSERT(false, "Should not come here!");
@ -818,7 +814,7 @@ void RemoveListenerAfterAddingTest::onEnter()
item2->setPosition(VisibleRect::center() + Vec2(0.0f, 40.0f));
auto item3 = MenuItemFont::create("Click Me 3", [=](Object* sender) {
auto item3 = MenuItemFont::create("Click Me 3", [this, addNextButton](Object* /*sender*/) {
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event* event) -> bool {
AXASSERT(false, "Should not come here!");
@ -1060,7 +1056,7 @@ StopPropagationTest::StopPropagationTest()
auto touchOneByOneListener = EventListenerTouchOneByOne::create();
touchOneByOneListener->setSwallowTouches(true);
touchOneByOneListener->onTouchBegan = [=](Touch* touch, Event* event) {
touchOneByOneListener->onTouchBegan = [this](Touch* touch, Event* event) {
// Skip if don't touch top half screen.
if (!this->isPointInTopHalfAreaOfScreen(touch->getLocation()))
return false;
@ -1085,7 +1081,7 @@ StopPropagationTest::StopPropagationTest()
};
auto touchAllAtOnceListener = EventListenerTouchAllAtOnce::create();
touchAllAtOnceListener->onTouchesBegan = [=](const std::vector<Touch*>& touches, Event* event) {
touchAllAtOnceListener->onTouchesBegan = [this](const std::vector<Touch*>& touches, Event* event) {
// Skip if don't touch top half screen.
if (this->isPointInTopHalfAreaOfScreen(touches[0]->getLocation()))
return;
@ -1101,7 +1097,7 @@ StopPropagationTest::StopPropagationTest()
event->stopPropagation();
};
touchAllAtOnceListener->onTouchesEnded = [=](const std::vector<Touch*>& touches, Event* event) {
touchAllAtOnceListener->onTouchesEnded = [this](const std::vector<Touch*>& touches, Event* event) {
// Skip if don't touch top half screen.
if (this->isPointInTopHalfAreaOfScreen(touches[0]->getLocation()))
return;
@ -1222,14 +1218,14 @@ PauseResumeTargetTest::PauseResumeTargetTest()
sprite3->setPosition(Vec2(0, 0));
sprite2->addChild(sprite3, -1);
auto popup = MenuItemFont::create("Popup", [=](Object* sender) {
auto popup = MenuItemFont::create("Popup", [this, sprite3](Object* sender) {
sprite3->getListener()->setEnabled(false);
_eventDispatcher->pauseEventListenersForTarget(this, true);
auto colorLayer = LayerColor::create(Color4B(0, 0, 255, 100));
this->addChild(colorLayer, 99999);
auto closeItem = MenuItemFont::create("close", [=](Object* sender) {
auto closeItem = MenuItemFont::create("close", [this, colorLayer, sprite3](Object* /*sender*/) {
colorLayer->removeFromParent();
_eventDispatcher->resumeEventListenersForTarget(this, true);
sprite3->getListener()->setEnabled(true);
@ -1279,7 +1275,7 @@ PauseResumeTargetTest2::PauseResumeTargetTest2()
_touchableSprite->setPosition(origin + Vec2(size.width / 2, size.height / 2) + Vec2(-80.0f, 40.0f));
addChild(_touchableSprite);
_itemPauseTouch = MenuItemFont::create("pauseTouch", [=](Object* sender) {
_itemPauseTouch = MenuItemFont::create("pauseTouch", [this](Object* /*sender*/) {
_itemPauseTouch->setEnabled(false);
_itemResumeTouch->setEnabled(true);
@ -1289,7 +1285,7 @@ PauseResumeTargetTest2::PauseResumeTargetTest2()
_itemPauseTouch->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
_itemPauseTouch->setPosition(VisibleRect::right() + Vec2(-150.0f, 0.0f));
_itemResumeTouch = MenuItemFont::create("resumeTouch", [=](Object* sender) {
_itemResumeTouch = MenuItemFont::create("resumeTouch", [this](Object* /*sender*/) {
_itemPauseTouch->setEnabled(true);
_itemResumeTouch->setEnabled(false);
@ -1299,7 +1295,7 @@ PauseResumeTargetTest2::PauseResumeTargetTest2()
_itemResumeTouch->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
_itemResumeTouch->setPosition(VisibleRect::right() + Vec2(0, 0));
_itemAddToScene = MenuItemFont::create("addToScene", [=](Object* sender) {
_itemAddToScene = MenuItemFont::create("addToScene", [this](Object* /*sender*/) {
_itemAddToScene->setEnabled(false);
_itemRemoveFromScene->setEnabled(true);
@ -1309,7 +1305,7 @@ PauseResumeTargetTest2::PauseResumeTargetTest2()
_itemAddToScene->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
_itemAddToScene->setPosition(VisibleRect::right() + Vec2(-150.0f, -50.0f));
_itemRemoveFromScene = MenuItemFont::create("removeFromScene", [=](Object* sender) {
_itemRemoveFromScene = MenuItemFont::create("removeFromScene", [this](Object* /*sender*/) {
_itemAddToScene->setEnabled(true);
_itemRemoveFromScene->setEnabled(false);
_touchableSprite->removeFromParentAndCleanup(false);
@ -1359,14 +1355,14 @@ PauseResumeTargetTest3::PauseResumeTargetTest3()
_touchableSprite->setPosition(origin + Vec2(size.width / 2, size.height / 2) + Vec2(-80.0f, 40.0f));
addChild(_touchableSprite);
auto item = MenuItemFont::create("addListener", [=](Object* sender) {
auto item = MenuItemFont::create("addListener", [this](Object* sender) {
MenuItemFont* senderItem = static_cast<MenuItemFont*>(sender);
senderItem->setEnabled(false);
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [=](Touch* touch, Event* event) {
listener->onTouchBegan = [this](Touch* touch, Event* event) {
Vec2 locationInNode = _touchableSprite->convertToNodeSpace(touch->getLocation());
Size s = _touchableSprite->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
@ -1433,7 +1429,7 @@ Issue4129::Issue4129() : _bugFixed(false)
_eventDispatcher->removeAllEventListeners();
auto nextItem = MenuItemFont::create("Reset", [=](Object* sender) {
auto nextItem = MenuItemFont::create("Reset", [this](Object* /*sender*/) {
AXASSERT(_bugFixed, "This issue was not fixed!");
getTestSuite()->restartCurrTest();
});
@ -1632,7 +1628,7 @@ RegisterAndUnregisterWhileEventHanldingTest::RegisterAndUnregisterWhileEventHanl
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
auto callback1 = [=](DanglingNodePointersTestSprite* sprite) {
auto callback1 = [this, origin, size](DanglingNodePointersTestSprite* sprite) {
auto callback2 = [](DanglingNodePointersTestSprite* sprite) {
AXASSERT(false, "This should never get called!");
};

View File

@ -117,7 +117,7 @@ bool Physics3DTestDemo::init()
TTFConfig ttfConfig("fonts/arial.ttf", 10);
auto label = Label::createWithTTF(ttfConfig, "DebugDraw OFF");
auto menuItem = MenuItemLabel::create(label, [=](Object* /*ref*/) {
auto menuItem = MenuItemLabel::create(label, [this, label](Object* /*sender*/) {
if (getPhysics3DWorld()->isDebugDrawEnabled())
{
getPhysics3DWorld()->setDebugDrawEnable(false);
@ -758,7 +758,7 @@ bool Physics3DCollisionCallbackDemo::init()
this->addChild(mesh);
// preload
//
rigidBody->setCollisionCallback([=](const Physics3DCollisionInfo& ci) {
rigidBody->setCollisionCallback([this](const Physics3DCollisionInfo& ci) {
if (!ci.collisionPointList.empty())
{
if (ci.objA->getMask() != 0)

View File

@ -78,7 +78,7 @@ bool SpritePolygonTestCase::init()
{
TTFConfig ttfConfig("fonts/arial.ttf", 10);
auto label = Label::createWithTTF(ttfConfig, "DebugDraw OFF");
auto menuItem = MenuItemLabel::create(label, [=](Object* ref) {
auto menuItem = MenuItemLabel::create(label, [this, label](Object* ref) {
if (_isDebugDraw)
{
_isDebugDraw = false;

View File

@ -79,7 +79,7 @@ bool UIEditBoxTest::init()
auto buttonSize = button->getContentSize();
button->setTitleText("Single Line");
button->setPosition(_editName->getPosition() + Vec2(editBoxSize.width / 2 + buttonSize.width / 2, 0.0f));
button->addClickEventListener([=](Object* ref) { _editName->setInputMode(ui::EditBox::InputMode::SINGLE_LINE); });
button->addClickEventListener([this](Object* /*sender*/) { _editName->setInputMode(ui::EditBox::InputMode::SINGLE_LINE); });
addChild(button);
// middle
@ -102,7 +102,7 @@ bool UIEditBoxTest::init()
buttonPassword->setPosition(_editPassword->getPosition() +
Vec2(editBoxSize.width / 2 + buttonSize.width / 2, 0.0f));
buttonPassword->addClickEventListener(
[=](Object* ref) { _editPassword->setInputMode(ui::EditBox::InputMode::ANY); });
[this](Object* /*sender*/) { _editPassword->setInputMode(ui::EditBox::InputMode::ANY); });
addChild(buttonPassword);
// bottom
@ -129,7 +129,7 @@ bool UIEditBoxTest::init()
buttonEmail->setTitleText("Multiline");
buttonEmail->setPosition(_editEmailParent->getPosition() +
Vec2(editBoxSize.width / 2 + buttonSize.width / 2, 0.0f));
buttonEmail->addClickEventListener([=](Object* ref) { _editEmail->setInputMode(ui::EditBox::InputMode::ANY); });
buttonEmail->addClickEventListener([this](Object* /*sender*/) { _editEmail->setInputMode(ui::EditBox::InputMode::ANY); });
addChild(buttonEmail);
return true;
@ -213,7 +213,7 @@ bool UIEditBoxTestToggleVisibility::init()
auto buttonSize = button->getContentSize();
button->setTitleText("Toggle Visibility");
button->setPosition(_editName->getPosition() + Vec2(editBoxSize.width / 2 + buttonSize.width / 2, 0.0f));
button->addClickEventListener([=](Object* ref) { _editName->setVisible(!_editName->isVisible()); });
button->addClickEventListener([this](Object* /*sender*/) { _editName->setVisible(!_editName->isVisible()); });
addChild(button);
// middle
@ -235,7 +235,7 @@ bool UIEditBoxTestToggleVisibility::init()
buttonPassword->setPosition(_editPassword->getPosition() +
Vec2(editBoxSize.width / 2 + buttonSize.width / 2, 0.0f));
buttonPassword->addClickEventListener(
[=](Object* ref) { _editPassword->setVisible(!_editPassword->isVisible()); });
[this](Object* /*sender*/) { _editPassword->setVisible(!_editPassword->isVisible()); });
addChild(buttonPassword);
// bottom
@ -262,7 +262,7 @@ bool UIEditBoxTestToggleVisibility::init()
buttonEmail->setTitleText("Toggle Visibility");
buttonEmail->setPosition(_editEmailParent->getPosition() +
Vec2(editBoxSize.width / 2 + buttonSize.width / 2, 0.0f));
buttonEmail->addClickEventListener([=](Object* ref) { _editEmail->setVisible(!_editEmail->isVisible()); });
buttonEmail->addClickEventListener([this](Object* /*sender*/) { _editEmail->setVisible(!_editEmail->isVisible()); });
addChild(buttonEmail);
return true;

View File

@ -513,7 +513,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init()
button->setZoomScale(0.3f);
button->setPressedActionEnabled(true);
button->setTitleColor(Color3B::RED);
button->addClickEventListener([=](Object* sender) {
button->addClickEventListener([this, pageView](Object* /*sender*/) {
HBox* outerBox = HBox::create();
outerBox->setContentSize(Size(240.0f, 130.0f));
@ -547,7 +547,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init()
button2->setZoomScale(0.3f);
button2->setPressedActionEnabled(true);
button2->setTitleColor(Color3B::RED);
button2->addClickEventListener([=](Object* sender) {
button2->addClickEventListener([this, pageView](Object* /*sender*/) {
if (pageView->getItems().size() > 0)
{
pageView->removeItem(pageView->getItems().size() - 1);
@ -568,7 +568,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init()
button3->setZoomScale(0.3f);
button3->setPressedActionEnabled(true);
button3->setTitleColor(Color3B::RED);
button3->addClickEventListener([=](Object* sender) {
button3->addClickEventListener([this, pageView](Object* /*sender*/) {
pageView->removeAllItems();
_displayValueLabel->setString(
fmt::format("page count = {}", static_cast<int32_t>(pageView->getItems().size())));
@ -579,7 +579,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init()
auto button4 = (ui::Button*)button3->clone();
button4->setTitleText("Scroll to Page4");
button4->setPositionNormalized(Vec2(0.85f, 0.5f));
button4->addClickEventListener([=](Object* sender) {
button4->addClickEventListener([pageView](Object* /*sender*/) {
pageView->scrollToItem(3);
AXLOGD("current page index = {}", pageView->getCurrentPageIndex());
});

View File

@ -990,7 +990,7 @@ bool UIS9BatchTest::init()
addSpriteButton->setPosition(Vec2(winSize.width / 2 - 50, winSize.height - 100));
addSpriteButton->setTitleText("Add Normal Sprite");
std::srand((unsigned)time(nullptr));
addSpriteButton->addClickEventListener([=](Object*) {
addSpriteButton->addClickEventListener([this, spriteFrameNameArray, winSize](Object*) {
auto spriteFrameName = spriteFrameNameArray[rand() % 2];
auto sprite = Sprite::createWithSpriteFrameName(spriteFrameName);
sprite->setPosition(Vec2(rand() % (int)winSize.width + 50.0f, winSize.height / 2));
@ -1002,7 +1002,7 @@ bool UIS9BatchTest::init()
ui::Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
addSliceSpriteButton->setPosition(Vec2(winSize.width / 2 + 50, winSize.height - 100));
addSliceSpriteButton->setTitleText("Add Slice Sprite");
addSliceSpriteButton->addClickEventListener([=](Object*) {
addSliceSpriteButton->addClickEventListener([this, spriteFrameNameArray, winSize, preferedSize](Object*) {
int random = rand() % 2;
auto spriteFrameName = spriteFrameNameArray[random];
auto sprite = ui::Scale9Sprite::createWithSpriteFrameName(spriteFrameName);

View File

@ -71,7 +71,7 @@ bool WebViewTest::init()
resetBtn->setTitleText("Visit URL");
resetBtn->setPosition(Vec2(winSize / 2) + Vec2(50, _webView->getContentSize().height / 2 +
resetBtn->getContentSize().height / 2 + 10));
resetBtn->addClickEventListener([=](Object*) {
resetBtn->addClickEventListener([this, urlTextField](Object*) {
if (urlTextField->getString().size() != 0)
{
_webView->loadURL(std::string("https://").append(urlTextField->getString()));
@ -84,7 +84,7 @@ bool WebViewTest::init()
reloadBtn->setPosition(
Vec2(winSize / 2) +
Vec2(_webView->getContentSize().width / 2 + reloadBtn->getContentSize().width / 2 + 10, 50));
reloadBtn->addClickEventListener([=](Object*) { _webView->reload(); });
reloadBtn->addClickEventListener([this, reloadBtn](Object*) { _webView->reload(); });
this->addChild(reloadBtn);
Button* forwardBtn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
@ -92,7 +92,7 @@ bool WebViewTest::init()
forwardBtn->setPosition(
Vec2(winSize / 2) +
Vec2(_webView->getContentSize().width / 2 + forwardBtn->getContentSize().width / 2 + 10, 0));
forwardBtn->addClickEventListener([=](Object*) { _webView->goForward(); });
forwardBtn->addClickEventListener([this](Object*) { _webView->goForward(); });
this->addChild(forwardBtn);
Button* backBtn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
@ -100,7 +100,7 @@ bool WebViewTest::init()
backBtn->setPosition(
Vec2(winSize / 2) +
Vec2(_webView->getContentSize().width / 2 + backBtn->getContentSize().width / 2 + 10, -50));
backBtn->addClickEventListener([=](Object*) { _webView->goBack(); });
backBtn->addClickEventListener([this](Object*) { _webView->goBack(); });
this->addChild(backBtn);
Button* loadFileBtn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
@ -108,7 +108,7 @@ bool WebViewTest::init()
loadFileBtn->setPosition(
Vec2(winSize / 2) -
Vec2(_webView->getContentSize().width / 2 + loadFileBtn->getContentSize().width / 2 + 10, 50));
loadFileBtn->addClickEventListener([=](Object*) { _webView->loadFile("Test.html"); });
loadFileBtn->addClickEventListener([this](Object*) { _webView->loadFile("Test.html"); });
this->addChild(loadFileBtn);
Button* loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
@ -116,7 +116,7 @@ bool WebViewTest::init()
loadHTMLBtn->setPosition(
Vec2(winSize / 2) -
Vec2(_webView->getContentSize().width / 2 + loadHTMLBtn->getContentSize().width / 2 + 10, 0));
loadHTMLBtn->addClickEventListener([=](Object*) {
loadHTMLBtn->addClickEventListener([this](Object*) {
_webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World <img src=\"Icon.png\"/> </body>",
"Images/");
});
@ -127,7 +127,7 @@ bool WebViewTest::init()
evalJsBtn->setPosition(
Vec2(winSize / 2) -
Vec2(_webView->getContentSize().width / 2 + evalJsBtn->getContentSize().width / 2 + 10, -50));
evalJsBtn->addClickEventListener([=](Object*) { _webView->evaluateJS("alert(\"hello\")"); });
evalJsBtn->addClickEventListener([this](Object*) { _webView->evaluateJS("alert(\"hello\")"); });
evalJsBtn->setName("evalJs");
this->addChild(evalJsBtn);
@ -136,7 +136,7 @@ bool WebViewTest::init()
opacityBtn->setPosition(
Vec2(winSize / 2) -
Vec2(_webView->getContentSize().width / 2 + opacityBtn->getContentSize().width / 2 + 10, 100));
opacityBtn->addClickEventListener([=](Object*) {
opacityBtn->addClickEventListener([this, opacityBtn](Object*) {
auto currentOpacity = _webView->getOpacityWebView();
if (currentOpacity == 1.f)
{
@ -163,7 +163,7 @@ bool WebViewTest::init()
transparentBgBtn->setPosition(
Vec2(winSize / 2) +
Vec2(_webView->getContentSize().width / 2 + transparentBgBtn->getContentSize().width / 2 + 10, -100));
transparentBgBtn->addClickEventListener([=](Object*) { _webView->setBackgroundTransparent(); });
transparentBgBtn->addClickEventListener([this](Object*) { _webView->setBackgroundTransparent(); });
transparentBgBtn->setName("Transparent");
this->addChild(transparentBgBtn);