2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-18 22:52:47 +08:00
|
|
|
//
|
|
|
|
// Bug-14327.cpp
|
|
|
|
// cocos2d_tests
|
|
|
|
//
|
|
|
|
// Issue: https://github.com/cocos2d/cocos2d-x/pull/14327
|
|
|
|
// Please test in Windows
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Bug-14327.h"
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
|
|
|
bool Bug14327Layer::init()
|
|
|
|
{
|
|
|
|
if (BugsTestBase::init())
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto glview = Director::getInstance()->getOpenGLView();
|
2015-11-18 22:52:47 +08:00
|
|
|
auto visibleOrigin = glview->getVisibleOrigin();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto visibleSize = glview->getVisibleSize();
|
2015-11-18 22:52:47 +08:00
|
|
|
|
|
|
|
auto pBg = Sprite::create("Images/HelloWorld.png");
|
|
|
|
pBg->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 2));
|
|
|
|
addChild(pBg);
|
|
|
|
|
|
|
|
_removeTime = time(nullptr) + 20;
|
|
|
|
|
|
|
|
_TTFShowTime = Label::createWithSystemFont("Edit control will be removed after 00:20!", "Arial", 20);
|
2021-12-28 16:06:23 +08:00
|
|
|
_TTFShowTime->setPosition(
|
|
|
|
Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height - 60));
|
2015-11-18 22:52:47 +08:00
|
|
|
this->addChild(_TTFShowTime);
|
|
|
|
|
|
|
|
auto editBoxSize = Size(visibleSize.width - 100, visibleSize.height * 0.1);
|
|
|
|
|
|
|
|
std::string pNormalSprite = "extensions/green_edit.png";
|
|
|
|
_edit = ui::EditBox::create(editBoxSize + Size(0, 20), ui::Scale9Sprite::create(pNormalSprite));
|
|
|
|
_edit->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 2));
|
|
|
|
_edit->setFontColor(Color3B::RED);
|
|
|
|
_edit->setReturnType(ui::EditBox::KeyboardReturnType::DONE);
|
|
|
|
_edit->setDelegate(this);
|
|
|
|
this->addChild(_edit);
|
|
|
|
|
|
|
|
this->scheduleUpdate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bug14327Layer::update(float dt)
|
|
|
|
{
|
2021-09-02 13:48:05 +08:00
|
|
|
int32_t delta = _removeTime - time(nullptr);
|
2015-11-18 22:52:47 +08:00
|
|
|
if (delta > 0)
|
|
|
|
{
|
|
|
|
ldiv_t ret = ldiv(delta, 60L);
|
|
|
|
char str[100];
|
|
|
|
snprintf(str, 100, "%s%.2ld:%.2ld", "Edit control will be removed after ", ret.quot, ret.rem);
|
|
|
|
_TTFShowTime->setString(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_edit->removeFromParent();
|
|
|
|
_edit = nullptr;
|
|
|
|
_TTFShowTime->setString("Edit control has been removed!\nIt should not crash.");
|
|
|
|
this->unscheduleUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bug14327Layer::editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox)
|
|
|
|
{
|
|
|
|
log("editBox %p DidBegin !", editBox);
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void Bug14327Layer::editBoxEditingDidEndWithAction(cocos2d::ui::EditBox* editBox,
|
|
|
|
cocos2d::ui::EditBoxDelegate::EditBoxEndAction EditBoxEndAction)
|
2015-11-18 22:52:47 +08:00
|
|
|
{
|
|
|
|
log("editBox %p DidEnd !", editBox);
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:58:56 +08:00
|
|
|
void Bug14327Layer::editBoxTextChanged(cocos2d::ui::EditBox* editBox, std::string_view text)
|
2015-11-18 22:52:47 +08:00
|
|
|
{
|
2021-12-28 15:58:56 +08:00
|
|
|
log("editBox %p TextChanged, text: %s ", editBox, text.data());
|
2015-11-18 22:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Bug14327Layer::editBoxReturn(ui::EditBox* editBox)
|
|
|
|
{
|
|
|
|
log("editBox %p was returned !", editBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|