コード例 #1
0
ファイル: MultiLineEditbox.cpp プロジェクト: Toby91/DDEngine
void FalagardMultiLineEditbox::render()
{
    MultiLineEditbox* w = (MultiLineEditbox*)d_window;
    // render general frame and stuff before we handle the text itself
    cacheEditboxBaseImagery();

    // Render edit box text
    Rectf textarea(getTextRenderArea());
    cacheTextLines(textarea);

    // draw caret
    if ((w->hasInputFocus() && !w->isReadOnly()) &&
        (!d_blinkCaret || d_showCaret))
            cacheCaretImagery(textarea);
}
コード例 #2
0
ファイル: MultiLineEditbox.cpp プロジェクト: Toby91/DDEngine
void FalagardMultiLineEditbox::cacheTextLines(const Rectf& dest_area)
{
    MultiLineEditbox* w = (MultiLineEditbox*)d_window;
    // text is already formatted, we just grab the lines and render them with the required alignment.
    Rectf drawArea(dest_area);
    float vertScrollPos = w->getVertScrollbar()->getScrollPosition();
    drawArea.offset(Vector2f(-w->getHorzScrollbar()->getScrollPosition(), -vertScrollPos));

    const Font* fnt = w->getFont();

    if (fnt)
    {
        // calculate final colours to use.
        ColourRect colours;
        const float alpha = w->getEffectiveAlpha();
        ColourRect normalTextCol;
        setColourRectToUnselectedTextColour(normalTextCol);
        normalTextCol.modulateAlpha(alpha);
        ColourRect selectTextCol;
        setColourRectToSelectedTextColour(selectTextCol);
        selectTextCol.modulateAlpha(alpha);
        ColourRect selectBrushCol;
        w->hasInputFocus() ? setColourRectToActiveSelectionColour(selectBrushCol) :
                             setColourRectToInactiveSelectionColour(selectBrushCol);
        selectBrushCol.modulateAlpha(alpha);

        const MultiLineEditbox::LineList& d_lines = w->getFormattedLines();
        const size_t numLines = d_lines.size();

        // calculate the range of visible lines
        size_t sidx,eidx;
        sidx = static_cast<size_t>(vertScrollPos / fnt->getLineSpacing());
        eidx = 1 + sidx + static_cast<size_t>(dest_area.getHeight() / fnt->getLineSpacing());
        eidx = ceguimin(eidx, numLines);
        drawArea.d_min.d_y += fnt->getLineSpacing()*static_cast<float>(sidx);

        // for each formatted line.
        for (size_t i = sidx; i < eidx; ++i)
        {
            Rectf lineRect(drawArea);
            const MultiLineEditbox::LineInfo& currLine = d_lines[i];
            String lineText(w->getTextVisual().substr(currLine.d_startIdx, currLine.d_length));

            // offset the font little down so that it's centered within its own spacing
            const float old_top = lineRect.top();
            lineRect.d_min.d_y += (fnt->getLineSpacing() - fnt->getFontHeight()) * 0.5f;

            // if it is a simple 'no selection area' case
            if ((currLine.d_startIdx >= w->getSelectionEndIndex()) ||
                ((currLine.d_startIdx + currLine.d_length) <= w->getSelectionStartIndex()) ||
                (w->getSelectionBrushImage() == 0))
            {
                colours = normalTextCol;
                // render the complete line.
                fnt->drawText(w->getGeometryBuffer(), lineText,
                                lineRect.getPosition(), &dest_area, colours);
            }
            // we have at least some selection highlighting to do
            else
            {
                // Start of actual rendering section.
                String sect;
                size_t sectIdx = 0, sectLen;
                float selStartOffset = 0.0f, selAreaWidth = 0.0f;

                // render any text prior to selected region of line.
                if (currLine.d_startIdx < w->getSelectionStartIndex())
                {
                    // calculate length of text section
                    sectLen = w->getSelectionStartIndex() - currLine.d_startIdx;

                    // get text for this section
                    sect = lineText.substr(sectIdx, sectLen);
                    sectIdx += sectLen;

                    // get the pixel offset to the beginning of the selection area highlight.
                    selStartOffset = fnt->getTextAdvance(sect);

                    // draw this portion of the text
                    colours = normalTextCol;
                    fnt->drawText(w->getGeometryBuffer(), sect,
                                    lineRect.getPosition(), &dest_area, colours);

                    // set position ready for next portion of text
                    lineRect.d_min.d_x += selStartOffset;
                }

                // calculate the length of the selected section
                sectLen = ceguimin(w->getSelectionEndIndex() - currLine.d_startIdx, currLine.d_length) - sectIdx;

                // get the text for this section
                sect = lineText.substr(sectIdx, sectLen);
                sectIdx += sectLen;

                // get the extent to use as the width of the selection area highlight
                selAreaWidth = fnt->getTextAdvance(sect);

                const float text_top = lineRect.top();
                lineRect.top(old_top);

                // calculate area for the selection brush on this line
                lineRect.left(drawArea.left() + selStartOffset);
                lineRect.right(lineRect.left() + selAreaWidth);
                lineRect.bottom(lineRect.top() + fnt->getLineSpacing());

                // render the selection area brush for this line
                colours = selectBrushCol;
                w->getSelectionBrushImage()->render(w->getGeometryBuffer(), lineRect, &dest_area, colours);

                // draw the text for this section
                colours = selectTextCol;
                fnt->drawText(w->getGeometryBuffer(), sect,
                                lineRect.getPosition(), &dest_area, colours);

                lineRect.top(text_top);

                // render any text beyond selected region of line
                if (sectIdx < currLine.d_length)
                {
                    // update render position to the end of the selected area.
                    lineRect.d_min.d_x += selAreaWidth;

                    // calculate length of this section
                    sectLen = currLine.d_length - sectIdx;

                    // get the text for this section
                    sect = lineText.substr(sectIdx, sectLen);

                    // render the text for this section.
                    colours = normalTextCol;
                    fnt->drawText(w->getGeometryBuffer(), sect,
                                    lineRect.getPosition(), &dest_area, colours);
                }
            }

            // update master position for next line in paragraph.
            drawArea.d_min.d_y += fnt->getLineSpacing();
        }
    }
}