示例#1
0
void FalagardMultiLineEditbox::cacheCaretImagery(const Rectf& textArea)
{
    MultiLineEditbox* w = (MultiLineEditbox*)d_window;
    const Font* fnt = w->getFont();

    // require a font so that we can calculate caret position.
    if (fnt)
    {
        // get line that caret is in
        size_t caretLine = w->getLineNumberFromIndex(w->getCaretIndex());

        const MultiLineEditbox::LineList& d_lines = w->getFormattedLines();

        // if caret line is valid.
        if (caretLine < d_lines.size())
        {
            // calculate pixel offsets to where caret should be drawn
            size_t caretLineIdx = w->getCaretIndex() - d_lines[caretLine].d_startIdx;
            float ypos = caretLine * fnt->getLineSpacing();
            float xpos = fnt->getTextAdvance(w->getText().substr(d_lines[caretLine].d_startIdx, caretLineIdx));

//             // get base offset to target layer for cursor.
//             Renderer* renderer = System::getSingleton().getRenderer();
//             float baseZ = renderer->getZLayer(7) - renderer->getCurrentZ();

            // get WidgetLookFeel for the assigned look.
            const WidgetLookFeel& wlf = getLookNFeel();
            // get caret imagery
            const ImagerySection& caretImagery = wlf.getImagerySection("Caret");

            // calculate finat destination area for caret
            Rectf caretArea;
            caretArea.left(textArea.left() + xpos);
            caretArea.top(textArea.top() + ypos);
            caretArea.setWidth(caretImagery.getBoundingRect(*w).getSize().d_width);
            caretArea.setHeight(fnt->getLineSpacing());
            caretArea.offset(Vector2f(-w->getHorzScrollbar()->getScrollPosition(), -w->getVertScrollbar()->getScrollPosition()));

            // cache the caret image for rendering.
            caretImagery.render(*w, caretArea, 0, &textArea);
        }
    }
}
示例#2
0
void Chat::processMessage(Event * event)
{
	using namespace CEGUI;

	const char * message = event->getProperty("eventData").c_str() ;

	String messageChat(message);

	// add this entry to the command history buffer
	d_history.push_back(messageChat);
	// reset history position
	d_historyPos = d_history.size();
	// append newline to this entry
	message += '\n';
	// get history window
	MultiLineEditbox* history = static_cast<MultiLineEditbox*>(d_root->getChild("ListOfMessage"));
	// append new text to history output
	history->setText(history->getText() + messageChat);
	// scroll to bottom of history output
	history->setCaretIndex(static_cast<size_t>(-1));

}