void CATextSelectView::showTextSelView(const CCRect& rect, CAView* pControlView, bool showLeft, bool showRight) { if (getSuperview() != NULL) return; CCSize winSize = CAApplication::getApplication()->getWinSize(); setFrame(CCRect(0, 0, winSize.width, winSize.height)); setColor(CAColor_clear); setTextTag("CATextSelectView"); CCRect newRect = rect; if (showLeft) { m_pCursorMarkL->setFrame(CCRect(newRect.origin.x - CATextSelectArrWidth, newRect.origin.y + newRect.size.height, CATextSelectArrWidth, CATextSelectArrHeight)); m_pCursorMarkL->setVisible(true); } if (showRight) { m_pCursorMarkR->setFrame(CCRect(newRect.origin.x + newRect.size.width, newRect.origin.y + newRect.size.height, CATextSelectArrWidth, CATextSelectArrHeight)); m_pCursorMarkR->setVisible(true); } m_pTextViewMask->setFrame(newRect); m_pTextViewMask->setVisible(true); if (CAView *rootWindow = CAApplication::getApplication()->getRootWindow()) { rootWindow->removeSubviewByTextTag("CATextSelectView"); rootWindow->addSubview(this); } becomeFirstResponder(); m_pControlView = pControlView; }
void CATextView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent) { DPoint point = this->convertTouchToNodeSpace(pTouch); if (this->getBounds().containsPoint(point)) { becomeFirstResponder(); } else { resignFirstResponder(); } }
bool CATextField::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent) { DPoint point = this->convertTouchToNodeSpace(pTouch); if (this->getBounds().containsPoint(point)) { becomeFirstResponder(); ((CATextFieldWin32*)m_pTextField)->StartMouseMove(point); } else { resignFirstResponder(); ((CATextFieldWin32*)m_pTextField)->EndMouseMoveArr(); } return true; }
void CATextToolBarView::show(CAView* pView) { CCSize winSize = CAApplication::getApplication()->getWinSize(); float alertViewButtonHeight = 88; float alertViewWidth = winSize.width * 2 / 3; CCRect rect = CCRect(winSize.width / 2, winSize.height / 2 - alertViewButtonHeight, alertViewWidth, alertViewButtonHeight); m_pBackView = CAClippingView::create(); m_pBackView->setCenter(rect); this->addSubview(m_pBackView); this->setTextTag("CATextToolBarView"); m_pBackView->setAlphaThreshold(0.5f); CAScale9ImageView *backgroundImageView = CAScale9ImageView::createWithFrame(m_pBackView->getBounds()); backgroundImageView->setImage(CAImage::create("source_material/alert_back.png")); m_pBackView->addSubview(backgroundImageView); m_pBackView->setStencil(backgroundImageView->copy()); size_t btnCount = m_CallbackTargets.size(); for (int i = 0; i < btnCount; i++) { CAButton* btn = CAButton::create(CAButtonTypeSquareRect); btn->setTitleForState(CAControlStateAll, m_CallbackTargets[i].cszButtonText.c_str()); btn->setTitleColorForState(CAControlStateAll, ccc4(3, 100, 255, 255)); btn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_clear)); btn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(ccc4(226, 226, 226, 225))); btn->setTag(i); btn->addTarget(this, CAControl_selector(CATextToolBarView::alertViewCallback), CAControlEventTouchUpInSide); btn->setFrame(CCRect(i*alertViewWidth / btnCount, 0, alertViewWidth / btnCount, alertViewButtonHeight)); m_pBackView->addSubview(btn); if (i>0) { addGrayLine(alertViewWidth/btnCount * i); } } if (CAWindow *rootWindow = CAApplication::getApplication()->getRootWindow()) { rootWindow->insertSubview(this, CAWindowZOderTop); } becomeFirstResponder(); m_pControlView = pView; }
bool CATextSelectView::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent) { CCPoint cTouchPoint = this->convertTouchToNodeSpace(pTouch); CCRect newRectL = m_pCursorMarkL->getFrame(); newRectL.InflateRect(8); CCRect newRectR = m_pCursorMarkR->getFrame(); newRectR.InflateRect(8); m_iSelViewTouchPos = 0; if (newRectL.containsPoint(cTouchPoint)) { m_iSelViewTouchPos = 1; return true; } if (newRectR.containsPoint(cTouchPoint)) { m_iSelViewTouchPos = 2; return true; } CCPoint point = this->convertTouchToNodeSpace(pTouch); CCRect ccTextRect = m_pTextViewMask->getFrame(); if (ccTextRect.containsPoint(point)) { CATextToolBarView *pToolBar = CATextToolBarView::create(); pToolBar->addButton(UTF8("\u526a\u5207"), this, callfunc_selector(CATextSelectView::ccCutToClipboard)); pToolBar->addButton(UTF8("\u590d\u5236"), this, callfunc_selector(CATextSelectView::ccCopyToClipboard)); pToolBar->addButton(UTF8("\u7c98\u8d34"), this, callfunc_selector(CATextSelectView::ccPasteFromClipboard)); pToolBar->show(); } else { if (resignFirstResponder()) { hideTextSelView(); } else { becomeFirstResponder(); } } return true; }
void CATextField::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent) { CCPoint point = this->convertTouchToNodeSpace(pTouch); if (this->getBounds().containsPoint(point)) { becomeFirstResponder(); if (isFirstResponder()) { this->showCursorMark(); if (m_nInputType == KEY_BOARD_INPUT_PASSWORD) { if (!m_sText.empty()) { m_iCurPos =(int)m_vTextFiledChars.size(); m_iString_l_length = m_cImageSize.width; } m_pCursorMark->setCenterOrigin(CCPoint(getCursorX() + m_iHoriMargins, m_obContentSize.height / 2)); return; } calculateSelChars(point, 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 } else { hideCursorMark(); if (resignFirstResponder()) { this->updateImage(); } } m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos); execCurSelCharRange(); }
void CATextView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent) { if (CATextToolBarView::isTextToolBarShow()) return; if (m_bMoved) { m_bMoved = false; return; } CCPoint point = this->convertTouchToNodeSpace(pTouch); if (this->getBounds().containsPoint(point)) { if (canAttachWithIME() && !m_pTextSelView->isTextViewShow()) { becomeFirstResponder(); int iCurLine = 0; int iCurPosX = 0; calculateSelChars(point, iCurLine, iCurPosX, m_iCurPos); m_pCursorMark->setCenterOrigin(CCPoint(iCurPosX, m_iLineHeight*1.25f*iCurLine + m_iLineHeight / 2)); CCPoint pt = m_pCursorMark->getCenterOrigin(); m_pTextArrView->showTextArrView(CCPoint(pt.x, pt.y + m_iLineHeight*1.2f + m_pContainerView->getContentOffset().y)); m_curSelCharRange = std::pair<int,int>(m_iCurPos, m_iCurPos); #if CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID CCEGLView * pGlView = CAApplication::getApplication()->getOpenGLView(); pGlView->setIMECursorPos(getStringCharCount(m_szText), getContentText()); #endif } } else { if (canDetachWithIME()) { resignFirstResponder(); } } CATouchView::ccTouchEnded(pTouch, pEvent); }
void CATextField::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent) { CATouchView::ccTouchEnded(pTouch, pEvent); if (CATextToolBarView::isTextToolBarShow()) return; if (m_bMoved) { m_bMoved = false; return; } CCPoint point = this->convertTouchToNodeSpace(pTouch); if (this->getBounds().containsPoint(point)) { if (canAttachWithIME()) { becomeFirstResponder(); calculateSelChars(point, 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 } } else { if (canDetachWithIME()) { resignFirstResponder(); } } m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos); execCurSelCharRange(); }
void CATextView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent) { CAScheduler::unschedule(schedule_selector(CATextView::ccTouchTimer), this); if (CATextToolBarView::isTextToolBarShow() || m_pTextSelView->isTextViewShow()) return; CCPoint point = this->convertTouchToNodeSpace(pTouch); if (!isScrollWindowNotOutSide()) { if (this->getBounds().containsPoint(point)) { becomeFirstResponder(); if (isFirstResponder()) { this->showCursorMark(); int iCurLine = 0; int iCurPosX = 0; calculateSelChars(point, iCurLine, iCurPosX, m_iCurPos); m_pCursorMark->setCenterOrigin(CCPoint(iCurPosX, m_iLineHeight*1.25f*iCurLine + m_iLineHeight / 2)); CCPoint pt = m_pCursorMark->getCenterOrigin(); m_pTextArrView->showTextArrView(CCPoint(pt.x, pt.y + m_iLineHeight*1.2f + getContentOffset().y)); } } else { m_pTextArrView->hideTextArrView(); m_pTextSelView->hideTextSelView(); if (resignFirstResponder()) { this->hideCursorMark(); } } } m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos); execCurSelCharRange(); CAScrollView::ccTouchEnded(pTouch, pEvent); }
void CATextView::ccTouchPress(CATouch *pTouch, CAEvent *pEvent) { if (m_pTextSelView->isTextViewShow()) return; if (CATextToolBarView::isTextToolBarShow()) return; becomeFirstResponder(); CATextToolBarView *pToolBar = CATextToolBarView::create(); if (m_szText.empty()) { pToolBar->addButton(UTF8("\u7c98\u8d34"), this, callfunc_selector(CATextView::ccPasteFromClipboard)); } else { pToolBar->addButton(UTF8("\u7c98\u8d34"), this, callfunc_selector(CATextView::ccPasteFromClipboard)); pToolBar->addButton(UTF8("\u5168\u9009"), this, callfunc_selector(CATextView::ccSelectAll)); pToolBar->addButton(UTF8("\u9009\u62e9"), this, callfunc_selector(CATextView::ccStartSelect)); } pToolBar->show(this); }
void CATextField::ccTouchPress(CATouch *pTouch, CAEvent *pEvent) { if (m_nInputType == KEY_BOARD_INPUT_PASSWORD) return; std::string cszText = CAClipboard::getText(); if (cszText.empty() && m_sText.empty()) return; becomeFirstResponder(); CATextToolBarView *pToolBar = CATextToolBarView::create(); if (m_sText.empty()) { pToolBar->addButton(UTF8("\u7c98\u8d34"), this, callfunc_selector(CATextField::ccPasteFromClipboard)); } else { pToolBar->addButton(UTF8("\u7c98\u8d34"), this, callfunc_selector(CATextField::ccPasteFromClipboard)); pToolBar->addButton(UTF8("\u5168\u9009"), this, callfunc_selector(CATextField::ccSelectAll)); pToolBar->addButton(UTF8("\u9009\u62e9"), this, callfunc_selector(CATextField::ccStartSelect)); } pToolBar->show(); }
bool CATextView::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent) { if (m_pTouches->count() > 0) { m_pTouches->replaceObjectAtIndex(0, pTouch); return true; } bool isInertia = m_tInertia.getLength() < 1.0f; if (!CAScrollView::ccTouchBegan(pTouch, pEvent)) return false; CCPoint point = this->convertTouchToNodeSpace(pTouch); if (this->getBounds().containsPoint(point)) { becomeFirstResponder(); if (isFirstResponder()) { m_pCursorMark->setVisible(true); point.y += getContentOffset().y; int iCurLine = point.y / m_iLineHeight; if (m_vLinesTextView.empty()) { iCurLine = 0; } else if (iCurLine >= m_vLinesTextView.size()) { iCurLine = m_vLinesTextView.size() - 1; } int iHalfCharSize = 0; int iStartPos = 0; if (!m_vLinesTextView.empty()) { m_iCurPos = iStartPos = m_vLinesTextView[iCurLine].iStartCharPos; std::vector<TextAttribute>& v = m_vLinesTextView[iCurLine].TextAttrVect; for (int i = 0, iStringLeftX = 0; i < v.size(); i++) { TextAttribute& t = v[i]; if (point.x >= iStringLeftX - iHalfCharSize && point.x < iStringLeftX + t.charlength / 2) { break; } iStringLeftX += t.charlength; m_iCurPos += t.charSize; iHalfCharSize = t.charlength / 2; } } std::string s = m_szText.substr(iStartPos, m_iCurPos - iStartPos); if (!s.empty() && s[0] == '\n') { s.erase(0, 1); } m_pCursorMark->setCenterOrigin(CCPoint(getStringLength(s), (iCurLine * 2 + 1) * (m_iLineHeight / 2))); } return true; } else { if (resignFirstResponder()) { m_pCursorMark->setVisible(false); return false; } return false; } return true; }
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; }