Пример #1
0
void CATextView::updateImage()
{
	std::string text;
	if (m_szText.empty())
	{
		text = m_sPlaceHolder;
	}
	else
	{
		text = m_szText;
	}
	m_cFontColor = m_szText.empty() ? m_cPlaceHolderColor : m_cTextColor;

	float width = this->getBounds().size.width;
	width -= m_iHoriMargins * 2;

	CAImage* image = g_AFTFontCache.initWithString(text.c_str(),
		m_szFontName.c_str(),
		m_iFontSize,
		width,
		0,
		CATextAlignmentLeft,
		CAVerticalTextAlignmentTop,
		m_bWordWrap,
		m_iLineSpacing,
		false,
		false,
		false,
		&m_vLinesTextView);

    
	if (m_szText.empty())
	{
		m_vLinesTextView.clear();
	}
    m_pImageView->setColor(m_cFontColor);
	m_pImageView->setImage(image);
    CCRect rect = CCRectZero;

	if (image)
	{
		rect.size = image->getContentSize();
	}

    m_pImageView->setImageRect(rect);
	m_pContainerView->setViewSize(CCSizeMake(rect.size.width, rect.size.height));

	rect.origin = CCPointMake(m_iHoriMargins, 0);
    m_pImageView->setFrame(rect);
    
	calcCursorPosition();
}
Пример #2
0
	void clearText()
	{
		HideTextViewMask();

		m_vLinesTextView.clear();
		m_curSelCharRange.first = m_curSelCharRange.second = 0;
		m_iCurPos = 0;
		m_szText.clear();
		m_iStartMovePos = 0;
		
		calcCursorPosition();
		m_pCurPosition = m_pCursorMark->getCenterOrigin();
	}
Пример #3
0
void CATextView::moveArrowBtn(const CCPoint& pt)
{
	int iCurLine = 0; int iCurPosX = 0;
	calculateSelChars(convertToNodeSpace(pt), iCurLine, iCurPosX, m_iCurPos);
	m_curSelCharRange = std::make_pair(0, 0);
	calcCursorPosition();

	m_pCursorMark->stopAllActions();
	m_pCursorMark->setCenterOrigin(CCPoint(iCurPosX, m_iLineHeight*1.25f*iCurLine + m_iLineHeight / 2));
	m_pCursorMark->setVisible(true);

	CCPoint ptArr = m_pCursorMark->getCenterOrigin();
	m_pTextArrView->showTextArrView(CCPoint(ptArr.x, ptArr.y + m_iLineHeight*1.2f + m_pContainerView->getContentOffset().y));
}
Пример #4
0
void CATextView::cursorMoveBackward()
{
	if (m_iCurPos == 0 || m_szText.empty())
		return;

	int nMoveLen = 1;
	while (0x80 == (0xC0 & m_szText.at(m_iCurPos - nMoveLen)))
	{
		++nMoveLen;
	}
	m_iCurPos -= nMoveLen;

	m_curSelCharRange.first = m_curSelCharRange.second = 0;
	calcCursorPosition();
}
Пример #5
0
	bool execCurSelCharRange()
	{
		if (m_curSelCharRange.first == m_curSelCharRange.second)
			return false;

		int iOldCurPos = m_curSelCharRange.first;
		std::string cszText = m_szText.erase(m_curSelCharRange.first, m_curSelCharRange.second - m_curSelCharRange.first);
		setText(cszText);

		m_iCurPos = iOldCurPos;
		this->showCursorMark();
		calcCursorPosition();
		HideTextViewMask();
		return true;
	}
Пример #6
0
void CATextView::cursorMoveForward()
{
	if (m_iCurPos == m_szText.length() || m_szText.empty())
		return;

	int nMoveLen = 1;
	for (std::string::size_type n = m_iCurPos + nMoveLen; n < m_szText.length() && 0x80 == (0xC0 & m_szText.at(n));)
	{
		++nMoveLen;
		n = m_iCurPos + nMoveLen;
	}
	m_iCurPos += nMoveLen;

	m_curSelCharRange.first = m_curSelCharRange.second = 0;
	calcCursorPosition();
}
Пример #7
0
bool CATextView::execCurSelCharRange()
{
	CATextToolBarView::hideTextToolBar();

	if (m_curSelCharRange.first == m_curSelCharRange.second)
		return false;

	int iOldCurPos = m_curSelCharRange.first;
	std::string cszText = m_szText.erase(m_curSelCharRange.first, m_curSelCharRange.second - m_curSelCharRange.first);
	setText(cszText);

	m_iCurPos = iOldCurPos;
    this->showCursorMark();
	calcCursorPosition();
    m_pTextSelView->hideTextSelView();
	return true;
}
Пример #8
0
	void cursorMoveDown()
	{
		if (m_szText.empty() || m_iCurPos == m_szText.size())
			return;

		DPoint cursorRect = m_pCursorMark->getCenterOrigin();
		float scrollViewOffSetY = m_pContainerView->getContentOffset().y;
		DPoint point = DPoint(m_pCurPosition.x, cursorRect.y + m_iLineHeight - scrollViewOffSetY);

		int iCurLine = 0; int iCurPosX = 0;
		calculateSelChars(point, iCurLine, iCurPosX, m_iCurPos);
		m_pCursorMark->setCenterOrigin(DPoint(iCurPosX, m_iLineHeight*1.25f*iCurLine + m_iLineHeight / 2));
		showCursorMark();

		m_curSelCharRange = std::pair<int, int>(m_iCurPos, m_iCurPos);
		calcCursorPosition();
	}
Пример #9
0
void CATextView::updateImage()
{
	std::string text;
	if (m_szText.empty())
	{
		text = m_sPlaceHolder;
		this->setFontColor(m_cSpaceHolderColor);
	}
	else
	{
		text = m_szText;
		this->setFontColor(m_cTextColor);
	}

	float width = this->getBounds().size.width;
	float height = this->getBounds().size.height;
	CCSize size = CCSizeMake(width, 0);

	CAImage* image = NULL;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_LINUX)

	image = g_AFTFontCache.initWithStringEx(text.c_str(),
		m_szFontName.c_str(),
		m_iFontSize,
		width,
		0,
		m_vLinesTextView,
		m_iLineSpacing,
		m_bWordWrap);
#endif

	if (image == NULL || m_szText.empty())
	{
		m_vLinesTextView.clear();
	}

	m_pImageView->initWithImage(image);
	setViewSize(m_pImageView->getBounds().size);
	calcCursorPosition();
}
Пример #10
0
	void updateImage()
	{
		float width = this->getBounds().size.width;

		CAImage* image = g_AFTFontCache.initWithString(m_szText.c_str(),
			m_pCATextView->getTextColor(),
			m_szFontName.c_str(),
			m_pCATextView->getTextFontSize(),
			width,
			0,
			CATextAlignmentLeft,
			CAVerticalTextAlignmentTop,
			true,
			0,
			false,
			false,
			false,
			false,
			&m_vLinesTextView);

		if (m_szText.empty())
		{
			m_vLinesTextView.clear();
		}
		m_pImageView->setColor(CAColor_white);
		m_pImageView->setImage(image);
		DRect rect = DRectZero;

		if (image)
		{
			rect.size = image->getContentSize();
		}

		m_pImageView->setImageRect(rect);
		m_pContainerView->setViewSize(rect.size);
		m_pImageView->setFrame(rect);

		calcCursorPosition();
		m_pCurPosition = m_pCursorMark->getCenterOrigin();
	}
Пример #11
0
void CATextView::moveSelectChars(bool isLeftBtn, const CCPoint& pt)
{
	int l, r, p;
	calculateSelChars(convertToNodeSpace(pt), l, r, p);

	if (isLeftBtn)
	{
		if (p < m_curSelCharRange.second)
			m_curSelCharRange.first = p;
	}
	else
	{
		if (p > m_curSelCharRange.first)
			m_curSelCharRange.second = p;
	}

	m_iCurPos = p;
	calcCursorPosition();

	m_pTextArrView->hideTextArrView();
	m_pTextSelView->showTextSelView(this, getZZCRect(), m_iLineHeight);
	hideCursorMark();
}
Пример #12
0
void ConsoleInfo::edit(int key, int mod)
{
    if(key == SDLK_UNKNOWN || key == SDLK_BACKQUOTE || key == SDLK_BACKSLASH || !inited)
    {
        return;
    }

    if(key == SDLK_RETURN)
    {
        addLog(m_editingLine);
        addLine(std::string("> ") + m_editingLine, FontStyle::ConsoleInfo);
        Engine_ExecCmd(m_editingLine.c_str());
        m_editingLine.clear();
        m_cursorPos = 0;
        m_cursorX = 8 + 1;
        return;
    }

    m_blinkTime = 0.0;
    m_showCursor = 1;

    int16_t oldLength = utf8_strlen(m_editingLine.c_str());    // int16_t is absolutly enough

    switch(key)
    {
        case SDLK_UP:
        case SDLK_DOWN:
            if(m_historyLines.empty())
                break;
            Audio_Send(engine_lua.getGlobalSound(TR_AUDIO_SOUND_GLOBALID_MENUPAGE));
            if(key == SDLK_UP && m_historyPos < m_historyLines.size())
                ++m_historyPos;
            else if(key == SDLK_DOWN && m_historyPos > 0)
                --m_historyPos;
            if(m_historyPos > 0)
                m_editingLine = m_historyLines[m_historyPos - 1];
            else
                m_editingLine.clear();
            m_cursorPos = utf8_strlen(m_editingLine.c_str());
            break;

        case SDLK_LEFT:
            if(m_cursorPos > 0)
            {
                m_cursorPos--;
            }
            break;

        case SDLK_RIGHT:
            if(m_cursorPos < oldLength)
            {
                m_cursorPos++;
            }
            break;

        case SDLK_HOME:
            m_cursorPos = 0;
            break;

        case SDLK_END:
            m_cursorPos = oldLength;
            break;

        case SDLK_BACKSPACE:
            if(m_cursorPos > 0)
            {
                m_editingLine.erase(m_cursorPos - 1, 1);
                m_cursorPos--;
            }
            break;

        case SDLK_DELETE:
            if(m_cursorPos < oldLength)
            {
                m_editingLine.erase(m_cursorPos, 1);
            }
            break;

        case SDLK_TAB:
            {
                std::string needle = m_editingLine.substr(0, m_cursorPos);
                // find auto-completion terms, case-insensitive
                std::vector<std::string> found;
                std::copy_if(m_completionItems.begin(), m_completionItems.end(), std::back_inserter(found),
                             [needle](const std::string& completion){ return startsWithLowercase(completion, needle); });
                if(found.empty())
                {
                    // no completion, do nothing
                }
                else if(found.size() == 1)
                {
                    // if we have only one term found, use it!
                    m_editingLine.erase(0, found[0].length());
                    m_editingLine.insert(0, found[0]);
                    m_cursorPos = found[0].length();
                }
                else
                {
                    // else we must find the common completion string
                    for(std::string& term : found)
                    {
                        // cut off the needle part
                        term.erase(0, needle.length());
                    }
                    // now find a common start
                    std::string common = found[0];
                    for(size_t i=1; !common.empty() && i<found.size(); ++i)
                    {
                        // cut off from the end that's not common with current
                        for(size_t j=0; j<std::min(common.length(), found[i].length()); ++j)
                        {
                            if(std::tolower(common[j]) != std::tolower(found[i][j]))
                            {
                                common.erase(j);
                                break;
                            }
                        }
                    }
                    if(common.empty())
                    {
                        // nothing common, print possible completions
                        addLine("Possible completions:", FontStyle::ConsoleInfo);
                        for(const std::string& term : found)
                            addLine(std::string("* ") + needle + term, FontStyle::ConsoleInfo);
                    }
                    else
                    {
                        m_editingLine.insert(m_cursorPos, common);
                        m_cursorPos += common.length();
                    }
                }
            }
            break;

        default:
            if( key == SDLK_v && mod>0 && (mod & KMOD_CTRL) )
            {
                if(char* clipboard = SDL_GetClipboardText())
                {
                    const int16_t textLength = utf8_strlen(clipboard);
                    if(oldLength < m_lineSize - textLength)
                    {
                        m_editingLine.insert(m_cursorPos, clipboard);
                        m_cursorPos += textLength;
                    }
                    SDL_free(clipboard);
                }
            }
            else if(mod<0 && (oldLength < m_lineSize - 1) && (key >= SDLK_SPACE))
            {
                m_editingLine.insert(m_editingLine.begin() + m_cursorPos, char(key));
                m_cursorPos++;
            }
            break;
    }

    calcCursorPosition();
}
Пример #13
0
void ConsoleInfo::edit(int key)
{
    if(key == SDLK_UNKNOWN || key == SDLK_BACKQUOTE || key == SDLK_BACKSLASH || !inited)
    {
        return;
    }

    if(key == SDLK_RETURN)
    {
        addLog(m_editingLine);
        addLine(std::string("> ") + m_editingLine, FONTSTYLE_CONSOLE_INFO);
        Engine_ExecCmd(m_editingLine.c_str());
        m_editingLine.clear();
        m_cursorPos = 0;
        m_cursorX = 8 + 1;
        return;
    }

    m_blinkTime = 0.0;
    m_showCursor = 1;

    int16_t oldLength = utf8_strlen(m_editingLine.c_str());    // int16_t is absolutly enough

    switch(key)
    {
        case SDLK_UP:
        case SDLK_DOWN:
            if(m_historyLines.empty())
                break;
            Audio_Send(lua_GetGlobalSound(engine_lua, TR_AUDIO_SOUND_GLOBALID_MENUPAGE));
            if(key == SDLK_UP && m_historyPos < m_historyLines.size())
                ++m_historyPos;
            else if(key == SDLK_DOWN && m_historyPos > 0)
                --m_historyPos;
            if(m_historyPos > 0)
                m_editingLine = m_historyLines[m_historyPos - 1];
            else
                m_editingLine.clear();
            m_cursorPos = utf8_strlen(m_editingLine.c_str());
            break;

        case SDLK_LEFT:
            if(m_cursorPos > 0)
            {
                m_cursorPos--;
            }
            break;

        case SDLK_RIGHT:
            if(m_cursorPos < oldLength)
            {
                m_cursorPos++;
            }
            break;

        case SDLK_HOME:
            m_cursorPos = 0;
            break;

        case SDLK_END:
            m_cursorPos = oldLength;
            break;

        case SDLK_BACKSPACE:
            if(m_cursorPos > 0)
            {
                m_editingLine.erase(m_cursorPos - 1, 1);
                m_cursorPos--;
            }
            break;

        case SDLK_DELETE:
            if(m_cursorPos < oldLength)
            {
                m_editingLine.erase(m_cursorPos, 1);
            }
            break;

        default:
            if((oldLength < m_lineSize - 1) && (key >= SDLK_SPACE))
            {
                m_editingLine.insert(m_editingLine.begin() + m_cursorPos, char(key));
                m_cursorPos++;
            }
            break;
    }

    calcCursorPosition();
}