void LabelWidget::draw() { Rectanglei pos = rule().recti(); TextCanvas buf(pos.size()); buf.clear(d->background); // Use the wrapped lines to determine width and height. DENG2_ASSERT(!d->wraps.isEmpty()); Vector2i labelSize(d->wraps.width(), d->wraps.height()); // Determine position of the label based on alignment. Vector2i labelPos; if(d->align.testFlag(AlignRight)) { labelPos.x = buf.width() - labelSize.x; } else if(!d->align.testFlag(AlignLeft)) { labelPos.x = buf.width()/2 - labelSize.x/2; } if(d->align.testFlag(AlignBottom)) { labelPos.y = buf.height() - labelSize.y; } else if(!d->align.testFlag(AlignTop)) { labelPos.y = buf.height()/2 - labelSize.y/2; } buf.drawWrappedText(labelPos, d->label, d->wraps, d->attribs, d->align); targetCanvas().draw(buf, pos.topLeft); }
void LineEditWidget::draw() { Rectanglei pos = rule().recti(); // Temporary buffer for drawing. TextCanvas buf(pos.size()); TextCanvas::Char::Attribs attr = (hasFocus()? TextCanvas::Char::Reverse : TextCanvas::Char::DefaultAttributes); buf.clear(TextCanvas::Char(' ', attr)); buf.drawText(Vector2i(0, 0), prompt(), attr | TextCanvas::Char::Bold); // Underline the suggestion for completion. if(isSuggestingCompletion()) { buf.setRichFormatRange(TextCanvas::Char::Underline, completionRange()); } // Echo mode determines what we actually draw. String txt = text(); if(echoMode() == PasswordEchoMode) { txt = String(txt.size(), '*'); } buf.drawWrappedText(Vector2i(prompt().size(), 0), txt, lineWraps(), attr); targetCanvas().draw(buf, pos.topLeft); }