コード例 #1
0
//! Gets the area of the text in the edit box
//! \return Returns the size in pixels of the text
core::dimension2du CGUIEditBox::getTextDimension()
{
    core::rect<s32> ret;

    setTextRect(0);
    ret = CurrentTextRect;

    for (u32 i=1; i < BrokenText.size(); ++i)
    {
        setTextRect(i);
        ret.addInternalPoint(CurrentTextRect.UpperLeftCorner);
        ret.addInternalPoint(CurrentTextRect.LowerRightCorner);
    }

    return core::dimension2du(ret.getSize());
}
コード例 #2
0
void CGUIEditBox::calculateScrollPos()
{
#ifndef SERVER_ONLY
    if (!AutoScroll)
        return;

    // calculate horizontal scroll position
    s32 cursLine = getLineFromPos(CursorPos);
    setTextRect(cursLine);

    // don't do horizontal scrolling when wordwrap is enabled.
    if (!WordWrap)
    {
        // get cursor position
        IGUISkin* skin = Environment->getSkin();
        if (!skin)
            return;
        IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
        if (!font)
            return;

        core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text;
        s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos;

        s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos +
            font->getDimension(txtLine->subString(0, cPos).c_str()).Width;

        s32 cEnd = cStart + font->getDimension(L"_ ").Width;

        if (FrameRect.LowerRightCorner.X < cEnd)
            HScrollPos = cEnd - FrameRect.LowerRightCorner.X;
        else if (FrameRect.UpperLeftCorner.X > cStart)
            HScrollPos = cStart - FrameRect.UpperLeftCorner.X;
        else
            HScrollPos = 0;

        // todo: adjust scrollbar
    }

    // vertical scroll position
    if (FrameRect.LowerRightCorner.Y < CurrentTextRect.LowerRightCorner.Y + VScrollPos)
        VScrollPos = CurrentTextRect.LowerRightCorner.Y - FrameRect.LowerRightCorner.Y + VScrollPos;

    else if (FrameRect.UpperLeftCorner.Y > CurrentTextRect.UpperLeftCorner.Y + VScrollPos)
        VScrollPos = CurrentTextRect.UpperLeftCorner.Y - FrameRect.UpperLeftCorner.Y + VScrollPos;
    else
        VScrollPos = 0;

    // todo: adjust scrollbar
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
    CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice());
    if (dl)
    {
        dl->setIMELocation(calculateICPos());
    }
#endif
#endif   // SERVER_ONLY
}
コード例 #3
0
s32 CGUIEditBox::getCursorPos(s32 x, s32 y)
{
    IGUIFont* font = OverrideFont;
    IGUISkin* skin = Environment->getSkin();
    if (!OverrideFont)
        font = skin->getFont();

    const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;

    core::stringw *txtLine=0;
    s32 startPos=0;
    x+=3;

    for (u32 i=0; i < lineCount; ++i)
    {
        setTextRect(i);
        if (i == 0 && y < CurrentTextRect.UpperLeftCorner.Y)
            y = CurrentTextRect.UpperLeftCorner.Y;
        if (i == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y )
            y = CurrentTextRect.LowerRightCorner.Y;

        // is it inside this region?
        if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y)
        {
            // we've found the clicked line
            txtLine = (WordWrap || MultiLine) ? &BrokenText[i] : &Text;
            startPos = (WordWrap || MultiLine) ? BrokenTextPositions[i] : 0;
            break;
        }
    }

    if (x < CurrentTextRect.UpperLeftCorner.X)
        x = CurrentTextRect.UpperLeftCorner.X;

    s32 idx = txtLine ? font->getCharacterFromPos(txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X) : -1;

    // click was on or left of the line
    if (idx != -1)
        return idx + startPos;

    // click was off the right edge of the line, go to end.
    return txtLine->size() + startPos;
}
コード例 #4
0
ファイル: screen.cpp プロジェクト: CobaltBlues/scummvm
void Screen::printTextEx(const char *text, int16 x, int16 y, int16 fontNum, int16 textColor, int16 outlineColor, const ClipInfo &clipInfo) {
	if (*text == 0 || x < 0 || y < 0)
		return;

	int16 oldFontNum = _currentFontNum;
	Common::Rect oldTextRect;
	ClipInfo oldFontDrawCtx = _fontDrawCtx;

	_fontDrawCtx = clipInfo;

	getTextRect(oldTextRect);
	setFont(fontNum);
	setTextColor(textColor);
	setOutlineColor(outlineColor);
	setTextXY(x, y);
	printText(text);
	setTextRect(oldTextRect);
	setFont(oldFontNum);
	_fontDrawCtx = oldFontDrawCtx;

}
コード例 #5
0
ファイル: tdefileividesktop.cpp プロジェクト: Fat-Zer/tdebase
void KFileIVIDesktop::calcRect( const TQString& _text )
{
    TDEIconViewItem::calcRect( _text );

    if ( !iconView() || !m_shadow ||
         !wordWrap() || !( static_cast<KDesktopShadowSettings *>
             ( m_shadow->shadowSettings() ) )->isEnabled() )
        return;

    int spread = shadowThickness();
    TQRect itemTextRect = textRect();
    TQRect itemRect = rect();

    itemTextRect.setBottom( itemTextRect.bottom() + spread );
    itemTextRect.setRight( itemTextRect.right() + spread );
    itemRect.setBottom( itemRect.bottom() + spread );
    itemRect.setRight( itemRect.right() + spread );

    setTextRect( itemTextRect );
    setItemRect( itemRect );
}
コード例 #6
0
//! draws the element and its children
void CGUIEditBox::draw()
{
#ifndef SERVER_ONLY
    if (!IsVisible)
        return;

    const bool focus = Environment->hasFocus(this);

    IGUISkin* skin = Environment->getSkin();
    if (!skin)
        return;

    FrameRect = AbsoluteRect;

    // draw the border

    if (Border)
    {
        EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE;
        if ( isEnabled() )
            col = focus ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE;
        skin->draw3DSunkenPane(this, skin->getColor(col),
            false, true, FrameRect, &AbsoluteClippingRect);

        FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
        FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
        FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
        FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
    }
    core::rect<s32> localClipRect = FrameRect;
    localClipRect.clipAgainst(AbsoluteClippingRect);

    // draw the text

    IGUIFont* font = OverrideFont;
    if (!OverrideFont)
        font = skin->getFont();

    s32 cursorLine = 0;
    s32 charcursorpos = 0;

    if (font)
    {
        if (LastBreakFont != font)
        {
            breakText();
        }

        // calculate cursor pos

        core::stringw *txtLine = &Text;
        s32 startPos = 0;

        core::stringw s, s2;

        // get mark position
        const bool ml = (!PasswordBox && (WordWrap || MultiLine));
        const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
        const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
        const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0;
        const s32 hlineCount = ml ? getLineFromPos(realmend) - hlineStart + 1 : 1;
        const s32 lineCount = ml ? BrokenText.size() : 1;

        // Save the override color information.
        // Then, alter it if the edit box is disabled.
        const bool prevOver = OverrideColorEnabled;
        const video::SColor prevColor = OverrideColor;

        if (Text.size())
        {
            if (!isEnabled() && !OverrideColorEnabled)
            {
                OverrideColorEnabled = true;
                OverrideColor = skin->getColor(EGDC_GRAY_TEXT);
            }

            for (s32 i=0; i < lineCount; ++i)
            {
                setTextRect(i);

                // clipping test - don't draw anything outside the visible area
                core::rect<s32> c = localClipRect;
                c.clipAgainst(CurrentTextRect);
                if (!c.isValid())
                    continue;

                // get current line
                if (PasswordBox)
                {
                    if (BrokenText.size() != 1)
                    {
                        BrokenText.clear();
                        BrokenText.push_back(core::stringw());
                    }
                    if (BrokenText[0].size() != Text.size())
                    {
                        BrokenText[0] = Text;
                        for (u32 q = 0; q < Text.size(); ++q)
                        {
                            BrokenText[0] [q] = PasswordChar;
                        }
                    }
                    txtLine = &BrokenText[0];
                    startPos = 0;
                }
                else
                {
                    txtLine = ml ? &BrokenText[i] : &Text;
                    startPos = ml ? BrokenTextPositions[i] : 0;
                }

                font->draw(translations->fribidize(txtLine->c_str()), CurrentTextRect,
                           OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
                           false, true, &localClipRect);
                // draw with fribidize no matter what language, because in fribidize function,
                // it will return the input pointer if (this->isRTLLanguage()) from Translations::isRTLText
                // is false

                // draw mark and marked text
                if (focus && MarkBegin != MarkEnd && i >= hlineStart && i < hlineStart + hlineCount)
                {

                    s32 mbegin = 0, mend = 0;
                    s32 lineStartPos = 0, lineEndPos = txtLine->size();

                    if (i == hlineStart)
                    {
                        // highlight start is on this line
                        s = txtLine->subString(0, realmbgn - startPos);
                        mbegin = font->getDimension(s.c_str()).Width;

                        // deal with kerning
                        mbegin += font->getKerningWidth(
                            &((*txtLine)[realmbgn - startPos]),
                            realmbgn - startPos > 0 ? &((*txtLine)[realmbgn - startPos - 1]) : 0);

                        lineStartPos = realmbgn - startPos;
                    }
                    if (i == hlineStart + hlineCount - 1)
                    {
                        // highlight end is on this line
                        s2 = txtLine->subString(0, realmend - startPos);
                        mend = font->getDimension(s2.c_str()).Width;
                        lineEndPos = (s32)s2.size();
                    }
                    else
                        mend = font->getDimension(txtLine->c_str()).Width;

                    CurrentTextRect.UpperLeftCorner.X += mbegin;
                    CurrentTextRect.LowerRightCorner.X = CurrentTextRect.UpperLeftCorner.X + mend - mbegin;

                    // draw mark
                    skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), CurrentTextRect, &localClipRect);

                    // draw marked text
                    s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos);

                    if (s.size())
                        font->draw(s.c_str(), CurrentTextRect,
                            OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
                            false, true, &localClipRect);

                }
            }

            // Return the override color information to its previous settings.
            OverrideColorEnabled = prevOver;
            OverrideColor = prevColor;
        }

        // draw cursor

        if (WordWrap || MultiLine)
        {
            cursorLine = getLineFromPos(CursorPos);
            txtLine = &BrokenText[cursorLine];
            startPos = BrokenTextPositions[cursorLine];
        }
        s = txtLine->subString(0,CursorPos-startPos);
        charcursorpos = font->getDimension(s.c_str()).Width ;
        // + font->getKerningWidth(L"_", CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0);

        if (focus && (getTime() - BlinkStartTime) % 2 == 0 && !m_rtl)
        {
            //setTextRect(cursorLine);
            //CurrentTextRect.UpperLeftCorner.X += charcursorpos;

            setTextRect(0);

            core::rect< s32 > caret_rect = CurrentTextRect;
            caret_rect.UpperLeftCorner.X += charcursorpos - 1;
            caret_rect.LowerRightCorner.X = caret_rect.UpperLeftCorner.X + 2;
            GL32_draw2DRectangle( video::SColor(255,0,0,0), caret_rect );

            /*
            font->draw(L"_", CurrentTextRect,
                OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
                false, true, &localClipRect);
             */
        }
    }

    // draw children
    IGUIElement::draw();
#endif
}