Ejemplo n.º 1
0
    RECT SCaret::Draw(IRenderTarget *pRT,int x, int y,BOOL bErase)
    {
        SWindow * pOwner = SWindowMgr::GetWindow(m_owner);
        SASSERT(pOwner);
        SASSERT(pOwner->IsFocusable());
        
        CAutoRefPtr<IRenderTarget> pRTCaret;
        GETRENDERFACTORY->CreateRenderTarget(&pRTCaret,0,0);
        pRTCaret->SelectObject(m_bmpCaret);

        CSize szCaret = m_bmpCaret->Size();
        CRect rcCaret(CPoint(x,y),szCaret);
        CRect rcWnd = pOwner->GetClientRect();
        SWindow *pWnd = pOwner->GetParent();
        while(pWnd)
        {
            CRect rcLimit = pWnd->GetClientRect();
            rcWnd = rcWnd & rcLimit;
            pWnd = pWnd->GetParent();
        }
        pOwner->GetContainer()->FrameToHost(rcWnd);
        CRect rcCaretShow = rcCaret & rcWnd;
        
        pRT->BitBlt(&rcCaretShow,pRTCaret,rcCaretShow.left - rcCaret.left,rcCaretShow.top - rcCaret.top,DSTINVERT);
        return rcCaretShow;
    }
Ejemplo n.º 2
0
void CUIEditBox::OnFrameRender(const Matrix& mTransform, double fTime, float fElapsedTime)
{
    if(m_bVisible == false)
        return;

    CUIControl::updateUIMatrix(mTransform, fTime, fElapsedTime);


    int nSelStartX = 0, nCaretX = 0;  // Left and right X cordinates of the selection region

    {
        PlaceCaret(m_nCaret);  // Call PlaceCaret now that we have the font info (node),
        // so that scrolling can be handled.
    }

    RECT rc;
    rc.left =0;
    rc.right = m_rcRelativeBox.getWidth();
    rc.top =0;
    rc.bottom = m_rcRelativeBox.getHeight();
    m_Style.draw(rc, m_Buffer.GetBuffer() + m_nFirstVisible, GetState(), fElapsedTime);

    // Compute the X coordinates of the first visible character.
    //
    int nXFirst;
    m_Buffer.CPtoX(m_nFirstVisible, FALSE, nXFirst);

    //
    // Compute the X coordinates of the selection rectangle
    //
    m_Buffer.CPtoX(m_nCaret, FALSE, nCaretX);
    if(m_nCaret != m_nSelStart)
        m_Buffer.CPtoX(m_nSelStart, FALSE, nSelStartX);
    else
        nSelStartX = nCaretX;

    //
    // Render the selection rectangle
    //
    CRect<int> rcSelection;  // Make this available for rendering selected text
    if(m_nCaret != m_nSelStart)
    {
        int nSelLeftX = nCaretX, nSelRightX = nSelStartX;
        // Swap if left is bigger than right
        if(nSelLeftX > nSelRightX)
        {
            int nTemp = nSelLeftX;
            nSelLeftX = nSelRightX;
            nSelRightX = nTemp;
        }

        rcSelection.set(nSelLeftX, m_rcText.top, nSelRightX, m_rcText.bottom);
        rcSelection.offset(m_rcText.left - nXFirst, 0);
        rcSelection.IntersectRect(m_rcText, rcSelection);

        int nFirstToRender = __max(m_nFirstVisible, __min(m_nSelStart, m_nCaret));
        int nNumChatToRender = __max(m_nSelStart, m_nCaret) - nFirstToRender;
        //m_Styles[0].m_mapFont = m_SelTextColor;
        ///m_Style.Blend(CONTROL_STATE_FOCUS, fElapsedTime, 1);
        std::wstring wstrSelection = m_Buffer.GetBuffer() + nFirstToRender;
        wstrSelection = wstrSelection.substr(0,nNumChatToRender);
        m_StyleSelection.draw(rcSelection.getRECT(), wstrSelection.c_str(), GetState(), fElapsedTime);
    }

    //
    // Blink the caret
    //
    if(GetTickCount()*0.001f - m_dfLastBlink >= m_dfBlink)
    {
        m_bCaretOn = !m_bCaretOn;
        m_dfLastBlink = GetTickCount()*0.001f;
    }

    //
    // Render the caret if this control has the focus
    //
    if(IsFocus() && m_bCaretOn && !s_bHideCaret)
    {
        // Start the rectangle with insert mode caret
        CRect<int> rcCaret(m_rcText.left - nXFirst + nCaretX - 1, m_rcText.top,
                           m_rcText.left - nXFirst + nCaretX + 1, m_rcText.bottom);

        // If we are in overwrite mode, adjust the caret rectangle
        // to fill the entire character.
        if(!m_bInsertMode)
        {
            // Obtain the right edge X coord of the current character
            int nRightEdgeX;
            m_Buffer.CPtoX(m_nCaret, TRUE, nRightEdgeX);
            rcCaret.right = m_rcText.left - nXFirst + nRightEdgeX;
        }
        m_StyleSelection.draw(rcCaret.getRECT(), L"", GetState(), fElapsedTime);
    }
}
Ejemplo n.º 3
0
	void UIEditBox::Render()
	{
		UIElementPtr pElement = this->GetElement(0);
		if (pElement)
		{
			buffer_.SetFont(this->GetDialog()->GetFont(pElement->FontIndex()), this->GetDialog()->GetFontSize(pElement->FontIndex()));
			this->PlaceCaret(caret_pos_);  // Call PlaceCaret now that we have the font info (node),
			// so that scrolling can be handled.
		}

		// Render the control graphics
		for (int i = 0; i < 9; ++ i)
		{
			pElement = elements_[i];
			if (this->GetEnabled())
			{
				pElement->TextureColor().SetState(UICS_Normal);
			}
			else
			{
				pElement->TextureColor().SetState(UICS_Disabled);
			}

			this->GetDialog()->DrawSprite(*pElement, render_rc_[i]);
		}

		//
		// Compute the X coordinates of the first visible character.
		//
		int nXFirst = buffer_.CPtoX(first_visible_, false);

		//
		// Compute the X coordinates of the selection rectangle
		//
		int nSelStartX = 0;  // Left and right X cordinates of the selection region
		int nCaretX = buffer_.CPtoX(caret_pos_, false);
		if (caret_pos_ != sel_start_)
		{
			nSelStartX = buffer_.CPtoX(sel_start_, false);
		}
		else
		{
			nSelStartX = nCaretX;
		}

		//
		// Render the selection rectangle
		//
		IRect rcSelection;  // Make this available for rendering selected text
		if (caret_pos_ != sel_start_)
		{
			int nSelLeftX = nCaretX, nSelRightX = nSelStartX;
			// Swap if left is bigger than right
			if (nSelLeftX > nSelRightX)
			{
				std::swap(nSelLeftX, nSelRightX);
			}

			rcSelection = IRect(nSelLeftX, text_rc_.top(), nSelRightX, text_rc_.bottom());
			rcSelection += int2(text_rc_.left() - nXFirst, 0);
			rcSelection &= text_rc_;

			this->GetDialog()->DrawRect(rcSelection, -0.005f, sel_bk_color_);
		}

		//
		// Render the text
		//
		// Element 0 for text
		elements_[0]->FontColor().Current = text_color_;
		this->GetDialog()->DrawString(buffer_.GetBuffer().substr(first_visible_), *elements_[0], text_rc_);

		// Render the selected text
		if (caret_pos_ != sel_start_)
		{
			int nFirstToRender = std::max(first_visible_, std::min(sel_start_, caret_pos_));
			int nNumChatToRender = std::max(sel_start_, caret_pos_) - nFirstToRender;
			elements_[0]->FontColor().Current = sel_text_color_;
			this->GetDialog()->DrawString(buffer_.GetBuffer().substr(nFirstToRender, nNumChatToRender),
				*elements_[0], rcSelection);
		}

		//
		// Blink the caret
		//
		if (timer_.current_time() - last_blink_time_ >= blink_time_)
		{
			caret_on_ = !caret_on_;
			last_blink_time_ = timer_.current_time();
		}

		//
		// Render the caret if this control has the focus
		//
		if (has_focus_ && caret_on_ && !hide_caret_)
		{
			// Start the rectangle with insert mode caret
			IRect rcCaret(text_rc_.left() - nXFirst + nCaretX - 1, text_rc_.top(),
				text_rc_.left() - nXFirst + nCaretX + 1, text_rc_.bottom());

			// If we are in overwrite mode, adjust the caret rectangle
			// to fill the entire character.
			if (!insert_mode_)
			{
				// Obtain the right edge X coord of the current character
				int nRightEdgeX = buffer_.CPtoX(caret_pos_, true);
				rcCaret.right() = text_rc_.left() - nXFirst + nRightEdgeX;
			}

			this->GetDialog()->DrawRect(rcCaret, -0.1f, caret_color_);
		}
	}