PuzzleSDK
Bug-14327.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
25//
26// Bug-14327.cpp
27// cocos2d_tests
28//
29// Issue: https://github.com/cocos2d/cocos2d-x/pull/14327
30// Please test in Windows
31//
32//
33
34#include "Bug-14327.h"
35
36#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
37
39
41{
42 if (BugsTestBase::init())
43 {
44 auto glview = Director::getInstance()->getOpenGLView();
45 auto visibleOrigin = glview->getVisibleOrigin();
46 auto visibleSize = glview->getVisibleSize();
47
48 auto pBg = Sprite::create("Images/HelloWorld.png");
49 pBg->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 2));
50 addChild(pBg);
51
52 _removeTime = time(nullptr) + 20;
53
54 _TTFShowTime = Label::createWithSystemFont("Edit control will be removed after 00:20!", "Arial", 20);
55 _TTFShowTime->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height - 60));
56 this->addChild(_TTFShowTime);
57
58
59 auto editBoxSize = Size(visibleSize.width - 100, visibleSize.height * 0.1);
60
61 std::string pNormalSprite = "extensions/green_edit.png";
62 _edit = ui::EditBox::create(editBoxSize + Size(0, 20), ui::Scale9Sprite::create(pNormalSprite));
63 _edit->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 2));
64 _edit->setFontColor(Color3B::RED);
65 _edit->setReturnType(ui::EditBox::KeyboardReturnType::DONE);
66 _edit->setDelegate(this);
67 this->addChild(_edit);
68
69 this->scheduleUpdate();
70 return true;
71 }
72
73 return false;
74}
75
77{
78 long delta = _removeTime - time(nullptr);
79 if (delta > 0)
80 {
81 ldiv_t ret = ldiv(delta, 60L);
82 char str[100];
83 snprintf(str, 100, "%s%.2ld:%.2ld", "Edit control will be removed after ", ret.quot, ret.rem);
84 _TTFShowTime->setString(str);
85 }
86 else
87 {
88 _edit->removeFromParent();
89 _edit = nullptr;
90 _TTFShowTime->setString("Edit control has been removed!\nIt should not crash.");
91 this->unscheduleUpdate();
92 }
93}
94
95void Bug14327Layer::editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox)
96{
97 log("editBox %p DidBegin !", editBox);
98}
99
100void Bug14327Layer::editBoxEditingDidEndWithAction(cocos2d::ui::EditBox* editBox, cocos2d::ui::EditBoxDelegate::EditBoxEndAction EditBoxEndAction)
101{
102 log("editBox %p DidEnd !", editBox);
103}
104
105void Bug14327Layer::editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text)
106{
107 log("editBox %p TextChanged, text: %s ", editBox, text.c_str());
108}
109
110void Bug14327Layer::editBoxReturn(ui::EditBox* editBox)
111{
112 log("editBox %p was returned !", editBox);
113}
114
115#endif
USING_NS_CC
Definition: Bug-14327.cpp:38
virtual bool init() override
Definition: Bug-14327.cpp:40
cocos2d::Label * _TTFShowTime
Definition: Bug-14327.h:53
virtual void editBoxTextChanged(cocos2d::ui::EditBox *editBox, const std::string &text) override
Definition: Bug-14327.cpp:105
virtual void editBoxReturn(cocos2d::ui::EditBox *editBox) override
Definition: Bug-14327.cpp:110
virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox *editBox) override
Definition: Bug-14327.cpp:95
virtual void editBoxEditingDidEndWithAction(cocos2d::ui::EditBox *editBox, cocos2d::ui::EditBoxDelegate::EditBoxEndAction EditBoxEndAction) override
Definition: Bug-14327.cpp:100
virtual void update(float dt) override
Definition: Bug-14327.cpp:76
time_t _removeTime
Definition: Bug-14327.h:52
cocos2d::ui::EditBox * _edit
Definition: Bug-14327.h:54