Exemplo n.º 1
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;
}
Exemplo n.º 2
0
void CATextField::adjustCursorMoveBackward()
{
	this->updateImage();
    
	m_iString_l_length = getStringLength(m_sText.substr(0, m_iCurPos));
	m_iString_r_length = m_cImageSize.width - m_iString_l_length;
    
	if (getCursorX() <= 0)
	{
		m_iString_left_offX = -m_iString_l_length;
	}
	else
	{
		if (m_iString_r_length + getCursorX() < m_iLabelWidth)
		{
			m_iString_left_offX = MIN(0, m_iLabelWidth - m_cImageSize.width);
		}
	}
	CCRect r = CCRectMake(0, 0, m_cImageSize.width, m_cImageSize.height);
	r.origin.x = -m_iString_left_offX;
	r.size.width = getStringViewLength();
	this->setImageRect(r);
    
    if (m_nInputType == KEY_BOARD_INPUT_PASSWORD)
    {
        //float mPmarkWidth = MIN(m_obContentSize.width, getCursorX());
        m_pCursorMark->setCenterOrigin(CCPoint(this->getImageRect().size.width + m_iHoriMargins, m_obContentSize.height / 2));
    }
    else
    {
        float mPmarkWidth = MIN(m_obContentSize.width, getCursorX());
        m_pCursorMark->setCenterOrigin(CCPoint(mPmarkWidth + m_iHoriMargins, m_obContentSize.height / 2));
    }
}
Exemplo n.º 3
0
void decrementCursor() {
	if (getCursorX() < 1) {
		if (getCursorY() < 1) {
			setCursorY(0);
			setCursorX(current_video_mode->width);
		} else {
			setCursorY(getCursorY() - 1);
			setCursorX(current_video_mode->width);
		}
		return;
	}
	setCursorX(getCursorX() - 1);
}
Exemplo n.º 4
0
void CATextField::adjustCursorMove(bool forward)
{
	this->updateImage();

	if (m_sText.empty())
	{
		m_iString_l_length = m_iString_r_length = 0;
	}
	else
	{
		m_iString_l_length = getStringLength(m_sText.substr(0, m_iCurPos));
		m_iString_r_length = m_cImageSize.width - m_iString_l_length;
	}

	if (forward)
	{
		if (getCursorX() > m_iLabelWidth && m_iLabelWidth < m_iString_l_length)
		{
			m_iString_o_length = m_iLabelWidth - m_iString_l_length;
		}
	}
	else
	{
		if (getCursorX() <= 0)
		{
			m_iString_o_length = -m_iString_l_length;
		}
		else
		{
			if (m_iString_r_length + getCursorX() < m_iLabelWidth)
			{
				m_iString_o_length = MIN(0, m_iLabelWidth - m_cImageSize.width);
			}
		}
	}

	CCRect r = CCRect(0, 0, MIN(m_iLabelWidth, m_cImageSize.width), m_cImageSize.height);
	r.origin.x = -m_iString_o_length;
	r.size.width = getStringViewLength();
	if (r.size.width == 0)
	{
		r.size.width = m_cImageSize.width;
	}


	this->setImageRect(r);
	
	setCursorPosition();
}
Exemplo n.º 5
0
void CATextField::deleteBackward()
{
    if (m_nInputType==KEY_BOARD_INPUT_PASSWORD)
    {
        m_sText.clear();
		m_vTextFiledChars.clear();
		this->updateImage();
		m_iString_l_length = 0;
		m_iString_r_length = 0;
		m_iString_left_offX = 0;
		m_iCurPos = 0;
		m_curSelCharRange = std::make_pair(0, 0);
		m_pCursorMark->setCenterOrigin(CCPoint(m_iHoriMargins + getCursorX(), m_obContentSize.height / 2));

        return;
    }

	if (m_iCurPos==0 || m_sText.empty())
		return;

	int nDeleteLen = 1;
	while (0x80 == (0xC0 & m_sText.at(m_iCurPos - nDeleteLen)))
	{
		++nDeleteLen;
	}
	
    m_sText.erase(m_iCurPos - nDeleteLen, nDeleteLen);
    m_iCurPos -= nDeleteLen;
	m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos);
    CC_RETURN_IF(m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, m_sText.c_str(), (int)m_sText.length()));
	
	m_vTextFiledChars.erase(m_vTextFiledChars.begin() + getStringCharCount(m_sText.substr(0, m_iCurPos)));
	
    adjustCursorMoveBackward();
}
Exemplo n.º 6
0
void CATextField::moveArrowBtn(const CCPoint& pt)
{
	if (m_nInputType == KEY_BOARD_INPUT_PASSWORD)
		return;


    this->showCursorMark();
	
	int l, r, p;
	calculateSelChars(convertToNodeSpace(pt), l, r, p);
	m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos);

	m_iString_l_length = l;
	m_iString_r_length = r;
	bool isBackward = p < m_iCurPos;
	m_iCurPos = p;
	if (isBackward)
	{
		adjustCursorMoveBackward();
	}
	else
	{
		adjustCursorMoveForward();
	}

	m_pCursorMark->setCenterOrigin(CCPoint(getCursorX() + m_iHoriMargins, m_obContentSize.height / 2));

//	CATextArrowView* pTextArrowView = CATextArrowView::create();
//	pTextArrowView->showTextArrView(convertToWorldSpace(CCPoint(getCursorX() + m_iHoriMargins, m_obContentSize.height + CATextArrowViewHeight/2)), this);
}
void model_loader_app::onMouseButton(int button, int action, int mods)
{
	OpenGLApp::onMouseButton(button, action, mods);
	float x = getCursorX();
	float y = info.windowHeight - getCursorY();

	x = (x/(float)info.windowWidth - 0.5) * 2.0;
	y = (y/(float)info.windowHeight - 0.5) * 2.0;
	if(action == GLFW_PRESS)
	{
		if(x>=0.2 && x <=0.45 && y >= -0.9 && y < -0.75)
		{
			bRightPressed = true;
		}
		if(x<=-0.2 && x >=-0.45 && y >= -0.9 && y < -0.75)
		{
			bLeftPressed = true;
		}
	}
	else
	{
		if(bLeftPressed)
		{
			mMesh->changeAnim(false);
		}
		if(bRightPressed)
			mMesh->changeAnim();
		bLeftPressed = false;
		bRightPressed = false;
	}
}
Exemplo n.º 8
0
void incrementCursor() {
	if (getCursorX() >= current_video_mode->width) {
		setCursorX(0);
		if (getCursorY() >= current_video_mode->height - 1)
		{
			newLine();
			setCursorY(current_video_mode->height - 1);
		}
		else
			setCursorY(getCursorY() + 1);
		return;
	} else {
		setCursorX(getCursorX() + 1);
	}

}
Exemplo n.º 9
0
// Standard getchar
char getchar() {
	char c;
	int sx = getCursorX();
	int sy = getCursorY();
	while ((c = getC()) != '\n') {
		if (c != 0) {
			if (c != 0x0f) {
				if (c != '\r' || getCursorY() > sy || getCursorX() > sx)
					putchar(c);
			} else {
				putTab();
			}
		}
	}
	putchar(c);
	return c;
}
Exemplo n.º 10
0
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();
}
Exemplo n.º 11
0
void CATextField::setCursorPosition()
{
    if (m_nInputType == KEY_BOARD_INPUT_PASSWORD)
    {
		m_pCursorMark->setCenterOrigin(CCPoint((m_sText.empty() ? 0 : this->getImageRect().size.width) + m_iHoriMargins, m_obContentSize.height / 2));
    }
    else
    {
		float mPmarkWidth = MIN(m_iLabelWidth, getCursorX());
        m_pCursorMark->setCenterOrigin(CCPoint(mPmarkWidth + m_iHoriMargins, m_obContentSize.height / 2));
    }
}
Exemplo n.º 12
0
	void setCursorPosition()
	{
		m_pCursorMark->setFrame(DRect(0, 0, 2.5f, m_iFontHeight));
		if (m_pTextFieldX->isSecureTextEntry())
		{
			m_pCursorMark->setCenterOrigin(DPoint((m_sText.empty() ? 0 : this->getImageRect().size.width), m_obContentSize.height / 2));
		}
		else
		{
			int mPmarkWidth = MIN(m_iLabelWidth, getCursorX());
			m_pCursorMark->setCenterOrigin(DPoint(mPmarkWidth, m_obContentSize.height / 2));
		}
	}
Exemplo n.º 13
0
// Clears the screen from the given cursor to the end of the page.
// And rolls the cursor back.
void clear_screen_topdown() {
	int i = 0;
	int x = getCursorX();
	int y = getCursorY();
	setCursor(FALSE);
	while (i++ < (current_video_mode->width * (current_video_mode->height
			- y)) - x) {
		putchar(' ');
	}
	setCursor(TRUE);
	setCursorX(x);
	setCursorY(y);
}
Exemplo n.º 14
0
// Standard putchar
void putchar(char c) {

	if (c == '\r') {
		backSpace();
	} else if (c == '\n') {
		newLine();
	} else if (c == 0x0f || c == '\t') {
		if (getCursorX() % 4 == 0) {
			int i = 0;
			for (i = 0; i < 4; ++i) {
				putChar(c);
				putC(' ');
			}
		} else
			while (getCursorX() % 4 != 0) {
				putChar(c);
				putC(' ');
			}
	} else if (c != 0) {
		putChar(c);
		putC(c);
	}
}
Exemplo n.º 15
0
void video_write_c(char * data) {
	make_atomic();
	char a[] = { *data, defaultStyle };
	char c = *data;

	if (c == '\r') {
		backSpace();
	} else if (c == '\n') {
		newLine();
	} else if (c == 0x0f || c == '\t') {
		if (getCursorX() % 4 == 0) {
			int i = 0;
			for (i = 0; i < 4; ++i) {
				putChar(' ');
				*a = ' ';
				video_write(a, 2);
			}
		} else
			while (getCursorX() % 4 != 0) {
				putChar(' ');
				*a = ' ';
				video_write(a,2);
				incrementCursor();
			}
	} else if (c != 0) {
		putChar(c);
		if(current_video_mode->visible)	{
			video_write(a,2);
			incrementCursor();
		} else {
			setCursor(FALSE);
			incrementCursor();
			setCursor(TRUE);
		}
	}
	release_atomic();
}
Exemplo n.º 16
0
void video_reload() { 
	int x, y;
	int old_x = getCursorX();
	int old_y = getCursorY();
	setCursor(FALSE);
	for(x = 0; x < current_video_mode->width; ++x)
	{
		for(y = 0; y < current_video_mode->height; ++y)
		{
			setCursorX(x);
			setCursorY(y);
			putC(current_video_mode->screen[x][y]);
		}
	}
	setCursor(TRUE);
	setCursorX(old_x);
	setCursorY(old_y);
}
Exemplo n.º 17
0
bool CATextField::attachWithIME()
{
    bool bRet = CAIMEDelegate::attachWithIME();
    if (bRet)
    {
        // open keyboard
        CCEGLView * pGlView = CAApplication::getApplication()->getOpenGLView();
        if (pGlView)
        {
#if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
            if (getKeyboardType() ==KEY_BOARD_TYPE_NORMAL)
            {
                pGlView->setIMEKeyboardDefault();
            }
            else if (getKeyboardType() ==KEY_BOARD_TYPE_NUMBER)
            {
                pGlView->setIMEKeyboardNumber();
            }
            else if(getKeyboardType() ==KEY_BOARD_TYPE_ALPHABET)
            {
                pGlView->setIMEKeyboardAlphabet();
            }
            
            if (getKeyboardReturnType() ==KEY_BOARD_RETURN_SEND)
            {
                pGlView->setIMEKeyboardReturnSend();
            }
            else if (getKeyboardReturnType() ==KEY_BOARD_RETURN_SEARCH)
            {
                pGlView->setIMEKeyboardReturnSearch();
            }
            else if(getKeyboardReturnType() ==KEY_BOARD_RETURN_DONE)
            {
                pGlView->setIMEKeyboardReturnDone();
            }
#endif
            this->showCursorMark();
            m_pCursorMark->setCenterOrigin(CCPoint(getCursorX() + m_iHoriMargins, m_obContentSize.height / 2));
            pGlView->setIMEKeyboardState(true);
        }
    }
    return bRet;
}
Exemplo n.º 18
0
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();
}
Exemplo n.º 19
0
void CATextField::calculateSelChars(const CCPoint& point, int& l, int& r, int& p)
{
_CalcuAgain:
	int dtValue = point.x - m_iString_left_offX - m_iHoriMargins;
	l = r = p = 0;
	for (std::vector<TextAttribute>::iterator it = m_vTextFiledChars.begin(); it != m_vTextFiledChars.end(); ++it)
	{
		TextAttribute& t = *it;
		CC_BREAK_IF(l + t.charlength / 2 > dtValue && getCursorX() + m_iHoriMargins > 0);
		l += t.charlength;
		p += t.charSize;
	}
	r = m_cImageSize.width - l;

	if (p == 0 && m_iString_left_offX < 0)
	{
		m_iString_left_offX = 0;
		goto _CalcuAgain;
	}
}
Exemplo n.º 20
0
	void calculateSelChars(const DPoint& point, int& l, int& r, int& p)
	{
	_CalcuAgain:

		int dtValue = point.x - m_iString_o_length - getDtStrLength();
		int ll = 0, rr = 0, pp = 0;
		for (std::vector<TextAttribute>::iterator it = m_vTextFiledChars.begin(); it != m_vTextFiledChars.end(); ++it)
		{
			TextAttribute& t = *it;
			CC_BREAK_IF(ll + t.charlength / 2 > dtValue && getCursorX() >= 0);
			ll += t.charlength;
			pp += t.charSize;
		}
		rr = m_cImageSize.width - ll;

		if (pp == 0 && m_iString_o_length < 0)
		{
			m_iString_o_length = 0;
			goto _CalcuAgain;
		}
		l = ll; r = rr; p = pp;
	}
Exemplo n.º 21
0
//--------------------------------------------------------------
// adjust scroll posn after change in cursor posn
void mgSimpleField::updateScrollPosn()
{
  // scroll backwards if off front end
  while (m_cursorPosn < m_scrollPosn+2 && m_scrollPosn > 0)
  {
    m_scrollPosn = m_text.prevLetter(m_scrollPosn);
  }
   
  // scroll forwards if off back end
  int blankWidth = m_font->stringWidth(" ", 1);

  mgDimension size;
  getSize(size);
  while (true)
  {
    mgString fitText(m_text);
    fitText.deleteAt(0, m_scrollPosn);
    int cursorX = getCursorX(m_text);
    if (cursorX < (size.m_width-2*blankWidth))
      break;
    m_scrollPosn = m_text.nextLetter(m_scrollPosn);
  }
}
Exemplo n.º 22
0
Palette::Palette(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Palette),
    settings("./sweeper.ini", QSettings::IniFormat),
    pSettings(PaletteSettings(settings))
{
    pSettings.commitSettings();

    ui->setupUi(this);
    setWindowModality(Qt::ApplicationModal);
    setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);

    win = getWindowUnderCursor();
    int newX = getCursorX() - (width()/2);
    int newY = getCursorY() - (height()/2);
    move(newX, newY);

    state = QUuid();

    QMap<QString, HoverWatchState> &bob = pSettings.cells;
    for(QMap<QString, HoverWatchState>::const_iterator i = bob.constBegin();
        i != bob.constEnd();
        ++i) {
        HoverWatch *hv = new HoverWatch(i.value());
        cells.push_front(hv);
        int x, y; mapLocStr(i.key(), &x, &y);
        ui->grid->addWidget(hv, x, y);
    }
    //and now let all the hoverwatches connect to each other and us...
    for(QVector<HoverWatch*>::iterator it = cells.begin(); it != cells.end(); ++it) {
        for(QVector<HoverWatch*>::iterator jt = cells.begin(); jt != cells.end(); ++jt) {
            connect(*it, SIGNAL(hoverActivated(QUuid)), *jt, SLOT(reactToHover(QUuid)));
            connect(*it, SIGNAL(hoverActivated(QUuid)), this, SLOT(setState(QUuid)));
        }
    }
}
/**
* Set the cursor to the next line.
*/
void SimpleScallopShellData::nextLine()
{
  cursor_ = linearizer_.linearize((getCursorX() + 1) % (getHeight()), 0);
}
Exemplo n.º 24
0
void CATextField::willInsertText(const char *text, int len)
{



    if (m_nInputType ==KEY_BOARD_INPUT_PASSWORD)
        return;

    if (len>0)
    {


        if (!strcmp(temporaryString.c_str(), text))
        {
            return;
        }
        temporaryString =text;
        isEditing = true;
        spaceHolderIsOn = false;
        char sText[512]="";

        // m_sLeft_string.append(temporaryString);

        sprintf(sText, "%s%s%s",m_sLeft_string.c_str(),text,m_sRight_string.c_str());
        m_sText = sText;

        this->updateImage();
        float left_width = getStringLength(m_sLeft_string)+getStringLength(temporaryString);
        m_fString_right_length = m_rLabelRect.size.width - left_width;

        float willOffsetX = 0;

        if (left_width - m_fString_left_offX > labelWidth)
        {
            willOffsetX = labelWidth - left_width-m_fString_left_offX;
        }

        CCRect rect = CCRectZero;
        rect.size = this->getBounds().size;
        CCRect r = m_rLabelRect;
        r.origin.x = -m_fString_left_offX-willOffsetX;
        r.size.width = m_rLabelRect.size.width;
        //-m_fString_left_length-m_fString_right_length;
        r.size.width = MIN(r.size.width, labelWidth);

        this->setImageRect(r);

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

        return;
    }
    else if(len==0&&isEditing)
    {
        willBg->setFrame(CCRectMake(labelOrginX, m_rLabelRect.size.height/2,0, m_rLabelRect.size.height));
        willBg->setVisible(false);
        temporaryString="";
        isEditing =false;
        if (strcmp(m_sLeft_string.c_str(), ""))
        {
            this->updateImage();
        }
        else
        {
            m_sText = "";
            spaceHolderIsOn = true;
            this->updateImage();
        }
        m_pMark->setCenterOrigin(CCPoint(labelOrginX+getCursorX() , this->getBounds().size.height/2));
        return;
    }
}
Exemplo n.º 25
0
void Ui::Ncurses::setCursorY(int y)
{
  moveCursor(getCursorX(), y);
}
Exemplo n.º 26
0
float CATextField::getStringViewLength()
{
    return MIN(labelWidth, m_fString_right_length + getCursorX());
}
Exemplo n.º 27
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;
}
Exemplo n.º 28
0
void CATextField::insertText(const char * text, int len)
{
    if (len>3)
    {
        analyzeString(text,len);
        return;
    }
    if (m_nInputType == KEY_BOARD_INPUT_PASSWORD)
    {
        if (len>=2)
            return;
        if (spaceHolderIsOn)
        {
            spaceHolderIsOn = false;
            m_sText="";
        }
        m_sText = m_sPassWord;
        m_sText.append(text);



        std::string password="";
        for (int i=0; i<m_sText.length(); i++)
        {
            password.append("*");
        }
        m_sPassWord = m_sText;
        m_sText = password;
        this->updateImage();

        CCRect r = m_rLabelRect;
        r.origin.x = 0;
        r.origin.x = MAX(labelWidth-m_rLabelRect.size.width, 0);
        r.origin.x = MIN(0, r.origin.x);
        r.size.width = MIN(m_rLabelRect.size.width, labelWidth);
        this->setImageRect(r);
        float offsetX = MIN(labelWidth, m_rLabelRect.size.width);
        m_pMark->setCenterOrigin(CCPoint(offsetX+labelOrginX,this->getBounds().size.height/2));

        return;
    }

    if (!strcmp(text, "\n"))
    {
        return;
    }

    std::string inputstr;
    if (spaceHolderIsOn)
    {
        spaceHolderIsOn = false;
        m_sText = "";
    }

    if(isEditing)
    {
        isEditing =false;
    }
    willBg->setVisible(false);

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

        float left_width = getStringLength(m_sLeft_string);

        TextAttribute t;
        t.charlength = left_width - m_fString_left_length;
        t.charsize = strlen(text);
        m_vByteLengthArr.insert(m_vByteLengthArr.begin()+getStringCharCount(m_sLeft_string), t);

        char str[512]="";
        sprintf(str, "%s%s",m_sLeft_string.c_str(),m_sRight_string.c_str());
        m_sText = str;

        this->updateImage();

        m_fString_left_length = m_rLabelRect.size.width;
        //left_width;
        m_fString_right_length = m_rLabelRect.size.width - m_fString_left_length;

        if (m_fString_left_length + m_fString_left_offX > labelWidth)
        {
            m_fString_left_offX = labelWidth - m_fString_left_length;
        }


        CCRect rect = CCRectZero;
        rect.size = this->getBounds().size;
        CCRect r = m_rLabelRect;
        r.origin.x = -m_fString_left_offX;
        r.size.width = getStringViewLength();
        this->setImageRect(r);
    }
    m_pMark->setCenterOrigin(CCPoint(getCursorX()+labelOrginX,this->getBounds().size.height/2));

}
Exemplo n.º 29
0
int CATextField::getStringViewLength()
{
	return MIN(m_iLabelWidth, m_iString_r_length + getCursorX());
}
Exemplo n.º 30
0
void CATextField::deleteBackward()
{
    if (m_nInputType==KEY_BOARD_INPUT_PASSWORD)
    {
        m_sText="";
        spaceHolderIsOn=true;
        this->updateImage();
        m_pMark->setCenterOrigin(CCPoint(labelOrginX+getCursorX(), this->getBounds().size.height/2));

        return;
    }
    if(spaceHolderIsOn)
    {

        return;
    }

    int nStrLen =m_sLeft_string.length();

    int nDeleteLen = 1;    // default, erase 1 byte

    if (nStrLen == 0)
    {
        return;
    }

    while(0x80 == (0xC0 & m_sLeft_string.at(m_sLeft_string.length() - nDeleteLen)))
    {
        ++nDeleteLen;
    }
    if (m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, m_sLeft_string.c_str() + nStrLen - nDeleteLen, nDeleteLen))
    {
        // delegate doesn't wan't to delete backwards
        return;
    }
    // if all text deleted, show placeholder string
    if (m_sText.length() <= nDeleteLen)
    {
        m_sLeft_string="";
        spaceHolderIsOn=true;
        m_vByteLengthArr.clear();
        TextAttribute tt;
        tt.charsize =0;
        tt.charlength =0;
        m_vByteLengthArr.push_back(tt);
        m_pMark->setCenterOrigin(CCPoint(labelOrginX, this->getBounds().size.height/2));
        this->updateImage();
        return;
    }


    int length = MAX(0, nStrLen - nDeleteLen);

    std::string sText(m_sLeft_string.c_str(), length);
    char str[512]="";
    sprintf(str, "%s%s",sText.c_str(),m_sRight_string.c_str());
    m_sText = str;
    this->updateImage();

    m_vByteLengthArr.erase(m_vByteLengthArr.begin()+getStringCharCount(m_sLeft_string));
    m_sLeft_string = sText.c_str();
    float left_width = getStringLength(m_sLeft_string);

    m_fString_left_length = m_rLabelRect.size.width;
    //left_width;
    m_fString_right_length = m_rLabelRect.size.width - m_fString_left_length;

    if (m_fString_right_length + getCursorX() < labelWidth)
    {
        m_fString_left_offX = MIN(0, labelWidth - m_rLabelRect.size.width);
    }

    CCRect rect = CCRectZero;
    rect.size = this->getBounds().size;
    CCRect r = m_rLabelRect;
    r.origin.x = -m_fString_left_offX;
    r.size.width = getStringViewLength();
    this->setImageRect(r);
    m_pMark->setCenterOrigin(CCPoint( getCursorX()+labelOrginX, this->getBounds().size.height/2));
    return;
}