Пример #1
0
bool CATextField::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    CCPoint point = this->convertTouchToNodeSpace(pTouch);
    
    if (this->getBounds().containsPoint(point))
    {
        if (attachWithIME())
        {
            m_pMark->setCenterOrigin(CCPoint(m_pText->getLabelSize().width, this->getBounds().size.height/2));
            m_pMark->setVisible(true);
        }

        return true;
    }
    else
    {
        if (detachWithIME())
        {
            if (!strcmp(m_pText->getText().c_str(), ""))
            {
                m_pText->setTextcolor(m_cSpaceHolderColor);
                m_pText->setText(m_sPlaceHolder);
                spaceHolderIsOn=true;
            }
            m_pMark->setVisible(false);
            return false;
        }
        return false;
    }
    
    return false;
}
Пример #2
0
bool CATextView::resignFirstResponder()
{
	bool result = CAView::resignFirstResponder();
	if (result)
	{
		detachWithIME();
	}
	return result;
}
Пример #3
0
bool CATextField::resignFirstResponder()
{
	bool result = CAView::resignFirstResponder();
    if (result)
    {
		result = detachWithIME();
        hideCursorMark();
    }
    return result;
}
void TextFieldTTF::insertText(const char * text, size_t len)
{
    std::string insert(text, len);

    // insert \n means input end
    int pos = static_cast<int>(insert.find((char)TextFormatter::NewLine));
    if ((int)insert.npos != pos)
    {
        len = pos;
        insert.erase(pos);
    }

    if (len > 0)
    {
        if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len))
        {
            // delegate doesn't want to insert text
            return;
        }

        int countInsertChar = _calcCharCount(insert.c_str());
        _charCount += countInsertChar;

        if (_cursorEnabled)
        {
            StringUtils::StringUTF8 stringUTF8;

            stringUTF8.replace(_inputText);
            stringUTF8.insert(_cursorPosition, insert);

            setCursorPosition(_cursorPosition + countInsertChar);

            setString(stringUTF8.getAsCharSequence());
        }
        else
        {
            std::string sText(_inputText);
            sText.append(insert);
            setString(sText);
        }
    }

    if ((int)insert.npos == pos) {
        return;
    }

    // '\n' inserted, let delegate process first
    if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1))
    {
        return;
    }

    // if delegate hasn't processed, detach from IME by default
    detachWithIME();
}
Пример #5
0
bool CATextField::resignFirstResponder()
{
	bool result = CAView::resignFirstResponder();
    if (result)
    {
		detachWithIME();
        hideCursorMark();
        //this->updateImage();
    }
    return result;
}
Пример #6
0
bool CATextView::resignFirstResponder()
{
	bool result = CAView::resignFirstResponder();
	if (result)
	{
		detachWithIME();
		hideCursorMark();
        m_pTextSelView->hideTextSelView();
	}
	return result;
}
Пример #7
0
void CCTextFieldTTF::insertText(const char * text, int len)
{
    std::string sInsert(text, len);

    // insert \n means input end
    int nPos = sInsert.find('\n');
    if ((int)sInsert.npos != nPos)
    {
        len = nPos;
        sInsert.erase(nPos);
    }
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
    {
        // delegate doesn't want insert text
        return;
    }
    
    m_nCharCount += _calcCharCount(sInsert.c_str());
    std::string sText(*m_pInputText);
    sText.swap(sInsert);
    setString(sText.c_str());
#else
    if (len > 0)
    {
        if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
        {
            // delegate doesn't want insert text
            return;
        }
        
        m_nCharCount += _calcCharCount(sInsert.c_str());
        std::string sText(*m_pInputText);
        sText.append(sInsert);
        setString(sText.c_str());
    }
#endif
    if ((int)sInsert.npos == nPos) {
        return;
    }
    
    // '\n' has inserted,  let delegate process first
    if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
    {
        return;
    }
    
    // if delegate hasn't process, detach with ime as default
    detachWithIME();
}
void TextFieldTTF::controlKey(EventKeyboard::KeyCode keyCode)
{
    if (_cursorEnabled)
    {
        switch (keyCode)
        {
        case EventKeyboard::KeyCode::KEY_HOME:
        case EventKeyboard::KeyCode::KEY_KP_HOME:
            setCursorPosition(0);
            updateCursorDisplayText();
            break;
        case EventKeyboard::KeyCode::KEY_END:
            setCursorPosition(_charCount);
            updateCursorDisplayText();
            break;
        case EventKeyboard::KeyCode::KEY_DELETE:
        case EventKeyboard::KeyCode::KEY_KP_DELETE:
            if (_cursorPosition < (std::size_t)_charCount)
            {
                StringUtils::StringUTF8 stringUTF8;

                stringUTF8.replace(_inputText);
                stringUTF8.deleteChar(_cursorPosition);
                setCursorPosition(_cursorPosition);
                _charCount = stringUTF8.length();
                setString(stringUTF8.getAsCharSequence());
            }
            break;
        case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
            if (_cursorPosition)
            {
                setCursorPosition(_cursorPosition - 1);
                updateCursorDisplayText();
            }
            break;
        case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
            if (_cursorPosition < (std::size_t)_charCount)
            {
                setCursorPosition(_cursorPosition + 1);
                updateCursorDisplayText();
            }
            break;
        case EventKeyboard::KeyCode::KEY_ESCAPE:
            detachWithIME();
            break;
        default:
            break;
        }
    }
}
Пример #9
0
void PathEditor::setEnabled( bool var )
{
	if( var )
		attachWithIME();
	else
		detachWithIME();
	m_enabled = var;
	m_menuMaps->setVisible( var );
	m_menu->setVisible( var );
	m_labelStart->setVisible( var );
	m_labelFinish->setVisible( var );
	setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
	setTouchEnabled(var);
}
Пример #10
0
void TextFieldTTF::insertText(const char * text, size_t len)
{
    std::string insert(text, len);

    // insert \n means input end
    int pos = static_cast<int>(insert.find('\n'));
    if ((int)insert.npos != pos)
    {
        len = pos;
        insert.erase(pos);
    }

    if (len > 0)
    {
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8 && CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
        if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len))
        {
            // delegate doesn't want to insert text
            return;
        }

        _charCount += _calcCharCount(insert.c_str());
        std::string sText(_inputText);
        sText.append(insert);
        setString(sText);
#else
        size_t existlen = _inputText.length();
        if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str() + existlen, len - existlen))
        {
            // delegate doesn't want to insert text
            return;
        }
        setString(insert);
#endif
    }

    if ((int)insert.npos == pos) {
        return;
    }

    // '\n' inserted, let delegate process first
    if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1))
    {
        return;
    }

    // if delegate hasn't processed, detach from IME by default
    detachWithIME();
}
Пример #11
0
void CCTextFieldTTF::insertText(const char * text, int len)
{
    std::string sInsert(text, len);

    // insert \n means input end
    int nPos = sInsert.find('\n');
    //找到了 换行符号 输入就是 -1  len = -1
    //支持换行符
    if (!isMultiLine) {
        if ((int)sInsert.npos != nPos)
        {
            len = nPos;
            sInsert.erase(nPos);
        }
    }
    
    //换行符就不输入文字了
    if (len > 0)
    {
        //代理处理插入了字符 只在有最长限制的时候
        if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
        {
            // delegate doesn't want to insert text
            return;
        }

        m_nCharCount += _calcCharCount(sInsert.c_str());
        std::string sText(*m_pInputText);
        sText.append(sInsert);
        setString(sText.c_str());
    }

    //不是换行符 处理完毕 或者支持多行文本
    if (isMultiLine || (int)sInsert.npos == nPos) {
        return;
    }

    //代理处理换行符
    // '\n' inserted, let delegate process first
    if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
    {
        return;
    }

    //当点击背后的屏幕的时候 没有在键盘范围则退出场景即可
    // if delegate hasn't processed, detach from IME by default
    detachWithIME();
}
void TextFieldTTFActionTest::onClickTrackNode(bool bClicked)
{
    auto pTextField = (TextFieldTTF*)_trackNode;
    if (bClicked)
    {
        // TextFieldTTFTest be clicked
        CCLOG("TextFieldTTFActionTest:TextFieldTTF attachWithIME");
        pTextField->attachWithIME();
    }
    else
    {
        // TextFieldTTFTest not be clicked
        CCLOG("TextFieldTTFActionTest:TextFieldTTF detachWithIME");
        pTextField->detachWithIME();
    }
}
Пример #13
0
void CCTextFieldTTF::insertText(const char * text, int len)
{
    std::string sInsert(text, len);

    // insert \n means input end
    int nPos = sInsert.find('\n');
    if ((int)sInsert.npos != nPos)
    {
        len = nPos;
        sInsert.erase(nPos);
    }

    if (len > 0)
    {
        if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
        {
            // delegate doesn't want to insert text
            return;
        }

        m_nCharCount += _calcCharCount(sInsert.c_str());
        std::string sText(*m_pInputText);
        sText.append(sInsert);
        setString(sText.c_str());
        //////
        
    
        ///////
   
     
    }

    if ((int)sInsert.npos == nPos) {
        return;
    }

    // '\n' inserted, let delegate process first
    if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
    {
        return;
    }

    // if delegate hasn't processed, detach from IME by default
    detachWithIME();
}
Пример #14
0
bool TextBox::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	// Final position
	CCPoint* finalPosition = new CCPoint(pTouch->getLocationInView().x, size.height - pTouch->getLocationInView().y);
	*finalPosition = this->getParent()->convertToNodeSpace(*finalPosition);

	// If it is active and user clicked outside text box
	if (_is_active && !Objects2dHandler::isPositionInsideNode(finalPosition, this))
	{
		// Activate text box
		detachWithIME();
	}
	// If it is not active and user clicked inside text box
	else if (!_is_active && Objects2dHandler::isPositionInsideNode(finalPosition, this))
	{
		// Deactivate text box
		attachWithIME();
	}
	
	// Call other touch events
	return false;
}
Пример #15
0
void CATextField::resignResponder()
{
	detachWithIME();
	hideCursorMark();
}
Пример #16
0
void CCtrlTextFieldTTF::insertText(const char * text, int len)
{
	std::string sInsert(text, len);

	// insert \n means input end
	int nPos = sInsert.find('\n');
	if ((int)sInsert.npos != nPos)
	{
		len = nPos;
		sInsert.erase(nPos);
	}

	if (len > 0)
	{
		if (EditInputFlagAll == m_nInputType)
		{
			if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
			{
				// delegate doesn't want to insert text
				return;
			}

			m_strText.append(sInsert);
			m_nCharCount += _calcCharCount(sInsert.c_str());
			std::string sText(*m_pInputText);
			sText.append(sInsert);
			setString(sText.c_str());
		}
		else if (EditInputFlagPassword == m_nInputType)
		{
			int nInsertSize = _calcCharCount(sInsert.c_str());
			std::string strInsert = "";
			for (int i=0; i<nInsertSize; ++i)
			{
				strInsert.append("*");
			}

			if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, strInsert.c_str(), nInsertSize))
			{
				// delegate doesn't want to insert text
				return;
			}

			m_strText.append(sInsert);
			m_nCharCount += nInsertSize;
			std::string sText(*m_pInputText);
			sText.append(strInsert);			

			setString(sText.c_str());
		}

		if (EventChanged)
		{
			EventChanged();
		}
	}

	if ((int)sInsert.npos == nPos) {
		return;
	}

	// '\n' inserted, let delegate process first
	if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
	{
		return;
	}

	// if delegate hasn't processed, detach from IME by default
	detachWithIME();
}
Пример #17
0
bool MapMakerScene::init()
{
	if (!Layer::init())
	{
		return false;
	}
	m_lastSelectGroup = nullptr;
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	auto s = Director::getInstance()->getWinSize();
	//input map name
	auto pTextField = TextFieldTTF::textFieldWithPlaceHolder(std::string(LocalizedCStringByKey("input_map_name")),
		"fonts/arial.ttf",
		48);
	addChild(pTextField,0,"tbMapName");
	pTextField->setPosition(Vec2(s.width / 2,s.height - 250));

	//输入事件
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [pTextField](Touch* touch, Event*)
	{
		auto beginPos = touch->getLocation();
		Rect rect;
		rect.size = pTextField->getContentSize();
		auto clicked = isScreenPointInRect(beginPos, Camera::getVisitingCamera(), pTextField->getWorldToNodeTransform(), rect, nullptr);
		if (clicked)
		{
			return true;
		}
		pTextField->detachWithIME();
		return false;
	};
	listener->onTouchEnded = [pTextField](Touch* touch, Event* event)
	{
		auto endPos = touch->getLocation();
		Rect rect;
		rect.size = pTextField->getContentSize();
		auto clicked = isScreenPointInRect(endPos, Camera::getVisitingCamera(), pTextField->getWorldToNodeTransform(), rect, nullptr);
		if (clicked)
		{
			pTextField->attachWithIME();
		}

	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	//返回主菜单
	auto returnToMainMenuItem = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
		CC_CALLBACK_1(MapMakerScene::returnToMainMenuCallback, this)
		);
	returnToMainMenuItem->setPosition(Vec2(origin.x + visibleSize.width - returnToMainMenuItem->getContentSize().width / 2,
		origin.y + returnToMainMenuItem->getContentSize().height / 2));
	auto menu = Menu::create(returnToMainMenuItem, NULL);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 1);
    
	//baseplate
    auto baseplateLayer = SquareBaseplateLayer::create();
    baseplateLayer->createEmptyMap(BaseSize(15,15));
    baseplateLayer->drawBasesplate(Vec2(32,32));
    baseplateLayer->setPosition(Vec2(100,200));
    addChild(baseplateLayer);
    

    //菜单,创建group
    auto menuItemCreateGroup = MenuItemFont::create(LocalizedCStringByKey("create_group"));
    menuItemCreateGroup->setCallback(
    [=](Ref*)
    {
        auto squareGroup = SquareGroupMapMaker::create();
        squareGroup->setPosition(Vec2(100,100));
        squareGroup->SetSquareGroup(Vec2(32,32),SquareGroup::SQUAREGROUP_TYPE::ST_Z,Square::SQUARE_COLOR::SC_GREEN);
        squareGroup->DrawGroup();
		squareGroup->setSelectedListener(
			[=](SquareGroup* sg)
		{
			m_lastSelectGroup = sg;
		});
        this->addChild(squareGroup);
    }
    );
	//菜单,删除group
    auto menuItemDeleteSelectedGroup = MenuItemFont::create(LocalizedCStringByKey("delete_group"));
    menuItemDeleteSelectedGroup->setCallback(
    [=](Ref*)
    {
        for(Node* node:this->getChildren())
        {
			SquareGroupMapMaker* sg = dynamic_cast<SquareGroupMapMaker*>(node);
            if(sg != nullptr)
            {
                if(sg->getGroupState() == SGS_SELECTED)
                {
					assert(m_lastSelectGroup == sg);
					
					m_lastSelectGroup = nullptr;
                    this->removeChild(node);
                }
            }
        }
    }
    );
	//菜单,保存地图
    auto menuItemSaveMap = MenuItemFont::create(LocalizedCStringByKey("save_map"));
    menuItemSaveMap->setCallback(
    [=](Ref*)
    {
		saveMapToFile();
    }
    );
    //创建菜单组
    auto operationMenu = Menu::create(menuItemCreateGroup,menuItemDeleteSelectedGroup,menuItemSaveMap, NULL);
    operationMenu->alignItemsVerticallyWithPadding(20);
    
    addChild(operationMenu);
    operationMenu->setPosition(Vec2(s.width / 2, s.height - 100));
    
	//产生本地图的guid
	m_guid = std::string(GameUilityTools::CreateGuidString());

	//添加选择颜色的层
	auto colorLayer = SelectColorLayer::create();
	colorLayer->setPosition(Vec2(0, 0));
	colorLayer->setColorChangeListener(
		[=](Square::SQUARE_COLOR color){
		//todo xuhua
		if (m_lastSelectGroup)
		{
			m_lastSelectGroup->setSquareGroupColor(color);
			m_lastSelectGroup->DrawGroup();
		}
	}
		);
	addChild(colorLayer, 0);
	return true;
}
Пример #18
0
void CATextField::insertText(const char * text, int len)
{
    if (spaceHolderIsOn)
    {
        m_pText->setText("");
        m_pText->setTextcolor(m_cTextColor);
        spaceHolderIsOn=false;
        
    }
    std::string sInsert(text, len);
    
    // insert \n means input end
    int nPos = sInsert.find('\n');
    if ((int)sInsert.npos != nPos)
    {
        len = nPos;
        sInsert.erase(nPos);
    }
    
    if (len > 0)
    {
        if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
        {
            
            
            // delegate doesn't want to insert text
            return;
        }
        m_nCharCount += _calcCharCount(sInsert.c_str());
        std::string sText(m_pText->getText());
        std::string oldstr = sText;
        sText.append(sInsert);
        
        float length = 0;
        
        m_pText->setText(sText.c_str());
        
        CCRect rect = CCRectZero;
        rect.size = this->getBounds().size;
        rect.size.width = MIN(this->getBounds().size.width, m_pText->getLabelSize().width);
        
        if (m_pText->getLabelSize().width < this->getBounds().size.width)
        {
            m_pText->setFrame(rect);
            m_pMark->setCenterOrigin(CCPoint(m_pText->getLabelSize().width, this->getBounds().size.height/2));
        }
        else
        {
            m_pText->setText(oldstr);
            m_pText->setFrame(rect);
            m_pMark->setCenterOrigin(CCPoint(m_pText->getLabelSize().width, this->getBounds().size.height/2));
        }
        
        if (_oldPos != 0)
        {
            length = m_pText->getLabelSize().width - _oldPos;
        }
        else
        {
            length = m_pText->getLabelSize().width;
        }
        
    }
    
    if ((int)sInsert.npos == nPos) {
        return;
    }
    
    if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
    {
        return;
    }
    
    // if delegate hasn't processed, detach from IME by default
    detachWithIME();
}