Ejemplo n.º 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;
}
Ejemplo n.º 2
0
bool CATextField::becomeFirstResponder()
{
	bool result = CAView::becomeFirstResponder();
    if (result) 
	{
		attachWithIME();
        this->showCursorMark();
        if (m_nInputType == KEY_BOARD_INPUT_PASSWORD)
        {
            if (m_sText.empty())
            {
                m_pCursorMark->setCenterOrigin(CCPoint(getCursorX() + m_iHoriMargins, m_obContentSize.height / 2));
            }
        }
        calculateSelChars(CCPoint(this->getCursorX() + m_iHoriMargins, m_obContentSize.height / 2), m_iString_l_length, m_iString_r_length, m_iCurPos);
        
        m_pCursorMark->setCenterOrigin(CCPoint(getCursorX() + m_iHoriMargins, m_obContentSize.height / 2));

#if CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID
        CCEGLView * pGlView = CAApplication::getApplication()->getOpenGLView();
        pGlView->setIMECursorPos(getCursorPos(), getContentText());
#endif
    }
    return result;
}
Ejemplo n.º 3
0
bool CATextView::becomeFirstResponder()
{
	bool result = CAView::becomeFirstResponder();
	if (result)
	{
		attachWithIME();
	}
	return result;
}
Ejemplo n.º 4
0
bool CATextView::becomeFirstResponder()
{
	bool result = CAView::becomeFirstResponder();
	if (result)
	{
		result = attachWithIME();
		showCursorMark();
	}
	return result;
}
Ejemplo n.º 5
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);
}
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();
    }
}
Ejemplo n.º 7
0
bool CATextField::becomeFirstResponder()
{
	resignAllResponder(this);
    
	bool result = CAView::becomeFirstResponder();
    if (result) 
	{
		result = attachWithIME();
        this->showCursorMark();

        calculateSelChars(CCPoint(this->getCursorX() + m_iHoriMargins, m_obContentSize.height / 2), m_iString_l_length, m_iString_r_length, m_iCurPos);
        setCursorPosition();

#if CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID
        CCEGLView * pGlView = CAApplication::getApplication()->getOpenGLView();
        pGlView->setIMECursorPos(getCursorPos(), getContentText());
#endif
    }
    return result;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
void InputLabel::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
    CCLog("------------------------inputlabel touched");
    attachWithIME();
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
bool CATextField::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent)
{
    if (isEditing)
    {
        return false;
    }
    CCPoint point = this->convertTouchToNodeSpace(pTouch);

    if (this->getBounds().containsPoint(point))
    {
        becomeFirstResponder();
        if (isFirstResponder())
        {

            m_pMark->setVisible(true);
            attachWithIME();

            if (m_nInputType ==KEY_BOARD_INPUT_PASSWORD)
            {
                m_pMark->setCenterOrigin(CCPoint(labelOrginX+m_rLabelRect.size.width, this->getBounds().size.height/2));
                return true;
            }
            m_fString_left_length = 0;
            int byteCount = 0;
            for (std::vector<TextAttribute>::iterator itr = m_vByteLengthArr.begin(); itr!=m_vByteLengthArr.end(); itr++)
            {
                TextAttribute t =*(itr);
                m_fString_left_length+=t.charlength;
                byteCount += t.charsize;
                if (m_fString_left_length>point.x-m_fString_left_offX)
                {
                    m_sLeft_string = m_sText.substr(0,byteCount);
                    m_sRight_string = m_sText.substr(byteCount,m_sText.length());
                    m_fString_right_length = m_rLabelRect.size.width-m_fString_left_length;
                    break;
                } else if(itr == m_vByteLengthArr.end()-1&&!spaceHolderIsOn)
                {
                    m_sLeft_string = m_sText.substr(0,byteCount);
                    m_sRight_string = m_sText.substr(byteCount,m_sText.length());
                    m_fString_right_length = m_rLabelRect.size.width-m_fString_left_length;
                }

            }
            m_pMark->setCenterOrigin(CCPoint(getCursorX()+labelOrginX, this->getBounds().size.height/2));


        }
        return true;
    }
    else
    {
        if (resignFirstResponder())
        {
            if (!strcmp(m_sText.c_str(), ""))
            {
                m_sText="";
                spaceHolderIsOn=true;
                this->updateImage();
            }
            m_pMark->setVisible(false);
            return false;
        }
        return false;
    }

    return true;
}