void CocosGUIExamplesRegisterScene::textFieldEvent(CCObject *pSender, TextFiledEventType type)
{
    switch (type)
    {
        case TEXTFIELD_EVENT_ATTACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            
            if (strcmp(textField->getName(), "confirm_TextField") == 0)
            {
                CCMoveBy* moveBy = CCMoveBy::create(0.1f, ccp(0, textField->getContentSize().height * 2.5));
                m_pLayout->runAction(moveBy);
            }
        }
            break;
            
        case TEXTFIELD_EVENT_DETACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            
            if (strcmp(textField->getName(), "confirm_TextField") == 0)
            {
                CCMoveBy* moveBy = CCMoveBy::create(0.1f, ccp(0, -textField->getContentSize().height * 2.5));
                m_pLayout->runAction(moveBy);
            }
        }
            break;
            
        default:
            break;
    }
}
void UITextFieldTest::textFieldEvent(Ref *pSender, TextField::EventType type)
{
    switch (type)
    {
        case TextField::EventType::ATTACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size screenSize = CCDirector::getInstance()->getWinSize();
            textField->runAction(CCMoveTo::create(0.225f,
                                                  Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
            _displayValueLabel->setString(String::createWithFormat("attach with IME")->getCString());
        }
            break;
            
        case TextField::EventType::DETACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size screenSize = CCDirector::getInstance()->getWinSize();
            textField->runAction(CCMoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)));
            _displayValueLabel->setString(String::createWithFormat("detach with IME")->getCString());
        }
            break;
            
        case TextField::EventType::INSERT_TEXT:
            _displayValueLabel->setString(String::createWithFormat("insert words")->getCString());
            break;
            
        case TextField::EventType::DELETE_BACKWARD:
            _displayValueLabel->setString(String::createWithFormat("delete word")->getCString());
            break;
            
        default:
            break;
    }
}
void UITextFieldTest::textFieldEvent(Ref *pSender, TextFiledEventType type)
{
    switch (type)
    {
        case TEXTFIELD_EVENT_ATTACH_WITH_IME:
        {
            
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size screenSize = CCDirector::getInstance()->getWinSize();
            textField->runAction(CCMoveTo::create(0.225f,
                                                  Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
#endif
            _displayValueLabel->setText(String::createWithFormat("attach with IME")->getCString());
        }
            break;
            
        case TEXTFIELD_EVENT_DETACH_WITH_IME:
        {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size screenSize = CCDirector::getInstance()->getWinSize();
            textField->runAction(CCMoveTo::create(0.175f, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
#endif
            _displayValueLabel->setText(String::createWithFormat("detach with IME")->getCString());
        }
            break;
            
        case TEXTFIELD_EVENT_INSERT_TEXT:
            _displayValueLabel->setText(String::createWithFormat("insert words")->getCString());
            break;
            
        case TEXTFIELD_EVENT_DELETE_BACKWARD:
            _displayValueLabel->setText(String::createWithFormat("delete word")->getCString());
            break;
            
        default:
            break;
    }
}
示例#4
0
bool WebViewTest::init()
{
    if (UIScene::init()) {
        Size winSize = Director::getInstance()->getVisibleSize();

        
        _webView = cocos2d::experimental::ui::WebView::create();
        _webView->setPosition(winSize/2);
        _webView->setContentSize(winSize * 0.5);
        _webView->loadURL("http://www.google.com");
        _webView->setScalesPageToFit(true);
        
        _webView->setOnShouldStartLoading(CC_CALLBACK_2(WebViewTest::onWebViewShouldStartLoading, this));
        _webView->setOnDidFinishLoading(CC_CALLBACK_2(WebViewTest::onWebViewDidFinishLoading, this));
        _webView->setOnDidFailLoading(CC_CALLBACK_2(WebViewTest::onWebViewDidFailLoading, this));
        
        this->addChild(_webView);
        
        TextField *urlTextField = TextField::create("Input a URL here", "Arial", 20);
        urlTextField->setPlaceHolderColor(Color3B::RED);
        urlTextField->setPosition(Vec2(winSize/2) + Vec2(-80, _webView->getContentSize().height/2 +
                                                     urlTextField->getContentSize().height/2 + 10));
        this->addChild(urlTextField);
        
        Text *httpLabel = Text::create("http:// ", "Arial", 20);
        httpLabel->setTextColor(Color4B::GREEN);
        httpLabel->setAnchorPoint(Vec2(1.0,0.5));
        httpLabel->setPosition(urlTextField->getPosition() - Vec2(urlTextField->getContentSize().width/2,0));
        this->addChild(httpLabel);
        
        
        Button *resetBtn = Button::create("cocosui/animationbuttonnormal.png",
                                       "cocosui/animationbuttonpressed.png");
        resetBtn->setTitleText("Visit URL");
        resetBtn->setPosition(Vec2(winSize/2) + Vec2(50, _webView->getContentSize().height/2 +
                                            resetBtn->getContentSize().height/2 + 10));
        resetBtn->addClickEventListener([=](Ref*){
            _webView->loadURL(std::string("http://") + urlTextField->getString());
        });
        this->addChild(resetBtn);
        
        
        Button *reloadBtn = Button::create("cocosui/animationbuttonnormal.png",
                                          "cocosui/animationbuttonpressed.png");
        reloadBtn->setTitleText("Reload");
        reloadBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
                                                      reloadBtn->getContentSize().width/2 + 10,50 ));
        reloadBtn->addClickEventListener([=](Ref*){
            _webView->reload();
        });
        this->addChild(reloadBtn);
        
        Button *forwardBtn = Button::create("cocosui/animationbuttonnormal.png",
                                           "cocosui/animationbuttonpressed.png");
        forwardBtn->setTitleText("Forward");
        forwardBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
                                                      forwardBtn->getContentSize().width/2 + 10,0 ));
        forwardBtn->addClickEventListener([=](Ref*){
            _webView->goForward();
        });
        this->addChild(forwardBtn);
        
        
        
        Button *backBtn = Button::create("cocosui/animationbuttonnormal.png",
                                           "cocosui/animationbuttonpressed.png");
        backBtn->setTitleText("Back");
        backBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
                                                      backBtn->getContentSize().width/2 + 10,-50 ));
        backBtn->addClickEventListener([=](Ref*){
            _webView->goBack();
        });
        this->addChild(backBtn);
        
        
        Button *loadFileBtn = Button::create("cocosui/animationbuttonnormal.png",
                                           "cocosui/animationbuttonpressed.png");
        loadFileBtn->setTitleText("Load FILE");
        loadFileBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
                                                      loadFileBtn->getContentSize().width/2 + 10,50 ));
        loadFileBtn->addClickEventListener([=](Ref*){
            _webView->loadFile("Test.html");
        });
        this->addChild(loadFileBtn);
        
        Button *loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png",
                                            "cocosui/animationbuttonpressed.png");
        loadHTMLBtn->setTitleText("Load HTML");
        loadHTMLBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
                                                       loadHTMLBtn->getContentSize().width/2 + 10,0 ));
        loadHTMLBtn->addClickEventListener([=](Ref*){
            _webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World</body>","text/html");
        });
        this->addChild(loadHTMLBtn);
        
        
        
        
        Button *evalJsBtn = Button::create("cocosui/animationbuttonnormal.png",
                                         "cocosui/animationbuttonpressed.png");
        evalJsBtn->setTitleText("Evaluate JS");
        evalJsBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
                                                    evalJsBtn->getContentSize().width/2 + 10,-50 ));
        evalJsBtn->addClickEventListener([=](Ref*){
            _webView->evaluateJS("alert(\"hello\")");
        });
        this->addChild(evalJsBtn);
        
        return true;
    }
    return false;
}
示例#5
0
void UITextFieldTest_MaxLength::textFieldEvent(Object *pSender, TextFiledEventType type)
{
    switch (type)
    {
        case TEXTFIELD_EVENT_ATTACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size screenSize = CCDirector::getInstance()->getWinSize();
            textField->runAction(CCMoveTo::create(0.225f,
                                                  Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
            _displayValueLabel->setText(String::createWithFormat("attach with IME max length %d", textField->getMaxLength())->getCString());
        }
            break;
            
        case TEXTFIELD_EVENT_DETACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size screenSize = CCDirector::getInstance()->getWinSize();
            textField->runAction(CCMoveTo::create(0.175f, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
            _displayValueLabel->setText(String::createWithFormat("detach with IME max length %d", textField->getMaxLength())->getCString());
        }
            break;
            
        case TEXTFIELD_EVENT_INSERT_TEXT:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            _displayValueLabel->setText(String::createWithFormat("insert words max length %d", textField->getMaxLength())->getCString());
        }
            break;
            
        case TEXTFIELD_EVENT_DELETE_BACKWARD:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            _displayValueLabel->setText(String::createWithFormat("delete word max length %d", textField->getMaxLength())->getCString());
        }
            break;
            
        default:
            break;
    }
}
示例#6
0
void UITextFieldTest_LineWrap::textFieldEvent(Ref *pSender, TextField::EventType type)
{
    switch (type)
    {
        case TextField::EventType::ATTACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size widgetSize = _widget->getContentSize();
            textField->runAction(CCMoveTo::create(0.225f,
                                                  Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + textField->getContentSize().height / 2)));
            textField->setTextHorizontalAlignment(TextHAlignment::LEFT);
            textField->setTextVerticalAlignment(TextVAlignment::TOP);
            
            _displayValueLabel->setString(CCString::createWithFormat("attach with IME")->getCString());
        }
            break;
            
        case TextField::EventType::DETACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size widgetSize = _widget->getContentSize();
            textField->runAction(CCMoveTo::create(0.175f, Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)));
            textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
            textField->setTextVerticalAlignment(TextVAlignment::CENTER);
            
            _displayValueLabel->setString(CCString::createWithFormat("detach with IME")->getCString());
        }
            break;
            
        case TextField::EventType::INSERT_TEXT:
            _displayValueLabel->setString(CCString::createWithFormat("insert words")->getCString());
            break;
            
        case TextField::EventType::DELETE_BACKWARD:
            _displayValueLabel->setString(CCString::createWithFormat("delete word")->getCString());
            break;
            
        default:
            break;
    }
}